TestLibraryImpl.cpp

00001 #include "TestLibraryImpl.h"
00002 #include "Sct/SctNames.h"
00003 #include "Sct/SequenceUtils.h"
00004 #include "Sct/OmniMarshalling.h"
00005 #include "mrs/message.h"
00006 
00007 namespace SctCalibrationController {
00008     
00009   bool TestLibraryImpl::registerStaticFactoryMethodForTest(const std::string & name,  const FunctionPointer f) {
00010     std::cout << "Making a note of a TestRequest called [" << name << "] at line " << __LINE__ << " of " << __FILE__ << std::endl;
00011     bool success; // no need to initialise
00012 
00013     if (f!=0) {
00014       stringFunctionPtrMap()[name] = f;
00015       success = true;
00016     } else {
00017       std::cerr << "I refuse to make a note of a TestRequest called [" << name << "] at line " << __LINE__ << " of " << __FILE__ << " as the supplied function pointer was nil." << std::endl;
00018       success = false;
00019     };
00020     
00021     return success;
00022   };
00023 
00024   // The name that is supplied to this method should be the "bare" name of the test, i.e. leave out
00025   // any trailing "Test".  Example:  "StrobeDelay" not "StrobeDelayTest"
00026   Sct_CalibrationController::TestRequest_ptr TestLibraryImpl::getTestRequestByName(const char * name) {
00027     const std::string n = name; 
00028     const StringFunctionPtrMap::const_iterator it = stringFunctionPtrMap().find(n);
00029 
00030     Sct_CalibrationController::TestRequest_ptr ans = Sct_CalibrationController::TestRequest::_nil();
00031 
00032     if (it == stringFunctionPtrMap().end()) {
00033       std::ostringstream os;
00034       os << "Was asked in TestLibraryImpl::getTestRequestByName(const char * name) at line " << __LINE__ << " of " << __FILE__ << " for a TestRequest named [" << n << "] that doesn't exist, or rather has not yet been put into the map that records which ones exist!";
00035       Sct::SctNames::Mrs() << MRS_WARNING << "TEST_LIBRARY_IMPL" << MRS_TEXT(os.str()) << ENDM;
00036     } else {
00037       // Call the static instance method of the TestRequest to get hold of its instance.
00038       ans = ((it->second)());
00039       if (CORBA::is_nil(ans)) {
00040         // oh dear .. this should not happen .. something has gone wrong.
00041         std::ostringstream os;
00042         os << "I was asked in TestLibraryImpl::getTestRequestByName(const char * name) at line " << __LINE__ << " of " << __FILE__ << " for a TestRequest named [" << n << "].  This test was indeed registered with me, but the instance associated with the function pointer was nil.  There is something rotten in the state of Denmark.";
00043         Sct::SctNames::Mrs() << MRS_WARNING << "TEST_LIBRARY_IMPL" << MRS_TEXT(os.str()) << ENDM;
00044       };
00045     };
00046 
00047     return ans;
00048   }
00049 
00050   Sct_CalibrationController::TestLibrary::Strings* TestLibraryImpl::getTestNames() {
00051     const unsigned int siz=stringFunctionPtrMap().size();
00052     Sct_CalibrationController::TestLibrary::Strings*seq = Sct::SequenceUtils::newSafeSequence<Sct_CalibrationController::TestLibrary::Strings>(siz);
00053     unsigned int i=0;
00054     for (StringFunctionPtrMap::const_iterator it=stringFunctionPtrMap().begin();
00055          it!=stringFunctionPtrMap().end();
00056          (++it, ++i)) {
00057       (*seq)[i] = Sct::copyStringToCorba(it->first);
00058     };
00059     return seq;
00060   };
00061   
00062 TestLibraryImpl::TestLibraryImpl() {
00063     std::cout << "create TestLibraryImpl" << std::endl;
00064 }
00065 
00066 Sct_CalibrationController::TestLibrary_ptr TestLibraryImpl::instance() {
00067     static TestLibraryImpl* instance = new TestLibraryImpl();
00068     return instance->_this();
00069 }
00070 
00071 }

Generated on Mon Feb 6 14:01:34 2006 for SCT DAQ/DCS Software - C++ by  doxygen 1.4.6