Source

mana-core-clidcomps / test / ClassIDSvc_test.cxx

The default branch has multiple heads

Full commit
/** @file ClassIDSvc_test.cxx  unit test for ClassIDSvc
 * @author ATLAS Collaboration
 * $Id: ClassIDSvc_test.cxx,v 1.1.1.1 2007-03-02 00:02:36 calaf Exp $
 ***************************************************************************/

#undef NDEBUG

//<<<<<< INCLUDES                                                       >>>>>>

#include <cassert>
#include <iostream>
#include "TestTools/initGaudi.h"
#include "GaudiKernel/ISvcLocator.h"
#include "AthenaKernel/IClassIDSvc.h"
#include "CLIDSvc/ClassIDSvc.h"

#include "CLIDSvc/CLASS_DEF.h"
#include "CLIDSvc/tools/CLIDRegistry.h"
class Foo{};
CLASS_DEF( Foo, 8101, 0) 
class Bar{};
CLASS_DEF( Bar, 8107, 0) 

#define ASSERTERROR( FALSEEXPR )   \
    std::cerr << "Now we expect to see an error message:" << std::endl \
              << "----Error Message Starts--->>" << std::endl; \
    assert(!FALSEEXPR); \
    std::cerr<< "<<---Error Message Ends-------" << std::endl

using namespace std;
using namespace Athena_test;

int main() {
  cout << "*** ClassIDSvc_test starts ***" <<endl;
  ISvcLocator* pSvcLoc(0);
  if (!initGaudi("ClassIDSvc_test.txt", pSvcLoc)) {
    cerr << "This test can not be run" << endl;
    return 0;
  }  
  assert(pSvcLoc);

  IClassIDSvc* pClassIDSvc(0);
  assert((pSvcLoc->service("ClassIDSvc", pClassIDSvc, true)).isSuccess());
  assert(pClassIDSvc);

  assert(pClassIDSvc->nextAvailableID() == CLIDRegistry::MINCLID);
  Athena::PackageInfo info(PACKAGE_VERSION);
  Athena::PackageInfo info2("APack-00-39-98");
  assert(pClassIDSvc->setTypePackageForID(7890, "Bla", info2).isSuccess());
  ASSERTERROR(pClassIDSvc->setTypePackageForID(CLIDRegistry::MINCLID/2, "No", 
					       info).isSuccess());
  ASSERTERROR(pClassIDSvc->setTypePackageForID(CLIDRegistry::MAXCLID*2, "Nah", 
					       info).isSuccess());
  //FIXME is this an issue? Should we do the reverse check type -> id?
  assert(pClassIDSvc->setTypePackageForID(9942, "Bli", info).isSuccess());
  assert(pClassIDSvc->setTypePackageForID(9943, "Blu", info).isSuccess());
  ASSERTERROR(pClassIDSvc->setTypePackageForID(7890, "Ble", info).isSuccess());
  //check disabled  ASSERTERROR(pClassIDSvc->setTypePackageForID(9942, "Bli", info2).isSuccess());
  ASSERTERROR(pClassIDSvc->setTypePackageForID(9945, "Bli", info).isSuccess());
  assert(pClassIDSvc->setTypePackageForID(7890, "Bla", info2).isSuccess());
  assert(pClassIDSvc->setTypePackageForID(7890, " Bla", info2).isSuccess());
  assert(pClassIDSvc->setTypePackageForID(7890, "   Bl a ", info2).isSuccess());
  assert(pClassIDSvc->setTypePackageForID(7890, " B  l a ", info2).isSuccess());
  assert(pClassIDSvc->setTypePackageForID(7890, "Bla   ", info2).isSuccess());


  string name; 
  assert(pClassIDSvc->getTypeNameOfID(8101, name).isSuccess());
  assert(name == "Foo");
  assert(pClassIDSvc->getTypeNameOfID(8107, name).isSuccess());
  assert(name == "Bar");
  assert(pClassIDSvc->getTypeNameOfID(7890, name).isSuccess());
  assert(name == "Bla");
  assert(pClassIDSvc->getTypeNameOfID(9942, name).isSuccess());
  assert(name == "Bli");
  assert(pClassIDSvc->getTypeNameOfID(9943, name).isSuccess());
  assert(name == "Blu");
  assert(pClassIDSvc->getTypeNameOfID(2, name).isFailure());

  CLID id;
  assert(pClassIDSvc->getIDOfTypeName("Blu", id).isSuccess());
  assert(id == 9943);
  assert(pClassIDSvc->getIDOfTypeName("NotExist", id).isFailure());

  assert(pClassIDSvc->isIDInUse(9942));
  //  assert(!pClassIDSvc->isIDInUse(9945));
  assert(!pClassIDSvc->isIDInUse((unsigned)-2243341));

  assert(pClassIDSvc->isNameInUse("Blu"));
  assert(!pClassIDSvc->isNameInUse("NotExist"));
  assert(!pClassIDSvc->isNameInUse(""));

  //  dynamic_cast<ClassIDSvc*>(pClassIDSvc)->dump();

  assert((dynamic_cast<IService*>(pClassIDSvc)->finalize()).isSuccess());

  cout << "*** ClassIDSvc_test OK ***" <<endl;
  return 0;
}