OpenShot Library | libopenshot-audio
0.2.0
|
27 : name (nm), category (ctg)
51 if (test->getCategory() == category)
62 if (test->getCategory().isNotEmpty())
73 jassert (newRunner !=
nullptr);
84 jassert (runner !=
nullptr);
92 jassert (runner !=
nullptr);
94 runner->beginNewTest (
this, testName);
100 jassert (runner !=
nullptr);
105 runner->addFail (failureMessage);
111 jassert (runner !=
nullptr);
113 return runner->randomForTest;
117 UnitTestRunner::UnitTestRunner() {}
122 assertOnFailure = shouldAssert;
127 logPasses = shouldDisplayPasses;
132 return results.size();
137 return results [index];
152 randomForTest =
Random (randomSeed);
155 for (
auto* t : tests)
160 #if JUCE_EXCEPTIONS_DISABLED
161 t->performTest (
this);
165 t->performTest (
this);
169 addFail (
"An unhandled exception was thrown!");
197 void UnitTestRunner::beginNewTest (
UnitTest*
const test,
const String& subCategory)
202 auto* r =
new TestResult();
204 r->unitTestName = test->
getName();
205 r->subcategoryName = subCategory;
209 logMessage (
"-----------------------------------------------------------------");
210 logMessage (
"Starting test: " + r->unitTestName +
" / " + subCategory +
"...");
215 void UnitTestRunner::endTest()
217 if (
auto* r = results.getLast())
221 String m (
"FAILED!! ");
222 m << r->failures << (r->failures == 1 ?
" test" :
" tests")
223 <<
" failed, out of a total of " << (r->passes + r->failures);
231 logMessage (
"All tests completed successfully");
236 void UnitTestRunner::addPass()
239 const ScopedLock sl (results.getLock());
241 auto* r = results.getLast();
242 jassert (r !=
nullptr);
248 String message (
"Test ");
249 message << (r->failures + r->passes) <<
" passed";
257 void UnitTestRunner::addFail (
const String& failureMessage)
260 const ScopedLock sl (results.getLock());
262 auto* r = results.getLast();
263 jassert (r !=
nullptr);
267 String message (
"!!! Test ");
268 message << (r->failures + r->passes) <<
" failed";
270 if (failureMessage.isNotEmpty())
271 message <<
": " << failureMessage;
273 r->messages.add (message);
280 if (assertOnFailure) { jassertfalse; }
A special array for holding a list of strings.
virtual ~UnitTest()
Destructor.
int getNumResults() const noexcept
Returns the number of TestResult objects that have been performed.
Random getRandom() const
Returns a shared RNG that all unit tests should use.
int nextInt() noexcept
Returns the next random 32 bit integer.
static Array< UnitTest * > & getAllTests()
Returns the set of all UnitTest objects that currently exist.
void add(const ElementType &newElement)
Appends a new element at the end of the array.
void setAssertOnFailure(bool shouldAssert) noexcept
Sets a flag to indicate whether an assertion should be triggered if a test fails.
void setPassesAreLogged(bool shouldDisplayPasses) noexcept
Sets a flag to indicate whether successful tests should be logged.
void expect(bool testResult, const String &failureMessage=String())
Checks that the result of a test is true, and logs this result.
Holds a resizable array of primitive or copy-by-value objects.
void runAllTests(int64 randomSeed=0)
Runs all the UnitTest objects that currently exist.
static String toHexString(IntegerType number)
Returns a string representing this numeric value in hexadecimal.
Contains the results of a test.
A random number generator.
virtual void logMessage(const String &message)
Logs a message about the current test progress.
static void JUCE_CALLTYPE writeToLog(const String &message)
Writes a string to the current logger.
const String & getName() const noexcept
Returns the name of the test.
virtual ~UnitTestRunner()
Destructor.
bool addIfNotAlreadyThere(const String &stringToAdd, bool ignoreCase=false)
Adds a string to the array as long as it's not already in there.
bool isEmpty() const noexcept
Returns true if the string contains no characters.
virtual void shutdown()
You can optionally implement this method to clear up after your test has been run.
virtual void resultsUpdated()
Called when the list of results changes.
This is a base class for classes that perform a unit test.
virtual bool shouldAbortTests()
This can be overridden to let the runner know that it should abort the tests as soon as possible,...
void logMessage(const String &message)
Writes a message to the test log.
UnitTest(const String &name, const String &category=String())
Creates a test with the given name and optionally places it in a category.
virtual void runTest()=0
Implement this method in your subclass to actually run your tests.
void performTest(UnitTestRunner *runner)
Runs the test, using the specified UnitTestRunner.
static Array< UnitTest * > getTestsInCategory(const String &category)
Returns the set of UnitTests in a specified category.
Runs a set of unit tests.
static StringArray getAllCategories()
Returns a StringArray containing all of the categories of UnitTests that have been registered.
const TestResult * getResult(int index) const noexcept
Returns one of the TestResult objects that describes a test that has been run.
void runTestsInCategory(const String &category, int64 randomSeed=0)
Runs all the UnitTest objects within a specified category.
void beginTest(const String &testName)
Tells the system that a new subsection of tests is beginning.
virtual void initialise()
You can optionally implement this method to set up your test.
void runTests(const Array< UnitTest * > &tests, int64 randomSeed=0)
Runs a set of tests.