Browse files

Added Native script serialization unit test.

  • Loading branch information...
1 parent 23f59bb commit fc3d1ce42d883fccb459bf12b8f6bd1bb23da568 Filip Lundgren committed Jun 12, 2012
View
1 CryBrary.Tests/CryBrary.Tests.csproj
@@ -54,6 +54,7 @@
<Compile Include="Misc\ConvertTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Serialization\CrySerializerTests.cs" />
+ <Compile Include="Serialization\ScriptsTests.cs" />
<Compile Include="Testing\Assertion.cs" />
<Compile Include="Testing\Exceptions.cs" />
</ItemGroup>
View
69 CryBrary.Tests/CryBraryTests.cs
@@ -1,34 +1,37 @@
-using System;
-using CryEngine;
-using Moq;
-using NUnit.Framework;
-
-namespace CryBrary.Tests
-{
- public abstract class CryBraryTests
- {
- [SetUp]
- public void Init()
- {
- InitializeLoggingMethods();
- }
-
- private void InitializeLoggingMethods()
- {
- var loggingMethodsMock = new Mock<INativeLoggingMethods>();
- Action<string> loggingMethod = msg => System.Console.WriteLine(msg);
-
- loggingMethodsMock.Setup(m => m._Log(It.IsAny<string>())).Callback(loggingMethod);
- loggingMethodsMock.Setup(m => m._LogAlways(It.IsAny<string>())).Callback(loggingMethod);
- loggingMethodsMock.Setup(m => m._Warning(It.IsAny<string>())).Callback(loggingMethod);
-
- Debug.Methods = loggingMethodsMock.Object;
-
- var entityMethodsMock = new Mock<INativeEntityMethods>();
- Entity.Methods = entityMethodsMock.Object;
-
- var actorMethodsMock = new Mock<INativeActorMethods>();
- Actor.Actormethods = actorMethodsMock.Object;
- }
- }
+using System;
+using CryEngine;
+using CryEngine.Initialization;
+using Moq;
+using NUnit.Framework;
+
+namespace CryBrary.Tests
+{
+ public abstract class CryBraryTests
+ {
+ [SetUp]
+ public void Init()
+ {
+ InitializeLoggingMethods();
+
+ ScriptManager.IgnoreExternalCalls = true;
+ }
+
+ private void InitializeLoggingMethods()
+ {
+ var loggingMethodsMock = new Mock<INativeLoggingMethods>();
+ Action<string> loggingMethod = msg => System.Console.WriteLine(msg);
+
+ loggingMethodsMock.Setup(m => m._Log(It.IsAny<string>())).Callback(loggingMethod);
+ loggingMethodsMock.Setup(m => m._LogAlways(It.IsAny<string>())).Callback(loggingMethod);
+ loggingMethodsMock.Setup(m => m._Warning(It.IsAny<string>())).Callback(loggingMethod);
+
+ Debug.Methods = loggingMethodsMock.Object;
+
+ var entityMethodsMock = new Mock<INativeEntityMethods>();
+ Entity.Methods = entityMethodsMock.Object;
+
+ var actorMethodsMock = new Mock<INativeActorMethods>();
+ Actor.Actormethods = actorMethodsMock.Object;
+ }
+ }
}
View
43 CryBrary.Tests/Serialization/ScriptsTests.cs
@@ -0,0 +1,43 @@
+using CryEngine;
+using CryEngine.Serialization;
+using CryEngine.Initialization;
+
+using NUnit.Framework;
+
+using System;
+using System.IO;
+using System.Collections.Generic;
+
+namespace CryBrary.Tests.Serialization
+{
+ class ScriptsTests : CryBraryTests
+ {
+ [Test]
+ public void Serialize_Native_Scripts()
+ {
+ var serializer = new CrySerializer();
+
+ using(var stream = new MemoryStream())
+ {
+ ScriptManager.AddScriptInstance(new NativeEntity(1, IntPtr.Zero), ScriptType.Entity);
+ ScriptManager.AddScriptInstance(new NativeEntity(2, IntPtr.Zero), ScriptType.Entity);
+ ScriptManager.AddScriptInstance(new NativeActor(3), ScriptType.Actor);
+
+ serializer.Serialize(stream, ScriptManager.Scripts);
+
+ ScriptManager.Scripts = serializer.Deserialize(stream) as List<CryScript>;
+ Assert.IsNotNull(ScriptManager.Scripts);
+ Assert.AreEqual(2, ScriptManager.Scripts.Count);
+
+ var entityScript = ScriptManager.FindScript(ScriptType.Entity, x => x.Type == typeof(NativeEntity));
+ Assert.AreNotSame(default(CryScript), entityScript);
+ Assert.IsNotNull(entityScript.ScriptInstances);
+ Assert.AreEqual(1, (entityScript.ScriptInstances[0] as EntityBase).Id);
+ Assert.AreEqual(2, (entityScript.ScriptInstances[1] as EntityBase).Id);
+
+ var actor = ScriptManager.Find<NativeActor>(ScriptType.Actor, x => x.Id == 3);
+ Assert.IsNotNull(actor);
+ }
+ }
+ }
+}

0 comments on commit fc3d1ce

Please sign in to comment.