- add sources.
[platform/framework/web/crosswalk.git] / src / base / template_util_unittest.cc
1 // Copyright (c) 2012 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
7 #include "base/basictypes.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 namespace base {
11 namespace {
12
13 struct AStruct {};
14 class AClass {};
15 enum AnEnum {};
16
17 class Parent {};
18 class Child : public Parent {};
19
20 // is_pointer<Type>
21 COMPILE_ASSERT(!is_pointer<int>::value, IsPointer);
22 COMPILE_ASSERT(!is_pointer<int&>::value, IsPointer);
23 COMPILE_ASSERT(is_pointer<int*>::value, IsPointer);
24 COMPILE_ASSERT(is_pointer<const int*>::value, IsPointer);
25
26 // is_array<Type>
27 COMPILE_ASSERT(!is_array<int>::value, IsArray);
28 COMPILE_ASSERT(!is_array<int*>::value, IsArray);
29 COMPILE_ASSERT(!is_array<int(*)[3]>::value, IsArray);
30 COMPILE_ASSERT(is_array<int[]>::value, IsArray);
31 COMPILE_ASSERT(is_array<const int[]>::value, IsArray);
32 COMPILE_ASSERT(is_array<int[3]>::value, IsArray);
33
34 // is_non_const_reference<Type>
35 COMPILE_ASSERT(!is_non_const_reference<int>::value, IsNonConstReference);
36 COMPILE_ASSERT(!is_non_const_reference<const int&>::value, IsNonConstReference);
37 COMPILE_ASSERT(is_non_const_reference<int&>::value, IsNonConstReference);
38
39 // is_convertible<From, To>
40
41 // Extra parens needed to make preprocessor macro parsing happy. Otherwise,
42 // it sees the equivalent of:
43 //
44 //     (is_convertible < Child), (Parent > ::value)
45 //
46 // Silly C++.
47 COMPILE_ASSERT( (is_convertible<Child, Parent>::value), IsConvertible);
48 COMPILE_ASSERT(!(is_convertible<Parent, Child>::value), IsConvertible);
49 COMPILE_ASSERT(!(is_convertible<Parent, AStruct>::value), IsConvertible);
50 COMPILE_ASSERT( (is_convertible<int, double>::value), IsConvertible);
51 COMPILE_ASSERT( (is_convertible<int*, void*>::value), IsConvertible);
52 COMPILE_ASSERT(!(is_convertible<void*, int*>::value), IsConvertible);
53
54 // Array types are an easy corner case.  Make sure to test that
55 // it does indeed compile.
56 COMPILE_ASSERT(!(is_convertible<int[10], double>::value), IsConvertible);
57 COMPILE_ASSERT(!(is_convertible<double, int[10]>::value), IsConvertible);
58 COMPILE_ASSERT( (is_convertible<int[10], int*>::value), IsConvertible);
59
60 // is_same<Type1, Type2>
61 COMPILE_ASSERT(!(is_same<Child, Parent>::value), IsSame);
62 COMPILE_ASSERT(!(is_same<Parent, Child>::value), IsSame);
63 COMPILE_ASSERT( (is_same<Parent, Parent>::value), IsSame);
64 COMPILE_ASSERT( (is_same<int*, int*>::value), IsSame);
65 COMPILE_ASSERT( (is_same<int, int>::value), IsSame);
66 COMPILE_ASSERT( (is_same<void, void>::value), IsSame);
67 COMPILE_ASSERT(!(is_same<int, double>::value), IsSame);
68
69
70 // is_class<Type>
71 COMPILE_ASSERT(is_class<AStruct>::value, IsClass);
72 COMPILE_ASSERT(is_class<AClass>::value, IsClass);
73 COMPILE_ASSERT(!is_class<AnEnum>::value, IsClass);
74 COMPILE_ASSERT(!is_class<int>::value, IsClass);
75 COMPILE_ASSERT(!is_class<char*>::value, IsClass);
76 COMPILE_ASSERT(!is_class<int&>::value, IsClass);
77 COMPILE_ASSERT(!is_class<char[3]>::value, IsClass);
78
79 }  // namespace
80 }  // namespace base