Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 1febd72cec45d15f6a3b413964d276db381a9f07 (plain) (blame)
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*******************************************************************************
 * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * CONTRIBUTORS:
 * 		Thomas Schuetz (initial contribution)
 *
 *******************************************************************************/

#include "TestEtMessageQueue.h"
#include "etUnit/etUnit.h"
#include "messaging/etMessageQueue.h"

void TestEtMessageQueue_testPushPop(void){

	etMessage msg1 = {NULL, 123, 456};
	etMessage msg2 = {NULL, 222, 333};

	etMessageQueue queue1;
	etMessageQueue_init(&queue1);

	etMessageQueue_push(&queue1, &msg1);
	etMessageQueue_push(&queue1, &msg2);

	EXPECT_EQUAL_INT16("etMessageQueue.size before", 2, queue1.size);
	EXPECT_EQUAL_INT16("etMessageQueue.highWaterMark before", 2, queue1.highWaterMark);

	etMessage* rcvMsg1 = etMessageQueue_pop(&queue1);
	etMessage* rcvMsg2 = etMessageQueue_pop(&queue1);

	EXPECT_EQUAL_INT16("etMessageQueue.size after", 0, queue1.size);
	EXPECT_EQUAL_INT16("etMessageQueue.highWaterMark after", 2, queue1.highWaterMark);

	EXPECT_EQUAL_INT16("rcvMsg1->address", 123, rcvMsg1->address);
	EXPECT_EQUAL_INT16("rcvMsg1->evtID", 456, rcvMsg1->evtID);
	EXPECT_EQUAL_PTR("rcvMsg1->next", NULL, rcvMsg1->next);

	EXPECT_EQUAL_INT16("rcvMsg2->address", 222, rcvMsg2->address);
	EXPECT_EQUAL_INT16("rcvMsg2->evtID", 333, rcvMsg2->evtID);
	EXPECT_EQUAL_PTR("rcvMsg2->next", NULL, rcvMsg2->next);

	EXPECT_EQUAL_PTR("etMessageQueue->first", NULL, queue1.first);
	EXPECT_EQUAL_PTR("etMessageQueue->last", NULL, queue1.last);

	etMessage* rcvMsg3 = etMessageQueue_pop(&queue1);
	EXPECT_EQUAL_PTR("etMessageQueue_pop if empty", NULL, rcvMsg3);

}

#define MAX 1000

void TestEtMessageQueue_testMassiveMessaging(void){

	etMessage msgArray[MAX];

	etMessageQueue queue1;
	etMessageQueue_init(&queue1);

	int16 i;
	for(i=0; i<MAX; i++){
		//etMessage_init(&msgArray[i]);
		msgArray[i].address = i;
		msgArray[i].evtID = i;
	}

	int j;
	for(j=0; j<3; j++){
		for (i=0; i<MAX; i++){
			etMessageQueue_push(&queue1, &(msgArray[i]));
		}
		for (i=0; i<MAX; i++){
			etMessage* msg = etMessageQueue_pop(&queue1);
			// EXPECTS are hidden to avoid too many testcases in log
			if (msg == NULL){
				EXPECT_FALSE("msg == NULL", TRUE);
				break;
			}
			if (msg->address != msg->evtID){
				EXPECT_FALSE("msg->address != msg->evtID", TRUE);
				break;
			}
			if (msg->address != i){
				EXPECT_FALSE("msg->address != i", TRUE);
				break;
			}
		}
		EXPECT_EQUAL_INT32("i==MAX", MAX, i);
	}
}

void TestEtMessageQueue_runSuite(void){
	etUnit_openTestSuite("TestEtMessageQueue");
	ADD_TESTCASE(TestEtMessageQueue_testPushPop);
	ADD_TESTCASE(TestEtMessageQueue_testMassiveMessaging);
	etUnit_closeTestSuite();
}

Back to the top