1290001Sglebius#include <config.h> 2290001Sglebius 3290001Sglebius#include <rc_cmdlength.h> 4290001Sglebius 5290001Sglebius#include "unity.h" 6290001Sglebius 7290001Sglebiusvoid setUp(void); 8290001Sglebiusvoid tearDown(void); 9290001Sglebius 10290001Sglebiusvoid test_main( void ); 11290001Sglebiusint basic_good( void ); 12290001Sglebiusint embedded_nul( void ); 13290001Sglebiusint trailing_space( void ); 14290001Sglebius 15290001Sglebiusstatic int verbose = 1; // if not 0, also print results if test passed 16293896Sglebius// static int exit_on_err = 0; // if not 0, exit if test failed 17290001Sglebius 18290001Sglebius 19290001Sglebiusvoid setUp(void) 20290001Sglebius{ 21290001Sglebius} 22290001Sglebius 23290001Sglebius 24290001Sglebiusvoid tearDown(void) 25290001Sglebius{ 26290001Sglebius} 27290001Sglebius 28290001Sglebius 29290001Sglebius/* 30290001Sglebius * Test function calling the remote config buffer checker 31290001Sglebius * http://bugs.ntp.org/show_bug.cgi?id=2853 32290001Sglebius * 33290001Sglebius * size_t remoteconfig_cmdlength(const char *src_buf, const char *src_end) 34290001Sglebius * - trims whitespace & garbage from the right 35290001Sglebius * then looks for only \tSP-\127 starting from the left. 36290001Sglebius * It returns the number of "good" characters it found. 37290001Sglebius */ 38290001Sglebius 39290001Sglebius 40290001Sglebiusvoid test_main( void ) 41290001Sglebius{ 42290001Sglebius TEST_ASSERT_EQUAL(0, basic_good()); 43290001Sglebius TEST_ASSERT_EQUAL(0, embedded_nul()); 44290001Sglebius TEST_ASSERT_EQUAL(0, trailing_space()); 45290001Sglebius} 46290001Sglebius 47290001Sglebius 48290001Sglebiusint basic_good( void ) 49290001Sglebius{ 50290001Sglebius const char string[] = "good"; 51290001Sglebius const char *EOstring; 52290001Sglebius size_t len; 53290001Sglebius int failed; 54290001Sglebius 55290001Sglebius EOstring = string + sizeof string; 56290001Sglebius 57290001Sglebius len = remoteconfig_cmdlength(string, EOstring); 58290001Sglebius 59290001Sglebius failed = ( 4 != len ); 60290001Sglebius 61290001Sglebius if ( failed || verbose ) 62293896Sglebius printf( "remoteconfig_cmdlength(\"%s\") returned %llu, expected %u: %s\n", 63290001Sglebius string, 64293896Sglebius (unsigned long long)len, 65290001Sglebius 4, 66290001Sglebius failed ? "NO <<" : "yes" ); 67290001Sglebius 68290001Sglebius return failed ? -1 : 0; 69290001Sglebius} 70290001Sglebius 71290001Sglebius 72290001Sglebiusint embedded_nul( void ) 73290001Sglebius{ 74290001Sglebius const char string[] = "nul\0 there"; 75290001Sglebius const char *EOstring; 76290001Sglebius size_t len; 77290001Sglebius int failed; 78290001Sglebius 79290001Sglebius EOstring = string + sizeof string; 80290001Sglebius 81290001Sglebius len = remoteconfig_cmdlength(string, EOstring); 82290001Sglebius 83290001Sglebius failed = ( 3 != len ); 84290001Sglebius 85290001Sglebius if ( failed || verbose ) 86293896Sglebius printf( "remoteconfig_cmdlength(\"%s\") returned %llu, expected %u: %s\n", 87290001Sglebius string, 88293896Sglebius (unsigned long long)len, 89290001Sglebius 3, 90290001Sglebius failed ? "NO <<" : "yes" ); 91290001Sglebius 92290001Sglebius return failed ? -1 : 0; 93290001Sglebius} 94290001Sglebius 95290001Sglebius 96290001Sglebiusint trailing_space( void ) 97290001Sglebius{ 98290001Sglebius const char string[] = "trailing space "; 99290001Sglebius const char *EOstring; 100290001Sglebius size_t len; 101290001Sglebius int failed; 102290001Sglebius 103290001Sglebius EOstring = string + sizeof string; 104290001Sglebius 105290001Sglebius len = remoteconfig_cmdlength(string, EOstring); 106290001Sglebius 107290001Sglebius failed = ( 14 != len ); 108290001Sglebius 109290001Sglebius if ( failed || verbose ) 110293896Sglebius printf( "remoteconfig_cmdlength(\"%s\") returned %llu, expected %u: %s\n", 111290001Sglebius string, 112293896Sglebius (unsigned long long)len, 113290001Sglebius 14, 114290001Sglebius failed ? "NO <<" : "yes" ); 115290001Sglebius 116290001Sglebius return failed ? -1 : 0; 117290001Sglebius} 118