|
7 | 7 | # define JSONTEST_H_INCLUDED |
8 | 8 |
|
9 | 9 | # include <json/config.h> |
| 10 | +# include <json/value.h> |
10 | 11 | # include <stdio.h> |
11 | 12 | # include <deque> |
| 13 | +# include <sstream> |
12 | 14 | # include <string> |
13 | 15 |
|
14 | 16 | // ////////////////////////////////////////////////////////////////// |
@@ -84,16 +86,18 @@ namespace JsonTest { |
84 | 86 |
|
85 | 87 | void printFailure( bool printTestName ) const; |
86 | 88 |
|
87 | | - TestResult &operator << ( bool value ); |
88 | | - TestResult &operator << ( int value ); |
89 | | - TestResult &operator << ( unsigned int value ); |
90 | | -#ifdef JSON_HAS_INT64 |
91 | | - TestResult &operator << ( Json::Int64 value ); |
92 | | - TestResult &operator << ( Json::UInt64 value ); |
93 | | -#endif |
94 | | - TestResult &operator << ( double value ); |
95 | | - TestResult &operator << ( const char *value ); |
96 | | - TestResult &operator << ( const std::string &value ); |
| 89 | + // Generic operator that will work with anything ostream can deal with. |
| 90 | + template <typename T> |
| 91 | + TestResult &operator << ( const T& value ) { |
| 92 | + std::ostringstream oss; |
| 93 | + oss << value; |
| 94 | + return addToLastFailure(oss.str()); |
| 95 | + } |
| 96 | + |
| 97 | + // Specialized versions. |
| 98 | + TestResult &operator << ( bool value ) { |
| 99 | + return addToLastFailure(value ? "true" : "false"); |
| 100 | + } |
97 | 101 |
|
98 | 102 | private: |
99 | 103 | TestResult &addToLastFailure( const std::string &message ); |
@@ -177,9 +181,9 @@ namespace JsonTest { |
177 | 181 | Factories tests_; |
178 | 182 | }; |
179 | 183 |
|
180 | | - template<typename T> |
| 184 | + template<typename T, typename U> |
181 | 185 | TestResult & |
182 | | - checkEqual( TestResult &result, const T &expected, const T &actual, |
| 186 | + checkEqual( TestResult &result, const T &expected, const U &actual, |
183 | 187 | const char *file, unsigned int line, const char *expr ) |
184 | 188 | { |
185 | 189 | if ( expected != actual ) |
|
0 commit comments