Skip to content

Commit

Permalink
Add a test for a float to double migration
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Sep 12, 2023
1 parent 8b8f99a commit 36d06e6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions tests/schema_evolution/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ tested (if it is supported)
| `SimpleStruct` | no `int t` member in v2 | Addition of new members in components | As member of `ExampleWithArrayComponent` |
| `ExampleHit` | no `double t` member in v1 | Addition of new members in datatypes | Directly via `ExampleHit` |
| `ex2::NamespaceStruct` | renaming of `y` to `y_new` | Renaming of member variables | As member of `ex42::ExampleWithNamespace` |
| `ex42::ExampleWithARelation` | type of `number` member | migration of `float` to `double` | Direcetly via `ex42::ExampleWithARelation` |
2 changes: 1 addition & 1 deletion tests/schema_evolution/datalayout_new.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ datatypes :
Description : "Type with namespace and namespaced relation"
Author : "Joschka Lingemann"
Members:
- float number // just a number
- double number // just a number
OneToOneRelations :
- ex42::ExampleWithNamespace ref // a ref in a namespace
OneToManyRelations :
Expand Down
11 changes: 11 additions & 0 deletions tests/schema_evolution/read_new_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define PODIO_TESTS_SCHEMAEVOLUTION_READNEWDATA_H // NOLINT(llvm-header-guard): folder structure not suitable

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

Expand Down Expand Up @@ -52,6 +53,15 @@ int readExampleWithNamespace(const podio::Frame& event) {
return 0;
}

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

ASSERT_EQUAL(elem.number(), (double)3.14f, "Conversion from float to double member does not work as expected");

return 0;
}

template <typename ReaderT>
int read_new_data(const std::string& filename) {
ReaderT reader{};
Expand All @@ -63,6 +73,7 @@ int read_new_data(const std::string& filename) {
result += readSimpleStruct(event);
result += readExampleHit(event);
result += readExampleWithNamespace(event);
result += readExampleWithARelation(event);

return result;
}
Expand Down
10 changes: 10 additions & 0 deletions tests/schema_evolution/write_old_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define PODIO_TESTS_SCHEMAEVOLUTION_WRITEOLDDATA_H // NOLINT(llvm-header-guard): folder structure not suitable

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

Expand Down Expand Up @@ -41,12 +42,21 @@ auto writeExampleWithNamespace() {
return coll;
}

auto writeExamplewWithARelation() {
ex42::ExampleWithARelationCollection coll;
auto elem = coll.create();
elem.number(3.14f);

return coll;
}

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

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

return event;
}
Expand Down

0 comments on commit 36d06e6

Please sign in to comment.