Fingerprint_Card

Loading...
Searching...
No Matches
ZUnitTest.h
Go to the documentation of this file.
1#ifndef Z_UNIT_TEST_H
2#define Z_UNIT_TEST_H
3
4#include <Core/ZTypes.h>
5#include <Core/ZErrors.h>
6#include <ostream>
7#include <sstream>
8#include <vector>
9#include <cstdio>
10
11 namespace Zwipe
12{
13 typedef std::wstring string;
14 typedef std::stringstream stringstream;
15
16 string ErrorToString(ZResult error);
17
18 class EqualHelper
19 {
20 public:
21 template<typename T> static bool AreEqual(const T& expected, const T& actual)
22 {
23 return expected == actual;
24 }
25 };
26}
27
28#define Z_ASSERT_FAILA(conditionMessage, customMessage) \
29 { \
30 Zwipe::stringstream stream; \
31 stream << "Assert " << conditionMessage << " failed. Message: " << customMessage; \
32 Z_THROW_ERROR_FAILED_MA(stream.str().c_str()); \
33 }
34#define Z_ASSERT_MA(condition, customMessage) \
35 if (!(condition)) \
36 { \
37 Z_ASSERT_FAILA(Z_STRINGIZEA(condition), customMessage); \
38 }
39#define Z_ASSERT(condition) Z_ASSERT_MA(condition, Z_TA(""))
40#define Z_ASSERT_ARE_EQUAL_MA(expected, actual, customMessage) \
41 if (!Zwipe::EqualHelper::AreEqual(expected, actual)) \
42 { \
43 Z_ASSERT_FAILA(Z_TA("<") << (expected) << Z_TA("> == <") << (actual) << Z_TA(">"), customMessage); \
44 }
45#define Z_ASSERT_ARE_EQUAL(expected, actual) Z_ASSERT_ARE_EQUAL_MA(expected, actual, Z_TA(""))
46
47#include "CppUnitTest.h"
48
49#define Z_TEST_CLASS(name) TEST_CLASS(name) \
50 { \
51 typedef name TheTestClass; \
52 typedef ZResult (TheTestClass::*TestProc)(); \
53 void RunTest(TestProc pRunProc) \
54 {\
55 ZResult error = (this->*pRunProc)(); \
56 if (ZFailed(error)) \
57 { \
58 ::Microsoft::VisualStudio::CppUnitTestFramework::Assert::Fail(Zwipe::ErrorToString(error).c_str()); \
59 } \
60 } \
61 public:
62
63#define Z_TEST_METHOD(name) TEST_METHOD(name) \
64 { \
65 RunTest(&TheTestClass::name##Impl); \
66 } \
67 ZResult name##Impl()
68
69#define Z_TEST_INIT_METHOD(name) TEST_METHOD_INITIALIZE(name##Proxy) \
70 { \
71 ::Microsoft::VisualStudio::CppUnitTestFramework::Assert::AreEqual(Z_OK, name()); \
72 } \
73 ZResult name()
74
75#define Z_TEST_CLEANUP_METHOD(name) TEST_METHOD_CLEANUP(name##Proxy) \
76 { \
77 ::Microsoft::VisualStudio::CppUnitTestFramework::Assert::AreEqual(Z_OK, name()); \
78 }\
79 ZResult name()
80
81#define Z_TEST_LOG(message) \
82 { \
83 std::stringstream stream; \
84 stream << message; \
85 ::Microsoft::VisualStudio::CppUnitTestFramework::Logger::WriteMessage(stream.str().c_str()); \
86 }
87
88#endif // !Z_UNIT_TEST_H
Zwipe::EqualHelper
Definition ZUnitTest.h:19
Zwipe::EqualHelper::AreEqual
static bool AreEqual(const T &expected, const T &actual)
Definition ZUnitTest.h:21
Zwipe
Definition ZUnitTest.h:12
Zwipe::stringstream
std::stringstream stringstream
Definition ZUnitTest.h:14
Zwipe::ErrorToString
string ErrorToString(ZResult error)
Definition ZUnitTest.cpp:5
Zwipe::string
std::wstring string
Definition ZUnitTest.h:13