8 void test_main( void );
9 int basic_good( void );
10 int embedded_nul( void );
11 int trailing_space( void );
13 extern size_t remoteconfig_cmdlength(const char *, const char *);
15 static int verbose = 1; // if not 0, also print results if test passed
16 static int exit_on_err = 0; // if not 0, exit if test failed
30 * Test function calling the remote config buffer checker
31 * http://bugs.ntp.org/show_bug.cgi?id=2853
33 * size_t remoteconfig_cmdlength(const char *src_buf, const char *src_end)
34 * - trims whitespace & garbage from the right
35 * then looks for only \tSP-\127 starting from the left.
36 * It returns the number of "good" characters it found.
40 void test_main( void )
42 TEST_ASSERT_EQUAL(0, basic_good());
43 TEST_ASSERT_EQUAL(0, embedded_nul());
44 TEST_ASSERT_EQUAL(0, trailing_space());
48 int basic_good( void )
50 const char string[] = "good";
56 EOstring = string + sizeof string;
58 len = remoteconfig_cmdlength(string, EOstring);
60 failed = ( 4 != len );
62 if ( failed || verbose )
63 printf( "remoteconfig_cmdlength(\"%s\") returned %d, expected %d: %s\n",
67 failed ? "NO <<" : "yes" );
69 return failed ? -1 : 0;
73 int embedded_nul( void )
75 const char string[] = "nul\0 there";
81 EOstring = string + sizeof string;
83 len = remoteconfig_cmdlength(string, EOstring);
85 failed = ( 3 != len );
87 if ( failed || verbose )
88 printf( "remoteconfig_cmdlength(\"%s\") returned %d, expected %d: %s\n",
92 failed ? "NO <<" : "yes" );
94 return failed ? -1 : 0;
98 int trailing_space( void )
100 const char string[] = "trailing space ";
101 const char *EOstring;
106 EOstring = string + sizeof string;
108 len = remoteconfig_cmdlength(string, EOstring);
110 failed = ( 14 != len );
112 if ( failed || verbose )
113 printf( "remoteconfig_cmdlength(\"%s\") returned %d, expected %d: %s\n",
117 failed ? "NO <<" : "yes" );
119 return failed ? -1 : 0;