typed_value_unittest.cc 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. #include "components/zucchini/typed_value.h"
  5. #include <type_traits>
  6. #include "testing/gtest/include/gtest/gtest.h"
  7. namespace zucchini {
  8. struct ValueA : TypedValue<ValueA, int> {
  9. using ValueA::TypedValue::TypedValue;
  10. };
  11. struct ValueB : TypedValue<ValueB, int> {
  12. using ValueB::TypedValue::TypedValue;
  13. };
  14. TEST(TypedIdTest, Value) {
  15. EXPECT_EQ(42, ValueA(42).value());
  16. EXPECT_EQ(42, static_cast<int>(ValueA(42))); // explicit cast
  17. }
  18. TEST(TypedIdTest, Comparison) {
  19. EXPECT_TRUE(ValueA(0) == ValueA(0));
  20. EXPECT_FALSE(ValueA(0) == ValueA(42));
  21. EXPECT_FALSE(ValueA(0) != ValueA(0));
  22. EXPECT_TRUE(ValueA(0) != ValueA(42));
  23. }
  24. TEST(TypedIdTest, StrongType) {
  25. static_assert(!std::is_convertible<ValueA, ValueB>::value,
  26. "ValueA should not be convertible to ValueB");
  27. static_assert(!std::is_convertible<ValueB, ValueA>::value,
  28. "ValueB should not be convertible to ValueA");
  29. }
  30. } // namespace zucchini