diff --git a/hoot-core-test/src/test/cpp/hoot/core/io/OsmXmlWriterTest.cpp b/hoot-core-test/src/test/cpp/hoot/core/io/OsmXmlWriterTest.cpp index 881a623b21..f2bbd41b3f 100644 --- a/hoot-core-test/src/test/cpp/hoot/core/io/OsmXmlWriterTest.cpp +++ b/hoot-core-test/src/test/cpp/hoot/core/io/OsmXmlWriterTest.cpp @@ -39,6 +39,7 @@ class OsmXmlWriterTest : public HootTestFixture { CPPUNIT_TEST_SUITE(OsmXmlWriterTest); CPPUNIT_TEST(runEncodeCharsTest); + CPPUNIT_TEST(runChangesetIdTest); CPPUNIT_TEST_SUITE_END(); public: @@ -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"); diff --git a/hoot-core/src/main/cpp/hoot/core/io/OsmXmlWriter.cpp b/hoot-core/src/main/cpp/hoot/core/io/OsmXmlWriter.cpp index e044340ff5..6a651198a0 100644 --- a/hoot-core/src/main/cpp/hoot/core/io/OsmXmlWriter.cpp +++ b/hoot-core/src/main/cpp/hoot/core/io/OsmXmlWriter.cpp @@ -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())); } diff --git a/test-files/io/OsmXmlWriterTest/runChangesetIdTest.osm b/test-files/io/OsmXmlWriterTest/runChangesetIdTest.osm new file mode 100644 index 0000000000..e097f8adb2 --- /dev/null +++ b/test-files/io/OsmXmlWriterTest/runChangesetIdTest.osm @@ -0,0 +1,12 @@ + + + + + + + + + + + +