@@ -77,56 +77,60 @@ - (void)testHexToStringWithNonPrintableCharacters {
7777 XCTAssertEqualObjects ([NSString stringWithUTF8String: string], @" 52d04e1f" , @" " );
7878}
7979
80- - (void )testRedactUUIDWithExpectedPattern {
81- const char * readonly = " CoreSimulator 704.12.1 - Device: iPhone SE (2nd generation) "
82- " (45D62CC2-CFB5-4E33-AB61-B0684627F1B6) - Runtime: iOS 13.4 (17E8260) - "
83- " DeviceType: iPhone SE (2nd generation)" ;
84- size_t len = strlen (readonly);
85- char message[len];
86- strcpy (message, readonly);
87-
88- FIRCLSRedactUUID (message);
89-
90- NSString * actual = [NSString stringWithUTF8String: message];
91- NSString * expected = @" CoreSimulator 704.12.1 - Device: iPhone SE (2nd generation) "
92- @" (********-****-****-****-************) - Runtime: iOS 13.4 (17E8260) - "
93- @" DeviceType: iPhone SE (2nd generation)" ;
94-
95- XCTAssertEqualObjects (actual, expected);
96- }
97-
98- - (void )testRedactUUIDWithMalformedPattern {
99- const char * readonly = " CoreSimulator 704.12.1 - Device: iPhone SE (2nd generation) "
100- " (45D62CC2-CFB5-4E33-AB61-B0684627F1B6" ;
101- size_t len = strlen (readonly);
102- char message[len];
103- strcpy (message, readonly);
104-
105- FIRCLSRedactUUID (message);
106-
107- NSString * actual = [NSString stringWithUTF8String: message];
108- NSString * expected = @" CoreSimulator 704.12.1 - Device: iPhone SE (2nd generation) "
109- @" (45D62CC2-CFB5-4E33-AB61-B0684627F1B6" ;
110-
111- XCTAssertEqualObjects (actual, expected);
112- }
113-
114- - (void )testRedactUUIDWithoutUUID {
115- const char * readonly = " Fatal error: file /Users/test/src/foo/bar/ViewController.swift, line 25" ;
116- size_t len = strlen (readonly);
117- char message[len];
118- strcpy (message, readonly);
119-
120- FIRCLSRedactUUID (message);
121-
122- NSString * actual = [NSString stringWithUTF8String: message];
123- NSString * expected = @" Fatal error: file /Users/test/src/foo/bar/ViewController.swift, line 25" ;
124-
125- XCTAssertEqualObjects (actual, expected);
126- }
127-
128- - (void )testRedactUUIDWithNull {
129- char * message = NULL ;
130- XCTAssertNoThrow (FIRCLSRedactUUID (message));
80+ - (void )testRedactUUID {
81+ // Define a local struct to hold the test data
82+ struct TestCase {
83+ const char *name; // Name of the test case
84+ const char *readonly; // Input string
85+ const char *expected; // Expected output string
86+ };
87+
88+ // Initialize an array of test cases
89+ struct TestCase tests[] = {
90+ {.name = " Test with valid UUID" ,
91+ .readonly = " CoreSimulator 704.12.1 - Device: iPhone SE (2nd generation) "
92+ " (45D62CC2-CFB5-4E33-AB61-B0684627F1B6) - Runtime: iOS 13.4 (17E8260) - "
93+ " DeviceType: iPhone SE (2nd generation)" ,
94+ .expected = " CoreSimulator 704.12.1 - Device: iPhone SE (2nd generation) "
95+ " (********-****-****-****-************) - Runtime: iOS 13.4 (17E8260) - "
96+ " DeviceType: iPhone SE (2nd generation)" },
97+ {.name = " Test with no UUID" ,
98+ .readonly = " Example with no UUID" ,
99+ .expected = " Example with no UUID" },
100+ {.name = " Test with only UUID" ,
101+ .readonly = " (12345678-1234-1234-1234-123456789012)" ,
102+ .expected = " (********-****-****-****-************)" },
103+ {.name = " Test with malformed UUID pattern" ,
104+ .readonly = " CoreSimulator 704.12.1 - Device: iPhone SE (2nd generation) "
105+ " (45D62CC2-CFB5-4E33-AB61-B0684627F1B6" ,
106+ .expected = " CoreSimulator 704.12.1 - Device: iPhone SE (2nd generation) "
107+ " (45D62CC2-CFB5-4E33-AB61-B0684627F1B6" },
108+ {.name = " Test with other error string" ,
109+ .readonly = " Fatal error: file "
110+ " /Users/test/src/foo/bar/ViewController.swift, line 25" ,
111+ .expected = " Fatal error: file "
112+ " /Users/test/src/foo/bar/ViewController.swift, line 25" },
113+ {.name = " Test with NULL input" , .readonly = NULL , .expected = NULL }};
114+
115+ // Loop over the array of test cases
116+ for (size_t i = 0 ; i < sizeof (tests) / sizeof (tests[0 ]); i++) {
117+ if (tests[i].readonly == NULL ) {
118+ XCTAssertNoThrow (FIRCLSRedactUUID (NULL ));
119+ continue ;
120+ }
121+
122+ // copy the message because the function modifies the input
123+ // and the input is const
124+ char message[256 ];
125+ snprintf (message, sizeof (message), " %s " , tests[i].readonly );
126+
127+ // Redact the UUID
128+ FIRCLSRedactUUID (message);
129+
130+ // Compare the result with the expected output
131+ NSString *actual = [NSString stringWithUTF8String: message];
132+ NSString *expected = [NSString stringWithUTF8String: tests[i].expected];
133+ XCTAssertEqualObjects (actual, expected, @" Test named: '%s ' failed" , tests[i].name );
134+ }
131135}
132136@end
0 commit comments