-
Notifications
You must be signed in to change notification settings - Fork 12
/
test.c
81 lines (78 loc) · 1.99 KB
/
test.c
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
#include "rpa_queue.h"
#include <stdio.h>
bool test()
{
rpa_queue_t * queue = NULL;
uint32_t queue_capacity = 2;
if (!rpa_queue_create(&queue, queue_capacity)) {
printf("failed to create\n");
return false;
}
if (!rpa_queue_push(queue, "item 1")) {
printf("failed to push item\n");
return false;
}
if (!rpa_queue_trypush(queue, "item 2")) {
printf("failed to trypush item\n");
return false;
}
if (rpa_queue_trypush(queue, "item 3")) {
printf("item 3 accepted when it should have blocked\n");
return false;
}
char * data;
if (!rpa_queue_pop(queue, (void**) &data)) {
printf("pop failed\n");
return false;
}
printf("popped: %s\n", data);
if (!rpa_queue_trypop(queue, (void**) &data)) {
printf("trypop failed\n");
return false;
}
printf("popped: %s\n", data);
if (rpa_queue_trypop(queue, (void**) &data)) {
printf("pop succeeded when it should have failed\n");
return false;
}
/* try the timed versions */
if (!rpa_queue_timedpush(queue, "item 1", 100)) {
printf("failed to push item\n");
return false;
}
if (!rpa_queue_timedpush(queue, "item 2", 100)) {
printf("failed to trypush item\n");
return false;
}
printf("timedpush when full..."); fflush(stdout);
if (rpa_queue_timedpush(queue, "item 3", 1000)) {
printf("item 3 accepted when it should have blocked\n");
return false;
}
printf("DONE!\n");
if (!rpa_queue_timedpop(queue, (void**) &data, 1000)) {
printf("pop failed\n");
return false;
}
printf("popped: %s\n", data);
if (!rpa_queue_timedpop(queue, (void**) &data, 1000)) {
printf("trypop failed\n");
return false;
}
printf("popped: %s\n", data);
printf("timedpop when empty..."); fflush(stdout);
if (rpa_queue_timedpop(queue, (void**) &data, 1000)) {
printf("pop succeeded when it should have failed\n");
return false;
}
printf("DONE!\n");
return true;
}
int main()
{
if (!test()) {
return 1;
}
printf("test successful\n");
return 0;
}