File: test_eventqueue.tcc

package info (click to toggle)
uhub 0.4.1-3.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 1,436 kB
  • ctags: 2,270
  • sloc: ansic: 18,123; xml: 575; perl: 568; sh: 368; makefile: 24
file content (85 lines) | stat: -rw-r--r-- 1,706 bytes parent folder | download | duplicates (4)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <uhub.h>

static struct event_queue* eq;
static int eq_val;

static void eq_callback(void* callback_data, struct event_data* event_data)
{
	eq_val += event_data->id;
}

EXO_TEST(eventqueue_init_1, {
	eq = 0;
	eq_val = 0;
	return event_queue_initialize(&eq, eq_callback, &eq_val) == 0 && event_queue_size(eq) == 0;
});

EXO_TEST(eventqueue_init_2, {
	/* hack */
	return eq->callback_data == &eq_val && eq->callback == eq_callback && eq->q1 && eq->q2 && !eq->locked;
});

EXO_TEST(eventqueue_post_1, {
	struct event_data message;
	message.id  = 0x1001;
	message.ptr = &message;
	message.flags = message.id * 2;
	event_queue_post(eq, &message);
	return event_queue_size(eq) == 1;
});

EXO_TEST(eventqueue_process_1, {
	event_queue_process(eq);
	return eq_val == 0x1001;
});

EXO_TEST(eventqueue_size_1, {
	eq_val = 0;
	return event_queue_size(eq) == 0;
});

EXO_TEST(eventqueue_post_2, {
	struct event_data message;
	message.id  = 0x1002;
	message.ptr = &message;
	message.flags = message.id * 2;
	event_queue_post(eq, &message);
	return event_queue_size(eq) == 1;
});

EXO_TEST(eventqueue_size_2, {
	eq_val = 0;
	return event_queue_size(eq) == 1;
});


EXO_TEST(eventqueue_post_3, {
	struct event_data message;
	message.id  = 0x1003;
	message.ptr = &message;
	message.flags = message.id * 2;
	event_queue_post(eq, &message);
	return event_queue_size(eq) == 2;
});

EXO_TEST(eventqueue_size_3, {
	eq_val = 0;
	return event_queue_size(eq) == 2;
});

EXO_TEST(eventqueue_process_2, {
	event_queue_process(eq);
	return eq_val == 0x2005;
});

EXO_TEST(eventqueue_size_4, {
	eq_val = 0;
	return event_queue_size(eq) == 0;
});

EXO_TEST(eventqueue_shutdown_1, {
	event_queue_shutdown(eq);
	return 1;
});