blob: beb7313cc7f9fa7e38522e4e86b89fbc0d6bf9b7 [file] [log] [blame]
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/type_id.h"
#include "base/test/type_id_test_support_a.h"
#include "base/test/type_id_test_support_b.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace base {
namespace {
struct T {};
struct U {};
} // namespace
TEST(TypeId, Basic) {
static_assert(TypeId::Create<int>() == TypeId::Create<int>(), "");
static_assert(TypeId::Create<int>() != TypeId::Create<void>(), "");
static_assert(TypeId::Create<int>() != TypeId::Create<float>(), "");
static_assert(TypeId::Create<int>() != TypeId::Create<std::unique_ptr<T>>(),
"");
static_assert(TypeId::Create<int>() != TypeId::Create<std::unique_ptr<U>>(),
"");
static_assert(TypeId::Create<void>() != TypeId::Create<int>(), "");
static_assert(TypeId::Create<void>() == TypeId::Create<void>(), "");
static_assert(TypeId::Create<void>() != TypeId::Create<float>(), "");
static_assert(TypeId::Create<void>() != TypeId::Create<std::unique_ptr<T>>(),
"");
static_assert(TypeId::Create<void>() != TypeId::Create<std::unique_ptr<U>>(),
"");
static_assert(TypeId::Create<float>() != TypeId::Create<int>(), "");
static_assert(TypeId::Create<float>() != TypeId::Create<void>(), "");
static_assert(TypeId::Create<float>() == TypeId::Create<float>(), "");
static_assert(TypeId::Create<float>() != TypeId::Create<std::unique_ptr<T>>(),
"");
static_assert(TypeId::Create<float>() != TypeId::Create<std::unique_ptr<U>>(),
"");
static_assert(TypeId::Create<std::unique_ptr<T>>() != TypeId::Create<int>(),
"");
static_assert(TypeId::Create<std::unique_ptr<T>>() != TypeId::Create<void>(),
"");
static_assert(TypeId::Create<std::unique_ptr<T>>() != TypeId::Create<float>(),
"");
static_assert(TypeId::Create<std::unique_ptr<T>>() ==
TypeId::Create<std::unique_ptr<T>>(),
"");
static_assert(TypeId::Create<std::unique_ptr<T>>() !=
TypeId::Create<std::unique_ptr<U>>(),
"");
static_assert(TypeId::Create<std::unique_ptr<U>>() != TypeId::Create<int>(),
"");
static_assert(TypeId::Create<std::unique_ptr<U>>() != TypeId::Create<void>(),
"");
static_assert(TypeId::Create<std::unique_ptr<U>>() != TypeId::Create<float>(),
"");
static_assert(TypeId::Create<std::unique_ptr<U>>() !=
TypeId::Create<std::unique_ptr<T>>(),
"");
static_assert(TypeId::Create<std::unique_ptr<U>>() ==
TypeId::Create<std::unique_ptr<U>>(),
"");
}
TEST(TypeId, TypesInAnonymousNameSpacesDontCollide) {
EXPECT_NE(TypeIdTestSupportA::GetTypeIdForTypeInAnonymousNameSpace(),
TypeIdTestSupportB::GetTypeIdForTypeInAnonymousNameSpace());
}
// See http://crbug.com/914734
#if defined(ADDRESS_SANITIZER)
TEST(TypeId, DISABLED_IdenticalTypesFromDifferentCompilationUnitsMatch) {
#else
TEST(TypeId, IdenticalTypesFromDifferentCompilationUnitsMatch) {
#endif
EXPECT_EQ(TypeIdTestSupportA::GetTypeIdForUniquePtrInt(),
TypeIdTestSupportB::GetTypeIdForUniquePtrInt());
}
} // namespace base