3 #include <rc_cmdlength.h>
10 void test_main( void );
11 int basic_good( void );
12 int embedded_nul( void );
13 int trailing_space( void );
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";
55 EOstring = string + sizeof string;
57 len = remoteconfig_cmdlength(string, EOstring);
59 failed = ( 4 != len );
61 if ( failed || verbose )
62 printf( "remoteconfig_cmdlength(\"%s\") returned %llu, expected %u: %s\n",
64 (unsigned long long)len,
66 failed ? "NO <<" : "yes" );
68 return failed ? -1 : 0;
72 int embedded_nul( void )
74 const char string[] = "nul\0 there";
79 EOstring = string + sizeof string;
81 len = remoteconfig_cmdlength(string, EOstring);
83 failed = ( 3 != len );
85 if ( failed || verbose )
86 printf( "remoteconfig_cmdlength(\"%s\") returned %llu, expected %u: %s\n",
88 (unsigned long long)len,
90 failed ? "NO <<" : "yes" );
92 return failed ? -1 : 0;
96 int trailing_space( void )
98 const char string[] = "trailing space ";
103 EOstring = string + sizeof string;
105 len = remoteconfig_cmdlength(string, EOstring);
107 failed = ( 14 != len );
109 if ( failed || verbose )
110 printf( "remoteconfig_cmdlength(\"%s\") returned %llu, expected %u: %s\n",
112 (unsigned long long)len,
114 failed ? "NO <<" : "yes" );
116 return failed ? -1 : 0;