HIPC  0.5
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
test_queue.c
Go to the documentation of this file.
1 #include <assert.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 
5 #include <hipc/queue.h>
6 
7 static void test_hipcQueue(void)
8 {
9  struct HIPC_queue queue;
10  int buf[3];
11  int *item_p;
12 
13  hipcQueueInit(&queue, buf, sizeof(buf[0]),
14  sizeof(buf) / sizeof(buf[0]));
15  assert(sizeof(buf[0]) == hipcQueueItemSize(&queue));
16 
17  assert(NULL == hipcQueueEmpty(&queue));
18 
19  item_p = hipcQueueFull(&queue);
20  assert(NULL != item_p);
21  *item_p = 2;
22  hipcQueuePush(&queue); /* PUSH */
23 
24  assert(NULL != hipcQueueFull(&queue));
25 
26  item_p = hipcQueueEmpty(&queue);
27  assert(NULL != item_p);
28  assert(2 == *item_p);
29  hipcQueuePop(&queue); /* POP */
30 
31  assert(NULL == hipcQueueEmpty(&queue));
32 
33  item_p = hipcQueueFull(&queue);
34  assert(NULL != item_p);
35  *item_p = 3;
36  hipcQueuePush(&queue); /* PUSH */
37 
38  item_p = hipcQueueEmpty(&queue);
39  assert(NULL != item_p);
40  assert(3 == *item_p);
41 
42  item_p = hipcQueueFull(&queue);
43  assert(NULL != item_p);
44  *item_p = 5;
45  hipcQueuePush(&queue); /* PUSH */
46 
47  assert(NULL == hipcQueueFull(&queue));
48 
49  item_p = hipcQueueEmpty(&queue);
50  assert(NULL != item_p);
51  assert(3 == *item_p);
52  hipcQueuePop(&queue); /* POP */
53 
54  item_p = hipcQueueEmpty(&queue);
55  assert(NULL != item_p);
56  assert(5 == *item_p);
57 
58  item_p = hipcQueueFull(&queue);
59  assert(NULL != item_p);
60  *item_p = 7;
61  hipcQueuePush(&queue); /* PUSH */
62 
63  assert(NULL == hipcQueueFull(&queue));
64 
65  item_p = hipcQueueEmpty(&queue);
66  assert(NULL != item_p);
67  assert(5 == *item_p);
68  hipcQueuePop(&queue); /* POP */
69 
70  assert(NULL != hipcQueueFull(&queue));
71 
72  item_p = hipcQueueEmpty(&queue);
73  assert(NULL != item_p);
74  assert(7 == *item_p);
75  hipcQueuePop(&queue); /* POP */
76 
77  assert(NULL != hipcQueueFull(&queue));
78  assert(NULL == hipcQueueEmpty(&queue));
79 
80  item_p = hipcQueueFull(&queue);
81  assert(NULL != item_p);
82  *item_p = 11;
83  hipcQueuePush(&queue); /* PUSH */
84  item_p = hipcQueueFull(&queue);
85  assert(NULL != item_p);
86  *item_p = 13;
87  hipcQueuePush(&queue); /* PUSH */
88 
89  assert(NULL == hipcQueueFull(&queue));
90  assert(NULL != hipcQueueEmpty(&queue));
91 
92  hipcQueueClear(&queue);
93 
94  assert(NULL != hipcQueueFull(&queue));
95  assert(NULL == hipcQueueEmpty(&queue));
96 
97  item_p = hipcQueueFull(&queue);
98  assert(NULL != item_p);
99  *item_p = 17;
100  hipcQueuePush(&queue); /* PUSH */
101  item_p = hipcQueueFull(&queue);
102  assert(NULL != item_p);
103  *item_p = 19;
104  hipcQueuePush(&queue); /* PUSH */
105 
106  assert(NULL == hipcQueueFull(&queue));
107 
108  item_p = hipcQueueEmpty(&queue);
109  assert(NULL != item_p);
110  assert(17 == *item_p);
111  hipcQueuePop(&queue); /* POP */
112 
113  assert(NULL != hipcQueueFull(&queue));
114  assert(NULL != hipcQueueEmpty(&queue));
115 
116  hipcQueueClear(&queue);
117 
118  assert(NULL != hipcQueueFull(&queue));
119  assert(NULL == hipcQueueEmpty(&queue));
120 
121  hipcQueueClear(&queue);
122 
123  assert(NULL != hipcQueueFull(&queue));
124  assert(NULL == hipcQueueEmpty(&queue));
125 
126  return;
127 }
128 
129 int main(int argc, char *argv[])
130 {
131  if (2 != argc) {
132  fprintf(stderr, "Usage: %s test_id\n", argv[0]);
133  exit(EXIT_FAILURE);
134  }
135 
136  switch (argv[1][0]) {
137  case 'a':
138  test_hipcQueue();
139  break;
140  default:
141  fprintf(stderr, "Invalid test_id: %s \n", argv[1]);
142  exit(EXIT_FAILURE);
143  }
144 
145  return 0;
146 }
void hipcQueueClear(struct HIPC_queue *const que_p)
Clears a queue.
Definition: queue.c:108
static void test_hipcQueue(void)
Definition: test_queue.c:7
void hipcQueueInit(struct HIPC_queue *const que_p, void *const buf_p, const size_t item_size, const size_t n_slot)
Initializes a queue.
Definition: queue.c:12
void hipcQueuePop(struct HIPC_queue *const que_p)
Pops an item and releases a slot.
Definition: queue.c:61
int main(int argc, char *argv[])
Definition: test_queue.c:129
void hipcQueuePush(struct HIPC_queue *const que_p)
Pushes an item and occupies a slot.
Definition: queue.c:93
void * hipcQueueEmpty(struct HIPC_queue *const que_p)
Returns an address of the head item if it exists.
Definition: queue.c:44
void * hipcQueueFull(struct HIPC_queue const *const que_p)
Returns an address of an empty slot if it exists.
Definition: queue.c:76
size_t hipcQueueItemSize(struct HIPC_queue *const que_p)
Gets item size.
Definition: queue.c:32