diff --git a/src/OsmSharp/IO/PBF/Encoder.cs b/src/OsmSharp/IO/PBF/Encoder.cs index 547a779..ef8015f 100755 --- a/src/OsmSharp/IO/PBF/Encoder.cs +++ b/src/OsmSharp/IO/PBF/Encoder.cs @@ -318,7 +318,7 @@ private static void EncodeDenseNode(PrimitiveBlock block, Dictionary(new PBFOsmStreamSource(stream)); + + AreEqual(sourceObjects, resultObjects); + } } /// @@ -636,5 +682,62 @@ public void TestReadWriteCompressedRead_ShouldSucceed() Assert.AreEqual(1715, new PBFOsmStreamSource(memoryStream).Count(n => n is Node)); } } + + + /// + /// Test helper to test if 2 OsmGeo arrays are equal. + /// + private static void AreEqual(IEnumerable sourceObjects, IEnumerable resultObjects) + { + Assert.IsNotNull(resultObjects); + var sourceArray = sourceObjects.ToArray(); + var resultArray = resultObjects.ToArray(); + Assert.AreEqual(sourceArray.Length, resultArray.Length); + for (int i = 0; i < sourceArray.Length; i++) + { + AreEqual(sourceArray[i], resultArray[i]); + } + } + + /// + /// Test helper to test if 2 OsmGeos are equal. + /// + private static void AreEqual(OsmGeo sourceObject, OsmGeo resultObject) + { + Assert.AreEqual(sourceObject.Id, resultObject.Id); + Assert.AreEqual(sourceObject.ChangeSetId, resultObject.ChangeSetId); + Assert.AreEqual(sourceObject.TimeStamp.Value.Ticks, resultObject.TimeStamp.Value.Ticks, 10000000); + Assert.AreEqual(sourceObject.UserId, resultObject.UserId); + Assert.AreEqual(sourceObject.UserName, resultObject.UserName); + Assert.AreEqual(sourceObject.Version, resultObject.Version); + Assert.AreEqual(sourceObject.Tags?.Count ?? 0, resultObject.Tags?.Count ?? 0); + foreach (var sourceTag in sourceObject.Tags ?? new TagsCollection()) + { + Assert.IsTrue(resultObject.Tags.Contains(sourceTag)); + } + switch (sourceObject) + { + case Node sourceNode: + var resultNode = (Node)resultObject; + Assert.AreEqual(sourceNode.Latitude.Value, resultNode.Latitude.Value, .0001f); + Assert.AreEqual(sourceNode.Longitude.Value, resultNode.Longitude.Value, .0001f); + break; + case Way sourceWay: + var resultWay = (Way)resultObject; + Assert.IsTrue(sourceWay.Nodes.SequenceEqual(resultWay.Nodes)); + break; + case Relation sourceRelation: + var resultRelation = (Relation)resultObject; + Assert.AreEqual(sourceRelation.Members.Length, resultRelation.Members.Length); + for (int i = 0; i < sourceRelation.Members.Length; i++) + { + Assert.AreEqual(sourceRelation.Members[i].Type, resultRelation.Members[i].Type); + Assert.AreEqual(sourceRelation.Members[i].Id, resultRelation.Members[i].Id); + Assert.AreEqual(sourceRelation.Members[i].Role, resultRelation.Members[i].Role); + } + break; + } + } + } } \ No newline at end of file