Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-30 09:27:35

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include <boost/test/unit_test.hpp>
0010 
0011 #include "Acts/Utilities/detail/ScopeExit.hpp"
0012 
0013 #include <stdexcept>
0014 
0015 using Acts::detail::ScopeExit;
0016 
0017 BOOST_AUTO_TEST_SUITE(ScopeExitTests)
0018 
0019 BOOST_AUTO_TEST_CASE(CalledOnceAtScopeEnd) {
0020   int calls = 0;
0021   {
0022     const ScopeExit guard([&] { ++calls; });
0023     BOOST_CHECK_EQUAL(calls, 0);
0024   }
0025   BOOST_CHECK_EQUAL(calls, 1);
0026 }
0027 
0028 BOOST_AUTO_TEST_CASE(CalledOnEarlyReturn) {
0029   int calls = 0;
0030   auto f = [&](bool early) {
0031     const ScopeExit guard([&] { ++calls; });
0032     if (early) {
0033       return 1;
0034     }
0035     return 2;
0036   };
0037   BOOST_CHECK_EQUAL(f(true), 1);
0038   BOOST_CHECK_EQUAL(f(false), 2);
0039   BOOST_CHECK_EQUAL(calls, 2);
0040 }
0041 
0042 BOOST_AUTO_TEST_CASE(CalledOnException) {
0043   int calls = 0;
0044   BOOST_CHECK_THROW(
0045       {
0046         const ScopeExit guard([&] { ++calls; });
0047         throw std::runtime_error("scope");
0048       },
0049       std::runtime_error);
0050   BOOST_CHECK_EQUAL(calls, 1);
0051 }
0052 
0053 BOOST_AUTO_TEST_SUITE_END()