Added support for c++ test fixtures.
This commit is contained in:
parent
f9fb7e81be
commit
3aaaf71b85
@ -12,6 +12,10 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
add_executable(Fixture Fixture.cpp)
|
||||
target_link_libraries(Fixture deepstate)
|
||||
|
||||
add_executable(IntegerOverflow IntegerOverflow.cpp)
|
||||
target_link_libraries(IntegerOverflow deepstate)
|
||||
|
||||
|
||||
42
examples/Fixture.cpp
Normal file
42
examples/Fixture.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2017 Trail of Bits, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <deepstate/DeepState.hpp>
|
||||
|
||||
class MyTest : public deepstate::Test {
|
||||
public:
|
||||
|
||||
void SetUp(void) {
|
||||
LOG(INFO)
|
||||
<< "Setting up!";
|
||||
}
|
||||
|
||||
void TearDown(void) {
|
||||
LOG(INFO)
|
||||
<< "Tearing down!";
|
||||
}
|
||||
|
||||
deepstate::Symbolic<int> x;
|
||||
};
|
||||
|
||||
TEST_F(MyTest, Something) {
|
||||
ASSUME_NE(x, 0);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
return DeepState_Run();
|
||||
}
|
||||
|
||||
@ -115,6 +115,21 @@ DEEPSTATE_INLINE static bool IsSymbolic(double x) {
|
||||
return DeepState_IsSymbolicDouble(x);
|
||||
}
|
||||
|
||||
// A test fixture.
|
||||
class Test {
|
||||
public:
|
||||
Test(void) = default;
|
||||
~Test(void) = default;
|
||||
inline void SetUp(void) {}
|
||||
inline void TearDown(void) {}
|
||||
|
||||
private:
|
||||
Test(const Test &) = delete;
|
||||
Test(Test &&) = delete;
|
||||
Test &operator=(const Test &) = delete;
|
||||
Test &operator=(Test &&) = delete;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class Symbolic {
|
||||
public:
|
||||
@ -214,6 +229,38 @@ inline static void OneOf(FuncTys&&... funcs) {
|
||||
#define TEST(category, name) \
|
||||
DeepState_EntryPoint(category ## _ ## name)
|
||||
|
||||
#define _TEST_F(fixture_name, test_name, file, line) \
|
||||
class fixture_name ## _ ## test_name : public fixture_name { \
|
||||
public: \
|
||||
void DoRunTest(void); \
|
||||
static void RunTest(void) { \
|
||||
do { \
|
||||
fixture_name ## _ ## test_name self; \
|
||||
self.SetUp(); \
|
||||
self.DoRunTest(); \
|
||||
self.TearDown(); \
|
||||
} while (false); \
|
||||
DeepState_Pass(); \
|
||||
} \
|
||||
static struct DeepState_TestInfo kTestInfo; \
|
||||
}; \
|
||||
struct DeepState_TestInfo fixture_name ## _ ## test_name::kTestInfo = { \
|
||||
nullptr, \
|
||||
fixture_name ## _ ## test_name::RunTest, \
|
||||
DEEPSTATE_TO_STR(fixture_name ## _ ## test_name), \
|
||||
file, \
|
||||
line, \
|
||||
}; \
|
||||
DEEPSTATE_INITIALIZER(DeepState_Register_ ## test_name) { \
|
||||
fixture_name ## _ ## test_name::kTestInfo.prev = DeepState_LastTestInfo; \
|
||||
DeepState_LastTestInfo = &(fixture_name ## _ ## test_name::kTestInfo); \
|
||||
} \
|
||||
void fixture_name ## _ ## test_name :: DoRunTest(void)
|
||||
|
||||
|
||||
#define TEST_F(fixture_name, test_name) \
|
||||
_TEST_F(fixture_name, test_name, __FILE__, __LINE__)
|
||||
|
||||
#define LOG_DEBUG(cond) \
|
||||
::deepstate::Stream(DeepState_LogDebug, (cond), __FILE__, __LINE__)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user