2016-05-26 16:06:52 +03:00
|
|
|
|
//
|
|
|
|
|
// Unit tests for GKEntity
|
|
|
|
|
//
|
|
|
|
|
// Authors:
|
|
|
|
|
// Alex Soto <alex.soto@xamarin.com>
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// Copyright 2015 Xamarin Inc. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#if !__WATCHOS__
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using OpenTK;
|
|
|
|
|
|
|
|
|
|
using Foundation;
|
|
|
|
|
using GameplayKit;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
|
|
namespace MonoTouchFixtures.GamePlayKit {
|
|
|
|
|
|
|
|
|
|
[TestFixture]
|
|
|
|
|
[Preserve (AllMembers = true)]
|
|
|
|
|
public class GKEntityTests {
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void GetAndRemoveTest ()
|
|
|
|
|
{
|
2018-07-03 18:09:49 +03:00
|
|
|
|
TestRuntime.AssertXcodeVersion (7, 0);
|
2016-05-26 16:06:52 +03:00
|
|
|
|
|
|
|
|
|
var entity = GKEntity.GetEntity ();
|
|
|
|
|
entity.AddComponent (new NumberComponent (10));
|
|
|
|
|
entity.AddComponent (new NameComponent ("Ten"));
|
|
|
|
|
Assert.IsTrue (entity.Components.Length == 2, "entity.Components length must be 2");
|
|
|
|
|
|
|
|
|
|
// Test component retrieval by type
|
|
|
|
|
var component = entity.GetComponent (typeof(NumberComponent)) as NumberComponent;
|
|
|
|
|
Assert.NotNull (component, "Component must not be null");
|
|
|
|
|
Assert.IsTrue (component.Id == 10, "Component Id must be 10");
|
|
|
|
|
|
|
|
|
|
// Test component removal by type
|
|
|
|
|
Assert.NotNull (entity.GetComponent (typeof (NameComponent)), "Component typeof NameComponent must not be null");
|
|
|
|
|
entity.RemoveComponent (typeof(NameComponent));
|
|
|
|
|
Assert.IsTrue (entity.Components.Length == 1, "entity.Components length must be 1");
|
|
|
|
|
Assert.IsNull (entity.GetComponent (typeof (NameComponent)), "Component typeof NameComponent must be null");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void BadGetComponent ()
|
|
|
|
|
{
|
2018-07-03 18:09:49 +03:00
|
|
|
|
TestRuntime.AssertXcodeVersion (7, 0);
|
2016-05-26 16:06:52 +03:00
|
|
|
|
|
|
|
|
|
var entity = GKEntity.GetEntity ();
|
2020-07-16 09:19:33 +03:00
|
|
|
|
Assert.Throws<ArgumentNullException> (() => entity.GetComponent (null));
|
2016-05-26 16:06:52 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void BadRemoval ()
|
|
|
|
|
{
|
2018-07-03 18:09:49 +03:00
|
|
|
|
TestRuntime.AssertXcodeVersion (7, 0);
|
2016-05-26 16:06:52 +03:00
|
|
|
|
|
|
|
|
|
var entity = GKEntity.GetEntity ();
|
2020-07-16 09:19:33 +03:00
|
|
|
|
Assert.Throws<ArgumentNullException> (() => entity.RemoveComponent (null));
|
2016-05-26 16:06:52 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Preserve (AllMembers = true)]
|
|
|
|
|
class NameComponent : GKComponent {
|
|
|
|
|
|
|
|
|
|
public string Name { get; private set; }
|
|
|
|
|
|
|
|
|
|
public NameComponent (string name)
|
|
|
|
|
{
|
|
|
|
|
Name = name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public NameComponent (IntPtr handle) : base (handle) { }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Preserve (AllMembers = true)]
|
|
|
|
|
class NumberComponent : GKComponent {
|
|
|
|
|
|
|
|
|
|
public int Id { get; private set; }
|
|
|
|
|
|
|
|
|
|
public NumberComponent (int id)
|
|
|
|
|
{
|
|
|
|
|
Id = id;;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public NumberComponent (IntPtr handle) : base (handle) { }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif // __WATCHOS__
|