@@ -859,6 +859,68 @@ TEST_F(ProfileTest, deleteAllReportProfiles) {
859859 EXPECT_EQ (deleteAllReportProfiles (), T2ERROR_SUCCESS);
860860}
861861
862+ #ifdef GTEST_ENABLE
863+ extern " C" {
864+ typedef void * (*reportOnDemandFunc)(void *);
865+ reportOnDemandFunc reportOnDemandFuncCallback (void );
866+ typedef void (*freeProfilesHashMapFunc)(void *);
867+ freeProfilesHashMapFunc freeProfilesHashMapFuncCallback (void );
868+ typedef void (*freeReportProfileHashMapFunc)(void *);
869+ freeReportProfileHashMapFunc freeReportProfileHashMapFuncCallback (void );
870+ typedef void (*__msgpack_free_blobFunc)(void *);
871+ __msgpack_free_blobFunc __msgpack_free_blobFuncCallback (void );
872+ }
873+
874+ TEST (ReportProfilesCallbacks, FreeProfilesHashMap) {
875+ auto cb = freeProfilesHashMapFuncCallback ();
876+ ASSERT_NE (cb, nullptr );
877+
878+ // Test with an actual element
879+ hash_element_t * item = (hash_element_t *) std::malloc (sizeof (hash_element_t ));
880+ item->key = (char *) std::malloc (12 );
881+ std::strcpy (item->key , " testkey" );
882+ item->data = std::malloc (8 );
883+ cb (item);
884+
885+ // Test with nullptr
886+ cb (nullptr );
887+ }
888+ TEST_F (ProfileTest, reportOnDemandTest)
889+ {
890+ reportOnDemandFunc func = reportOnDemandFuncCallback ();
891+ ASSERT_NE (func,nullptr );
892+ func ((void *)" ABORT" );
893+ func ((void *)" FOO" );
894+ func (nullptr );
895+ }
896+
897+ TEST (ReportProfilesCallbacks, FreeReportProfileHashMap) {
898+ auto cb = freeReportProfileHashMapFuncCallback ();
899+ ASSERT_NE (cb, nullptr );
900+
901+ // Make an item with ReportProfile-like .data
902+ hash_element_t * item = (hash_element_t *) std::malloc (sizeof (hash_element_t ));
903+ item->key = (char *) std::malloc (12 );
904+ std::strcpy (item->key , " profkey" );
905+ struct ReportProfile {
906+ char * hash;
907+ char * config;
908+ void * hash_map_pad; // just to align with how your system might fill it, can be omitted
909+ };
910+ ReportProfile* rp = (ReportProfile*) std::malloc (sizeof (ReportProfile));
911+ rp->hash = (char *) std::malloc (6 );
912+ std::strcpy (rp->hash , " hashV" );
913+ rp->config = (char *) std::malloc (8 );
914+ std::strcpy (rp->config , " cfgVal" );
915+ item->data = rp;
916+
917+ cb (item);
918+
919+ // Safe to call with nullptr
920+ cb (nullptr );
921+ SUCCEED ();
922+ }
923+ #endif
862924#endif
863925
864926#if 1
@@ -909,11 +971,21 @@ TEST_F(ProfileTest, SetAndIsSet) {
909971 profile->cachedReportList = nullptr ;
910972 profile->protocol = strdup (" HTTP" );
911973 profile->encodingType = strdup (" JSON" );
912- profile->t2HTTPDest = nullptr ;
913- profile->grepSeekProfile = nullptr ;
974+ profile->jsonReportObj = nullptr ; // types now match
975+ profile->checkPreviousSeek = true ;
976+
977+ profile->t2HTTPDest = (T2HTTP *)malloc (sizeof (T2HTTP));
978+ profile->t2HTTPDest ->URL = strdup (" https://mock1xconf:50051/dataLakeMockXconf" );
979+ profile->isUpdated = true ;
980+ GrepSeekProfile *gsProfile = (GrepSeekProfile *)malloc (sizeof (GrepSeekProfile));
981+ if (gsProfile)
982+ {
983+ gsProfile->logFileSeekMap = hash_map_create ();
984+ gsProfile->execCounter = 0 ;
985+ }
986+ profile->grepSeekProfile = gsProfile;
987+ // profile->grepSeekProfile = nullptr;
914988 profile->reportInProgress = false ;
915- profile->isUpdated = false ;
916-
917989 EXPECT_CALL (*g_vectorMock, Vector_Size (_))
918990 .Times (::testing::AtMost (3 ))
919991 .WillRepeatedly (Return (0 )); // Return 1 to indicate one profile in the list
@@ -926,26 +998,29 @@ TEST_F(ProfileTest, SetAndIsSet) {
926998 EXPECT_CALL (*g_vectorMock, Vector_PushBack (_, _))
927999 .Times (::testing::AtMost (3 ))
9281000 .WillRepeatedly (Return (T2ERROR_SUCCESS));
929-
1001+
9301002 // Scheduler mock expectations - ProfileXConf_set calls registerProfileWithScheduler
9311003 EXPECT_CALL (*g_schedulerMock, registerProfileWithScheduler (_, _, _, _, _, _, _, _))
9321004 .Times (::testing::AtMost (1 ))
9331005 .WillRepeatedly (Return (T2ERROR_SUCCESS));
934-
1006+
9351007 EXPECT_EQ (ProfileXConf_set (profile), T2ERROR_SUCCESS);
9361008 EXPECT_TRUE (ProfileXConf_isSet ());
9371009
1010+
9381011 // Get name
9391012 char * name = ProfileXconf_getName ();
9401013 ASSERT_NE (name, nullptr );
9411014 EXPECT_STREQ (name, " TestProfile" );
9421015 free (name);
9431016
944- // Clean up - ProfileXConf_uninit calls unregisterProfileFromScheduler
945- EXPECT_CALL (*g_schedulerMock, unregisterProfileFromScheduler (_))
946- .Times (::testing::AtMost (1 ))
947- .WillRepeatedly (Return (T2ERROR_SUCCESS));
948-
1017+ test_set_reportThreadExits (true );
1018+ generateDcaReport (false ,true );
1019+ EXPECT_CALL (*g_schedulerMock, SendInterruptToTimeoutThread (_))
1020+ .Times (::testing::AtMost (1 ));
1021+
1022+ ReportProfiles_Interrupt ();
1023+
9491024 EXPECT_EQ (ProfileXConf_uninit (), T2ERROR_SUCCESS);
9501025}
9511026
0 commit comments