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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
#include <Queue.h>
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain.
*/
void setup() {
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(13, OUTPUT);
Serial.begin(9600);
Serial.println("Alive");
int testStatus = 0;
testStatus |= test_addTooMany();
testStatus |= test_removeNonExistent();
testStatus |= test_tooManyCharacters();
testStatus |= test_changeNonExistent();
testStatus |= test_runEmpty();
if(testStatus == 0)
{
Serial.println("All tests passed.");
} else {
Serial.println("Something Failed.");
}
}
void loop() {
delay(1000);
}
int testFunction(unsigned long now)
{
Serial.print("Hello: ");
Serial.print(now);
Serial.println();
}
int test_addTooMany(void)
{
Queue testQueue;
int rv;
int testStatus = 0;
rv = testQueue.scheduleFunction(testFunction, "Test1", 5000, 1000);
if(rv != 0)
{
Serial.println("test_addTooMany failed.");
testStatus = -1;
}
rv = testQueue.scheduleFunction(testFunction, "Test2", 5000, 1000);
if(rv != 0)
{
Serial.println("test_addTooMany failed.");
testStatus = -1;
}
rv = testQueue.scheduleFunction(testFunction, "Test3", 5000, 1000);
if(rv != 0)
{
Serial.println("test_addTooMany failed.");
testStatus = -1;
}
rv = testQueue.scheduleFunction(testFunction, "Test4", 5000, 1000);
if(rv != 0)
{
Serial.println("test_addTooMany failed.");
testStatus = -1;
}
rv = testQueue.scheduleFunction(testFunction, "Test5", 5000, 1000);
if(rv != 0)
{
Serial.println("test_addTooMany failed.");
testStatus = -1;
}
rv = testQueue.scheduleFunction(testFunction, "Test6", 5000, 1000);
if(rv != 0)
{
Serial.println("test_addTooMany failed.");
testStatus = -1;
}
rv = testQueue.scheduleFunction(testFunction, "Test7", 5000, 1000);
if(rv != 0)
{
Serial.println("test_addTooMany failed.");
testStatus = -1;
}
rv = testQueue.scheduleFunction(testFunction, "Test8", 5000, 1000);
if(rv != 0)
{
Serial.println("test_addTooMany failed.");
testStatus = -1;
}
rv = testQueue.scheduleFunction(testFunction, "Test9", 5000, 1000);
if(rv != 0)
{
Serial.println("test_addTooMany failed.");
testStatus = -1;
}
rv = testQueue.scheduleFunction(testFunction, "Test10", 5000, 1000);
if(rv != 0)
{
Serial.println("test_addTooMany failed.");
testStatus = -1;
}
rv = testQueue.scheduleFunction(testFunction, "Test11", 5000, 1000);
if(rv != -1)
{
Serial.println("test_addTooMany failed.");
testStatus = -1;
}
return testStatus;
}
int test_removeNonExistent(void)
{
Queue testQueue;
int rv;
int testStatus = 0;
rv = testQueue.scheduleFunction(testFunction, "Test", 5000, 1000);
if(rv != 0)
{
Serial.println("test_removeNonExistent failed.");
testStatus = -1;
}
rv = testQueue.scheduleRemoveFunction("Fail");
if(rv != -1)
{
Serial.println("test_removeNonExistent failed.");
testStatus = -1;
}
return testStatus;
}
int test_tooManyCharacters(void)
{
Queue testQueue;
int rv;
int testStatus = 0;
rv = testQueue.scheduleFunction(testFunction, "ReallyLongName", 5000, 1000);
if(rv != -1)
{
Serial.println("test_tooManyCharacters failed.");
testStatus = -1;
}
return testStatus;
}
int test_changeNonExistent(void)
{
Queue testQueue;
int rv;
int testStatus = 0;
rv = testQueue.scheduleFunction(testFunction, "Test", 5000, 1000);
if(rv != 0)
{
Serial.println("test_changeNonExistent failed.");
testStatus = -1;
}
rv = testQueue.scheduleChangeFunction("Fail", 1000, 1000);
if(rv != -1)
{
Serial.println("test_changeNonExistent failed.");
testStatus = -1;
}
return testStatus;
}
int test_runEmpty(void)
{
Queue myQueue;
int rv = 0;
int testStatus = 0;
rv = myQueue.Run(10);
if (rv != -1)
{
Serial.println("test_runEmpty failed.");
testStatus = -1;
}
return testStatus;
}
|