Quellcode durchsuchen

[test] Update snprintf_ok() to use okx()

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown vor 8 Jahren
Ursprung
Commit
320488d0f9
1 geänderte Dateien mit 25 neuen und 14 gelöschten Zeilen
  1. 25
    14
      src/tests/vsprintf_test.c

+ 25
- 14
src/tests/vsprintf_test.c Datei anzeigen

@@ -39,21 +39,32 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
39 39
 /**
40 40
  * Report an snprintf() test result
41 41
  *
42
+ * @v len		Buffer length
43
+ * @v expected		Expected result
44
+ * @v file		Test code file
45
+ * @v line		Test code line
46
+ * @v format		Format string
47
+ * @v ...		Arguments
42 48
  */
43
-#define snprintf_ok( len, result, format, ... ) do {			\
44
-	char actual[ (len) ];						\
45
-	const char expected[] = result;					\
46
-	size_t actual_len;						\
47
-									\
48
-	actual_len = snprintf ( actual, sizeof ( actual ),		\
49
-				format, ##__VA_ARGS__ );		\
50
-	ok ( actual_len >= strlen ( result ) );				\
51
-	ok ( strcmp ( actual, expected ) == 0 );			\
52
-	if ( strcmp ( actual, expected ) != 0 ) {			\
53
-		DBG ( "SNPRINTF expected \"%s\", got \"%s\"\n",		\
54
-		      expected, actual );				\
55
-	}								\
56
-	} while ( 0 )
49
+static void snprintf_okx ( size_t len, const char *expected, const char *file,
50
+			   unsigned int line, const char *fmt, ... ) {
51
+	char actual[len];
52
+	size_t actual_len;
53
+	va_list args;
54
+
55
+	va_start ( args, fmt );
56
+	actual_len = vsnprintf ( actual, sizeof ( actual ), fmt, args );
57
+	va_end ( args );
58
+	okx ( actual_len >= strlen ( expected ), file, line );
59
+	okx ( strcmp ( actual, expected ) == 0, file, line );
60
+	if ( strcmp ( actual, expected ) != 0 ) {
61
+		DBG ( "SNPRINTF expected \"%s\", got \"%s\"\n",
62
+		      expected, actual );
63
+	}
64
+}
65
+#define snprintf_ok( len, result, format, ... )				\
66
+	snprintf_okx ( len, result, __FILE__, __LINE__, format,		\
67
+		       ##__VA_ARGS__ )
57 68
 
58 69
 /**
59 70
  * Perform vsprintf() self-tests

Laden…
Abbrechen
Speichern