コード例 #1
0
int usServiceFactoryTest(int /*argc*/, char* /*argv*/[])
{
  US_TEST_BEGIN("ServiceFactoryTest");

  TestServiceFactoryModuleScope();
  TestServiceFactoryPrototypeScope();

  US_TEST_END()
}
コード例 #2
0
ファイル: usServiceRegistryTest.cpp プロジェクト: 0r/MITK
int usServiceRegistryTest(int /*argc*/, char* /*argv*/[])
{
  US_TEST_BEGIN("ServiceRegistryTest");

  TestServiceInterfaceId();
  TestMultipleServiceRegistrations();
  TestServicePropertiesUpdate();

  US_TEST_END()
}
コード例 #3
0
int usModuleResourceTest(int /*argc*/, char* /*argv*/[])
{
  US_TEST_BEGIN("ModuleResourceTest");

  ModuleContext* mc = GetModuleContext();
  assert(mc);

#ifdef US_BUILD_SHARED_LIBS
  SharedLibrary libR(LIB_PATH, "TestModuleR");
  try
  {
    libR.Load();
  }
  catch (const std::exception& e)
  {
    US_TEST_FAILED_MSG(<< "Load module exception: " << e.what())
  }
#endif

  Module* moduleR = ModuleRegistry::GetModule("TestModuleR");
  US_TEST_CONDITION_REQUIRED(moduleR != nullptr, "Test for existing module TestModuleR")

  US_TEST_CONDITION(moduleR->GetName() == "TestModuleR", "Test module name")

  testInvalidResource(moduleR);

  testResourceFromExecutable(mc->GetModule());

  testResourceTree(moduleR);

  testResourceOperators(moduleR);

  testTextResource(moduleR);
  testTextResourceAsBinary(moduleR);
  testSpecialCharacters(moduleR);

  testBinaryResource(moduleR);

  testCompressedResource(moduleR);

  ModuleResource foo = moduleR->GetResource("foo.txt");
  US_TEST_CONDITION(foo.IsValid() == true, "Valid resource")
#ifdef US_BUILD_SHARED_LIBS
  libR.Unload();
  US_TEST_CONDITION(foo.IsValid() == true, "Still valid resource")
#endif

  testResourcesFrom("TestModuleRL");
  testResourcesFrom("TestModuleRA");

  US_TEST_END()
}
コード例 #4
0
ファイル: usStaticModuleTest.cpp プロジェクト: 0r/MITK
int usStaticModuleTest(int /*argc*/, char* /*argv*/[])
{
  US_TEST_BEGIN("StaticModuleTest");

  ModuleContext* mc = GetModuleContext();
  TestModuleListener listener;

  ModuleListenerRegistrationHelper<TestModuleListener> ml(mc, &listener, &TestModuleListener::ModuleChanged);
  ServiceListenerRegistrationHelper<TestModuleListener> sl(mc, &listener, &TestModuleListener::ServiceChanged);

  SharedLibrary libB(LIB_PATH, "TestModuleB");
  frame020a(mc, listener, libB);
  frame030b(mc, listener, libB);

  US_TEST_END()
}
コード例 #5
0
ファイル: usModuleTest.cpp プロジェクト: Maggunator/MITK
int usModuleTest(int /*argc*/, char* /*argv*/[])
{
  US_TEST_BEGIN("ModuleTest");

  frame02a();

  ModuleContext* mc = GetModuleContext();
  TestModuleListener listener;

  try
  {
    mc->AddModuleListener(&listener, &TestModuleListener::ModuleChanged);
  }
  catch (const std::logic_error& ise)
  {
    US_TEST_OUTPUT( << "module listener registration failed " << ise.what() );
    throw;
  }

  try
  {
    mc->AddServiceListener(&listener, &TestModuleListener::ServiceChanged);
  }
  catch (const std::logic_error& ise)
  {
    US_TEST_OUTPUT( << "service listener registration failed " << ise.what() );
    throw;
  }

  frame005a(mc);
  frame010a(mc);
  frame018a(mc);

  SharedLibrary libA(LIB_PATH, "TestModuleA");
  frame020a(mc, listener, libA);
  frame030b(mc, listener, libA);

  frame045a(mc);

  mc->RemoveModuleListener(&listener, &TestModuleListener::ModuleChanged);
  mc->RemoveServiceListener(&listener, &TestModuleListener::ServiceChanged);

  US_TEST_END()
}
コード例 #6
0
US_USE_NAMESPACE

int usServiceTrackerTest(int /*argc*/, char* /*argv*/[])
{
  US_TEST_BEGIN("ServiceTrackerTest")

  ModuleContext* mc = GetModuleContext();
  SharedLibraryHandle libS("TestModuleS");

  // Start the test target to get a service published.
  try
  {
    libS.Load();
  }
  catch (const std::exception& e)
  {
    US_TEST_FAILED_MSG( << "Failed to load module, got exception: " << e.what() );
  }

  // 1. Create a ServiceTracker with ServiceTrackerCustomizer == null

  std::string s1("org.cppmicroservices.TestModuleSService");
  ServiceReference servref = mc->GetServiceReference(s1 + "0");

  US_TEST_CONDITION_REQUIRED(servref != 0, "Test if registered service of id org.cppmicroservices.TestModuleSService0");

  ServiceControlInterface* serviceController = mc->GetService<ServiceControlInterface>(servref);
  US_TEST_CONDITION_REQUIRED(serviceController != 0, "Test valid service controller");

  std::auto_ptr<ServiceTracker<> > st1(new ServiceTracker<>(mc, servref));

  // 2. Check the size method with an unopened service tracker

  US_TEST_CONDITION_REQUIRED(st1->Size() == 0, "Test if size == 0");

  // 3. Open the service tracker and see what it finds,
  // expect to find one instance of the implementation,
  // "org.cppmicroservices.TestModuleSService0"

  st1->Open();
  std::string expName  = "TestModuleS";
  std::list<ServiceReference> sa2;
  st1->GetServiceReferences(sa2);

  US_TEST_CONDITION_REQUIRED(sa2.size() == 1, "Checking ServiceTracker size");
  std::string name(us_service_impl_name(mc->GetService(sa2.front())));
  US_TEST_CONDITION_REQUIRED(name == expName, "Checking service implementation name");

  // 5. Close this service tracker
  st1->Close();

  // 6. Check the size method, now when the servicetracker is closed
  US_TEST_CONDITION_REQUIRED(st1->Size() == 0, "Checking ServiceTracker size");

  // 7. Check if we still track anything , we should get null
  sa2.clear();
  st1->GetServiceReferences(sa2);
  US_TEST_CONDITION_REQUIRED(sa2.empty(), "Checking ServiceTracker size");

  // 8. A new Servicetracker, this time with a filter for the object
  std::string fs = std::string("(") + ServiceConstants::OBJECTCLASS() + "=" + s1 + "*" + ")";
  LDAPFilter f1(fs);
  st1.reset(new ServiceTracker<>(mc, f1));
  // add a service
  serviceController->ServiceControl(1, "register", 7);

  // 9. Open the service tracker and see what it finds,
  // expect to find two instances of references to
  // "org.cppmicroservices.TestModuleSService*"
  // i.e. they refer to the same piece of code

  st1->Open();
  sa2.clear();
  st1->GetServiceReferences(sa2);
  US_TEST_CONDITION_REQUIRED(sa2.size() == 2, "Checking service reference count");
  for (std::list<ServiceReference>::const_iterator i = sa2.begin();  i != sa2.end(); ++i)
  {
    std::string name(mc->GetService(*i)->GetNameOfClass());
    US_TEST_CONDITION_REQUIRED(name == expName, "Check for expected class name");
  }

  // 10. Get libTestModuleS to register one more service and see if it appears
  serviceController->ServiceControl(2, "register", 1);
  sa2.clear();
  st1->GetServiceReferences(sa2);
  US_TEST_CONDITION_REQUIRED(sa2.size() == 3, "Checking service reference count");
  for (std::list<ServiceReference>::const_iterator i = sa2.begin(); i != sa2.end(); ++i)
  {
    std::string name(mc->GetService(*i)->GetNameOfClass());
    US_TEST_CONDITION_REQUIRED(name == expName, "Check for expected class name");
  }

  // 11. Get libTestModuleS to register one more service and see if it appears
  serviceController->ServiceControl(3, "register", 2);
  sa2.clear();
  st1->GetServiceReferences(sa2);
  US_TEST_CONDITION_REQUIRED(sa2.size() == 4, "Checking service reference count");
  for (std::list<ServiceReference>::const_iterator i = sa2.begin(); i != sa2.end(); ++i)
  {
    std::string name = mc->GetService(*i)->GetNameOfClass();
    US_TEST_CONDITION_REQUIRED(name == expName, "Check for expected class name");
  }

  // 12. Get libTestModuleS to unregister one service and see if it disappears
  serviceController->ServiceControl(3, "unregister", 0);
  sa2.clear();
  st1->GetServiceReferences(sa2);
  US_TEST_CONDITION_REQUIRED(sa2.size() == 3, "Checking service reference count");
  for (std::list<ServiceReference>::const_iterator i = sa2.begin(); i != sa2.end(); ++i)
  {
    std::string name = mc->GetService(*i)->GetNameOfClass();
    US_TEST_CONDITION_REQUIRED(name == expName, "Check for expected class name");
  }

  // 13. Get the highest ranking service reference, it should have ranking 7
  ServiceReference h1 = st1->GetServiceReference();
  int rank = any_cast<int>(h1.GetProperty(ServiceConstants::SERVICE_RANKING()));
  US_TEST_CONDITION_REQUIRED(rank == 7, "Check service rank");

  // 14. Get the service of the highest ranked service reference

  US_BASECLASS_NAME* o1 = st1->GetService(h1);
  US_TEST_CONDITION_REQUIRED(o1 != 0, "Check for non-null service");

  // 14a Get the highest ranked service, directly this time
  US_BASECLASS_NAME* o3 = st1->GetService();
  US_TEST_CONDITION_REQUIRED(o3 != 0, "Check for non-null service");
  US_TEST_CONDITION_REQUIRED(o1 == o3, "Check for equal service instances");

  // 15. Now release the tracking of that service and then try to get it
  //     from the servicetracker, which should yield a null object
  serviceController->ServiceControl(1, "unregister", 7);
  US_BASECLASS_NAME* o2 = st1->GetService(h1);
  US_TEST_CONDITION_REQUIRED(o2 == 0, "Checkt that service is null");

  // 16. Get all service objects this tracker tracks, it should be 2
  std::list<US_BASECLASS_NAME*> ts1;
  st1->GetServices(ts1);
  US_TEST_CONDITION_REQUIRED(ts1.size() == 2, "Check service count");

  // 17. Test the remove method.
  //     First register another service, then remove it being tracked
  serviceController->ServiceControl(1, "register", 7);
  h1 = st1->GetServiceReference();
  std::list<ServiceReference> sa3;
  st1->GetServiceReferences(sa3);
  US_TEST_CONDITION_REQUIRED(sa3.size() == 3, "Check service reference count");
  for (std::list<ServiceReference>::const_iterator i = sa3.begin(); i != sa3.end(); ++i)
  {
    std::string name = mc->GetService(*i)->GetNameOfClass();
    US_TEST_CONDITION_REQUIRED(name == expName, "Checking for expected class name");
  }

  st1->Remove(h1);           // remove tracking on one servref
  sa2.clear();
  st1->GetServiceReferences(sa2);
  US_TEST_CONDITION_REQUIRED(sa2.size() == 2, "Check service reference count");

  // 18. Test the addingService method,add a service reference

  // 19. Test the removedService method, remove a service reference


  // 20. Test the waitForService method
  US_BASECLASS_NAME* o9 = st1->WaitForService(50);
  US_TEST_CONDITION_REQUIRED(o9 != 0, "Checking WaitForService method");

  US_TEST_END()
}
コード例 #7
0
ファイル: usSharedLibraryTest.cpp プロジェクト: 0r/MITK
US_USE_NAMESPACE

int usSharedLibraryTest(int /*argc*/, char* /*argv*/[])
{
  US_TEST_BEGIN("SharedLibraryTest");

#ifdef US_PLATFORM_WINDOWS
  const std::string LIB_PATH = US_RUNTIME_OUTPUT_DIRECTORY;
  const std::string LIB_PREFIX = "";
  const std::string LIB_SUFFIX = ".dll";
  const char PATH_SEPARATOR = '\\';
#elif defined(US_PLATFORM_APPLE)
  const std::string LIB_PATH = US_LIBRARY_OUTPUT_DIRECTORY;
  const std::string LIB_PREFIX = "lib";
  const std::string LIB_SUFFIX = ".dylib";
  const char PATH_SEPARATOR = '/';
#else
  const std::string LIB_PATH = US_LIBRARY_OUTPUT_DIRECTORY;
  const std::string LIB_PREFIX = "lib";
  const std::string LIB_SUFFIX = ".so";
  const char PATH_SEPARATOR = '/';

#endif

  const std::string libAFilePath = LIB_PATH + PATH_SEPARATOR + LIB_PREFIX + "TestModuleA" + LIB_SUFFIX;
  SharedLibrary lib1(libAFilePath);
  US_TEST_CONDITION(lib1.GetFilePath() == libAFilePath, "Absolute file path")
  US_TEST_CONDITION(lib1.GetLibraryPath() == LIB_PATH, "Library path")
  US_TEST_CONDITION(lib1.GetName() == "TestModuleA", "Name")
  US_TEST_CONDITION(lib1.GetPrefix() == LIB_PREFIX, "Prefix")
  US_TEST_CONDITION(lib1.GetSuffix() == LIB_SUFFIX, "Suffix")
  lib1.SetName("bla");
  US_TEST_CONDITION(lib1.GetName() == "TestModuleA", "Name after SetName()")
  lib1.SetLibraryPath("bla");
  US_TEST_CONDITION(lib1.GetLibraryPath() == LIB_PATH, "Library path after SetLibraryPath()")
  lib1.SetPrefix("bla");
  US_TEST_CONDITION(lib1.GetPrefix() == LIB_PREFIX, "Prefix after SetPrefix()")
  lib1.SetSuffix("bla");
  US_TEST_CONDITION(lib1.GetSuffix() == LIB_SUFFIX, "Suffix after SetSuffix()")
  US_TEST_CONDITION(lib1.GetFilePath() == libAFilePath, "File path after setters")

  lib1.SetFilePath("bla");
  US_TEST_CONDITION(lib1.GetFilePath() == "bla", "Invalid file path")
  US_TEST_CONDITION(lib1.GetLibraryPath().empty(), "Empty lib path")
  US_TEST_CONDITION(lib1.GetName() == "bla", "Invalid file name")
  US_TEST_CONDITION(lib1.GetPrefix() == LIB_PREFIX, "Invalid prefix")
  US_TEST_CONDITION(lib1.GetSuffix() == LIB_SUFFIX, "Invalid suffix")

  US_TEST_FOR_EXCEPTION(std::runtime_error, lib1.Load())
  US_TEST_CONDITION(lib1.IsLoaded() == false, "Is loaded")
  US_TEST_CONDITION(lib1.GetHandle() == NULL, "Handle")

  lib1.SetFilePath(libAFilePath);
  lib1.Load();
  US_TEST_CONDITION(lib1.IsLoaded() == true, "Is loaded")
  US_TEST_CONDITION(lib1.GetHandle() != NULL, "Handle")
  US_TEST_FOR_EXCEPTION(std::logic_error, lib1.Load())

  lib1.SetFilePath("bla");
  US_TEST_CONDITION(lib1.GetFilePath() == libAFilePath, "File path")
  lib1.Unload();


  SharedLibrary lib2(LIB_PATH, "TestModuleA");
  US_TEST_CONDITION(lib2.GetFilePath() == libAFilePath, "File path")
  lib2.SetPrefix("");
  US_TEST_CONDITION(lib2.GetPrefix().empty(), "Lib prefix")
  US_TEST_CONDITION(lib2.GetFilePath() == LIB_PATH + PATH_SEPARATOR + "TestModuleA" + LIB_SUFFIX, "File path")

  SharedLibrary lib3 = lib2;
  US_TEST_CONDITION(lib3.GetFilePath() == lib2.GetFilePath(), "Compare file path")
  lib3.SetPrefix(LIB_PREFIX);
  US_TEST_CONDITION(lib3.GetFilePath() == libAFilePath, "Compare file path")
  lib3.Load();
  US_TEST_CONDITION(lib3.IsLoaded(), "lib3 loaded")
  US_TEST_CONDITION(!lib2.IsLoaded(), "lib2 not loaded")
  lib1 = lib3;
  US_TEST_FOR_EXCEPTION(std::logic_error, lib1.Load())
  lib2.SetPrefix(LIB_PREFIX);
  lib2.Load();

  lib3.Unload();
  US_TEST_CONDITION(!lib3.IsLoaded(), "lib3 unloaded")
  US_TEST_CONDITION(!lib1.IsLoaded(), "lib3 unloaded")
  lib2.Unload();
  lib1.Unload();

  US_TEST_END()
}