| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/template_util.h" | 5 #include "base/template_util.h" |
| 6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
| 7 | 7 |
| 8 namespace base { | 8 namespace base { |
| 9 namespace { | 9 namespace { |
| 10 | 10 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 // EXPECT_TRUE( (is_convertible < Child), (Parent > ::value)); | 44 // EXPECT_TRUE( (is_convertible < Child), (Parent > ::value)); |
| 45 // | 45 // |
| 46 // Silly C++. | 46 // Silly C++. |
| 47 EXPECT_TRUE( (is_convertible<Child, Parent>::value) ); | 47 EXPECT_TRUE( (is_convertible<Child, Parent>::value) ); |
| 48 EXPECT_FALSE( (is_convertible<Parent, Child>::value) ); | 48 EXPECT_FALSE( (is_convertible<Parent, Child>::value) ); |
| 49 EXPECT_FALSE( (is_convertible<Parent, AStruct>::value) ); | 49 EXPECT_FALSE( (is_convertible<Parent, AStruct>::value) ); |
| 50 | 50 |
| 51 EXPECT_TRUE( (is_convertible<int, double>::value) ); | 51 EXPECT_TRUE( (is_convertible<int, double>::value) ); |
| 52 EXPECT_TRUE( (is_convertible<int*, void*>::value) ); | 52 EXPECT_TRUE( (is_convertible<int*, void*>::value) ); |
| 53 EXPECT_FALSE( (is_convertible<void*, int*>::value) ); | 53 EXPECT_FALSE( (is_convertible<void*, int*>::value) ); |
| 54 |
| 55 // Array types are an easy corner case. Make sure to test that |
| 56 // it does indeed compile. |
| 57 EXPECT_FALSE( (is_convertible<int[10], double>::value) ); |
| 58 EXPECT_FALSE( (is_convertible<double, int[10]>::value) ); |
| 59 EXPECT_TRUE( (is_convertible<int[10], int*>::value) ); |
| 54 } | 60 } |
| 55 | 61 |
| 56 TEST(TemplateUtilTest, IsSame) { | 62 TEST(TemplateUtilTest, IsSame) { |
| 57 EXPECT_FALSE( (is_same<Child, Parent>::value) ); | 63 EXPECT_FALSE( (is_same<Child, Parent>::value) ); |
| 58 EXPECT_FALSE( (is_same<Parent, Child>::value) ); | 64 EXPECT_FALSE( (is_same<Parent, Child>::value) ); |
| 59 EXPECT_TRUE( (is_same<Parent, Parent>::value) ); | 65 EXPECT_TRUE( (is_same<Parent, Parent>::value) ); |
| 60 | 66 |
| 61 EXPECT_TRUE( (is_same<int*, int*>::value) ); | 67 EXPECT_TRUE( (is_same<int*, int*>::value) ); |
| 62 EXPECT_TRUE( (is_same<int, int>::value) ); | 68 EXPECT_TRUE( (is_same<int, int>::value) ); |
| 63 EXPECT_TRUE( (is_same<void, void>::value) ); | 69 EXPECT_TRUE( (is_same<void, void>::value) ); |
| 64 EXPECT_FALSE( (is_same<int, double>::value) ); | 70 EXPECT_FALSE( (is_same<int, double>::value) ); |
| 65 } | 71 } |
| 66 | 72 |
| 67 TEST(TemplateUtilTest, IsClass) { | 73 TEST(TemplateUtilTest, IsClass) { |
| 68 EXPECT_TRUE(is_class<AStruct>::value); | 74 EXPECT_TRUE(is_class<AStruct>::value); |
| 69 EXPECT_TRUE(is_class<AClass>::value); | 75 EXPECT_TRUE(is_class<AClass>::value); |
| 70 | 76 |
| 71 EXPECT_FALSE(is_class<AnEnum>::value); | 77 EXPECT_FALSE(is_class<AnEnum>::value); |
| 72 EXPECT_FALSE(is_class<int>::value); | 78 EXPECT_FALSE(is_class<int>::value); |
| 73 EXPECT_FALSE(is_class<char*>::value); | 79 EXPECT_FALSE(is_class<char*>::value); |
| 74 EXPECT_FALSE(is_class<int&>::value); | 80 EXPECT_FALSE(is_class<int&>::value); |
| 75 EXPECT_FALSE(is_class<char[3]>::value); | 81 EXPECT_FALSE(is_class<char[3]>::value); |
| 76 } | 82 } |
| 77 | 83 |
| 78 } // namespace | 84 } // namespace |
| 79 } // namespace base | 85 } // namespace base |
| OLD | NEW |