File: gpstolfp.c

package info (click to toggle)
ntpsec 1.2.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,360 kB
  • sloc: ansic: 62,698; python: 32,477; sh: 1,575; yacc: 1,331; makefile: 193; javascript: 138
file content (54 lines) | stat: -rw-r--r-- 1,272 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "gpstolfp.h"
#include "ntp_types.h"

#include "unity.h"
#include "unity_fixture.h"

#include "config.h"
#include "ntp_stdlib.h"

TEST_GROUP(gpstolfp);

TEST_SETUP(gpstolfp){}
TEST_TEAR_DOWN(gpstolfp){}

TEST(gpstolfp, check) {
	uint64_t build_t, gps_t;
	struct calendar in, out;
	unsigned int build_week, week;
	unsigned long int TOW;

	unsigned int bw[] = {MIN_BUILD_GPSWEEK, 2048, MAX_BUILD_GPSWEEK};
	uint16_t by[] = {2016, 2019, 2096};
	uint8_t bm[] = {6, 4,  7};
	uint8_t bd[] = {5, 7, 1};

	for (int i = 0; i < 3; i++) {
		ZERO(in);
		in.year=by[i];
		in.month=bm[i];
		in.monthday = bd[i];
		caltogps(&in, 0, &week, &TOW);
		TEST_ASSERT_TRUE(week == bw[i] && TOW == 0);
	}

	for (uint32_t b = MIN_BUILD_GPSWEEK; b <= MAX_BUILD_GPSWEEK; b++) {
		build_week = b;
		week = b;
		gpstocal(week, 0, 0, &out);
		build_t = ntpcal_dayjoin(ntpcal_date_to_rd(&out) - DAY_NTP_STARTS,
		       ntpcal_date_to_daysec(&out));
		for (week = 0; week < GPSWEEKS; week++) {
			gpsweekadj(&week, build_week);
			ZERO(out);
			gpstocal(week, 0, 0, &out);
			gps_t = ntpcal_dayjoin(ntpcal_date_to_rd(&out) - DAY_NTP_STARTS,
			       ntpcal_date_to_daysec(&out));
			TEST_ASSERT_FALSE(build_t > gps_t);
		}
	}
}

TEST_GROUP_RUNNER(gpstolfp) {
	RUN_TEST_CASE(gpstolfp, check);
}