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

Side by Side Diff: base/template_util_unittest.cc

Issue 2001783002: base: Support using (D)CHECK on scoped enums. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use CR_GLIBCXX_4_7_0 macro, since I bothered to define it Created 4 years, 7 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 unified diff | Download patch
« base/logging.h ('K') | « base/template_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 6
7 #include <string>
8
7 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
8 10
9 namespace base { 11 namespace base {
10 namespace { 12 namespace {
11 13
14 enum SimpleEnum { SIMPLE_ENUM };
15 enum EnumWithExplicitType : uint64_t { ENUM_WITH_EXPLICIT_TYPE };
16 enum class ScopedEnum { SCOPED_ENUM };
17 enum class ScopedEnumWithOperator { SCOPED_ENUM_WITH_OPERATOR };
18 std::ostream& operator<<(std::ostream& os, ScopedEnumWithOperator v) {
19 return os;
20 }
21 struct SimpleStruct {};
22 struct StructWithOperator {};
23 std::ostream& operator<<(std::ostream& os, const StructWithOperator& v) {
24 return os;
25 }
26
12 // is_non_const_reference<Type> 27 // is_non_const_reference<Type>
13 static_assert(!is_non_const_reference<int>::value, "IsNonConstReference"); 28 static_assert(!is_non_const_reference<int>::value, "IsNonConstReference");
14 static_assert(!is_non_const_reference<const int&>::value, 29 static_assert(!is_non_const_reference<const int&>::value,
15 "IsNonConstReference"); 30 "IsNonConstReference");
16 static_assert(is_non_const_reference<int&>::value, "IsNonConstReference"); 31 static_assert(is_non_const_reference<int&>::value, "IsNonConstReference");
17 32
18 class AssignParent {}; 33 class AssignParent {};
19 class AssignChild : AssignParent {}; 34 class AssignChild : AssignParent {};
20 35
21 // is_assignable<Type1, Type2> 36 // is_assignable<Type1, Type2>
(...skipping 19 matching lines...) Expand all
41 AssignNoMove& operator=(const AssignNoMove&) = delete; 56 AssignNoMove& operator=(const AssignNoMove&) = delete;
42 }; 57 };
43 58
44 static_assert(is_copy_assignable<AssignCopy>::value, "IsCopyAssignable"); 59 static_assert(is_copy_assignable<AssignCopy>::value, "IsCopyAssignable");
45 static_assert(!is_copy_assignable<AssignNoCopy>::value, "IsCopyAssignable"); 60 static_assert(!is_copy_assignable<AssignNoCopy>::value, "IsCopyAssignable");
46 61
47 static_assert(is_move_assignable<AssignCopy>::value, "IsMoveAssignable"); 62 static_assert(is_move_assignable<AssignCopy>::value, "IsMoveAssignable");
48 static_assert(is_move_assignable<AssignNoCopy>::value, "IsMoveAssignable"); 63 static_assert(is_move_assignable<AssignNoCopy>::value, "IsMoveAssignable");
49 static_assert(!is_move_assignable<AssignNoMove>::value, "IsMoveAssignable"); 64 static_assert(!is_move_assignable<AssignNoMove>::value, "IsMoveAssignable");
50 65
66 // A few standard types that definitely support printing.
67 static_assert(internal::SupportsOstreamOperator<int>::value,
68 "ints should be printable");
69 static_assert(internal::SupportsOstreamOperator<const char*>::value,
70 "C strings should be printable");
71 static_assert(internal::SupportsOstreamOperator<std::string>::value,
72 "std::string should be printable");
73
74 // Various kinds of enums operator<< support.
75 static_assert(internal::SupportsOstreamOperator<SimpleEnum>::value,
76 "simple enum should be printable by value");
77 static_assert(internal::SupportsOstreamOperator<const SimpleEnum&>::value,
78 "simple enum should be printable by const ref");
79 static_assert(internal::SupportsOstreamOperator<EnumWithExplicitType>::value,
80 "enum with explicit type should be printable by value");
81 static_assert(
82 internal::SupportsOstreamOperator<const EnumWithExplicitType&>::value,
83 "enum with explicit type should be printable by const ref");
84 static_assert(!internal::SupportsOstreamOperator<ScopedEnum>::value,
85 "scoped enum should not be printable by value");
86 static_assert(!internal::SupportsOstreamOperator<const ScopedEnum&>::value,
87 "simple enum should not be printable by const ref");
88 static_assert(internal::SupportsOstreamOperator<ScopedEnumWithOperator>::value,
89 "scoped enum with operator<< should be printable by value");
90 static_assert(
91 internal::SupportsOstreamOperator<const ScopedEnumWithOperator&>::value,
92 "scoped enum with operator<< should be printable by const ref");
93
94 // operator<< support on structs.
95 static_assert(!internal::SupportsOstreamOperator<SimpleStruct>::value,
96 "simple struct should not be printable by value");
97 static_assert(!internal::SupportsOstreamOperator<const SimpleStruct&>::value,
98 "simple struct should not be printable by const ref");
99 static_assert(internal::SupportsOstreamOperator<StructWithOperator>::value,
100 "struct with operator<< should be printable by value");
101 static_assert(
102 internal::SupportsOstreamOperator<const StructWithOperator&>::value,
103 "struct with operator<< should be printable by const ref");
104
105 // underlying type of enums
106 static_assert(std::is_integral<underlying_type<SimpleEnum>::type>::value,
107 "simple enum must have some integral type");
108 static_assert(
109 std::is_same<underlying_type<EnumWithExplicitType>::type, uint64_t>::value,
110 "explicit type must be detected");
111 static_assert(std::is_same<underlying_type<ScopedEnum>::type, int>::value,
112 "scoped enum defaults to int");
113
51 } // namespace 114 } // namespace
52 } // namespace base 115 } // namespace base
OLDNEW
« base/logging.h ('K') | « base/template_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698