Skip to content

Commit

Permalink
Add tests that reproduce crash / failure
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Jul 25, 2023
1 parent 65b58ea commit d303c90
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
13 changes: 13 additions & 0 deletions tests/read_frame.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef PODIO_TESTS_READ_FRAME_H // NOLINT(llvm-header-guard): folder structure not suitable
#define PODIO_TESTS_READ_FRAME_H // NOLINT(llvm-header-guard): folder structure not suitable

#include "datamodel/ExampleWithVectorMemberCollection.h"
#include "read_test.h"

#include "extension_model/ContainedTypeCollection.h"
Expand Down Expand Up @@ -60,6 +61,14 @@ void processExtensions(const podio::Frame& event, int iEvent, podio::version::Ve
ASSERT(structs[2].y == 2 * iEvent, "struct value not as expected");
}

void checkVecMemSubsetColl(const podio::Frame& event) {
const auto& subsetColl = event.get<ExampleWithVectorMemberCollection>("VectorMemberSubsetColl");
const auto& origColl = event.get<ExampleWithVectorMemberCollection>("WithVectorMember");
ASSERT(subsetColl.isSubsetCollection(), "subset collection not read back as a sbuset collection");
ASSERT(subsetColl.size() == 1, "subset collection should have size 1");
ASSERT(subsetColl[0] == origColl[0], "subset coll does not have the right contents");
}

template <typename ReaderT>
int read_frames(const std::string& filename, bool assertBuildVersion = true) {
auto reader = ReaderT();
Expand Down Expand Up @@ -112,6 +121,10 @@ int read_frames(const std::string& filename, bool assertBuildVersion = true) {
if (reader.currentFileVersion() > podio::version::Version{0, 16, 2}) {
processExtensions(otherFrame, i + 100, reader.currentFileVersion());
}
// As well as a test for the vector members subset category
if (reader.currentFileVersion() >= podio::version::Version{0, 16, 99}) {
checkVecMemSubsetColl(otherFrame);
}
}

if (reader.readNextEntry(podio::Category::Event)) {
Expand Down
12 changes: 11 additions & 1 deletion tests/write_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,15 @@ auto createVectorMemberCollection(int i) {
return vecs;
}

auto createVectorMemberSubsetCollection(const ExampleWithVectorMemberCollection& coll) {
ExampleWithVectorMemberCollection refs;
refs.setSubsetCollection();

refs.push_back(coll[0]);

return refs;
}

auto createInfoCollection(int i) {
EventInfoCollection info;

Expand Down Expand Up @@ -361,7 +370,8 @@ podio::Frame makeFrame(int iFrame) {
podio::Frame frame{};

frame.put(createArrayCollection(iFrame), "arrays");
frame.put(createVectorMemberCollection(iFrame), "WithVectorMember");
const auto& vecMemColl = frame.put(createVectorMemberCollection(iFrame), "WithVectorMember");
frame.put(createVectorMemberSubsetCollection(vecMemColl), "VectorMemberSubsetColl");
frame.put(createInfoCollection(iFrame), "info");
frame.put(createFixedWidthCollection(), "fixedWidthInts");

Expand Down

0 comments on commit d303c90

Please sign in to comment.