Skip to content

Commit

Permalink
Parameterize PostGisTest
Browse files Browse the repository at this point in the history
  • Loading branch information
FObermaier committed Feb 9, 2021
1 parent 847b00e commit 2f9f551
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions test/NetTopologySuite.IO.PostGis.Test/PostGisTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;

using System.Collections;
using System.Collections.Generic;
using System.Net;
using NetTopologySuite.Geometries;
using NetTopologySuite.Geometries.Implementation;
using NUnit.Framework;
Expand Down Expand Up @@ -94,7 +96,7 @@ public class PostGisTest
// new (correct) representation
"GEOMETRYCOLLECTION EMPTY",
// new (correct) representation - does not work on 0.X
// "POINT EMPTY",
"POINT EMPTY",
// new (correct) representation - does not work on 0.X
"LINESTRING EMPTY",
// new (correct) representation - does not work on 0.X
Expand All @@ -111,19 +113,29 @@ public class PostGisTest
// The srid we use for the srid tests
public static int SRID = 4326;

private static readonly PostGisReader br = new PostGisReader(new PackedCoordinateSequenceFactory(), new PrecisionModel());
//private PostGisReader br = new PostGisReader(PackedCoordinateSequenceFactory.DoubleFactory, new PrecisionModel());
private static readonly PrecisionModel pm = new PrecisionModel();
private static readonly WKTReader wr = new WKTReader();

static IEnumerable<CoordinateSequenceFactory> TestFactories( )
{
yield return CoordinateArraySequenceFactory.Instance;
yield return PackedCoordinateSequenceFactory.DoubleFactory;
yield return PackedCoordinateSequenceFactory.FloatFactory;
yield return DotSpatialAffineCoordinateSequenceFactory.Instance;
}

/// <summary>
///
/// </summary>
[Test]
public void General()
[TestCaseSource(nameof(TestFactories))]
public void General(CoordinateSequenceFactory factory)
{
var geomFactory = new GeometryFactory(pm, 0, factory);
for (int i = 0; i < testset.Length; i++)
{
General(testset[i], -1);
General(testset[i], SRID);
General(geomFactory, testset[i], -1);
General(geomFactory, testset[i], SRID);
}
}

Expand All @@ -132,9 +144,10 @@ public void General()
/// </summary>
/// <param name="wkt"></param>
/// <param name="srid"></param>
private static void General(string wkt, int srid)
private static void General(GeometryFactory geomFactory, string wkt, int srid)
{
var geom = wr.Read(wkt);
var wktReader = new WKTReader(geomFactory);
var geom = wktReader.Read(wkt);
string parsed = geom.AsText();
var regeom = wr.Read(parsed);
string reparsed = regeom.AsText();
Expand All @@ -145,16 +158,16 @@ private static void General(string wkt, int srid)
Assert.IsTrue(geom.EqualsExact(regeom));
Assert.AreEqual(parsed, reparsed);

var pgr = new PostGisReader(geomFactory);
byte[] bytesB = new PostGisWriter(ByteOrder.BigEndian).Write(regeom);
var regeom2 = br.Read(bytesB);
var regeom2 = pgr.Read(bytesB);
Assert.IsTrue(geom.EqualsExact(regeom2));

byte[] bytesL = new PostGisWriter(ByteOrder.LittleEndian).Write(regeom);
var regeom3 = br.Read(bytesL);
var regeom3 = pgr.Read(bytesL);
Assert.IsTrue(geom.EqualsExact(regeom3));
Assert.IsTrue(regeom2.EqualsExact(regeom3));


Assert.AreEqual(bytesB.Length, bytesL.Length);
}

Expand Down

0 comments on commit 2f9f551

Please sign in to comment.