20240422
This commit is contained in:
commit
e0afef912e
1285 files changed
+83219
No files matched your search
@@ -0,0 +1,132 @@
|
||||
namespace Mapbox.MapboxSdkCs.UnitTest
|
||||
{
|
||||
|
||||
|
||||
using NUnit.Framework;
|
||||
using Mapbox.Unity.Location;
|
||||
|
||||
|
||||
[TestFixture]
|
||||
internal class AngleSmoothingTest
|
||||
{
|
||||
|
||||
|
||||
[Test]
|
||||
public void NoOp()
|
||||
{
|
||||
//NoOp does nothing. should always return latest value
|
||||
AngleSmoothingNoOp noop = new AngleSmoothingNoOp();
|
||||
string opName = noop.GetType().Name + " ";
|
||||
noop.Add(23);
|
||||
Assert.AreEqual(23d, noop.Calculate(), opName + "did modify data");
|
||||
noop.Add(29);
|
||||
Assert.AreEqual(29d, noop.Calculate(), opName + "did modify data");
|
||||
noop.Add(178.5);
|
||||
Assert.AreEqual(178.5d, noop.Calculate(), opName + "did modify data");
|
||||
noop.Add(359.99);
|
||||
Assert.AreEqual(359.99d, noop.Calculate(), opName + "did modify data");
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void Average()
|
||||
{
|
||||
// simple average
|
||||
AngleSmoothingAverage avg = new AngleSmoothingAverage();
|
||||
string opName = avg.GetType().Name + " ";
|
||||
avg.Add(355);
|
||||
avg.Add(15);
|
||||
Assert.AreEqual(5d, avg.Calculate(), opName + "did not properly calculate across 0");
|
||||
|
||||
avg.Add(335);
|
||||
Assert.AreEqual(355d, avg.Calculate(), opName + "did not properly calculate back across 0");
|
||||
|
||||
// add more angles to check if internal buffer rolls over correctly
|
||||
avg.Add(180);
|
||||
avg.Add(160);
|
||||
avg.Add(140);
|
||||
avg.Add(120);
|
||||
avg.Add(100);
|
||||
Assert.AreEqual(140d, avg.Calculate(), opName + "internal default buffer of 5 did not roll over correctly");
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void LowPass()
|
||||
{
|
||||
//simple low pass filter
|
||||
// parameter 1.0 => no smoothing: despite calucations going on last value should be returned
|
||||
AngleSmoothingLowPass lp = new AngleSmoothingLowPass(1.0d);
|
||||
string opName = lp.GetType().Name + " ";
|
||||
lp.Add(45);
|
||||
lp.Add(90);
|
||||
lp.Add(135);
|
||||
lp.Add(180);
|
||||
lp.Add(225);
|
||||
Assert.AreEqual(225d, lp.Calculate(), opName + "smoothed but shouldn't have");
|
||||
|
||||
lp = new AngleSmoothingLowPass(0.5d);
|
||||
lp.Add(45);
|
||||
lp.Add(90);
|
||||
lp.Add(135);
|
||||
lp.Add(180);
|
||||
lp.Add(225);
|
||||
Assert.AreEqual(193.75d, lp.Calculate(), opName + "did not smooth as expected");
|
||||
|
||||
// parameter 1.0 => no smoothing: despite calucations going on last value should be returned
|
||||
lp = new AngleSmoothingLowPass(1d);
|
||||
lp.Add(355);
|
||||
lp.Add(355);
|
||||
lp.Add(5);
|
||||
lp.Add(5);
|
||||
lp.Add(5);
|
||||
Assert.AreEqual(5d, lp.Calculate(), opName + "did not *not* smooth across '0' as expected");
|
||||
|
||||
lp = new AngleSmoothingLowPass(0.5d);
|
||||
lp.Add(355);
|
||||
lp.Add(355);
|
||||
lp.Add(10);
|
||||
lp.Add(10);
|
||||
lp.Add(10);
|
||||
Assert.AreEqual(8.14d, lp.Calculate(), opName + "did not smooth across '0' as expected");
|
||||
lp.Add(320);
|
||||
Assert.AreEqual(344.02d, lp.Calculate(), opName + "did not smooth back across '0' as expected");
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void Weighted()
|
||||
{
|
||||
// exponential moving average
|
||||
// parameter 1.0 => no smoothing
|
||||
AngleSmoothingEMA ema = new AngleSmoothingEMA();
|
||||
string opName = ema.GetType().Name + " ";
|
||||
ema.Add(45);
|
||||
ema.Add(90);
|
||||
ema.Add(135);
|
||||
ema.Add(180);
|
||||
ema.Add(225);
|
||||
Assert.AreEqual(165.74d, ema.Calculate(), opName + "didn't smooth as expected");
|
||||
|
||||
ema = new AngleSmoothingEMA();
|
||||
ema.Add(350);
|
||||
ema.Add(355);
|
||||
ema.Add(5);
|
||||
ema.Add(10);
|
||||
ema.Add(10);
|
||||
Assert.AreEqual(3.85d, ema.Calculate(), opName + "didn't smooth as expected across 0");
|
||||
|
||||
ema = new AngleSmoothingEMA();
|
||||
ema.Add(20);
|
||||
ema.Add(15);
|
||||
ema.Add(350);
|
||||
ema.Add(345);
|
||||
ema.Add(330);
|
||||
Assert.AreEqual(350.43d, ema.Calculate(), opName + "didn't smooth as expected back across 0");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4c71959e4a4a64446a39de632554cf41
|
||||
timeCreated: 1529510706
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="BboxToVector2dBoundsConverterTest.cs" company="Mapbox">
|
||||
// Copyright (c) 2016 Mapbox. All rights reserved.
|
||||
// </copyright>
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
namespace Mapbox.MapboxSdkCs.UnitTest
|
||||
{
|
||||
using Mapbox.Json;
|
||||
using Mapbox.Utils;
|
||||
using Mapbox.Utils.JsonConverters;
|
||||
using NUnit.Framework;
|
||||
|
||||
[TestFixture]
|
||||
internal class BboxToVector2dBoundsConverterTest
|
||||
{
|
||||
private string geoCoordinateBoundsStr = "[38.9165,-77.0295,30.2211,-80.5521]";
|
||||
|
||||
private Vector2dBounds geoCoordinateBoundsObj = new Vector2dBounds(
|
||||
sw: new Vector2d(y: -77.0295, x: 38.9165),
|
||||
ne: new Vector2d(y: -80.5521, x: 30.2211));
|
||||
|
||||
[Test]
|
||||
public void Deserialize()
|
||||
{
|
||||
Vector2dBounds deserializedVector2dBounds = JsonConvert.DeserializeObject<Vector2dBounds>(geoCoordinateBoundsStr, JsonConverters.Converters);
|
||||
Assert.AreEqual(geoCoordinateBoundsObj.ToString(), deserializedVector2dBounds.ToString());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Serialize()
|
||||
{
|
||||
string serializedVector2dBounds = JsonConvert.SerializeObject(geoCoordinateBoundsObj, JsonConverters.Converters);
|
||||
Assert.AreEqual(geoCoordinateBoundsStr, serializedVector2dBounds);
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 58a06458684f24a7d8758d87456c38ee
|
||||
timeCreated: 1498231546
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,63 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="BearingFilterTest.cs" company="Mapbox">
|
||||
// Copyright (c) 2016 Mapbox. All rights reserved.
|
||||
// </copyright>
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
namespace Mapbox.MapboxSdkCs.UnitTest
|
||||
{
|
||||
using System;
|
||||
using Mapbox;
|
||||
using NUnit.Framework;
|
||||
using Mapbox.Utils;
|
||||
|
||||
[TestFixture]
|
||||
internal class BearingFilterTest
|
||||
{
|
||||
private BearingFilter _bearingFilter;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_bearingFilter = new BearingFilter(10, 10);
|
||||
}
|
||||
|
||||
public void BearingTooLarge()
|
||||
{
|
||||
_bearingFilter = new BearingFilter(361, 10);
|
||||
}
|
||||
|
||||
public void BearingTooSmall()
|
||||
{
|
||||
_bearingFilter = new BearingFilter(-1, 10);
|
||||
}
|
||||
|
||||
public void RangeTooLarge()
|
||||
{
|
||||
_bearingFilter = new BearingFilter(10, 181);
|
||||
}
|
||||
|
||||
public void RangeTooSmall()
|
||||
{
|
||||
_bearingFilter = new BearingFilter(10, -1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InvalidValues()
|
||||
{
|
||||
Assert.Throws<Exception>(BearingTooLarge);
|
||||
Assert.Throws<Exception>(BearingTooSmall);
|
||||
Assert.Throws<Exception>(RangeTooSmall);
|
||||
Assert.Throws<Exception>(RangeTooLarge);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ToStringTest()
|
||||
{
|
||||
Assert.AreEqual(_bearingFilter.ToString(), "10,10");
|
||||
|
||||
_bearingFilter = new BearingFilter(null, null);
|
||||
Assert.AreEqual(_bearingFilter.ToString(), string.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 92c453cc66e7c404aa6b98cd2488dd54
|
||||
timeCreated: 1498231546
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,31 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="CanonicalTileIdTest.cs" company="Mapbox">
|
||||
// Copyright (c) 2016 Mapbox. All rights reserved.
|
||||
// </copyright>
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
namespace Mapbox.MapboxSdkCs.UnitTest
|
||||
{
|
||||
using Mapbox.Map;
|
||||
using Mapbox.Utils;
|
||||
using NUnit.Framework;
|
||||
|
||||
[TestFixture]
|
||||
internal class CanonicalTileIdTest
|
||||
{
|
||||
[Test]
|
||||
public void ToVector2d()
|
||||
{
|
||||
var set = TileCover.Get(Vector2dBounds.World(), 5);
|
||||
|
||||
foreach (var tile in set)
|
||||
{
|
||||
var reverse = TileCover.CoordinateToTileId(tile.ToVector2d(), 5);
|
||||
|
||||
Assert.AreEqual(tile.Z, reverse.Z);
|
||||
Assert.AreEqual(tile.X, reverse.X);
|
||||
Assert.AreEqual(tile.Y, reverse.Y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f7d7e9f06ea614f1897bff8ed17eeba9
|
||||
timeCreated: 1498231547
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,159 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="CompressionTest.cs" company="Mapbox">
|
||||
// Copyright (c) 2016 Mapbox. All rights reserved.
|
||||
// </copyright>
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
// TODO: figure out how run tests outside of Unity with .NET framework, something like '#if !UNITY'
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
|
||||
namespace Mapbox.MapboxSdkCs.UnitTest
|
||||
{
|
||||
using System.Text;
|
||||
using Mapbox.Platform;
|
||||
using Mapbox.Utils;
|
||||
using NUnit.Framework;
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
using UnityEngine.TestTools;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
#endif
|
||||
|
||||
[TestFixture]
|
||||
internal class CompressionTest
|
||||
{
|
||||
|
||||
|
||||
private FileSource _fs;
|
||||
private int _timeout = 10;
|
||||
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
_fs = new FileSource(Unity.MapboxAccess.Instance.Configuration.GetMapsSkuToken, Unity.MapboxAccess.Instance.Configuration.AccessToken);
|
||||
_timeout = Unity.MapboxAccess.Instance.Configuration.DefaultTimeout;
|
||||
#else
|
||||
// when run outside of Unity FileSource gets the access token from environment variable 'MAPBOX_ACCESS_TOKEN'
|
||||
_fs = new FileSource();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void Empty()
|
||||
{
|
||||
var buffer = new byte[] { };
|
||||
Assert.AreEqual(buffer, Compression.Decompress(buffer));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NotCompressed()
|
||||
{
|
||||
var buffer = Encoding.ASCII.GetBytes("foobar");
|
||||
Assert.AreEqual(buffer, Compression.Decompress(buffer));
|
||||
}
|
||||
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
[UnityTest]
|
||||
public IEnumerator Corrupt()
|
||||
{
|
||||
#else
|
||||
[Test]
|
||||
public void Corrupt() {
|
||||
#endif
|
||||
var buffer = new byte[] { };
|
||||
|
||||
// Vector tiles are compressed.
|
||||
_fs.Request(
|
||||
"https://api.mapbox.com/v4/mapbox.mapbox-streets-v7/0/0/0.vector.pbf",
|
||||
(Response res) =>
|
||||
{
|
||||
if (res.HasError)
|
||||
{
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
Debug.LogError(res.ExceptionsAsString);
|
||||
#else
|
||||
System.Diagnostics.Debug.WriteLine(res.ExceptionsAsString);
|
||||
#endif
|
||||
}
|
||||
buffer = res.Data;
|
||||
},
|
||||
_timeout
|
||||
);
|
||||
|
||||
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
IEnumerator enumerator = _fs.WaitForAllRequests();
|
||||
while (enumerator.MoveNext()) { yield return null; }
|
||||
#else
|
||||
_fs.WaitForAllRequests();
|
||||
#endif
|
||||
|
||||
Assert.Greater(buffer.Length, 30);
|
||||
|
||||
buffer[10] = 0;
|
||||
buffer[20] = 0;
|
||||
buffer[30] = 0;
|
||||
|
||||
Assert.AreEqual(buffer, Compression.Decompress(buffer));
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
[UnityTest]
|
||||
public IEnumerator Decompress()
|
||||
{
|
||||
#else
|
||||
[Test]
|
||||
public void Decompress() {
|
||||
#endif
|
||||
var buffer = new byte[] { };
|
||||
|
||||
// Vector tiles are compressed.
|
||||
_fs.Request(
|
||||
"https://api.mapbox.com/v4/mapbox.mapbox-streets-v7/0/0/0.vector.pbf",
|
||||
(Response res) =>
|
||||
{
|
||||
if (res.HasError)
|
||||
{
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
Debug.LogError(res.ExceptionsAsString);
|
||||
#else
|
||||
System.Diagnostics.Debug.WriteLine(res.ExceptionsAsString);
|
||||
#endif
|
||||
}
|
||||
buffer = res.Data;
|
||||
},
|
||||
_timeout
|
||||
);
|
||||
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
IEnumerator enumerator = _fs.WaitForAllRequests();
|
||||
while (enumerator.MoveNext()) { yield return null; }
|
||||
#else
|
||||
_fs.WaitForAllRequests();
|
||||
#endif
|
||||
|
||||
// tiles are automatically decompressed during HttpRequest on full .Net framework
|
||||
// not on .NET Core / UWP / Unity
|
||||
#if UNITY_EDITOR_OSX && UNITY_IOS
|
||||
Assert.AreEqual(buffer.Length, Compression.Decompress(buffer).Length); // EditMode on OSX
|
||||
#elif UNITY_EDITOR && (UNITY_IOS || UNITY_ANDROID) // PlayMode tests in Editor
|
||||
Debug.Log("EditMode tests in Editor");
|
||||
Assert.Less(buffer.Length, Compression.Decompress(buffer).Length);
|
||||
#elif !UNITY_EDITOR && (UNITY_EDITOR_OSX || UNITY_IOS || UNITY_ANDROID) // PlayMode tests on device
|
||||
Debug.Log("PlayMode tests on device");
|
||||
Assert.AreEqual(buffer.Length, Compression.Decompress(buffer).Length);
|
||||
#elif NETFX_CORE
|
||||
Assert.Less(buffer.Length, Compression.Decompress(buffer).Length);
|
||||
#else
|
||||
Assert.AreEqual(buffer.Length, Compression.Decompress(buffer).Length);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d77460974e8834b2a8f3b1a72c49325b
|
||||
timeCreated: 1498231547
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,104 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="DirectionResourceTest.cs" company="Mapbox">
|
||||
// Copyright (c) 2016 Mapbox. All rights reserved.
|
||||
// </copyright>
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
namespace Mapbox.MapboxSdkCs.UnitTest
|
||||
{
|
||||
using System;
|
||||
using Mapbox.Utils;
|
||||
using NUnit.Framework;
|
||||
|
||||
[TestFixture]
|
||||
internal class DirectionResourceTest
|
||||
{
|
||||
private Vector2d[] _coordinates = { new Vector2d(10, 10), new Vector2d(20, 20) };
|
||||
private Directions.RoutingProfile _profile = Directions.RoutingProfile.Driving;
|
||||
private Directions.DirectionResource _directionResource;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_directionResource = new Directions.DirectionResource(_coordinates, _profile);
|
||||
}
|
||||
|
||||
public void MismatchedBearings()
|
||||
{
|
||||
_directionResource.Bearings = new BearingFilter[] { new BearingFilter(10, 10) };
|
||||
}
|
||||
|
||||
public void MismatchedRadiuses()
|
||||
{
|
||||
_directionResource.Radiuses = new double[] { 10 };
|
||||
}
|
||||
|
||||
public void TooSmallRadius()
|
||||
{
|
||||
_directionResource.Radiuses = new double[] { 10, -1 };
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SetInvalidBearings()
|
||||
{
|
||||
Assert.Throws<Exception>(MismatchedBearings);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SetInvalidRadiuses_Mismatched()
|
||||
{
|
||||
Assert.Throws<Exception>(MismatchedRadiuses);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SetInvalidRadiuses_TooSmall()
|
||||
{
|
||||
Assert.Throws<Exception>(TooSmallRadius);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetUrl()
|
||||
{
|
||||
// With only constructor
|
||||
Assert.AreEqual("https://api.mapbox.com/directions/v5/mapbox/driving/10.00000,10.00000;20.00000,20.00000.json", _directionResource.GetUrl());
|
||||
|
||||
// With alternatives
|
||||
_directionResource.Alternatives = false;
|
||||
// ToLower is needed to make test pass on OSX
|
||||
Assert.AreEqual("https://api.mapbox.com/directions/v5/mapbox/driving/10.00000,10.00000;20.00000,20.00000.json?alternatives=false".ToLower(), _directionResource.GetUrl());
|
||||
|
||||
// With bearings
|
||||
_directionResource.Bearings = new BearingFilter[] { new BearingFilter(90, 45), new BearingFilter(90, 30) };
|
||||
Assert.AreEqual("https://api.mapbox.com/directions/v5/mapbox/driving/10.00000,10.00000;20.00000,20.00000.json?alternatives=false&bearings=90%2C45%3B90%2C30".ToLower(), _directionResource.GetUrl().ToLower());
|
||||
|
||||
// Bearings are nullable
|
||||
_directionResource.Bearings = new BearingFilter[] { new BearingFilter(90, 45), new BearingFilter(null, null) };
|
||||
Assert.AreEqual("https://api.mapbox.com/directions/v5/mapbox/driving/10.00000,10.00000;20.00000,20.00000.json?alternatives=false&bearings=90%2C45%3B".ToLower(), _directionResource.GetUrl().ToLower());
|
||||
|
||||
// With continue straight
|
||||
_directionResource.ContinueStraight = false;
|
||||
Assert.AreEqual("https://api.mapbox.com/directions/v5/mapbox/driving/10.00000,10.00000;20.00000,20.00000.json?alternatives=false&bearings=90%2C45%3B&continue_straight=false".ToLower(), _directionResource.GetUrl().ToLower());
|
||||
|
||||
// With overview
|
||||
_directionResource.Overview = Directions.Overview.Full;
|
||||
Assert.AreEqual("https://api.mapbox.com/directions/v5/mapbox/driving/10.00000,10.00000;20.00000,20.00000.json?alternatives=false&bearings=90%2C45%3B&continue_straight=false&overview=full".ToLower(), _directionResource.GetUrl().ToLower());
|
||||
|
||||
// With steps
|
||||
_directionResource.Radiuses = new double[] { 30, 30 };
|
||||
Assert.AreEqual("https://api.mapbox.com/directions/v5/mapbox/driving/10.00000,10.00000;20.00000,20.00000.json?alternatives=false&bearings=90%2C45%3B&continue_straight=false&overview=full&radiuses=30%2C30".ToLower(), _directionResource.GetUrl().ToLower());
|
||||
|
||||
// With steps
|
||||
_directionResource.Steps = false;
|
||||
Assert.AreEqual("https://api.mapbox.com/directions/v5/mapbox/driving/10.00000,10.00000;20.00000,20.00000.json?alternatives=false&bearings=90%2C45%3B&continue_straight=false&overview=full&radiuses=30%2C30&steps=false".ToLower(), _directionResource.GetUrl().ToLower());
|
||||
|
||||
// Set all to null
|
||||
_directionResource.Alternatives = null;
|
||||
_directionResource.Bearings = null;
|
||||
_directionResource.ContinueStraight = null;
|
||||
_directionResource.Overview = null;
|
||||
_directionResource.Radiuses = null;
|
||||
_directionResource.Steps = null;
|
||||
Assert.AreEqual("https://api.mapbox.com/directions/v5/mapbox/driving/10.00000,10.00000;20.00000,20.00000.json", _directionResource.GetUrl());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 345f6d8ee2d3743779572d1c3701f2fd
|
||||
timeCreated: 1498231546
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,63 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="DirectionsTest.cs" company="Mapbox">
|
||||
// Copyright (c) 2016 Mapbox. All rights reserved.
|
||||
// </copyright>
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
namespace Mapbox.MapboxSdkCs.UnitTest
|
||||
{
|
||||
|
||||
using Mapbox.Directions;
|
||||
using Mapbox.Json;
|
||||
using Mapbox.Platform;
|
||||
using NUnit;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test that Directions serializes and deserializes responses correctly.
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
internal class DirectionsTest
|
||||
{
|
||||
|
||||
private string _basicResponse = "{\"routes\":[{\"legs\":[{\"steps\":[],\"summary\":\"\",\"duration\":214.4,\"distance\":1318.2,\"annotation\":null}],\"geometry\":\"_urwFt}qbMuLp_@jWzPoHhRMK\",\"duration\":214.4,\"distance\":1318.2,\"weight\":0.0,\"weight_name\":null}],\"waypoints\":[{\"name\":\"East 13th Street\",\"location\":[-73.988909,40.733122]},{\"name\":\"6th Avenue\",\"location\":[-74.00001,40.733004]}],\"code\":\"Ok\"}";
|
||||
private string _responseWithSteps = "{\"routes\":[{\"legs\":[{\"steps\":[{\"intersections\":[{\"out\":0,\"entry\":[true],\"bearings\":[299],\"location\":[-73.988909,40.733122]},{\"out\":3,\"entry\":[true,false,false,true],\"bearings\":[15,120,195,300],\"location\":[-73.989868,40.733528],\"in\":1},{\"out\":3,\"entry\":[false,false,true,true],\"bearings\":[15,120,195,300],\"location\":[-73.990945,40.733978],\"in\":1},{\"out\":3,\"entry\":[true,false,false,true],\"bearings\":[30,120,210,300],\"location\":[-73.992266,40.734532],\"in\":1}],\"geometry\":\"_urwFt}qbMqA~DyAvEmBfG{CpJ\",\"maneuver\":{\"bearing_after\":299,\"type\":\"depart\",\"modifier\":\"left\",\"bearing_before\":0,\"Location\":[40.733122,-73.988909],\"instruction\":\"Head northwest on East 13th Street\"},\"duration\":90.5,\"distance\":502.1,\"name\":\"East 13th Street\",\"mode\":\"driving\"},{\"intersections\":[{\"out\":2,\"entry\":[false,false,true,true],\"bearings\":[30,120,210,300],\"location\":[-73.994118,40.735313],\"in\":1},{\"out\":2,\"entry\":[false,true,true,false],\"bearings\":[30,120,210,300],\"location\":[-73.994585,40.734672],\"in\":0},{\"out\":2,\"entry\":[false,false,true,true],\"bearings\":[30,120,210,300],\"location\":[-73.99505,40.734034],\"in\":0},{\"out\":2,\"entry\":[false,true,true,false],\"bearings\":[30,120,210,300],\"location\":[-73.995489,40.733437],\"in\":0},{\"out\":2,\"entry\":[false,false,true,true],\"bearings\":[30,120,210,300],\"location\":[-73.995914,40.732847],\"in\":0},{\"out\":2,\"entry\":[false,true,true,false],\"bearings\":[30,120,210,300],\"location\":[-73.996351,40.732255],\"in\":0}],\"geometry\":\"ubswFf~rbM~B|A~BzAtBvAtBrAtBvAh@Vd@`@lAx@JH\",\"maneuver\":{\"bearing_after\":209,\"type\":\"turn\",\"modifier\":\"left\",\"bearing_before\":299,\"Location\":[40.735313,-73.994118],\"instruction\":\"Turn left onto 5th Avenue\"},\"duration\":67.8,\"distance\":496.3,\"name\":\"5th Avenue\",\"mode\":\"driving\"},{\"intersections\":[{\"out\":2,\"entry\":[false,true,true],\"bearings\":[30,120,300],\"location\":[-73.996976,40.731414],\"in\":0}],\"geometry\":\"ijrwFbpsbMKPoChHEH\",\"maneuver\":{\"bearing_after\":305,\"type\":\"end of road\",\"modifier\":\"right\",\"bearing_before\":212,\"Location\":[40.731414,-73.996976],\"instruction\":\"Turn right onto Washington Square North\"},\"duration\":21.0,\"distance\":164.2,\"name\":\"Washington Square North\",\"mode\":\"driving\"},{\"intersections\":[{\"out\":3,\"entry\":[false,false,true,true],\"bearings\":[30,120,210,300],\"location\":[-73.998612,40.732215],\"in\":1}],\"geometry\":\"korwFhzsbMmCbH\",\"maneuver\":{\"bearing_after\":303,\"type\":\"new name\",\"modifier\":\"straight\",\"bearing_before\":303,\"Location\":[40.732215,-73.998612],\"instruction\":\"Continue straight onto Waverly Place\"},\"duration\":34.5,\"distance\":146.0,\"name\":\"Waverly Place\",\"mode\":\"driving\"},{\"intersections\":[{\"out\":0,\"entry\":[true,false,false,true],\"bearings\":[30,120,210,300],\"location\":[-74.000066,40.732929],\"in\":1}],\"geometry\":\"ysrwFlctbMMK\",\"maneuver\":{\"bearing_after\":30,\"type\":\"turn\",\"modifier\":\"right\",\"bearing_before\":303,\"Location\":[40.732929,-74.000066],\"instruction\":\"Turn right onto 6th Avenue\"},\"duration\":0.6,\"distance\":9.6,\"name\":\"6th Avenue\",\"mode\":\"driving\"},{\"intersections\":[{\"out\":0,\"entry\":[true],\"bearings\":[210],\"location\":[-74.00001,40.733004],\"in\":0}],\"geometry\":\"gtrwF`ctbM\",\"maneuver\":{\"bearing_after\":0,\"type\":\"arrive\",\"modifier\":null,\"bearing_before\":30,\"Location\":[40.732929,-74.000066],\"instruction\":\"You have arrived at your destination\"},\"duration\":0.0,\"distance\":0.0,\"name\":\"6th Avenue\",\"mode\":\"driving\"}],\"summary\":\"East 13th Street, 5th Avenue\",\"duration\":214.4,\"distance\":1318.2,\"annotation\":null}],\"geometry\":\"_urwFt}qbMuLp_@jWzPoHhRMK\",\"duration\":214.4,\"distance\":1318.2,\"weight\":0.0,\"weight_name\":null}],\"waypoints\":[{\"name\":\"East 13th Street\",\"location\":[-73.988909,40.733122]},{\"name\":\"6th Avenue\",\"location\":[-74.00001,40.733004]}],\"code\":\"Ok\"}";
|
||||
private Directions _directions = new Directions(new FileSource(Unity.MapboxAccess.Instance.Configuration.GetMapsSkuToken, Unity.MapboxAccess.Instance.Configuration.AccessToken));
|
||||
|
||||
|
||||
|
||||
[Test]
|
||||
public void SerializesAndDeserializesBasic()
|
||||
{
|
||||
// First, deserialize the example response
|
||||
DirectionsResponse basicResp = _directions.Deserialize(_basicResponse);
|
||||
|
||||
// Then deserialize it back to a string.
|
||||
string basicReserialized = _directions.Serialize(basicResp);
|
||||
|
||||
// Ensure the two match
|
||||
Assert.AreEqual(_basicResponse, basicReserialized);
|
||||
}
|
||||
|
||||
|
||||
//TODO: implement a proper Json object comaparer
|
||||
/// <summary> This test will fail, see https://github.com/mapbox/mapbox-sdk-unity/issues/51. </summary>
|
||||
[Test]
|
||||
public void SerializesAndDeserializesWithSteps()
|
||||
{
|
||||
// First, deserialize the example response.
|
||||
DirectionsResponse withStepsResp = _directions.Deserialize(_responseWithSteps);
|
||||
|
||||
// Then deserialize it back to a string.
|
||||
string withStepsReserialized = _directions.Serialize(withStepsResp);
|
||||
|
||||
// Ensure the two match.
|
||||
Assert.AreEqual(_responseWithSteps, withStepsReserialized);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 255dbd247672f4f0abf600a702d2def7
|
||||
timeCreated: 1498231546
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,250 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="FileSourceTest.cs" company="Mapbox">
|
||||
// Copyright (c) 2016 Mapbox. All rights reserved.
|
||||
// </copyright>
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
// TODO: figure out how run tests outside of Unity with .NET framework, something like '#if !UNITY'
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
|
||||
namespace Mapbox.MapboxSdkCs.UnitTest
|
||||
{
|
||||
|
||||
|
||||
using Mapbox.Platform;
|
||||
using NUnit.Framework;
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
using UnityEngine.TestTools;
|
||||
using System.Collections;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
[TestFixture]
|
||||
internal class FileSourceTest
|
||||
{
|
||||
|
||||
private const string _url = "https://api.mapbox.com/geocoding/v5/mapbox.places/helsinki.json";
|
||||
private FileSource _fs;
|
||||
private int _timeout = 10;
|
||||
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
_fs = new FileSource(Unity.MapboxAccess.Instance.Configuration.GetMapsSkuToken, Unity.MapboxAccess.Instance.Configuration.AccessToken);
|
||||
_timeout = Unity.MapboxAccess.Instance.Configuration.DefaultTimeout;
|
||||
#else
|
||||
// when run outside of Unity FileSource gets the access token from environment variable 'MAPBOX_ACCESS_TOKEN'
|
||||
_fs = new FileSource();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if !UNITY_5_6_OR_NEWER
|
||||
[Test]
|
||||
public void AccessTokenSet()
|
||||
{
|
||||
Assert.IsNotNull(
|
||||
Environment.GetEnvironmentVariable("MAPBOX_ACCESS_TOKEN"),
|
||||
"MAPBOX_ACCESS_TOKEN not set in the environment."
|
||||
);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
[UnityTest]
|
||||
public IEnumerator Request()
|
||||
#else
|
||||
[Test]
|
||||
public void Request()
|
||||
#endif
|
||||
{
|
||||
byte[] data = null;
|
||||
_fs.Request(
|
||||
_url,
|
||||
(Response res) =>
|
||||
{
|
||||
data = res.Data;
|
||||
}
|
||||
, _timeout
|
||||
);
|
||||
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
IEnumerator enumerator = _fs.WaitForAllRequests();
|
||||
while (enumerator.MoveNext()) { yield return null; }
|
||||
#else
|
||||
_fs.WaitForAllRequests();
|
||||
#endif
|
||||
Assert.IsNotNull(data, "No data received from the servers.");
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
[UnityTest]
|
||||
public IEnumerator MultipleRequests()
|
||||
#else
|
||||
[Test]
|
||||
public void Request()
|
||||
#endif
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
_fs.Request(_url, (Response res) => ++count, _timeout);
|
||||
_fs.Request(_url, (Response res) => ++count, _timeout);
|
||||
_fs.Request(_url, (Response res) => ++count, _timeout);
|
||||
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
IEnumerator enumerator = _fs.WaitForAllRequests();
|
||||
while (enumerator.MoveNext()) { yield return null; }
|
||||
#else
|
||||
_fs.WaitForAllRequests();
|
||||
#endif
|
||||
|
||||
Assert.AreEqual(count, 3, "Should have received 3 replies.");
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
[UnityTest]
|
||||
#if UNITY_ANDROID || UNITY_IOS
|
||||
[Ignore("test ignored: Request.Cancel() does not work on some devices")]
|
||||
#endif
|
||||
public IEnumerator RequestCancel()
|
||||
#else
|
||||
[Test]
|
||||
public void RequestCancel()
|
||||
#endif
|
||||
{
|
||||
var request = _fs.Request(
|
||||
//use "heavy" tile with 182KB that request doesn't finish before it is cancelled
|
||||
"https://a.tiles.mapbox.com/v4/mapbox.mapbox-terrain-v2,mapbox.mapbox-streets-v7/10/545/361.vector.pbf",
|
||||
(Response res) =>
|
||||
{
|
||||
// HACK!! THIS IS BAAAD, investigate more!
|
||||
// on *some* Android devices (eg Samsung S8 not on Pixel 2) and *some* iPhones
|
||||
// HasError is false as the request finishes successfully before 'Cancel()' kicks in
|
||||
// couldn't find the reason or a proper fix.
|
||||
// maybe some OS internal caching?
|
||||
#if UNITY_ANDROID || UNITY_IOS
|
||||
UnityEngine.Debug.LogWarning("test 'RequestCancel' not run");
|
||||
return;
|
||||
#endif
|
||||
|
||||
Assert.IsTrue(res.HasError);
|
||||
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
Assert.IsNotNull(res.Exceptions[0]);
|
||||
Assert.AreEqual("Request aborted", res.Exceptions[0].Message);
|
||||
#else
|
||||
WebException wex = res.Exceptions[0] as WebException;
|
||||
Assert.IsNotNull(wex);
|
||||
Assert.AreEqual(wex.Status, WebExceptionStatus.RequestCanceled);
|
||||
#endif
|
||||
},
|
||||
_timeout
|
||||
);
|
||||
|
||||
request.Cancel();
|
||||
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
IEnumerator enumerator = _fs.WaitForAllRequests();
|
||||
while (enumerator.MoveNext()) { yield return null; }
|
||||
#else
|
||||
_fs.WaitForAllRequests();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
[UnityTest]
|
||||
public IEnumerator RequestDnsError()
|
||||
#else
|
||||
[Test]
|
||||
public void RequestDnsError()
|
||||
#endif
|
||||
{
|
||||
_fs.Request(
|
||||
"https://dnserror.shouldnotwork",
|
||||
(Response res) =>
|
||||
{
|
||||
Assert.IsTrue(res.HasError);
|
||||
// Attention: when using Fiddler to throttle requests message is "Failed to receive data"
|
||||
Assert.IsTrue(
|
||||
res.Exceptions[0].Message.Contains("destination host")
|
||||
, string.Format("Exception message [{0}] does not contain 'destination host'", res.Exceptions[0].Message)
|
||||
);
|
||||
},
|
||||
_timeout
|
||||
);
|
||||
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
IEnumerator enumerator = _fs.WaitForAllRequests();
|
||||
while (enumerator.MoveNext()) { yield return null; }
|
||||
#else
|
||||
_fs.WaitForAllRequests();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
[UnityTest]
|
||||
public IEnumerator RequestForbidden()
|
||||
#else
|
||||
[Test]
|
||||
public void RequestForbidden()
|
||||
#endif
|
||||
{
|
||||
// Mapbox servers will return a forbidden when attempting
|
||||
// to access a page outside the API space with a token
|
||||
// on the query. Let's hope the behaviour stay like this.
|
||||
_fs.Request(
|
||||
"https://mapbox.com/forbidden",
|
||||
(Response res) =>
|
||||
{
|
||||
Assert.IsTrue(res.HasError);
|
||||
Assert.AreEqual(403, res.StatusCode);
|
||||
},
|
||||
_timeout
|
||||
);
|
||||
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
IEnumerator enumerator = _fs.WaitForAllRequests();
|
||||
while (enumerator.MoveNext()) { yield return null; }
|
||||
#else
|
||||
_fs.WaitForAllRequests();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
[UnityTest]
|
||||
public IEnumerator WaitWithNoRequests()
|
||||
#else
|
||||
[Test]
|
||||
public void WaitWithNoRequests()
|
||||
#endif
|
||||
{
|
||||
// This should simply not block.
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
IEnumerator enumerator = _fs.WaitForAllRequests();
|
||||
while (enumerator.MoveNext()) { yield return null; }
|
||||
#else
|
||||
_fs.WaitForAllRequests();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ec486731809ff42cf82d08418a7c179a
|
||||
timeCreated: 1498231547
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,150 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="ForwardGeocodeResourceTest.cs" company="Mapbox">
|
||||
// Copyright (c) 2016 Mapbox. All rights reserved.
|
||||
// </copyright>
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
namespace Mapbox.MapboxSdkCs.UnitTest
|
||||
{
|
||||
|
||||
using System;
|
||||
using Mapbox.Utils;
|
||||
using NUnit.Framework;
|
||||
|
||||
|
||||
[TestFixture]
|
||||
internal class ForwardGeocodeResourceTest
|
||||
{
|
||||
private const string _query = "Minneapolis, MN";
|
||||
private Geocoding.ForwardGeocodeResource _forwardGeocodeResource;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_forwardGeocodeResource = new Geocoding.ForwardGeocodeResource(_query);
|
||||
}
|
||||
|
||||
public void BadType()
|
||||
{
|
||||
_forwardGeocodeResource.Types = new string[] { "fake" };
|
||||
}
|
||||
|
||||
public void BadTypeWithGoodType()
|
||||
{
|
||||
_forwardGeocodeResource.Types = new string[] { "place", "fake" };
|
||||
}
|
||||
|
||||
public void BadCountry()
|
||||
{
|
||||
_forwardGeocodeResource.Types = new string[] { "zz" };
|
||||
}
|
||||
|
||||
public void BadCountryWithGoodType()
|
||||
{
|
||||
_forwardGeocodeResource.Types = new string[] { "zz", "ar" };
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SetInvalidTypes()
|
||||
{
|
||||
Assert.Throws<Exception>(BadType);
|
||||
Assert.Throws<Exception>(BadTypeWithGoodType);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SetInvalidCountries()
|
||||
{
|
||||
Assert.Throws<Exception>(BadCountry);
|
||||
Assert.Throws<Exception>(BadCountryWithGoodType);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetUrl()
|
||||
{
|
||||
// With only constructor
|
||||
// TODO: find proper fix for encoded url parameters crashing on some iPhones
|
||||
#if UNITY_IOS
|
||||
UnityEngine.Debug.LogWarning("ForwardGeocodeResourceTest.GetUrl() TODO: find proper fix for encoded url parameters crashing on some iPhones");
|
||||
Assert.AreEqual("https://api.mapbox.com/geocoding/v5/mapbox.places/Minneapolis++MN.json", _forwardGeocodeResource.GetUrl());
|
||||
#else
|
||||
Assert.AreEqual("https://api.mapbox.com/geocoding/v5/mapbox.places/Minneapolis%2C%20MN.json", _forwardGeocodeResource.GetUrl());
|
||||
#endif
|
||||
|
||||
|
||||
// With autocomplete
|
||||
_forwardGeocodeResource.Autocomplete = false;
|
||||
#if UNITY_IOS
|
||||
Assert.AreEqual("https://api.mapbox.com/geocoding/v5/mapbox.places/Minneapolis++MN.json?autocomplete=false", _forwardGeocodeResource.GetUrl());
|
||||
#else
|
||||
Assert.AreEqual("https://api.mapbox.com/geocoding/v5/mapbox.places/Minneapolis%2C%20MN.json?autocomplete=false", _forwardGeocodeResource.GetUrl());
|
||||
#endif
|
||||
|
||||
|
||||
// With bbox
|
||||
_forwardGeocodeResource.Bbox = new Vector2dBounds(new Vector2d(15, 10), new Vector2d(25, 20));
|
||||
#if UNITY_IOS
|
||||
Assert.AreEqual("https://api.mapbox.com/geocoding/v5/mapbox.places/Minneapolis++MN.json?autocomplete=false&bbox=10.00000%2C15.00000%2C20.00000%2C25.00000".ToLower(), _forwardGeocodeResource.GetUrl().ToLower());
|
||||
#else
|
||||
Assert.AreEqual("https://api.mapbox.com/geocoding/v5/mapbox.places/Minneapolis++MN.json?autocomplete=false&bbox=10.00000%2C15.00000%2C20.00000%2C25.00000", _forwardGeocodeResource.GetUrl());
|
||||
#endif
|
||||
|
||||
|
||||
// With one country
|
||||
_forwardGeocodeResource.Country = new string[] { "ar" };
|
||||
#if UNITY_IOS
|
||||
Assert.AreEqual("https://api.mapbox.com/geocoding/v5/mapbox.places/Minneapolis++MN.json?autocomplete=false&bbox=10.00000%2C15.00000%2C20.00000%2C25.00000&country=ar".ToLower(), _forwardGeocodeResource.GetUrl().ToLower());
|
||||
#else
|
||||
Assert.AreEqual("https://api.mapbox.com/geocoding/v5/mapbox.places/Minneapolis%2C%20MN.json?autocomplete=false&bbox=10.00000%2C15.00000%2C20.00000%2C25.00000&country=ar", _forwardGeocodeResource.GetUrl());
|
||||
#endif
|
||||
|
||||
|
||||
// With multiple countries
|
||||
_forwardGeocodeResource.Country = new string[] { "ar", "fi" };
|
||||
#if UNITY_IOS
|
||||
Assert.AreEqual("https://api.mapbox.com/geocoding/v5/mapbox.places/Minneapolis++MN.json?autocomplete=false&bbox=10.00000%2C15.00000%2C20.00000%2C25.00000&country=ar%2Cfi".ToLower(), _forwardGeocodeResource.GetUrl().ToLower());
|
||||
#else
|
||||
Assert.AreEqual("https://api.mapbox.com/geocoding/v5/mapbox.places/Minneapolis%2C%20MN.json?autocomplete=false&bbox=10.00000%2C15.00000%2C20.00000%2C25.00000&country=ar%2Cfi", _forwardGeocodeResource.GetUrl());
|
||||
#endif
|
||||
|
||||
|
||||
// With proximity
|
||||
_forwardGeocodeResource.Proximity = new Vector2d(10, 5);
|
||||
#if UNITY_IOS
|
||||
Assert.AreEqual("https://api.mapbox.com/geocoding/v5/mapbox.places/Minneapolis++MN.json?autocomplete=false&bbox=10.00000%2C15.00000%2C20.00000%2C25.00000&country=ar%2Cfi&proximity=5.00000%2C10.00000".ToLower(), _forwardGeocodeResource.GetUrl().ToLower());
|
||||
#else
|
||||
Assert.AreEqual("https://api.mapbox.com/geocoding/v5/mapbox.places/Minneapolis%2C%20MN.json?autocomplete=false&bbox=10.00000%2C15.00000%2C20.00000%2C25.00000&country=ar%2Cfi&proximity=5.00000%2C10.00000", _forwardGeocodeResource.GetUrl());
|
||||
#endif
|
||||
|
||||
|
||||
// With one types
|
||||
_forwardGeocodeResource.Types = new string[] { "country" };
|
||||
#if UNITY_IOS
|
||||
Assert.AreEqual("https://api.mapbox.com/geocoding/v5/mapbox.places/Minneapolis++MN.json?autocomplete=false&bbox=10.00000%2C15.00000%2C20.00000%2C25.00000&country=ar%2Cfi&proximity=5.00000%2C10.00000&types=country".ToLower(), _forwardGeocodeResource.GetUrl().ToLower());
|
||||
#else
|
||||
Assert.AreEqual("https://api.mapbox.com/geocoding/v5/mapbox.places/Minneapolis%2C%20MN.json?autocomplete=false&bbox=10.00000%2C15.00000%2C20.00000%2C25.00000&country=ar%2Cfi&proximity=5.00000%2C10.00000&types=country", _forwardGeocodeResource.GetUrl());
|
||||
#endif
|
||||
|
||||
|
||||
// With multiple types
|
||||
_forwardGeocodeResource.Types = new string[] { "country", "region" };
|
||||
#if UNITY_IOS
|
||||
Assert.AreEqual("https://api.mapbox.com/geocoding/v5/mapbox.places/Minneapolis++MN.json?autocomplete=false&bbox=10.00000%2C15.00000%2C20.00000%2C25.00000&country=ar%2Cfi&proximity=5.00000%2C10.00000&types=country%2Cregion".ToLower(), _forwardGeocodeResource.GetUrl().ToLower());
|
||||
#else
|
||||
Assert.AreEqual("https://api.mapbox.com/geocoding/v5/mapbox.places/Minneapolis%2C%20MN.json?autocomplete=false&bbox=10.00000%2C15.00000%2C20.00000%2C25.00000&country=ar%2Cfi&proximity=5.00000%2C10.00000&types=country%2Cregion", _forwardGeocodeResource.GetUrl());
|
||||
#endif
|
||||
|
||||
// Set all to null
|
||||
_forwardGeocodeResource.Autocomplete = null;
|
||||
_forwardGeocodeResource.Bbox = null;
|
||||
_forwardGeocodeResource.Country = null;
|
||||
_forwardGeocodeResource.Proximity = null;
|
||||
_forwardGeocodeResource.Types = null;
|
||||
|
||||
#if UNITY_IOS
|
||||
Assert.AreEqual("https://api.mapbox.com/geocoding/v5/mapbox.places/Minneapolis++MN.json", _forwardGeocodeResource.GetUrl());
|
||||
#else
|
||||
Assert.AreEqual("https://api.mapbox.com/geocoding/v5/mapbox.places/Minneapolis%2C%20MN.json", _forwardGeocodeResource.GetUrl());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 91c78df7257b9401c83b93a8c8382016
|
||||
timeCreated: 1498231546
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,41 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="Vector2dTest.cs" company="Mapbox">
|
||||
// Copyright (c) 2016 Mapbox. All rights reserved.
|
||||
// </copyright>
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
namespace Mapbox.MapboxSdkCs.UnitTest
|
||||
{
|
||||
|
||||
using Mapbox.Utils;
|
||||
using NUnit.Framework;
|
||||
|
||||
|
||||
[TestFixture]
|
||||
internal class Vector2dTest
|
||||
{
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void NullIsland()
|
||||
{
|
||||
var lngLat = new Vector2d(0, 0);
|
||||
Assert.AreEqual("0.00000,0.00000", lngLat.ToString());
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void DC()
|
||||
{
|
||||
var lngLat = new Vector2d(38.9165, -77.0295);
|
||||
Assert.AreEqual("-77.02950,38.91650", lngLat.ToString());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9ce0cc51863054b17aed4f4fdfb8a2d3
|
||||
timeCreated: 1498231546
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,127 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="Vector2dBoundsTest.cs" company="Mapbox">
|
||||
// Copyright (c) 2016 Mapbox. All rights reserved.
|
||||
// </copyright>
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
namespace Mapbox.MapboxSdkCs.UnitTest
|
||||
{
|
||||
|
||||
using Mapbox.Utils;
|
||||
using NUnit.Framework;
|
||||
|
||||
|
||||
[TestFixture]
|
||||
internal class Vector2dBoundsTest
|
||||
{
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void SmallBounds()
|
||||
{
|
||||
var a = new Vector2d(0, 0);
|
||||
var b = new Vector2d(10, 10);
|
||||
var bounds = new Vector2dBounds(a, b);
|
||||
Assert.AreEqual("0.00000,0.00000,10.00000,10.00000", bounds.ToString());
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void Extend()
|
||||
{
|
||||
var bounds1 = new Vector2dBounds(new Vector2d(-10, -10), new Vector2d(10, 10));
|
||||
var bounds2 = new Vector2dBounds(new Vector2d(-20, -20), new Vector2d(20, 20));
|
||||
|
||||
bounds1.Extend(bounds2);
|
||||
|
||||
Assert.AreEqual(bounds1.South, bounds2.South);
|
||||
Assert.AreEqual(bounds1.West, bounds2.West);
|
||||
Assert.AreEqual(bounds1.North, bounds2.North);
|
||||
Assert.AreEqual(bounds1.East, bounds2.East);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void Hull()
|
||||
{
|
||||
var bounds1 = new Vector2dBounds(new Vector2d(-10, -10), new Vector2d(10, 10));
|
||||
var bounds2 = Vector2dBounds.FromCoordinates(new Vector2d(10, 10), new Vector2d(-10, -10));
|
||||
|
||||
Assert.AreEqual(bounds1.South, bounds2.South);
|
||||
Assert.AreEqual(bounds1.West, bounds2.West);
|
||||
Assert.AreEqual(bounds1.North, bounds2.North);
|
||||
Assert.AreEqual(bounds1.East, bounds2.East);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void World()
|
||||
{
|
||||
var bounds = Vector2dBounds.World();
|
||||
|
||||
Assert.AreEqual(bounds.South, -90);
|
||||
Assert.AreEqual(bounds.West, -180);
|
||||
Assert.AreEqual(bounds.North, 90);
|
||||
Assert.AreEqual(bounds.East, 180);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void CardinalLimits()
|
||||
{
|
||||
var bounds = new Vector2dBounds(new Vector2d(10, 20), new Vector2d(30, 40));
|
||||
|
||||
// SouthWest, first parameter.
|
||||
Assert.AreEqual(bounds.South, 10);
|
||||
Assert.AreEqual(bounds.West, 20);
|
||||
|
||||
// NorthEast, second parameter.
|
||||
Assert.AreEqual(bounds.North, 30);
|
||||
Assert.AreEqual(bounds.East, 40);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void IsEmpty()
|
||||
{
|
||||
var bounds1 = new Vector2dBounds(new Vector2d(10, 10), new Vector2d(0, 0));
|
||||
Assert.IsTrue(bounds1.IsEmpty());
|
||||
|
||||
var bounds2 = new Vector2dBounds(new Vector2d(0, 0), new Vector2d(0, 0));
|
||||
Assert.IsFalse(bounds2.IsEmpty());
|
||||
|
||||
var bounds3 = new Vector2dBounds(new Vector2d(0, 0), new Vector2d(10, 10));
|
||||
Assert.IsFalse(bounds3.IsEmpty());
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void Center()
|
||||
{
|
||||
var bounds1 = new Vector2dBounds(new Vector2d(0, 0), new Vector2d(0, 0));
|
||||
Assert.AreEqual(bounds1.Center, new Vector2d(0, 0));
|
||||
|
||||
bounds1.Center = new Vector2d(10, 10);
|
||||
Assert.AreEqual(new Vector2dBounds(new Vector2d(10, 10), new Vector2d(10, 10)), bounds1);
|
||||
|
||||
var bounds2 = new Vector2dBounds(new Vector2d(-10, -10), new Vector2d(10, 10));
|
||||
Assert.AreEqual(bounds2.Center, new Vector2d(0, 0));
|
||||
|
||||
bounds2.Center = new Vector2d(10, 10);
|
||||
Assert.AreEqual(new Vector2dBounds(new Vector2d(0, 0), new Vector2d(20, 20)), bounds2);
|
||||
|
||||
var bounds3 = new Vector2dBounds(new Vector2d(0, 0), new Vector2d(20, 40));
|
||||
Assert.AreEqual(bounds3.Center, new Vector2d(10, 20));
|
||||
|
||||
bounds3.Center = new Vector2d(10, 10);
|
||||
Assert.AreEqual(new Vector2dBounds(new Vector2d(0, -10), new Vector2d(20, 30)), bounds3);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b162f01b49ed74739bf159c9e2f36097
|
||||
timeCreated: 1498231547
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,54 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="GeocoderTest.cs" company="Mapbox">
|
||||
// Copyright (c) 2016 Mapbox. All rights reserved.
|
||||
// </copyright>
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
namespace Mapbox.MapboxSdkCs.UnitTest
|
||||
{
|
||||
|
||||
using Geocoding;
|
||||
using Mapbox.Json;
|
||||
using Mapbox.Platform;
|
||||
using Mapbox.Unity;
|
||||
using Mapbox.Utils.JsonConverters;
|
||||
using NUnit.Framework;
|
||||
|
||||
/// <summary>
|
||||
/// Test that Geocoder serializes and deserializes responses correctly.
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
internal class GeocoderTest
|
||||
{
|
||||
private readonly Geocoder _geocoder = new Geocoder(new FileSource(Unity.MapboxAccess.Instance.Configuration.GetMapsSkuToken, Unity.MapboxAccess.Instance.Configuration.AccessToken)); //MapboxAccess.Instance.Geocoder;
|
||||
private string _forwardResponse = "{\"type\":\"FeatureCollection\",\"query\":[\"minneapolis\"],\"features\":[{\"id\":\"place.12871500125885940\",\"type\":\"Feature\",\"text\":\"Minneapolis\",\"place_name\":\"Minneapolis, Minnesota, United States\",\"relevance\":0.99,\"properties\":{\"wikidata\":\"Q36091\"},\"bbox\":[-93.5226520099878,44.7853029900244,-93.1424209928836,45.2129100099882],\"center\":[-93.2655,44.9773],\"geometry\":{\"type\":\"Point\",\"coordinates\":[-93.2655,44.9773]},\"context\":[{\"id\":\"postcode.11389548391063390\",\"text\":\"55415\"},{\"id\":\"region.12225983719702200\",\"text\":\"Minnesota\",\"short_code\":\"US-MN\",\"wikidata\":\"Q1527\"},{\"id\":\"country.12862386939497690\",\"text\":\"United States\",\"short_code\":\"us\",\"wikidata\":\"Q30\"}]},{\"id\":\"poi.15555644443768740\",\"type\":\"Feature\",\"text\":\"Minneapolis City Hall\",\"place_name\":\"Minneapolis City Hall, Minneapolis, Minnesota 55415, United States\",\"relevance\":0.99,\"properties\":{\"wikidata\":\"Q1384874\",\"landmark\":true,\"tel\":null,\"address\":null,\"category\":\"other\"},\"center\":[-93.265277777778,44.977222222222],\"geometry\":{\"type\":\"Point\",\"coordinates\":[-93.265277777778,44.977222222222]},\"context\":[{\"id\":\"neighborhood.13081559486410050\",\"text\":\"Greater Central\"},{\"id\":\"place.12871500125885940\",\"text\":\"Minneapolis\",\"wikidata\":\"Q36091\"},{\"id\":\"postcode.11389548391063390\",\"text\":\"55415\"},{\"id\":\"region.12225983719702200\",\"text\":\"Minnesota\",\"short_code\":\"US-MN\",\"wikidata\":\"Q1527\"},{\"id\":\"country.12862386939497690\",\"text\":\"United States\",\"short_code\":\"us\",\"wikidata\":\"Q30\"}]},{\"id\":\"poi.6527299549845510\",\"type\":\"Feature\",\"text\":\"Minneapolis Grain Exchange\",\"place_name\":\"Minneapolis Grain Exchange, Minneapolis, Minnesota 55415, United States\",\"relevance\":0.99,\"properties\":{\"wikidata\":\"Q1540984\",\"landmark\":true,\"tel\":null,\"address\":null,\"category\":\"other\"},\"center\":[-93.2636,44.9775],\"geometry\":{\"type\":\"Point\",\"coordinates\":[-93.2636,44.9775]},\"context\":[{\"id\":\"neighborhood.13081559486410050\",\"text\":\"Greater Central\"},{\"id\":\"place.12871500125885940\",\"text\":\"Minneapolis\",\"wikidata\":\"Q36091\"},{\"id\":\"postcode.11389548391063390\",\"text\":\"55415\"},{\"id\":\"region.12225983719702200\",\"text\":\"Minnesota\",\"short_code\":\"US-MN\",\"wikidata\":\"Q1527\"},{\"id\":\"country.12862386939497690\",\"text\":\"United States\",\"short_code\":\"us\",\"wikidata\":\"Q30\"}]},{\"id\":\"poi.12655750184890630\",\"type\":\"Feature\",\"text\":\"Minneapolis Armory\",\"place_name\":\"Minneapolis Armory, Minneapolis, Minnesota 55415, United States\",\"relevance\":0.99,\"properties\":{\"wikidata\":\"Q745327\",\"landmark\":true,\"tel\":null,\"address\":null,\"category\":\"other\"},\"center\":[-93.263278,44.975092],\"geometry\":{\"type\":\"Point\",\"coordinates\":[-93.263278,44.975092]},\"context\":[{\"id\":\"neighborhood.13081559486410050\",\"text\":\"Greater Central\"},{\"id\":\"place.12871500125885940\",\"text\":\"Minneapolis\",\"wikidata\":\"Q36091\"},{\"id\":\"postcode.11389548391063390\",\"text\":\"55415\"},{\"id\":\"region.12225983719702200\",\"text\":\"Minnesota\",\"short_code\":\"US-MN\",\"wikidata\":\"Q1527\"},{\"id\":\"country.12862386939497690\",\"text\":\"United States\",\"short_code\":\"us\",\"wikidata\":\"Q30\"}]},{\"id\":\"poi.4855757554573390\",\"type\":\"Feature\",\"text\":\"Minneapolis Chain of Lakes Park\",\"place_name\":\"Minneapolis Chain of Lakes Park, Minneapolis, Minnesota 55405, United States\",\"relevance\":0.99,\"properties\":{\"wikidata\":null,\"landmark\":true,\"tel\":null,\"address\":null,\"category\":\"park\",\"maki\":\"picnic-site\"},\"bbox\":[-93.330260720104,44.9504758437682,-93.3013567328453,44.969400319872],\"center\":[-93.310259,44.959942],\"geometry\":{\"type\":\"Point\",\"coordinates\":[-93.310259,44.959942]},\"context\":[{\"id\":\"neighborhood.12530456224376080\",\"text\":\"Kenwood\"},{\"id\":\"place.12871500125885940\",\"text\":\"Minneapolis\",\"wikidata\":\"Q36091\"},{\"id\":\"postcode.10829535691218220\",\"text\":\"55405\"},{\"id\":\"region.12225983719702200\",\"text\":\"Minnesota\",\"short_code\":\"US-MN\",\"wikidata\":\"Q1527\"},{\"id\":\"country.12862386939497690\",\"text\":\"United States\",\"short_code\":\"us\",\"wikidata\":\"Q30\"}]}],\"attribution\":\"NOTICE: \u00A9 2016 Mapbox and its suppliers. All rights reserved. Use of this data is subject to the Mapbox Terms of Service (https://www.mapbox.com/about/maps/). This response and the information it contains may not be retained.\"}";
|
||||
private string _reverseResponse = "{\"type\":\"FeatureCollection\",\"query\":[-77.0268808,38.925326999999996],\"features\":[{\"id\":\"address.5375777428110760\",\"type\":\"Feature\",\"text\":\"11th St NW\",\"place_name\":\"2717 11th St NW, Washington, District of Columbia 20001, United States\",\"relevance\":1.0,\"properties\":{},\"center\":[-77.026824,38.925306],\"geometry\":{\"type\":\"Point\",\"coordinates\":[-77.026824,38.925306]},\"address\":\"2717\",\"context\":[{\"id\":\"neighborhood.11736072639395000\",\"text\":\"Pleasant Plains\"},{\"id\":\"place.12334081418246050\",\"text\":\"Washington\",\"wikidata\":\"Q61\"},{\"id\":\"postcode.3526019892841050\",\"text\":\"20001\"},{\"id\":\"region.6884744206035790\",\"text\":\"District of Columbia\",\"short_code\":\"US-DC\",\"wikidata\":\"Q61\"},{\"id\":\"country.12862386939497690\",\"text\":\"United States\",\"wikidata\":\"Q30\",\"short_code\":\"us\"}]},{\"id\":\"neighborhood.11736072639395000\",\"type\":\"Feature\",\"text\":\"Pleasant Plains\",\"place_name\":\"Pleasant Plains, Washington, 20001, District of Columbia, United States\",\"relevance\":1.0,\"properties\":{},\"bbox\":[-77.0367101373528,38.9177500315001,-77.0251464843832,38.9273657639],\"center\":[-77.0303,38.9239],\"geometry\":{\"type\":\"Point\",\"coordinates\":[-77.0303,38.9239]},\"context\":[{\"id\":\"place.12334081418246050\",\"text\":\"Washington\",\"wikidata\":\"Q61\"},{\"id\":\"postcode.3526019892841050\",\"text\":\"20001\"},{\"id\":\"region.6884744206035790\",\"text\":\"District of Columbia\",\"short_code\":\"US-DC\",\"wikidata\":\"Q61\"},{\"id\":\"country.12862386939497690\",\"text\":\"United States\",\"wikidata\":\"Q30\",\"short_code\":\"us\"}]},{\"id\":\"place.12334081418246050\",\"type\":\"Feature\",\"text\":\"Washington\",\"place_name\":\"Washington, District of Columbia, United States\",\"relevance\":1.0,\"properties\":{\"wikidata\":\"Q61\"},\"bbox\":[-77.1197590084041,38.8031129900659,-76.90939299,38.9955480080759],\"center\":[-77.0366,38.895],\"geometry\":{\"type\":\"Point\",\"coordinates\":[-77.0366,38.895]},\"context\":[{\"id\":\"postcode.3526019892841050\",\"text\":\"20001\"},{\"id\":\"region.6884744206035790\",\"text\":\"District of Columbia\",\"short_code\":\"US-DC\",\"wikidata\":\"Q61\"},{\"id\":\"country.12862386939497690\",\"text\":\"United States\",\"wikidata\":\"Q30\",\"short_code\":\"us\"}]},{\"id\":\"postcode.3526019892841050\",\"type\":\"Feature\",\"text\":\"20001\",\"place_name\":\"20001, District of Columbia, United States\",\"relevance\":1.0,\"properties\":{},\"bbox\":[-77.028082,38.890834,-77.007177,38.929058],\"center\":[-77.018017,38.909197],\"geometry\":{\"type\":\"Point\",\"coordinates\":[-77.018017,38.909197]},\"context\":[{\"id\":\"region.6884744206035790\",\"text\":\"District of Columbia\",\"short_code\":\"US-DC\",\"wikidata\":\"Q61\"},{\"id\":\"country.12862386939497690\",\"text\":\"United States\",\"wikidata\":\"Q30\",\"short_code\":\"us\"}]},{\"id\":\"region.6884744206035790\",\"type\":\"Feature\",\"text\":\"District of Columbia\",\"place_name\":\"District of Columbia, United States\",\"relevance\":1.0,\"properties\":{\"short_code\":\"US-DC\",\"wikidata\":\"Q61\"},\"bbox\":[-77.2081379659453,38.7177026348658,-76.909393,38.995548],\"center\":[-76.990661,38.89657],\"geometry\":{\"type\":\"Point\",\"coordinates\":[-76.990661,38.89657]},\"context\":[{\"id\":\"country.12862386939497690\",\"text\":\"United States\",\"wikidata\":\"Q30\",\"short_code\":\"us\"}]},{\"id\":\"country.12862386939497690\",\"type\":\"Feature\",\"text\":\"United States\",\"place_name\":\"United States\",\"relevance\":1.0,\"properties\":{\"wikidata\":\"Q30\",\"short_code\":\"us\"},\"bbox\":[-179.330950579,18.765563302,179.959578044,71.540723637],\"center\":[-97.922211,39.381266],\"geometry\":{\"type\":\"Point\",\"coordinates\":[-97.922211,39.381266]}}],\"attribution\":\"NOTICE: © 2016 Mapbox and its suppliers. All rights reserved. Use of this data is subject to the Mapbox Terms of Service (https://www.mapbox.com/about/maps/). This response and the information it contains may not be retained.\"}";
|
||||
|
||||
[Test]
|
||||
public void SerializesAndDeserializesReverse()
|
||||
{
|
||||
// First, deserialize the example response
|
||||
ReverseGeocodeResponse reverseResp = _geocoder.Deserialize<ReverseGeocodeResponse>(_reverseResponse);
|
||||
|
||||
// Then deserialize it back to a string.
|
||||
string reverseReserialized = JsonConvert.SerializeObject(reverseResp, JsonConverters.Converters);
|
||||
|
||||
// Ensure the two match
|
||||
Assert.AreEqual(_reverseResponse, reverseReserialized);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void SerializesAndDeserializesForward()
|
||||
{
|
||||
// First, deserialize the example response
|
||||
ForwardGeocodeResponse forwardResp = _geocoder.Deserialize<ForwardGeocodeResponse>(_forwardResponse);
|
||||
|
||||
// Then deserialize it back to a string.
|
||||
string forwardReserialized = JsonConvert.SerializeObject(forwardResp, JsonConverters.Converters);
|
||||
|
||||
// Ensure the two match
|
||||
Assert.AreEqual(_forwardResponse, forwardReserialized);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e32c94248ffc8435ea3385aa22e5b67e
|
||||
timeCreated: 1498231547
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="LonLatToVector2dConverterTest.cs" company="Mapbox">
|
||||
// Copyright (c) 2016 Mapbox. All rights reserved.
|
||||
// </copyright>
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
namespace Mapbox.MapboxSdkCs.UnitTest
|
||||
{
|
||||
|
||||
using Mapbox.Json;
|
||||
using Mapbox.Utils;
|
||||
using Mapbox.Utils.JsonConverters;
|
||||
using NUnit.Framework;
|
||||
|
||||
|
||||
[TestFixture]
|
||||
internal class LonLatToVector2dConverterTest
|
||||
{
|
||||
|
||||
// Mapbox API returns longitude,latitude
|
||||
private string _lonLatStr = "[-77.0295,38.9165]";
|
||||
|
||||
// In Unity, x = latitude, y = longitude
|
||||
private Vector2d _latLonObject = new Vector2d(y: -77.0295, x: 38.9165);
|
||||
|
||||
|
||||
[Test]
|
||||
public void Deserialize()
|
||||
{
|
||||
Vector2d deserializedLonLat = JsonConvert.DeserializeObject<Vector2d>(_lonLatStr, JsonConverters.Converters);
|
||||
Assert.AreEqual(_latLonObject.ToString(), deserializedLonLat.ToString());
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void Serialize()
|
||||
{
|
||||
string serializedLonLat = JsonConvert.SerializeObject(_latLonObject, JsonConverters.Converters);
|
||||
Assert.AreEqual(_lonLatStr, serializedLonLat);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 40c0342b3b48a4e0c86d1dab20a71c57
|
||||
timeCreated: 1498231546
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,212 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="MapTest.cs" company="Mapbox">
|
||||
// Copyright (c) 2016 Mapbox. All rights reserved.
|
||||
// </copyright>
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
// TODO: figure out how run tests outside of Unity with .NET framework, something like '#if !UNITY'
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
|
||||
namespace Mapbox.MapboxSdkCs.UnitTest
|
||||
{
|
||||
|
||||
using Mapbox.Map;
|
||||
using Mapbox.Platform;
|
||||
using Mapbox.Utils;
|
||||
using NUnit.Framework;
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
using System.Collections;
|
||||
using UnityEngine.TestTools;
|
||||
#endif
|
||||
|
||||
|
||||
[TestFixture]
|
||||
internal class MapTest
|
||||
{
|
||||
|
||||
private FileSource _fs;
|
||||
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
_fs = new FileSource(Unity.MapboxAccess.Instance.Configuration.GetMapsSkuToken, Unity.MapboxAccess.Instance.Configuration.AccessToken);
|
||||
#else
|
||||
// when run outside of Unity FileSource gets the access token from environment variable 'MAPBOX_ACCESS_TOKEN'
|
||||
_fs = new FileSource();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
[UnityTest]
|
||||
public IEnumerator World()
|
||||
#else
|
||||
[Test]
|
||||
public void World()
|
||||
#endif
|
||||
{
|
||||
var map = new Map<VectorTile>(_fs);
|
||||
|
||||
map.Vector2dBounds = Vector2dBounds.World();
|
||||
map.Zoom = 3;
|
||||
|
||||
var mapObserver = new Utils.VectorMapObserver();
|
||||
map.Subscribe(mapObserver);
|
||||
map.Update();
|
||||
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
IEnumerator enumerator = _fs.WaitForAllRequests();
|
||||
while (enumerator.MoveNext()) { yield return null; }
|
||||
#else
|
||||
_fs.WaitForAllRequests();
|
||||
#endif
|
||||
|
||||
Assert.AreEqual(64, mapObserver.Tiles.Count);
|
||||
|
||||
map.Unsubscribe(mapObserver);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
[UnityTest]
|
||||
public IEnumerator RasterHelsinki()
|
||||
#else
|
||||
[Test]
|
||||
public void RasterHelsinki()
|
||||
#endif
|
||||
{
|
||||
var map = new Map<RasterTile>(_fs);
|
||||
|
||||
map.Center = new Vector2d(60.163200, 24.937700);
|
||||
map.Zoom = 13;
|
||||
|
||||
var mapObserver = new Utils.RasterMapObserver();
|
||||
map.Subscribe(mapObserver);
|
||||
map.Update();
|
||||
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
IEnumerator enumerator = _fs.WaitForAllRequests();
|
||||
while (enumerator.MoveNext()) { yield return null; }
|
||||
#else
|
||||
_fs.WaitForAllRequests();
|
||||
#endif
|
||||
|
||||
Assert.AreEqual(1, mapObserver.Tiles.Count);
|
||||
Assert.IsNotNull(mapObserver.Tiles[0]);
|
||||
|
||||
map.Unsubscribe(mapObserver);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
[UnityTest]
|
||||
public IEnumerator ChangeTilesetId()
|
||||
#else
|
||||
[Test]
|
||||
public void ChangeTilesetId()
|
||||
#endif
|
||||
{
|
||||
var map = new Map<ClassicRasterTile>(_fs);
|
||||
|
||||
var mapObserver = new Utils.ClassicRasterMapObserver();
|
||||
map.Subscribe(mapObserver);
|
||||
|
||||
map.Center = new Vector2d(60.163200, 24.937700);
|
||||
map.Zoom = 13;
|
||||
map.TilesetId = "invalid";
|
||||
map.Update();
|
||||
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
IEnumerator enumerator = _fs.WaitForAllRequests();
|
||||
while (enumerator.MoveNext()) { yield return null; }
|
||||
#else
|
||||
_fs.WaitForAllRequests();
|
||||
#endif
|
||||
|
||||
Assert.AreEqual(0, mapObserver.Tiles.Count);
|
||||
|
||||
map.TilesetId = "mapbox.terrain-rgb";
|
||||
map.Update();
|
||||
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
enumerator = _fs.WaitForAllRequests();
|
||||
while (enumerator.MoveNext()) { yield return null; }
|
||||
#else
|
||||
_fs.WaitForAllRequests();
|
||||
#endif
|
||||
|
||||
Assert.AreEqual(1, mapObserver.Tiles.Count);
|
||||
|
||||
map.TilesetId = null; // Use default tileset ID.
|
||||
map.Update();
|
||||
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
enumerator = _fs.WaitForAllRequests();
|
||||
while (enumerator.MoveNext()) { yield return null; }
|
||||
#else
|
||||
_fs.WaitForAllRequests();
|
||||
#endif
|
||||
|
||||
Assert.AreEqual(2, mapObserver.Tiles.Count);
|
||||
|
||||
// Should have fetched tiles from different tileset IDs.
|
||||
Assert.AreNotEqual(mapObserver.Tiles[0], mapObserver.Tiles[1]);
|
||||
|
||||
map.Unsubscribe(mapObserver);
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Test]
|
||||
public void SetVector2dBoundsZoom()
|
||||
{
|
||||
var map1 = new Map<RasterTile>(_fs);
|
||||
var map2 = new Map<RasterTile>(_fs);
|
||||
|
||||
map1.Zoom = 3;
|
||||
map1.Vector2dBounds = Vector2dBounds.World();
|
||||
|
||||
map2.SetVector2dBoundsZoom(Vector2dBounds.World(), 3);
|
||||
|
||||
Assert.AreEqual(map1.Tiles.Count, map2.Tiles.Count);
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Test]
|
||||
public void TileMax()
|
||||
{
|
||||
var map = new Map<RasterTile>(_fs);
|
||||
|
||||
map.SetVector2dBoundsZoom(Vector2dBounds.World(), 2);
|
||||
map.Update();
|
||||
Assert.Less(map.Tiles.Count, Map<RasterTile>.TileMax);
|
||||
|
||||
// Should stay the same, ignore requests.
|
||||
map.SetVector2dBoundsZoom(Vector2dBounds.World(), 5);
|
||||
map.Update();
|
||||
Assert.AreEqual(16, map.Tiles.Count);
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Test]
|
||||
public void Zoom()
|
||||
{
|
||||
var map = new Map<RasterTile>(_fs);
|
||||
|
||||
map.Zoom = 50;
|
||||
Assert.AreEqual(20, map.Zoom);
|
||||
|
||||
map.Zoom = -50;
|
||||
Assert.AreEqual(0, map.Zoom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 02c5791defbcf4d1ebf04166ef29344b
|
||||
timeCreated: 1498231546
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,693 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="MapMatcherTest.cs" company="Mapbox">
|
||||
// Copyright (c) 2017 Mapbox. All rights reserved.
|
||||
// </copyright>
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
|
||||
// TODO: figure out how run tests outside of Unity with .NET framework, something like '#if !UNITY'
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
|
||||
namespace Mapbox.MapboxSdkCs.UnitTest
|
||||
{
|
||||
|
||||
|
||||
using Mapbox.Platform;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine.TestTools;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Mapbox.MapMatching;
|
||||
using Mapbox.Utils;
|
||||
|
||||
|
||||
|
||||
[TestFixture]
|
||||
internal class MapMatcherTest
|
||||
{
|
||||
|
||||
private const string _url = "https://api.mapbox.com/matching/v5/mapbox/driving/-117.1728265285492,32.71204416018209;-117.17288821935652,32.712258556224;-117.17293113470076,32.712443613445814;-117.17292040586472,32.71256999376694;-117.17298477888109,32.712603845608285;-117.17314302921294,32.71259933203019;-117.17334151268004,32.71254065549407";
|
||||
private FileSource _fs;
|
||||
private int _timeout = 10;
|
||||
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_fs = new FileSource(Unity.MapboxAccess.Instance.Configuration.GetMapsSkuToken, Unity.MapboxAccess.Instance.Configuration.AccessToken);
|
||||
_timeout = Unity.MapboxAccess.Instance.Configuration.DefaultTimeout;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator AsSimpleAsPossible()
|
||||
{
|
||||
|
||||
MapMatchingResource resource = new MapMatchingResource();
|
||||
resource.Coordinates = new Vector2d[]
|
||||
{
|
||||
new Vector2d(32.71204416018209,-117.1728265285492),
|
||||
new Vector2d(32.712258556224,-117.17288821935652),
|
||||
new Vector2d(32.712443613445814,-117.17293113470076),
|
||||
new Vector2d(32.71256999376694,-117.17292040586472),
|
||||
new Vector2d(32.712603845608285,-117.17298477888109),
|
||||
new Vector2d(32.71259933203019,-117.17314302921294),
|
||||
new Vector2d(32.71254065549407,-117.17334151268004),
|
||||
};
|
||||
|
||||
MapMatcher mapMatcher = new MapMatcher(_fs, _timeout);
|
||||
MapMatchingResponse matchingResponse = null;
|
||||
mapMatcher.Match(
|
||||
resource,
|
||||
(MapMatchingResponse response) =>
|
||||
{
|
||||
matchingResponse = response;
|
||||
}
|
||||
);
|
||||
|
||||
IEnumerator enumerator = _fs.WaitForAllRequests();
|
||||
while (enumerator.MoveNext()) { yield return null; }
|
||||
|
||||
commonBasicResponseAsserts(matchingResponse);
|
||||
|
||||
Assert.AreEqual(7, matchingResponse.Tracepoints.Length, "Wrong number of tracepoints");
|
||||
Assert.AreEqual(3, matchingResponse.Tracepoints[3].WaypointIndex, "Wrong WaypointIndex");
|
||||
|
||||
Assert.AreEqual(1, matchingResponse.Matchings.Length, "Wrong number of matchings");
|
||||
Assert.That(matchingResponse.Matchings[0].Weight > 0 && matchingResponse.Matchings[0].Weight < 100, "Wrong Weight: {0}", matchingResponse.Matchings[0].Weight);
|
||||
Assert.AreEqual("routability", matchingResponse.Matchings[0].WeightName, "Wrong WeightName");
|
||||
Assert.AreEqual(6, matchingResponse.Matchings[0].Legs.Count, "Wrong number of legs");
|
||||
Assert.AreEqual(8, matchingResponse.Matchings[0].Geometry.Count, "Wrong number of vertices in geometry");
|
||||
}
|
||||
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator Profiles()
|
||||
{
|
||||
//walking
|
||||
IEnumerator<MapMatchingResponse> enumerator = profile(Profile.MapboxWalking);
|
||||
MapMatchingResponse matchingResponse = null;
|
||||
while (enumerator.MoveNext())
|
||||
{
|
||||
matchingResponse = enumerator.Current;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
Assert.GreaterOrEqual(matchingResponse.Matchings[0].Duration, 300, "'mapbox/walking' duration [{0}] less than expected", matchingResponse.Matchings[0].Duration);
|
||||
|
||||
//cycling
|
||||
enumerator = profile(Profile.MapboxCycling);
|
||||
matchingResponse = null;
|
||||
while (enumerator.MoveNext())
|
||||
{
|
||||
matchingResponse = enumerator.Current;
|
||||
yield return null;
|
||||
}
|
||||
Assert.GreaterOrEqual(matchingResponse.Matchings[0].Duration, 100, "'mapbox/cycling' duration less than expected");
|
||||
|
||||
//driving traffic
|
||||
enumerator = profile(Profile.MapboxDrivingTraffic);
|
||||
matchingResponse = null;
|
||||
while (enumerator.MoveNext())
|
||||
{
|
||||
matchingResponse = enumerator.Current;
|
||||
yield return null;
|
||||
}
|
||||
Assert.GreaterOrEqual(matchingResponse.Matchings[0].Duration, 100, "'driving-traffic' duration less than expected");
|
||||
|
||||
//driving
|
||||
enumerator = profile(Profile.MapboxDriving);
|
||||
matchingResponse = null;
|
||||
while (enumerator.MoveNext())
|
||||
{
|
||||
matchingResponse = enumerator.Current;
|
||||
yield return null;
|
||||
}
|
||||
Assert.GreaterOrEqual(matchingResponse.Matchings[0].Duration, 100, "'driving' duration less than expected");
|
||||
}
|
||||
|
||||
|
||||
private IEnumerator<MapMatchingResponse> profile(Profile profile)
|
||||
{
|
||||
MapMatchingResource resource = new MapMatchingResource();
|
||||
resource.Coordinates = new Vector2d[]
|
||||
{
|
||||
new Vector2d(48.27275388447381,16.34687304496765),
|
||||
new Vector2d(48.271925526874405,16.344040632247925),
|
||||
new Vector2d(48.27190410365491,16.343783140182495),
|
||||
new Vector2d(48.27198265541583,16.343053579330444),
|
||||
new Vector2d(48.27217546377159,16.342334747314453),
|
||||
new Vector2d(48.27251823238551,16.341615915298462),
|
||||
new Vector2d(48.27223259203358,16.3416588306427),
|
||||
new Vector2d(48.27138280254541,16.34069323539734),
|
||||
new Vector2d(48.27114714413402,16.34015679359436 )
|
||||
};
|
||||
resource.Profile = profile;
|
||||
|
||||
MapMatcher mapMatcher = new MapMatcher(_fs, _timeout);
|
||||
MapMatchingResponse matchingResponse = null;
|
||||
mapMatcher.Match(
|
||||
resource,
|
||||
(MapMatchingResponse response) =>
|
||||
{
|
||||
matchingResponse = response;
|
||||
}
|
||||
);
|
||||
|
||||
IEnumerator enumerator = _fs.WaitForAllRequests();
|
||||
while (enumerator.MoveNext()) { yield return null; }
|
||||
|
||||
commonBasicResponseAsserts(matchingResponse);
|
||||
|
||||
yield return matchingResponse;
|
||||
}
|
||||
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator NoSegment()
|
||||
{
|
||||
|
||||
MapMatchingResource resource = new MapMatchingResource();
|
||||
resource.Coordinates = new Vector2d[]
|
||||
{
|
||||
new Vector2d(48.28585,16.55267),
|
||||
new Vector2d(48.28933,16.55211)
|
||||
};
|
||||
|
||||
MapMatcher mapMatcher = new MapMatcher(_fs, _timeout);
|
||||
MapMatchingResponse matchingResponse = null;
|
||||
mapMatcher.Match(
|
||||
resource,
|
||||
(MapMatchingResponse response) =>
|
||||
{
|
||||
matchingResponse = response;
|
||||
}
|
||||
);
|
||||
|
||||
IEnumerator enumerator = _fs.WaitForAllRequests();
|
||||
while (enumerator.MoveNext()) { yield return null; }
|
||||
|
||||
Assert.IsNotNull(matchingResponse, "Matching response is NULL");
|
||||
Assert.IsFalse(matchingResponse.HasRequestError, "Error during web request");
|
||||
Assert.AreEqual("NoSegment", matchingResponse.Code, "Matching code != 'NoSegment'");
|
||||
Assert.AreEqual("Could not find a matching segment for input coordinates", matchingResponse.Message, "Message not as expected");
|
||||
|
||||
Assert.IsNull(matchingResponse.Tracepoints, "Tracepoints are not NULL");
|
||||
|
||||
Assert.IsNotNull(matchingResponse.Matchings, "Matchings are NULL");
|
||||
Assert.AreEqual(0, matchingResponse.Matchings.Length, "Wrong number of matchings");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator Radiuses()
|
||||
{
|
||||
|
||||
MapMatchingResource resource = new MapMatchingResource();
|
||||
resource.Coordinates = new Vector2d[]
|
||||
{
|
||||
new Vector2d(48.28585,16.55267),
|
||||
new Vector2d(48.28933,16.55211)
|
||||
};
|
||||
resource.Radiuses = new uint[] { 50, 50 };
|
||||
|
||||
MapMatcher mapMatcher = new MapMatcher(_fs, _timeout);
|
||||
MapMatchingResponse matchingResponse = null;
|
||||
mapMatcher.Match(
|
||||
resource,
|
||||
(MapMatchingResponse response) =>
|
||||
{
|
||||
matchingResponse = response;
|
||||
}
|
||||
);
|
||||
|
||||
IEnumerator enumerator = _fs.WaitForAllRequests();
|
||||
while (enumerator.MoveNext()) { yield return null; }
|
||||
|
||||
commonBasicResponseAsserts(matchingResponse);
|
||||
|
||||
Assert.AreEqual(2, matchingResponse.Tracepoints.Length, "Wrong number of tracepoints");
|
||||
Assert.AreEqual(1, matchingResponse.Tracepoints[1].WaypointIndex, "Wrong WaypointIndex");
|
||||
|
||||
Assert.AreEqual(1, matchingResponse.Matchings.Length, "Wrong number of matchings");
|
||||
Assert.GreaterOrEqual(matchingResponse.Matchings[0].Weight, 22.5, "Wrong Weight");
|
||||
Assert.AreEqual("routability", matchingResponse.Matchings[0].WeightName, "Wrong WeightName");
|
||||
Assert.AreEqual(1, matchingResponse.Matchings[0].Legs.Count, "Wrong number of legs");
|
||||
Assert.AreEqual(2, matchingResponse.Matchings[0].Geometry.Count, "Wrong number of vertices in geometry");
|
||||
}
|
||||
|
||||
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator AlternativesWithSteps()
|
||||
{
|
||||
|
||||
MapMatchingResource resource = new MapMatchingResource();
|
||||
resource.Coordinates = new Vector2d[]
|
||||
{
|
||||
new Vector2d(48.31331,16.49062),
|
||||
new Vector2d(48.31638,16.49243)
|
||||
};
|
||||
resource.Radiuses = new uint[] { 10, 30 };
|
||||
resource.Steps = true;
|
||||
|
||||
MapMatcher mapMatcher = new MapMatcher(_fs, _timeout);
|
||||
MapMatchingResponse matchingResponse = null;
|
||||
mapMatcher.Match(
|
||||
resource,
|
||||
(MapMatchingResponse response) =>
|
||||
{
|
||||
matchingResponse = response;
|
||||
}
|
||||
);
|
||||
|
||||
IEnumerator enumerator = _fs.WaitForAllRequests();
|
||||
while (enumerator.MoveNext()) { yield return null; }
|
||||
|
||||
commonBasicResponseAsserts(matchingResponse);
|
||||
|
||||
Assert.AreEqual(2, matchingResponse.Tracepoints.Length, "Wrong number of tracepoints");
|
||||
Assert.GreaterOrEqual(2, matchingResponse.Tracepoints[0].AlternativesCount, "Wrong 'AlternativesCount' for Tracepoint[0]");
|
||||
Assert.GreaterOrEqual(19, matchingResponse.Tracepoints[1].AlternativesCount, "Wrong 'AlternativesCount' for Tracepoint[1]");
|
||||
|
||||
Assert.IsNotNull(matchingResponse.Matchings[0].Legs[0].Steps, "Steps are NULL");
|
||||
Assert.AreEqual(2, matchingResponse.Matchings[0].Legs[0].Steps.Count, "Wrong number of steps");
|
||||
Assert.IsNotNull(matchingResponse.Matchings[0].Legs[0].Steps[0].Intersections, "Intersections are NULL");
|
||||
Assert.AreEqual(3, matchingResponse.Matchings[0].Legs[0].Steps[0].Intersections.Count, "Wrong number of intersections");
|
||||
}
|
||||
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator OverviewSimplified()
|
||||
{
|
||||
MapMatchingResource resource = new MapMatchingResource();
|
||||
resource.Coordinates = new Vector2d[]
|
||||
{
|
||||
new Vector2d(48.28514194095631,16.32358074188232),
|
||||
new Vector2d(48.28528472524657,16.324278116226196),
|
||||
new Vector2d(48.28502771323672,16.325350999832153),
|
||||
new Vector2d(48.284999156266906,16.326016187667847),
|
||||
new Vector2d(48.284870649705155,16.326134204864502),
|
||||
new Vector2d(48.28467074996644,16.32594108581543),
|
||||
new Vector2d(48.28467074996644,16.325050592422485),
|
||||
new Vector2d(48.28459935701301,16.324610710144043)
|
||||
|
||||
};
|
||||
resource.Overview = Overview.Simplified;
|
||||
|
||||
MapMatcher mapMatcher = new MapMatcher(_fs, _timeout);
|
||||
MapMatchingResponse matchingResponse = null;
|
||||
mapMatcher.Match(
|
||||
resource,
|
||||
(MapMatchingResponse response) =>
|
||||
{
|
||||
matchingResponse = response;
|
||||
}
|
||||
);
|
||||
|
||||
IEnumerator enumerator = _fs.WaitForAllRequests();
|
||||
while (enumerator.MoveNext()) { yield return null; }
|
||||
|
||||
commonBasicResponseAsserts(matchingResponse);
|
||||
|
||||
Assert.GreaterOrEqual(matchingResponse.Matchings[0].Geometry.Count, 14, "Wrong number of vertices in match geometry");
|
||||
}
|
||||
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator OverviewFull()
|
||||
{
|
||||
MapMatchingResource resource = new MapMatchingResource();
|
||||
resource.Coordinates = new Vector2d[]
|
||||
{
|
||||
new Vector2d(48.28514194095631,16.32358074188232),
|
||||
new Vector2d(48.28528472524657,16.324278116226196),
|
||||
new Vector2d(48.28502771323672,16.325350999832153),
|
||||
new Vector2d(48.284999156266906,16.326016187667847),
|
||||
new Vector2d(48.284870649705155,16.326134204864502),
|
||||
new Vector2d(48.28467074996644,16.32594108581543),
|
||||
new Vector2d(48.28467074996644,16.325050592422485),
|
||||
new Vector2d(48.28459935701301,16.324610710144043)
|
||||
|
||||
};
|
||||
resource.Overview = Overview.Full;
|
||||
|
||||
MapMatcher mapMatcher = new MapMatcher(_fs, _timeout);
|
||||
MapMatchingResponse matchingResponse = null;
|
||||
mapMatcher.Match(
|
||||
resource,
|
||||
(MapMatchingResponse response) =>
|
||||
{
|
||||
matchingResponse = response;
|
||||
}
|
||||
);
|
||||
|
||||
IEnumerator enumerator = _fs.WaitForAllRequests();
|
||||
while (enumerator.MoveNext()) { yield return null; }
|
||||
|
||||
commonBasicResponseAsserts(matchingResponse);
|
||||
|
||||
Assert.GreaterOrEqual(matchingResponse.Matchings[0].Geometry.Count, 20, "Wrong number of vertices in match geometry");
|
||||
}
|
||||
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator Timestamps()
|
||||
{
|
||||
|
||||
MapMatchingResource resource = new MapMatchingResource();
|
||||
resource.Coordinates = new Vector2d[]
|
||||
{
|
||||
new Vector2d(48.1974721043879,16.36202484369278),
|
||||
new Vector2d(48.197922645046546,16.36285901069641)
|
||||
};
|
||||
resource.Timestamps = new long[]
|
||||
{
|
||||
946684800,
|
||||
946684980
|
||||
};
|
||||
|
||||
MapMatcher mapMatcher = new MapMatcher(_fs, _timeout);
|
||||
MapMatchingResponse matchingResponse = null;
|
||||
mapMatcher.Match(
|
||||
resource,
|
||||
(MapMatchingResponse response) =>
|
||||
{
|
||||
matchingResponse = response;
|
||||
}
|
||||
);
|
||||
|
||||
IEnumerator enumerator = _fs.WaitForAllRequests();
|
||||
while (enumerator.MoveNext()) { yield return null; }
|
||||
|
||||
commonBasicResponseAsserts(matchingResponse);
|
||||
}
|
||||
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator Annotation()
|
||||
{
|
||||
|
||||
MapMatchingResource resource = new MapMatchingResource();
|
||||
resource.Coordinates = new Vector2d[]
|
||||
{
|
||||
new Vector2d(48.1974721043879,16.36202484369278),
|
||||
new Vector2d(48.197922645046546,16.36285901069641)
|
||||
};
|
||||
//need to pass 'Overview.Full' to get 'Congestion'
|
||||
resource.Overview = Overview.Full;
|
||||
resource.Annotations = Annotations.Distance | Annotations.Duration | Annotations.Speed | Annotations.Congestion;
|
||||
|
||||
MapMatcher mapMatcher = new MapMatcher(_fs, _timeout);
|
||||
MapMatchingResponse matchingResponse = null;
|
||||
mapMatcher.Match(
|
||||
resource,
|
||||
(MapMatchingResponse response) =>
|
||||
{
|
||||
matchingResponse = response;
|
||||
}
|
||||
);
|
||||
|
||||
IEnumerator enumerator = _fs.WaitForAllRequests();
|
||||
while (enumerator.MoveNext()) { yield return null; }
|
||||
|
||||
commonBasicResponseAsserts(matchingResponse);
|
||||
|
||||
Directions.Leg leg = matchingResponse.Matchings[0].Legs[0];
|
||||
Assert.IsNotNull(leg.Annotation, "Annotation is NULL");
|
||||
Assert.IsNotNull(leg.Annotation.Distance, "Distance is NULL");
|
||||
Assert.IsNotNull(leg.Annotation.Duration, "Duration is NULL");
|
||||
Assert.IsNotNull(leg.Annotation.Speed, "Speed is NULL");
|
||||
Assert.IsNotNull(leg.Annotation.Congestion, "Congestion is NULL");
|
||||
|
||||
Assert.GreaterOrEqual(leg.Annotation.Distance[1], 42, "Annotation has wrong distnce");
|
||||
}
|
||||
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator Tidy()
|
||||
{
|
||||
|
||||
MapMatchingResource resource = new MapMatchingResource();
|
||||
resource.Coordinates = new Vector2d[]
|
||||
{
|
||||
new Vector2d(48.187092481625704,16.312205493450165),
|
||||
new Vector2d(48.187083540475875,16.312505900859833),
|
||||
new Vector2d(48.18709426985548,16.312503218650818),
|
||||
new Vector2d(48.18707281109407,16.312503218650818),
|
||||
new Vector2d(48.18709605808517,16.312524676322937),
|
||||
new Vector2d(48.18707817578527,16.312530040740967),
|
||||
new Vector2d(48.1870656581716,16.312524676322937),
|
||||
new Vector2d(48.187079964015524,16.312484443187714),
|
||||
new Vector2d(48.18704598762968,16.312776803970337)
|
||||
};
|
||||
resource.Tidy = true;
|
||||
|
||||
MapMatcher mapMatcher = new MapMatcher(_fs, _timeout);
|
||||
MapMatchingResponse matchingResponse = null;
|
||||
mapMatcher.Match(
|
||||
resource,
|
||||
(MapMatchingResponse response) =>
|
||||
{
|
||||
matchingResponse = response;
|
||||
}
|
||||
);
|
||||
|
||||
IEnumerator enumerator = _fs.WaitForAllRequests();
|
||||
while (enumerator.MoveNext()) { yield return null; }
|
||||
|
||||
commonBasicResponseAsserts(matchingResponse);
|
||||
|
||||
Tracepoint[] tps = matchingResponse.Tracepoints;
|
||||
//tracepoints removed by 'Tidy' are set to 'null'
|
||||
Assert.IsNotNull(tps, "Tracepoints is NULL");
|
||||
Assert.IsNull(tps[6], "Tracepoints is NULL");
|
||||
Assert.IsNull(tps[7], "Tracepoints is NULL");
|
||||
}
|
||||
|
||||
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator LanguageEnglish()
|
||||
{
|
||||
|
||||
MapMatchingResource resource = new MapMatchingResource();
|
||||
resource.Coordinates = new Vector2d[]
|
||||
{
|
||||
new Vector2d(48.1974721043879,16.36202484369278),
|
||||
new Vector2d(48.197922645046546,16.36285901069641)
|
||||
};
|
||||
//set Steps to true to get turn-by-turn-instructions
|
||||
resource.Steps = true;
|
||||
//no language parameter needed: English is default
|
||||
|
||||
MapMatcher mapMatcher = new MapMatcher(_fs, _timeout);
|
||||
MapMatchingResponse matchingResponse = null;
|
||||
mapMatcher.Match(
|
||||
resource,
|
||||
(MapMatchingResponse response) =>
|
||||
{
|
||||
matchingResponse = response;
|
||||
}
|
||||
);
|
||||
|
||||
IEnumerator enumerator = _fs.WaitForAllRequests();
|
||||
while (enumerator.MoveNext()) { yield return null; }
|
||||
|
||||
commonBasicResponseAsserts(matchingResponse);
|
||||
|
||||
Directions.Step step0 = matchingResponse.Matchings[0].Legs[0].Steps[0];
|
||||
Directions.Step step1 = matchingResponse.Matchings[0].Legs[0].Steps[1];
|
||||
Assert.AreEqual("Head northeast on Rechte Wienzeile (B1)", step0.Maneuver.Instruction, "Step[0]:Instruction not as expected");
|
||||
Assert.AreEqual("You have arrived at your destination", step1.Maneuver.Instruction, "Step[1]:Instruction not as expected");
|
||||
}
|
||||
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator LanguageGerman()
|
||||
{
|
||||
|
||||
MapMatchingResource resource = new MapMatchingResource();
|
||||
resource.Coordinates = new Vector2d[]
|
||||
{
|
||||
new Vector2d(48.1974721043879,16.36202484369278),
|
||||
new Vector2d(48.197922645046546,16.36285901069641)
|
||||
};
|
||||
//set Steps to true to get turn-by-turn-instructions
|
||||
resource.Steps = true;
|
||||
resource.Language = InstructionLanguages.German;
|
||||
|
||||
MapMatcher mapMatcher = new MapMatcher(_fs, _timeout);
|
||||
MapMatchingResponse matchingResponse = null;
|
||||
mapMatcher.Match(
|
||||
resource,
|
||||
(MapMatchingResponse response) =>
|
||||
{
|
||||
matchingResponse = response;
|
||||
}
|
||||
);
|
||||
|
||||
IEnumerator enumerator = _fs.WaitForAllRequests();
|
||||
while (enumerator.MoveNext()) { yield return null; }
|
||||
|
||||
commonBasicResponseAsserts(matchingResponse);
|
||||
|
||||
Directions.Step step0 = matchingResponse.Matchings[0].Legs[0].Steps[0];
|
||||
Directions.Step step1 = matchingResponse.Matchings[0].Legs[0].Steps[1];
|
||||
Assert.AreEqual("Fahren Sie Richtung Nordosten auf Rechte Wienzeile (B1)", step0.Maneuver.Instruction, "Step[0]:Instruction not as expected");
|
||||
Assert.AreEqual("Sie haben Ihr Ziel erreicht", step1.Maneuver.Instruction, "Step[1]:Instruction not as expected");
|
||||
}
|
||||
|
||||
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator AllParameters()
|
||||
{
|
||||
|
||||
MapMatchingResource resource = new MapMatchingResource();
|
||||
resource.Profile = Profile.MapboxWalking;
|
||||
resource.Geometries = Geometries.Polyline6;
|
||||
resource.Coordinates = new Vector2d[]
|
||||
{
|
||||
new Vector2d(48.28585,16.55267),
|
||||
new Vector2d(48.28933,16.55211)
|
||||
};
|
||||
resource.Timestamps = new long[]
|
||||
{
|
||||
946684800,
|
||||
946684980
|
||||
};
|
||||
resource.Radiuses = new uint[] { 50, 50 };
|
||||
//set Steps to true to get turn-by-turn-instructions
|
||||
resource.Steps = true;
|
||||
//need to pass 'Overview.Full' to get 'Congestion'
|
||||
resource.Overview = Overview.Full;
|
||||
resource.Annotations = Annotations.Distance | Annotations.Duration | Annotations.Speed | Annotations.Congestion;
|
||||
resource.Tidy = true;
|
||||
resource.Language = InstructionLanguages.German;
|
||||
|
||||
|
||||
MapMatcher mapMatcher = new MapMatcher(_fs, _timeout);
|
||||
MapMatchingResponse matchingResponse = null;
|
||||
mapMatcher.Match(
|
||||
resource,
|
||||
(MapMatchingResponse response) =>
|
||||
{
|
||||
matchingResponse = response;
|
||||
}
|
||||
);
|
||||
|
||||
IEnumerator enumerator = _fs.WaitForAllRequests();
|
||||
while (enumerator.MoveNext()) { yield return null; }
|
||||
|
||||
commonBasicResponseAsserts(matchingResponse);
|
||||
|
||||
Directions.Leg leg = matchingResponse.Matchings[0].Legs[0];
|
||||
Assert.IsNotNull(leg.Annotation, "Annotation is NULL");
|
||||
Assert.IsNotNull(leg.Annotation.Distance, "Distance is NULL");
|
||||
Assert.IsNotNull(leg.Annotation.Duration, "Duration is NULL");
|
||||
Assert.IsNotNull(leg.Annotation.Speed, "Speed is NULL");
|
||||
Assert.IsNotNull(leg.Annotation.Congestion, "Congestion is NULL");
|
||||
|
||||
Directions.Step step1 = matchingResponse.Matchings[0].Legs[0].Steps[1];
|
||||
Assert.IsTrue(step1.Maneuver.Instruction.Contains("Sie haben Ihr Ziel erreicht"), "Step[1]:Instruction not as expected");
|
||||
|
||||
}
|
||||
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator CoordinatesNull()
|
||||
{
|
||||
|
||||
MapMatchingResource resource = new MapMatchingResource();
|
||||
Assert.Throws(
|
||||
typeof(System.Exception)
|
||||
, () => resource.Coordinates = null
|
||||
, "MapMatchingResource did not throw when setting null coordinates"
|
||||
);
|
||||
|
||||
yield return null;
|
||||
|
||||
|
||||
MapMatcher mapMatcher = new MapMatcher(_fs, _timeout);
|
||||
MapMatchingResponse matchingResponse = null;
|
||||
|
||||
Assert.Throws(
|
||||
typeof(System.Exception)
|
||||
, () =>
|
||||
{
|
||||
mapMatcher.Match(
|
||||
resource,
|
||||
(MapMatchingResponse response) =>
|
||||
{
|
||||
matchingResponse = response;
|
||||
}
|
||||
);
|
||||
}
|
||||
, "MapMatcher.Match did not throw with null coordinates"
|
||||
);
|
||||
|
||||
IEnumerator enumerator = _fs.WaitForAllRequests();
|
||||
while (enumerator.MoveNext()) { yield return null; }
|
||||
|
||||
Assert.IsNull(matchingResponse, "Matching response was expected to be null");
|
||||
}
|
||||
|
||||
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator InvalidCoordinate()
|
||||
{
|
||||
|
||||
MapMatchingResource resource = new MapMatchingResource();
|
||||
resource.Coordinates = new Vector2d[]
|
||||
{
|
||||
new Vector2d(-117.1728265285492, 32.71204416018209),
|
||||
new Vector2d(-117.17288821935652,32.712258556224),
|
||||
};
|
||||
|
||||
MapMatcher mapMatcher = new MapMatcher(_fs, _timeout);
|
||||
MapMatchingResponse matchingResponse = null;
|
||||
mapMatcher.Match(
|
||||
resource,
|
||||
(MapMatchingResponse response) =>
|
||||
{
|
||||
matchingResponse = response;
|
||||
}
|
||||
);
|
||||
|
||||
IEnumerator enumerator = _fs.WaitForAllRequests();
|
||||
while (enumerator.MoveNext()) { yield return null; }
|
||||
Assert.IsNotNull(matchingResponse, "Matching response is NULL");
|
||||
Assert.IsTrue(matchingResponse.HasRequestError, "No web request error");
|
||||
Assert.IsTrue(matchingResponse.HasMatchingError, "No matching error");
|
||||
Assert.AreEqual("InvalidInput", matchingResponse.Code, "Matching code != 'InvalidInput'");
|
||||
Assert.IsNotNull(matchingResponse.Message, "Matching message is NULL");
|
||||
Assert.IsNotEmpty(matchingResponse.Message, "Matching message is empty");
|
||||
Assert.AreEqual("Coordinate is invalid: 32.71204,-117.17283", matchingResponse.Message, "Matching message not as expected");
|
||||
}
|
||||
|
||||
|
||||
private void commonBasicResponseAsserts(MapMatchingResponse matchingResponse)
|
||||
{
|
||||
Assert.IsNotNull(matchingResponse, "Matching response is NULL");
|
||||
Assert.IsFalse(matchingResponse.HasRequestError, "Error during web request");
|
||||
Assert.AreEqual("Ok", matchingResponse.Code, "Matching code != 'Ok'");
|
||||
Assert.IsFalse(matchingResponse.HasMatchingError, "Macthing error");
|
||||
|
||||
Assert.IsNotNull(matchingResponse.Tracepoints, "Tracepoints are NULL");
|
||||
Assert.GreaterOrEqual(matchingResponse.Tracepoints.Length, 2, "Less than 2 tracepoints");
|
||||
|
||||
Assert.IsNotNull(matchingResponse.Matchings, "Matchings are NULL");
|
||||
Assert.GreaterOrEqual(1, matchingResponse.Matchings.Length, "Less than 1 matchings");
|
||||
Assert.IsNotNull(matchingResponse.Matchings[0].Legs, "Legs are NULL");
|
||||
Assert.GreaterOrEqual(matchingResponse.Matchings[0].Legs.Count, 1, "1st match has no legs");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 59de4f0f699183d4ab19690a6b94c1a0
|
||||
timeCreated: 1508247612
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="PolylineToVector2dListConverterTest.cs" company="Mapbox">
|
||||
// Copyright (c) 2016 Mapbox. All rights reserved.
|
||||
// </copyright>
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
namespace Mapbox.MapboxSdkCs.UnitTest
|
||||
{
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Mapbox.Json;
|
||||
using Mapbox.Utils;
|
||||
using Mapbox.Utils.JsonConverters;
|
||||
using NUnit.Framework;
|
||||
|
||||
|
||||
[TestFixture]
|
||||
internal class PolylineToVector2dListConverterTest
|
||||
{
|
||||
|
||||
// (38.5, -120.2), (40.7, -120.95), (43.252, -126.453)
|
||||
private readonly List<Vector2d> _polyLineObj = new List<Vector2d>()
|
||||
{
|
||||
new Vector2d(38.5, -120.2),
|
||||
new Vector2d(40.7, -120.95),
|
||||
new Vector2d(43.252, -126.453)
|
||||
};
|
||||
|
||||
private string _polyLineString = "\"_p~iF~ps|U_ulLnnqC_mqNvxq`@\"";
|
||||
|
||||
|
||||
[Test]
|
||||
public void Deserialize()
|
||||
{
|
||||
List<Vector2d> deserializedLine = JsonConvert.DeserializeObject<List<Vector2d>>(_polyLineString, JsonConverters.Converters);
|
||||
Assert.AreEqual(_polyLineObj, deserializedLine);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void Serialize()
|
||||
{
|
||||
string serializedLine = JsonConvert.SerializeObject(_polyLineObj, JsonConverters.Converters);
|
||||
Assert.AreEqual(_polyLineString, serializedLine);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e1b862f6c5e734a409c075ec1bce13e1
|
||||
timeCreated: 1498231547
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,60 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="PolylineUtilsTest.cs" company="Mapbox">
|
||||
// Copyright (c) 2016 Mapbox. All rights reserved.
|
||||
// </copyright>
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
namespace Mapbox.MapboxSdkCs.UnitTest
|
||||
{
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Mapbox.Utils;
|
||||
using NUnit.Framework;
|
||||
|
||||
|
||||
/// <summary>Polyline utils test.</summary>
|
||||
[TestFixture]
|
||||
public class PolylineUtilsTest
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Tests the decode.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Sample values from https://developers.google.com/maps/documentation/utilities/polylinealgorithm.
|
||||
/// </remarks>
|
||||
[Test]
|
||||
public void TestDecode()
|
||||
{
|
||||
// _p~iF~ps|U_ulLnnqC_mqNvxq`@
|
||||
List<Vector2d> path = PolylineUtils.Decode(
|
||||
"_p~iF~ps|U_ulLnnqC_mqNvxq`@");
|
||||
|
||||
// (38.5, -120.2), (40.7, -120.95), (43.252, -126.453)
|
||||
Assert.AreEqual(-120.2, path[0].y);
|
||||
Assert.AreEqual(38.5, path[0].x);
|
||||
Assert.AreEqual(-120.95, path[1].y);
|
||||
Assert.AreEqual(40.7, path[1].x);
|
||||
Assert.AreEqual(-126.453, path[2].y);
|
||||
Assert.AreEqual(43.252, path[2].x);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>Tests the encode.</summary>
|
||||
[Test]
|
||||
public void TestEncode()
|
||||
{
|
||||
// (38.5, -120.2), (40.7, -120.95), (43.252, -126.453)
|
||||
var path = new List<Vector2d>();
|
||||
path.Add(new Vector2d(38.5, -120.2));
|
||||
path.Add(new Vector2d(40.7, -120.95));
|
||||
path.Add(new Vector2d(43.252, -126.453));
|
||||
|
||||
// _p~iF~ps|U_ulLnnqC_mqNvxq`@
|
||||
Assert.AreEqual("_p~iF~ps|U_ulLnnqC_mqNvxq`@", PolylineUtils.Encode(path));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fa0f5d050d73344bf85556235addd1b9
|
||||
timeCreated: 1498231547
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,70 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="ReverseGeocodeResourceTest.cs" company="Mapbox">
|
||||
// Copyright (c) 2016 Mapbox. All rights reserved.
|
||||
// </copyright>
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
namespace Mapbox.MapboxSdkCs.UnitTest
|
||||
{
|
||||
|
||||
using System;
|
||||
using Mapbox.Utils;
|
||||
using NUnit.Framework;
|
||||
|
||||
|
||||
[TestFixture]
|
||||
internal class ReverseGeocodeResourceTest
|
||||
{
|
||||
|
||||
private const string _baseUrl = "https://api.mapbox.com/geocoding/v5/mapbox.places/";
|
||||
private Vector2d _queryLocation = new Vector2d(10, 10);
|
||||
private string _expectedQueryString = "10.00000,10.00000";
|
||||
private Geocoding.ReverseGeocodeResource _reverseGeocodeResource;
|
||||
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_reverseGeocodeResource = new Geocoding.ReverseGeocodeResource(_queryLocation);
|
||||
}
|
||||
|
||||
public void BadType()
|
||||
{
|
||||
_reverseGeocodeResource.Types = new string[] { "fake" };
|
||||
}
|
||||
|
||||
public void BadTypeWithGoodType()
|
||||
{
|
||||
_reverseGeocodeResource.Types = new string[] { "place", "fake" };
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SetInvalidTypes()
|
||||
{
|
||||
Assert.Throws<Exception>(BadType);
|
||||
Assert.Throws<Exception>(BadTypeWithGoodType);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetUrl()
|
||||
{
|
||||
// With only constructor
|
||||
Assert.AreEqual(_baseUrl + _expectedQueryString + ".json", _reverseGeocodeResource.GetUrl());
|
||||
|
||||
// With one types
|
||||
_reverseGeocodeResource.Types = new string[] { "country" };
|
||||
Assert.AreEqual(_baseUrl + _expectedQueryString + ".json?types=country", _reverseGeocodeResource.GetUrl());
|
||||
|
||||
// With multiple types
|
||||
_reverseGeocodeResource.Types = new string[] { "country", "region" };
|
||||
// ToLower is need to make test pass on OSX
|
||||
Assert.AreEqual((_baseUrl + _expectedQueryString + ".json?types=country%2Cregion").ToLower(), _reverseGeocodeResource.GetUrl().ToLower());
|
||||
|
||||
// Set all to null
|
||||
_reverseGeocodeResource.Types = null;
|
||||
Assert.AreEqual(_baseUrl + _expectedQueryString + ".json", _reverseGeocodeResource.GetUrl());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7f39fa05cece94053b2bf5b0c31eb1da
|
||||
timeCreated: 1498231546
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,300 @@
|
||||
namespace Mapbox.MapboxSdkCs.UnitTest
|
||||
{
|
||||
using Mapbox.Map;
|
||||
using Mapbox.Platform.Cache;
|
||||
using Mapbox.Unity.Utilities;
|
||||
using Mapbox.Utils;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using ued = UnityEngine.Debug;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
|
||||
[TestFixture]
|
||||
internal class SQLiteCacheTest
|
||||
{
|
||||
|
||||
|
||||
private const string _dbName = "UNITTEST.db";
|
||||
// tileset names
|
||||
private const string TS_NO_OVERWRITE = "NoOverwrite";
|
||||
private const string TS_FORCE_OVERWRITE = "ForceOverwrite";
|
||||
private const string TS_CONCURRENT1 = "concurrent1";
|
||||
private const string TS_CONCURRENT2 = "concurrent2";
|
||||
private const string TS_CONCURRENT3 = "concurrent3";
|
||||
private const string TS_CONCURRENT4 = "concurrent4";
|
||||
private const string TS_PRUNE = "concurrent4";
|
||||
private const string TS_REINIT = "reinit";
|
||||
private string[] _allTilesetNames;
|
||||
private SQLiteCache _cache;
|
||||
private string _className;
|
||||
private HashSet<CanonicalTileId> _tileIds;
|
||||
// be careful when setting the 'maxTileCount' parameter. when setting too low unwanted pruning might happen.
|
||||
private uint _maxCacheTileCount = 6000;
|
||||
|
||||
|
||||
[OneTimeSetUp]
|
||||
public void Init()
|
||||
{
|
||||
_className = this.GetType().Name;
|
||||
|
||||
Runnable.EnableRunnableInEditor();
|
||||
|
||||
_allTilesetNames = new string[] {
|
||||
TS_NO_OVERWRITE
|
||||
, TS_FORCE_OVERWRITE
|
||||
, TS_CONCURRENT1
|
||||
, TS_CONCURRENT2
|
||||
, TS_CONCURRENT3
|
||||
, TS_CONCURRENT4
|
||||
, TS_PRUNE
|
||||
, TS_REINIT
|
||||
};
|
||||
|
||||
Vector2d southWest = new Vector2d(48.2174, 16.3662);
|
||||
Vector2d northEast = new Vector2d(48.2310, 16.3877);
|
||||
Vector2dBounds bounds = new Vector2dBounds(southWest, northEast);
|
||||
_tileIds = TileCover.Get(bounds, 19);
|
||||
|
||||
|
||||
// delete cache from previous runs
|
||||
string dbFullPath = SQLiteCache.GetFullDbPath(_dbName);
|
||||
if (File.Exists(dbFullPath)) { File.Delete(dbFullPath); }
|
||||
|
||||
_cache = new SQLiteCache(_maxCacheTileCount, _dbName);
|
||||
}
|
||||
|
||||
|
||||
[OneTimeTearDown]
|
||||
public void Cleanup()
|
||||
{
|
||||
if (null != _cache)
|
||||
{
|
||||
_cache.Dispose();
|
||||
_cache = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Test, Order(1)]
|
||||
public void InsertSameTileNoOverwrite()
|
||||
{
|
||||
string methodName = _className + "." + new StackFrame().GetMethod().Name;
|
||||
List<long> elapsed = simpleInsert(TS_NO_OVERWRITE, false);
|
||||
logTime(methodName, elapsed);
|
||||
cacheItemAsserts(TS_NO_OVERWRITE, new CanonicalTileId(0, 0, 0));
|
||||
Assert.AreEqual(1, _cache.TileCount(TS_NO_OVERWRITE), "tileset {0}: unexpected number of tiles", TS_NO_OVERWRITE);
|
||||
}
|
||||
|
||||
|
||||
[Test, Order(2)]
|
||||
public void InsertSameTileForceOverwrite()
|
||||
{
|
||||
string methodName = _className + "." + new StackFrame().GetMethod().Name;
|
||||
List<long> elapsed = simpleInsert(TS_FORCE_OVERWRITE, true);
|
||||
logTime(methodName, elapsed);
|
||||
cacheItemAsserts(TS_FORCE_OVERWRITE, new CanonicalTileId(0, 0, 0));
|
||||
Assert.AreEqual(1, _cache.TileCount(TS_FORCE_OVERWRITE), "tileset {0}: unexpected number of tiles", TS_FORCE_OVERWRITE);
|
||||
}
|
||||
|
||||
|
||||
[UnityTest, Order(3)]
|
||||
public IEnumerator ConcurrentTilesetInsert()
|
||||
{
|
||||
|
||||
ued.LogFormat("about to insert {0} tiles for each tileset", _tileIds.Count);
|
||||
|
||||
int rIdCr1 = Runnable.Run(InsertCoroutine(TS_CONCURRENT1, false, _tileIds));
|
||||
int rIdCr2 = Runnable.Run(InsertCoroutine(TS_CONCURRENT2, false, _tileIds));
|
||||
int rIdCr3 = Runnable.Run(InsertCoroutine(TS_CONCURRENT3, false, _tileIds));
|
||||
int rIdCr4 = Runnable.Run(InsertCoroutine(TS_CONCURRENT4, false, _tileIds));
|
||||
|
||||
while (Runnable.IsRunning(rIdCr1) || Runnable.IsRunning(rIdCr2) || Runnable.IsRunning(rIdCr3) || Runnable.IsRunning(rIdCr4))
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
[Test, Order(4)]
|
||||
public void VerifyTilesFromConcurrentInsert()
|
||||
{
|
||||
ued.Log("verifying concurrently inserted tiles ...");
|
||||
|
||||
string[] tilesetNames = new string[] { TS_CONCURRENT1, TS_CONCURRENT2, TS_CONCURRENT3, TS_CONCURRENT4 };
|
||||
|
||||
foreach (string tilesetName in tilesetNames)
|
||||
{
|
||||
Assert.AreEqual(_tileIds.Count, _cache.TileCount(tilesetName), "tileset '{0}' does not contain expected number of tiles", tilesetName);
|
||||
}
|
||||
|
||||
foreach (string tilesetName in tilesetNames)
|
||||
{
|
||||
foreach (CanonicalTileId tileId in _tileIds)
|
||||
{
|
||||
cacheItemAsserts(tilesetName, tileId);
|
||||
}
|
||||
}
|
||||
|
||||
ued.Log("all tiles in cache!");
|
||||
}
|
||||
|
||||
|
||||
[Test, Order(5)]
|
||||
public void Prune()
|
||||
{
|
||||
string methodName = _className + "." + new StackFrame().GetMethod().Name;
|
||||
HashSet<CanonicalTileId> tileIds = new HashSet<CanonicalTileId>();
|
||||
|
||||
int tiles2Insert = (int)_maxCacheTileCount + (int)_cache.PruneCacheDelta + 1;
|
||||
ued.Log(string.Format("about to insert {0} tiles", tiles2Insert));
|
||||
for (int x = 0; x < tiles2Insert; x++)
|
||||
{
|
||||
tileIds.Add(new CanonicalTileId(x, 131205, 18));
|
||||
}
|
||||
|
||||
List<long> elapsed = simpleInsert(TS_PRUNE, false, tileIds);
|
||||
logTime(methodName, elapsed);
|
||||
Assert.AreEqual(_maxCacheTileCount, _cache.TileCount(TS_PRUNE), _cache.PruneCacheDelta, "tileset [{0}]: pruning did not work as expected", TS_PRUNE);
|
||||
}
|
||||
|
||||
|
||||
[Test, Order(6)]
|
||||
public void Clear()
|
||||
{
|
||||
// We still should have tiles in the cache
|
||||
long tileCnt = getAllTilesCount();
|
||||
|
||||
// beware 'Assert.Greater' has parameters flipped compared to 'Assert.AreEqual'
|
||||
Assert.GreaterOrEqual(tileCnt, _cache.MaxCacheSize, "number of tiles lower than expected");
|
||||
|
||||
_cache.Clear();
|
||||
// have to Reinit after Clear()
|
||||
_cache.ReInit();
|
||||
|
||||
tileCnt = getAllTilesCount();
|
||||
|
||||
Assert.AreEqual(0, tileCnt, "'Clear()' did not work as expected");
|
||||
}
|
||||
|
||||
|
||||
[Test, Order(7)]
|
||||
public void ReInit()
|
||||
{
|
||||
// after previous 'Clear' there shouldn't be any tiles in cache
|
||||
long tileCnt = getAllTilesCount();
|
||||
Assert.AreEqual(0, tileCnt, "'Clear()' did not work as expected");
|
||||
// insert one tile
|
||||
simpleInsert(TS_REINIT, false, itemCount: 1);
|
||||
tileCnt = getAllTilesCount();
|
||||
Assert.AreEqual(1, tileCnt, "one tile was not inserted");
|
||||
|
||||
_cache.ReInit();
|
||||
|
||||
Assert.AreEqual(1, tileCnt, "tile was lost during 'ReInit()'");
|
||||
}
|
||||
|
||||
|
||||
#region helper methods
|
||||
|
||||
|
||||
private long getAllTilesCount()
|
||||
{
|
||||
long tileCnt = 0;
|
||||
foreach (string tilesetName in _allTilesetNames)
|
||||
{
|
||||
tileCnt += _cache.TileCount(tilesetName);
|
||||
}
|
||||
return tileCnt;
|
||||
}
|
||||
|
||||
|
||||
private void cacheItemAsserts(string tilesetName, CanonicalTileId tileId)
|
||||
{
|
||||
CacheItem ci = _cache.Get(tilesetName, tileId);
|
||||
Assert.NotNull(ci, "tileset '{0}': {1} not found in cache", tilesetName, tileId);
|
||||
Assert.NotNull(ci.Data, "tileset '{0}': {1} tile data is null", tilesetName, tileId);
|
||||
Assert.NotZero(ci.Data.Length, "tileset '{0}': {1} data length is 0", tilesetName, tileId);
|
||||
}
|
||||
|
||||
|
||||
private IEnumerator InsertCoroutine(string tileSetName, bool forceInsert, HashSet<CanonicalTileId> tileIds = null)
|
||||
{
|
||||
ued.Log(string.Format("coroutine [{0}] started", tileSetName));
|
||||
yield return null;
|
||||
|
||||
List<long> elapsed = simpleInsert(tileSetName, forceInsert, tileIds);
|
||||
|
||||
ued.Log(string.Format("coroutine [{0}] finished", tileSetName));
|
||||
logTime(tileSetName, elapsed);
|
||||
}
|
||||
|
||||
|
||||
private List<long> simpleInsert(string tileSetName, bool forceInsert, HashSet<CanonicalTileId> tileIds = null, int itemCount = 1000)
|
||||
{
|
||||
if (null != tileIds) { itemCount = tileIds.Count; }
|
||||
|
||||
List<long> elapsed = new List<long>();
|
||||
Stopwatch sw = new Stopwatch();
|
||||
|
||||
for (int i = 0; i < itemCount; i++)
|
||||
{
|
||||
CanonicalTileId tileId = null != tileIds ? tileIds.ElementAt(i) : new CanonicalTileId(0, 0, 0);
|
||||
DateTime now = DateTime.UtcNow;
|
||||
CacheItem cacheItem = new CacheItem()
|
||||
{
|
||||
AddedToCacheTicksUtc = now.Ticks,
|
||||
// simulate 100KB data
|
||||
Data = Enumerable.Repeat((byte)0x58, 100 * 1024).ToArray(),
|
||||
ETag = "etag",
|
||||
LastModified = now
|
||||
};
|
||||
|
||||
sw.Start();
|
||||
_cache.Add(tileSetName, tileId, cacheItem, forceInsert);
|
||||
sw.Stop();
|
||||
elapsed.Add(sw.ElapsedMilliseconds);
|
||||
sw.Reset();
|
||||
}
|
||||
|
||||
return elapsed;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void logTime(string label, List<long> elapsed)
|
||||
{
|
||||
double overall = elapsed.Sum() / 1000.0;
|
||||
double min = elapsed.Min() / 1000.0;
|
||||
double max = elapsed.Max() / 1000.0;
|
||||
double avg = elapsed.Average() / 1000.0;
|
||||
|
||||
double sum = elapsed.Sum(d => Math.Pow(d - avg, 2));
|
||||
double stdDev = (Math.Sqrt((sum) / (elapsed.Count - 1))) / 1000.0;
|
||||
|
||||
ued.Log(string.Format(
|
||||
CultureInfo.InvariantCulture
|
||||
, "[{0}] {1} items, overall time:{2,6:0.000}s avg:{3,6:0.000}s min:{4,6:0.000}s max:{5,6:0.000}s stdDev:{6,6:0.000}s"
|
||||
, label
|
||||
, elapsed.Count
|
||||
, overall
|
||||
, avg
|
||||
, min
|
||||
, max
|
||||
, stdDev
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e9829dc6854b57c4daa504cf64758026
|
||||
timeCreated: 1528105352
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,108 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="TileTest.cs" company="Mapbox">
|
||||
// Copyright (c) 2016 Mapbox. All rights reserved.
|
||||
// </copyright>
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
|
||||
// TODO: figure out how run tests outside of Unity with .NET framework, something like '#if !UNITY'
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
|
||||
|
||||
namespace Mapbox.MapboxSdkCs.UnitTest
|
||||
{
|
||||
|
||||
|
||||
using Mapbox.Map;
|
||||
using Mapbox.Platform;
|
||||
using NUnit.Framework;
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
using System.Collections;
|
||||
using UnityEngine.TestTools;
|
||||
#endif
|
||||
|
||||
|
||||
[TestFixture]
|
||||
internal class TileTest
|
||||
{
|
||||
|
||||
|
||||
private FileSource _fs;
|
||||
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
_fs = new FileSource(Unity.MapboxAccess.Instance.Configuration.GetMapsSkuToken, Unity.MapboxAccess.Instance.Configuration.AccessToken);
|
||||
#else
|
||||
// when run outside of Unity FileSource gets the access token from environment variable 'MAPBOX_ACCESS_TOKEN'
|
||||
_fs = new FileSource();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
[UnityTest]
|
||||
public IEnumerator TileLoading()
|
||||
#else
|
||||
[Test]
|
||||
public void TileLoading()
|
||||
#endif
|
||||
{
|
||||
byte[] data;
|
||||
|
||||
var parameters = new Tile.Parameters();
|
||||
parameters.Fs = _fs;
|
||||
parameters.Id = new CanonicalTileId(1, 1, 1);
|
||||
|
||||
var tile = new RawPngRasterTile();
|
||||
tile.Initialize(parameters, () => { data = tile.Data; });
|
||||
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
IEnumerator enumerator = _fs.WaitForAllRequests();
|
||||
while (enumerator.MoveNext()) { yield return null; }
|
||||
#else
|
||||
_fs.WaitForAllRequests();
|
||||
#endif
|
||||
|
||||
Assert.Greater(tile.Data.Length, 1000);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
[UnityTest]
|
||||
public IEnumerator States()
|
||||
#else
|
||||
[Test]
|
||||
public void States()
|
||||
#endif
|
||||
{
|
||||
var parameters = new Tile.Parameters();
|
||||
parameters.Fs = _fs;
|
||||
parameters.Id = new CanonicalTileId(1, 1, 1);
|
||||
|
||||
var tile = new RawPngRasterTile();
|
||||
Assert.AreEqual(Tile.State.New, tile.CurrentState);
|
||||
|
||||
tile.Initialize(parameters, () => { });
|
||||
Assert.AreEqual(Tile.State.Loading, tile.CurrentState);
|
||||
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
IEnumerator enumerator = _fs.WaitForAllRequests();
|
||||
while (enumerator.MoveNext()) { yield return null; }
|
||||
#else
|
||||
_fs.WaitForAllRequests();
|
||||
#endif
|
||||
|
||||
Assert.AreEqual(Tile.State.Loaded, tile.CurrentState);
|
||||
|
||||
tile.Cancel();
|
||||
Assert.AreEqual(Tile.State.Canceled, tile.CurrentState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 458f515b81c004c5982c33a6fb6f99ed
|
||||
timeCreated: 1498231546
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,63 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="TileCoverTest.cs" company="Mapbox">
|
||||
// Copyright (c) 2016 Mapbox. All rights reserved.
|
||||
// </copyright>
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
namespace Mapbox.MapboxSdkCs.UnitTest
|
||||
{
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Mapbox.Map;
|
||||
using Mapbox.Utils;
|
||||
using NUnit.Framework;
|
||||
|
||||
|
||||
[TestFixture]
|
||||
internal class TileCoverTest
|
||||
{
|
||||
|
||||
|
||||
[Test]
|
||||
public void World()
|
||||
{
|
||||
// Zoom > 8 will generate so many tiles that we
|
||||
// might run out of memory.
|
||||
for (int zoom = 0; zoom < 8; ++zoom)
|
||||
{
|
||||
var tiles = TileCover.Get(Vector2dBounds.World(), zoom);
|
||||
Assert.AreEqual(Math.Pow(4, zoom), tiles.Count);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void Helsinki()
|
||||
{
|
||||
// Assertion results verified on Mapbox GL Native.
|
||||
var sw = new Vector2d(60.163200, 24.937700);
|
||||
var ne = new Vector2d(60.163300, 24.937800);
|
||||
|
||||
var set1 = TileCover.Get(new Vector2dBounds(sw, ne), 13);
|
||||
Assert.AreEqual(1, set1.Count);
|
||||
|
||||
var list1 = new List<CanonicalTileId>(set1);
|
||||
Assert.AreEqual("13/4663/2371", list1[0].ToString());
|
||||
|
||||
var set2 = TileCover.Get(new Vector2dBounds(sw, ne), 6);
|
||||
Assert.AreEqual(1, set2.Count);
|
||||
|
||||
var list2 = new List<CanonicalTileId>(set2);
|
||||
Assert.AreEqual("6/36/18", list2[0].ToString());
|
||||
|
||||
var set3 = TileCover.Get(new Vector2dBounds(sw, ne), 0);
|
||||
Assert.AreEqual(1, set3.Count);
|
||||
|
||||
var list3 = new List<CanonicalTileId>(set3);
|
||||
Assert.AreEqual("0/0/0", list3[0].ToString());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5990cb1e4cf9440e1ab76a610a3364fc
|
||||
timeCreated: 1498231546
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,225 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="FileSourceTest.cs" company="Mapbox">
|
||||
// Copyright (c) 2016 Mapbox. All rights reserved.
|
||||
// </copyright>
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
// TODO: figure out how run tests outside of Unity with .NET framework, something like '#if !UNITY'
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
|
||||
namespace Mapbox.MapboxSdkCs.UnitTest
|
||||
{
|
||||
|
||||
|
||||
using Mapbox.Platform;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine.TestTools;
|
||||
using System.Collections;
|
||||
using Mapbox.Platform.TilesetTileJSON;
|
||||
|
||||
|
||||
[TestFixture]
|
||||
internal class TileJSONTest
|
||||
{
|
||||
|
||||
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator MapboxStreets()
|
||||
{
|
||||
string id = "mapbox.mapbox-streets-v7";
|
||||
int minZoom = 0;
|
||||
int maxZoom = 16;
|
||||
|
||||
TileJSONResponse response = null;
|
||||
|
||||
Unity.MapboxAccess.Instance.TileJSON.Get(
|
||||
id
|
||||
, (TileJSONResponse tjr) =>
|
||||
{
|
||||
response = tjr;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
IEnumerator enumerator = ((FileSource)Unity.MapboxAccess.Instance.TileJSON.FileSource).WaitForAllRequests();
|
||||
while (enumerator.MoveNext()) { yield return null; }
|
||||
|
||||
testsCommonToVectorAndRasterTilesets(response, id, minZoom, maxZoom);
|
||||
testsForVectorTilesets(response);
|
||||
}
|
||||
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator ConcatenatedVectorTilesets()
|
||||
{
|
||||
string id = "mapbox.mapbox-traffic-v1,mapbox.mapbox-streets-v7";
|
||||
int minZoom = 0;
|
||||
int maxZoom = 16;
|
||||
|
||||
TileJSONResponse response = null;
|
||||
|
||||
Unity.MapboxAccess.Instance.TileJSON.Get(
|
||||
id
|
||||
, (TileJSONResponse tjr) =>
|
||||
{
|
||||
response = tjr;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
IEnumerator enumerator = ((FileSource)Unity.MapboxAccess.Instance.TileJSON.FileSource).WaitForAllRequests();
|
||||
while (enumerator.MoveNext()) { yield return null; }
|
||||
|
||||
testsCommonToVectorAndRasterTilesets(
|
||||
response
|
||||
, id
|
||||
, minZoom
|
||||
, maxZoom
|
||||
, boundsSouth: -90
|
||||
, boundsNorth: 90
|
||||
);
|
||||
testsForVectorTilesets(response);
|
||||
}
|
||||
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator MapboxSatellite()
|
||||
{
|
||||
string id = "mapbox.satellite";
|
||||
int minZoom = 0;
|
||||
int maxZoom = 22;
|
||||
|
||||
TileJSONResponse response = null;
|
||||
|
||||
Unity.MapboxAccess.Instance.TileJSON.Get(
|
||||
id
|
||||
, (TileJSONResponse tjr) =>
|
||||
{
|
||||
response = tjr;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
IEnumerator enumerator = ((FileSource)Unity.MapboxAccess.Instance.TileJSON.FileSource).WaitForAllRequests();
|
||||
while (enumerator.MoveNext()) { yield return null; }
|
||||
|
||||
testsCommonToVectorAndRasterTilesets(response, id, minZoom, maxZoom, boundsSouth: -85, boundsNorth: 85);
|
||||
}
|
||||
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator MapboxEmerald()
|
||||
{
|
||||
string id = "mapbox.emerald";
|
||||
int minZoom = 0;
|
||||
int maxZoom = 22;
|
||||
|
||||
TileJSONResponse response = null;
|
||||
|
||||
Unity.MapboxAccess.Instance.TileJSON.Get(
|
||||
id
|
||||
, (TileJSONResponse tjr) =>
|
||||
{
|
||||
response = tjr;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
IEnumerator enumerator = ((FileSource)Unity.MapboxAccess.Instance.TileJSON.FileSource).WaitForAllRequests();
|
||||
while (enumerator.MoveNext()) { yield return null; }
|
||||
|
||||
testsCommonToVectorAndRasterTilesets(response, id, minZoom, maxZoom);
|
||||
|
||||
Assert.IsNotEmpty(response.Source, "'Source' not set properly");
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void testsForVectorTilesets(TileJSONResponse response)
|
||||
{
|
||||
Assert.IsNotNull(response.VectorLayers, "'VectorLayers' not set properly");
|
||||
Assert.GreaterOrEqual(response.VectorLayers.Length, 1, "Not enough 'VectorLayers'");
|
||||
|
||||
TileJSONObjectVectorLayer vl1 = response.VectorLayers[0];
|
||||
Assert.IsNotNull(vl1.Fields, "VectorLayer fields not parsed properly");
|
||||
Assert.GreaterOrEqual(vl1.Fields.Count, 1, "Not enough vector layer fields");
|
||||
Assert.IsNotEmpty(vl1.Id, "'Id' of vector layer not parsed properly");
|
||||
Assert.IsNotEmpty(vl1.Source, "'Source' of vector layer not parsed properly");
|
||||
Assert.IsNotEmpty(vl1.SourceName, "'SourceName' of vector layer not parsed properly");
|
||||
}
|
||||
|
||||
|
||||
private void testsCommonToVectorAndRasterTilesets(
|
||||
TileJSONResponse response
|
||||
, string id
|
||||
, int minZoom
|
||||
, int maxZoom
|
||||
, double boundsWest = -180
|
||||
, double boundsSouth = -85.0511
|
||||
, double boundsEast = 180
|
||||
, double boundsNorth = 85.0511
|
||||
)
|
||||
{
|
||||
Assert.IsNotNull(response, "Parsing error or no data received from the servers.");
|
||||
|
||||
Assert.IsNotEmpty(response.Attribution, "Attribution not set.");
|
||||
|
||||
Assert.AreEqual(boundsWest, response.BoundsParsed.West, "Bounds.West does not match");
|
||||
Assert.AreEqual(boundsSouth, response.BoundsParsed.South, 0.003, "Bounds.South does not match");
|
||||
Assert.AreEqual(boundsEast, response.BoundsParsed.East, "Bounds.East does not match");
|
||||
Assert.AreEqual(boundsNorth, response.BoundsParsed.North, 0.003, "Bounds.North does not match");
|
||||
|
||||
// this does not work as some tilesets report whole world bounds despite covering a small area only
|
||||
// revisit some time in the future
|
||||
//Assert.AreEqual(response.BoundsParsed.Center.x, response.CenterParsed.x, 0.003, "Center.x does not match");
|
||||
//Assert.AreEqual(response.BoundsParsed.Center.y, response.CenterParsed.y, "Center.y does not match");
|
||||
|
||||
//concatenated tilesets don't have created property
|
||||
if (response.Created.HasValue)
|
||||
{
|
||||
Assert.Greater(response.Created.Value, 0, "'Created' not set");
|
||||
Assert.IsNotNull(response.CreatedUtc, "'CreatedUtc' not set properly'");
|
||||
}
|
||||
|
||||
// mapbox.satellite doesn't set 'format': bug??
|
||||
// revisit in the future
|
||||
//Assert.IsNotEmpty(response.Format, "'Format' is empty");
|
||||
|
||||
// concatenated tilesets don't report 'id'
|
||||
if (!id.Contains(","))
|
||||
{
|
||||
Assert.IsNotEmpty(response.Id, "'Id' is empty");
|
||||
Assert.AreEqual(id, response.Id, "'Id' not set properly");
|
||||
}
|
||||
Assert.AreEqual(minZoom, response.MinZoom, "'MinZoom' not set properly");
|
||||
Assert.AreEqual(maxZoom, response.MaxZoom, "'MaxZoom' not set properly");
|
||||
|
||||
//Unmodified tilesets don't have a modified property
|
||||
if (response.Modified.HasValue)
|
||||
{
|
||||
Assert.Greater(response.Modified.Value, 0, "'Modified not set'");
|
||||
Assert.IsTrue(response.ModifiedUtc.HasValue, "'Modified not properly parsed'");
|
||||
}
|
||||
|
||||
Assert.IsNotEmpty(response.Name, "'Name' not set properly");
|
||||
Assert.IsFalse(response.Private, "'Private' not set properly");
|
||||
Assert.AreEqual("xyz", response.Scheme, "'Scheme' not set properly");
|
||||
Assert.IsNotEmpty(response.TileJSONVersion, "'TileJSONVersion not set properly");
|
||||
|
||||
Assert.IsNotNull(response.Tiles, "'Tiles' not set properly");
|
||||
Assert.GreaterOrEqual(response.Tiles.Length, 1, "Not enough 'Tiles'");
|
||||
|
||||
// concatenated tilesets don't report 'webpage'
|
||||
if (!id.Contains(","))
|
||||
{
|
||||
Assert.IsNotEmpty(response.WebPage, "'WebPage' not set properly");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 609e55c6e2c34624eb02d61d96cb34f0
|
||||
timeCreated: 1515592137
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,78 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="TileResourceTest.cs" company="Mapbox">
|
||||
// Copyright (c) 2016 Mapbox. All rights reserved.
|
||||
// </copyright>
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
// TODO: figure out how run tests outside of Unity with .NET framework, something like '#if !UNITY'
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
|
||||
namespace Mapbox.MapboxSdkCs.UnitTest
|
||||
{
|
||||
|
||||
using Mapbox.Map;
|
||||
using Mapbox.Utils;
|
||||
using NUnit.Framework;
|
||||
|
||||
[TestFixture]
|
||||
public class TileResourceTest
|
||||
{
|
||||
|
||||
private string _api;
|
||||
private CanonicalTileId _tileId;
|
||||
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_api = Constants.BaseAPI;
|
||||
_tileId = new CanonicalTileId(0, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void GetUrlRaster()
|
||||
{
|
||||
var res1 = TileResource.MakeRaster(_tileId, null);
|
||||
Assert.AreEqual(_api + "styles/v1/mapbox/satellite-v9/tiles/0/0/0", res1.GetUrl().Split("?".ToCharArray())[0]);
|
||||
|
||||
var res2 = TileResource.MakeRaster(_tileId, "mapbox://styles/mapbox/basic-v9");
|
||||
Assert.AreEqual(_api + "styles/v1/mapbox/basic-v9/tiles/0/0/0", res2.GetUrl().Split("?".ToCharArray())[0]);
|
||||
|
||||
var res3 = TileResource.MakeRaster(_tileId, "https://api.mapbox.com/styles/v1/penny/penny-map/tiles");
|
||||
Assert.AreEqual(_api + "styles/v1/penny/penny-map/tiles/0/0/0", res3.GetUrl().Split("?".ToCharArray())[0]);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void GetUrlClassicRaster()
|
||||
{
|
||||
var res1 = TileResource.MakeClassicRaster(_tileId, null);
|
||||
Assert.AreEqual(_api + "v4/mapbox.satellite/0/0/0.png", res1.GetUrl().Split("?".ToCharArray())[0]);
|
||||
|
||||
var res2 = TileResource.MakeClassicRaster(_tileId, "foobar");
|
||||
Assert.AreEqual(_api + "v4/foobar/0/0/0.png", res2.GetUrl().Split("?".ToCharArray())[0]);
|
||||
|
||||
var res3 = TileResource.MakeClassicRaster(_tileId, "test");
|
||||
Assert.AreEqual(_api + "v4/test/0/0/0.png", res3.GetUrl().Split("?".ToCharArray())[0]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetUrlVector()
|
||||
{
|
||||
var res1 = TileResource.MakeVector(_tileId, null);
|
||||
Assert.AreEqual(_api + "v4/mapbox.mapbox-streets-v7/0/0/0.vector.pbf", res1.GetUrl().Split("?".ToCharArray())[0]);
|
||||
|
||||
var res2 = TileResource.MakeVector(_tileId, "foobar");
|
||||
Assert.AreEqual(_api + "v4/foobar/0/0/0.vector.pbf", res2.GetUrl().Split("?".ToCharArray())[0]);
|
||||
|
||||
var res3 = TileResource.MakeVector(_tileId, "test");
|
||||
Assert.AreEqual(_api + "v4/test/0/0/0.vector.pbf", res3.GetUrl().Split("?".ToCharArray())[0]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a7052b373a72748da8c09b8288e433fc
|
||||
timeCreated: 1498231547
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,109 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="TokenTest.cs" company="Mapbox">
|
||||
// Copyright (c) 2017 Mapbox. All rights reserved.
|
||||
// </copyright>
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
|
||||
namespace Mapbox.MapboxSdkCs.UnitTest
|
||||
{
|
||||
|
||||
|
||||
using Mapbox.Tokens;
|
||||
using Mapbox.Unity;
|
||||
using NUnit.Framework;
|
||||
using System.Collections;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
|
||||
[TestFixture]
|
||||
internal class TokenTest
|
||||
{
|
||||
|
||||
|
||||
private MapboxTokenApi _tokenApi;
|
||||
private string _configAccessToken;
|
||||
private Func<string> _configSkuToken;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_tokenApi = new MapboxTokenApi();
|
||||
_configAccessToken = MapboxAccess.Instance.Configuration.AccessToken;
|
||||
_configSkuToken = MapboxAccess.Instance.Configuration.GetMapsSkuToken;
|
||||
}
|
||||
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator RetrieveConfigToken()
|
||||
{
|
||||
|
||||
MapboxToken token = null;
|
||||
|
||||
_tokenApi.Retrieve(
|
||||
_configSkuToken,
|
||||
_configAccessToken,
|
||||
(MapboxToken tok) =>
|
||||
{
|
||||
token = tok;
|
||||
}
|
||||
);
|
||||
|
||||
while (null == token) { yield return null; }
|
||||
|
||||
Assert.IsNull(token.ErrorMessage);
|
||||
Assert.IsFalse(token.HasError);
|
||||
Assert.AreEqual(MapboxTokenStatus.TokenValid, token.Status, "Config token is not valid");
|
||||
}
|
||||
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator TokenMalformed()
|
||||
{
|
||||
|
||||
MapboxToken token = null;
|
||||
|
||||
_tokenApi.Retrieve(
|
||||
_configSkuToken,
|
||||
"yada.yada",
|
||||
(MapboxToken tok) =>
|
||||
{
|
||||
token = tok;
|
||||
}
|
||||
);
|
||||
|
||||
while (null == token) { yield return null; }
|
||||
|
||||
Assert.IsNull(token.ErrorMessage);
|
||||
Assert.IsFalse(token.HasError);
|
||||
Assert.AreEqual(MapboxTokenStatus.TokenMalformed, token.Status, "token is malformed");
|
||||
}
|
||||
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator TokenInvalid()
|
||||
{
|
||||
|
||||
MapboxToken token = null;
|
||||
|
||||
_tokenApi.Retrieve(
|
||||
_configSkuToken,
|
||||
"pk.12345678901234567890123456789012345.0123456789012345678901",
|
||||
(MapboxToken tok) =>
|
||||
{
|
||||
token = tok;
|
||||
}
|
||||
);
|
||||
|
||||
while (null == token) { yield return null; }
|
||||
|
||||
Assert.IsNull(token.ErrorMessage);
|
||||
Assert.IsFalse(token.HasError);
|
||||
Assert.AreEqual(MapboxTokenStatus.TokenInvalid, token.Status, "token is invalid");
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 067fbf2b171d0d24fb888953affd5740
|
||||
timeCreated: 1512087400
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,82 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="Utils.cs" company="Mapbox">
|
||||
// Copyright (c) 2016 Mapbox. All rights reserved.
|
||||
// </copyright>
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
namespace Mapbox.MapboxSdkCs.UnitTest
|
||||
{
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Mapbox.Map;
|
||||
|
||||
|
||||
internal static class Utils
|
||||
{
|
||||
internal class VectorMapObserver : Mapbox.Utils.IObserver<VectorTile>
|
||||
{
|
||||
private List<VectorTile> tiles = new List<VectorTile>();
|
||||
|
||||
public List<VectorTile> Tiles
|
||||
{
|
||||
get
|
||||
{
|
||||
return tiles;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnNext(VectorTile tile)
|
||||
{
|
||||
if (tile.CurrentState == Tile.State.Loaded)
|
||||
{
|
||||
tiles.Add(tile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class RasterMapObserver : Mapbox.Utils.IObserver<RasterTile>
|
||||
{
|
||||
private List<byte[]> tiles = new List<byte[]>();
|
||||
|
||||
public List<byte[]> Tiles
|
||||
{
|
||||
get
|
||||
{
|
||||
return tiles;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnNext(RasterTile tile)
|
||||
{
|
||||
if (tile.CurrentState == Tile.State.Loaded && !tile.HasError)
|
||||
{
|
||||
tiles.Add(tile.Data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class ClassicRasterMapObserver : Mapbox.Utils.IObserver<ClassicRasterTile>
|
||||
{
|
||||
private List<byte[]> tiles = new List<byte[]>();
|
||||
|
||||
public List<byte[]> Tiles
|
||||
{
|
||||
get
|
||||
{
|
||||
return tiles;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnNext(ClassicRasterTile tile)
|
||||
{
|
||||
if (tile.CurrentState == Tile.State.Loaded && !tile.HasError)
|
||||
{
|
||||
tiles.Add(tile.Data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e6a3a4a684cc64e609e83b2b547a9e82
|
||||
timeCreated: 1498231547
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,138 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="VectorTileTest.cs" company="Mapbox">
|
||||
// Copyright (c) 2016 Mapbox. All rights reserved.
|
||||
// </copyright>
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
// TODO: figure out how run tests outside of Unity with .NET framework, something like '#if !UNITY'
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
|
||||
|
||||
namespace Mapbox.MapboxSdkCs.UnitTest
|
||||
{
|
||||
|
||||
using System.Linq;
|
||||
using Mapbox.Map;
|
||||
using Mapbox.Platform;
|
||||
using Mapbox.Utils;
|
||||
using NUnit.Framework;
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
using UnityEngine.TestTools;
|
||||
using System.Collections;
|
||||
#endif
|
||||
|
||||
|
||||
[TestFixture]
|
||||
internal class VectorTileTest
|
||||
{
|
||||
|
||||
|
||||
private FileSource _fs;
|
||||
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
_fs = new FileSource(Unity.MapboxAccess.Instance.Configuration.GetMapsSkuToken, Unity.MapboxAccess.Instance.Configuration.AccessToken);
|
||||
#else
|
||||
// when run outside of Unity FileSource gets the access token from environment variable 'MAPBOX_ACCESS_TOKEN'
|
||||
_fs = new FileSource();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
[UnityTest]
|
||||
public IEnumerator ParseSuccess()
|
||||
#else
|
||||
[Test]
|
||||
public void ParseSuccess()
|
||||
#endif
|
||||
{
|
||||
var map = new Map<VectorTile>(_fs);
|
||||
|
||||
var mapObserver = new Utils.VectorMapObserver();
|
||||
map.Subscribe(mapObserver);
|
||||
|
||||
// Helsinki city center.
|
||||
map.Center = new Vector2d(60.163200, 24.937700);
|
||||
|
||||
for (int zoom = 15; zoom > 0; zoom--)
|
||||
{
|
||||
map.Zoom = zoom;
|
||||
map.Update();
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
IEnumerator enumerator = _fs.WaitForAllRequests();
|
||||
while (enumerator.MoveNext()) { yield return null; }
|
||||
#else
|
||||
_fs.WaitForAllRequests();
|
||||
#endif
|
||||
}
|
||||
|
||||
// We must have all the tiles for Helsinki from 0-15.
|
||||
Assert.AreEqual(15, mapObserver.Tiles.Count);
|
||||
|
||||
foreach (var tile in mapObserver.Tiles)
|
||||
{
|
||||
Assert.Greater(tile.LayerNames().Count, 0, "Tile contains at least one layer");
|
||||
Mapbox.VectorTile.VectorTileLayer layer = tile.GetLayer("water");
|
||||
Assert.NotNull(layer, "Tile contains 'water' layer. Layers: {0}", string.Join(",", tile.LayerNames().ToArray()));
|
||||
Assert.Greater(layer.FeatureCount(), 0, "Water layer has features");
|
||||
Mapbox.VectorTile.VectorTileFeature feature = layer.GetFeature(0);
|
||||
Assert.Greater(feature.Geometry<long>().Count, 0, "Feature has geometry");
|
||||
Assert.Greater(tile.GeoJson.Length, 1000);
|
||||
}
|
||||
|
||||
map.Unsubscribe(mapObserver);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
[UnityTest]
|
||||
public IEnumerator SeveralTiles()
|
||||
#else
|
||||
[Test]
|
||||
public void ParseSuccess
|
||||
#endif
|
||||
{
|
||||
var map = new Map<VectorTile>(_fs);
|
||||
|
||||
var mapObserver = new Utils.VectorMapObserver();
|
||||
map.Subscribe(mapObserver);
|
||||
|
||||
map.Vector2dBounds = Vector2dBounds.World();
|
||||
map.Zoom = 3; // 64 tiles.
|
||||
map.Update();
|
||||
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
IEnumerator enumerator = _fs.WaitForAllRequests();
|
||||
while (enumerator.MoveNext()) { yield return null; }
|
||||
#else
|
||||
_fs.WaitForAllRequests();
|
||||
#endif
|
||||
|
||||
Assert.AreEqual(64, mapObserver.Tiles.Count);
|
||||
|
||||
foreach (var tile in mapObserver.Tiles)
|
||||
{
|
||||
if (!tile.HasError)
|
||||
{
|
||||
Assert.Greater(tile.GeoJson.Length, 41);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.GreaterOrEqual(tile.Exceptions.Count, 1, "not set enough exceptions set on 'Tile'");
|
||||
}
|
||||
}
|
||||
|
||||
map.Unsubscribe(mapObserver);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1b9319977dcf54a1d9f78833a2490004
|
||||
timeCreated: 1498231546
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in new issue
Block a user