File: seqnum.c

package info (click to toggle)
chiaki 2.2.0-1.2
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 5,312 kB
  • sloc: ansic: 17,616; cpp: 7,901; xml: 2,691; sh: 395; python: 96; makefile: 6
file content (71 lines) | stat: -rw-r--r-- 1,473 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL

#include <munit.h>

#include <chiaki/seqnum.h>


static MunitResult test_seq_num_16(const MunitParameter params[], void *user)
{
	ChiakiSeqNum16 a = 0;
	do
	{
		ChiakiSeqNum16 b = a + 1;
		munit_assert(chiaki_seq_num_16_gt(b, a));
		munit_assert(!chiaki_seq_num_16_gt(a, b));
		munit_assert(chiaki_seq_num_16_lt(a, b));
		munit_assert(!chiaki_seq_num_16_lt(b, a));
		a = b;
	} while(a);

	a = 0;
	do
	{
		ChiakiSeqNum16 b = a + 0xfff;
		munit_assert(chiaki_seq_num_16_gt(b, a));
		munit_assert(!chiaki_seq_num_16_gt(a, b));
		munit_assert(chiaki_seq_num_16_lt(a, b));
		munit_assert(!chiaki_seq_num_16_lt(b, a));
		a++;
	} while(a);

	munit_assert(chiaki_seq_num_16_gt(1, 0xfff5));
	munit_assert(!chiaki_seq_num_16_gt(0xfff5, 1));

	return MUNIT_OK;
}


static MunitResult test_seq_num_32(const MunitParameter params[], void *user)
{
	munit_assert(chiaki_seq_num_32_gt(1, 0));
	munit_assert(!chiaki_seq_num_32_gt(0, 1));
	munit_assert(!chiaki_seq_num_32_lt(1, 0));
	munit_assert(chiaki_seq_num_32_lt(0, 1));
	munit_assert(chiaki_seq_num_32_gt(1, 0xfffffff5));
	munit_assert(!chiaki_seq_num_32_gt(0xfffffff5, 1));

	return MUNIT_OK;
}



MunitTest tests_seq_num[] = {
	{
		"/seq_num_16",
		test_seq_num_16,
		NULL,
		NULL,
		MUNIT_TEST_OPTION_NONE,
		NULL
	},
	{
		"/seq_num_32",
		test_seq_num_32,
		NULL,
		NULL,
		MUNIT_TEST_OPTION_NONE,
		NULL
	},
	{ NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }
};