Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

manager_good.cc

Go to the documentation of this file.
00001 /*
00002  * manager_good.cc
00003  *
00004  * Copyright (c) 2003 The University of Utah and the Flux Group.
00005  * All rights reserved.
00006  *
00007  * This file is licensed under the terms of the GNU Public License.  
00008  * See the file "license.terms" for restrictions on redistribution 
00009  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
00010  */
00011 
00012 /**
00013  * @file manager_good.cc
00014  *
00015  * Test the ManagerImpl class.
00016  */
00017 
00018 #include "config.h"
00019 
00020 #if !defined(DEBUG)
00021 #define DEBUG 1
00022 #endif
00023 
00024 #include <assert.h>
00025 #include <assert_pp.h>
00026 
00027 #include <BrokerC.h>
00028 #include <ManagerImpl.hh>
00029 
00030 #include <StubTask.hh>
00031 #include <StubPolicy.hh>
00032 
00033 int main(int argc, char *argv[])
00034 {
00035     int retval = EXIT_SUCCESS;
00036     
00037     /* ORB setup */
00038     CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
00039     
00040     CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
00041     
00042     PortableServer::POA_var root_poa =
00043         PortableServer::POA::_narrow(obj.in());
00044     PortableServer::POAManager_var mgr = root_poa->the_POAManager();
00045     mgr->activate();
00046 
00047     /* Broker setup */
00048     ManagerImpl *mi = new ManagerImpl("dummy");
00049     Broker::Manager_var manager;
00050 
00051     manager = mi->_this();
00052 
00053     StubPolicy *sp = new StubPolicy("dummy");
00054     Broker::Policy_var policy;
00055 
00056     policy = sp->_this();
00057 
00058     StubTask *st = new StubTask();
00059     Broker::Task_var task;
00060 
00061     task = st->_this();
00062 
00063     /* Check initial values */
00064     assert(CORBA::is_nil(manager->CurrentPolicy()));
00065 
00066     Broker::ScheduleParameters sparam;
00067     sparam.length(0);
00068     
00069     /* Add a task and */
00070     manager->AddTask(task.in(), sparam);
00071     /* ... make sure its in there (i.e. no exception). */
00072     manager->RemoveTask(task.in());
00073 
00074     /* Add policy and */
00075     manager->CurrentPolicy(policy.in());
00076     /* ... check activated state */
00077     assert(!CORBA::is_nil(manager->CurrentPolicy()));
00078     assert(sp->sp_Tasks.length() == 0);
00079 
00080     /* Make sure we can set a nil policy */
00081     manager->CurrentPolicy(Broker::Policy::_nil());
00082     assert(CORBA::is_nil(manager->CurrentPolicy()));
00083 
00084     /* Make sure existing tasks are passed to Broker::Policy::Activate */
00085     manager->AddTask(task.in(), sparam);
00086     manager->CurrentPolicy(policy.in());
00087     assert(sp->sp_Tasks.length() == 1);
00088 
00089     /* Make sure Broker::Policy::Deactivate is called and */
00090     manager->CurrentPolicy(Broker::Policy::_nil());
00091     /* ... the policy drops the tasks. */
00092     assert(sp->sp_Tasks.length() == 0);
00093 
00094     /* Recheck activation. */
00095     manager->CurrentPolicy(policy.in());
00096     assert(sp->sp_Tasks.length() == 1);
00097 
00098     /* Check dynamic removal and addition of task. */
00099     manager->RemoveTask(task.in());
00100     assert(sp->sp_Tasks.length() == 0);
00101     manager->AddTask(task.in(), sparam);
00102     assert(sp->sp_Tasks.length() == 1);
00103 
00104     task = Broker::Task::_nil();
00105     delete st;
00106     
00107     //policy = Broker::Policy::_nil();
00108     //delete sp;
00109 
00110     manager = Broker::Manager::_nil();
00111     delete mi;
00112     
00113     return( retval );
00114 }

Generated on Fri Oct 22 07:50:24 2004 for CPU Broker by  doxygen 1.3.9.1