Skip to content

Commit

Permalink
Merge pull request Tencent#153 from lindaluo1113/master
Browse files Browse the repository at this point in the history
增加UT用例
  • Loading branch information
chexiongsheng authored May 17, 2017
2 parents d6558b9 + 022fc7c commit 39c3202
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 3 deletions.
25 changes: 25 additions & 0 deletions Test/UnitTest/StreamingAssets/luaCallCs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2292,4 +2292,29 @@ function CMyTestCaseLuaCallCS.CaseFirstPushEnum(self)
ASSERT_EQ(ret, "1")
local ret = CS.LuaTestObj.FirstPushEnumFunc(2)
ASSERT_EQ(ret, "4")
end

function CMyTestCaseLuaCallCS.CaseReferTestClass(self)
self.count = 1 + self.count
local int_x = 10
local int_y = 12
local str_z = "abc"
local class1, ret_y, ret_z = CS.ReferTestClass(int_x, int_y)
local ret = class1:Get_X_Y_ADD()
ASSERT_EQ(ret, 22)
ASSERT_EQ(ret_y, 11)
ASSERT_EQ(ret_z, "test1")

local class3, ret_z = CS.ReferTestClass(int_x)
local ret = class3:Get_X_Y_ADD()
ASSERT_EQ(ret, 20)
ASSERT_EQ(ret_z, "test3")
end

function CMyTestCaseLuaCallCS.CaseVariableParamFuncNoParam(self)
self.count = 1 + self.count
local ret = CS.LuaTestObj.VariableParamFunc2()
ASSERT_EQ(ret, 0)
local ret = CS.LuaTestObj.VariableParamFunc2("abc", "haha")
ASSERT_EQ(ret, 2)
end
25 changes: 25 additions & 0 deletions Test/UnitTest/StreamingAssets/luaCallCsReflect.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1132,4 +1132,29 @@ function CMyTestCaseLuaCallCSReflect.CaseFirstPushEnum(self)
ASSERT_EQ(ret, "1")
local ret = CS.LuaTestObjReflect.FirstPushEnumFunc(2)
ASSERT_EQ(ret, "4")
end

function CMyTestCaseLuaCallCSReflect.CaseReferTestClass(self)
self.count = 1 + self.count
local int_x = 10
local int_y = 12
local str_z = "abc"
local class1, ret_y, ret_z = CS.ReferTestClassReflect(int_x, int_y)
local ret = class1:Get_X_Y_ADD()
ASSERT_EQ(ret, 22)
ASSERT_EQ(ret_y, 11)
ASSERT_EQ(ret_z, "test1")

local class3, ret_z = CS.ReferTestClassReflect(int_x)
local ret = class3:Get_X_Y_ADD()
ASSERT_EQ(ret, 20)
ASSERT_EQ(ret_z, "test3")
end

function CMyTestCaseLuaCallCSReflect.CaseVariableParamFuncNoParam(self)
self.count = 1 + self.count
local ret = CS.LuaTestObjReflect.VariableParamFunc2()
ASSERT_EQ(ret, 0)
local ret = CS.LuaTestObjReflect.VariableParamFunc2("abc", "haha")
ASSERT_EQ(ret, 2)
end
4 changes: 2 additions & 2 deletions Test/UnitTest/StreamingAssets/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ co = coroutine.create(function()

AddLTestSuite(CMyTestCaseLuaCallCS:new(), "CMyTestCaseLuaCallCS", "Case")
AddLTestSuite(CMyTestCaseLuaCallCSReflect:new(), "CMyTestCaseLuaCallCSReflect", "Case")
AddLTestSuite(CMyTestCaseGenCode:new(), "CMyTestCaseGenCode", "Case")
--AddLTestSuite(CMyTestCaseGenCode:new(), "CMyTestCaseGenCode", "Case")
AddLTestSuite(CMyTestCaseCSCallLua:new(), "CMyTestCaseCSCallLua", "test")
--AddLTestSuite(CMyTestCaseLuaTdr:new(), "CMyTestCaseLuaTdr", "Case")

Expand All @@ -59,7 +59,7 @@ function main()

AddLTestSuite(CMyTestCaseLuaCallCS:new(), "CMyTestCaseLuaCallCS", "Case")
AddLTestSuite(CMyTestCaseLuaCallCSReflect:new(), "CMyTestCaseLuaCallCSReflect", "Case")
AddLTestSuite(CMyTestCaseGenCode:new(), "CMyTestCaseGenCode", "Case")
--AddLTestSuite(CMyTestCaseGenCode:new(), "CMyTestCaseGenCode", "Case")
AddLTestSuite(CMyTestCaseCSCallLua:new(), "CMyTestCaseCSCallLua", "test")
--AddLTestSuite(CMyTestCaseLuaTdr:new(), "CMyTestCaseLuaTdr", "Case")
RunAllTests(CMyTestEnv:new())
Expand Down
38 changes: 37 additions & 1 deletion Test/UnitTest/xLuaTest/LuaTestObj.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,12 @@ public static int VariableParamFunc(int i, params string[] strs)
{
return 0;
}


public static int VariableParamFunc2(params int[] strs)
{
return strs.Length;
}

public static int TestEnumFunc(LuaTestType x)
{
return (int)x;
Expand Down Expand Up @@ -1938,4 +1943,35 @@ public int TwoDimensionListMethod(int[][] args)
}
return value;
}
}

//验证构造函数支持refer,out修饰符,[email protected] for v2.1.7
[LuaCallCSharp]
public class ReferTestClass
{
public ReferTestClass(int x, ref int y, out string z)
{
var_x = x;
var_y = y;
y = y - 1;
z = "test1";
var_z = z;
}

public ReferTestClass(int x, out string z)
{
var_x = x;
var_y = 10;
z = "test3";
var_z = z;
}

public int Get_X_Y_ADD()
{
return var_x + var_y;
}

private int var_x;
private int var_y;
private string var_z;
}
36 changes: 36 additions & 0 deletions Test/UnitTest/xLuaTest/LuaTestObjReflect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,11 @@ public static int VariableParamFunc(int i, params int[] strs)
return 0;
}

public static int VariableParamFunc2(params int[] strs)
{
return strs.Length;
}

public static string FirstPushEnumFunc(int i)
{
string luaScript = @"
Expand Down Expand Up @@ -995,4 +1000,35 @@ public int TwoDimensionListMethod(int[][] args)
}
return value;
}
}


//验证构造函数支持refer,out修饰符,[email protected] for v2.1.7
public class ReferTestClassReflect
{
public ReferTestClassReflect(int x, ref int y, out string z)
{
var_x = x;
var_y = y;
y = y - 1;
z = "test1";
var_z = z;
}

public ReferTestClassReflect(int x, out string z)
{
var_x = x;
var_y = 10;
z = "test3";
var_z = z;
}

public int Get_X_Y_ADD()
{
return var_x + var_y;
}

private int var_x;
private int var_y;
private string var_z;
}

0 comments on commit 39c3202

Please sign in to comment.