Skip to content

Commit

Permalink
Add test for #3314
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarrec committed Jun 18, 2020
1 parent c710464 commit e4c4b24
Showing 1 changed file with 85 additions and 1 deletion.
86 changes: 85 additions & 1 deletion src/gbxml/Test/ForwardTranslator_GTest.cpp
Expand Up @@ -45,7 +45,9 @@
#include "../../model/StandardOpaqueMaterial.hpp"
#include "../../model/StandardOpaqueMaterial_Impl.hpp"
#include "../../model/Space.hpp"
#include "../../model/Space_Impl.hpp"
#include "../../model/ThermalZone.hpp"
#include "../../model/ThermalZone_Impl.hpp"

#include "../../model/Model.hpp"

Expand Down Expand Up @@ -181,7 +183,7 @@ TEST_F(gbXMLFixture, ForwardTranslator_ConstructionLayers) {

ASSERT_TRUE(model2);
//std::cout << *model2 << std::endl;
auto osurf = model2->getModelObjectByName<Surface>(surfname);
auto osurf = model2->getModelObjectByName<Surface>(surfname);
ASSERT_TRUE(osurf);
auto ocons = osurf->construction();
ASSERT_TRUE(ocons);
Expand All @@ -193,3 +195,85 @@ TEST_F(gbXMLFixture, ForwardTranslator_ConstructionLayers) {
EXPECT_TRUE(olayeredcons->layers()[2].optionalCast<MasslessOpaqueMaterial>());
EXPECT_TRUE(olayeredcons->layers()[3].optionalCast<StandardOpaqueMaterial>());
}

TEST_F(gbXMLFixture, ForwardTranslator_NoFacility) {
// Test for #3314: gbXML translation does not roundtrip unless Facility object present

Model model;

Construction construction(model);
construction.setName("Construction1");

MaterialVector layers;

MasslessOpaqueMaterial material1(model);
material1.setName("Material1");
layers.push_back(material1);

StandardOpaqueMaterial material2(model);
material2.setName("Material2");
layers.push_back(material2);

MasslessOpaqueMaterial material3(model);
material3.setName("Material3");
layers.push_back(material3);

StandardOpaqueMaterial material4(model);
material4.setName("Material4");
material4.setRoughness("MediumSmooth");
layers.push_back(material4);

construction.setLayers(layers);

// Not instantiating facility nor building on purpose
// Facility facility = model.getUniqueModelObject<Facility>();
// Building building = model.getUniqueModelObject<Building>();

Space space(model);
space.setName("Space1");

Point3dVector points;
points.push_back(Point3d(0, 0, 1));
points.push_back(Point3d(0, 0, 0));
points.push_back(Point3d(1, 0, 0));
points.push_back(Point3d(1, 0, 1));

//std::string surfname("Surface 1"); // DLM: note this will fail because "Surface 1" gets round tripped as "Surface_1"
std::string surfname("Surface1");
Surface surface(points, model);
surface.setName(surfname);
surface.setConstruction(construction);
surface.setSpace(space);

ThermalZone zone(model);
zone.setName("Zone1");
space.setThermalZone(zone);

// save model for diffing
path modelPath = resourcesPath() / openstudio::toPath("gbxml/ForwardTranslator_NoFacility_original.osm");
model.save(modelPath, true);

// Write out the XML
path p = resourcesPath() / openstudio::toPath("gbxml/ForwardTranslator_NoFacility.xml");

ForwardTranslator forwardTranslator;
bool test = forwardTranslator.modelToGbXML(model, p);

EXPECT_TRUE(test);

// Read the XML back in and check surface/space/zone were all translated
ReverseTranslator reverseTranslator;
boost::optional<Model> model2 = reverseTranslator.loadModel(p);

ASSERT_TRUE(model2);
//std::cout << *model2 << std::endl;
auto osurf = model2->getModelObjectByName<Surface>(surfname);
ASSERT_TRUE(osurf);
auto ospace = model2->getModelObjectByName<Space>(space.nameString());
ASSERT_TRUE(ospace);
auto ozone = model2->getModelObjectByName<ThermalZone>(zone.nameString()); // Dragostea Din Tei!
ASSERT_TRUE(ozone);

modelPath = resourcesPath() / openstudio::toPath("gbxml/ForwardTranslator_NoFacility_roundtripped.osm");
model2->save(modelPath, true);
}

0 comments on commit e4c4b24

Please sign in to comment.