diff options
author | gavinp@chromium.org <gavinp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-19 18:34:08 +0000 |
---|---|---|
committer | gavinp@chromium.org <gavinp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-19 18:34:08 +0000 |
commit | a6d6d468a98941c27dad0f58144948e520419d00 (patch) | |
tree | ca962bd0ab82ac062e788609b2708a9c177ab5b2 /base/template_util_unittest.cc | |
parent | ea610dca7aec778637f4acec069cc65e4c565359 (diff) | |
download | chromium_src-a6d6d468a98941c27dad0f58144948e520419d00.zip chromium_src-a6d6d468a98941c27dad0f58144948e520419d00.tar.gz chromium_src-a6d6d468a98941c27dad0f58144948e520419d00.tar.bz2 |
Switch template_utils_unittest to using COMPILE_ASSERT.
This should be faster, and just as correct.
BUG=None
Review URL: https://chromiumcodereview.appspot.com/10565006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@142998 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/template_util_unittest.cc')
-rw-r--r-- | base/template_util_unittest.cc | 111 |
1 files changed, 53 insertions, 58 deletions
diff --git a/base/template_util_unittest.cc b/base/template_util_unittest.cc index b330a01..4cfa3e4 100644 --- a/base/template_util_unittest.cc +++ b/base/template_util_unittest.cc @@ -1,8 +1,10 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // 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 |