summaryrefslogtreecommitdiffstats
path: root/winpr/libwinpr/utils/test/TestQueue.c
blob: 9c65af5f41bf88900fec1f36f9b589767c0788d4 (plain)
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
#include <winpr/crt.h>
#include <winpr/tchar.h>
#include <winpr/collections.h>

int TestQueue(int argc, char* argv[])
{
	size_t item = 0;
	size_t count = 0;
	wQueue* queue = NULL;

	WINPR_UNUSED(argc);
	WINPR_UNUSED(argv);

	queue = Queue_New(TRUE, -1, -1);
	if (!queue)
		return -1;

	for (size_t index = 1; index <= 10; index++)
	{
		Queue_Enqueue(queue, (void*)(size_t)index);
	}

	count = Queue_Count(queue);
	printf("queue count: %" PRIuz "\n", count);

	for (size_t index = 1; index <= 10; index++)
	{
		item = (size_t)Queue_Dequeue(queue);

		if (item != index)
			return -1;
	}

	count = Queue_Count(queue);
	printf("queue count: %" PRIuz "\n", count);

	Queue_Enqueue(queue, (void*)(size_t)1);
	Queue_Enqueue(queue, (void*)(size_t)2);
	Queue_Enqueue(queue, (void*)(size_t)3);

	Queue_Dequeue(queue);
	Queue_Dequeue(queue);

	Queue_Enqueue(queue, (void*)(size_t)4);
	Queue_Enqueue(queue, (void*)(size_t)5);
	Queue_Enqueue(queue, (void*)(size_t)6);

	Queue_Dequeue(queue);
	Queue_Dequeue(queue);
	Queue_Dequeue(queue);
	Queue_Dequeue(queue);

	Queue_Clear(queue);
	Queue_Free(queue);

	return 0;
}