2016-05-26 16:06:52 +03:00
|
|
|
//
|
|
|
|
// Unit tests for SKSpriteNode
|
|
|
|
//
|
|
|
|
// Authors:
|
|
|
|
// Sebastien Pouliot <sebastien@xamarin.com>
|
|
|
|
//
|
|
|
|
// Copyright 2013 Xamarin Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#if !__WATCHOS__
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Drawing;
|
|
|
|
#if XAMCORE_2_0
|
|
|
|
using Foundation;
|
2018-07-04 12:44:14 +03:00
|
|
|
using ObjCRuntime;
|
2017-01-12 21:13:56 +03:00
|
|
|
#if MONOMAC
|
|
|
|
using AppKit;
|
|
|
|
using UIColor = AppKit.NSColor;
|
|
|
|
#else
|
2016-05-26 16:06:52 +03:00
|
|
|
using UIKit;
|
2017-01-12 21:13:56 +03:00
|
|
|
#endif
|
2016-05-26 16:06:52 +03:00
|
|
|
using SpriteKit;
|
|
|
|
#else
|
|
|
|
using MonoTouch.Foundation;
|
|
|
|
using MonoTouch.SpriteKit;
|
|
|
|
using MonoTouch.UIKit;
|
|
|
|
#endif
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
#if XAMCORE_2_0
|
|
|
|
using RectangleF=CoreGraphics.CGRect;
|
|
|
|
using SizeF=CoreGraphics.CGSize;
|
|
|
|
using PointF=CoreGraphics.CGPoint;
|
|
|
|
#else
|
|
|
|
using nfloat=global::System.Single;
|
|
|
|
using nint=global::System.Int32;
|
|
|
|
using nuint=global::System.UInt32;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace MonoTouchFixtures.SpriteKit {
|
|
|
|
|
|
|
|
[TestFixture]
|
|
|
|
[Preserve (AllMembers = true)]
|
|
|
|
public class SpriteNodeTest {
|
|
|
|
|
|
|
|
void CheckEmpty (SKSpriteNode n)
|
|
|
|
{
|
|
|
|
Assert.IsNotNull (n.Color, "Color");
|
|
|
|
Assert.Null (n.Name, "Name");
|
|
|
|
Assert.True (n.Size.IsEmpty, "Size");
|
|
|
|
Assert.Null (n.Texture, "Texture");
|
|
|
|
}
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
public void VersionCheck ()
|
|
|
|
{
|
2018-07-04 12:44:14 +03:00
|
|
|
TestRuntime.AssertSystemVersion (PlatformName.iOS, 7, 0, throwIfOtherPlatform: false);
|
|
|
|
TestRuntime.AssertSystemVersion (PlatformName.TvOS, 9, 0, throwIfOtherPlatform: false);
|
|
|
|
TestRuntime.AssertSystemVersion (PlatformName.MacOSX, 10, 9, throwIfOtherPlatform: false);
|
|
|
|
TestRuntime.AssertSystemVersion (PlatformName.WatchOS, 3, 0, throwIfOtherPlatform: false);
|
2016-05-26 16:06:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Ctor ()
|
|
|
|
{
|
|
|
|
using (var n = new SKSpriteNode ()) {
|
|
|
|
CheckEmpty (n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void CtorColor ()
|
|
|
|
{
|
|
|
|
using (var n = new SKSpriteNode ((UIColor) null, SizeF.Empty)) {
|
|
|
|
CheckEmpty (n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void CtorName ()
|
|
|
|
{
|
|
|
|
Assert.Throws<ArgumentNullException> (delegate { new SKSpriteNode ((string) null); }, "string");
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void CtorTexture ()
|
|
|
|
{
|
|
|
|
using (var n = new SKSpriteNode ((SKTexture) null)) {
|
|
|
|
CheckEmpty (n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void CtorTextureColor ()
|
|
|
|
{
|
|
|
|
using (var n = new SKSpriteNode (null, null, SizeF.Empty)) {
|
|
|
|
CheckEmpty (n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Color ()
|
|
|
|
{
|
|
|
|
using (var n = new SKSpriteNode (UIColor.Blue, SizeF.Empty)) {
|
2017-01-12 21:13:56 +03:00
|
|
|
#if MONOMAC
|
2018-07-03 18:09:49 +03:00
|
|
|
Assert.That (n.Color.ToString (), Is.EqualTo ("Device RGB(0.016804177314043,0.198350995779037,1,1)").Or.EqualTo ("Device RGB(0,0,1,1)").Or.EqualTo ("Device RGB(0.016804177314043,0.198350965976715,1,1)"), "Color-1");
|
2017-01-12 21:13:56 +03:00
|
|
|
#else
|
2016-05-26 16:06:52 +03:00
|
|
|
Assert.That (n.Color.ToString (), Is.EqualTo ("UIColor [A=255, R=0, G=0, B=255]"), "Color-1");
|
2017-01-12 21:13:56 +03:00
|
|
|
#endif
|
2016-05-26 16:06:52 +03:00
|
|
|
n.Color = null;
|
2017-01-12 21:13:56 +03:00
|
|
|
#if MONOMAC
|
|
|
|
Assert.That (n.Color.ToString (), Is.EqualTo ("Device RGB(0,0,0,0)"), "Color-2");
|
|
|
|
#else
|
2016-05-26 16:06:52 +03:00
|
|
|
Assert.That (n.Color.ToString (), Is.EqualTo ("UIColor [A=0, R=0, G=0, B=0]"), "Color-2");
|
2017-01-12 21:13:56 +03:00
|
|
|
#endif
|
2016-05-26 16:06:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Texture ()
|
|
|
|
{
|
|
|
|
using (var t = SKTexture.FromImageNamed ("basn3p08.png"))
|
|
|
|
using (var n = new SKSpriteNode (t)) {
|
|
|
|
Assert.AreSame (n.Texture, t, "Texture-1");
|
|
|
|
n.Texture = null;
|
|
|
|
Assert.IsNull (n.Texture, "Texture-2");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // !__WATCHOS__
|