Skip to content

Commit

Permalink
Add failing test for renamed member variables
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Jun 21, 2023
1 parent 3ccd157 commit 557f347
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
1 change: 1 addition & 0 deletions tests/schema_evolution/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ tested (if it is supported)
|--|--|--|--|
| `SimpleStruct` | no `int y` member in v1 | Addition of new members in components | As member of `ExampleWithArrayComponent` |
| `ExampleHit` | no `double energy` member in v1 | Addition of new members in datatypes | Directly via `ExampleHit` |
| `ex2::NamespaceStruct` | renaming of `y_old` to `y` | Renaming of member variables | As member of `ex42::ExampleWithNamespace` |
36 changes: 27 additions & 9 deletions tests/schema_evolution/read_new_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,50 @@

#include "datamodel/ExampleHitCollection.h"
#include "datamodel/ExampleWithArrayComponentCollection.h"
#include "datamodel/ExampleWithNamespaceCollection.h"

#include "podio/Frame.h"

#include <iostream>
#include <string>

#define ASSERT_EQUAL(actual, expected, msg) \
if ((expected) != (actual)) { \
std::cerr << __PRETTY_FUNCTION__ << ": " << msg << " (expected: " << expected << ", actual: " << actual << ")"; \
return 1; \
}

int readSimpleStruct(const podio::Frame& event) {
const auto& coll = event.get<ExampleWithArrayComponentCollection>("simpleStructTest");
auto elem = coll[0];
const auto sstruct = elem.s();

if (sstruct.y != 0 || sstruct.x != 42 || sstruct.z != 123) {
return 1;
}
ASSERT_EQUAL(sstruct.y, 0, "New component member not 0 initialized");
ASSERT_EQUAL(sstruct.x, 42, "Existing component member changed");
ASSERT_EQUAL(sstruct.z, 123, "Existing component member changed");

return 0;
}

int readExampleHit(const podio::Frame& event) {
const auto& coll = event.get<ExampleHitCollection>("datatypeMemberAdditionTest");
auto elem = coll[0];

if (elem.energy() != 0) {
return 1;
}
if (elem.x() != 1.23 || elem.y() != 1.23 || elem.z() != 1.23 || elem.cellID() != 0xcaffee) {
return 1;
}
ASSERT_EQUAL(elem.energy(), 0, "New datatype member variable not 0 initialized");
ASSERT_EQUAL(elem.x(), 1.23, "Member variables unrelated to schema evolution have changed");
ASSERT_EQUAL(elem.y(), 1.23, "Member variables unrelated to schema evolution have changed");
ASSERT_EQUAL(elem.z(), 1.23, "Member variables unrelated to schema evolution have changed");
ASSERT_EQUAL(elem.cellID(), 0xcaffee, "Member variables unrelated to schema evolution have changed");

return 0;
}

int readExampleWithNamespace(const podio::Frame& event) {
const auto& coll = event.get<ex42::ExampleWithNamespaceCollection>("componentMemberRenameTest");
auto elem = coll[0];

ASSERT_EQUAL(elem.y(), 42, "Renamed component member variable does not have the expected value");
ASSERT_EQUAL(elem.x(), 123, "Member variables unrelated to schema evolution have changed");

return 0;
}
Expand All @@ -44,6 +61,7 @@ int read_new_data(const std::string& filename) {
int result = 0;
result += readSimpleStruct(event);
result += readExampleHit(event);
result += readExampleWithNamespace(event);

return result;
}
Expand Down
11 changes: 11 additions & 0 deletions tests/schema_evolution/write_old_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "datamodel/ExampleHitCollection.h"
#include "datamodel/ExampleWithArrayComponentCollection.h"
#include "datamodel/ExampleWithNamespaceCollection.h"

#include "podio/Frame.h"

Expand Down Expand Up @@ -31,11 +32,21 @@ auto writeExampleHit() {
return coll;
}

auto writeExampleWithNamespace() {
ex42::ExampleWithNamespaceCollection coll;
auto elem = coll.create();
elem.y_old(42);
elem.x(123);

return coll;
}

podio::Frame createFrame() {
podio::Frame event;

event.put(writeSimpleStruct(), "simpleStructTest");
event.put(writeExampleHit(), "datatypeMemberAdditionTest");
event.put(writeExampleWithNamespace(), "componentMemberRenameTest");

return event;
}
Expand Down

0 comments on commit 557f347

Please sign in to comment.