• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

realm / realm-core / 2357

29 May 2024 11:05PM UTC coverage: 90.843% (+0.04%) from 90.801%
2357

push

Evergreen

web-flow
Merge pull request #7609 from realm/tg/session-lifecycle

RCORE-2092 Simplify the SessionWrapper lifecycle a bit

101578 of 179868 branches covered (56.47%)

506 of 544 new or added lines in 14 files covered. (93.01%)

42 existing lines in 13 files now uncovered.

214462 of 236080 relevant lines covered (90.84%)

5704793.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.16
/test/test_util_scope_exit.cpp
1
/*************************************************************************
2
 *
3
 * Copyright 2016 Realm Inc.
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 **************************************************************************/
18

19
#include "testsettings.hpp"
20

21
#include <realm/util/scope_exit.hpp>
22

23
#include "test.hpp"
24

25
using namespace realm;
26

27
// Test independence and thread-safety
28
// -----------------------------------
29
//
30
// All tests must be thread safe and independent of each other. This
31
// is required because it allows for both shuffling of the execution
32
// order and for parallelized testing.
33
//
34
// In particular, avoid using std::rand() since it is not guaranteed
35
// to be thread safe. Instead use the API offered in
36
// `test/util/random.hpp`.
37
//
38
// All files created in tests must use the TEST_PATH macro (or one of
39
// its friends) to obtain a suitable file system path. See
40
// `test/util/test_path.hpp`.
41
//
42
//
43
// Debugging and the ONLY() macro
44
// ------------------------------
45
//
46
// A simple way of disabling all tests except one called `Foo`, is to
47
// replace TEST(Foo) with ONLY(Foo) and then recompile and rerun the
48
// test suite. Note that you can also use filtering by setting the
49
// environment varible `UNITTEST_FILTER`. See `README.md` for more on
50
// this.
51
//
52
// Another way to debug a particular test, is to copy that test into
53
// `experiments/testcase.cpp` and then run `sh build.sh
54
// check-testcase` (or one of its friends) from the command line.
55

56
namespace {
57

58
TEST(Util_ScopeExit_Basics)
59
{
2✔
60
    bool called = false;
2✔
61
    {
2✔
62
        util::ScopeExit se([&]() noexcept {
2✔
63
            called = true;
2✔
64
        });
2✔
65
        CHECK_NOT(called);
2✔
66
    }
2✔
67
    CHECK(called);
2✔
68

69
    called = false;
2✔
70
    try {
2✔
71
        util::ScopeExit se([&]() noexcept {
2✔
72
            called = true;
2✔
73
        });
2✔
74
        CHECK_NOT(called);
2✔
75
        throw 0;
2✔
76
    }
2✔
77
    catch (int) {
2✔
78
    }
2✔
79
    CHECK(called);
2✔
80

81
    called = false;
2✔
82
    {
2✔
83
        util::ScopeExit se([&]() noexcept {
2✔
NEW
84
            called = true;
×
NEW
85
        });
×
86
        CHECK_NOT(called);
2✔
87
        se.cancel();
2✔
88
    }
2✔
89
    CHECK_NOT(called);
2✔
90
}
2✔
91

92
TEST(Util_ScopeExit_Fail)
93
{
2✔
94
    bool called = false;
2✔
95
    {
2✔
96
        util::ScopeExitFail se([&]() noexcept {
2✔
NEW
97
            called = true;
×
NEW
98
        });
×
99
        CHECK_NOT(called);
2✔
100
    }
2✔
101
    CHECK_NOT(called);
2✔
102

103
    called = false;
2✔
104
    try {
2✔
105
        util::ScopeExit se([&]() noexcept {
2✔
106
            called = true;
2✔
107
        });
2✔
108
        CHECK_NOT(called);
2✔
109
        throw 0;
2✔
110
    }
2✔
111
    catch (int) {
2✔
112
    }
2✔
113
    CHECK(called);
2✔
114
}
2✔
115

116
} // unnamed namespace
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc