[email protected] | b38d357 | 2011-02-15 01:27:38 | [diff] [blame^] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "base/template_util.h" |
| 6 | #include "testing/gtest/include/gtest/gtest.h" |
| 7 | |
| 8 | namespace base { |
| 9 | namespace { |
| 10 | |
| 11 | struct AStruct {}; |
| 12 | class AClass {}; |
| 13 | enum AnEnum {}; |
| 14 | |
| 15 | class Parent {}; |
| 16 | class Child : public Parent {}; |
| 17 | |
| 18 | TEST(TemplateUtilTest, IsPointer) { |
| 19 | EXPECT_FALSE(is_pointer<int>::value); |
| 20 | EXPECT_FALSE(is_pointer<int&>::value); |
| 21 | EXPECT_TRUE(is_pointer<int*>::value); |
| 22 | EXPECT_TRUE(is_pointer<const int*>::value); |
| 23 | } |
| 24 | |
| 25 | TEST(TemplateUtilTest, IsArray) { |
| 26 | EXPECT_FALSE(is_array<int>::value); |
| 27 | EXPECT_FALSE(is_array<int*>::value); |
| 28 | EXPECT_FALSE(is_array<int(*)[3]>::value); |
| 29 | EXPECT_TRUE(is_array<int[]>::value); |
| 30 | EXPECT_TRUE(is_array<const int[]>::value); |
| 31 | EXPECT_TRUE(is_array<int[3]>::value); |
| 32 | } |
| 33 | |
| 34 | TEST(TemplateUtilTest, IsNonConstReference) { |
| 35 | EXPECT_FALSE(is_non_const_reference<int>::value); |
| 36 | EXPECT_FALSE(is_non_const_reference<const int&>::value); |
| 37 | EXPECT_TRUE(is_non_const_reference<int&>::value); |
| 38 | } |
| 39 | |
| 40 | #if !defined(OS_WIN) |
| 41 | // TODO(ajwong): Why is is_convertible disabled on windows? |
| 42 | TEST(TemplateUtilTest, IsConvertible) { |
| 43 | // Extra parents needed to make EXPECT_*'s parsing happy. Otherwise, |
| 44 | // it sees the equivalent of |
| 45 | // |
| 46 | // EXPECT_TRUE( (is_convertible < Child), (Parent > ::value)); |
| 47 | // |
| 48 | // Silly C++. |
| 49 | EXPECT_TRUE( (is_convertible<Child, Parent>::value) ); |
| 50 | EXPECT_FALSE( (is_convertible<Parent, Child>::value) ); |
| 51 | } |
| 52 | #endif // !defined(OS_WIN) |
| 53 | |
| 54 | TEST(TemplateUtilTest, IsClass) { |
| 55 | EXPECT_EQ(true, is_class<AStruct>::value); |
| 56 | EXPECT_EQ(true, is_class<AClass>::value); |
| 57 | |
| 58 | EXPECT_EQ(false, is_class<AnEnum>::value); |
| 59 | EXPECT_EQ(false, is_class<int>::value); |
| 60 | EXPECT_EQ(false, is_class<char*>::value); |
| 61 | EXPECT_EQ(false, is_class<int&>::value); |
| 62 | EXPECT_EQ(false, is_class<char[3]>::value); |
| 63 | } |
| 64 | |
| 65 | } // namespace |
| 66 | } // namespace base |