Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(619)

Unified Diff: ppapi/tests/test_case.h

Issue 69663002: PPAPI: Implement PPB_FileMapping on POSIX (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rough patch. Starting testing. Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ppapi/tests/all_c_includes.h ('k') | ppapi/tests/test_file_mapping.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/tests/test_case.h
diff --git a/ppapi/tests/test_case.h b/ppapi/tests/test_case.h
index 0a96c9b6652e4d11ba5082a95b4ed03d68a301cc..177e227d46522b1ae2a3cb0a84b36d73267d3a34 100644
--- a/ppapi/tests/test_case.h
+++ b/ppapi/tests/test_case.h
@@ -9,6 +9,7 @@
#include <limits>
#include <map>
#include <set>
+#include <sstream>
#include <string>
#include "ppapi/c/pp_resource.h"
@@ -273,6 +274,56 @@ class TestCaseFactory {
static TestCaseFactory* head_;
};
+
+// This is an implementation detail, for use by ASSERT macros.
+template <class T>
+struct StringinatorBase {
+ static std::string ToString(const T& value, const std::string& s) {
+ std::stringstream stream;
+ stream << value;
+ return s + "(" + stream.str() + ")";
+ }
+ private:
+ // Not implemented, do not use.
+ StringinatorBase();
+ ~StringinatorBase();
+};
+// The default version is for types that are not known to be stringifiable.
+// TODO(dmichael): Are there some useful traits for this?
+template <class T>
+struct Stringinator {
+ static std::string ToString(const T& value, const std::string& s) {
+ return s;
+ }
+ private:
+ // Not implemented, do not use.
+ Stringinator();
+ ~Stringinator();
+};
+#define STRINGINATOR_FOR_TYPE(type) \
+template <> \
+struct Stringinator<type> : public StringinatorBase<type> {};
+STRINGINATOR_FOR_TYPE(int32_t);
+STRINGINATOR_FOR_TYPE(uint32_t);
+STRINGINATOR_FOR_TYPE(int64_t);
+STRINGINATOR_FOR_TYPE(uint64_t);
+STRINGINATOR_FOR_TYPE(float);
+STRINGINATOR_FOR_TYPE(double);
+STRINGINATOR_FOR_TYPE(bool);
+STRINGINATOR_FOR_TYPE(std::string);
+//TODO(dmichael): Put this somewhere else
+template <class T>
+std::string ToString(const T& param, const char* s) {
+ return Stringinator<T>::ToString(param, std::string(s));
+}
+// This overload is necessary to allow values from pp_errors.h such as PP_OK to
+// work. They won't automatically convert to an integral type to instantiate the
+// above template.
+inline std::string ToString(int32_t param, const char* s) {
+ return Stringinator<int32_t>::ToString(param, std::string(s));
+}
+#define TO_STRING(param) ToString(param, #param)
+
// Use the REGISTER_TEST_CASE macro in your TestCase implementation file to
// register your TestCase. If your test is named TestFoo, then add the
// following to test_foo.cc:
@@ -373,7 +424,13 @@ class TestCaseFactory {
return MakeFailureMessage(__FILE__, __LINE__, #cmd); \
} while (false)
#define ASSERT_FALSE(cmd) ASSERT_TRUE(!(cmd))
-#define ASSERT_EQ(a, b) ASSERT_TRUE((a) == (b))
+#define ASSERT_BINARY_INTERNAL(a, op, b) \
+ do { \
+ if (!((a) op (b))) \
+ return MakeFailureMessage(__FILE__, __LINE__, \
+ (TO_STRING((a)) + " " #op " " + TO_STRING((b))).c_str()); \
+ } while (false)
+#define ASSERT_EQ(a, b) ASSERT_BINARY_INTERNAL((a), ==, (b))
#define ASSERT_NE(a, b) ASSERT_TRUE((a) != (b))
#define ASSERT_LT(a, b) ASSERT_TRUE((a) < (b))
#define ASSERT_LE(a, b) ASSERT_TRUE((a) <= (b))
« no previous file with comments | « ppapi/tests/all_c_includes.h ('k') | ppapi/tests/test_file_mapping.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698