File: test-time.c

package info (click to toggle)
ell 0.81-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,344 kB
  • sloc: ansic: 61,546; sh: 4,896; makefile: 574
file content (45 lines) | stat: -rw-r--r-- 969 bytes parent folder | download | duplicates (2)
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
/*
 * Embedded Linux library
 * Copyright (C) 2019  Intel Corporation
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <assert.h>

#include <ell/ell.h>

static void test_before_after_diff(const void *data)
{
	uint64_t small = 10;
	uint64_t big = 100;

	assert(l_time_after(big, small));
	assert(l_time_before(small, big));
	assert(l_time_diff(small, big) == l_time_diff(big, small));
}

static void test_offset(const void *data)
{
	uint64_t max = UINT64_MAX;
	uint64_t max_minus = UINT64_MAX - 1000;

	assert(l_time_offset(max, 1) == UINT64_MAX);
	assert(l_time_offset(max, max) == UINT64_MAX);
	assert(l_time_offset(max_minus, 1000) == max);
	assert(l_time_offset(max_minus, 1001) == UINT64_MAX);
}

int main(int argc, char *argv[])
{
	l_test_init(&argc, &argv);

	l_test_add("Test before/after/diff", test_before_after_diff, NULL);
	l_test_add("Test offset", test_offset, NULL);

	return l_test_run();
}