-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow ESHandle be constructed from a whyFailedFactory of another ESHa…
…ndle
- Loading branch information
Showing
3 changed files
with
107 additions
and
3 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,99 @@ | ||
#include "catch.hpp" | ||
|
||
#include "FWCore/Framework/interface/ESHandle.h" | ||
#include "FWCore/Utilities/interface/EDMException.h" | ||
|
||
namespace { | ||
class TestExceptionFactory : public edm::ESHandleExceptionFactory { | ||
public: | ||
std::exception_ptr make() const override { return std::make_exception_ptr(edm::Exception(edm::errors::OtherCMS)); } | ||
}; | ||
} // namespace | ||
|
||
TEST_CASE("test edm::ESHandle", "[ESHandle]") { | ||
SECTION("Default constructor") { | ||
edm::ESHandle<int> handle; | ||
REQUIRE(not handle.isValid()); | ||
REQUIRE(not handle.failedToGet()); | ||
REQUIRE_THROWS_AS(handle.description(), edm::Exception); | ||
REQUIRE(handle.product() == nullptr); | ||
} | ||
|
||
SECTION("Valid construction, without ComponentDescription") { | ||
int const value = 42; | ||
edm::ESHandle<int> handle(&value); | ||
REQUIRE(not handle.isValid()); | ||
REQUIRE(not handle.failedToGet()); | ||
REQUIRE_THROWS_AS(handle.description(), edm::Exception); | ||
REQUIRE(handle.product() != nullptr); | ||
REQUIRE(*handle == value); | ||
} | ||
|
||
SECTION("Valid construction, with ComponentDescription") { | ||
int const value = 42; | ||
edm::eventsetup::ComponentDescription const desc; | ||
edm::ESHandle<int> handle(&value, &desc); | ||
REQUIRE(handle.isValid()); | ||
REQUIRE(not handle.failedToGet()); | ||
REQUIRE(handle.description() == &desc); | ||
REQUIRE(handle.product() != nullptr); | ||
REQUIRE(*handle == value); | ||
} | ||
|
||
SECTION("Failure construction from temporary") { | ||
edm::ESHandle<int> handle(std::make_shared<TestExceptionFactory>()); | ||
REQUIRE(not handle.isValid()); | ||
REQUIRE(handle.failedToGet()); | ||
REQUIRE_THROWS_AS(handle.description(), edm::Exception); | ||
REQUIRE_THROWS_AS(handle.product(), edm::Exception); | ||
} | ||
|
||
SECTION("Failure construction from object") { | ||
auto const factory = std::make_shared<TestExceptionFactory>(); | ||
edm::ESHandle<int> handle(factory); | ||
REQUIRE(not handle.isValid()); | ||
REQUIRE(handle.failedToGet()); | ||
REQUIRE_THROWS_AS(handle.description(), edm::Exception); | ||
REQUIRE_THROWS_AS(handle.product(), edm::Exception); | ||
REQUIRE(handle.whyFailedFactory().get() == factory.get()); | ||
} | ||
|
||
SECTION("Failure construction from another ESHandle") { | ||
auto const factory = std::make_shared<TestExceptionFactory>(); | ||
edm::ESHandle<int> handleA(factory); | ||
edm::ESHandle<int> handle(handleA.whyFailedFactory()); | ||
REQUIRE(not handle.isValid()); | ||
REQUIRE(handle.failedToGet()); | ||
REQUIRE_THROWS_AS(handle.description(), edm::Exception); | ||
REQUIRE_THROWS_AS(handle.product(), edm::Exception); | ||
REQUIRE(handle.whyFailedFactory().get() == factory.get()); | ||
} | ||
|
||
SECTION("Swap") { | ||
int const valueA = 42; | ||
edm::eventsetup::ComponentDescription const descA; | ||
edm::ESHandle<int> handleA(&valueA, &descA); | ||
|
||
SECTION("with value") { | ||
int const valueB = 3; | ||
edm::ESHandle<int> handleB(&valueB); | ||
|
||
std::swap(handleA, handleB); | ||
REQUIRE(not handleA.isValid()); | ||
REQUIRE(handleB.isValid()); | ||
REQUIRE(*handleB == valueA); | ||
} | ||
|
||
SECTION("with failure factory") { | ||
auto factory = std::make_shared<TestExceptionFactory>(); | ||
edm::ESHandle<int> handleB(factory); | ||
|
||
std::swap(handleA, handleB); | ||
REQUIRE(not handleA.isValid()); | ||
REQUIRE(handleA.failedToGet()); | ||
REQUIRE(handleA.whyFailedFactory().get() == factory.get()); | ||
REQUIRE(handleB.isValid()); | ||
REQUIRE(*handleB == valueA); | ||
} | ||
} | ||
} |