summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2009-01-03 08:59:08 +0000
committerChris Wilson <chris+github@qwirx.com>2009-01-03 08:59:08 +0000
commit5e7f5ac8b32ceee8067d405f10bc8e14991fbd65 (patch)
treeb786a532ec0dd915ada394a96df051e7c685c924 /lib
parent2b1c6f82d57d187a20e4a7ebb34f3abbc22bac71 (diff)
Move TEST_EQUAL macro into lib/common/Test.h, rename to TEST_EQUAL_LINE,
provide TEST_EQUAL that only takes two arguments for simplicity.
Diffstat (limited to 'lib')
-rw-r--r--lib/common/Test.h56
1 files changed, 56 insertions, 0 deletions
diff --git a/lib/common/Test.h b/lib/common/Test.h
index fa3dcc83..f4766ddc 100644
--- a/lib/common/Test.h
+++ b/lib/common/Test.h
@@ -77,6 +77,62 @@ extern std::string bbackupd_args, bbstored_args, bbackupquery_args, test_args;
} \
}
+// utility macro for comparing two strings in a line
+#define TEST_EQUAL(_expected, _found) \
+{ \
+ std::ostringstream _oss1; \
+ _oss1 << _expected; \
+ std::string _exp_str = _oss1.str(); \
+ \
+ std::ostringstream _oss2; \
+ _oss2 << _found; \
+ std::string _found_str = _oss2.str(); \
+ \
+ if(_exp_str != _found_str) \
+ { \
+ printf("Expected <%s> but found <%s>\n", \
+ _exp_str.c_str(), _found_str.c_str()); \
+ \
+ std::ostringstream _oss3; \
+ _oss3 << #_found << " != " << #_expected; \
+ \
+ TEST_FAIL_WITH_MESSAGE(_oss3.str().c_str()); \
+ } \
+}
+
+// utility macro for comparing two strings in a line
+#define TEST_EQUAL_LINE(_expected, _found, _line) \
+{ \
+ std::ostringstream _oss1; \
+ _oss1 << _expected; \
+ std::string _exp_str = _oss1.str(); \
+ \
+ std::ostringstream _oss2; \
+ _oss2 << _found; \
+ std::string _found_str = _oss2.str(); \
+ \
+ if(_exp_str != _found_str) \
+ { \
+ std::string _line_str = _line; \
+ printf("Expected <%s> but found <%s> in <%s>\n", \
+ _exp_str.c_str(), _found_str.c_str(), _line_str.c_str()); \
+ \
+ std::ostringstream _oss3; \
+ _oss3 << #_found << " != " << #_expected << " in " << _line; \
+ \
+ TEST_FAIL_WITH_MESSAGE(_oss3.str().c_str()); \
+ } \
+}
+
+
+// utility macro for testing a line
+#define TEST_LINE(_condition, _line) \
+ TEST_THAT(_condition); \
+ if (!(_condition)) \
+ { \
+ printf("Test failed on <%s>\n", _line.c_str()); \
+ }
+
bool TestFileExists(const char *Filename);
bool TestDirExists(const char *Filename);