forked from RaptDept/ptparser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdirectiontestsuite.cpp
444 lines (386 loc) · 14.1 KB
/
directiontestsuite.cpp
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
/////////////////////////////////////////////////////////////////////////////
// Name: directiontestsuite.cpp
// Purpose: Performs unit testing on the Direction class
// Author: Brad Larsen
// Modified by:
// Created: Jan 9, 2005
// RCS-ID:
// Copyright: (c) Brad Larsen
// License: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#include "stdwx.h"
#include "directiontestsuite.h"
#include "direction.h"
#include "powertabfileheader.h" // Needed for file version constants
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
IMPLEMENT_DYNAMIC_CLASS(DirectionTestSuite, TestSuite)
/// Default Constructor
DirectionTestSuite::DirectionTestSuite()
{
//------Last Checked------//
// - Jan 11, 2005
}
/// Destructor
DirectionTestSuite::~DirectionTestSuite()
{
//------Last Checked------//
// - Jan 11, 2005
}
/// Gets the total number of tests in the test suite
/// @return The total number of tests in the test suite
size_t DirectionTestSuite::GetTestCount() const
{
//------Last Checked------//
// - Jan 11, 2005
return (602);
}
/// Executes all test cases in the test suite
/// @return True if all tests were executed, false if not
bool DirectionTestSuite::RunTestCases()
{
//------Last Checked------//
// - Jan 11, 2005
if (!TestCaseConstructor())
return (false);
if (!TestCaseCreation())
return (false);
if (!TestCaseOperator())
return (false);
if (!TestCaseSerialize())
return (false);
if (!TestCasePosition())
return (false);
if (!TestCaseSymbolType())
return (false);
if (!TestCaseActiveSymbol())
return (false);
if (!TestCaseRepeatNumber())
return (false);
if (!TestCaseSymbolArray())
return (false);
if (!TestCaseOperations())
return (false);
return (true);
}
/// Tests the Constructors
/// @return True if all tests were executed, false if not
bool DirectionTestSuite::TestCaseConstructor()
{
//------Last Checked------//
// - Jan 11, 2005
// TEST CASE: Default constructor
{
Direction direction;
TEST(wxT("Default Constructor"),
(direction.GetPosition() == Direction::DEFAULT_POSITION) &&
(direction.GetSymbolCount() == 0)
);
}
// TEST CASE: Primary constructor
{
Direction direction(12, Direction::toCoda, Direction::activeDaCapo, 4);
wxByte symbolType = 0;
wxByte activeSymbol = 0;
wxByte repeatNumber = 0;
bool ok = direction.GetSymbol(0, symbolType, activeSymbol, repeatNumber);
TEST(wxT("Primary Constructor"),
(ok) &&
(direction.GetPosition() == 12) &&
(symbolType == Direction::toCoda) &&
(activeSymbol == Direction::activeDaCapo) &&
(repeatNumber == 4)
);
}
// TEST CASE: Copy constructor
{
Direction direction(12, Direction::toCoda, Direction::activeDaCapo, 4);
Direction direction2(direction);
TEST(wxT("Copy Constructor"),
(direction2 == direction)
);
}
return (true);
}
/// Tests the Creation Functions
/// @return True if all tests were executed, false if not
bool DirectionTestSuite::TestCaseCreation()
{
//------Last Checked------//
// - Jan 11, 2005
Direction direction(12, Direction::toCoda, Direction::activeDaCapo, 4);
Direction* clone = (Direction*)direction.CloneObject();
TEST(wxT("CloneObject"),
(*clone == direction)
);
delete clone;
return (true);
}
/// Tests the Operators
/// @return True if all tests were executed, false if not
bool DirectionTestSuite::TestCaseOperator()
{
//------Last Checked------//
// - Jan 11, 2005
// TEST CASE: Operator=
{
Direction direction(12, Direction::toCoda, Direction::activeDaCapo, 4);
Direction direction2 = direction;
TEST(wxT("Operator="),
(direction2 == direction)
);
direction = direction;
TEST(wxT("Operator= (self-assignment)"),
(direction == direction)
);
}
// TEST CASE: Operator==
{
Direction direction(12, Direction::toCoda, Direction::activeDaCapo, 4);
Direction direction2(12, Direction::toCoda, Direction::activeDaCapo, 4);
Direction direction3(13, Direction::toDoubleCoda,
Direction::activeDaCapo, 4);
Direction direction4(12, Direction::toCoda, Direction::activeNone, 4);
Direction direction5(12, Direction::toCoda, Direction::activeDaCapo, 5);
Direction direction6(12, Direction::toCoda, Direction::activeDaCapo, 4);
direction6.AddSymbol(Direction::toDoubleCoda, Direction::activeDaCapo,
4);
TEST(wxT("Operator== - direction == direction"),
(direction == direction2));
TEST(wxT("Operator== - direction != direction"),
!(direction == direction3));
TEST(wxT("Operator== - direction != direction 2"),
!(direction == direction4));
TEST(wxT("Operator== - direction != direction 3"),
!(direction == direction5));
TEST(wxT("Operator== - direction != direction 4"),
!(direction == direction6));
}
// TEST CASE: Operator!=
{
Direction direction(12, Direction::toCoda, Direction::activeDaCapo, 4);
Direction direction2(12, Direction::toCoda, Direction::activeDaCapo, 4);
Direction direction3(13, Direction::toDoubleCoda,
Direction::activeDaCapo, 4);
Direction direction4(12, Direction::toCoda, Direction::activeNone, 4);
Direction direction5(12, Direction::toCoda, Direction::activeDaCapo, 5);
Direction direction6(12, Direction::toCoda, Direction::activeDaCapo, 4);
direction6.AddSymbol(Direction::toDoubleCoda, Direction::activeDaCapo,
4);
TEST(wxT("Operator!= - direction == direction"),
!(direction != direction2));
TEST(wxT("Operator!= - direction != direction"),
(direction != direction3));
TEST(wxT("Operator!= - direction != direction 2"),
(direction != direction4));
TEST(wxT("Operator!= - direction != direction 3"),
(direction != direction5));
TEST(wxT("Operator!= - direction != direction 4"),
(direction != direction6));
}
return (true);
}
/// Tests the Serialization Fucntions
/// @return True if all tests were executed, false if not
bool DirectionTestSuite::TestCaseSerialize()
{
//------Last Checked------//
// - Jan 11, 2005
bool ok = false;
TestStream testStream;
PowerTabOutputStream streamOut(testStream.GetOutputStream());
// Write test data to stream
Direction directionOut(12, Direction::toCoda, Direction::activeDaCapo, 4);
directionOut.Serialize(streamOut);
// Output must be OK before using input
if (testStream.CheckOutputState())
{
PowerTabInputStream streamIn(testStream.GetInputStream());
// Read test data back from stream
Direction directionIn;
directionIn.Deserialize(streamIn,
PowerTabFileHeader::FILEVERSION_CURRENT);
// Validate the data
ok = ((directionIn == directionOut)
&& (streamIn.CheckState()));
}
TEST(wxT("Serialize"), ok);
return (true);
}
/// Tests the Position Functions
/// @return True if all tests were executed, false if not
bool DirectionTestSuite::TestCasePosition()
{
//------Last Checked------//
// - Jan 11, 2005
Direction direction;
// TEST CASE: IsValidPosition
{
wxUint32 i = 0;
for (; i <= (Direction::MAX_POSITION + 1); i++)
{
TEST(wxString::Format(wxT("IsValidPosition - %d"), i),
(Direction::IsValidPosition(i) ==
(i <= Direction::MAX_POSITION))
);
}
}
// TEST CASE: SetPosition
{
wxUint32 i = 0;
for (; i <= (Direction::MAX_POSITION + 1); i++)
{
TEST(wxT("SetPosition - %d"),
(direction.SetPosition(i) == (i <= Direction::MAX_POSITION)) &&
((i > Direction::MAX_POSITION) ? 1 :
(direction.GetPosition() == i))
);
}
}
return (true);
}
/// Tests the Symbol Type Functions
/// @return True if all tests were executed, false if not
bool DirectionTestSuite::TestCaseSymbolType()
{
//------Last Checked------//
// - Jan 11, 2005
wxByte i = Direction::coda;
for (; i <= (Direction::dalSegnoSegnoAlFine + 1); i++)
TEST(wxString::Format(wxT("IsValidSymbolType - %d"), i),
(Direction::IsValidSymbolType(i) ==
(i <= Direction::dalSegnoSegnoAlFine))
);
return (true);
}
/// Tests the Active Symbol Functions
/// @return True if all tests were executed, false if not
bool DirectionTestSuite::TestCaseActiveSymbol()
{
//------Last Checked------//
// - Jan 11, 2005
wxByte i = Direction::activeNone;
for (; i <= (Direction::activeDalSegnoSegno + 1); i++)
TEST(wxString::Format(wxT("IsValidActiveSymbol - %d"), i),
(Direction::IsValidActiveSymbol(i) ==
(i <= Direction::activeDalSegnoSegno))
);
return (true);
}
/// Tests the Repeat Number Functions
/// @return True if all tests were executed, false if not
bool DirectionTestSuite::TestCaseRepeatNumber()
{
//------Last Checked------//
// - Jan 11, 2005
wxByte i = 0;
for (; i <= (Direction::MAX_REPEAT_NUMBER + 1); i++)
TEST(wxString::Format(wxT("IsValidRepeatNumber - %d"), i),
(Direction::IsValidRepeatNumber(i) ==
(i <= Direction::MAX_REPEAT_NUMBER))
);
return (true);
}
/// Tests the Symbol Array Functions
bool DirectionTestSuite::TestCaseSymbolArray()
{
//------Last Checked------//
// - Jan 11, 2005
Direction direction(12, Direction::toCoda, Direction::activeDaCapo, 4);
direction.AddSymbol(Direction::toDoubleCoda, Direction::activeDalSegno, 5);
direction.AddSymbol(Direction::coda);
// TEST CASE: IsValidSymbolIndex
{
wxUint32 i = 0;
for (; i <= Direction::MAX_SYMBOLS; i++)
TEST(wxString::Format(wxT("IsValidSymbolIndex - %d"), i),
(direction.IsValidSymbolIndex(i) == (i < Direction::MAX_SYMBOLS))
);
}
// TEST CASE: AddSymbol
{
Direction direction2;
TEST(wxT("AddSymbol"),
(direction2.AddSymbol(Direction::toCoda, Direction::activeDaCapo,
5)) && (direction2.GetSymbolCount() == 1)
);
TEST(wxT("AddSymbol - full"),
(!direction.AddSymbol(Direction::doubleCoda)));
}
// TEST CASE: GetSymbolCount
{
TEST(wxT("GetSymbolCount"), (direction.GetSymbolCount() == 3));
}
// TEST CASE: SetSymbol
{
Direction direction2(12, Direction::toCoda, Direction::activeDaCapo, 5);
TEST(wxT("SetSymbol - invalid index"),
(!direction2.SetSymbol(Direction::MAX_SYMBOLS, Direction::coda,
Direction::activeNone, 0))
);
TEST(wxT("SetSymbol - invalid symbol type"),
(!direction2.SetSymbol(0, 255, Direction::activeNone, 0))
);
TEST(wxT("SetSymbol - invalid active symbol"),
(!direction2.SetSymbol(0, Direction::coda, 255, 0))
);
TEST(wxT("SetSymbol - invalid repeat number"),
(!direction2.SetSymbol(0, Direction::coda, Direction::activeNone,
Direction::MAX_REPEAT_NUMBER + 1))
);
direction2.SetSymbol(0, Direction::coda, Direction::activeNone, 0);
wxByte symbolType = 0;
wxByte activeSymbol = 0;
wxByte repeatNumber = 0;
direction2.GetSymbol(0, symbolType, activeSymbol, repeatNumber);
TEST(wxT("SetSymbol"),
(symbolType == Direction::coda) &&
(activeSymbol == Direction::activeNone) &&
(repeatNumber == 0)
);
}
// TEST CASE: IsSymbolType
{
TEST(wxT("IsSymbolType - invalid index"),
(!direction.IsSymbolType(Direction::MAX_SYMBOLS, Direction::toCoda))
);
TEST(wxT("IsSymbolType - invalid symbol type"),
(!direction.IsSymbolType(0, 255))
);
TEST(wxT("IsSymbolType"),
(direction.IsSymbolType(0, Direction::toCoda)) &&
(direction.IsSymbolType(1, Direction::toDoubleCoda)) &&
(direction.IsSymbolType(2, Direction::coda))
);
}
// TEST CASE: RemoveSymbolAtIndex
{
TEST(wxT("RemoveSymbolAtIndex - invalid index"),
(!direction.RemoveSymbolAtIndex(Direction::MAX_SYMBOLS))
);
TEST(wxT("RemoveSymbolAtIndex"),
(direction.RemoveSymbolAtIndex(0)) &&
(direction.GetSymbolCount() == 2)
);
}
// TEST CASE: DeleteSymbolArrayContents
{
direction.DeleteSymbolArrayContents();
TEST(wxT("DeleteSymbolArrayContents"),
(direction.GetSymbolCount() == 0)
);
}
return (true);
}
/// Tests the Operations
/// @return True if all tests were executed, false if not
bool DirectionTestSuite::TestCaseOperations()
{
//------Last Checked------//
// - Jan 11, 2005
Direction direction(12, Direction::toCoda, Direction::activeDaCapo, 4);
TEST(wxT("GetText - invalid symbol index"), (!direction.GetText(1)));
TEST(wxT("GetText"), (direction.GetText(0) == wxT("To Coda")));
return (true);
}