]>
git.proxmox.com Git - ceph.git/blob - 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.
8 #include "rocksdb/utilities/object_registry.h"
9 #include "util/testharness.h"
13 class EnvRegistryTest
: public testing::Test
{
15 static int num_a
, num_b
;
18 int EnvRegistryTest::num_a
= 0;
19 int EnvRegistryTest::num_b
= 0;
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();
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();
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);
44 res
= NewCustomObject
<Env
>("b://test", &env_guard
);
45 ASSERT_NE(res
, nullptr);
46 ASSERT_NE(env_guard
, nullptr);
50 res
= NewCustomObject
<Env
>("c://test", &env_guard
);
51 ASSERT_EQ(res
, nullptr);
52 ASSERT_EQ(env_guard
, nullptr);
57 } // namespace rocksdb
59 int main(int argc
, char** argv
) {
60 ::testing::InitGoogleTest(&argc
, argv
);
61 return RUN_ALL_TESTS();
67 int main(int argc
, char** argv
) {
68 fprintf(stderr
, "SKIPPED as EnvRegistry is not supported in ROCKSDB_LITE\n");
72 #endif // ROCKSDB_LITE