diff options
author | Johannes Schanda <schanda@itestra.de> | 2013-08-27 18:03:33 +0200 |
---|---|---|
committer | Gerrit Code Review <qqmthk1@lpmodthk02.bmwgroup.net> | 2013-08-27 18:03:33 +0200 |
commit | e5763a15d45ff1e5f2f03b9fde07c253a3d0f9f2 (patch) | |
tree | 092c9311c20b323422aab87e5855d3a042daabbb | |
parent | 614c604041783d03d7d994c66dfa389e3257c08c (diff) | |
parent | 4088e5c506c9a8f3a8e761692eee823656f5618b (diff) | |
download | genivi-common-api-dbus-runtime-e5763a15d45ff1e5f2f03b9fde07c253a3d0f9f2.tar.gz |
Merge "Fixed logic error in tests on dynamic loading"
-rw-r--r-- | src/test/dbusDynamicLoadingTests/DBusDynamicLoadingBasicTest.cpp | 64 | ||||
-rw-r--r-- | src/test/dbusDynamicLoadingTests/DBusDynamicLoadingDefinitions.h | 50 |
2 files changed, 73 insertions, 41 deletions
diff --git a/src/test/dbusDynamicLoadingTests/DBusDynamicLoadingBasicTest.cpp b/src/test/dbusDynamicLoadingTests/DBusDynamicLoadingBasicTest.cpp index 9c49a6e..fb91f5f 100644 --- a/src/test/dbusDynamicLoadingTests/DBusDynamicLoadingBasicTest.cpp +++ b/src/test/dbusDynamicLoadingTests/DBusDynamicLoadingBasicTest.cpp @@ -58,13 +58,16 @@ TEST_F(DBusDynamicLoadingBasicTest, LoadsUnconfiguredDefaultDynamicallyLinkedLib } TEST_F(DBusDynamicLoadingBasicTest, LoadsSpecificDynamicallyLinkedDBusLibrary) { + //DBus is defined as default binding in the configuration file std::shared_ptr<CommonAPI::Runtime> defaultRuntime = CommonAPI::Runtime::load(); + + //The Fake binding has "DBus" defined as its alias, so this call will access the Fake binding! std::shared_ptr<CommonAPI::Runtime> dbusRuntime = CommonAPI::Runtime::load("DBus"); + EXPECT_TRUE((bool)defaultRuntime); EXPECT_TRUE((bool)dbusRuntime); - //Even though Fake has "DBus" defined as an alias, the well known name of the DBus binding - //(which coincidentially is "DBus") has precedence. - ASSERT_EQ(dbusRuntime, defaultRuntime); + + ASSERT_NE(dbusRuntime, defaultRuntime); } TEST_F(DBusDynamicLoadingBasicTest, LoadsAliasedDynamicallyLinkedDBusLibrary) { @@ -80,10 +83,14 @@ TEST_F(DBusDynamicLoadingBasicTest, ReturnsEmptyPointerOnRequestForUnknownMiddle } TEST_F(DBusDynamicLoadingBasicTest, LoadsDBusLibraryAsSingleton) { - std::shared_ptr<CommonAPI::Runtime> runtime1 = CommonAPI::Runtime::load("DBus"); + //"DBus" is set as default. Due to the alias definition in the Fake binding, it would not + //be accessible when passing this well known name as parameter, only the aliases still + //point to the DBus binding. + std::shared_ptr<CommonAPI::Runtime> runtime1 = CommonAPI::Runtime::load(); std::shared_ptr<CommonAPI::Runtime> runtime2 = CommonAPI::Runtime::load("MyFirstAlias"); std::shared_ptr<CommonAPI::Runtime> runtime3 = CommonAPI::Runtime::load("MySecondAlias"); - std::shared_ptr<CommonAPI::Runtime> runtime4 = CommonAPI::Runtime::load("DBus"); + std::shared_ptr<CommonAPI::Runtime> runtime4 = CommonAPI::Runtime::load(); + EXPECT_TRUE((bool)runtime1); EXPECT_TRUE((bool)runtime2); EXPECT_TRUE((bool)runtime3); @@ -98,7 +105,7 @@ TEST_F(DBusDynamicLoadingBasicTest, LoadsDBusLibraryAsSingleton) { } TEST_F(DBusDynamicLoadingBasicTest, RuntimeLoadsFactory) { - std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load("DBus"); + std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load(); ASSERT_TRUE((bool)runtime); std::shared_ptr<CommonAPI::Factory> proxyFactory = runtime->createFactory(); @@ -106,7 +113,7 @@ TEST_F(DBusDynamicLoadingBasicTest, RuntimeLoadsFactory) { } TEST_F(DBusDynamicLoadingBasicTest, RuntimeLoadsServicePublisher) { - std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load("DBus"); + std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load(); ASSERT_TRUE((bool)runtime); std::shared_ptr<CommonAPI::ServicePublisher> servicePublisher = runtime->getServicePublisher(); @@ -114,7 +121,7 @@ TEST_F(DBusDynamicLoadingBasicTest, RuntimeLoadsServicePublisher) { } TEST_F(DBusDynamicLoadingBasicTest, FactoryCanCreateProxies) { - std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load("DBus"); + std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load(); ASSERT_TRUE((bool)runtime); std::shared_ptr<CommonAPI::Factory> proxyFactory = runtime->createFactory(); @@ -124,24 +131,53 @@ TEST_F(DBusDynamicLoadingBasicTest, FactoryCanCreateProxies) { ASSERT_TRUE((bool)defaultTestProxy); } -TEST_F(DBusDynamicLoadingBasicTest, ServicePublisherCanRegisterStubs) { +TEST_F(DBusDynamicLoadingBasicTest, FakeFactoryCannotCreateProxies) { + //Fake has the alias "DBus". Therefore, the actual DBus-binding is NOT accessible via + //its well known name! std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load("DBus"); ASSERT_TRUE((bool)runtime); + std::shared_ptr<CommonAPI::Factory> proxyFactory = runtime->createFactory(); + EXPECT_TRUE((bool)proxyFactory); + + auto defaultTestProxy = proxyFactory->buildProxy<commonapi::tests::TestInterfaceProxy>(testServiceAddress); + ASSERT_FALSE((bool)defaultTestProxy); +} + +TEST_F(DBusDynamicLoadingBasicTest, ServicePublisherCanRegisterStubs) { + std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load(); + ASSERT_TRUE((bool)runtime); + std::shared_ptr<CommonAPI::Factory> serviceFactory = runtime->createFactory(); - EXPECT_TRUE((bool)serviceFactory); + ASSERT_TRUE((bool)serviceFactory); std::shared_ptr<CommonAPI::ServicePublisher> servicePublisher = runtime->getServicePublisher(); - EXPECT_TRUE((bool)servicePublisher); + ASSERT_TRUE((bool)servicePublisher); auto myStub = std::make_shared<commonapi::tests::TestInterfaceStubDefault>(); - servicePublisher->registerService(myStub, testServiceAddress, serviceFactory); - servicePublisher->unregisterService(testServiceAddress); + EXPECT_TRUE(servicePublisher->registerService(myStub, testServiceAddress, serviceFactory)); + EXPECT_TRUE(servicePublisher->unregisterService(testServiceAddress)); +} + +TEST_F(DBusDynamicLoadingBasicTest, FakeServicePublisherTellsUsItWontRegisterStubs) { + std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load("Fake"); + ASSERT_TRUE((bool)runtime); + + std::shared_ptr<CommonAPI::Factory> serviceFactory = runtime->createFactory(); + ASSERT_TRUE((bool)serviceFactory); + + std::shared_ptr<CommonAPI::ServicePublisher> servicePublisher = runtime->getServicePublisher(); + ASSERT_TRUE((bool)servicePublisher); + + auto myStub = std::make_shared<commonapi::tests::TestInterfaceStubDefault>(); + + EXPECT_FALSE(servicePublisher->registerService(myStub, testServiceAddress, serviceFactory)); + EXPECT_FALSE(servicePublisher->unregisterService(testServiceAddress)); } TEST_F(DBusDynamicLoadingBasicTest, CreatedProxiesAndServicesCanCommunicate) { - std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load("DBus"); + std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load(); ASSERT_TRUE((bool)runtime); std::shared_ptr<CommonAPI::Factory> proxyFactory = runtime->createFactory(); diff --git a/src/test/dbusDynamicLoadingTests/DBusDynamicLoadingDefinitions.h b/src/test/dbusDynamicLoadingTests/DBusDynamicLoadingDefinitions.h index cecf22e..529af6b 100644 --- a/src/test/dbusDynamicLoadingTests/DBusDynamicLoadingDefinitions.h +++ b/src/test/dbusDynamicLoadingTests/DBusDynamicLoadingDefinitions.h @@ -30,35 +30,12 @@ const std::string COMMONAPI_ENVIRONMENT_BINDING_PATH = "COMMONAPI_BINDING_PATH"; const std::string currentBinaryFileFQN = CommonAPI::getCurrentBinaryFileFQN(); const std::string currentWorkingDirectory = currentBinaryFileFQN.substr(0, currentBinaryFileFQN.find_last_of("/") + 1); -const std::string firstAlias = "MyFirstAlias"; -const std::string secondAlias = "MySecondAlias"; -const std::string firstAliasDefinition = "alias=" + firstAlias + "\n"; -const std::string secondAliasDefinition = "alias=" + secondAlias + "\n"; -const std::string combinedAliasDefinition = "alias=" + firstAlias + ":" + secondAlias + "\n"; +const std::string firstAliasDefinition = "alias=MyFirstAlias\n"; +const std::string secondAliasDefinition = "alias=MySecondAlias\n"; +const std::string combinedAliasDefinition = "alias=MyFirstAlias:MySecondAlias\n"; const std::string libraryDBusPathDefinition = "libpath=" + currentWorkingDirectory + "libCommonAPI-DBus.so\n"; const std::string libraryFakePathDefinition = "libpath=" + currentWorkingDirectory + "libCommonAPI-Fake.so\n"; const std::string generatedDBusPathDefinition = "genpath=" + currentWorkingDirectory + "libSomeOtherNameForGeneratedDBus.so\n"; -const std::string dbusBindingDefinitionStart = "{binding:DBus}\n"; -const std::string fakeBindingDefinitionStart = "{binding:Fake}\n"; - -const std::string validForLocalDBusBinding = - dbusBindingDefinitionStart + - combinedAliasDefinition + - libraryDBusPathDefinition + - "default" + - fakeBindingDefinitionStart + - "alias=DBus\n"; - -const std::string validForMultiplyDefinedDBusBinding = - dbusBindingDefinitionStart + - libraryDBusPathDefinition + - generatedDBusPathDefinition + - firstAliasDefinition + - "\n" + - dbusBindingDefinitionStart + - secondAliasDefinition + - "libpath=/useless/path"; - const std::string __garbageString = "" "{not#a$valid/binding+PATH}\n" @@ -76,6 +53,25 @@ const std::string __garbageString = "{noBinding:/useless/path}\n" "{:incomplete}\n"; + +const std::string validForLocalDBusBinding = + "{binding:DBus}\n" + + combinedAliasDefinition + + libraryDBusPathDefinition + + "default\n" + + "{binding:Fake}\n" + + "alias=DBus\n"; + +const std::string validForMultiplyDefinedDBusBinding = + "{binding:DBus}\n" + + libraryDBusPathDefinition + + generatedDBusPathDefinition + + firstAliasDefinition + + "\n" + + "{binding:DBus}\n" + + secondAliasDefinition + + "libpath=/useless/path"; + const std::string mixedValidityValuesAndBindings = "{binding: InvalidBinding}\n" + firstAliasDefinition + @@ -105,7 +101,7 @@ const std::string noValidityValuesAndBindings = "libpath=/some/path/to/nowhere\n" + "default\n" + __garbageString + - dbusBindingDefinitionStart + + "{binding:DBus}\n" + "genpath=" + currentWorkingDirectory + "libNonsense.so\n"; |