diff --git a/tests/schema_evolution/README.md b/tests/schema_evolution/README.md index 0b55945ab..4ed849b48 100644 --- a/tests/schema_evolution/README.md +++ b/tests/schema_evolution/README.md @@ -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` | diff --git a/tests/schema_evolution/read_new_data.h b/tests/schema_evolution/read_new_data.h index e31e3c3e8..59ed31550 100644 --- a/tests/schema_evolution/read_new_data.h +++ b/tests/schema_evolution/read_new_data.h @@ -3,20 +3,28 @@ #include "datamodel/ExampleHitCollection.h" #include "datamodel/ExampleWithArrayComponentCollection.h" +#include "datamodel/ExampleWithNamespaceCollection.h" #include "podio/Frame.h" #include #include +#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("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; } @@ -24,12 +32,21 @@ int readExampleHit(const podio::Frame& event) { const auto& coll = event.get("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("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; } @@ -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; } diff --git a/tests/schema_evolution/write_old_data.h b/tests/schema_evolution/write_old_data.h index 3367f2fa9..9232e59af 100644 --- a/tests/schema_evolution/write_old_data.h +++ b/tests/schema_evolution/write_old_data.h @@ -3,6 +3,7 @@ #include "datamodel/ExampleHitCollection.h" #include "datamodel/ExampleWithArrayComponentCollection.h" +#include "datamodel/ExampleWithNamespaceCollection.h" #include "podio/Frame.h" @@ -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; }