1 // Copyright 2019 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 "base/util/type_safety/pass_key.h"
6 
7 #include <utility>
8 
9 #include "testing/gtest/include/gtest/gtest.h"
10 
11 namespace util {
12 namespace {
13 
14 class Manager;
15 
16 // May not be created without a PassKey.
17 class Restricted {
18  public:
Restricted(util::PassKey<Manager>)19   Restricted(util::PassKey<Manager>) {}
20 };
21 
22 class Manager {
23  public:
24   enum class ExplicitConstruction { kTag };
25   enum class UniformInitialization { kTag };
26 
Manager(ExplicitConstruction)27   Manager(ExplicitConstruction) : restricted_(util::PassKey<Manager>()) {}
Manager(UniformInitialization)28   Manager(UniformInitialization) : restricted_({}) {}
29 
30  private:
31   Restricted restricted_;
32 };
33 
34 // If this file compiles, then these test will run and pass. This is useful
35 // for verifying that the file actually was compiled into the unit test binary.
36 
TEST(PassKeyTest,ExplicitConstruction)37 TEST(PassKeyTest, ExplicitConstruction) {
38   Manager manager(Manager::ExplicitConstruction::kTag);
39 }
40 
TEST(PassKeyTest,UniformInitialization)41 TEST(PassKeyTest, UniformInitialization) {
42   Manager manager(Manager::UniformInitialization::kTag);
43 }
44 
45 }  // namespace
46 }  // namespace util
47