blob: e3602ccc5b008c9c767096874c353334db92de98 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
// Copyright (c) 2018 The LevelDB Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. See the AUTHORS file for names of contributors.
#include "util/no_destructor.h"
#include <cstdint>
#include <cstdlib>
#include <utility>
#include "gtest/gtest.h"
namespace leveldb {
namespace {
struct DoNotDestruct {
public:
DoNotDestruct(uint32_t a, uint64_t b) : a(a), b(b) {}
~DoNotDestruct() { std::abort(); }
// Used to check constructor argument forwarding.
uint32_t a;
uint64_t b;
};
constexpr const uint32_t kGoldenA = 0xdeadbeef;
constexpr const uint64_t kGoldenB = 0xaabbccddeeffaabb;
} // namespace
TEST(NoDestructorTest, StackInstance) {
NoDestructor<DoNotDestruct> instance(kGoldenA, kGoldenB);
ASSERT_EQ(kGoldenA, instance.get()->a);
ASSERT_EQ(kGoldenB, instance.get()->b);
}
TEST(NoDestructorTest, StaticInstance) {
static NoDestructor<DoNotDestruct> instance(kGoldenA, kGoldenB);
ASSERT_EQ(kGoldenA, instance.get()->a);
ASSERT_EQ(kGoldenB, instance.get()->b);
}
} // namespace leveldb
|