diff options
author | snappy.mirrorbot@gmail.com <snappy.mirrorbot@gmail.com@03e5f5b5-db94-4691-08a0-1a8bf15f6143> | 2012-05-22 09:32:50 +0000 |
---|---|---|
committer | snappy.mirrorbot@gmail.com <snappy.mirrorbot@gmail.com@03e5f5b5-db94-4691-08a0-1a8bf15f6143> | 2012-05-22 09:32:50 +0000 |
commit | c4fa09760690b6cad194745e6000581c45b02ef4 (patch) | |
tree | a4e185ca7c6b055db7472fdf3c1f7ec4816b68fb /snappy-test.h | |
parent | 953ad2bd60459aadc502210dfeee08d5da9af1ae (diff) | |
download | snappy-c4fa09760690b6cad194745e6000581c45b02ef4.tar.gz |
Snappy library no longer depends on iostream.
Achieved by moving logging macro definitions to a test-only
header file, and by changing non-test code to use assert,
fprintf, and abort instead of LOG/CHECK macros.
R=sesse
git-svn-id: http://snappy.googlecode.com/svn/trunk@62 03e5f5b5-db94-4691-08a0-1a8bf15f6143
Diffstat (limited to 'snappy-test.h')
-rw-r--r-- | snappy-test.h | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/snappy-test.h b/snappy-test.h index ef6a955..86a92fd 100644 --- a/snappy-test.h +++ b/snappy-test.h @@ -31,6 +31,9 @@ #ifndef UTIL_SNAPPY_OPENSOURCE_SNAPPY_TEST_H_ #define UTIL_SNAPPY_OPENSOURCE_SNAPPY_TEST_H_ +#include <iostream> +#include <string> + #include "snappy-stubs-internal.h" #include <stdio.h> @@ -496,6 +499,65 @@ static void CompressFile(const char* fname); static void UncompressFile(const char* fname); static void MeasureFile(const char* fname); +// Logging. + +#define LOG(level) LogMessage() +#define VLOG(level) true ? (void)0 : \ + snappy::LogMessageVoidify() & snappy::LogMessage() + +class LogMessage { + public: + LogMessage() { } + ~LogMessage() { + cerr << endl; + } + + LogMessage& operator<<(const std::string& msg) { + cerr << msg; + return *this; + } + LogMessage& operator<<(int x) { + cerr << x; + return *this; + } +}; + +// Asserts, both versions activated in debug mode only, +// and ones that are always active. + +#define CRASH_UNLESS(condition) \ + PREDICT_TRUE(condition) ? (void)0 : \ + snappy::LogMessageVoidify() & snappy::LogMessageCrash() + +class LogMessageCrash : public LogMessage { + public: + LogMessageCrash() { } + ~LogMessageCrash() { + cerr << endl; + abort(); + } +}; + +// This class is used to explicitly ignore values in the conditional +// logging macros. This avoids compiler warnings like "value computed +// is not used" and "statement has no effect". + +class LogMessageVoidify { + public: + LogMessageVoidify() { } + // This has to be an operator with a precedence lower than << but + // higher than ?: + void operator&(const LogMessage&) { } +}; + +#define CHECK(cond) CRASH_UNLESS(cond) +#define CHECK_LE(a, b) CRASH_UNLESS((a) <= (b)) +#define CHECK_GE(a, b) CRASH_UNLESS((a) >= (b)) +#define CHECK_EQ(a, b) CRASH_UNLESS((a) == (b)) +#define CHECK_NE(a, b) CRASH_UNLESS((a) != (b)) +#define CHECK_LT(a, b) CRASH_UNLESS((a) < (b)) +#define CHECK_GT(a, b) CRASH_UNLESS((a) > (b)) + } // namespace using snappy::CompressFile; |