1284990Scy#include <config.h>
2284990Scy
3290000Sglebius#include <rc_cmdlength.h>
4290000Sglebius
5284990Scy#include "unity.h"
6284990Scy
7284990Scyvoid setUp(void);
8284990Scyvoid tearDown(void);
9284990Scy
10284990Scyvoid test_main( void );
11284990Scyint basic_good( void );
12284990Scyint embedded_nul( void );
13284990Scyint trailing_space( void );
14284990Scy
15284990Scystatic int verbose = 1;        // if not 0, also print results if test passed
16293894Sglebius// static int exit_on_err = 0;    // if not 0, exit if test failed
17284990Scy
18284990Scy
19284990Scyvoid setUp(void)
20284990Scy{
21284990Scy}
22284990Scy
23284990Scy
24284990Scyvoid tearDown(void)
25284990Scy{
26284990Scy}
27284990Scy
28284990Scy
29284990Scy/*
30284990Scy * Test function calling the remote config buffer checker
31284990Scy * http://bugs.ntp.org/show_bug.cgi?id=2853
32284990Scy *
33284990Scy * size_t remoteconfig_cmdlength(const char *src_buf, const char *src_end)
34284990Scy * - trims whitespace & garbage from the right
35284990Scy * then looks for only \tSP-\127 starting from the left.
36284990Scy * It returns the number of "good" characters it found.
37284990Scy */
38284990Scy
39284990Scy
40284990Scyvoid test_main( void )
41284990Scy{
42284990Scy	TEST_ASSERT_EQUAL(0, basic_good());
43284990Scy	TEST_ASSERT_EQUAL(0, embedded_nul());
44284990Scy	TEST_ASSERT_EQUAL(0, trailing_space());
45284990Scy}
46284990Scy
47284990Scy
48284990Scyint basic_good( void )
49284990Scy{
50284990Scy	const char string[] = "good";
51284990Scy	const char *EOstring;
52284990Scy	size_t len;
53284990Scy	int failed;
54284990Scy
55284990Scy	EOstring = string + sizeof string;
56284990Scy
57284990Scy	len = remoteconfig_cmdlength(string, EOstring);
58284990Scy
59284990Scy	failed = ( 4 != len );
60284990Scy
61284990Scy	if ( failed || verbose )
62293894Sglebius		printf( "remoteconfig_cmdlength(\"%s\") returned %llu, expected %u: %s\n",
63284990Scy			string,
64293894Sglebius			(unsigned long long)len,
65284990Scy			4,
66284990Scy			failed ? "NO <<" : "yes" );
67284990Scy
68284990Scy	return failed ? -1 : 0;
69284990Scy}
70284990Scy
71284990Scy
72284990Scyint embedded_nul( void )
73284990Scy{
74284990Scy	const char string[] = "nul\0 there";
75284990Scy	const char *EOstring;
76284990Scy	size_t len;
77284990Scy	int failed;
78284990Scy
79284990Scy	EOstring = string + sizeof string;
80284990Scy
81284990Scy	len = remoteconfig_cmdlength(string, EOstring);
82284990Scy
83284990Scy	failed = ( 3 != len );
84284990Scy
85284990Scy	if ( failed || verbose )
86293894Sglebius		printf( "remoteconfig_cmdlength(\"%s\") returned %llu, expected %u: %s\n",
87284990Scy			string,
88293894Sglebius			(unsigned long long)len,
89284990Scy			3,
90284990Scy			failed ? "NO <<" : "yes" );
91284990Scy
92284990Scy	return failed ? -1 : 0;
93284990Scy}
94284990Scy
95284990Scy
96284990Scyint trailing_space( void )
97284990Scy{
98284990Scy	const char string[] = "trailing space ";
99284990Scy	const char *EOstring;
100284990Scy	size_t len;
101284990Scy	int failed;
102284990Scy
103284990Scy	EOstring = string + sizeof string;
104284990Scy
105284990Scy	len = remoteconfig_cmdlength(string, EOstring);
106284990Scy
107284990Scy	failed = ( 14 != len );
108284990Scy
109284990Scy	if ( failed || verbose )
110293894Sglebius		printf( "remoteconfig_cmdlength(\"%s\") returned %llu, expected %u: %s\n",
111284990Scy			string,
112293894Sglebius			(unsigned long long)len,
113284990Scy			14,
114284990Scy			failed ? "NO <<" : "yes" );
115284990Scy
116284990Scy	return failed ? -1 : 0;
117284990Scy}
118