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

manager_bad.cc

Go to the documentation of this file.
00001 /*
00002  * manager_bad.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_bad.cc
00014  *
00015  * Test the ManagerImpl class to make sure it detects bad inputs.
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 
00032 struct {
00033     int verbose;
00034 } args = {
00035     1,
00036 };
00037 
00038 /**
00039  * Macro used to catch and possibly print out expected exceptions.
00040  *
00041  * @param BLOCK The block of code to execute in a try/catch.
00042  * @param EXCEPTION The expected exception.
00043  */
00044 #define expect_catch(BLOCK, EXCEPTION)                          \
00045 {                                                               \
00046     try                                                         \
00047     {                                                           \
00048         BLOCK;                                                  \
00049         ensure(0);                                              \
00050     }                                                           \
00051     catch(const EXCEPTION &_e)                                  \
00052     {                                                           \
00053         if( args.verbose )                                      \
00054         {                                                       \
00055             cerr << "Tried \""                                  \
00056                  << __STRING(BLOCK)                             \
00057                  << "\" at line "                               \
00058                  << __LINE__                                    \
00059                  << " and got expected exception \""            \
00060                  << _e                                          \
00061                  << "\""                                        \
00062                  << endl;                                       \
00063         }                                                       \
00064     }                                                           \
00065 }
00066 
00067 #if defined(BLOCK_ON_SEGV)
00068 static void sigloop(int sig)
00069 {
00070     for( ;; )
00071     {
00072         sleep(5);
00073     }
00074 }
00075 #endif
00076 
00077 int main(int argc, char *argv[])
00078 {
00079     int retval = EXIT_SUCCESS;
00080 
00081 #if defined(BLOCK_ON_SEGV)
00082     signal(SIGSEGV, sigloop);
00083 #endif
00084     
00085     /* ORB setup */
00086     CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
00087     
00088     CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
00089     
00090     PortableServer::POA_var root_poa =
00091         PortableServer::POA::_narrow(obj.in());
00092     PortableServer::POAManager_var mgr = root_poa->the_POAManager();
00093     mgr->activate();
00094 
00095     /* Broker setup */
00096     ManagerImpl *mi = new ManagerImpl("dummy");
00097     Broker::Manager_var manager;
00098 
00099     manager = mi->_this();
00100 
00101     StubTask *st = new StubTask();
00102     Broker::Task_var task;
00103 
00104     task = st->_this();
00105     
00106     assert(CORBA::is_nil(manager->CurrentPolicy()));
00107 
00108     manager->CurrentPolicy(Broker::Policy::_nil());
00109 
00110     Broker::ScheduleParameters sparam;
00111     sparam.length(0);
00112 
00113     /* Check nil argument to Broker::Manager::AddTask */
00114     expect_catch(manager->AddTask(Broker::Task::_nil(), sparam),
00115                  CORBA::BAD_PARAM);
00116 
00117     manager->AddTask(task.in(), sparam);
00118     /* Check re-add of same task. */
00119     expect_catch(manager->AddTask(task.in(), sparam), CORBA::BAD_PARAM);
00120 
00121     /* Check nil argument to Broker::Manager::RemoveTask */
00122     expect_catch(manager->RemoveTask(Broker::Task::_nil()), CORBA::BAD_PARAM);
00123 
00124     manager->RemoveTask(task.in());
00125     /* Check double remove. */
00126     expect_catch(manager->RemoveTask(task.in()), CORBA::BAD_PARAM);
00127 
00128     /* Check nil to Broker::Manager::ChangeTaskCPU */
00129     expect_catch(manager->ChangeTaskCPU(Broker::RealTimeTask::_nil(),
00130                                         0,
00131                                         0,
00132                                         0),
00133                  CORBA::BAD_PARAM);
00134 
00135     task = Broker::Task::_nil();
00136     delete st;
00137 
00138     manager = Broker::Manager::_nil();
00139     delete mi;
00140     
00141     return( retval );
00142 }

Generated on Mon Dec 1 16:29:06 2003 for CPU Broker by doxygen 1.3.4