Toolbox snapshot
The Reactive C++ Toolbox
Loading...
Searching...
No Matches
Trans.ut.cpp
Go to the documentation of this file.
1// The Reactive C++ Toolbox.
2// Copyright (C) 2013-2019 Swirly Cloud Limited
3// Copyright (C) 2021 Reactive Markets Limited
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#include "Trans.hpp"
18
19#include <boost/test/unit_test.hpp>
20
21using namespace std;
22using namespace toolbox;
23
24namespace {
25
26struct Foo {
27
28 int start_calls{0};
29 int commit_calls{0};
30 int rollback_calls{0};
31
32 void clear() noexcept
33 {
34 start_calls = 0;
35 commit_calls = 0;
36 rollback_calls = 0;
37 }
38
39 void start() { ++start_calls; }
40 void commit() { ++commit_calls; }
41 void rollback() noexcept { ++rollback_calls; }
42};
43
45
46} // namespace
47
49
51{
52 Foo foo;
53 {
55 trans.commit();
56 }
57 BOOST_CHECK_EQUAL(foo.start_calls, 1);
58 BOOST_CHECK_EQUAL(foo.commit_calls, 1);
59 BOOST_CHECK_EQUAL(foo.rollback_calls, 0);
60 {
62 trans.commit();
63 }
64 BOOST_CHECK_EQUAL(foo.start_calls, 2);
65 BOOST_CHECK_EQUAL(foo.commit_calls, 2);
66 BOOST_CHECK_EQUAL(foo.rollback_calls, 0);
67}
68
70{
71 Foo foo;
72 {
74 }
75 BOOST_CHECK_EQUAL(foo.start_calls, 1);
76 BOOST_CHECK_EQUAL(foo.commit_calls, 0);
77 BOOST_CHECK_EQUAL(foo.rollback_calls, 1);
78 {
80 }
81 BOOST_CHECK_EQUAL(foo.start_calls, 2);
82 BOOST_CHECK_EQUAL(foo.commit_calls, 0);
83 BOOST_CHECK_EQUAL(foo.rollback_calls, 2);
84}
85
BOOST_CHECK_EQUAL(v.size(), 10U)
BOOST_AUTO_TEST_CASE(TransScopedCommitCase)
Definition Trans.ut.cpp:50
STL namespace.
void clear(timeval &tv) noexcept
Definition Time.hpp:294
constexpr auto bind() noexcept
Definition Slot.hpp:92