This is an automated email from the ASF dual-hosted git repository. pnoltes pushed a commit to branch feature/#91_rsa_enum_issue in repository https://gitbox.apache.org/repos/asf/celix.git
commit 19d952d877b5d13b57680942d4857abaf00eeffc Author: Pepijn Noltes <[email protected]> AuthorDate: Mon Mar 9 13:20:52 2020 +0100 #91 Refactors remote service dfi cpputests to google tests --- .../remote_service_admin_dfi/CMakeLists.txt | 2 +- .../{test => gtest}/CMakeLists.txt | 10 +-- .../{test => gtest}/client.properties.in | 0 .../{test => gtest}/config.properties.in | 0 .../{test => gtest}/server.properties.in | 0 .../remote_service_admin_dfi/gtest/src/main.cc | 26 ++++++++ .../src/rsa_client_server_tests.cc} | 52 ++++++++------- .../src/rsa_tests.cpp => gtest/src/rsa_tests.cc} | 74 +++++++++++----------- .../{test => gtest}/src/tst_activator.c | 0 .../{test => gtest}/src/tst_service.h | 0 .../test/src/run_tests.cpp | 26 -------- .../gtest/src/bundle_context_services_test.cpp | 2 +- 12 files changed, 96 insertions(+), 96 deletions(-) diff --git a/bundles/remote_services/remote_service_admin_dfi/CMakeLists.txt b/bundles/remote_services/remote_service_admin_dfi/CMakeLists.txt index 3aa1936..d15ca97 100644 --- a/bundles/remote_services/remote_service_admin_dfi/CMakeLists.txt +++ b/bundles/remote_services/remote_service_admin_dfi/CMakeLists.txt @@ -48,7 +48,7 @@ if (RSA_REMOTE_SERVICE_ADMIN_DFI) ) if (ENABLE_TESTING) - add_subdirectory(test) + add_subdirectory(gtest) endif() diff --git a/bundles/remote_services/remote_service_admin_dfi/test/CMakeLists.txt b/bundles/remote_services/remote_service_admin_dfi/gtest/CMakeLists.txt similarity index 94% rename from bundles/remote_services/remote_service_admin_dfi/test/CMakeLists.txt rename to bundles/remote_services/remote_service_admin_dfi/gtest/CMakeLists.txt index 6355e95..793d167 100644 --- a/bundles/remote_services/remote_service_admin_dfi/test/CMakeLists.txt +++ b/bundles/remote_services/remote_service_admin_dfi/gtest/CMakeLists.txt @@ -36,15 +36,17 @@ target_link_libraries(rsa_dfi_tst_bundle PRIVATE ${CPPUTEST_LIBRARY} calculator_ target_include_directories(rsa_dfi_tst_bundle PRIVATE src) add_executable(test_rsa_dfi - src/run_tests.cpp - src/rsa_tests.cpp - src/rsa_client_server_tests.cpp + src/main.cc + src/rsa_tests.cc + src/rsa_client_server_tests.cc ) target_include_directories(test_rsa_dfi PRIVATE src) -target_link_libraries(test_rsa_dfi PRIVATE CURL::libcurl ${CPPUTEST_LIBRARY} +target_link_libraries(test_rsa_dfi PRIVATE + CURL::libcurl Celix::framework Celix::rsa_common calculator_api + GTest::GTest ) get_property(rsa_bundle_file TARGET rsa_dfi PROPERTY BUNDLE_FILE) diff --git a/bundles/remote_services/remote_service_admin_dfi/test/client.properties.in b/bundles/remote_services/remote_service_admin_dfi/gtest/client.properties.in similarity index 100% rename from bundles/remote_services/remote_service_admin_dfi/test/client.properties.in rename to bundles/remote_services/remote_service_admin_dfi/gtest/client.properties.in diff --git a/bundles/remote_services/remote_service_admin_dfi/test/config.properties.in b/bundles/remote_services/remote_service_admin_dfi/gtest/config.properties.in similarity index 100% rename from bundles/remote_services/remote_service_admin_dfi/test/config.properties.in rename to bundles/remote_services/remote_service_admin_dfi/gtest/config.properties.in diff --git a/bundles/remote_services/remote_service_admin_dfi/test/server.properties.in b/bundles/remote_services/remote_service_admin_dfi/gtest/server.properties.in similarity index 100% rename from bundles/remote_services/remote_service_admin_dfi/test/server.properties.in rename to bundles/remote_services/remote_service_admin_dfi/gtest/server.properties.in diff --git a/bundles/remote_services/remote_service_admin_dfi/gtest/src/main.cc b/bundles/remote_services/remote_service_admin_dfi/gtest/src/main.cc new file mode 100644 index 0000000..09731c4 --- /dev/null +++ b/bundles/remote_services/remote_service_admin_dfi/gtest/src/main.cc @@ -0,0 +1,26 @@ +/** + *Licensed to the Apache Software Foundation (ASF) under one + *or more contributor license agreements. See the NOTICE file + *distributed with this work for additional information + *regarding copyright ownership. The ASF licenses this file + *to you under the Apache License, Version 2.0 (the + *"License"); you may not use this file except in compliance + *with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + *Unless required by applicable law or agreed to in writing, + *software distributed under the License is distributed on an + *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + *specific language governing permissions and limitations + *under the License. + */ + +#include <gtest/gtest.h> + +int main(int argc, char **argv) { + ::testing::InitGoogleTest(&argc, argv); + int rc = RUN_ALL_TESTS(); + return rc; +} \ No newline at end of file diff --git a/bundles/remote_services/remote_service_admin_dfi/test/src/rsa_client_server_tests.cpp b/bundles/remote_services/remote_service_admin_dfi/gtest/src/rsa_client_server_tests.cc similarity index 79% rename from bundles/remote_services/remote_service_admin_dfi/test/src/rsa_client_server_tests.cpp rename to bundles/remote_services/remote_service_admin_dfi/gtest/src/rsa_client_server_tests.cc index 74f7ef4..9c99504 100644 --- a/bundles/remote_services/remote_service_admin_dfi/test/src/rsa_client_server_tests.cpp +++ b/bundles/remote_services/remote_service_admin_dfi/gtest/src/rsa_client_server_tests.cc @@ -17,14 +17,11 @@ * under the License. */ - +#include "gtest/gtest.h" #include <remote_constants.h> #include <tst_service.h> #include "celix_api.h" -#include <CppUTest/CommandLineTestRunner.h> -#include <CppUTest/TestHarness.h> - extern "C" { #include <stdio.h> @@ -47,19 +44,19 @@ extern "C" { static void setupFm(void) { //server celix_properties_t *serverProps = celix_properties_load("server.properties"); - CHECK_TRUE(serverProps != NULL); + ASSERT_TRUE(serverProps != NULL); serverFramework = celix_frameworkFactory_createFramework(serverProps); - CHECK_TRUE(serverFramework != NULL); + ASSERT_TRUE(serverFramework != NULL); serverContext = celix_framework_getFrameworkContext(serverFramework); - CHECK_TRUE(serverContext != NULL); + ASSERT_TRUE(serverContext != NULL); //client celix_properties_t *clientProperties = celix_properties_load("client.properties"); - CHECK_TRUE(clientProperties != NULL); + ASSERT_TRUE(clientProperties != NULL); clientFramework = celix_frameworkFactory_createFramework(clientProperties); - CHECK_TRUE(clientFramework != NULL); + ASSERT_TRUE(clientFramework != NULL); clientContext = celix_framework_getFrameworkContext(clientFramework); - CHECK_TRUE(clientContext != NULL); + ASSERT_TRUE(clientContext != NULL); } static void teardownFm(void) { @@ -73,32 +70,32 @@ extern "C" { bool ok; bool discovered = tst->isCalcDiscovered(tst->handle); - CHECK_TRUE(discovered); + ASSERT_TRUE(discovered); ok = tst->testCalculator(tst->handle); - CHECK_TRUE(ok); + ASSERT_TRUE(ok); discovered = tst->isRemoteExampleDiscovered(tst->handle); - CHECK_TRUE(discovered); + ASSERT_TRUE(discovered); ok = tst->testRemoteComplex(tst->handle); - CHECK_TRUE(ok); + ASSERT_TRUE(ok); ok = tst->testRemoteAction(tst->handle); - CHECK_TRUE(ok); + ASSERT_TRUE(ok); ok = tst->testRemoteNumbers(tst->handle); - CHECK_TRUE(ok); + ASSERT_TRUE(ok); ok = tst->testRemoteString(tst->handle); - CHECK_TRUE(ok); + ASSERT_TRUE(ok); ok = tst->testRemoteConstString(tst->handle); - CHECK_TRUE(ok); + ASSERT_TRUE(ok); //TODO fix for apple dfi handling, see issue #91 - //ok = tst->testRemoteEnum(tst->handle); - //CHECK_TRUE(ok); +// ok = tst->testRemoteEnum(tst->handle); +// ASSERT_TRUE(ok); }; static void test(void) { @@ -108,22 +105,23 @@ extern "C" { opts.filter.ignoreServiceLanguage = true; opts.waitTimeoutInSeconds = 2; bool called = celix_bundleContext_useServiceWithOptions(clientContext, &opts); - CHECK_TRUE(called); + ASSERT_TRUE(called); } } - -TEST_GROUP(RsaDfiClientServerTests) { - void setup() { +class RsaDfiClientServerTests : public ::testing::Test { +public: + RsaDfiClientServerTests() { setupFm(); } - - void teardown() { + ~RsaDfiClientServerTests() override { teardownFm(); } + }; -TEST(RsaDfiClientServerTests, Test1) { + +TEST_F(RsaDfiClientServerTests, Test1) { test(); } diff --git a/bundles/remote_services/remote_service_admin_dfi/test/src/rsa_tests.cpp b/bundles/remote_services/remote_service_admin_dfi/gtest/src/rsa_tests.cc similarity index 82% rename from bundles/remote_services/remote_service_admin_dfi/test/src/rsa_tests.cpp rename to bundles/remote_services/remote_service_admin_dfi/gtest/src/rsa_tests.cc index 334575a..b2fee66 100644 --- a/bundles/remote_services/remote_service_admin_dfi/test/src/rsa_tests.cpp +++ b/bundles/remote_services/remote_service_admin_dfi/gtest/src/rsa_tests.cc @@ -17,13 +17,12 @@ * under the License. */ +#include "gtest/gtest.h" + #include <remote_constants.h> #include "celix_api.h" #include "calculator_service.h" -#include <CppUTest/TestHarness.h> -#include <CppUTest/CommandLineTestRunner.h> - extern "C" { #include "remote_service_admin.h" @@ -38,15 +37,15 @@ extern "C" { static void setupFm(void) { celix_properties_t *fwProperties = celix_properties_load("config.properties"); - CHECK_TRUE(fwProperties != NULL); + ASSERT_TRUE(fwProperties != NULL); framework = celix_frameworkFactory_createFramework(fwProperties); - CHECK_TRUE(framework != NULL); + ASSERT_TRUE(framework != NULL); context = celix_framework_getFrameworkContext(framework); - CHECK_TRUE(context != NULL); + ASSERT_TRUE(context != NULL); calcSvcId = celix_bundleContext_findService(context, CALCULATOR_SERVICE); - CHECK_TRUE(calcSvcId >= 0L); + ASSERT_TRUE(calcSvcId >= 0L); } static void teardownFm(void) { @@ -59,12 +58,12 @@ extern "C" { celix_array_list_t *imported = celix_arrayList_create(); int rc = rsa->getExportedServices(rsa->admin, &exported); - CHECK_EQUAL(CELIX_SUCCESS, rc); - CHECK_EQUAL(0, celix_arrayList_size(exported)); + ASSERT_EQ(CELIX_SUCCESS, rc); + ASSERT_EQ(0, celix_arrayList_size(exported)); rc = rsa->getImportedEndpoints(rsa->admin, &imported); - CHECK_EQUAL(CELIX_SUCCESS, rc); - CHECK_EQUAL(0, celix_arrayList_size(imported)); + ASSERT_EQ(CELIX_SUCCESS, rc); + ASSERT_EQ(0, celix_arrayList_size(imported)); celix_arrayList_destroy(imported); celix_arrayList_destroy(exported); @@ -77,7 +76,7 @@ extern "C" { opts.filter.ignoreServiceLanguage = true; opts.waitTimeoutInSeconds = 0.25; bool called = celix_bundleContext_useServiceWithOptions(context, &opts); - CHECK_TRUE(called); + ASSERT_TRUE(called); } static void testExportServiceCallback(void *handle __attribute__((unused)), void *svc) { @@ -88,12 +87,12 @@ extern "C" { celix_array_list_t *svcRegistration = NULL; int rc = rsa->exportService(rsa->admin, strSvcId, NULL, &svcRegistration); - CHECK_EQUAL(CELIX_SUCCESS, rc); + ASSERT_EQ(CELIX_SUCCESS, rc); - CHECK_EQUAL(1, celix_arrayList_size(svcRegistration)); + ASSERT_EQ(1, celix_arrayList_size(svcRegistration)); rc = rsa->exportRegistration_close(rsa->admin,(export_registration_t *)(arrayList_get(svcRegistration,0))); - CHECK_EQUAL(CELIX_SUCCESS, rc); + ASSERT_EQ(CELIX_SUCCESS, rc); } @@ -104,7 +103,7 @@ extern "C" { opts.filter.ignoreServiceLanguage = true; opts.waitTimeoutInSeconds = 0.25; bool called = celix_bundleContext_useServiceWithOptions(context, &opts); - CHECK_TRUE(called); + ASSERT_TRUE(called); } static void testImportServiceCallback(void *handle __attribute__((unused)), void *svc) { @@ -122,28 +121,28 @@ extern "C" { celix_properties_set(props, OSGI_FRAMEWORK_OBJECTCLASS, "org.apache.celix.Example"); rc = endpointDescription_create(props, &endpoint); - CHECK_EQUAL(CELIX_SUCCESS, rc); + ASSERT_EQ(CELIX_SUCCESS, rc); rc = rsa->importService(rsa->admin, endpoint, ®); - CHECK_EQUAL(CELIX_SUCCESS, rc); - CHECK(reg != NULL); + ASSERT_EQ(CELIX_SUCCESS, rc); + ASSERT_TRUE(reg != NULL); service_reference_pt ref = NULL; rc = bundleContext_getServiceReference(context, (char *)"org.apache.celix.Example", &ref); - CHECK_EQUAL(CELIX_SUCCESS, rc); - CHECK(ref != NULL); + ASSERT_EQ(CELIX_SUCCESS, rc); + ASSERT_TRUE(ref != NULL); rc = bundleContext_ungetServiceReference(context, ref); - CHECK_EQUAL(CELIX_SUCCESS, rc); + ASSERT_EQ(CELIX_SUCCESS, rc); rc = endpointDescription_destroy(endpoint); - CHECK_EQUAL(CELIX_SUCCESS, rc); + ASSERT_EQ(CELIX_SUCCESS, rc); /* Cannot test. uses requesting bundles descriptor void *service = NULL; rc = bundleContext_getService(context, ref, &service); - CHECK_EQUAL(CELIX_SUCCESS, rc); - CHECK(service != NULL); + ASSERT_EQ(CELIX_SUCCESS, rc); + ASSERT_TRUE(service != NULL); */ } @@ -154,15 +153,15 @@ extern "C" { opts.filter.ignoreServiceLanguage = true; opts.waitTimeoutInSeconds = 0.25; bool called = celix_bundleContext_useServiceWithOptions(context, &opts); - CHECK_TRUE(called); + ASSERT_TRUE(called); } static void testBundles(void) { array_list_pt bundles = NULL; int rc = bundleContext_getBundles(context, &bundles); - CHECK_EQUAL(0, rc); - CHECK_EQUAL(3, arrayList_size(bundles)); //framework, rsa_dfi & calc + ASSERT_EQ(0, rc); + ASSERT_EQ(3, arrayList_size(bundles)); //framework, rsa_dfi & calc /* int size = arrayList_size(bundles); @@ -183,29 +182,30 @@ extern "C" { } - -TEST_GROUP(RsaDfiTests) { - void setup() { +class RsaDfiTests : public ::testing::Test { +public: + RsaDfiTests() { setupFm(); } - - void teardown() { + ~RsaDfiTests() override { teardownFm(); } + }; -TEST(RsaDfiTests, InfoTest) { + +TEST_F(RsaDfiTests, InfoTest) { testServices(); } -TEST(RsaDfiTests, ExportService) { +TEST_F(RsaDfiTests, ExportService) { testExportService(); } -TEST(RsaDfiTests, ImportService) { +TEST_F(RsaDfiTests, ImportService) { testImportService(); } -TEST(RsaDfiTests, TestBundles) { +TEST_F(RsaDfiTests, TestBundles) { testBundles(); } diff --git a/bundles/remote_services/remote_service_admin_dfi/test/src/tst_activator.c b/bundles/remote_services/remote_service_admin_dfi/gtest/src/tst_activator.c similarity index 100% rename from bundles/remote_services/remote_service_admin_dfi/test/src/tst_activator.c rename to bundles/remote_services/remote_service_admin_dfi/gtest/src/tst_activator.c diff --git a/bundles/remote_services/remote_service_admin_dfi/test/src/tst_service.h b/bundles/remote_services/remote_service_admin_dfi/gtest/src/tst_service.h similarity index 100% rename from bundles/remote_services/remote_service_admin_dfi/test/src/tst_service.h rename to bundles/remote_services/remote_service_admin_dfi/gtest/src/tst_service.h diff --git a/bundles/remote_services/remote_service_admin_dfi/test/src/run_tests.cpp b/bundles/remote_services/remote_service_admin_dfi/test/src/run_tests.cpp deleted file mode 100644 index efaee82..0000000 --- a/bundles/remote_services/remote_service_admin_dfi/test/src/run_tests.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#include <CppUTest/TestHarness.h> -#include "CppUTest/CommandLineTestRunner.h" - -int main(int argc, char** argv) { - MemoryLeakWarningPlugin::turnOffNewDeleteOverloads(); - return RUN_ALL_TESTS(argc, argv); -} \ No newline at end of file diff --git a/libs/framework/gtest/src/bundle_context_services_test.cpp b/libs/framework/gtest/src/bundle_context_services_test.cpp index 17e0d89..0006266 100644 --- a/libs/framework/gtest/src/bundle_context_services_test.cpp +++ b/libs/framework/gtest/src/bundle_context_services_test.cpp @@ -175,7 +175,7 @@ TEST_F(CelixBundleContextServicesTests, registerAndUseService) { }; TEST_F(CelixBundleContextServicesTests, registerAndUseServiceWithTimeout) { - const int NR_ITERATIONS = 5; //NOTE this test is sensitive for triggering race condition in the celix framework, therefore is used a few times. + const int NR_ITERATIONS = 1000; //NOTE this test is sensitive for triggering race condition in the celix framework, therefore is used a few times. for (int i = 0; i < NR_ITERATIONS; ++i) { printf("Iter %i\n", i); struct calc {
