Skip to content

Commit

Permalink
Add simple reproducer of previous issue as test
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Nov 5, 2024
1 parent 87e0fee commit 8a3d387
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/unittests/frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ TEST_CASE("Frame parameters", "[frame][basics]") {
// Can't rely on an insertion order here
REQUIRE(std::find(stringKeys.begin(), stringKeys.end(), "aString") != stringKeys.end());
REQUIRE(std::find(stringKeys.begin(), stringKeys.end(), "someStrings") != stringKeys.end());

// Check the cases with empty vectors as parameters
event.putParameter("emptyVec", std::vector<int>{});
const auto emptyVec = event.getParameter<std::vector<int>>("emptyVec").value();
REQUIRE(emptyVec.empty());
REQUIRE_FALSE(event.getParameter<int>("emptyVec").has_value());
}

// NOTE: Due to the extremely small tasks that are done in these tests, they will
Expand Down
15 changes: 15 additions & 0 deletions tests/unittests/unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,21 @@ TEST_CASE("GenericParameters", "[generic-parameters]") {
REQUIRE_FALSE(gp.get<std::vector<std::string>>("Missing"));
}

TEST_CASE("GenericParameters empty vector single value access", "[generic-parameters]") {
auto gp = podio::GenericParameters();
gp.set("empty-ints", std::vector<int>{});

// Getting the whole vector works
const auto maybeVec = gp.get<std::vector<int>>("empty-ints");
REQUIRE(maybeVec.has_value());
const auto& vec = maybeVec.value();
REQUIRE(vec.empty());

// Trying to get a single (i.e. the first) value will not work
const auto maybeVal = gp.get<int>("empty-ints");
REQUIRE_FALSE(maybeVal.has_value());
}

TEST_CASE("GenericParameters constructors", "[generic-parameters]") {
// Tests for making sure that generic parameters can be moved / copied correctly
auto originalParams = podio::GenericParameters{};
Expand Down

0 comments on commit 8a3d387

Please sign in to comment.