Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 8479ac93f8aad943c8cd5794d73265189680c659 (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
/*******************************************************************************
 * Copyright (c) 2012 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:
 * 		Henrik Rentz-Reichert (initial contribution)
 *
 *******************************************************************************/

#include "TestEtQueue.h"

#include <stddef.h>
#include "etUnit/etUnit.h"
#include "base/etQueue.h"

#define MAX 1000

typedef struct etTestObject {
	etQueueObj base;
	etInt16 a;
	etInt16 b;
} etTestObject;

static void TestEtQueue_test(etInt16 id){
	etTestObject objects[MAX];
	int16 i;

	etQueue queue;
	etQueue_init(&queue);

	for(i=0; i<MAX; i++){
		objects[i].a = i;
		objects[i].b = i*2;
	}

	int j;
	for(j=0; j<3; j++){
		for (i=0; i<MAX; i++){
			etQueue_push(&queue, &(objects[i].base));
		}
		for (i=0; i<MAX; i++){
			etTestObject* obj = (etTestObject*) etQueue_pop(&queue);
			// EXPECTS are hidden to avoid too many testcases in log
			if (obj == NULL){
				EXPECT_FALSE(id, "obj == NULL", TRUE);
				break;
			}
			if (2*obj->a != obj->b){
				EXPECT_FALSE(id, "2*obj->a != obj->b", TRUE);
				break;
			}
			if (obj->a != i){
				EXPECT_FALSE(id, "obj->a != i", TRUE);
				break;
			}
		}
		EXPECT_EQUAL_INT32(id, "i==MAX", MAX, i);
	}
}

void TestEtQueue_runSuite(void){
	etUnit_openTestSuite("TestQueue");
	ADD_TESTCASE(TestEtQueue_test);
	etUnit_closeTestSuite();
}

Back to the top