-
Notifications
You must be signed in to change notification settings - Fork 1
/
chordtexttestsuite.cpp
266 lines (229 loc) · 7.36 KB
/
chordtexttestsuite.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
/////////////////////////////////////////////////////////////////////////////
// Name: chordtexttestsuite.cpp
// Purpose: Performs unit testing on the ChordText class
// Author: Brad Larsen
// Modified by:
// Created: Jan 3, 2005
// RCS-ID:
// Copyright: (c) Brad Larsen
// License: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#include "stdwx.h"
#include "chordtexttestsuite.h"
#include "chordtext.h"
#include "powertabfileheader.h" // Needed for file version constants
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
IMPLEMENT_DYNAMIC_CLASS(ChordTextTestSuite, TestSuite)
/// Default Constructor
ChordTextTestSuite::ChordTextTestSuite()
{
//------Last Checked------//
// - Jan 3, 2005
}
/// Destructor
ChordTextTestSuite::~ChordTextTestSuite()
{
//------Last Checked------//
// - Jan 3, 2005
}
/// Gets the total number of tests in the test suite
/// @return The total number of tests in the test suite
size_t ChordTextTestSuite::GetTestCount() const
{
//------Last Checked------//
// - Jan 3, 2005
return (528);
}
/// Executes all test cases in the test suite
/// @return True if all tests were executed, false if not
bool ChordTextTestSuite::RunTestCases()
{
//------Last Checked------//
// - Jan 3, 2005
if (!TestCaseConstructor())
return (false);
if (!TestCaseCreation())
return (false);
if (!TestCaseOperator())
return (false);
if (!TestCaseSerialize())
return (false);
if (!TestCasePosition())
return (false);
if (!TestCaseChordName())
return (false);
return (true);
}
/// Tests the Constructors
/// @return True if all tests were executed, false if not
bool ChordTextTestSuite::TestCaseConstructor()
{
//------Last Checked------//
// - Jan 3, 2005
ChordName chordName;
chordName.SetFormula(ChordName::minor);
// TEST CASE: Default constructor
{
ChordText chordText;
TEST(wxT("Default Constructor"),
(chordText.GetPosition() == 0)
);
}
// TEST CASE: Primary constructor
{
ChordText chordText(12, chordName);
TEST(wxT("Primary Constructor"),
(chordText.GetPosition() == 12) &&
(chordText.GetChordName() == chordName)
);
}
// TEST CASE: Copy constructor
{
ChordText chordText(12, chordName);
ChordText chordText2(chordText);
TEST(wxT("Copy Constructor"),
(chordText2.GetPosition() == 12) &&
(chordText2.GetChordName() == chordName)
);
}
return (true);
}
/// Tests the Creation Functions
/// @return True if all tests were executed, false if not
bool ChordTextTestSuite::TestCaseCreation()
{
//------Last Checked------//
// - Jan 12, 2005
ChordName chordName;
chordName.SetFormula(ChordName::minor);
ChordText chordText(12, chordName);
ChordText* clone = (ChordText*)chordText.CloneObject();
TEST(wxT("CloneObject"),
(*clone == chordText)
);
delete clone;
return (true);
}
/// Tests the Operators
/// @return True if all tests were executed, false if not
bool ChordTextTestSuite::TestCaseOperator()
{
//------Last Checked------//
// - Jan 3, 2005
ChordName chordName;
chordName.SetFormula(ChordName::minor);
ChordName chordName2;
chordName2.SetFormula(ChordName::augmented);
// TEST CASE: Operator=
{
ChordText chordText(12, chordName);
ChordText chordText2 = chordText;
TEST(wxT("Operator="),
(chordText2.GetPosition() == 12) &&
(chordText2.GetChordName() == chordName)
);
chordText = chordText;
TEST(wxT("Operator= (self-assignment)"),
(chordText == chordText)
);
}
// TEST CASE: Operator==
{
ChordText chordText(12, chordName);
ChordText chordText2(12, chordName);
ChordText chordText3(13, chordName);
ChordText chordText4(12, chordName2);
TEST(wxT("Operator== - chordText == chordText"),
(chordText == chordText2));
TEST(wxT("Operator== - chordText != chordText"),
!(chordText == chordText3));
TEST(wxT("Operator== - chordText != chordText 2"),
!(chordText == chordText4));
}
// TEST CASE: Operator!=
{
ChordText chordText(12, chordName);
ChordText chordText2(12, chordName);
ChordText chordText3(13, chordName);
ChordText chordText4(12, chordName2);
TEST(wxT("Operator!= - chordText == chordText"),
!(chordText != chordText2));
TEST(wxT("Operator!= - chordText != chordText"),
(chordText != chordText3));
TEST(wxT("Operator!= - chordText != chordText 2"),
(chordText != chordText4));
}
return (true);
}
/// Tests the Serialization Fucntions
/// @return True if all tests were executed, false if not
bool ChordTextTestSuite::TestCaseSerialize()
{
//------Last Checked------//
// - Jan 3, 2005
bool ok = false;
TestStream testStream;
PowerTabOutputStream streamOut(testStream.GetOutputStream());
// Write test data to stream
ChordText chordTextOut(12, ChordName());
chordTextOut.Serialize(streamOut);
// Output must be OK before using input
if (testStream.CheckOutputState())
{
PowerTabInputStream streamIn(testStream.GetInputStream());
// Read test data back from stream
ChordText chordTextIn;
chordTextIn.Deserialize(streamIn,
PowerTabFileHeader::FILEVERSION_CURRENT);
// Validate the data
ok = ((chordTextIn == chordTextOut)
&& (streamIn.CheckState()));
}
TEST(wxT("Serialize"), ok);
return (true);
}
/// Tests the Position Functions
/// @return True if all tests were executed, false if not
bool ChordTextTestSuite::TestCasePosition()
{
//------Last Checked------//
// - Jan 3, 2005
ChordText chordText;
// TEST CASE: IsValidPosition
{
wxUint32 i = 0;
for (; i <= 256; i++)
{
TEST(wxString::Format(wxT("IsValidPosition - %d"), i),
(ChordText::IsValidPosition(i) == (i < 256))
);
}
}
// TEST CASE: SetPosition
{
wxUint32 i = 0;
for (; i <= 256; i++)
{
TEST(wxString::Format(wxT("SetPosition - %d"), i),
(chordText.SetPosition(i) == (i < 256)) &&
((i == 256) ? 1 : (chordText.GetPosition() == i))
);
}
}
return (true);
}
/// Tests the Chord Name Functions
/// @return True if all tests were executed, false if not
bool ChordTextTestSuite::TestCaseChordName()
{
//------Last Checked------//
// - Jan 3, 2005
ChordName chordName;
chordName.SetFormula(ChordName::major6th);
ChordText chordText;
chordText.SetChordName(chordName);
TEST(wxT("SetChordName"), (chordName == chordText.GetChordName()));
return (true);
}