[M108 Migration][VD] Support set time and time zone offset
[platform/framework/web/chromium-efl.git] / base / template_util_unittest.cc
1 // Copyright 2012 The Chromium Authors
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 <string>
8 #include <type_traits>
9
10 #include "base/containers/flat_tree.h"
11 #include "base/test/move_only_int.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 namespace base {
15 namespace {
16
17 enum SimpleEnum { SIMPLE_ENUM };
18 enum EnumWithExplicitType : uint64_t { ENUM_WITH_EXPLICIT_TYPE };
19 enum class ScopedEnum { SCOPED_ENUM };
20 enum class ScopedEnumWithOperator { SCOPED_ENUM_WITH_OPERATOR };
21 std::ostream& operator<<(std::ostream& os, ScopedEnumWithOperator v) {
22   return os;
23 }
24 struct SimpleStruct {};
25 struct StructWithOperator {};
26 std::ostream& operator<<(std::ostream& os, const StructWithOperator& v) {
27   return os;
28 }
29 struct StructWithToString {
30   std::string ToString() const { return ""; }
31 };
32
33 // A few standard types that definitely support printing.
34 static_assert(internal::SupportsOstreamOperator<int>::value,
35               "ints should be printable");
36 static_assert(internal::SupportsOstreamOperator<const char*>::value,
37               "C strings should be printable");
38 static_assert(internal::SupportsOstreamOperator<std::string>::value,
39               "std::string should be printable");
40
41 // Various kinds of enums operator<< support.
42 static_assert(internal::SupportsOstreamOperator<SimpleEnum>::value,
43               "simple enum should be printable by value");
44 static_assert(internal::SupportsOstreamOperator<const SimpleEnum&>::value,
45               "simple enum should be printable by const ref");
46 static_assert(internal::SupportsOstreamOperator<EnumWithExplicitType>::value,
47               "enum with explicit type should be printable by value");
48 static_assert(
49     internal::SupportsOstreamOperator<const EnumWithExplicitType&>::value,
50     "enum with explicit type should be printable by const ref");
51 static_assert(!internal::SupportsOstreamOperator<ScopedEnum>::value,
52               "scoped enum should not be printable by value");
53 static_assert(!internal::SupportsOstreamOperator<const ScopedEnum&>::value,
54               "simple enum should not be printable by const ref");
55 static_assert(internal::SupportsOstreamOperator<ScopedEnumWithOperator>::value,
56               "scoped enum with operator<< should be printable by value");
57 static_assert(
58     internal::SupportsOstreamOperator<const ScopedEnumWithOperator&>::value,
59     "scoped enum with operator<< should be printable by const ref");
60
61 // operator<< support on structs.
62 static_assert(!internal::SupportsOstreamOperator<SimpleStruct>::value,
63               "simple struct should not be printable by value");
64 static_assert(!internal::SupportsOstreamOperator<const SimpleStruct&>::value,
65               "simple struct should not be printable by const ref");
66 static_assert(internal::SupportsOstreamOperator<StructWithOperator>::value,
67               "struct with operator<< should be printable by value");
68 static_assert(
69     internal::SupportsOstreamOperator<const StructWithOperator&>::value,
70     "struct with operator<< should be printable by const ref");
71
72 // .ToString() support on structs.
73 static_assert(!internal::SupportsToString<SimpleStruct>::value,
74               "simple struct value doesn't support .ToString()");
75 static_assert(!internal::SupportsToString<const SimpleStruct&>::value,
76               "simple struct const ref doesn't support .ToString()");
77 static_assert(internal::SupportsToString<StructWithToString>::value,
78               "struct with .ToString() should be printable by value");
79 static_assert(internal::SupportsToString<const StructWithToString&>::value,
80               "struct with .ToString() should be printable by const ref");
81
82 // is_scoped_enum
83 TEST(TemplateUtil, IsScopedEnum) {
84   static_assert(!is_scoped_enum<int>::value, "");
85   static_assert(!is_scoped_enum<SimpleEnum>::value, "");
86   static_assert(!is_scoped_enum<EnumWithExplicitType>::value, "");
87   static_assert(is_scoped_enum<ScopedEnum>::value, "");
88 }
89
90 TEST(TemplateUtil, RemoveCvRefT) {
91   static_assert(std::is_same<int, remove_cvref_t<const int>>::value, "");
92   static_assert(std::is_same<int, remove_cvref_t<const volatile int>>::value,
93                 "");
94   static_assert(std::is_same<int, remove_cvref_t<int&>>::value, "");
95   static_assert(std::is_same<int, remove_cvref_t<const int&>>::value, "");
96   static_assert(std::is_same<int, remove_cvref_t<const volatile int&>>::value,
97                 "");
98   static_assert(std::is_same<int, remove_cvref_t<int&&>>::value, "");
99   static_assert(
100       std::is_same<SimpleStruct, remove_cvref_t<const SimpleStruct&>>::value,
101       "");
102   static_assert(std::is_same<int*, remove_cvref_t<int*>>::value, "");
103
104   // Test references and pointers to arrays.
105   static_assert(std::is_same<int[3], remove_cvref_t<int[3]>>::value, "");
106   static_assert(std::is_same<int[3], remove_cvref_t<int(&)[3]>>::value, "");
107   static_assert(std::is_same<int(*)[3], remove_cvref_t<int(*)[3]>>::value, "");
108
109   // Test references and pointers to functions.
110   static_assert(std::is_same<void(int), remove_cvref_t<void(int)>>::value, "");
111   static_assert(std::is_same<void(int), remove_cvref_t<void (&)(int)>>::value,
112                 "");
113   static_assert(
114       std::is_same<void (*)(int), remove_cvref_t<void (*)(int)>>::value, "");
115 }
116
117 }  // namespace
118
119 }  // namespace base