forked from acts-project/acts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add optional context type getter (acts-project#3853)
Also adds a unit test.
- Loading branch information
1 parent
f335b09
commit f796676
Showing
3 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// This file is part of the ACTS project. | ||
// | ||
// Copyright (C) 2016 CERN for the benefit of the ACTS project | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
#include <boost/test/tools/old/interface.hpp> | ||
#include <boost/test/unit_test.hpp> | ||
|
||
#include "Acts/Utilities/detail/ContextType.hpp" | ||
|
||
using namespace Acts; | ||
|
||
BOOST_AUTO_TEST_SUITE(ContextTypeTests) | ||
|
||
BOOST_AUTO_TEST_CASE(PackUnpack) { | ||
ContextType ctx; | ||
|
||
int v = 42; | ||
ctx = v; | ||
|
||
BOOST_CHECK_EQUAL(ctx.get<int>(), 42); | ||
BOOST_CHECK_THROW(ctx.get<double>(), std::bad_any_cast); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(MaybeUnpack) { | ||
ContextType ctx; | ||
|
||
int v = 42; | ||
ctx = v; | ||
|
||
BOOST_CHECK_EQUAL(*ctx.maybeGet<int>(), 42); | ||
BOOST_CHECK_EQUAL(ctx.maybeGet<double>(), nullptr); | ||
} | ||
|
||
BOOST_AUTO_TEST_SUITE_END() |