-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #366 from JeffersonLab/nbrei_facgen_fix
Bugfix: User-defined factory generators
- Loading branch information
Showing
9 changed files
with
52 additions
and
69 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
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
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
44 changes: 44 additions & 0 deletions
44
src/programs/unit_tests/Components/JFactoryGeneratorTests.cc
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,44 @@ | ||
|
||
|
||
#include <catch.hpp> | ||
#include <JANA/JApplication.h> | ||
#include <JANA/JFactoryGenerator.h> | ||
#include <JANA/Services/JComponentManager.h> | ||
|
||
|
||
// ----------------------------------- | ||
// UserDefined | ||
// ----------------------------------- | ||
namespace jana::components::jfactorygeneratortests_userdefined { | ||
|
||
struct MyData { int x; }; | ||
|
||
class MyFac : public JFactoryT<MyData> { | ||
void Init() override { | ||
GetApplication(); // This will throw if nullptr | ||
} | ||
void Process(const std::shared_ptr<const JEvent>&) override { | ||
std::vector<MyData*> results; | ||
results.push_back(new MyData {22}); | ||
Set(results); | ||
} | ||
}; | ||
|
||
class MyFacGen : public JFactoryGenerator { | ||
|
||
void GenerateFactories(JFactorySet *factory_set) override { | ||
factory_set->Add(new MyFac); | ||
} | ||
}; | ||
|
||
TEST_CASE("JFactoryGeneratorTests_UserDefined") { | ||
JApplication app; | ||
app.Add(new MyFacGen()); | ||
app.Initialize(); | ||
auto event = std::make_shared<JEvent>(); | ||
app.GetService<JComponentManager>()->configure_event(*event); | ||
|
||
auto data = event->Get<MyData>(); | ||
REQUIRE(data.at(0)->x == 22); | ||
} | ||
} |