annotate win32-mingw/include/kj/test.h @ 56:af97cad61ff0

Add updated build of PortAudio for OSX
author Chris Cannam <cannam@all-day-breakfast.com>
date Tue, 03 Jan 2017 15:10:52 +0000
parents 37d53a7e8262
children eccd51b72864
rev   line source
Chris@50 1 // Copyright (c) 2013-2014 Sandstorm Development Group, Inc. and contributors
Chris@50 2 // Licensed under the MIT License:
Chris@50 3 //
Chris@50 4 // Permission is hereby granted, free of charge, to any person obtaining a copy
Chris@50 5 // of this software and associated documentation files (the "Software"), to deal
Chris@50 6 // in the Software without restriction, including without limitation the rights
Chris@50 7 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Chris@50 8 // copies of the Software, and to permit persons to whom the Software is
Chris@50 9 // furnished to do so, subject to the following conditions:
Chris@50 10 //
Chris@50 11 // The above copyright notice and this permission notice shall be included in
Chris@50 12 // all copies or substantial portions of the Software.
Chris@50 13 //
Chris@50 14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Chris@50 15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Chris@50 16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Chris@50 17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Chris@50 18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Chris@50 19 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Chris@50 20 // THE SOFTWARE.
Chris@50 21
Chris@50 22 #ifndef KJ_TEST_H_
Chris@50 23 #define KJ_TEST_H_
Chris@50 24
Chris@50 25 #if defined(__GNUC__) && !KJ_HEADER_WARNINGS
Chris@50 26 #pragma GCC system_header
Chris@50 27 #endif
Chris@50 28
Chris@50 29 #include "debug.h"
Chris@50 30 #include "vector.h"
Chris@50 31
Chris@50 32 namespace kj {
Chris@50 33
Chris@50 34 class TestRunner;
Chris@50 35
Chris@50 36 class TestCase {
Chris@50 37 public:
Chris@50 38 TestCase(const char* file, uint line, const char* description);
Chris@50 39 ~TestCase();
Chris@50 40
Chris@50 41 virtual void run() = 0;
Chris@50 42
Chris@50 43 private:
Chris@50 44 const char* file;
Chris@50 45 uint line;
Chris@50 46 const char* description;
Chris@50 47 TestCase* next;
Chris@50 48 TestCase** prev;
Chris@50 49 bool matchedFilter;
Chris@50 50
Chris@50 51 friend class TestRunner;
Chris@50 52 };
Chris@50 53
Chris@50 54 #define KJ_TEST(description) \
Chris@50 55 /* Make sure the linker fails if tests are not in anonymous namespaces. */ \
Chris@50 56 extern int KJ_CONCAT(YouMustWrapTestsInAnonymousNamespace, __COUNTER__) KJ_UNUSED; \
Chris@50 57 class KJ_UNIQUE_NAME(TestCase): public ::kj::TestCase { \
Chris@50 58 public: \
Chris@50 59 KJ_UNIQUE_NAME(TestCase)(): ::kj::TestCase(__FILE__, __LINE__, description) {} \
Chris@50 60 void run() override; \
Chris@50 61 } KJ_UNIQUE_NAME(testCase); \
Chris@50 62 void KJ_UNIQUE_NAME(TestCase)::run()
Chris@50 63
Chris@50 64 #if _MSC_VER
Chris@50 65 #define KJ_INDIRECT_EXPAND(m, vargs) m vargs
Chris@50 66 #define KJ_FAIL_EXPECT(...) \
Chris@50 67 KJ_INDIRECT_EXPAND(KJ_LOG, (ERROR , __VA_ARGS__));
Chris@50 68 #define KJ_EXPECT(cond, ...) \
Chris@50 69 if (cond); else KJ_INDIRECT_EXPAND(KJ_FAIL_EXPECT, ("failed: expected " #cond , __VA_ARGS__))
Chris@50 70 #else
Chris@50 71 #define KJ_FAIL_EXPECT(...) \
Chris@50 72 KJ_LOG(ERROR, ##__VA_ARGS__);
Chris@50 73 #define KJ_EXPECT(cond, ...) \
Chris@50 74 if (cond); else KJ_FAIL_EXPECT("failed: expected " #cond, ##__VA_ARGS__)
Chris@50 75 #endif
Chris@50 76
Chris@50 77 #define KJ_EXPECT_THROW(type, code) \
Chris@50 78 do { \
Chris@50 79 KJ_IF_MAYBE(e, ::kj::runCatchingExceptions([&]() { code; })) { \
Chris@50 80 KJ_EXPECT(e->getType() == ::kj::Exception::Type::type, \
Chris@50 81 "code threw wrong exception type: " #code, e->getType()); \
Chris@50 82 } else { \
Chris@50 83 KJ_FAIL_EXPECT("code did not throw: " #code); \
Chris@50 84 } \
Chris@50 85 } while (false)
Chris@50 86
Chris@50 87 #define KJ_EXPECT_THROW_MESSAGE(message, code) \
Chris@50 88 do { \
Chris@50 89 KJ_IF_MAYBE(e, ::kj::runCatchingExceptions([&]() { code; })) { \
Chris@50 90 KJ_EXPECT(::kj::_::hasSubstring(e->getDescription(), message), \
Chris@50 91 "exception description didn't contain expected substring", e->getDescription()); \
Chris@50 92 } else { \
Chris@50 93 KJ_FAIL_EXPECT("code did not throw: " #code); \
Chris@50 94 } \
Chris@50 95 } while (false)
Chris@50 96
Chris@50 97 #define KJ_EXPECT_LOG(level, substring) \
Chris@50 98 ::kj::_::LogExpectation KJ_UNIQUE_NAME(_kjLogExpectation)(::kj::LogSeverity::level, substring)
Chris@50 99 // Expects that a log message with the given level and substring text will be printed within
Chris@50 100 // the current scope. This message will not cause the test to fail, even if it is an error.
Chris@50 101
Chris@50 102 // =======================================================================================
Chris@50 103
Chris@50 104 namespace _ { // private
Chris@50 105
Chris@50 106 bool hasSubstring(kj::StringPtr haystack, kj::StringPtr needle);
Chris@50 107
Chris@50 108 class LogExpectation: public ExceptionCallback {
Chris@50 109 public:
Chris@50 110 LogExpectation(LogSeverity severity, StringPtr substring);
Chris@50 111 ~LogExpectation();
Chris@50 112
Chris@50 113 void logMessage(LogSeverity severity, const char* file, int line, int contextDepth,
Chris@50 114 String&& text) override;
Chris@50 115
Chris@50 116 private:
Chris@50 117 LogSeverity severity;
Chris@50 118 StringPtr substring;
Chris@50 119 bool seen;
Chris@50 120 UnwindDetector unwindDetector;
Chris@50 121 };
Chris@50 122
Chris@50 123 class GlobFilter {
Chris@50 124 // Implements glob filters for the --filter flag.
Chris@50 125 //
Chris@50 126 // Exposed in header only for testing.
Chris@50 127
Chris@50 128 public:
Chris@50 129 explicit GlobFilter(const char* pattern);
Chris@50 130 explicit GlobFilter(ArrayPtr<const char> pattern);
Chris@50 131
Chris@50 132 bool matches(StringPtr name);
Chris@50 133
Chris@50 134 private:
Chris@50 135 String pattern;
Chris@50 136 Vector<uint> states;
Chris@50 137
Chris@50 138 void applyState(char c, int state);
Chris@50 139 };
Chris@50 140
Chris@50 141 } // namespace _ (private)
Chris@50 142 } // namespace kj
Chris@50 143
Chris@50 144 #endif // KJ_TEST_H_