1717#include " test/mocks/rdkconfigMock.h"
1818#include " test/mocks/VectorMock.h"
1919#include " test/bulkdata/SchedulerMock.h"
20+ #include " test/bulkdata/profileMock.h"
2021
2122using namespace std ;
2223
@@ -34,6 +35,8 @@ extern "C" {
3435#include " profilexconf.h"
3536#include " t2eventreceiver.h"
3637#include " msgpack.h"
38+ #include < glib.h>
39+ #include < glib/gi18n.h>
3740
3841extern bool initialized;
3942
@@ -46,6 +49,7 @@ SystemMock * g_systemMock = NULL;
4649rdklogMock *m_rdklogMock = NULL ;
4750rbusMock *g_rbusMock = NULL ;
4851rdkconfigMock *g_rdkconfigMock = nullptr ;
52+ profileMock *g_profileMock = nullptr ;
4953extern VectorMock *g_vectorMock;
5054extern SchedulerMock *g_schedulerMock;
5155
@@ -59,6 +63,7 @@ class ProfileTest : public ::testing::Test {
5963 g_rdkconfigMock = new rdkconfigMock ();
6064 g_vectorMock = new VectorMock ();
6165 g_schedulerMock = new SchedulerMock ();
66+ g_profileMock = new profileMock ();
6267 }
6368 void TearDown () override
6469 {
@@ -68,13 +73,15 @@ class ProfileTest : public ::testing::Test {
6873 delete g_rdkconfigMock;
6974 delete g_vectorMock;
7075 delete g_schedulerMock;
76+ delete g_profileMock;
7177
7278 g_fileIOMock = nullptr ;
7379 g_systemMock = nullptr ;
7480 g_rbusMock = nullptr ;
7581 g_rdkconfigMock = nullptr ;
7682 g_vectorMock = nullptr ;
7783 g_schedulerMock = nullptr ;
84+ g_profileMock = nullptr ;
7885 }
7986};
8087
@@ -859,12 +866,81 @@ TEST_F(ProfileTest, deleteAllReportProfiles) {
859866 EXPECT_EQ (deleteAllReportProfiles (), T2ERROR_SUCCESS);
860867}
861868
869+ #ifdef GTEST_ENABLE
870+ extern " C" {
871+ typedef void * (*reportOnDemandFunc)(void *);
872+ reportOnDemandFunc reportOnDemandFuncCallback (void );
873+ typedef void (*freeProfilesHashMapFunc)(void *);
874+ freeProfilesHashMapFunc freeProfilesHashMapFuncCallback (void );
875+ typedef void (*freeReportProfileHashMapFunc)(void *);
876+ freeReportProfileHashMapFunc freeReportProfileHashMapFuncCallback (void );
877+ typedef void (*__msgpack_free_blobFunc)(void *);
878+ __msgpack_free_blobFunc __msgpack_free_blobFuncCallback (void );
879+ }
880+
881+ TEST (ReportProfilesCallbacks, FreeProfilesHashMap) {
882+ auto cb = freeProfilesHashMapFuncCallback ();
883+ ASSERT_NE (cb, nullptr );
884+
885+ // Test with an actual element
886+ hash_element_t * item = (hash_element_t *) std::malloc (sizeof (hash_element_t ));
887+ item->key = (char *) std::malloc (12 );
888+ std::strcpy (item->key , " testkey" );
889+ item->data = std::malloc (8 );
890+ cb (item);
891+
892+ // Test with nullptr
893+ cb (nullptr );
894+ }
895+ TEST_F (ProfileTest, reportOnDemandTest)
896+ {
897+ reportOnDemandFunc func = reportOnDemandFuncCallback ();
898+ ASSERT_NE (func,nullptr );
899+ func ((void *)" ABORT" );
900+ func ((void *)" FOO" );
901+ func (nullptr );
902+ }
903+
904+ TEST (ReportProfilesCallbacks, FreeReportProfileHashMap) {
905+ auto cb = freeReportProfileHashMapFuncCallback ();
906+ ASSERT_NE (cb, nullptr );
907+
908+ // Make an item with ReportProfile-like .data
909+ hash_element_t * item = (hash_element_t *) std::malloc (sizeof (hash_element_t ));
910+ item->key = (char *) std::malloc (12 );
911+ std::strcpy (item->key , " profkey" );
912+ struct ReportProfile {
913+ char * hash;
914+ char * config;
915+ void * hash_map_pad; // just to align with how your system might fill it, can be omitted
916+ };
917+ ReportProfile* rp = (ReportProfile*) std::malloc (sizeof (ReportProfile));
918+ rp->hash = (char *) std::malloc (6 );
919+ std::strcpy (rp->hash , " hashV" );
920+ rp->config = (char *) std::malloc (8 );
921+ std::strcpy (rp->config , " cfgVal" );
922+ item->data = rp;
923+
924+ cb (item);
925+
926+ // Safe to call with nullptr
927+ cb (nullptr );
928+ SUCCEED ();
929+ }
930+ #endif
862931#endif
863932
864933#if 1
865934// comment
866935// =================================== profilexconf.c ================================
867936
937+
938+ #ifdef GTEST_ENABLE
939+ extern " C" {
940+ void test_set_reportThreadExits (bool value);
941+ }
942+ #endif
943+
868944TEST_F (ProfileTest, InitAndUninit) {
869945 // Covers ProfileXConf_init and ProfileXConf_uninit
870946#if 1
@@ -909,11 +985,21 @@ TEST_F(ProfileTest, SetAndIsSet) {
909985 profile->cachedReportList = nullptr ;
910986 profile->protocol = strdup (" HTTP" );
911987 profile->encodingType = strdup (" JSON" );
912- profile->t2HTTPDest = nullptr ;
913- profile->grepSeekProfile = nullptr ;
988+ profile->jsonReportObj = nullptr ; // types now match
989+ profile->checkPreviousSeek = true ;
990+
991+ profile->t2HTTPDest = (T2HTTP *)malloc (sizeof (T2HTTP));
992+ profile->t2HTTPDest ->URL = strdup (" https://mock1xconf:50051/dataLakeMockXconf" );
993+ profile->isUpdated = true ;
994+ GrepSeekProfile *gsProfile = (GrepSeekProfile *)malloc (sizeof (GrepSeekProfile));
995+ if (gsProfile)
996+ {
997+ gsProfile->logFileSeekMap = hash_map_create ();
998+ gsProfile->execCounter = 0 ;
999+ }
1000+ profile->grepSeekProfile = gsProfile;
1001+ // profile->grepSeekProfile = nullptr;
9141002 profile->reportInProgress = false ;
915- profile->isUpdated = false ;
916-
9171003 EXPECT_CALL (*g_vectorMock, Vector_Size (_))
9181004 .Times (::testing::AtMost (3 ))
9191005 .WillRepeatedly (Return (0 )); // Return 1 to indicate one profile in the list
@@ -926,26 +1012,29 @@ TEST_F(ProfileTest, SetAndIsSet) {
9261012 EXPECT_CALL (*g_vectorMock, Vector_PushBack (_, _))
9271013 .Times (::testing::AtMost (3 ))
9281014 .WillRepeatedly (Return (T2ERROR_SUCCESS));
929-
1015+
9301016 // Scheduler mock expectations - ProfileXConf_set calls registerProfileWithScheduler
9311017 EXPECT_CALL (*g_schedulerMock, registerProfileWithScheduler (_, _, _, _, _, _, _, _))
9321018 .Times (::testing::AtMost (1 ))
9331019 .WillRepeatedly (Return (T2ERROR_SUCCESS));
934-
1020+
9351021 EXPECT_EQ (ProfileXConf_set (profile), T2ERROR_SUCCESS);
9361022 EXPECT_TRUE (ProfileXConf_isSet ());
9371023
1024+
9381025 // Get name
9391026 char * name = ProfileXconf_getName ();
9401027 ASSERT_NE (name, nullptr );
9411028 EXPECT_STREQ (name, " TestProfile" );
9421029 free (name);
9431030
944- // Clean up - ProfileXConf_uninit calls unregisterProfileFromScheduler
945- EXPECT_CALL (*g_schedulerMock, unregisterProfileFromScheduler (_))
946- .Times (::testing::AtMost (1 ))
947- .WillRepeatedly (Return (T2ERROR_SUCCESS));
948-
1031+ test_set_reportThreadExits (true );
1032+ generateDcaReport (false ,true );
1033+ EXPECT_CALL (*g_schedulerMock, SendInterruptToTimeoutThread (_))
1034+ .Times (::testing::AtMost (1 ));
1035+
1036+ ReportProfiles_Interrupt ();
1037+
9491038 EXPECT_EQ (ProfileXConf_uninit (), T2ERROR_SUCCESS);
9501039}
9511040
0 commit comments