@@ -1073,3 +1073,60 @@ TEST_F(MigrationTest, check_user_factory_can_create_all_static_properties) {
10731073 }
10741074 }
10751075}
1076+
1077+ void change_property (ValueBase* value) {
1078+ switch (value->type ()) {
1079+ case PrimitiveType::Bool:
1080+ *value = !value->asBool ();
1081+ break ;
1082+ case PrimitiveType::Int:
1083+ *value = value->asInt () + 1 ;
1084+ break ;
1085+ case PrimitiveType::Int64:
1086+ *value = value->asInt64 () + 1 ;
1087+ break ;
1088+ case PrimitiveType::Double:
1089+ *value = value->asDouble () + 1 ;
1090+ break ;
1091+ case PrimitiveType::String:
1092+ *value = value->asString () + " postfix" ;
1093+ break ;
1094+ case PrimitiveType::Ref:
1095+ // We can't just change the pointer here but would need to create another valid object as pointer target.
1096+ // Ignore for now since we don't have Ref properties inside structs yet.
1097+ break ;
1098+ case PrimitiveType::Table:
1099+ case PrimitiveType::Struct: {
1100+ auto & container = value->getSubstructure ();
1101+ for (size_t index = 0 ; index < container.size (); index++) {
1102+ change_property (container.get (index));
1103+ }
1104+ } break ;
1105+ }
1106+ }
1107+
1108+ TEST_F (MigrationTest, check_struct_copy_operators) {
1109+ // Check that the copy constructor and operator= work for all struct types.
1110+ // If this fails fix the implementation of the failing struct member function.
1111+
1112+ auto & userFactory{UserObjectFactory::getInstance ()};
1113+
1114+ for (auto & item : userFactory.getStructTypes ()) {
1115+ auto name = item.first ;
1116+ auto property = userFactory.createValue (name);
1117+ ASSERT_TRUE (property->type () != PrimitiveType::Ref) << fmt::format (" Struct name {}" , name);
1118+
1119+ change_property (property);
1120+
1121+ // clone uses the copy constructor
1122+ auto prop_clone = property->clone (nullptr );
1123+ ASSERT_TRUE (*property == *prop_clone) << fmt::format (" Struct name {}" , name);
1124+
1125+ // check operator=
1126+ auto property_2 = userFactory.createValue (name);
1127+ ASSERT_FALSE (*property_2 == *property);
1128+
1129+ *property_2 = *property;
1130+ ASSERT_TRUE (*property_2 == *property) << fmt::format (" Struct name {}" , name);
1131+ }
1132+ }
0 commit comments