2626#include " celix_properties_ei.h"
2727#include " celix_utils_ei.h"
2828#include " celix_threads_ei.h"
29+ #include " celix_string_hash_map_ei.h"
30+ #include " celix_filter_ei.h"
31+ #include " asprintf_ei.h"
2932
3033class TopologyManagerCreatingErrorInjectionTestSuite : public ::testing::Test {
3134public:
@@ -45,6 +48,10 @@ class TopologyManagerCreatingErrorInjectionTestSuite : public ::testing::Test {
4548 celix_ei_expect_calloc (nullptr , 0 , nullptr );
4649 celix_ei_expect_celixThreadMutex_create (nullptr , 0 , 0 );
4750 celix_ei_expect_celix_longHashMap_create (nullptr , 0 , nullptr );
51+ celix_ei_expect_celix_stringHashMap_create (nullptr , 0 , nullptr );
52+ celix_ei_expect_celix_stringHashMap_putLong (nullptr , 1 , 0 );
53+ celix_ei_expect_celix_utils_strdup (nullptr , 0 , nullptr );
54+ celix_ei_expect_celix_stringHashMap_createWithOptions (nullptr , 0 , nullptr );
4855 }
4956
5057 std::shared_ptr<celix_framework_t > fw{};
@@ -60,6 +67,42 @@ TEST_F(TopologyManagerCreatingErrorInjectionTestSuite, AllocingMemoryErrorTest)
6067 EXPECT_EQ (CELIX_ENOMEM, status);
6168}
6269
70+ TEST_F (TopologyManagerCreatingErrorInjectionTestSuite, CreatingImportedServiceRankingOffsetMapErrorTest) {
71+ celix_ei_expect_celix_stringHashMap_create ((void *)topologyManager_create, 0 , nullptr );
72+ void *scope{};
73+ topology_manager_t *tmPtr{};
74+ auto status = topologyManager_create (ctx.get (), logHelper.get (), &tmPtr, &scope);
75+ EXPECT_EQ (CELIX_ENOMEM, status);
76+ }
77+
78+ TEST_F (TopologyManagerCreatingErrorInjectionTestSuite, ImportedServiceRankingOffsetStringDuplicationErrorTest) {
79+ setenv (" CELIX_RSA_IMPORTED_SERVICE_RANKING_OFFSETS" , " configType1=10,configType2=20" , 1 );
80+ celix_ei_expect_celix_utils_strdup ((void *)topologyManager_create, 1 , nullptr );
81+ void *scope{};
82+ topology_manager_t *tmPtr{};
83+ auto status = topologyManager_create (ctx.get (), logHelper.get (), &tmPtr, &scope);
84+ EXPECT_EQ (CELIX_ENOMEM, status);
85+ unsetenv (" CELIX_RSA_IMPORTED_SERVICE_RANKING_OFFSETS" );
86+ }
87+
88+ TEST_F (TopologyManagerCreatingErrorInjectionTestSuite, AddingImportedServiceRankingOffsetErrorTest) {
89+ setenv (" CELIX_RSA_IMPORTED_SERVICE_RANKING_OFFSETS" , " configType1=10,configType2=20" , 1 );
90+ celix_ei_expect_celix_stringHashMap_putLong ((void *)topologyManager_create, 1 , ENOMEM);
91+ void *scope{};
92+ topology_manager_t *tmPtr{};
93+ auto status = topologyManager_create (ctx.get (), logHelper.get (), &tmPtr, &scope);
94+ EXPECT_EQ (ENOMEM, status);
95+ unsetenv (" CELIX_RSA_IMPORTED_SERVICE_RANKING_OFFSETS" );
96+ }
97+
98+ TEST_F (TopologyManagerCreatingErrorInjectionTestSuite, CreatingImportedServiceMapErrorTest) {
99+ celix_ei_expect_celix_stringHashMap_createWithOptions ((void *)topologyManager_create, 0 , nullptr );
100+ void *scope{};
101+ topology_manager_t *tmPtr{};
102+ auto status = topologyManager_create (ctx.get (), logHelper.get (), &tmPtr, &scope);
103+ EXPECT_EQ (CELIX_ENOMEM, status);
104+ }
105+
63106TEST_F (TopologyManagerCreatingErrorInjectionTestSuite, CreatingMutexErrorTest) {
64107 celix_ei_expect_celixThreadMutex_create ((void *)topologyManager_create, 0 , CELIX_ENOMEM);
65108 void *scope{};
@@ -121,6 +164,12 @@ class TopologyManagerErrorInjectionTestSuite : public TopologyManagerTestSuiteBa
121164 celix_ei_expect_celix_properties_set (nullptr , 0 , 0 );
122165 celix_ei_expect_celix_utils_strdup (nullptr , 0 , nullptr );
123166 celix_ei_expect_celix_arrayList_add (nullptr , 0 , 0 );
167+ celix_ei_expect_celix_filter_create (nullptr , 0 , nullptr );
168+ celix_ei_expect_celix_properties_getAsStringArrayList (nullptr , 0 , 0 );
169+ celix_ei_expect_celix_properties_setLong (nullptr , 0 , 0 );
170+ celix_ei_expect_asprintf (nullptr , 0 , 0 );
171+ celix_ei_expect_celix_arrayList_createWithOptions (nullptr , 0 , nullptr );
172+ celix_ei_expect_celix_stringHashMap_put (nullptr , 0 , 0 );
124173 }
125174
126175 void TestExportServiceFailure (void (*errorInject)(void )) {
@@ -263,5 +312,118 @@ TEST_F(TopologyManagerErrorInjectionTestSuite, AddDynamicIpEndpointToListErrorTe
263312 });
264313}
265314
315+ TEST_F (TopologyManagerErrorInjectionTestSuite, CreatingFilterErrorWhenImportScopeChangedTest) {
316+ celix_ei_expect_celix_filter_create (CELIX_EI_UNKNOWN_CALLER, 0 , nullptr , 2 );
317+ auto status = tm_addImportScope (tms.get (), (char *)" (service.imported.configs=tm_test_config_type)" );
318+ EXPECT_EQ (CELIX_ILLEGAL_ARGUMENT, status);
319+ }
320+
321+ TEST_F (TopologyManagerErrorInjectionTestSuite, AllocingMemoryForImportedServiceEntryErrorTest) {
322+ TestImportService ([](topology_manager_t * tm, service_reference_pt, void *, endpoint_description_t *importEndpoint) {
323+ celix_ei_expect_calloc (CELIX_EI_UNKNOWN_CALLER, 0 , nullptr );
324+ auto status = topologyManager_addImportedService (tm, importEndpoint, nullptr );
325+ EXPECT_EQ (CELIX_ENOMEM, status);
326+
327+ status = topologyManager_removeImportedService (tm, importEndpoint, nullptr );
328+ EXPECT_EQ (CELIX_SUCCESS, status);
329+ });
330+ }
331+
332+ TEST_F (TopologyManagerErrorInjectionTestSuite, GettingServiceImportedConfigsErrorTest) {
333+ TestImportService ([](topology_manager_t * tm, service_reference_pt, void *, endpoint_description_t *importEndpoint) {
334+ celix_ei_expect_celix_properties_getAsStringArrayList (CELIX_EI_UNKNOWN_CALLER, 0 , ENOMEM);
335+ auto status = topologyManager_addImportedService (tm, importEndpoint, nullptr );
336+ EXPECT_EQ (ENOMEM, status);
337+
338+ celix_properties_unset (importEndpoint->properties , CELIX_RSA_SERVICE_IMPORTED_CONFIGS);
339+ status = topologyManager_addImportedService (tm, importEndpoint, nullptr );
340+ EXPECT_EQ (CELIX_ENOMEM, status);
341+ });
342+ }
343+
344+ TEST_F (TopologyManagerErrorInjectionTestSuite, CopyImportedServicePropertiesErrorTest) {
345+ TestImportService ([](topology_manager_t * tm, service_reference_pt, void *, endpoint_description_t *importEndpoint) {
346+ celix_ei_expect_celix_properties_copy (CELIX_EI_UNKNOWN_CALLER, 0 , nullptr );// called in endpointDescription_clone
347+ auto status = topologyManager_addImportedService (tm, importEndpoint, nullptr );
348+ EXPECT_EQ (ENOMEM, status);
349+ });
350+ }
351+
352+ TEST_F (TopologyManagerErrorInjectionTestSuite, SettingImportedServiceRankingErrorTest) {
353+ setenv (" CELIX_RSA_IMPORTED_SERVICE_RANKING_OFFSETS" , " tm_test_config_type=10" , 1 );
354+ tm.reset ();
355+ void * scope = nullptr ;
356+ topology_manager_t * tmPtr{};
357+ auto status = topologyManager_create (ctx.get (), logHelper.get (), &tmPtr, &scope);
358+ EXPECT_EQ (status, CELIX_SUCCESS);
359+ tm = std::shared_ptr<topology_manager_t >{tmPtr, [](auto t) {topologyManager_destroy (t);}};
360+
361+ TestImportService ([](topology_manager_t * tm, service_reference_pt, void *, endpoint_description_t *importEndpoint) {
362+ celix_ei_expect_celix_properties_setLong (CELIX_EI_UNKNOWN_CALLER, 0 , ENOMEM);// called in endpointDescription_clone
363+ auto status = topologyManager_addImportedService (tm, importEndpoint, nullptr );
364+ EXPECT_EQ (ENOMEM, status);
365+ });
366+
367+ unsetenv (" CELIX_RSA_IMPORTED_SERVICE_RANKING_OFFSETS" );
368+ }
369+
370+
371+ TEST_F (TopologyManagerErrorInjectionTestSuite, CreatingImportsMapFailureTest) {
372+ TestImportService ([](topology_manager_t * tm, service_reference_pt, void *, endpoint_description_t *importEndpoint) {
373+ celix_ei_expect_celix_longHashMap_create (CELIX_EI_UNKNOWN_CALLER, 0 , nullptr );
374+ auto status = topologyManager_addImportedService (tm, importEndpoint, nullptr );
375+ EXPECT_EQ (ENOMEM, status);
376+
377+ status = topologyManager_removeImportedService (tm, importEndpoint, nullptr );
378+ EXPECT_EQ (CELIX_SUCCESS, status);
379+ });
380+ }
381+
382+ TEST_F (TopologyManagerErrorInjectionTestSuite, AddingImportedServiceToMapFailureTest) {
383+ TestImportService ([](topology_manager_t * tm, service_reference_pt, void *, endpoint_description_t *importEndpoint) {
384+ celix_ei_expect_celix_stringHashMap_put (CELIX_EI_UNKNOWN_CALLER, 0 , ENOMEM);
385+ auto status = topologyManager_addImportedService (tm, importEndpoint, nullptr );
386+ EXPECT_EQ (ENOMEM, status);
387+
388+ status = topologyManager_removeImportedService (tm, importEndpoint, nullptr );
389+ EXPECT_EQ (CELIX_SUCCESS, status);
390+ });
391+ }
392+
393+ TEST_F (TopologyManagerErrorInjectionTestSuite, AddingImportedRegistrationToMapFailureTest) {
394+ TestImportService ([this ](topology_manager_t * tm, service_reference_pt rsaSvcRef, void * rsaSvc, endpoint_description_t *importEndpoint) {
395+ auto status = topologyManager_rsaAdded (tm, rsaSvcRef, rsaSvc);
396+ EXPECT_EQ (CELIX_SUCCESS, status);
397+ celix_ei_expect_celix_longHashMap_put (CELIX_EI_UNKNOWN_CALLER, 0 , ENOMEM);
398+ status = topologyManager_addImportedService (tm, importEndpoint, nullptr );
399+ EXPECT_EQ (CELIX_SUCCESS, status);
400+ celix_service_filter_options_t opts{};
401+ opts.filter = (char *)" (service.imported.configs=tm_test_config_type)" ;
402+ auto svcId = celix_bundleContext_findServiceWithOptions (ctx.get (), &opts);
403+ EXPECT_EQ (svcId, -1 );
404+
405+ status = topologyManager_removeImportedService (tm, importEndpoint, nullptr );
406+ EXPECT_EQ (CELIX_SUCCESS, status);
407+ status = topologyManager_rsaRemoved (tm, rsaSvcRef, rsaSvc);
408+ EXPECT_EQ (CELIX_SUCCESS, status);
409+ });
410+ }
266411
412+ TEST_F (TopologyManagerErrorInjectionTestSuite, AddingImportedRegistrationToMapFailureWhenAddRsaTest) {
413+ TestImportService ([this ](topology_manager_t * tm, service_reference_pt rsaSvcRef, void * rsaSvc, endpoint_description_t *importEndpoint) {
414+ auto status = topologyManager_addImportedService (tm, importEndpoint, nullptr );
415+ EXPECT_EQ (CELIX_SUCCESS, status);
416+ celix_ei_expect_celix_longHashMap_put (CELIX_EI_UNKNOWN_CALLER, 0 , ENOMEM, 2 );
417+ status = topologyManager_rsaAdded (tm, rsaSvcRef, rsaSvc);
418+ EXPECT_EQ (CELIX_SUCCESS, status);
419+ celix_service_filter_options_t opts{};
420+ opts.filter = (char *)" (service.imported.configs=tm_test_config_type)" ;
421+ auto svcId = celix_bundleContext_findServiceWithOptions (ctx.get (), &opts);
422+ EXPECT_EQ (svcId, -1 );
267423
424+ status = topologyManager_rsaRemoved (tm, rsaSvcRef, rsaSvc);
425+ EXPECT_EQ (CELIX_SUCCESS, status);
426+ status = topologyManager_removeImportedService (tm, importEndpoint, nullptr );
427+ EXPECT_EQ (CELIX_SUCCESS, status);
428+ });
429+ }
0 commit comments