@@ -626,6 +626,29 @@ TEST_F(protocolTestFixture, CURLINTERFACE_STATIC_SetHeader_setopt_failure)
626626 EXPECT_EQ (resp.curlSetopCode , CURLE_FAILED_INIT);
627627}
628628
629+ TEST_F (protocolTestFixture, CURLINTERFACE_STATIC_SetHeader_FirstSetopt_failure_lineNumber)
630+ {
631+ SetHeaderFunc setHeaderCb = getSetHeaderCallback ();
632+ ASSERT_NE (setHeaderCb, nullptr );
633+
634+ CURL *curl = (CURL*)0x1 ;
635+ const char *destURL = " http://localhost" ;
636+ struct curl_slist *headerList = nullptr ;
637+ childResponse resp;
638+ memset (&resp, 0 , sizeof (resp));
639+
640+ // The very first curl_easy_setopt_mock call returns CURLE_FAILED_INIT.
641+ EXPECT_CALL (*g_fileIOMock, curl_easy_setopt_mock (_,_,_))
642+ .Times (1 )
643+ .WillOnce (Return (CURLE_FAILED_INIT));
644+
645+ T2ERROR code = setHeaderCb (curl, destURL, &headerList, &resp);
646+ EXPECT_EQ (code, T2ERROR_FAILURE);
647+ EXPECT_EQ (resp.curlSetopCode , CURLE_FAILED_INIT);
648+ // Assert that lineNumber field gets set. (Should match the __LINE__ where the macro is expanded; we test it's nonzero.)
649+ EXPECT_NE (resp.lineNumber , 0 );
650+ }
651+
629652TEST_F (protocolTestFixture, CURLINTERFACE_STATIC_SetMtlsHeaders_setopt_failure)
630653{
631654 SetMtlsHeadersFunc cb = getSetMtlsHeadersCallback ();
@@ -764,6 +787,40 @@ TEST_F(protocolTestFixture, CURLINTERFACE_STATIC_SetHeader_HTTPHEADER_failure)
764787 EXPECT_EQ (resp.curlSetopCode , CURLE_COULDNT_CONNECT);
765788}
766789
790+ TEST_F (protocolTestFixture, CURLINTERFACE_STATIC_SetHeader_HTTPHEADER_failure_block)
791+ {
792+ SetHeaderFunc setHeaderCb = getSetHeaderCallback ();
793+ ASSERT_NE (setHeaderCb, nullptr );
794+
795+ CURL *curl = (CURL*)0x1 ;
796+ const char *destURL = " http://localhost" ;
797+ struct curl_slist *headerList = nullptr ;
798+ childResponse resp;
799+ memset (&resp, 0 , sizeof (resp));
800+
801+ // Simulate curl_slist_append returns
802+ EXPECT_CALL (*g_fileIOMock, curl_slist_append (_, _))
803+ .Times (2 )
804+ .WillRepeatedly (Return ((struct curl_slist *)0x1 ));
805+
806+ // Mock all prior curl_easy_setopt calls to return OK, only HTTPHEADER fails
807+ ::testing::Sequence s;
808+ EXPECT_CALL (*g_fileIOMock, curl_easy_setopt_mock (_, ::testing::Ne (CURLOPT_HTTPHEADER), _))
809+ .Times (::testing::AtLeast (1 ))
810+ .InSequence (s)
811+ .WillRepeatedly (Return (CURLE_OK));
812+ EXPECT_CALL (*g_fileIOMock, curl_easy_setopt_mock (_, CURLOPT_HTTPHEADER, _))
813+ .InSequence (s)
814+ .WillOnce (Return (CURLE_COULDNT_CONNECT)); // Simulate failure at HTTPHEADER
815+
816+ T2ERROR result = setHeaderCb (curl, destURL, &headerList, &resp);
817+
818+ EXPECT_EQ (result, T2ERROR_FAILURE);
819+ EXPECT_EQ (resp.curlSetopCode , CURLE_COULDNT_CONNECT);
820+ // Should be set to a non-zero line number corresponding to line 166 in your source
821+ EXPECT_NE (resp.lineNumber , 0 );
822+ }
823+
767824TEST_F (protocolTestFixture, CURLINTERFACE_STATIC_SetHeader_WRITEFUNCTION_failure)
768825{
769826 SetHeaderFunc setHeaderCb = getSetHeaderCallback ();
@@ -958,3 +1015,51 @@ TEST_F(protocolTestFixture, CURLINTERFACE_STATIC_SetHeader_SUCCESS)
9581015 EXPECT_NE (headerList, nullptr );
9591016}
9601017#endif
1018+
1019+ #ifdef GTEST_ENABLE
1020+ extern " C" {
1021+ pthread_mutex_t * getRbusMethodMutex (void );
1022+ pthread_mutex_t * getCurlFileMutex (void );
1023+ typedef void (*sendOverHTTPInitFunc)();
1024+ sendOverHTTPInitFunc sendOverHTTPInitFuncCallback ();
1025+
1026+ typedef void (*asyncMethodHandlerFunc)(rbusHandle_t,char const *,rbusError_t,rbusObject_t);
1027+ asyncMethodHandlerFunc asyncMethodHandlerFuncCallback (void );
1028+ }
1029+
1030+ TEST (CurlInterface_Static, SendOverHTTPInit_CoversMutexInit)
1031+ {
1032+ // Get function pointer to static sendOverHTTPInit
1033+ auto fn = sendOverHTTPInitFuncCallback ();
1034+ ASSERT_NE (fn, nullptr );
1035+ fn ();
1036+ // Check that the mutex is initialized (trylock succeeds or returns expected error if already locked)
1037+ pthread_mutex_t *pmutex = getCurlFileMutex ();
1038+ int trylock_result = pthread_mutex_trylock (pmutex);
1039+ // Accept either success (0) or busy (EBUSY) as initialized.
1040+ EXPECT_TRUE (trylock_result == 0 || trylock_result == EBUSY);
1041+
1042+ if (trylock_result == 0 ) { // If locked, unlock for cleanup
1043+ pthread_mutex_unlock (pmutex);
1044+ }
1045+
1046+ pthread_mutex_destroy (pmutex);
1047+ }
1048+ TEST (AsyncMethodHandlerFunc, CoversAllBranches)
1049+ {
1050+ // Access and initialize the mutex defined in the C module
1051+ pthread_mutex_t * pmutex = getRbusMethodMutex ();
1052+ pthread_mutex_init (pmutex, NULL );
1053+
1054+ // Get function pointer for static asyncMethodHandler
1055+ auto fn = asyncMethodHandlerFuncCallback ();
1056+ ASSERT_NE (fn, nullptr );
1057+
1058+ // Success branch: sets isRbusMethod = true and unlocks
1059+ fn (NULL , " TestMethodSuccess" , RBUS_ERROR_SUCCESS, NULL );
1060+ // Error branch: sets isRbusMethod = false and unlocks
1061+ fn (NULL , " TestMethodFail" , RBUS_ERROR_BUS_ERROR, NULL );
1062+
1063+ pthread_mutex_destroy (pmutex);
1064+ }
1065+ #endif
0 commit comments