openshot-audio  0.1.7
juce_UnitTest.h
Go to the documentation of this file.
1 /*
2  ==============================================================================
3 
4  This file is part of the juce_core module of the JUCE library.
5  Copyright (c) 2015 - ROLI Ltd.
6 
7  Permission to use, copy, modify, and/or distribute this software for any purpose with
8  or without fee is hereby granted, provided that the above copyright notice and this
9  permission notice appear in all copies.
10 
11  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
12  TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
13  NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
15  IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
16  CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 
18  ------------------------------------------------------------------------------
19 
20  NOTE! This permissive ISC license applies ONLY to files within the juce_core module!
21  All other JUCE modules are covered by a dual GPL/commercial license, so if you are
22  using any other modules, be sure to check that you also comply with their license.
23 
24  For more details, visit www.juce.com
25 
26  ==============================================================================
27 */
28 
29 #ifndef JUCE_UNITTEST_H_INCLUDED
30 #define JUCE_UNITTEST_H_INCLUDED
31 
32 class UnitTestRunner;
33 
34 
35 //==============================================================================
74 {
75 public:
76  //==============================================================================
78  explicit UnitTest (const String& name);
79 
81  virtual ~UnitTest();
82 
84  const String& getName() const noexcept { return name; }
85 
90  void performTest (UnitTestRunner* runner);
91 
93  static Array<UnitTest*>& getAllTests();
94 
95  //==============================================================================
99  virtual void initialise();
100 
104  virtual void shutdown();
105 
111  virtual void runTest() = 0;
112 
113  //==============================================================================
118  void beginTest (const String& testName);
119 
120  //==============================================================================
139  void expect (bool testResult, const String& failureMessage = String::empty);
140 
144  template <class ValueType>
145  void expectEquals (ValueType actual, ValueType expected, String failureMessage = String::empty)
146  {
147  const bool result = (actual == expected);
148 
149  if (! result)
150  {
151  if (failureMessage.isNotEmpty())
152  failureMessage << " -- ";
153 
154  failureMessage << "Expected value: " << expected << ", Actual value: " << actual;
155  }
156 
157  expect (result, failureMessage);
158  }
159 
160  //==============================================================================
164  void logMessage (const String& message);
165 
180  Random getRandom() const;
181 
182 private:
183  //==============================================================================
184  const String name;
185  UnitTestRunner* runner;
186 
188 };
189 
190 
191 //==============================================================================
204 {
205 public:
206  //==============================================================================
208  UnitTestRunner();
209 
211  virtual ~UnitTestRunner();
212 
221  void runTests (const Array<UnitTest*>& tests, int64 randomSeed = 0);
222 
229  void runAllTests (int64 randomSeed = 0);
230 
234  void setAssertOnFailure (bool shouldAssert) noexcept;
235 
239  void setPassesAreLogged (bool shouldDisplayPasses) noexcept;
240 
241  //==============================================================================
248  struct TestResult
249  {
254 
256  int passes;
258  int failures;
259 
262  };
263 
267  int getNumResults() const noexcept;
268 
272  const TestResult* getResult (int index) const noexcept;
273 
274 protected:
278  virtual void resultsUpdated();
279 
284  virtual void logMessage (const String& message);
285 
289  virtual bool shouldAbortTests();
290 
291 private:
292  //==============================================================================
293  friend class UnitTest;
294 
295  UnitTest* currentTest;
296  String currentSubCategory;
298  bool assertOnFailure, logPasses;
299  Random randomForTest;
300 
301  void beginNewTest (UnitTest* test, const String& subCategory);
302  void endTest();
303 
304  void addPass();
305  void addFail (const String& failureMessage);
306 
308 };
309 
310 
311 #endif // JUCE_UNITTEST_H_INCLUDED
void expectEquals(ValueType actual, ValueType expected, String failureMessage=String::empty)
Definition: juce_UnitTest.h:145
String subcategoryName
Definition: juce_UnitTest.h:253
static const String empty
Definition: juce_String.h:152
#define noexcept
Definition: juce_CompilerSupport.h:141
StringArray messages
Definition: juce_UnitTest.h:261
Definition: juce_UnitTest.h:248
String unitTestName
Definition: juce_UnitTest.h:251
const String & getName() const noexcept
Definition: juce_UnitTest.h:84
Definition: juce_String.h:43
#define JUCE_API
Definition: juce_StandardHeader.h:139
Definition: juce_Random.h:39
Definition: juce_CriticalSection.h:47
int failures
Definition: juce_UnitTest.h:258
Definition: juce_UnitTest.h:73
long long int64
Definition: juce_MathsFunctions.h:60
Definition: juce_StringArray.h:39
Definition: juce_UnitTest.h:203
Definition: juce_Array.h:60
Definition: juce_OwnedArray.h:55
#define JUCE_DECLARE_NON_COPYABLE(className)
Definition: juce_PlatformDefs.h:191
int passes
Definition: juce_UnitTest.h:256