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

Unified Diff: base/template_util_unittest.cc

Issue 10565006: Switch template_utils_unittest to using COMPILE_ASSERT. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remediate to review Created 8 years, 6 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/template_util_unittest.cc
diff --git a/base/template_util_unittest.cc b/base/template_util_unittest.cc
index b330a013f6f7ccc222a2be74c320a2559c05cec0..1b0e1e563cd8bd015deb7931f840e123d7834a94 100644
--- a/base/template_util_unittest.cc
+++ b/base/template_util_unittest.cc
@@ -3,6 +3,8 @@
// found in the LICENSE file.
#include "base/template_util.h"
+
+#include "base/basictypes.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace base {
@@ -15,71 +17,64 @@ enum AnEnum {};
class Parent {};
class Child : public Parent {};
-TEST(TemplateUtilTest, IsPointer) {
- EXPECT_FALSE(is_pointer<int>::value);
- EXPECT_FALSE(is_pointer<int&>::value);
- EXPECT_TRUE(is_pointer<int*>::value);
- EXPECT_TRUE(is_pointer<const int*>::value);
-}
-
-TEST(TemplateUtilTest, IsArray) {
- EXPECT_FALSE(is_array<int>::value);
- EXPECT_FALSE(is_array<int*>::value);
- EXPECT_FALSE(is_array<int(*)[3]>::value);
- EXPECT_TRUE(is_array<int[]>::value);
- EXPECT_TRUE(is_array<const int[]>::value);
- EXPECT_TRUE(is_array<int[3]>::value);
-}
+// is_pointer<Type>
+COMPILE_ASSERT(!is_pointer<int>::value, IsPointer);
+COMPILE_ASSERT(!is_pointer<int&>::value, IsPointer);
+COMPILE_ASSERT(is_pointer<int*>::value, IsPointer);
+COMPILE_ASSERT(is_pointer<const int*>::value, IsPointer);
-TEST(TemplateUtilTest, IsNonConstReference) {
- EXPECT_FALSE(is_non_const_reference<int>::value);
- EXPECT_FALSE(is_non_const_reference<const int&>::value);
- EXPECT_TRUE(is_non_const_reference<int&>::value);
-}
+// is_array<Type>
+COMPILE_ASSERT(!is_array<int>::value, IsArray);
+COMPILE_ASSERT(!is_array<int*>::value, IsArray);
+COMPILE_ASSERT(!is_array<int(*)[3]>::value, IsArray);
+COMPILE_ASSERT(is_array<int[]>::value, IsArray);
+COMPILE_ASSERT(is_array<const int[]>::value, IsArray);
+COMPILE_ASSERT(is_array<int[3]>::value, IsArray);
-TEST(TemplateUtilTest, IsConvertible) {
- // Extra parens needed to make EXPECT_*'s parsing happy. Otherwise,
- // it sees the equivalent of
- //
- // EXPECT_TRUE( (is_convertible < Child), (Parent > ::value));
- //
- // Silly C++.
- EXPECT_TRUE( (is_convertible<Child, Parent>::value) );
- EXPECT_FALSE( (is_convertible<Parent, Child>::value) );
- EXPECT_FALSE( (is_convertible<Parent, AStruct>::value) );
+// is_non_const_reference<Type>
+COMPILE_ASSERT(!is_non_const_reference<int>::value, IsNonConstReference);
+COMPILE_ASSERT(!is_non_const_reference<const int&>::value, IsNonConstReference);
+COMPILE_ASSERT(is_non_const_reference<int&>::value, IsNonConstReference);
- EXPECT_TRUE( (is_convertible<int, double>::value) );
- EXPECT_TRUE( (is_convertible<int*, void*>::value) );
- EXPECT_FALSE( (is_convertible<void*, int*>::value) );
+// is_convertible<From, To>
- // Array types are an easy corner case. Make sure to test that
- // it does indeed compile.
- EXPECT_FALSE( (is_convertible<int[10], double>::value) );
- EXPECT_FALSE( (is_convertible<double, int[10]>::value) );
- EXPECT_TRUE( (is_convertible<int[10], int*>::value) );
-}
+// Extra parens needed to make preprocessor macro parsing happy. Otherwise,
+// it sees the equivalent of:
+//
+// (is_convertible < Child), (Parent > ::value)
+//
+// Silly C++.
+COMPILE_ASSERT( (is_convertible<Child, Parent>::value), IsConvertible);
+COMPILE_ASSERT(!(is_convertible<Parent, Child>::value), IsConvertible);
+COMPILE_ASSERT(!(is_convertible<Parent, AStruct>::value), IsConvertible);
+COMPILE_ASSERT( (is_convertible<int, double>::value), IsConvertible);
+COMPILE_ASSERT( (is_convertible<int*, void*>::value), IsConvertible);
+COMPILE_ASSERT(!(is_convertible<void*, int*>::value), IsConvertible);
-TEST(TemplateUtilTest, IsSame) {
- EXPECT_FALSE( (is_same<Child, Parent>::value) );
- EXPECT_FALSE( (is_same<Parent, Child>::value) );
- EXPECT_TRUE( (is_same<Parent, Parent>::value) );
+// Array types are an easy corner case. Make sure to test that
+// it does indeed compile.
+COMPILE_ASSERT(!(is_convertible<int[10], double>::value), IsConvertible);
+COMPILE_ASSERT(!(is_convertible<double, int[10]>::value), IsConvertible);
+COMPILE_ASSERT( (is_convertible<int[10], int*>::value), IsConvertible);
- EXPECT_TRUE( (is_same<int*, int*>::value) );
- EXPECT_TRUE( (is_same<int, int>::value) );
- EXPECT_TRUE( (is_same<void, void>::value) );
- EXPECT_FALSE( (is_same<int, double>::value) );
-}
+// is_same<Type1, Type2>
+COMPILE_ASSERT(!(is_same<Child, Parent>::value), IsSame);
+COMPILE_ASSERT(!(is_same<Parent, Child>::value), IsSame);
+COMPILE_ASSERT( (is_same<Parent, Parent>::value), IsSame);
+COMPILE_ASSERT( (is_same<int*, int*>::value), IsSame);
+COMPILE_ASSERT( (is_same<int, int>::value), IsSame);
+COMPILE_ASSERT( (is_same<void, void>::value), IsSame);
+COMPILE_ASSERT(!(is_same<int, double>::value), IsSame);
-TEST(TemplateUtilTest, IsClass) {
- EXPECT_TRUE(is_class<AStruct>::value);
- EXPECT_TRUE(is_class<AClass>::value);
- EXPECT_FALSE(is_class<AnEnum>::value);
- EXPECT_FALSE(is_class<int>::value);
- EXPECT_FALSE(is_class<char*>::value);
- EXPECT_FALSE(is_class<int&>::value);
- EXPECT_FALSE(is_class<char[3]>::value);
-}
+// is_class<Type>
+COMPILE_ASSERT(is_class<AStruct>::value, IsClass);
+COMPILE_ASSERT(is_class<AClass>::value, IsClass);
+COMPILE_ASSERT(!is_class<AnEnum>::value, IsClass);
+COMPILE_ASSERT(!is_class<int>::value, IsClass);
+COMPILE_ASSERT(!is_class<char*>::value, IsClass);
+COMPILE_ASSERT(!is_class<int&>::value, IsClass);
+COMPILE_ASSERT(!is_class<char[3]>::value, IsClass);
} // namespace
} // namespace base
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698