| 68 | */ |
| 69 | |
| 70 | TEST_F(ModelFixture, ResourceObject_Clone) { |
| 71 | Model original; |
| 72 | Construction construction(original); |
| 73 | construction.standardsInformation(); |
| 74 | StandardOpaqueMaterial material(original); |
| 75 | bool ok = construction.setLayers(MaterialVector(1u, material)); |
| 76 | EXPECT_TRUE(ok); |
| 77 | EXPECT_EQ(3u, original.numObjects()) << original; |
| 78 | EXPECT_EQ(1u, construction.numLayers()) << construction; |
| 79 | |
| 80 | // clone into original |
| 81 | auto newConstruction = construction.clone(original).cast<Construction>(); |
| 82 | // self cloned |
| 83 | EXPECT_FALSE(newConstruction == construction); |
| 84 | EXPECT_TRUE(newConstruction.model() == construction.model()); |
| 85 | // child cloned |
| 86 | EXPECT_EQ(2u, original.getConcreteModelObjects<StandardsInformationConstruction>().size()) << original; |
| 87 | EXPECT_FALSE(newConstruction.standardsInformation() == construction.standardsInformation()); |
| 88 | EXPECT_EQ(2u, original.getConcreteModelObjects<StandardsInformationConstruction>().size()) << original; |
| 89 | // resource not cloned |
| 90 | EXPECT_EQ(1u, newConstruction.numLayers()); |
| 91 | EXPECT_TRUE(newConstruction.layers() == construction.layers()); |
| 92 | EXPECT_EQ(5u, original.numObjects()) << original; |
| 93 | |
| 94 | // clone into new model |
| 95 | Model newModel; |
| 96 | newConstruction = construction.clone(newModel).cast<Construction>(); |
| 97 | EXPECT_FALSE(newConstruction.model() == construction.model()); |
| 98 | EXPECT_EQ(3u, newModel.numObjects()) << newModel; |
| 99 | EXPECT_EQ("Material 1", newConstruction.layers()[0].name().get()); |
| 100 | // clone again -- object and child added again, resource reused |
| 101 | auto anotherNewConstruction = construction.clone(newModel).cast<Construction>(); |
| 102 | EXPECT_FALSE(anotherNewConstruction == newConstruction); |
| 103 | EXPECT_EQ(5u, newModel.numObjects()) << newModel; |
| 104 | EXPECT_EQ("Material 1", anotherNewConstruction.layers()[0].name().get()); |
| 105 | // change resource data |
| 106 | newConstruction.layers()[0].setName("Material with Changed Data"); |
| 107 | // clone again -- all added again |
| 108 | anotherNewConstruction = construction.clone(newModel).cast<Construction>(); |
| 109 | EXPECT_EQ(8u, newModel.numObjects()) << newModel; |
| 110 | EXPECT_EQ("Material with Changed Data", newConstruction.layers()[0].name().get()); |
| 111 | EXPECT_EQ("Material 1", anotherNewConstruction.layers()[0].name().get()); |
| 112 | } |
nothing calls this directly
no test coverage detected