TEST_F(IdfFixture, WorkspaceObject_FieldSettingWithHiddenPushes) { Workspace scratch(StrictnessLevel::None,IddFileType::EnergyPlus); // Strictness level None std::stringstream text; text << "ZoneHVAC:HighTemperatureRadiant," << std::endl << " MyRadiantSystem," << std::endl << " MyHVACSchedule," << std::endl << " MyCoreZone," << std::endl << " HeatingDesignCapacity," << std::endl << " Autosize," << std::endl << " ," << std::endl << " ," << std::endl << " Electricity;"; OptionalIdfObject oObj = IdfObject::load(text.str()); ASSERT_TRUE(oObj); IdfObject idfObject = *oObj; OptionalWorkspaceObject w1 = scratch.addObject(idfObject); ASSERT_TRUE(w1); OptionalWorkspaceObject tObject = scratch.getObject(w1->handle ()); ASSERT_TRUE(tObject); WorkspaceObject object = *tObject; EXPECT_EQ(static_cast<unsigned>(8),object.numFields()); // create schedule object to point to from non-extensible field text.str(""); text << "Schedule:Compact," << std::endl << " AlwaysOn," << std::endl << " ," << std::endl << " For: AllOtherDays," << std::endl << " Until: 24:00," << std::endl << " 1.0;"; oObj = IdfObject::load(text.str()); ASSERT_TRUE(oObj); idfObject = *oObj; ASSERT_TRUE(idfObject.iddObject().type() == IddObjectType::Schedule_Compact); OptionalWorkspaceObject w2 = scratch.addObject(idfObject); ASSERT_TRUE(w2); EXPECT_TRUE(object.setPointer(14,w2->handle ())); EXPECT_EQ(15u,object.numFields()); tObject = object.getTarget(14); ASSERT_TRUE(tObject); EXPECT_TRUE(tObject->handle() == w2->handle()); // hidden pushing for setting extensible string pointer EXPECT_TRUE(object.setString(16,*(tObject->name()))); // should only work at strictness none tObject = object.getTarget(16); ASSERT_TRUE(tObject); EXPECT_TRUE(tObject->handle() == w2->handle()); EXPECT_EQ(18u,object.numFields()); // hidden pushing for setting extensible double EXPECT_TRUE(object.setDouble(19,0.5)); EXPECT_EQ(20u,object.numFields()); OptionalDouble dValue = object.getDouble(19); ASSERT_TRUE(dValue); EXPECT_NEAR(0.5,*dValue,tol); // SHOULD NOT BE VALID scratch = Workspace(StrictnessLevel::Draft, IddFileType::EnergyPlus); // Non-null data must be valid text.str(""); text << "ZoneHVAC:HighTemperatureRadiant," << std::endl << " MyRadiantSystem," << std::endl << " MyHVACSchedule," << std::endl << " MyCoreZone," << std::endl << " HeatingDesignCapacity," << std::endl << " Autosize," << std::endl << " ," << std::endl << " ," << std::endl << " Electricity;"; oObj = IdfObject::load(text.str()); ASSERT_TRUE(oObj); idfObject = *oObj; w2 = scratch.addObject(idfObject); ASSERT_TRUE(w2); tObject = scratch.getObject(w2->handle()); ASSERT_TRUE(tObject); object = *tObject; // hidden pushing for setting nonextensible double EXPECT_FALSE(object.setDouble(9,1.5)); EXPECT_EQ(8u,object.numFields()); EXPECT_TRUE(object.setDouble(9,0.6)); EXPECT_EQ(10u,object.numFields()); // hidden pushing for setting nonextensible string EXPECT_FALSE(object.setString(12,"bad key")); EXPECT_EQ(10u,object.numFields()); EXPECT_TRUE(object.setString(12,"MeanAirTemperature")); EXPECT_EQ(13u,object.numFields()); // hidden pushing for setting nonextensible pointer EXPECT_TRUE(object.setString(14,"")); EXPECT_EQ(15u,object.numFields()); // hidden pushing for setting extensible string pointer EXPECT_FALSE(object.setString(16,"MySurface")); EXPECT_EQ(15u,object.numFields()); EXPECT_TRUE(object.setString(16,"")); EXPECT_EQ(18u,object.numFields()); // hidden pushing for setting extensible double EXPECT_FALSE(object.setDouble(21,-1.5)); EXPECT_EQ(18u,object.numFields()); EXPECT_TRUE(object.setDouble(19,0.5)); EXPECT_EQ(20u,object.numFields()); }
TEST_F(IdfFixture,WorkspaceObjectWatcher_RelationshipFieldChanges) { IdfObject object(IddObjectType::DaylightingDevice_Tubular); Workspace workspace(StrictnessLevel::Draft, IddFileType::EnergyPlus); OptionalWorkspaceObject owo = workspace.addObject(object); ASSERT_TRUE(owo); WorkspaceObject tdd = *owo; WorkspaceObjectWatcher watcher(tdd); EXPECT_FALSE(watcher.dirty()); // add zone objects object = IdfObject(IddObjectType::Zone); owo = workspace.addObject(object); ASSERT_TRUE(owo); EXPECT_EQ("Zone 1",owo->name().get()); owo = workspace.addObject(object); ASSERT_TRUE(owo); EXPECT_EQ("Zone 2",owo->name().get()); owo = workspace.addObject(object); ASSERT_TRUE(owo); EXPECT_EQ("Zone 3",owo->name().get()); EXPECT_FALSE(watcher.dirty()); vector<string> vals; vals.push_back("Zone 1"); vals.push_back("1.0"); IdfExtensibleGroup eg = tdd.pushExtensibleGroup(vals); ASSERT_FALSE(eg.empty()); EXPECT_TRUE(watcher.dirty()); EXPECT_TRUE(watcher.dataChanged()); EXPECT_FALSE(watcher.nameChanged()); EXPECT_TRUE(watcher.relationshipChanged()); watcher.clearState(); EXPECT_FALSE(watcher.dirty()); EXPECT_FALSE(watcher.dataChanged()); EXPECT_FALSE(watcher.nameChanged()); EXPECT_FALSE(watcher.relationshipChanged()); EXPECT_TRUE(eg.setString(0,"Zone 2")); EXPECT_TRUE(watcher.dirty()); EXPECT_FALSE(watcher.dataChanged()); EXPECT_FALSE(watcher.nameChanged()); EXPECT_TRUE(watcher.relationshipChanged()); watcher.clearState(); EXPECT_FALSE(watcher.dirty()); EXPECT_FALSE(watcher.dataChanged()); EXPECT_FALSE(watcher.nameChanged()); EXPECT_FALSE(watcher.relationshipChanged()); EXPECT_TRUE(eg.setDouble(1,2.0)); EXPECT_TRUE(watcher.dirty()); EXPECT_TRUE(watcher.dataChanged()); EXPECT_FALSE(watcher.nameChanged()); EXPECT_FALSE(watcher.relationshipChanged()); watcher.clearState(); EXPECT_FALSE(watcher.dirty()); EXPECT_FALSE(watcher.dataChanged()); EXPECT_FALSE(watcher.nameChanged()); EXPECT_FALSE(watcher.relationshipChanged()); }