Commit a70b2763 authored by Vinicius Jarina's avatar Vinicius Jarina
Browse files

Added WP8 support

parent 296609ca
using System; using System;
using System.Text; using System.Text;
using System.Collections.Generic; using System.Collections.Generic;
using NUnit.Framework;
using NLuaTest.Mock; using NLuaTest.Mock;
using System.Reflection; using System.Reflection;
using System.Threading; using System.Threading;
...@@ -11,8 +10,18 @@ using NLua.Exceptions; ...@@ -11,8 +10,18 @@ using NLua.Exceptions;
using MonoTouch.Foundation; using MonoTouch.Foundation;
#endif #endif
#if WINDOWS_PHONE
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
using SetUp = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestInitializeAttribute;
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
using Test = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestMethodAttribute;
#else
using NUnit.Framework;
#endif
namespace NLuaTest namespace NLuaTest
{ {
[TestFixture] [TestFixture]
#if MONOTOUCH #if MONOTOUCH
[Preserve (AllMembers = true)] [Preserve (AllMembers = true)]
...@@ -33,8 +42,8 @@ namespace NLuaTest ...@@ -33,8 +42,8 @@ namespace NLuaTest
lua.DoString ("err,errMsg=pcall(test.exceptionMethod,test)"); lua.DoString ("err,errMsg=pcall(test.exceptionMethod,test)");
bool err = (bool)lua ["err"]; bool err = (bool)lua ["err"];
Exception errMsg = (Exception)lua ["errMsg"]; Exception errMsg = (Exception)lua ["errMsg"];
Assert.False (err); Assert.AreEqual (false , err);
Assert.NotNull (errMsg.InnerException); Assert.AreNotEqual (null, errMsg.InnerException);
Assert.AreEqual ("exception test", errMsg.InnerException.Message); Assert.AreEqual ("exception test", errMsg.InnerException.Message);
} }
} }
...@@ -54,10 +63,10 @@ namespace NLuaTest ...@@ -54,10 +63,10 @@ namespace NLuaTest
try { try {
lua.DoString ("test:exceptionMethod()"); lua.DoString ("test:exceptionMethod()");
//failed //failed
Assert.True (false); Assert.AreEqual(false, true);
} catch (Exception) { } catch (Exception) {
//passed //passed
Assert.True (true); Assert.AreEqual (true, true);
} }
} }
} }
...@@ -75,10 +84,10 @@ namespace NLuaTest ...@@ -75,10 +84,10 @@ namespace NLuaTest
lua.DoString ("TestClass=luanet.import_type('NLuaTest.Mock.TestClass')"); lua.DoString ("TestClass=luanet.import_type('NLuaTest.Mock.TestClass')");
lua.DoString ("test=TestClass()"); lua.DoString ("test=TestClass()");
lua.DoString ("val=test.NullableBool"); lua.DoString ("val=test.NullableBool");
Assert.Null ((object)lua ["val"]); Assert.AreEqual (null, (object)lua ["val"]);
lua.DoString ("test.NullableBool = true"); lua.DoString ("test.NullableBool = true");
lua.DoString ("val=test.NullableBool"); lua.DoString ("val=test.NullableBool");
Assert.True ((bool)lua ["val"]); Assert.AreEqual (true, (bool)lua ["val"]);
} }
} }
...@@ -120,6 +129,7 @@ namespace NLuaTest ...@@ -120,6 +129,7 @@ namespace NLuaTest
public void TestDispose () public void TestDispose ()
{ {
System.GC.Collect (); System.GC.Collect ();
#if !WINDOWS_PHONE
long startingMem = System.Diagnostics.Process.GetCurrentProcess ().WorkingSet64; long startingMem = System.Diagnostics.Process.GetCurrentProcess ().WorkingSet64;
for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {
...@@ -130,6 +140,7 @@ namespace NLuaTest ...@@ -130,6 +140,7 @@ namespace NLuaTest
//TODO: make this test assert so that it is useful //TODO: make this test assert so that it is useful
Console.WriteLine ("Was using " + startingMem / 1024 / 1024 + "MB, now using: " + System.Diagnostics.Process.GetCurrentProcess ().WorkingSet64 / 1024 / 1024 + "MB"); Console.WriteLine ("Was using " + startingMem / 1024 / 1024 + "MB, now using: " + System.Diagnostics.Process.GetCurrentProcess ().WorkingSet64 / 1024 / 1024 + "MB");
#endif
} }
private void _Calc (Lua lua, int i) private void _Calc (Lua lua, int i)
...@@ -179,7 +190,7 @@ namespace NLuaTest ...@@ -179,7 +190,7 @@ namespace NLuaTest
while (completed < iterations && !failureDetected) while (completed < iterations && !failureDetected)
Thread.Sleep (50); Thread.Sleep (50);
Assert.False (failureDetected); Assert.AreEqual (false, failureDetected);
} }
} }
...@@ -195,11 +206,11 @@ namespace NLuaTest ...@@ -195,11 +206,11 @@ namespace NLuaTest
try { try {
lua.DoString ("test:_PrivateMethod()"); lua.DoString ("test:_PrivateMethod()");
} catch { } catch {
Assert.True (true); Assert.AreEqual (true, true);
return; return;
} }
Assert.True (false); Assert.AreEqual(true, false);
} }
} }
...@@ -324,10 +335,10 @@ namespace NLuaTest ...@@ -324,10 +335,10 @@ namespace NLuaTest
//Cause the event to be fired //Cause the event to be fired
entity.Click (); entity.Click ();
//failed //failed
Assert.True (false); Assert.AreEqual(true, false);
} catch (LuaException) { } catch (LuaException) {
//passed //passed
Assert.True (true); Assert.AreEqual (true, true);
} }
} }
} }
...@@ -339,7 +350,7 @@ namespace NLuaTest ...@@ -339,7 +350,7 @@ namespace NLuaTest
try { try {
lua.DoString ("thiswillthrowanerror", "MyChunk"); lua.DoString ("thiswillthrowanerror", "MyChunk");
} catch (Exception e) { } catch (Exception e) {
Assert.True (e.Message.StartsWith ("[string \"MyChunk\"]")); Assert.AreEqual (true, e.Message.StartsWith ("[string \"MyChunk\"]"));
} }
} }
} }
...@@ -371,8 +382,8 @@ namespace NLuaTest ...@@ -371,8 +382,8 @@ namespace NLuaTest
} catch { } catch {
} }
Assert.True (classWithGenericMethod.GenericMethodSuccess); Assert.AreEqual (true, classWithGenericMethod.GenericMethodSuccess);
Assert.True (classWithGenericMethod.Validate<double> (100)); //note the gotcha: numbers are all being passed to generic methods as doubles Assert.AreEqual (true, classWithGenericMethod.Validate<double> (100)); //note the gotcha: numbers are all being passed to generic methods as doubles
try { try {
lua.DoString ("luanet.load_assembly('NLuaTest')"); lua.DoString ("luanet.load_assembly('NLuaTest')");
...@@ -382,7 +393,7 @@ namespace NLuaTest ...@@ -382,7 +393,7 @@ namespace NLuaTest
} catch { } catch {
} }
Assert.True (classWithGenericMethod.GenericMethodSuccess); Assert.AreEqual (true, classWithGenericMethod.GenericMethodSuccess);
Assert.AreEqual (56, (classWithGenericMethod.PassedValue as TestClass).val); Assert.AreEqual (56, (classWithGenericMethod.PassedValue as TestClass).val);
} }
} }
...@@ -414,8 +425,8 @@ namespace NLuaTest ...@@ -414,8 +425,8 @@ namespace NLuaTest
string b = (string)lua.GetString ("b"); string b = (string)lua.GetString ("b");
string c = (string)lua.GetString ("c"); string c = (string)lua.GetString ("c");
Assert.AreEqual (2, a); Assert.AreEqual (2, a);
Assert.NotNull (b); Assert.AreNotEqual (null, b);
Assert.NotNull (c); Assert.AreNotEqual (null, c);
} }
} }
...@@ -820,10 +831,10 @@ namespace NLuaTest ...@@ -820,10 +831,10 @@ namespace NLuaTest
t1.testval = 4; t1.testval = 4;
lua ["netobj"] = t1; lua ["netobj"] = t1;
object o = lua ["netobj"]; object o = lua ["netobj"];
Assert.True (o is TestClass); Assert.AreEqual (true, o is TestClass);
TestClass t2 = (TestClass)lua ["netobj"]; TestClass t2 = (TestClass)lua ["netobj"];
Assert.AreEqual (t2.testval, 4); Assert.AreEqual (t2.testval, 4);
Assert.True (t1 == t2); Assert.AreEqual (t1 , t2);
} }
} }
///* ///*
...@@ -857,8 +868,8 @@ namespace NLuaTest ...@@ -857,8 +868,8 @@ namespace NLuaTest
tab ["c"] = t1; tab ["c"] = t1;
TestClass t2 = (TestClass)lua ["a.b.c"]; TestClass t2 = (TestClass)lua ["a.b.c"];
//Console.WriteLine("a.b.c="+t2.testval); //Console.WriteLine("a.b.c="+t2.testval);
Assert.AreEqual (t2.testval, 4); Assert.AreEqual (4, t2.testval);
Assert.True (t1 == t2); Assert.AreEqual (t1 , t2);
} }
} }
/* /*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment