-
Notifications
You must be signed in to change notification settings - Fork 1
/
dynamictestsuite.cpp
412 lines (362 loc) · 12.6 KB
/
dynamictestsuite.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
/////////////////////////////////////////////////////////////////////////////
// Name: dynamictestsuite.cpp
// Purpose: Performs unit testing on the Dynamic class
// Author: Brad Larsen
// Modified by:
// Created: Dec 10, 2004
// RCS-ID:
// Copyright: (c) Brad Larsen
// License: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#include "stdwx.h"
#include "dynamictestsuite.h"
#include "dynamic.h"
#include "powertabfileheader.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
IMPLEMENT_DYNAMIC_CLASS(DynamicTestSuite, TestSuite)
/// Default Constructor
DynamicTestSuite::DynamicTestSuite()
{
//------Last Checked------//
// - Jan 13, 2005
}
/// Destructor
DynamicTestSuite::~DynamicTestSuite()
{
//------Last Checked------//
// - Jan 13, 2005
}
/// Gets the total number of tests in the test suite
/// @return The total number of tests in the test suite
size_t DynamicTestSuite::GetTestCount() const
{
//------Last Checked------//
// - Jan 13, 2005
return (568);
}
/// Executes all test cases in the test suite
/// @return True if all tests were executed, false if not
bool DynamicTestSuite::RunTestCases()
{
//------Last Checked------//
// - Jan 13, 2005
if (!TestCaseConstructor())
return (false);
if (!TestCaseCreation())
return (false);
if (!TestCaseOperator())
return (false);
if (!TestCaseSerialize())
return (false);
if (!TestCaseSystem())
return (false);
if (!TestCaseStaff())
return (false);
if (!TestCasePosition())
return (false);
if (!TestCaseVolume())
return (false);
return (true);
}
/// Tests the Constructors
/// @return True if all tests were executed, false if not
bool DynamicTestSuite::TestCaseConstructor()
{
//------Last Checked------//
// - Jan 12, 2005
// TEST CASE: Default constructor
{
Dynamic dynamic;
TEST(wxT("Default Constructor"),
(dynamic.GetSystem() == Dynamic::DEFAULT_SYSTEM) &&
(dynamic.GetStaff() == Dynamic::DEFAULT_STAFF) &&
(dynamic.GetPosition() == Dynamic::DEFAULT_POSITION) &&
(dynamic.GetStaffVolume() == Dynamic::DEFAULT_STAFF_VOLUME) &&
(dynamic.GetRhythmSlashVolume() ==
Dynamic::DEFAULT_RHYTHM_SLASH_VOLUME)
);
}
// TEST CASE: Primary constructor
{
Dynamic dynamic(1,2,3,Dynamic::ff,Dynamic::mf);
TEST(wxT("Primary Constructor"),
(dynamic.GetSystem() == 1) &&
(dynamic.GetStaff() == 2) &&
(dynamic.GetPosition() == 3) &&
(dynamic.GetStaffVolume() == Dynamic::ff) &&
(dynamic.GetRhythmSlashVolume() == Dynamic::mf)
);
}
// TEST CASE: Copy constructor
{
Dynamic dynamic(1,2,3,Dynamic::ff,Dynamic::mf);
Dynamic dynamic2(dynamic);
TEST(wxT("Copy Constructor"),
(dynamic == dynamic2)
);
}
return (true);
}
/// Tests the Creation Functions
/// @return True if all tests were executed, false if not
bool DynamicTestSuite::TestCaseCreation()
{
//------Last Checked------//
// - Jan 12, 2005
Dynamic dynamic(1,2,3,Dynamic::ff,Dynamic::mf);
Dynamic* clone = (Dynamic*)dynamic.CloneObject();
TEST(wxT("CloneObject"),
(*clone == dynamic)
);
delete clone;
return (true);
}
/// Tests the Operators
/// @return True if all tests were executed, false if not
bool DynamicTestSuite::TestCaseOperator()
{
//------Last Checked------//
// - Jan 12, 2005
// TEST CASE: Assignment Operator
{
Dynamic dynamic(1,2,3,Dynamic::ff,Dynamic::mf);
Dynamic dynamic2 = dynamic;
TEST(wxT("Operator="),
(dynamic == dynamic2)
);
// TEST CASE: Operator= (self-assignment)
dynamic = dynamic;
TEST(wxT("Operator= (self-assignment)"),
(dynamic == dynamic)
);
}
// TEST CASE: Equality Operator
{
Dynamic dynamic(1,2,3,Dynamic::ff,Dynamic::mf);
Dynamic dynamic2(1,2,3,Dynamic::ff,Dynamic::mf);
Dynamic dynamic3(2,2,3,Dynamic::ff,Dynamic::mf);
Dynamic dynamic4(1,3,3,Dynamic::ff,Dynamic::mf);
Dynamic dynamic5(1,2,4,Dynamic::ff,Dynamic::mf);
Dynamic dynamic6(1,2,3,Dynamic::fff,Dynamic::mf);
Dynamic dynamic7(1,2,3,Dynamic::ff,Dynamic::f);
TEST(wxT("Operator== - dynamic == dynamic"), (dynamic == dynamic2));
TEST(wxT("Operator== - dynamic != dynamic"), !(dynamic == dynamic3));
TEST(wxT("Operator== - dynamic != dynamic 2"), !(dynamic == dynamic4));
TEST(wxT("Operator== - dynamic != dynamic 3"), !(dynamic == dynamic5));
TEST(wxT("Operator== - dynamic != dynamic 4"), !(dynamic == dynamic6));
TEST(wxT("Operator== - dynamic != dynamic 5"), !(dynamic == dynamic7));
}
// TEST CASE: Inequality Operator
{
Dynamic dynamic(1,2,3,Dynamic::ff,Dynamic::mf);
Dynamic dynamic2(1,2,3,Dynamic::ff,Dynamic::mf);
Dynamic dynamic3(2,2,3,Dynamic::ff,Dynamic::mf);
Dynamic dynamic4(1,3,3,Dynamic::ff,Dynamic::mf);
Dynamic dynamic5(1,2,4,Dynamic::ff,Dynamic::mf);
Dynamic dynamic6(1,2,3,Dynamic::fff,Dynamic::mf);
Dynamic dynamic7(1,2,3,Dynamic::ff,Dynamic::f);
TEST(wxT("Operator!= - dynamic == dynamic"), !(dynamic != dynamic2));
TEST(wxT("Operator!= - dynamic != dynamic"), (dynamic != dynamic3));
TEST(wxT("Operator!= - dynamic != dynamic 2"), (dynamic != dynamic4));
TEST(wxT("Operator!= - dynamic != dynamic 3"), (dynamic != dynamic5));
TEST(wxT("Operator!= - dynamic != dynamic 4"), (dynamic != dynamic6));
TEST(wxT("Operator!= - dynamic != dynamic 5"), (dynamic != dynamic7));
}
return (true);
}
/// Tests the Serialization Functions
/// @return True if all tests were executed, false if not
bool DynamicTestSuite::TestCaseSerialize()
{
//------Last Checked------//
// - Jan 12, 2005
bool ok = false;
TestStream testStream;
PowerTabOutputStream streamOut(testStream.GetOutputStream());
// Write test data to stream
Dynamic dynamicOut(1,2,3,Dynamic::f,Dynamic::mf);
dynamicOut.Serialize(streamOut);
// Output must be OK before using input
if (testStream.CheckOutputState())
{
PowerTabInputStream streamIn(testStream.GetInputStream());
// Read test data back from stream
Dynamic dynamicIn;
dynamicIn.Deserialize(streamIn,
PowerTabFileHeader::FILEVERSION_CURRENT);
// Validate the data
ok = ((dynamicIn == dynamicOut)
&& (streamIn.CheckState()));
}
TEST(wxT("Serialize"), ok);
return (true);
}
/// Tests the System Functions
/// @return True if all tests were executed, false if not
bool DynamicTestSuite::TestCaseSystem()
{
//------Last Checked------//
// - Jan 12, 2005
// Note: Using a loop to test all values runs too slow
const wxUint32 testValueCount = 4;
wxUint32 testValues[testValueCount];
testValues[0] = 0;
testValues[1] = 16384;
testValues[2] = 65535;
testValues[3] = 65536;
// TEST CASE: IsValidSystem
{
wxUint32 i = 0;
for (; i < testValueCount; i++)
{
TEST(wxString::Format(wxT("IsValidSystem - %d"), testValues[i]),
(Dynamic::IsValidSystem(testValues[i]) == (i < 3))
);
}
}
// TEST CASE: SetSystem
{
Dynamic dynamic;
wxUint32 i = 0;
for (; i < testValueCount; i++)
{
TEST(wxString::Format(wxT("SetSystem - %d"), testValues[i]),
(dynamic.SetSystem(testValues[i]) == (i < 3)) &&
((i == 3) ? 1 : (dynamic.GetSystem() == testValues[i]))
);
}
}
return (true);
}
/// Tests the Staff Functions
/// @return True if all tests were executed, false if not
bool DynamicTestSuite::TestCaseStaff()
{
//------Last Checked------//
// - Jan 12, 2005
// TEST CASE: IsValidStaff
{
wxUint32 i = 0;
for (; i <= (Dynamic::MAX_STAFF + 1); i++)
{
TEST(wxString::Format(wxT("IsValidStaff - %d"), i),
(Dynamic::IsValidStaff(i) == (i <= Dynamic::MAX_STAFF))
);
}
}
// TEST CASE: SetStaff
{
Dynamic dynamic;
wxUint32 i = 0;
for (; i <= (Dynamic::MAX_STAFF + 1); i++)
{
TEST(wxString::Format(wxT("SetStaff - %d"), i),
(dynamic.SetStaff(i) == (i <= Dynamic::MAX_STAFF)) &&
((i > Dynamic::MAX_STAFF) ? 1 : (dynamic.GetStaff() == i))
);
}
}
return (true);
}
/// Tests the Position Functions
/// @return True if all tests were executed, false if not
bool DynamicTestSuite::TestCasePosition()
{
//------Last Checked------//
// - Jan 12, 2005
// TEST CASE: IsValidPosition
{
wxUint32 i = 0;
for (; i <= (Dynamic::MAX_POSITION + 1); i++)
{
TEST(wxString::Format(wxT("IsValidPosition - %d"), i),
(Dynamic::IsValidPosition(i) == (i <= Dynamic::MAX_POSITION))
);
}
}
// TEST CASE: SetPosition
{
Dynamic dynamic;
wxUint32 i = 0;
for (; i <= (Dynamic::MAX_POSITION + 1); i++)
{
TEST(wxString::Format(wxT("SetPosition - %d"), i),
(dynamic.SetPosition(i) == (i <= Dynamic::MAX_POSITION)) &&
((i > Dynamic::MAX_POSITION) ? 1 : (dynamic.GetPosition() == i))
);
}
}
return (true);
}
/// Tests the Volume Functions
/// @return True if all tests were executed, false if not
bool DynamicTestSuite::TestCaseVolume()
{
//------Last Checked------//
// - Jan 12, 2005
// TEST CASE: IsValidVolume
{
const wxUint32 testValueCount = 11;
wxByte testValues[testValueCount];
testValues[0] = Dynamic::notSet;
testValues[1] = Dynamic::fff;
testValues[2] = Dynamic::ff;
testValues[3] = Dynamic::f;
testValues[4] = Dynamic::mf;
testValues[5] = Dynamic::mp;
testValues[6] = Dynamic::p;
testValues[7] = Dynamic::pp;
testValues[8] = Dynamic::ppp;
testValues[9] = Dynamic::off;
testValues[10] = Dynamic::notSet - 1;
wxUint32 i = 0;
for (; i < testValueCount; i++)
TEST(wxString::Format(wxT("IsValidVolume - %d"), i),
(Dynamic::IsValidVolume(testValues[i]) ==
(testValues[i] != (Dynamic::notSet - 1)))
);
}
// TEST CASE: SetStaffVolume
{
Dynamic dynamic;
TEST(wxT("SetStaffVolume - invalid volume"),
!dynamic.SetStaffVolume(Dynamic::notSet - 1));
TEST(wxT("SetStaffVolume - valid volume"),
(dynamic.SetStaffVolume(Dynamic::ff)) &&
(dynamic.GetStaffVolume() == Dynamic::ff) &&
(dynamic.IsStaffVolumeSet())
);
}
// TEST CASE: SetRhythmSlashVolume
{
Dynamic dynamic;
TEST(wxT("SetRhythmSlashVolume - invalid volume"),
!dynamic.SetRhythmSlashVolume(Dynamic::notSet - 1));
TEST(wxT("SetRhythmSlashVolume - valid volume"),
(dynamic.SetRhythmSlashVolume(Dynamic::ff)) &&
(dynamic.GetRhythmSlashVolume() == Dynamic::ff) &&
(dynamic.IsRhythmSlashVolumeSet())
);
}
// TEST CASE: SetVolume
{
Dynamic dynamic;
TEST(wxT("SetVolume - invalid staff volume"),
!dynamic.SetVolume(false, Dynamic::notSet - 1));
TEST(wxT("SetVolume - staff valid"),
(dynamic.SetVolume(false, Dynamic::ff)) &&
(dynamic.GetVolume(false) == Dynamic::ff) &&
(dynamic.IsVolumeSet(false))
);
TEST(wxT("SetVolume - invalid rhythm slash volume"),
!dynamic.SetVolume(true, Dynamic::notSet - 1));
TEST(wxT("SetVolume - rhythm slash valid"),
(dynamic.SetVolume(true, Dynamic::ff)) &&
(dynamic.GetVolume(true) == Dynamic::ff) &&
(dynamic.IsVolumeSet(true))
);
}
return (true);
}