This repository has been archived by the owner on Jan 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
/
SequenceTest.cpp
174 lines (128 loc) · 4.45 KB
/
SequenceTest.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
#include "Sequence.h"
#include "DirManager.h"
#include <wx/hash.h>
#include <vector>
#include <iostream>
class SequenceTest
{
private:
Sequence *mSequence;
DirManager *mDirManager;
std::vector<float> mMemorySequence;
public:
SequenceTest()
{
std::cout << "==> Testing Sequence\n";
srand(time(NULL));
}
void SetUp()
{
DirManager::SetTempDir("/tmp/sequence-test-dir");
mDirManager = new DirManager;
mSequence = new Sequence(mDirManager, floatSample);
mMemorySequence.clear();
}
void TearDown()
{
delete mSequence;
delete mDirManager;
mMemorySequence.clear();
}
void TestReferencing()
{
/* Thrash the Sequence through repeated appends, deletes, etc.
* Then delete the sequence and ensure that all blocks have
* been unreferenced to the point of deletion -- the dirmanager
* should be empty. */
std::cout << "\tafter thrashing the sequence and deleting it, all block files should have been deleted..." << std::flush;
int appendBufLen = (int)(mSequence->GetMaxBlockSize() * 1.4);
samplePtr appendBuf = NewSamples(appendBufLen, floatSample);
int i;
for(i = 0; i < 10; i++)
mSequence->Append(appendBuf, floatSample, appendBufLen);
for(i = 0; i < 10; i++)
{
Sequence *tmpSequence;
/* append */
mSequence->Append(appendBuf, floatSample, appendBufLen);
/* copy/paste */
int s0 = rand()%mSequence->GetNumSamples();
int len = rand()%(mSequence->GetNumSamples() - s0);
mSequence->Copy(s0, s0+len, &tmpSequence);
int dest = rand()%mSequence->GetNumSamples();
mSequence->Paste(dest, tmpSequence);
delete tmpSequence;
/* delete */
int del = rand()%mSequence->GetNumSamples();
int dellen = rand()%((mSequence->GetNumSamples()-del)/2);
mSequence->Delete(del, dellen);
}
delete mSequence;
mSequence = NULL;
assert(mDirManager->blockFileHash->GetCount() == 0);
std::cout << "ok\n";
}
void TestSetGarbageInput()
{
std::cout << "\tSequence::Set() should return false (and not crash) if given garbage input..." << std::flush;
/* Create 10 samples in the sequence so the Set requests will
* be valid */
samplePtr appendBuf = NewSamples(10, floatSample);
mSequence->Append(appendBuf, floatSample, 10);
/* should fail, "set" buffer should not be null */
assert(mSequence->Set(NULL, floatSample, 0, 10) == false);
/* should fail, -5 is not a sample format */
assert(mSequence->Set(appendBuf, (sampleFormat)-5, 0, 10) == false);
/* should fail, -1 is not a valid offset */
assert(mSequence->Set(appendBuf, floatSample, -1, 10) == false);
/* should fail, the sequence is only 10 samples long */
assert(mSequence->Set(appendBuf, floatSample, 0, 15) == false);
std::cout << "ok\n";
}
void TestGetGarbageInput()
{
std::cout << "\tSequence::Get() should return false (and not crash) if given garbage input..." << std::flush;
/* Create 10 samples in the sequence so the Set requests will
* be valid */
samplePtr appendBuf = NewSamples(10, floatSample);
mSequence->Append(appendBuf, floatSample, 10);
/* should fail, "get" buffer should not be null */
assert(mSequence->Get(NULL, floatSample, 0, 10) == false);
/* should fail, -1 is not a valid offset */
assert(mSequence->Get(appendBuf, floatSample, -1, 10) == false);
/* should fail, the sequence is only 10 samples long */
assert(mSequence->Get(appendBuf, floatSample, 0, 15) == false);
std::cout << "ok\n";
}
};
int main()
{
SequenceTest tester;
tester.SetUp();
tester.TestReferencing();
tester.TearDown();
tester.SetUp();
tester.TestSetGarbageInput();
tester.TearDown();
tester.SetUp();
tester.TestGetGarbageInput();
tester.TearDown();
return 0;
}
class wxWindow;
void ShowWarningDialog(wxWindow *parent,
wxString internalDialogName,
wxString message)
{
std::cout << "warning: " << message << std::endl;
}
// Indentation settings for Vim and Emacs and unique identifier for Arch, a
// version control system. Please do not modify past this point.
//
// Local Variables:
// c-basic-offset: 3
// indent-tabs-mode: nil
// End:
//
// vim: et sts=3 sw=3
// arch-tag: 854b5b56-912e-4903-97f6-55314045153d