forked from Tracktion/tracktion_engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAudioNodeDev.h
220 lines (171 loc) · 7.45 KB
/
AudioNodeDev.h
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
/*******************************************************************************
The block below describes the properties of this PIP. A PIP is a short snippet
of code that can be read by the Projucer and used to generate a JUCE project.
BEGIN_JUCE_PIP_METADATA
name: AudioNodeDev
version: 0.0.1
vendor: Tracktion
website: www.tracktion.com
description: Used for development of the new audio graph.
dependencies: juce_audio_basics, juce_audio_devices, juce_audio_formats, juce_audio_processors, juce_audio_utils,
juce_core, juce_data_structures, juce_dsp, juce_events, juce_graphics,
juce_gui_basics, juce_gui_extra, juce_osc, tracktion_engine, tracktion_graph
exporters: linux_make, vs2017, xcode_iphone, xcode_mac
moduleFlags: JUCE_STRICT_REFCOUNTEDPOINTER=1, JUCE_PLUGINHOST_AU=1, JUCE_PLUGINHOST_VST3=1
defines: ENABLE_EXPERIMENTAL_TRACKTION_GRAPH=1, TRACKTION_UNIT_TESTS=1
type: Console
mainClass: AudioNodeDev
END_JUCE_PIP_METADATA
*******************************************************************************/
#pragma once
using namespace tracktion_engine;
//==============================================================================
//==============================================================================
class TestUIBehaviour : public UIBehaviour
{
public:
TestUIBehaviour() = default;
void runTaskWithProgressBar (ThreadPoolJobWithProgress& t) override
{
TaskRunner runner (t);
while (runner.isThreadRunning())
if (! MessageManager::getInstance()->runDispatchLoopUntil (10))
break;
}
private:
//==============================================================================
struct TaskRunner : public Thread
{
TaskRunner (ThreadPoolJobWithProgress& t)
: Thread (t.getJobName()), task (t)
{
startThread();
}
~TaskRunner() override
{
task.signalJobShouldExit();
waitForThreadToExit (10000);
}
void run() override
{
while (! threadShouldExit())
if (task.runJob() == ThreadPoolJob::jobHasFinished)
break;
}
ThreadPoolJobWithProgress& task;
};
};
//==============================================================================
//==============================================================================
class TestEngineBehaviour : public EngineBehaviour
{
public:
TestEngineBehaviour() = default;
bool autoInitialiseDeviceManager() override
{
return false;
}
};
//==============================================================================
//==============================================================================
struct CoutLogger : public Logger
{
void logMessage (const String& message) override
{
std::cout << message << "\n";
}
};
//==============================================================================
//==============================================================================
namespace JUnit
{
/** Creates a JUnit formatted ValueTree from a UnitTestRunner's results. */
ValueTree createJUnitResultValueTree (const UnitTestRunner::TestResult& result)
{
ValueTree testcase ("testcase");
testcase.setProperty ("classname", result.unitTestName, nullptr);
testcase.setProperty ("name", result.subcategoryName, nullptr);
for (auto message : result.messages)
testcase.appendChild (ValueTree { "failure", {{ "message", message }}}, nullptr);
return testcase;
}
/** Creates a JUnit formatted 'testsuite' ValueTree from a UnitTestRunner's results. */
ValueTree createJUnitValueTree (const String& testSuiteName, const UnitTestRunner& runner, RelativeTime duration)
{
ValueTree suite ("testsuite");
suite.setProperty ("name", testSuiteName, nullptr);
suite.setProperty ("tests", runner.getNumResults(), nullptr);
suite.setProperty ("timestamp", Time::getCurrentTime().toISO8601 (true), nullptr);
if (duration.inSeconds() > 0.0)
suite.setProperty ("time", duration.inSeconds(), nullptr);
int numFailures = 0;
for (int i = 0; i < runner.getNumResults(); ++i)
{
if (auto result = runner.getResult (i))
{
suite.appendChild (createJUnitResultValueTree (*result), nullptr);
numFailures += result->failures;
}
}
suite.setProperty ("failures", numFailures, nullptr);
return suite;
}
/** Creates a JUnit formatted 'testsuite' XmlElement from a UnitTestRunner's results. */
std::unique_ptr<XmlElement> createJUnitXML (const String& testSuiteName, const UnitTestRunner& runner, RelativeTime duration)
{
return createJUnitValueTree (testSuiteName, runner, duration).createXml();
}
/** Converts a UnitTestRunner's results to a JUnit formatted XML file. */
Result createJUnitXMLFile (const File& destinationFile, const String& testSuiteName, const UnitTestRunner& runner, RelativeTime duration)
{
if (auto xml = createJUnitXML (testSuiteName, runner, duration))
if (! xml->writeTo (destinationFile))
return Result::fail ("Unable to write to file at: " + destinationFile.getFullPathName());
return Result::ok();
}
}
//==============================================================================
//==============================================================================
namespace TestRunner
{
int runTests (const File& junitResultsFile)
{
CoutLogger logger;
Logger::setCurrentLogger (&logger);
tracktion_engine::Engine engine { ProjectInfo::projectName, std::make_unique<TestUIBehaviour>(), std::make_unique<TestEngineBehaviour>() };
UnitTestRunner testRunner;
testRunner.setAssertOnFailure (false);
Array<UnitTest*> tests;
tests.addArray (UnitTest::getTestsInCategory ("tracktion_graph"));
const auto startTime = Time::getCurrentTime();
testRunner.runTests (tests);
const auto endTime = Time::getCurrentTime();
int numFailues = 0;
for (int i = 0; i <= testRunner.getNumResults(); ++i)
if (auto result = testRunner.getResult (i))
numFailues += result->failures;
if (junitResultsFile != File())
{
junitResultsFile.create();
auto res = JUnit::createJUnitXMLFile (junitResultsFile, "Tracktion", testRunner, endTime - startTime);
if (res)
Logger::writeToLog ("Wrote junit results to :" + junitResultsFile.getFullPathName());
else
Logger::writeToLog (res.getErrorMessage());
}
Logger::setCurrentLogger (nullptr);
return numFailues > 0 ? 1 : 0;
}
}
//==============================================================================
//==============================================================================
int main (int argv, char** argc)
{
File junitFile;
for (int i = 1; i < argv; ++i)
if (String (argc[i]) == "--junit-xml-file")
if ((i + 1) < argv)
junitFile = String (argc[i + 1]);
ScopedJuceInitialiser_GUI init;
return TestRunner::runTests (junitFile);
}