Unverified Commit 469c964b authored by Vinicius Jarina's avatar Vinicius Jarina Committed by GitHub
Browse files

Cleanup tests. (#277)

parent 5e9a190a
......@@ -778,7 +778,7 @@ namespace NLua
public void LoadCLRPackage()
{
_luaState.DoString(Lua.clr_package);
_luaState.DoString(clr_package);
}
/*
* Gets a function global variable as a delegate of
......
using System;
using NLua;
namespace NLuaTest.TestTypes
{
class LuaITestClassHandler : ILuaGeneratedType, ITest
{
public LuaTable __luaInterface_luaTable;
public Type[][] __luaInterface_returnTypes;
public LuaITestClassHandler(LuaTable luaTable, Type[][] returnTypes)
{
__luaInterface_luaTable = luaTable;
__luaInterface_returnTypes = returnTypes;
}
public LuaTable LuaInterfaceGetLuaTable()
{
return __luaInterface_luaTable;
}
public int intProp
{
get
{
object[] args = { __luaInterface_luaTable };
object[] inArgs = { __luaInterface_luaTable };
int[] outArgs = { };
Type[] returnTypes = __luaInterface_returnTypes[0];
LuaFunction function = NLua.Method.LuaClassHelper.GetTableFunction(__luaInterface_luaTable, "get_intProp");
object ret = NLua.Method.LuaClassHelper.CallFunction(function, args, returnTypes, inArgs, outArgs);
return (int)ret;
}
set
{
int i = value;
object[] args = {
__luaInterface_luaTable ,
i
};
object[] inArgs = {
__luaInterface_luaTable,
i
};
int[] outArgs = { };
Type[] returnTypes = __luaInterface_returnTypes[1];
LuaFunction function = NLua.Method.LuaClassHelper.GetTableFunction(__luaInterface_luaTable, "set_intProp");
NLua.Method.LuaClassHelper.CallFunction(function, args, returnTypes, inArgs, outArgs);
}
}
public TestClass refProp
{
get
{
object[] args = { __luaInterface_luaTable };
object[] inArgs = { __luaInterface_luaTable };
int[] outArgs = { };
Type[] returnTypes = __luaInterface_returnTypes[2];
LuaFunction function = NLua.Method.LuaClassHelper.GetTableFunction(__luaInterface_luaTable, "get_refProp");
object ret = NLua.Method.LuaClassHelper.CallFunction(function, args, returnTypes, inArgs, outArgs);
return (TestClass)ret;
}
set
{
TestClass test = value;
object[] args = {
__luaInterface_luaTable ,
test
};
object[] inArgs = {
__luaInterface_luaTable,
test
};
int[] outArgs = { };
Type[] returnTypes = __luaInterface_returnTypes[3];
LuaFunction function = NLua.Method.LuaClassHelper.GetTableFunction(__luaInterface_luaTable, "set_refProp");
NLua.Method.LuaClassHelper.CallFunction(function, args, returnTypes, inArgs, outArgs);
}
}
public int test1(int a, int b)
{
object[] args = {
__luaInterface_luaTable,
a,
b
};
object[] inArgs = {
__luaInterface_luaTable,
a,
b
};
int[] outArgs = { };
Type[] returnTypes = __luaInterface_returnTypes[4];
LuaFunction function = NLua.Method.LuaClassHelper.GetTableFunction(__luaInterface_luaTable, "test1");
object ret = NLua.Method.LuaClassHelper.CallFunction(function, args, returnTypes, inArgs, outArgs);
return (int)ret;
}
public int test2(int a, out int b)
{
object[] args = {
__luaInterface_luaTable,
a,
0
};
object[] inArgs = {
__luaInterface_luaTable,
a
};
int[] outArgs = { 1 };
Type[] returnTypes = __luaInterface_returnTypes[5];
LuaFunction function = NLua.Method.LuaClassHelper.GetTableFunction(__luaInterface_luaTable, "test2");
object ret = NLua.Method.LuaClassHelper.CallFunction(function, args, returnTypes, inArgs, outArgs);
b = (int)args[1];
return (int)ret;
}
public void test3(int a, ref int b)
{
object[] args = {
__luaInterface_luaTable,
a,
b
};
object[] inArgs = {
__luaInterface_luaTable,
a,
b
};
int[] outArgs = { 1 };
Type[] returnTypes = __luaInterface_returnTypes[6];
LuaFunction function = NLua.Method.LuaClassHelper.GetTableFunction(__luaInterface_luaTable, "test3");
NLua.Method.LuaClassHelper.CallFunction(function, args, returnTypes, inArgs, outArgs);
b = (int)args[1];
}
public TestClass test4(int a, int b)
{
object[] args = {
__luaInterface_luaTable,
a,
b
};
object[] inArgs = {
__luaInterface_luaTable,
a,
b
};
int[] outArgs = { };
Type[] returnTypes = __luaInterface_returnTypes[7];
LuaFunction function = NLua.Method.LuaClassHelper.GetTableFunction(__luaInterface_luaTable, "test4");
object ret = NLua.Method.LuaClassHelper.CallFunction(function, args, returnTypes, inArgs, outArgs);
return (TestClass)ret;
}
public int test5(TestClass a, TestClass b)
{
object[] args = {
__luaInterface_luaTable,
a,
b
};
object[] inArgs = {
__luaInterface_luaTable,
a,
b
};
int[] outArgs = { };
Type[] returnTypes = __luaInterface_returnTypes[8];
LuaFunction function = NLua.Method.LuaClassHelper.GetTableFunction(__luaInterface_luaTable, "test5");
object ret = NLua.Method.LuaClassHelper.CallFunction(function, args, returnTypes, inArgs, outArgs);
return (int)ret;
}
public int test6(int a, out TestClass b)
{
object[] args = {
__luaInterface_luaTable,
a,
null
};
object[] inArgs = {
__luaInterface_luaTable,
a,
};
int[] outArgs = { 1 };
Type[] returnTypes = __luaInterface_returnTypes[9];
LuaFunction function = NLua.Method.LuaClassHelper.GetTableFunction(__luaInterface_luaTable, "test6");
object ret = NLua.Method.LuaClassHelper.CallFunction(function, args, returnTypes, inArgs, outArgs);
b = (TestClass)args[1];
return (int)ret;
}
public void test7(int a, ref TestClass b)
{
object[] args = {
__luaInterface_luaTable,
a,
b
};
object[] inArgs = {
__luaInterface_luaTable,
a,
b
};
int[] outArgs = { 1 };
Type[] returnTypes = __luaInterface_returnTypes[10];
LuaFunction function = NLua.Method.LuaClassHelper.GetTableFunction(__luaInterface_luaTable, "test7");
NLua.Method.LuaClassHelper.CallFunction(function, args, returnTypes, inArgs, outArgs);
b = (TestClass)args[1];
}
}
}
using System;
using NLua;
namespace NLuaTest.TestTypes
{
class LuaTestClassHandler : TestClass, ILuaGeneratedType
{
public LuaTable __luaInterface_luaTable;
public Type[][] __luaInterface_returnTypes;
public LuaTestClassHandler(LuaTable luaTable, Type[][] returnTypes)
{
__luaInterface_luaTable = luaTable;
__luaInterface_returnTypes = returnTypes;
}
public LuaTable LuaInterfaceGetLuaTable()
{
return __luaInterface_luaTable;
}
public override int overridableMethod(int x, int y)
{
object[] args = new object[] {
__luaInterface_luaTable,
x,
y
};
object[] inArgs = new object[] {
__luaInterface_luaTable,
x,
y
};
int[] outArgs = new int[] { };
Type[] returnTypes = __luaInterface_returnTypes[0];
LuaFunction function = NLua.Method.LuaClassHelper.GetTableFunction(__luaInterface_luaTable, "overridableMethod");
object ret = NLua.Method.LuaClassHelper.CallFunction(function, args, returnTypes, inArgs, outArgs);
return (int)ret;
}
}
}
using System;
using System.Text;
using System.Collections.Generic;
using NUnit.Framework;
using NLuaTest.Mock;
using System.Reflection;
using System.Threading;
using NLua;
using NLua.Exceptions;
#if !__TVOS__ && !__IOS__ && !__WATCHOS__
using NLuaTest.TestTypes;
#if !__TVOS__ && !__IOS__ && !__WATCHOS__
namespace NLuaTest
{
[TestFixture]
public class AAACodeGenTests
public class CodeGenTests
{
/*
* Tests passing a Lua function to a delegate
......@@ -26,7 +29,7 @@ namespace NLuaTest
using (Lua lua = new Lua())
{
lua.DoString("luanet.load_assembly('NLuaTest')");
lua.DoString("TestClass=luanet.import_type('NLuaTest.Mock.TestClass')");
lua.DoString("TestClass=luanet.import_type('NLuaTest.TestTypes.TestClass')");
lua.DoString("test=TestClass()");
lua.DoString("function func(x,y) return x+y; end");
lua.DoString("test=TestClass()");
......@@ -46,7 +49,7 @@ namespace NLuaTest
using (Lua lua = new Lua())
{
lua.DoString("luanet.load_assembly('NLuaTest')");
lua.DoString("TestClass=luanet.import_type('NLuaTest.Mock.TestClass')");
lua.DoString("TestClass=luanet.import_type('NLuaTest.TestTypes.TestClass')");
lua.DoString("test=TestClass()");
lua.DoString("function func(x) return x,x*2; end");
lua.DoString("test=TestClass()");
......@@ -66,7 +69,7 @@ namespace NLuaTest
using (Lua lua = new Lua())
{
lua.DoString("luanet.load_assembly('NLuaTest')");
lua.DoString("TestClass=luanet.import_type('NLuaTest.Mock.TestClass')");
lua.DoString("TestClass=luanet.import_type('NLuaTest.TestTypes.TestClass')");
lua.DoString("test=TestClass()");
lua.DoString("function func(x,y) return x+y; end");
lua.DoString("test=TestClass()");
......@@ -86,7 +89,7 @@ namespace NLuaTest
using (Lua lua = new Lua())
{
lua.DoString("luanet.load_assembly('NLuaTest')");
lua.DoString("TestClass=luanet.import_type('NLuaTest.Mock.TestClass')");
lua.DoString("TestClass=luanet.import_type('NLuaTest.TestTypes.TestClass')");
lua.DoString("test=TestClass()");
lua.DoString("function func(x,y) return TestClass(x+y); end");
lua.DoString("test=TestClass()");
......@@ -106,7 +109,7 @@ namespace NLuaTest
using (Lua lua = new Lua())
{
lua.DoString("luanet.load_assembly('NLuaTest')");
lua.DoString("TestClass=luanet.import_type('NLuaTest.Mock.TestClass')");
lua.DoString("TestClass=luanet.import_type('NLuaTest.TestTypes.TestClass')");
lua.DoString("test=TestClass()");
lua.DoString("function func(x,y) return x.testval+y.testval; end");
lua.DoString("a=test:callDelegate5(func)");
......@@ -125,7 +128,7 @@ namespace NLuaTest
using (Lua lua = new Lua())
{
lua.DoString("luanet.load_assembly('NLuaTest')");
lua.DoString("TestClass=luanet.import_type('NLuaTest.Mock.TestClass')");
lua.DoString("TestClass=luanet.import_type('NLuaTest.TestTypes.TestClass')");
lua.DoString("test=TestClass()");
lua.DoString("function func(x) return x,TestClass(x*2); end");
lua.DoString("test=TestClass()");
......@@ -145,7 +148,7 @@ namespace NLuaTest
using (Lua lua = new Lua())
{
lua.DoString("luanet.load_assembly('NLuaTest')");
lua.DoString("TestClass=luanet.import_type('NLuaTest.Mock.TestClass')");
lua.DoString("TestClass=luanet.import_type('NLuaTest.TestTypes.TestClass')");
lua.DoString("test=TestClass()");
lua.DoString("function func(x,y) return TestClass(x+y.testval); end");
lua.DoString("a=test:callDelegate7(func)");
......@@ -166,7 +169,7 @@ namespace NLuaTest
using (Lua lua = new Lua())
{
lua.DoString("luanet.load_assembly('NLuaTest')");
lua.DoString("TestClass=luanet.import_type('NLuaTest.Mock.TestClass')");
lua.DoString("TestClass=luanet.import_type('NLuaTest.TestTypes.TestClass')");
lua.DoString("test=TestClass()");
lua.DoString("itest={}");
lua.DoString("function itest:test1(x,y) return x+y; end");
......@@ -188,10 +191,10 @@ namespace NLuaTest
using (Lua lua = new Lua())
{
lua.DoString("luanet.load_assembly('NLuaTest')");
lua.DoString("TestClass=luanet.import_type('NLuaTest.Mock.TestClass')");
lua.DoString("TestClass=luanet.import_type('NLuaTest.TestTypes.TestClass')");
lua.DoString("test={}");
lua.DoString("function test:overridableMethod(x,y) print(self[base]); return 6 end");
lua.DoString("luanet.make_object(test,'NLuaTest.Mock.TestClass')");
lua.DoString("luanet.make_object(test,'NLuaTest.TestTypes.TestClass')");
lua.DoString("a=TestClass.callOverridable(test,2,3)");
int a = (int)lua.GetNumber("a");
lua.DoString("luanet.free_object(test)");
......
......@@ -17,7 +17,7 @@ namespace NLuaTest
#endif
public class Core
{
Lua lua = null;
Lua _lua;
string GetTestPath(string name)
{
......@@ -27,7 +27,7 @@ namespace NLuaTest
void AssertFile(string path)
{
lua.DoFile(path);
_lua.DoFile(path);
}
void TestLuaFile(string name)
......@@ -39,10 +39,10 @@ namespace NLuaTest
[SetUp]
public void Setup()
{
lua = new Lua();
lua.RegisterFunction("WriteLineString", typeof(Console).GetMethod("WriteLine", new Type[] { typeof(String) }));
_lua = new Lua();
_lua.RegisterFunction("WriteLineString", typeof(Console).GetMethod("WriteLine", new Type[] { typeof(String) }));
lua.DoString(@"
_lua.DoString(@"
function print (param)
WriteLineString (tostring(param))
end
......@@ -52,8 +52,8 @@ namespace NLuaTest
[TearDown]
public void TearDown()
{
lua.Dispose();
lua = null;
_lua.Dispose();
_lua = null;
}
[Test]
......@@ -105,6 +105,5 @@ namespace NLuaTest
{
TestLuaFile("sort");
}
}
}
......@@ -2,8 +2,6 @@ using System;
using System.IO;
using NLua;
using NLuaTest.Mock;
using NUnit.Framework;
......@@ -45,7 +43,7 @@ namespace LoadFileTests
int height = (int)(double)lua["height"];
string message = (string)lua["message"];
int color_g = (int)(double)lua["color.g"];
LuaFunction func = (LuaFunction)lua["func"];
var func = (LuaFunction)lua["func"];
object[] res = func.Call(12, 34);
int x = (int)(double)res[0];
int y = (int)(double)res[1];
......@@ -82,7 +80,7 @@ namespace LoadFileTests
int height = (int)(double)lua["height"];
string message = (string)lua["message"];
int color_g = (int)(double)lua["color.g"];
LuaFunction func = (LuaFunction)lua["func"];
var func = (LuaFunction)lua["func"];
object[] res = func.Call(12, 34);
int x = (int)(double)res[0];
int y = (int)(double)res[1];
......
This diff is collapsed.
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
......@@ -9,12 +9,45 @@
<Import_RootNamespace>NLuaTest.Shared</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)AAACodeGenTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)BinderClass\LuaITestClassHandler.cs" />
<Compile Include="$(MSBuildThisFileDirectory)BinderClass\LuaTestClassHandler.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CodeGenTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Core.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Entity.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TestTypes\DoWorkClass.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TestTypes\IFoo1.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TestTypes\IFoo2.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TestTypes\ITest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TestTypes\LuaEventArgsHandler.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TestTypes\LuaTestDelegate6Handler.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TestTypes\LuaTestDelegate7Handler.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TestTypes\MyClass.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TestTypes\TestClass.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TestTypes\TestClass3.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TestTypes\TestClassGeneric.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TestTypes\TestClassWithGenericMethod.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TestTypes\TestClassWithMethodDefaultParameter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TestTypes\TestClassWithOverloadedMethod.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TestTypes\TestEnum.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TestTypes\LuaTestDelegate5Handler.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TestTypes\LuaTestDelegate4Handler.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TestTypes\LuaTestDelegate3Handler.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TestTypes\LuaTestDelegate2Handler.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TestTypes\Delegates.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TestTypes\LuaTestDelegate1Handler.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TestTypes\TestStruct.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TestTypes\DefaultElementModel.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TestTypes\Employee.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TestTypes\Entity.cs" />
<Compile Include="$(MSBuildThisFileDirectory)LoadFileTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)LuaTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TestLua.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TestTypes\Master.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TestTypes\Parameter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TestTypes\Person.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TestTypes\PersonExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TestTypes\TestCaseName.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TestTypes\TestClassX.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Properties\AssemblyInfo.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TestTypes\Vector.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TestTypes\VectorExtension.cs" />
</ItemGroup>
</Project>
\ No newline at end of file
using System;
namespace NLuaTest.TestTypes
{
public class DefaultElementModel
{
public Action<double> DrawMe { get; set; }
}
}
\ No newline at end of file

namespace NLuaTest.TestTypes
{
/*
* Delegates used for testing Lua function -> delegate translation
*/
public delegate int TestDelegate1(int a, int b);
public delegate int TestDelegate2(int a, out int b);
public delegate void TestDelegate3(int a, ref int b);
public delegate TestClass TestDelegate4(int a, int b);
public delegate int TestDelegate5(TestClass a, TestClass b);
public delegate int TestDelegate6(int a, out TestClass b);
public delegate void TestDelegate7(int a, ref TestClass b);
}
using System;
using System.Threading;
namespace NLuaTest.TestTypes
{
/// <summary>
/// Use to test threading
/// </summary>
class DoWorkClass
{
public void DoWork()
{
//simulate work by sleeping
Thread.Sleep(new Random().Next(0, 1000));
}
}
}
\ No newline at end of file
namespace NLuaTest.TestTypes
{
public class Employee : Person
{
public string occupation;
}
}
\ No newline at end of file
using System;
namespace NLuaTest.Mock
namespace NLuaTest.TestTypes
{
public class Entity
{
......
namespace NLuaTest.TestTypes
{
public interface IFoo1
{
int foo();
}
}
\ No newline at end of file
namespace NLuaTest.TestTypes
{
public interface IFoo2
{
int foo();
}
}
\ No newline at end of file
namespace NLuaTest.TestTypes
{
public interface ITest
{
int intProp
{
get;
set;
}
TestClass refProp
{
get;
set;
}
int test1(int a, int b);
int test2(int a, out int b);
void test3(int a, ref int b);
TestClass test4(int a, int b);
int test5(TestClass a, TestClass b);
int test6(int a, out TestClass b);
void test7(int a, ref TestClass b);
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Text;
namespace NLuaTest.TestTypes
{
class LuaEventArgsHandler : NLua.Method.LuaDelegate
{
void CallFunction(object sender, EventArgs eventArgs)
{
object[] args = { sender, eventArgs };
object[] inArgs = { sender, eventArgs };
int[] outArgs = { };
CallFunction(args, inArgs, outArgs);
}
}
}

namespace NLuaTest.TestTypes
{
class LuaTestDelegate1Handler : NLua.Method.LuaDelegate
{
int CallFunction(int a, int b)
{
object[] args = { a, b };
object[] inArgs = { a, b };
int[] outArgs = { };
object ret = CallFunction(args, inArgs, outArgs);
return (int)ret;
}
}
}
namespace NLuaTest.TestTypes
{
class LuaTestDelegate2Handler : NLua.Method.LuaDelegate
{
int CallFunction(int a, out int b)
{
object[] args = { a, 0 };
object[] inArgs = { a };
int[] outArgs = { 1 };
object ret = CallFunction(args, inArgs, outArgs);
b = (int)args[1];
return (int)ret;
}
}
}
\ No newline at end of file
namespace NLuaTest.TestTypes
{
class LuaTestDelegate3Handler : NLua.Method.LuaDelegate
{
void CallFunction(int a, ref int b)
{
object[] args = { a, b };
object[] inArgs = { a, b };
int[] outArgs = { 1 };
CallFunction(args, inArgs, outArgs);
b = (int)args[1];
}
}
}
\ No newline at end of file
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