• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 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 "components/zucchini/typed_value.h"
6 
7 #include <type_traits>
8 
9 #include "testing/gtest/include/gtest/gtest.h"
10 
11 namespace zucchini {
12 
13 struct ValueA : TypedValue<ValueA, int> {
14   using ValueA::TypedValue::TypedValue;
15 };
16 
17 struct ValueB : TypedValue<ValueB, int> {
18   using ValueB::TypedValue::TypedValue;
19 };
20 
TEST(TypedIdTest,Value)21 TEST(TypedIdTest, Value) {
22   EXPECT_EQ(42, ValueA(42).value());
23   EXPECT_EQ(42, static_cast<int>(ValueA(42)));  // explicit cast
24 }
25 
TEST(TypedIdTest,Comparison)26 TEST(TypedIdTest, Comparison) {
27   EXPECT_TRUE(ValueA(0) == ValueA(0));
28   EXPECT_FALSE(ValueA(0) == ValueA(42));
29   EXPECT_FALSE(ValueA(0) != ValueA(0));
30   EXPECT_TRUE(ValueA(0) != ValueA(42));
31 }
32 
TEST(TypedIdTest,StrongType)33 TEST(TypedIdTest, StrongType) {
34   static_assert(!std::is_convertible<ValueA, ValueB>::value,
35                 "ValueA should not be convertible to ValueB");
36   static_assert(!std::is_convertible<ValueB, ValueA>::value,
37                 "ValueB should not be convertible to ValueA");
38 }
39 
40 }  // namespace zucchini
41