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

manager_bad.cc

Go to the documentation of this file.
00001 /*
00002  * manager_bad.cc
00003  *
00004  * Copyright (c) 2003, 2004 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 <iostream>
00026 #include <assert_pp.h>
00027 
00028 #include <BrokerC.h>
00029 #include <ManagerImpl.hh>
00030 
00031 #include <StubTask.hh>
00032 
00033 using namespace std;
00034 
00035 /**
00036  * Executable arguments.
00037  */
00038 static struct {
00039     int verbose;
00040 } args = {
00041     1,
00042 };
00043 
00044 /**
00045  * Macro used to catch and possibly print out expected exceptions.
00046  *
00047  * @param BLOCK The block of code to execute in a try/catch.
00048  * @param EXCEPTION The expected exception.
00049  */
00050 #define expect_catch(BLOCK, EXCEPTION)                          \
00051 {                                                               \
00052     try                                                         \
00053     {                                                           \
00054         BLOCK;                                                  \
00055         ensure(0);                                              \
00056     }                                                           \
00057     catch(const EXCEPTION &_e)                                  \
00058     {                                                           \
00059         if( args.verbose )                                      \
00060         {                                                       \
00061             cerr << "Tried \""                                  \
00062                  << __STRING(BLOCK)                             \
00063                  << "\" at line "                               \
00064                  << __LINE__                                    \
00065                  << " and got expected exception \""            \
00066                  << _e                                          \
00067                  << "\""                                        \
00068                  << endl;                                       \
00069         }                                                       \
00070     }                                                           \
00071     catch(const CORBA::Exception &_e)                           \
00072     {                                                           \
00073         if( args.verbose )                                      \
00074         {                                                       \
00075             cerr << "Tried \""                                  \
00076                  << __STRING(BLOCK)                             \
00077                  << "\" at line "                               \
00078                  << __LINE__                                    \
00079                  << " and got unexpected exception \""          \
00080                  << _e                                          \
00081                  << "\""                                        \
00082                  << endl;                                       \
00083         }                                                       \
00084     }                                                           \
00085 }
00086 
00087 #if defined(BLOCK_ON_SEGV)
00088 static void sigloop(int sig)
00089 {
00090     for( ;; )
00091     {
00092         sleep(5);
00093     }
00094 }
00095 #endif
00096 
00097 int main(int argc, char *argv[])
00098 {
00099     int retval = EXIT_SUCCESS;
00100 
00101 #if defined(BLOCK_ON_SEGV)
00102     signal(SIGSEGV, sigloop);
00103 #endif
00104 
00105     try
00106     {
00107         /* ORB setup */
00108         CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
00109         
00110         CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
00111         
00112         PortableServer::POA_var root_poa =
00113             PortableServer::POA::_narrow(obj.in());
00114         PortableServer::POAManager_var mgr = root_poa->the_POAManager();
00115         mgr->activate();
00116         
00117         /* Broker setup */
00118         ManagerImpl *mi = new ManagerImpl("dummy");
00119         Broker::Manager_var manager;
00120         
00121         manager = mi->_this();
00122         
00123         StubTask *st = new StubTask();
00124         Broker::Task_var task;
00125         
00126         task = st->_this();
00127         
00128         assert(CORBA::is_nil(manager->CurrentPolicy()));
00129         
00130         manager->CurrentPolicy(Broker::Policy::_nil());
00131         
00132         Broker::ScheduleParameters sparam;
00133         sparam.length(0);
00134         
00135         /* Check nil argument to Broker::Manager::AddTask */
00136         expect_catch(manager->AddTask(Broker::Task::_nil(), sparam),
00137                      CORBA::BAD_PARAM);
00138         
00139         manager->AddTask(task.in(), sparam);
00140         /* Check re-add of same task. */
00141         expect_catch(manager->AddTask(task.in(), sparam), CORBA::BAD_PARAM);
00142         
00143         /* Check nil argument to Broker::Manager::RemoveTask */
00144         expect_catch(manager->RemoveTask(Broker::Task::_nil()),
00145                      CORBA::BAD_PARAM);
00146 
00147         manager->RemoveTask(task.in());
00148         /* Check double remove. */
00149         expect_catch(manager->RemoveTask(task.in()), CORBA::BAD_PARAM);
00150         
00151         {
00152             Broker::CPUReserve cr;
00153             
00154             /* Check nil to Broker::Manager::ChangeTaskCPU */
00155             expect_catch(manager->ChangeTaskCPU(Broker::RealTimeTask::_nil(),
00156                                                 cr),
00157                          CORBA::BAD_PARAM);
00158         }
00159         
00160         task = Broker::Task::_nil();
00161         delete st;
00162         
00163         manager = Broker::Manager::_nil();
00164         delete mi;
00165     }
00166     catch(const CORBA::Exception &e)
00167     {
00168         cerr << "Caught unexpected exception: " << e << endl;
00169     }
00170     
00171     return( retval );
00172 }

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