From 7f077a5b706285427324eb5139ba9ce4db7a80db Mon Sep 17 00:00:00 2001 From: Alex Hennings Date: Thu, 29 Aug 2019 15:49:06 -0400 Subject: [PATCH 1/2] [if-unused-imposter]: --- src/OsmSharp/Changesets/OsmChange.cs | 9 +- src/OsmSharp/Changesets/OsmChangeDelete.cs | 69 +++++++++++++ .../IO/Xml/Changesets/OsmChange.Xml.cs | 53 ++++------ .../IO/Xml/Changesets/OsmChangeDelete.Xml.cs | 97 +++++++++++++++++++ .../IO/Xml/Changesets/OsmChangeTests.cs | 5 +- 5 files changed, 194 insertions(+), 39 deletions(-) create mode 100644 src/OsmSharp/Changesets/OsmChangeDelete.cs create mode 100644 src/OsmSharp/IO/Xml/Changesets/OsmChangeDelete.Xml.cs diff --git a/src/OsmSharp/Changesets/OsmChange.cs b/src/OsmSharp/Changesets/OsmChange.cs index b676688..c76fbb2 100755 --- a/src/OsmSharp/Changesets/OsmChange.cs +++ b/src/OsmSharp/Changesets/OsmChange.cs @@ -62,9 +62,10 @@ public partial class OsmChange /// public OsmGeo[] Modify { get; set; } - /// - /// Gets or sets the delete change array. - /// - public OsmGeo[] Delete { get; set; } + + /// + /// Gets or sets the delete change array. + /// + public OsmChangeDelete Delete { get; set; } } } \ No newline at end of file diff --git a/src/OsmSharp/Changesets/OsmChangeDelete.cs b/src/OsmSharp/Changesets/OsmChangeDelete.cs new file mode 100644 index 0000000..b495c18 --- /dev/null +++ b/src/OsmSharp/Changesets/OsmChangeDelete.cs @@ -0,0 +1,69 @@ +// The MIT License (MIT) + +// Copyright (c) 2016 Ben Abelshausen + +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: + +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. + +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System.Collections; +using System.Collections.Generic; + +namespace OsmSharp.Changesets +{ + /// + /// The delete section of a changeset, pretending to be an OsmGeo[]. + /// + public partial class OsmChangeDelete : IEnumerable + { + private OsmGeo[] Delete { get; set; } + + public int Length => Delete.Length; + + public OsmGeo this[int i] + { + get { return Delete[i]; } + set { Delete[i] = value; } + } + + public bool IfUnused { get; set; } + + public IEnumerator GetEnumerator() + { + return ((IEnumerable)Delete).GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return ((IEnumerable)Delete).GetEnumerator(); + } + + public static implicit operator OsmGeo[](OsmChangeDelete delete) + { + return delete.Delete; + } + + public static implicit operator OsmChangeDelete(OsmGeo[] delete) + { + return new OsmChangeDelete() + { + Delete = delete, + IfUnused = false + }; + } + } +} diff --git a/src/OsmSharp/IO/Xml/Changesets/OsmChange.Xml.cs b/src/OsmSharp/IO/Xml/Changesets/OsmChange.Xml.cs index bd43c54..b1ea72d 100755 --- a/src/OsmSharp/IO/Xml/Changesets/OsmChange.Xml.cs +++ b/src/OsmSharp/IO/Xml/Changesets/OsmChange.Xml.cs @@ -26,6 +26,7 @@ using System.Xml; using System.Xml.Schema; using System.Xml.Serialization; +using System.Linq; namespace OsmSharp.Changesets { @@ -50,11 +51,10 @@ void IXmlSerializable.ReadXml(XmlReader reader) this.Attribution = reader.GetAttribute("attribution"); this.License = reader.GetAttribute("license"); - List creates = new List(); ; - List modifies = new List(); ; - List deletes = new List(); ; + List creates = new List(); + List modifies = new List(); - reader.GetElements( + reader.GetElements( new Tuple( "create", () => { @@ -104,30 +104,13 @@ void IXmlSerializable.ReadXml(XmlReader reader) new Tuple( "delete", () => { - if (reader.IsEmptyElement) - { - reader.Read(); - return; - } - reader.Read(); - while ((reader.Name == "node" || - reader.Name == "way" || - reader.Name == "relation")) - { - deletes.Add(OsmChange.ReadOsmGeo(reader)); - if (reader.NodeType == XmlNodeType.EndElement && (reader.Name == "node" || - reader.Name == "way" || - reader.Name == "relation")) - { - reader.Read(); - } - } - reader.Read(); + this.Delete = new OsmChangeDelete(); + (this.Delete as IXmlSerializable).ReadXml(reader); + // reader.Read()? })); this.Create = creates.ToArray(); this.Modify = modifies.ToArray(); - this.Delete = deletes.ToArray(); } private static OsmGeo ReadOsmGeo(XmlReader reader) @@ -157,34 +140,36 @@ void IXmlSerializable.WriteXml(XmlWriter writer) writer.WriteAttribute("attribution", this.Attribution); writer.WriteAttribute("license", this.License); - if (this.Create != null) + if (this.Create != null) { writer.WriteStartElement("create"); - for (var i = 0; i < this.Create.Length; i++) + // Add in order: nodes, ways, relations + foreach (var OsmGeo in this.Create.OrderBy(g => g.Type)) { - OsmChange.WriteOsmGeo(writer, this.Create[i]); + OsmChange.WriteOsmGeo(writer, OsmGeo); } writer.WriteEndElement(); } if (this.Modify != null) { writer.WriteStartElement("modify"); - for (var i = 0; i < this.Modify.Length; i++) - { - OsmChange.WriteOsmGeo(writer, this.Modify[i]); + foreach (var OsmGeo in this.Modify) + { + OsmChange.WriteOsmGeo(writer, OsmGeo); } writer.WriteEndElement(); } if (this.Delete != null) { writer.WriteStartElement("delete"); - for (var i = 0; i < this.Delete.Length; i++) - { - OsmChange.WriteOsmGeo(writer, this.Delete[i]); + // Delete in order: relations, ways, nodes + foreach (var OsmGeo in this.Delete.OrderByDescending(g => g.Type)) + { + OsmChange.WriteOsmGeo(writer, OsmGeo); } writer.WriteEndElement(); } - } + } private static void WriteOsmGeo(XmlWriter writer, OsmGeo osmGeo) { diff --git a/src/OsmSharp/IO/Xml/Changesets/OsmChangeDelete.Xml.cs b/src/OsmSharp/IO/Xml/Changesets/OsmChangeDelete.Xml.cs new file mode 100644 index 0000000..ea3b071 --- /dev/null +++ b/src/OsmSharp/IO/Xml/Changesets/OsmChangeDelete.Xml.cs @@ -0,0 +1,97 @@ +// The MIT License (MIT) + +// Copyright (c) 2016 Ben Abelshausen + +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: + +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. + +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using System.Collections.Generic; +using System.Xml; +using System.Xml.Schema; +using System.Xml.Serialization; +using System.Linq; +using OsmSharp.IO.Xml; + +namespace OsmSharp.Changesets +{ + /// + /// Represents a changeset delete. + /// + [XmlRoot("delete")] + public partial class OsmChangeDelete : IXmlSerializable + { + XmlSchema IXmlSerializable.GetSchema() + { + return null; + } + + void IXmlSerializable.ReadXml(XmlReader reader) + { + this.IfUnused = reader.GetAttribute("if-unused") != null; + + List deletes = new List(); + + reader.GetElements( + new Tuple( + "node", () => + { + var osmGeo = new Node(); + (osmGeo as IXmlSerializable).ReadXml(reader); + deletes.Add(osmGeo); + }), + new Tuple( + "way", () => + { + var osmGeo = new Way(); + (osmGeo as IXmlSerializable).ReadXml(reader); + deletes.Add(osmGeo); + }), + new Tuple( + "relation", () => + { + var osmGeo = new Relation(); + (osmGeo as IXmlSerializable).ReadXml(reader); + deletes.Add(osmGeo); + })); + + if (deletes.Any()) + { + this.Delete = deletes.ToArray(); + } + } + + void IXmlSerializable.WriteXml(XmlWriter writer) + { + // When the 'if-unused' attribute exists, it is interpreted as 'true' + // so don't put 'false' as a value + if (this.IfUnused) + { + writer.WriteAttribute("if-unused", this.IfUnused); + } + + if (this.Delete != null) + { + foreach (var element in this.Delete) + { + writer.WriteElement(element.Type.ToString().ToLower(), (IXmlSerializable)element); + } + } + } + } +} \ No newline at end of file diff --git a/test/OsmSharp.Test/IO/Xml/Changesets/OsmChangeTests.cs b/test/OsmSharp.Test/IO/Xml/Changesets/OsmChangeTests.cs index 7df742b..360f8c3 100755 --- a/test/OsmSharp.Test/IO/Xml/Changesets/OsmChangeTests.cs +++ b/test/OsmSharp.Test/IO/Xml/Changesets/OsmChangeTests.cs @@ -109,6 +109,7 @@ public void TestDeserialize_Empty() Assert.IsNotNull(osmChange); Assert.AreEqual(0, osmChange.Create.Length); Assert.AreEqual(0, osmChange.Delete.Length); + Assert.IsNull(osmChange.Delete.IfUnused); Assert.AreEqual(0, osmChange.Modify.Length); Assert.AreEqual(0.6, osmChange.Version); Assert.IsNull(osmChange.Generator); @@ -126,6 +127,7 @@ public void TestDeserialize_WithAttributes() Assert.IsNotNull(osmChange); Assert.AreEqual(0, osmChange.Create.Length); Assert.AreEqual(0, osmChange.Delete.Length); + Assert.IsNull(osmChange.Delete.IfUnused); Assert.AreEqual(0, osmChange.Modify.Length); Assert.AreEqual(0.6, osmChange.Version); Assert.AreEqual("OsmSharp", osmChange.Generator); @@ -184,12 +186,13 @@ public void TestDeserialize_IfUnused() new StringReader("")) as OsmChange; Assert.IsNotNull(osmChange); - Assert.AreEqual(0 ,osmChange.Create.Length); + Assert.AreEqual(0, osmChange.Create.Length); Assert.IsNotNull(osmChange.Modify); Assert.AreEqual(1, osmChange.Modify.Length); Assert.AreEqual(1014872736, osmChange.Modify[0].Id); Assert.AreEqual(OsmGeoType.Node, osmChange.Modify[0].Type); Assert.AreEqual(0, osmChange.Delete.Length); + Assert.IsTrue(osmChange.Delete.IfUnused); Assert.AreEqual(0.6, osmChange.Version); Assert.AreEqual("iD", osmChange.Generator); } From 71c71fe105b1eabcb69d9f0dfd75747664c922ed Mon Sep 17 00:00:00 2001 From: Alex Hennings Date: Thu, 29 Aug 2019 16:16:30 -0400 Subject: [PATCH 2/2] [if-unused-imposter]: --- src/OsmSharp/Changesets/OsmChange.cs | 12 ++- src/OsmSharp/Changesets/OsmChangeDelete.cs | 69 ------------- .../IO/Xml/Changesets/OsmChange.Xml.cs | 76 ++++++++++----- .../IO/Xml/Changesets/OsmChangeDelete.Xml.cs | 97 ------------------- .../IO/Xml/Changesets/OsmChangeTests.cs | 31 ++++-- 5 files changed, 87 insertions(+), 198 deletions(-) delete mode 100644 src/OsmSharp/Changesets/OsmChangeDelete.cs delete mode 100644 src/OsmSharp/IO/Xml/Changesets/OsmChangeDelete.Xml.cs diff --git a/src/OsmSharp/Changesets/OsmChange.cs b/src/OsmSharp/Changesets/OsmChange.cs index c76fbb2..09b8b70 100755 --- a/src/OsmSharp/Changesets/OsmChange.cs +++ b/src/OsmSharp/Changesets/OsmChange.cs @@ -62,10 +62,14 @@ public partial class OsmChange /// public OsmGeo[] Modify { get; set; } + /// + /// Gets or sets the delete change array. + /// + public OsmGeo[] Delete { get; set; } - /// - /// Gets or sets the delete change array. - /// - public OsmChangeDelete Delete { get; set; } + /// + /// Gets or sets the deleteIfUnused change array. + /// + public OsmGeo[] DeleteIfUnused { get; set; } } } \ No newline at end of file diff --git a/src/OsmSharp/Changesets/OsmChangeDelete.cs b/src/OsmSharp/Changesets/OsmChangeDelete.cs deleted file mode 100644 index b495c18..0000000 --- a/src/OsmSharp/Changesets/OsmChangeDelete.cs +++ /dev/null @@ -1,69 +0,0 @@ -// The MIT License (MIT) - -// Copyright (c) 2016 Ben Abelshausen - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: - -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. - -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -using System.Collections; -using System.Collections.Generic; - -namespace OsmSharp.Changesets -{ - /// - /// The delete section of a changeset, pretending to be an OsmGeo[]. - /// - public partial class OsmChangeDelete : IEnumerable - { - private OsmGeo[] Delete { get; set; } - - public int Length => Delete.Length; - - public OsmGeo this[int i] - { - get { return Delete[i]; } - set { Delete[i] = value; } - } - - public bool IfUnused { get; set; } - - public IEnumerator GetEnumerator() - { - return ((IEnumerable)Delete).GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return ((IEnumerable)Delete).GetEnumerator(); - } - - public static implicit operator OsmGeo[](OsmChangeDelete delete) - { - return delete.Delete; - } - - public static implicit operator OsmChangeDelete(OsmGeo[] delete) - { - return new OsmChangeDelete() - { - Delete = delete, - IfUnused = false - }; - } - } -} diff --git a/src/OsmSharp/IO/Xml/Changesets/OsmChange.Xml.cs b/src/OsmSharp/IO/Xml/Changesets/OsmChange.Xml.cs index b1ea72d..a862e55 100755 --- a/src/OsmSharp/IO/Xml/Changesets/OsmChange.Xml.cs +++ b/src/OsmSharp/IO/Xml/Changesets/OsmChange.Xml.cs @@ -53,16 +53,18 @@ void IXmlSerializable.ReadXml(XmlReader reader) List creates = new List(); List modifies = new List(); + List deletes = new List(); + List deletesIfUnused = new List(); - reader.GetElements( + reader.GetElements( new Tuple( "create", () => { - if (reader.IsEmptyElement) - { - reader.Read(); - return; - } + if (reader.IsEmptyElement) + { + reader.Read(); + return; + } reader.Read(); while ((reader.Name == "node" || reader.Name == "way" || @@ -81,11 +83,11 @@ void IXmlSerializable.ReadXml(XmlReader reader) new Tuple( "modify", () => { - if (reader.IsEmptyElement) - { - reader.Read(); - return; - } + if (reader.IsEmptyElement) + { + reader.Read(); + return; + } reader.Read(); while ((reader.Name == "node" || reader.Name == "way" || @@ -104,13 +106,32 @@ void IXmlSerializable.ReadXml(XmlReader reader) new Tuple( "delete", () => { - this.Delete = new OsmChangeDelete(); - (this.Delete as IXmlSerializable).ReadXml(reader); - // reader.Read()? + if (reader.IsEmptyElement) + { + reader.Read(); + return; + } + var ifUnused = reader.GetAttribute("if-unused") != null; + reader.Read(); + while ((reader.Name == "node" || + reader.Name == "way" || + reader.Name == "relation")) + { + (ifUnused ? deletesIfUnused : deletes).Add(OsmChange.ReadOsmGeo(reader)); + if (reader.NodeType == XmlNodeType.EndElement && (reader.Name == "node" || + reader.Name == "way" || + reader.Name == "relation")) + { + reader.Read(); + } + } + reader.Read(); })); this.Create = creates.ToArray(); this.Modify = modifies.ToArray(); + this.Delete = deletes.ToArray(); + this.DeleteIfUnused = deletesIfUnused.ToArray(); } private static OsmGeo ReadOsmGeo(XmlReader reader) @@ -140,10 +161,10 @@ void IXmlSerializable.WriteXml(XmlWriter writer) writer.WriteAttribute("attribution", this.Attribution); writer.WriteAttribute("license", this.License); - if (this.Create != null) + if (this.Create != null) { writer.WriteStartElement("create"); - // Add in order: nodes, ways, relations + // Add in order: nodes, ways, relations foreach (var OsmGeo in this.Create.OrderBy(g => g.Type)) { OsmChange.WriteOsmGeo(writer, OsmGeo); @@ -153,8 +174,8 @@ void IXmlSerializable.WriteXml(XmlWriter writer) if (this.Modify != null) { writer.WriteStartElement("modify"); - foreach (var OsmGeo in this.Modify) - { + foreach (var OsmGeo in this.Modify) + { OsmChange.WriteOsmGeo(writer, OsmGeo); } writer.WriteEndElement(); @@ -162,14 +183,25 @@ void IXmlSerializable.WriteXml(XmlWriter writer) if (this.Delete != null) { writer.WriteStartElement("delete"); - // Delete in order: relations, ways, nodes - foreach (var OsmGeo in this.Delete.OrderByDescending(g => g.Type)) - { + // Delete elements in this order: relations, ways, nodes + foreach (var OsmGeo in this.Delete.OrderByDescending(g => g.Type)) + { + OsmChange.WriteOsmGeo(writer, OsmGeo); + } + writer.WriteEndElement(); + } + if (this.DeleteIfUnused != null) + { + writer.WriteStartElement("delete"); + writer.WriteAttribute("if-unused", "true"); + // Delete elements in this order: relations, ways, nodes + foreach (var OsmGeo in this.DeleteIfUnused.OrderByDescending(g => g.Type)) + { OsmChange.WriteOsmGeo(writer, OsmGeo); } writer.WriteEndElement(); } - } + } private static void WriteOsmGeo(XmlWriter writer, OsmGeo osmGeo) { diff --git a/src/OsmSharp/IO/Xml/Changesets/OsmChangeDelete.Xml.cs b/src/OsmSharp/IO/Xml/Changesets/OsmChangeDelete.Xml.cs deleted file mode 100644 index ea3b071..0000000 --- a/src/OsmSharp/IO/Xml/Changesets/OsmChangeDelete.Xml.cs +++ /dev/null @@ -1,97 +0,0 @@ -// The MIT License (MIT) - -// Copyright (c) 2016 Ben Abelshausen - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: - -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. - -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -using System; -using System.Collections.Generic; -using System.Xml; -using System.Xml.Schema; -using System.Xml.Serialization; -using System.Linq; -using OsmSharp.IO.Xml; - -namespace OsmSharp.Changesets -{ - /// - /// Represents a changeset delete. - /// - [XmlRoot("delete")] - public partial class OsmChangeDelete : IXmlSerializable - { - XmlSchema IXmlSerializable.GetSchema() - { - return null; - } - - void IXmlSerializable.ReadXml(XmlReader reader) - { - this.IfUnused = reader.GetAttribute("if-unused") != null; - - List deletes = new List(); - - reader.GetElements( - new Tuple( - "node", () => - { - var osmGeo = new Node(); - (osmGeo as IXmlSerializable).ReadXml(reader); - deletes.Add(osmGeo); - }), - new Tuple( - "way", () => - { - var osmGeo = new Way(); - (osmGeo as IXmlSerializable).ReadXml(reader); - deletes.Add(osmGeo); - }), - new Tuple( - "relation", () => - { - var osmGeo = new Relation(); - (osmGeo as IXmlSerializable).ReadXml(reader); - deletes.Add(osmGeo); - })); - - if (deletes.Any()) - { - this.Delete = deletes.ToArray(); - } - } - - void IXmlSerializable.WriteXml(XmlWriter writer) - { - // When the 'if-unused' attribute exists, it is interpreted as 'true' - // so don't put 'false' as a value - if (this.IfUnused) - { - writer.WriteAttribute("if-unused", this.IfUnused); - } - - if (this.Delete != null) - { - foreach (var element in this.Delete) - { - writer.WriteElement(element.Type.ToString().ToLower(), (IXmlSerializable)element); - } - } - } - } -} \ No newline at end of file diff --git a/test/OsmSharp.Test/IO/Xml/Changesets/OsmChangeTests.cs b/test/OsmSharp.Test/IO/Xml/Changesets/OsmChangeTests.cs index 360f8c3..6e6b0de 100755 --- a/test/OsmSharp.Test/IO/Xml/Changesets/OsmChangeTests.cs +++ b/test/OsmSharp.Test/IO/Xml/Changesets/OsmChangeTests.cs @@ -88,11 +88,26 @@ public void TestSerialize() { Id = 300 } + }, + DeleteIfUnused = new OsmGeo[] + { + new Node() + { + Id = 31 + }, + new Way() + { + Id = 301 + }, + new Relation() + { + Id = 3001 + } } }; var result = osmChange.SerializeToXml(); - Assert.AreEqual("", + Assert.AreEqual("", result); } @@ -109,7 +124,7 @@ public void TestDeserialize_Empty() Assert.IsNotNull(osmChange); Assert.AreEqual(0, osmChange.Create.Length); Assert.AreEqual(0, osmChange.Delete.Length); - Assert.IsNull(osmChange.Delete.IfUnused); + Assert.AreEqual(0, osmChange.DeleteIfUnused.Length); Assert.AreEqual(0, osmChange.Modify.Length); Assert.AreEqual(0.6, osmChange.Version); Assert.IsNull(osmChange.Generator); @@ -127,7 +142,7 @@ public void TestDeserialize_WithAttributes() Assert.IsNotNull(osmChange); Assert.AreEqual(0, osmChange.Create.Length); Assert.AreEqual(0, osmChange.Delete.Length); - Assert.IsNull(osmChange.Delete.IfUnused); + Assert.AreEqual(0, osmChange.DeleteIfUnused.Length); Assert.AreEqual(0, osmChange.Modify.Length); Assert.AreEqual(0.6, osmChange.Version); Assert.AreEqual("OsmSharp", osmChange.Generator); @@ -172,7 +187,10 @@ public void TestDeserialize_Full() Assert.AreEqual(300, osmChange.Delete[2].Id); Assert.AreEqual(OsmGeoType.Relation, osmChange.Delete[2].Type); - Assert.AreEqual(0.6, osmChange.Version); + Assert.IsNotNull(osmChange.DeleteIfUnused); + Assert.AreEqual(0, osmChange.DeleteIfUnused.Length); + + Assert.AreEqual(0.6, osmChange.Version); Assert.AreEqual("OsmSharp", osmChange.Generator); } @@ -183,7 +201,7 @@ public void TestDeserialize_IfUnused() var serializer = new XmlSerializer(typeof(OsmChange)); var osmChange = serializer.Deserialize( - new StringReader("")) as OsmChange; + new StringReader("")) as OsmChange; Assert.IsNotNull(osmChange); Assert.AreEqual(0, osmChange.Create.Length); @@ -192,7 +210,8 @@ public void TestDeserialize_IfUnused() Assert.AreEqual(1014872736, osmChange.Modify[0].Id); Assert.AreEqual(OsmGeoType.Node, osmChange.Modify[0].Type); Assert.AreEqual(0, osmChange.Delete.Length); - Assert.IsTrue(osmChange.Delete.IfUnused); + Assert.AreEqual(1, osmChange.DeleteIfUnused.Length); + Assert.AreEqual(3, osmChange.DeleteIfUnused[0].Id); Assert.AreEqual(0.6, osmChange.Version); Assert.AreEqual("iD", osmChange.Generator); }