Skip to content

Commit

Permalink
Don't output the changeset ID when the element ID is negative. (#3321)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmarchant authored Jul 1, 2019
1 parent 99bfad1 commit 1446e80
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
29 changes: 29 additions & 0 deletions hoot-core-test/src/test/cpp/hoot/core/io/OsmXmlWriterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class OsmXmlWriterTest : public HootTestFixture
{
CPPUNIT_TEST_SUITE(OsmXmlWriterTest);
CPPUNIT_TEST(runEncodeCharsTest);
CPPUNIT_TEST(runChangesetIdTest);
CPPUNIT_TEST_SUITE_END();

public:
Expand Down Expand Up @@ -72,6 +73,34 @@ class OsmXmlWriterTest : public HootTestFixture
uut.write(map, output);
HOOT_FILE_EQUALS(_inputPath + "runEncodeCharsTest.osm", output);
}

void runChangesetIdTest()
{
OsmXmlWriter uut;

OsmMapPtr map(new OsmMap());
Tags tags1;
tags1.set("Note", "Node1");
NodePtr node1 = TestUtils::createNode(map, Status::Unknown1, 0.0, 0.0, 15.0, tags1);
node1->setChangeset(10);

Tags tags2;
tags2.set("Note", "Node2");
NodePtr node2 = TestUtils::createNode(map, Status::Unknown1, 0.0, 0.0, 15.0, tags2);
node2->setId(10);
node2->setChangeset(10);

// The values of the IDs and Changeset IDs shouldn't change here
CPPUNIT_ASSERT_EQUAL(-1L, node1->getId());
CPPUNIT_ASSERT_EQUAL(10L, node1->getChangeset());
CPPUNIT_ASSERT_EQUAL(10L, node2->getId());
CPPUNIT_ASSERT_EQUAL(10L, node2->getChangeset());
// But when written out Node1 shouldn't have a changeset ID because it has a negative Node ID

const QString output = _outputPath + "runChangesetIdTest-out.osm";
uut.write(map, output);
HOOT_FILE_EQUALS(_inputPath + "runChangesetIdTest.osm", output);
}
};

CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(OsmXmlWriterTest, "quick");
Expand Down
3 changes: 2 additions & 1 deletion hoot-core/src/main/cpp/hoot/core/io/OsmXmlWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ void OsmXmlWriter::_writeMetadata(const Element *e)
_writer->writeAttribute("version", QString::number(e->getVersion()));
}
}
if (e->getChangeset() != ElementData::CHANGESET_EMPTY)
if (e->getChangeset() != ElementData::CHANGESET_EMPTY &&
e->getId() > 0) // Negative IDs are considered "new" elements and shouldn't have a changeset
{
_writer->writeAttribute("changeset", QString::number(e->getChangeset()));
}
Expand Down
12 changes: 12 additions & 0 deletions test-files/io/OsmXmlWriterTest/runChangesetIdTest.osm
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<osm version="0.6" generator="hootenanny" srs="+epsg:4326">
<bounds minlat="0" minlon="0" maxlat="0" maxlon="0"/>
<node visible="true" id="10" timestamp="1970-01-01T00:00:00Z" version="1" changeset="10" lat="0.0000000000000000" lon="0.0000000000000000">
<tag k="Note" v="Node2"/>
<tag k="error:circular" v="15"/>
</node>
<node visible="true" id="-1" timestamp="1970-01-01T00:00:00Z" version="1" lat="0.0000000000000000" lon="0.0000000000000000">
<tag k="Note" v="Node1"/>
<tag k="error:circular" v="15"/>
</node>
</osm>

0 comments on commit 1446e80

Please sign in to comment.