]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/utilities/object_registry_test.cc
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / rocksdb / utilities / object_registry_test.cc
1 // Copyright (c) 2016-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under the BSD-style license found in the
3 // LICENSE file in the root directory of this source tree. An additional grant
4 // of patent rights can be found in the PATENTS file in the same directory.
5
6 #ifndef ROCKSDB_LITE
7
8 #include "rocksdb/utilities/object_registry.h"
9 #include "util/testharness.h"
10
11 namespace rocksdb {
12
13 class EnvRegistryTest : public testing::Test {
14 public:
15 static int num_a, num_b;
16 };
17
18 int EnvRegistryTest::num_a = 0;
19 int EnvRegistryTest::num_b = 0;
20
21 static Registrar<Env> test_reg_a("a://.*", [](const std::string& uri,
22 std::unique_ptr<Env>* env_guard) {
23 ++EnvRegistryTest::num_a;
24 return Env::Default();
25 });
26
27 static Registrar<Env> test_reg_b("b://.*", [](const std::string& uri,
28 std::unique_ptr<Env>* env_guard) {
29 ++EnvRegistryTest::num_b;
30 // Env::Default() is a singleton so we can't grant ownership directly to the
31 // caller - we must wrap it first.
32 env_guard->reset(new EnvWrapper(Env::Default()));
33 return env_guard->get();
34 });
35
36 TEST_F(EnvRegistryTest, Basics) {
37 std::unique_ptr<Env> env_guard;
38 auto res = NewCustomObject<Env>("a://test", &env_guard);
39 ASSERT_NE(res, nullptr);
40 ASSERT_EQ(env_guard, nullptr);
41 ASSERT_EQ(1, num_a);
42 ASSERT_EQ(0, num_b);
43
44 res = NewCustomObject<Env>("b://test", &env_guard);
45 ASSERT_NE(res, nullptr);
46 ASSERT_NE(env_guard, nullptr);
47 ASSERT_EQ(1, num_a);
48 ASSERT_EQ(1, num_b);
49
50 res = NewCustomObject<Env>("c://test", &env_guard);
51 ASSERT_EQ(res, nullptr);
52 ASSERT_EQ(env_guard, nullptr);
53 ASSERT_EQ(1, num_a);
54 ASSERT_EQ(1, num_b);
55 }
56
57 } // namespace rocksdb
58
59 int main(int argc, char** argv) {
60 ::testing::InitGoogleTest(&argc, argv);
61 return RUN_ALL_TESTS();
62 }
63
64 #else // ROCKSDB_LITE
65 #include <stdio.h>
66
67 int main(int argc, char** argv) {
68 fprintf(stderr, "SKIPPED as EnvRegistry is not supported in ROCKSDB_LITE\n");
69 return 0;
70 }
71
72 #endif // ROCKSDB_LITE