1 #include "config.h"
2 
3 //some unused features are still in the wrapper, unconverted
4 
5 #include "ntp_types.h"
6 #include "ntp_fp.h"
7 
8 #include "timevalops.h"
9 
10 #include <math.h>
11 #include "unity.h"
12 
13 
14 #define TEST_ASSERT_EQUAL_timeval(a, b) {				\
15     TEST_ASSERT_EQUAL_MESSAGE(a.tv_sec, b.tv_sec, "Field tv_sec");	\
16     TEST_ASSERT_EQUAL_MESSAGE(a.tv_usec, b.tv_usec, "Field tv_usec");	\
17 }
18 
19 
20 static u_int32 my_tick_to_tsf(u_int32 ticks);
21 static u_int32 my_tsf_to_tick(u_int32 tsf);
22 
23 
24 // that's it...
25 typedef struct {
26 	long	usec;
27 	u_int32	frac;
28 } lfpfracdata ;
29 
30 struct timeval timeval_init( time_t hi, long lo);
31 const bool timeval_isValid(struct timeval V);
32 l_fp l_fp_init(int32 i, u_int32 f);
33 bool AssertTimevalClose(const struct timeval m, const struct timeval n, const struct timeval limit);
34 bool AssertFpClose(const l_fp m, const l_fp n, const l_fp limit);
35 
36 void setUp(void);
37 void test_Helpers1(void);
38 void test_Normalise(void);
39 void test_SignNoFrac(void);
40 void test_SignWithFrac(void);
41 void test_CmpFracEQ(void);
42 void test_CmpFracGT(void);
43 void test_CmpFracLT(void);
44 void test_AddFullNorm(void);
45 void test_AddFullOflow1(void);
46 void test_AddUsecNorm(void);
47 void test_AddUsecOflow1(void);
48 void test_SubFullNorm(void);
49 void test_SubFullOflow(void);
50 void test_SubUsecNorm(void);
51 void test_SubUsecOflow(void);
52 void test_Neg(void);
53 void test_AbsNoFrac(void);
54 void test_AbsWithFrac(void);
55 void test_Helpers2(void);
56 void test_ToLFPbittest(void);
57 void test_ToLFPrelPos(void);
58 void test_ToLFPrelNeg(void);
59 void test_ToLFPabs(void);
60 void test_FromLFPbittest(void);
61 void test_FromLFPrelPos(void);
62 void test_FromLFPrelNeg(void);
63 void test_LFProundtrip(void);
64 void test_ToString(void);
65 
66 
67 //**********************************MY CUSTOM FUNCTIONS***********************
68 
69 
70 void
setUp(void)71 setUp(void)
72 {
73 	init_lib();
74 
75 	return;
76 }
77 
78 
79 struct timeval
timeval_init(time_t hi,long lo)80 timeval_init(time_t hi, long lo)
81 {
82 	struct timeval V;
83 
84 	V.tv_sec = hi;
85 	V.tv_usec = lo;
86 
87 	return V;
88 }
89 
90 
91 const bool
timeval_isValid(struct timeval V)92 timeval_isValid(struct timeval V)
93 {
94 
95 	return V.tv_usec >= 0 && V.tv_usec < 1000000;
96 }
97 
98 
99 l_fp
l_fp_init(int32 i,u_int32 f)100 l_fp_init(int32 i, u_int32 f)
101 {
102 	l_fp temp;
103 
104 	temp.l_i  = i;
105 	temp.l_uf = f;
106 
107 	return temp;
108 }
109 
110 
111 bool
AssertTimevalClose(const struct timeval m,const struct timeval n,const struct timeval limit)112 AssertTimevalClose(const struct timeval m, const struct timeval n, const struct timeval limit)
113 {
114 	struct timeval diff;
115 
116 	diff = abs_tval(sub_tval(m, n));
117 	if (cmp_tval(limit, diff) >= 0)
118 		return TRUE;
119 	else
120 	{
121 		printf("m_expr which is %ld.%lu \nand\nn_expr which is %ld.%lu\nare not close; diff=%ld.%luusec\n", m.tv_sec, m.tv_usec, n.tv_sec, n.tv_usec, diff.tv_sec, diff.tv_usec);
122 		//I don't have variables m_expr and n_expr in unity, those are command line arguments which only getst has!!!
123 
124 		return FALSE;
125 	}
126 }
127 
128 
129 bool
AssertFpClose(const l_fp m,const l_fp n,const l_fp limit)130 AssertFpClose(const l_fp m, const l_fp n, const l_fp limit)
131 {
132 	l_fp diff;
133 
134 	if (L_ISGEQ(&m, &n)) {
135 		diff = m;
136 		L_SUB(&diff, &n);
137 	} else {
138 		diff = n;
139 		L_SUB(&diff, &m);
140 	}
141 	if (L_ISGEQ(&limit, &diff)) {
142 		return TRUE;
143 	}
144 	else {
145 		printf("m_expr which is %s \nand\nn_expr which is %s\nare not close; diff=%susec\n", lfptoa(&m, 10), lfptoa(&n, 10), lfptoa(&diff, 10));
146 		//printf("m_expr which is %d.%d \nand\nn_expr which is %d.%d\nare not close; diff=%d.%dusec\n", m.l_uf, m.Ul_i, n.l_uf, n.Ul_i, diff.l_uf, diff.Ul_i);
147 		return FALSE;
148 	}
149 }
150 
151 
152 //---------------------------------------------------
153 
154 static const lfpfracdata fdata[] = {
155 	{      0, 0x00000000 }, {   7478, 0x01ea1405 },
156 	{  22077, 0x05a6d699 }, { 125000, 0x20000000 },
157 	{ 180326, 0x2e29d841 }, { 207979, 0x353e1c9b },
158 	{ 250000, 0x40000000 }, { 269509, 0x44fe8ab5 },
159 	{ 330441, 0x5497c808 }, { 333038, 0x5541fa76 },
160 	{ 375000, 0x60000000 }, { 394734, 0x650d4995 },
161 	{ 446327, 0x72427c7c }, { 500000, 0x80000000 },
162 	{ 517139, 0x846338b4 }, { 571953, 0x926b8306 },
163 	{ 587353, 0x965cc426 }, { 625000, 0xa0000000 },
164 	{ 692136, 0xb12fd32c }, { 750000, 0xc0000000 },
165 	{ 834068, 0xd5857aff }, { 848454, 0xd9344806 },
166 	{ 854222, 0xdaae4b02 }, { 861465, 0xdc88f862 },
167 	{ 875000, 0xe0000000 }, { 910661, 0xe921144d },
168 	{ 922162, 0xec12cf10 }, { 942190, 0xf1335d25 }
169 };
170 
171 
172 u_int32
my_tick_to_tsf(u_int32 ticks)173 my_tick_to_tsf(u_int32 ticks)
174 {
175 	// convert microseconds to l_fp fractional units, using double
176 	// precision float calculations or, if available, 64bit integer
177 	// arithmetic. This should give the precise fraction, rounded to
178 	// the nearest representation.
179 
180 #ifdef HAVE_U_INT64
181 	return (u_int32)((( ((u_int64)(ticks)) << 32) + 500000) / 1000000); //I put too much () when casting just to be safe
182 #else
183 	return (u_int32)( ((double)(ticks)) * 4294.967296 + 0.5);
184 #endif
185 	// And before you ask: if ticks >= 1000000, the result is
186 	// truncated nonsense, so don't use it out-of-bounds.
187 }
188 
189 
190 u_int32
my_tsf_to_tick(u_int32 tsf)191 my_tsf_to_tick(u_int32 tsf)
192 {
193 	// Inverse operation: converts fraction to microseconds.
194 #ifdef HAVE_U_INT64
195 	return (u_int32)( ((u_int64)(tsf) * 1000000 + 0x80000000) >> 32); //CHECK ME!!!
196 #else
197 	return (u_int32)(double(tsf) / 4294.967296 + 0.5);
198 #endif
199 	// Beware: The result might be 10^6 due to rounding!
200 }
201 
202 
203 //*******************************END OF CUSTOM FUNCTIONS*********************
204 
205 
206 // ---------------------------------------------------------------------
207 // test support stuff - part1
208 // ---------------------------------------------------------------------
209 
210 void
test_Helpers1(void)211 test_Helpers1(void)
212 {
213 	struct timeval x;
214 
215 	for (x.tv_sec = -2; x.tv_sec < 3; x.tv_sec++) {
216 		x.tv_usec = -1;
217 		TEST_ASSERT_FALSE(timeval_isValid(x));
218 		x.tv_usec = 0;
219 		TEST_ASSERT_TRUE(timeval_isValid(x));
220 		x.tv_usec = 999999;
221 		TEST_ASSERT_TRUE(timeval_isValid(x));
222 		x.tv_usec = 1000000;
223 		TEST_ASSERT_FALSE(timeval_isValid(x));
224 	}
225 
226 	return;
227 }
228 
229 
230 //----------------------------------------------------------------------
231 // test normalisation
232 //----------------------------------------------------------------------
233 
234 void
test_Normalise(void)235 test_Normalise(void)
236 {
237 	long ns;
238 
239 	for (ns = -2000000000; ns <= 2000000000; ns += 10000000) {
240 		struct timeval x = timeval_init(0, ns);
241 
242 		x = normalize_tval(x);
243 		TEST_ASSERT_TRUE(timeval_isValid(x));
244 	}
245 
246 	return;
247 }
248 
249 //----------------------------------------------------------------------
250 // test classification
251 //----------------------------------------------------------------------
252 
253 void
test_SignNoFrac(void)254 test_SignNoFrac(void)
255 {
256 	int i;
257 
258 	// sign test, no fraction
259 	for (i = -4; i <= 4; ++i) {
260 		struct timeval a = timeval_init(i, 0);
261 		int	     E = (i > 0) - (i < 0);
262 		int	     r = test_tval(a);
263 
264 		TEST_ASSERT_EQUAL(E, r);
265 	}
266 
267 	return;
268 }
269 
270 
271 void
test_SignWithFrac(void)272 test_SignWithFrac(void)
273 {
274 	// sign test, with fraction
275 	int i;
276 
277 	for (i = -4; i <= 4; ++i) {
278 		struct timeval a = timeval_init(i, 10);
279 		int	     E = (i >= 0) - (i < 0);
280 		int	     r = test_tval(a);
281 
282 		TEST_ASSERT_EQUAL(E, r);
283 	}
284 
285 	return;
286 }
287 
288 //----------------------------------------------------------------------
289 // test compare
290 //----------------------------------------------------------------------
291 void
test_CmpFracEQ(void)292 test_CmpFracEQ(void)
293 {
294 	int i, j;
295 
296 	// fractions are equal
297 	for (i = -4; i <= 4; ++i)
298 		for (j = -4; j <= 4; ++j) {
299 			struct timeval a = timeval_init(i, 200);
300 			struct timeval b = timeval_init(j, 200);
301 			int	     E = (i > j) - (i < j);
302 			int	     r = cmp_tval_denorm(a, b);
303 
304 			TEST_ASSERT_EQUAL(E, r);
305 		}
306 
307 	return;
308 }
309 
310 
311 void
test_CmpFracGT(void)312 test_CmpFracGT(void)
313 {
314 	// fraction a bigger fraction b
315 	int i, j;
316 
317 	for (i = -4; i <= 4; ++i)
318 		for (j = -4; j <= 4; ++j) {
319 			struct timeval a = timeval_init( i , 999800);
320 			struct timeval b = timeval_init( j , 200);
321 			int	     E = (i >= j) - (i < j);
322 			int	     r = cmp_tval_denorm(a, b);
323 
324 			TEST_ASSERT_EQUAL(E, r);
325 		}
326 
327 	return;
328 }
329 
330 
331 void
test_CmpFracLT(void)332 test_CmpFracLT(void)
333 {
334 	// fraction a less fraction b
335 	int i, j;
336 
337 	for (i = -4; i <= 4; ++i)
338 		for (j = -4; j <= 4; ++j) {
339 			struct timeval a = timeval_init(i, 200);
340 			struct timeval b = timeval_init(j, 999800);
341 			int	     E = (i > j) - (i <= j);
342 			int	     r = cmp_tval_denorm(a, b);
343 
344 			TEST_ASSERT_EQUAL(E, r);
345 		}
346 
347 	return;
348 }
349 
350 //----------------------------------------------------------------------
351 // Test addition (sum)
352 //----------------------------------------------------------------------
353 
354 void
test_AddFullNorm(void)355 test_AddFullNorm(void)
356 {
357 	int i, j;
358 
359 	for (i = -4; i <= 4; ++i)
360 		for (j = -4; j <= 4; ++j) {
361 			struct timeval a = timeval_init(i, 200);
362 			struct timeval b = timeval_init(j, 400);
363 			struct timeval E = timeval_init(i + j, 200 + 400);
364 			struct timeval c;
365 
366 			c = add_tval(a, b);
367 			TEST_ASSERT_EQUAL_timeval(E, c);
368 		}
369 
370 	return;
371 }
372 
373 
374 void
test_AddFullOflow1(void)375 test_AddFullOflow1(void)
376 {
377 	int i, j;
378 
379 	for (i = -4; i <= 4; ++i)
380 		for (j = -4; j <= 4; ++j) {
381 			struct timeval a = timeval_init(i, 200);
382 			struct timeval b = timeval_init(j, 999900);
383 			struct timeval E = timeval_init(i + j + 1, 100);
384 			struct timeval c;
385 
386 			c = add_tval(a, b);
387 			TEST_ASSERT_EQUAL_timeval(E, c);
388 		}
389 
390 	return;
391 }
392 
393 
394 void
test_AddUsecNorm(void)395 test_AddUsecNorm(void)
396 {
397 	int i;
398 
399 	for (i = -4; i <= 4; ++i) {
400 		struct timeval a = timeval_init(i, 200);
401 		struct timeval E = timeval_init(i, 600);
402 		struct timeval c;
403 
404 		c = add_tval_us(a, 600 - 200);
405 		TEST_ASSERT_EQUAL_timeval(E, c);
406 	}
407 
408 	return;
409 }
410 
411 
412 void
test_AddUsecOflow1(void)413 test_AddUsecOflow1(void)
414 {
415 	int i;
416 
417 	for (i = -4; i <= 4; ++i) {
418 		struct timeval a = timeval_init(i, 200);
419 		struct timeval E = timeval_init(i + 1, 100);
420 		struct timeval c;
421 
422 		c = add_tval_us(a, MICROSECONDS - 100);
423 		TEST_ASSERT_EQUAL_timeval(E, c);
424 	}
425 
426 	return;
427 }
428 
429 //----------------------------------------------------------------------
430 // test subtraction (difference)
431 //----------------------------------------------------------------------
432 
433 void
test_SubFullNorm(void)434 test_SubFullNorm(void)
435 {
436 	int i, j;
437 
438 	for (i = -4; i <= 4; ++i)
439 		for (j = -4; j <= 4; ++j) {
440 			struct timeval a = timeval_init(i, 600);
441 			struct timeval b = timeval_init(j, 400);
442 			struct timeval E = timeval_init(i - j, 600 - 400);
443 			struct timeval c;
444 
445 			c = sub_tval(a, b);
446 			TEST_ASSERT_EQUAL_timeval(E, c);
447 		}
448 
449 	return;
450 }
451 
452 
453 void
test_SubFullOflow(void)454 test_SubFullOflow(void)
455 {
456 	int i, j;
457 
458 	for (i = -4; i <= 4; ++i)
459 		for (j = -4; j <= 4; ++j) {
460 			struct timeval a = timeval_init(i, 100);
461 			struct timeval b = timeval_init(j, 999900);
462 			struct timeval E = timeval_init(i - j - 1, 200);
463 			struct timeval c;
464 
465 			c = sub_tval(a, b);
466 			TEST_ASSERT_EQUAL_timeval(E, c);
467 		}
468 
469 	return;
470 }
471 
472 
473 void
test_SubUsecNorm(void)474 test_SubUsecNorm(void)
475 {
476 	int i = -4;
477 
478 	for (i = -4; i <= 4; ++i) {
479 		struct timeval a = timeval_init(i, 600);
480 		struct timeval E = timeval_init(i, 200);
481 		struct timeval c;
482 
483 		c = sub_tval_us(a, 600 - 200);
484 		TEST_ASSERT_EQUAL_timeval(E, c);
485 	}
486 
487 	return;
488 }
489 
490 
491 void
test_SubUsecOflow(void)492 test_SubUsecOflow(void)
493 {
494 	int i = -4;
495 
496 	for (i = -4; i <= 4; ++i) {
497 		struct timeval a = timeval_init(i, 100);
498 		struct timeval E = timeval_init(i - 1, 200);
499 		struct timeval c;
500 
501 		c = sub_tval_us(a, MICROSECONDS - 100);
502 		TEST_ASSERT_EQUAL_timeval(E, c);
503 	}
504 
505 	return;
506 }
507 
508 //----------------------------------------------------------------------
509 // test negation
510 //----------------------------------------------------------------------
511 
512 void
test_Neg(void)513 test_Neg(void)
514 {
515 	int i = -4;
516 
517 	for (i = -4; i <= 4; ++i) {
518 		struct timeval a = timeval_init(i, 100);
519 		struct timeval b;
520 		struct timeval c;
521 
522 		b = neg_tval(a);
523 		c = add_tval(a, b);
524 		TEST_ASSERT_EQUAL(0, test_tval(c));
525 	}
526 
527 	return;
528 }
529 
530 //----------------------------------------------------------------------
531 // test abs value
532 //----------------------------------------------------------------------
533 
534 void
test_AbsNoFrac(void)535 test_AbsNoFrac(void)
536 {
537 	int i = -4;
538 
539 	for (i = -4; i <= 4; ++i) {
540 		struct timeval a = timeval_init(i, 0);
541 		struct timeval b;
542 
543 		b = abs_tval(a);
544 		TEST_ASSERT_EQUAL((i != 0), test_tval(b));
545 	}
546 
547 	return;
548 }
549 
550 
551 void
test_AbsWithFrac(void)552 test_AbsWithFrac(void)
553 {
554 	int i = -4;
555 
556 	for (i = -4; i <= 4; ++i) {
557 		struct timeval a = timeval_init(i, 100);
558 		struct timeval b;
559 
560 		b = abs_tval(a);
561 		TEST_ASSERT_EQUAL(1, test_tval(b));
562 	}
563 
564 	return;
565 }
566 
567 // ---------------------------------------------------------------------
568 // test support stuff -- part 2
569 // ---------------------------------------------------------------------
570 
571 
572 void
test_Helpers2(void)573 test_Helpers2(void)
574 {
575 	struct timeval limit = timeval_init(0, 2);
576 	struct timeval x, y;
577 	long i;
578 
579 	for (x.tv_sec = -2; x.tv_sec < 3; x.tv_sec++) {
580 		for (x.tv_usec = 1;
581 		     x.tv_usec < 1000000;
582 		     x.tv_usec += 499999) {
583 			for (i = -4; i < 5; ++i) {
584 				y = x;
585 				y.tv_usec += i;
586 				if (i >= -2 && i <= 2) {
587 					TEST_ASSERT_TRUE(AssertTimevalClose(x, y, limit));//ASSERT_PRED_FORMAT2(isClose, x, y);
588 				}
589 				else {
590 					TEST_ASSERT_FALSE(AssertTimevalClose(x, y, limit));
591 				}
592 			}
593 		}
594 	}
595 
596 	return;
597 }
598 
599 // and the global predicate instances we're using here
600 
601 //static l_fp lfpClose =  l_fp_init(0, 1); //static AssertFpClose FpClose(0, 1);
602 //static struct timeval timevalClose = timeval_init(0, 1); //static AssertTimevalClose TimevalClose(0, 1);
603 
604 //----------------------------------------------------------------------
605 // conversion to l_fp
606 //----------------------------------------------------------------------
607 
608 void
test_ToLFPbittest(void)609 test_ToLFPbittest(void)
610 {
611 	l_fp lfpClose =  l_fp_init(0, 1);
612 
613 	u_int32 i = 0;
614 	for (i = 0; i < 1000000; ++i) {
615 		struct timeval a = timeval_init(1, i);
616 		l_fp E = l_fp_init(1, my_tick_to_tsf(i));
617 		l_fp r;
618 
619 		r = tval_intv_to_lfp(a);
620 		TEST_ASSERT_TRUE(AssertFpClose(E, r, lfpClose));	//ASSERT_PRED_FORMAT2(FpClose, E, r);
621 	}
622 
623 	return;
624 }
625 
626 
627 void
test_ToLFPrelPos(void)628 test_ToLFPrelPos(void)
629 {
630 	l_fp lfpClose =  l_fp_init(0, 1);
631 	int i = 0;
632 
633 	for (i = 0; i < COUNTOF(fdata); ++i) {
634 		struct timeval a = timeval_init(1, fdata[i].usec);
635 		l_fp E = l_fp_init(1, fdata[i].frac);
636 		l_fp r;
637 
638 		r = tval_intv_to_lfp(a);
639 		TEST_ASSERT_TRUE(AssertFpClose(E, r, lfpClose));
640 	}
641 
642 	return;
643 }
644 
645 
646 void
test_ToLFPrelNeg(void)647 test_ToLFPrelNeg(void)
648 {
649 	l_fp lfpClose =  l_fp_init(0, 1);
650 	int i = 0;
651 
652 	for (i = 0; i < COUNTOF(fdata); ++i) {
653 		struct timeval a = timeval_init(-1, fdata[i].usec);
654 		l_fp E = l_fp_init(~0, fdata[i].frac);
655 		l_fp    r;
656 
657 		r = tval_intv_to_lfp(a);
658 		TEST_ASSERT_TRUE(AssertFpClose(E, r, lfpClose));
659 	}
660 
661 	return;
662 }
663 
664 
665 void
test_ToLFPabs(void)666 test_ToLFPabs(void)
667 {
668 	l_fp lfpClose =  l_fp_init(0, 1);
669 	int i = 0;
670 
671 	for (i = 0; i < COUNTOF(fdata); ++i) {
672 		struct timeval a = timeval_init(1, fdata[i].usec);
673 		l_fp E = l_fp_init(1 + JAN_1970, fdata[i].frac);
674 		l_fp    r;
675 
676 		r = tval_stamp_to_lfp(a);
677 		TEST_ASSERT_TRUE(AssertFpClose(E, r, lfpClose));
678 	}
679 
680 	return;
681 }
682 
683 //----------------------------------------------------------------------
684 // conversion from l_fp
685 //----------------------------------------------------------------------
686 
687 void
test_FromLFPbittest(void)688 test_FromLFPbittest(void)
689 {
690 	struct timeval timevalClose = timeval_init(0, 1);
691 	// Not *exactly* a bittest, because 2**32 tests would take a
692 	// really long time even on very fast machines! So we do test
693 	// every 1000 fractional units.
694 	u_int32 tsf = 0;
695 
696 	for (tsf = 0; tsf < ~((u_int32)(1000)); tsf += 1000) {
697 		struct timeval E = timeval_init(1, my_tsf_to_tick(tsf));
698 		l_fp a = l_fp_init(1, tsf);
699 		struct timeval r;
700 
701 		r = lfp_intv_to_tval(a);
702 		// The conversion might be off by one microsecond when
703 		// comparing to calculated value.
704 		TEST_ASSERT_TRUE(AssertTimevalClose(E, r, timevalClose));
705 	}
706 
707 	return;
708 }
709 
710 
711 void
test_FromLFPrelPos(void)712 test_FromLFPrelPos(void)
713 {
714 	struct timeval timevalClose = timeval_init(0, 1);
715 	int i = 0;
716 
717 	for (i = 0; i < COUNTOF(fdata); ++i) {
718 		l_fp a = l_fp_init(1, fdata[i].frac);
719 		struct timeval E = timeval_init(1, fdata[i].usec);
720 		struct timeval r;
721 
722 		r = lfp_intv_to_tval(a);
723 		TEST_ASSERT_TRUE(AssertTimevalClose(E, r, timevalClose));
724 	}
725 
726 	return;
727 }
728 
729 
730 void
test_FromLFPrelNeg(void)731 test_FromLFPrelNeg(void)
732 {
733 	struct timeval timevalClose = timeval_init(0, 1);
734 	int i = 0;
735 
736 	for (i = 0; i < COUNTOF(fdata); ++i) {
737 		l_fp a = l_fp_init(~0, fdata[i].frac);
738 		struct timeval E = timeval_init(-1, fdata[i].usec);
739 		struct timeval r;
740 
741 		r = lfp_intv_to_tval(a);
742 		TEST_ASSERT_TRUE(AssertTimevalClose(E, r, timevalClose));
743 	}
744 
745 	return;
746 }
747 
748 
749 // usec -> frac -> usec roundtrip, using a prime start and increment
750 void
test_LFProundtrip(void)751 test_LFProundtrip(void)
752 {
753 	int32_t t = -1;
754 	u_int32 i = 5;
755 
756 	for (t = -1; t < 2; ++t)
757 		for (i = 5; i < 1000000; i += 11) {
758 			struct timeval E = timeval_init(t, i);
759 			l_fp a;
760 			struct timeval r;
761 
762 			a = tval_intv_to_lfp(E);
763 			r = lfp_intv_to_tval(a);
764 			TEST_ASSERT_EQUAL_timeval(E, r);
765 		}
766 
767 	return;
768 }
769 
770 //----------------------------------------------------------------------
771 // string formatting
772 //----------------------------------------------------------------------
773 
774 void
test_ToString(void)775 test_ToString(void)
776 {
777 	static const struct {
778 		time_t	     sec;
779 		long	     usec;
780 		const char * repr;
781 	} data [] = {
782 		{ 0, 0,	 "0.000000" },
783 		{ 2, 0,	 "2.000000" },
784 		{-2, 0, "-2.000000" },
785 		{ 0, 1,	 "0.000001" },
786 		{ 0,-1,	"-0.000001" },
787 		{ 1,-1,	 "0.999999" },
788 		{-1, 1, "-0.999999" },
789 		{-1,-1, "-1.000001" },
790 	};
791 	int i;
792 
793 	for (i = 0; i < COUNTOF(data); ++i) {
794 		struct timeval a = timeval_init(data[i].sec, data[i].usec);
795 		const char *  E = data[i].repr;
796 		const char *  r = tvaltoa(a);
797 
798 		TEST_ASSERT_EQUAL_STRING(E, r);
799 	}
800 
801 	return;
802 }
803 
804 // -*- EOF -*-
805