-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test JOmniFactory/JService interaction
- Loading branch information
1 parent
165a8fd
commit f041ee1
Showing
3 changed files
with
84 additions
and
1 deletion.
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,82 @@ | ||
|
||
#include <catch.hpp> | ||
#include <JANA/JApplication.h> | ||
#include <JANA/JService.h> | ||
#include <JANA/Components/JOmniFactory.h> | ||
#include <JANA/Components/JOmniFactoryGeneratorT.h> | ||
|
||
namespace jana::jservicetests { | ||
|
||
class DummyService: public JService { | ||
bool init_started = false; | ||
bool init_finished = false; | ||
public: | ||
void Init() override { | ||
LOG_INFO(GetLogger()) << "Starting DummyService::Init()" << LOG_END; | ||
init_started = true; | ||
throw std::runtime_error("Something goes wrong"); | ||
init_finished = true; | ||
LOG_INFO(GetLogger()) << "Finishing DummyService::Init()" << LOG_END; | ||
} | ||
}; | ||
|
||
TEST_CASE("JServiceTests_ExceptionInInit") { | ||
JApplication app; | ||
app.ProvideService(std::make_shared<DummyService>()); | ||
try { | ||
app.Initialize(); | ||
REQUIRE(1 == 0); // Shouldn't be reachable | ||
|
||
auto sut = app.GetService<DummyService>(); | ||
REQUIRE(1 == 0); // Definitely shouldn't be reachable | ||
} | ||
catch (JException& e) { | ||
REQUIRE(e.GetMessage() == "Something goes wrong"); | ||
REQUIRE(e.type_name == "jana::jservicetests::DummyService"); | ||
REQUIRE(e.function_name == "JService::Init"); | ||
} | ||
} | ||
|
||
struct DummyData {int x;}; | ||
|
||
struct DummyOmniFactory: public jana::components::JOmniFactory<DummyOmniFactory> { | ||
|
||
Service<DummyService> m_svc {this}; | ||
Output<DummyData> m_output {this}; | ||
|
||
void Configure() { | ||
} | ||
|
||
void ChangeRun(int32_t /*run_nr*/) { | ||
} | ||
|
||
void Execute(int32_t /*run_nr*/, uint64_t /*evt_nr*/) { | ||
m_output().push_back(new DummyData{22}); | ||
} | ||
}; | ||
|
||
TEST_CASE("JServiceTests_ExceptionInInit_Issue381") { | ||
JApplication app; | ||
app.ProvideService(std::make_shared<DummyService>()); | ||
|
||
auto gen = new components::JOmniFactoryGeneratorT<DummyOmniFactory>(); | ||
gen->AddWiring("dummy", {}, {"data"}); | ||
app.Add(gen); | ||
|
||
try { | ||
app.Initialize(); | ||
REQUIRE(1 == 0); // Shouldn't be reachable | ||
auto event = std::make_shared<JEvent>(&app); | ||
auto data = event->Get<DummyData>("data"); | ||
REQUIRE(1 == 0); // Definitely shouldn't be reachable | ||
REQUIRE(data.at(0)->x == 22); | ||
} | ||
catch (JException& e) { | ||
REQUIRE(e.GetMessage() == "Something goes wrong"); | ||
REQUIRE(e.type_name == "jana::jservicetests::DummyService"); | ||
REQUIRE(e.function_name == "JService::Init"); | ||
} | ||
} | ||
|
||
} // namespace jana::jservicetests | ||
|