PengZheng commented on a change in pull request #399: URL: https://github.com/apache/celix/pull/399#discussion_r816547547
########## File path: libs/framework/gtest/src/bundle_context_services_test.cpp ########## @@ -61,6 +61,189 @@ class CelixBundleContextServicesTests : public ::testing::Test { CelixBundleContextServicesTests(const CelixBundleContextServicesTests&) = delete; CelixBundleContextServicesTests& operator=(CelixBundleContextServicesTests&&) = delete; CelixBundleContextServicesTests& operator=(const CelixBundleContextServicesTests&) = delete; + + void registerAndUseServiceWithCorrectVersion(bool direct) { + struct calc { + int (*calc)(int); + }; + + const char *calcName = "calc"; + struct calc svc; + svc.calc = [](int n) -> int { + return n * 42; + }; + + celix_service_use_options_t use_opts{}; + use_opts.filter.serviceName = "calc"; + use_opts.filter.versionRange = "[1,2)"; + if(direct) { + use_opts.flags = CELIX_SERVICE_USE_DIRECT; + } + + celix_service_registration_options_t reg_opts{}; + reg_opts.serviceName = calcName; + reg_opts.serviceVersion = "1.5"; + reg_opts.svc = &svc; + + bool called = celix_bundleContext_useServiceWithOptions(ctx, &use_opts); + ASSERT_TRUE(!called); //service not avail. + + std::future<bool> result{std::async([&]{ + use_opts.waitTimeoutInSeconds = 5.0; + printf("Trying to call calc with timeout of %f\n", use_opts.waitTimeoutInSeconds); + bool calledAsync = celix_bundleContext_useServiceWithOptions(ctx, &use_opts); + printf("returned from use service with timeout. calc called %s.\n", calledAsync ? "true" : "false"); + return calledAsync; + })}; + long svcId = celix_bundleContext_registerServiceWithOptions(ctx, ®_opts); + ASSERT_TRUE(svcId >= 0); + + ASSERT_TRUE(result.get()); //should return true after waiting for the registered service. + + celix_bundleContext_unregisterService(ctx, svcId); + } Review comment: Fixed. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@celix.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org