Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
NLua
Commits
469c964b
Unverified
Commit
469c964b
authored
Feb 09, 2019
by
Vinicius Jarina
Committed by
GitHub
Feb 09, 2019
Browse files
Cleanup tests. (#277)
parent
5e9a190a
Changes
41
Hide whitespace changes
Inline
Side-by-side
tests/src/TestTypes/LuaTestDelegate4Handler.cs
0 → 100644
View file @
469c964b
namespace
NLuaTest.TestTypes
{
class
LuaTestDelegate4Handler
:
NLua
.
Method
.
LuaDelegate
{
TestClass
CallFunction
(
int
a
,
int
b
)
{
object
[]
args
=
{
a
,
b
};
object
[]
inArgs
=
{
a
,
b
};
int
[]
outArgs
=
{
};
object
ret
=
CallFunction
(
args
,
inArgs
,
outArgs
);
return
(
TestClass
)
ret
;
}
}
}
\ No newline at end of file
tests/src/TestTypes/LuaTestDelegate5Handler.cs
0 → 100644
View file @
469c964b
namespace
NLuaTest.TestTypes
{
class
LuaTestDelegate5Handler
:
NLua
.
Method
.
LuaDelegate
{
int
CallFunction
(
TestClass
a
,
TestClass
b
)
{
object
[]
args
=
{
a
,
b
};
object
[]
inArgs
=
{
a
,
b
};
int
[]
outArgs
=
{
};
object
ret
=
CallFunction
(
args
,
inArgs
,
outArgs
);
return
(
int
)
ret
;
}
}
}
\ No newline at end of file
tests/src/TestTypes/LuaTestDelegate6Handler.cs
0 → 100644
View file @
469c964b
namespace
NLuaTest.TestTypes
{
class
LuaTestDelegate6Handler
:
NLua
.
Method
.
LuaDelegate
{
int
CallFunction
(
int
a
,
ref
TestClass
b
)
{
object
[]
args
=
{
a
,
b
};
object
[]
inArgs
=
{
a
};
int
[]
outArgs
=
{
1
};
object
ret
=
CallFunction
(
args
,
inArgs
,
outArgs
);
b
=
(
TestClass
)
args
[
1
];
return
(
int
)
ret
;
}
}
}
\ No newline at end of file
tests/src/TestTypes/LuaTestDelegate7Handler.cs
0 → 100644
View file @
469c964b
namespace
NLuaTest.TestTypes
{
class
LuaTestDelegate7Handler
:
NLua
.
Method
.
LuaDelegate
{
void
CallFunction
(
int
a
,
ref
TestClass
b
)
{
object
[]
args
=
{
a
,
b
};
object
[]
inArgs
=
{
a
,
b
};
int
[]
outArgs
=
{
1
};
CallFunction
(
args
,
inArgs
,
outArgs
);
b
=
(
TestClass
)
args
[
1
];
}
}
}
\ No newline at end of file
tests/src/TestTypes/Master.cs
0 → 100644
View file @
469c964b
namespace
NLuaTest.TestTypes
{
public
class
Master
{
public
static
string
read
()
{
return
"test-master"
;
}
public
static
string
read
(
Parameter
test
)
{
return
test
.
field1
;
}
}
}
\ No newline at end of file
tests/src/TestTypes/MyClass.cs
0 → 100644
View file @
469c964b
namespace
NLuaTest.TestTypes
{
class
MyClass
{
public
int
Func1
()
{
return
1
;
}
}
}
\ No newline at end of file
tests/src/TestTypes/Parameter.cs
0 → 100644
View file @
469c964b
namespace
NLuaTest.TestTypes
{
public
class
Parameter
{
public
string
field1
=
"parameter-field1"
;
}
}
\ No newline at end of file
tests/src/TestTypes/Person.cs
0 → 100644
View file @
469c964b
namespace
NLuaTest.TestTypes
{
public
class
Person
{
public
string
firstName
;
}
}
\ No newline at end of file
tests/src/TestTypes/PersonExtensions.cs
0 → 100644
View file @
469c964b
namespace
NLuaTest.TestTypes
{
public
static
class
PersonExtensions
{
public
static
string
GetFirstName
(
this
Person
argPerson
)
{
return
argPerson
.
firstName
;
}
}
}
\ No newline at end of file
tests/src/TestTypes/TestCaseName.cs
0 → 100644
View file @
469c964b
namespace
NLuaTest.TestTypes
{
public
class
TestCaseName
{
public
string
name
=
"name"
;
public
string
Name
=>
"**"
+
name
+
"**"
;
}
}
\ No newline at end of file
tests/src/Test
Lua
.cs
→
tests/src/Test
Types/TestClass
.cs
View file @
469c964b
using
System
;
using
System
;
using
NLua
;
using
NLua
;
using
System.Threading
;
namespace
NLuaTest.
Mock
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
);
/* Delegate Lua-handlers */
class
LuaTestDelegate1Handler
:
NLua
.
Method
.
LuaDelegate
{
int
CallFunction
(
int
a
,
int
b
)
{
object
[]
args
=
new
object
[]
{
a
,
b
};
object
[]
inArgs
=
new
object
[]
{
a
,
b
};
int
[]
outArgs
=
new
int
[]
{
};
object
ret
=
base
.
CallFunction
(
args
,
inArgs
,
outArgs
);
return
(
int
)
ret
;
}
}
class
LuaTestDelegate2Handler
:
NLua
.
Method
.
LuaDelegate
{
int
CallFunction
(
int
a
,
out
int
b
)
{
object
[]
args
=
new
object
[]
{
a
,
0
};
object
[]
inArgs
=
new
object
[]
{
a
};
int
[]
outArgs
=
new
int
[]
{
1
};
object
ret
=
base
.
CallFunction
(
args
,
inArgs
,
outArgs
);
b
=
(
int
)
args
[
1
];
return
(
int
)
ret
;
}
}
class
LuaTestDelegate3Handler
:
NLua
.
Method
.
LuaDelegate
{
void
CallFunction
(
int
a
,
ref
int
b
)
{
object
[]
args
=
new
object
[]
{
a
,
b
};
object
[]
inArgs
=
new
object
[]
{
a
,
b
};
int
[]
outArgs
=
new
int
[]
{
1
};
base
.
CallFunction
(
args
,
inArgs
,
outArgs
);
b
=
(
int
)
args
[
1
];
}
}
class
LuaTestDelegate4Handler
:
NLua
.
Method
.
LuaDelegate
{
TestClass
CallFunction
(
int
a
,
int
b
)
{
object
[]
args
=
new
object
[]
{
a
,
b
};
object
[]
inArgs
=
new
object
[]
{
a
,
b
};
int
[]
outArgs
=
new
int
[]
{
};
object
ret
=
base
.
CallFunction
(
args
,
inArgs
,
outArgs
);
return
(
TestClass
)
ret
;
}
}
class
LuaTestDelegate5Handler
:
NLua
.
Method
.
LuaDelegate
{
int
CallFunction
(
TestClass
a
,
TestClass
b
)
{
object
[]
args
=
new
object
[]
{
a
,
b
};
object
[]
inArgs
=
new
object
[]
{
a
,
b
};
int
[]
outArgs
=
new
int
[]
{
};
object
ret
=
base
.
CallFunction
(
args
,
inArgs
,
outArgs
);
return
(
int
)
ret
;
}
}
class
LuaTestDelegate6Handler
:
NLua
.
Method
.
LuaDelegate
{
int
CallFunction
(
int
a
,
ref
TestClass
b
)
{
object
[]
args
=
new
object
[]
{
a
,
b
};
object
[]
inArgs
=
new
object
[]
{
a
};
int
[]
outArgs
=
new
int
[]
{
1
};
object
ret
=
base
.
CallFunction
(
args
,
inArgs
,
outArgs
);
b
=
(
TestClass
)
args
[
1
];
return
(
int
)
ret
;
}
}
class
LuaTestDelegate7Handler
:
NLua
.
Method
.
LuaDelegate
{
void
CallFunction
(
int
a
,
ref
TestClass
b
)
{
object
[]
args
=
new
object
[]
{
a
,
b
};
object
[]
inArgs
=
new
object
[]
{
a
,
b
};
int
[]
outArgs
=
new
int
[]
{
1
};
base
.
CallFunction
(
args
,
inArgs
,
outArgs
);
b
=
(
TestClass
)
args
[
1
];
}
}
/*
* Interface used for testing Lua table -> interface translation
*/
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
);
}
public
interface
IFoo1
{
int
foo
();
}
public
interface
IFoo2
{
int
foo
();
}
class
MyClass
{
public
int
Func1
()
{
return
1
;
}
}
/// <summary>
/// Use to test threading
/// </summary>
class
DoWorkClass
{
public
void
DoWork
()
{
//simulate work by sleeping
//Console.WriteLine("Started to do work on thread: " + Thread.CurrentThread.ManagedThreadId);
Thread
.
Sleep
(
new
Random
().
Next
(
0
,
1000
));
//Console.WriteLine("Finished work on thread: " + Thread.CurrentThread.ManagedThreadId);
}
}
/// <summary>
/// test structure passing
/// </summary>
public
struct
TestStruct
{
public
TestStruct
(
float
val
)
{
v
=
val
;
}
public
float
v
;
public
float
val
{
get
{
return
v
;
}
set
{
v
=
value
;
}
}
}
/// <summary>
/// test enum
/// </summary>
public
enum
TestEnum
{
ValueA
,
ValueB
}
/// <summary>
/// Generic class with generic and non-generic methods
/// </summary>
/// <typeparam name="T"></typeparam>
public
class
TestClassGeneric
<
T
>
{
private
object
_PassedValue
;
private
bool
_RegularMethodSuccess
;
public
bool
RegularMethodSuccess
{
get
{
return
_RegularMethodSuccess
;
}
}
private
bool
_GenericMethodSuccess
;
public
bool
GenericMethodSuccess
{
get
{
return
_GenericMethodSuccess
;
}
}
public
void
GenericMethod
(
T
value
)
{
_PassedValue
=
value
;
_GenericMethodSuccess
=
true
;
}
public
void
RegularMethod
()
{
_RegularMethodSuccess
=
true
;
}
/// <summary>
/// Returns true if the generic method was successfully passed a matching value
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public
bool
Validate
(
T
value
)
{
return
value
.
Equals
(
_PassedValue
);
}
}
/// <summary>
/// Normal class containing a generic method
/// </summary>
public
class
TestClassWithGenericMethod
{
private
object
_PassedValue
;
public
object
PassedValue
{
get
{
return
_PassedValue
;
}
}
private
bool
_GenericMethodSuccess
;
public
bool
GenericMethodSuccess
{
get
{
return
_GenericMethodSuccess
;
}
}
public
void
GenericMethod
<
T
>(
T
value
)
{
_PassedValue
=
value
;
_GenericMethodSuccess
=
true
;
}
internal
bool
Validate
<
T
>(
T
value
)
{
return
value
.
Equals
(
_PassedValue
);
}
}
public
class
TestClass2
{
public
static
int
func
(
int
x
,
int
y
)
{
return
x
+
y
;
}
public
int
funcInstance
(
int
x
,
int
y
)
{
return
x
+
y
;
}
}
/*
* Sample class used in several test cases to check if
* Lua scripts are accessing objects correctly
*/
public
class
TestClass
:
IFoo1
,
IFoo2
public
class
TestClass
:
IFoo1
,
IFoo2
{
{
public
int
val
;
public
int
val
;
...
@@ -472,7 +166,6 @@ namespace NLuaTest.Mock
...
@@ -472,7 +166,6 @@ namespace NLuaTest.Mock
{
{
int
a
=
3
;
int
a
=
3
;
del
(
2
,
ref
a
);
del
(
2
,
ref
a
);
//Console.WriteLine(a);
return
a
;
return
a
;
}
}
...
@@ -641,46 +334,4 @@ namespace NLuaTest.Mock
...
@@ -641,46 +334,4 @@ namespace NLuaTest.Mock
return
i
;
return
i
;
}
}
}
}
}
public
class
TestClassWithOverloadedMethod
\ No newline at end of file
{
public
int
CallsToStringFunc
{
get
;
set
;
}
public
int
CallsToIntFunc
{
get
;
set
;
}
public
void
Func
(
string
param
)
{
CallsToStringFunc
++;
}
public
void
Func
(
int
param
)
{
CallsToIntFunc
++;
}
}
public
class
TestClassWithMethodDefaultParameter
{
public
int
x
;
public
void
Func
(
string
param1
,
int
param2
=
0
,
int
param3
=
0
,
string
param
=
null
)
{
if
(
param
==
null
)
x
+=
1
;
else
if
(
param
==
"foo"
)
x
+=
2
;
else
if
(
param
==
""
)
x
+=
4
;
}
public
void
Func2
(
string
param1
,
int
param2
=
0
,
int
param3
=
0
,
string
param
=
"default"
)
{
if
(
param
==
null
)
x
+=
1
;
else
if
(
param
==
"foo"
)
x
+=
2
;
else
if
(
param
==
"default"
)
x
+=
4
;
else
if
(
param
==
""
)
x
+=
8
;
}
}
}
tests/src/TestTypes/TestClass3.cs
0 → 100644
View file @
469c964b
namespace
NLuaTest.TestTypes
{
public
class
TestClass2
{
public
static
int
func
(
int
x
,
int
y
)
{
return
x
+
y
;
}
public
int
funcInstance
(
int
x
,
int
y
)
{
return
x
+
y
;
}
}
}
\ No newline at end of file
tests/src/TestTypes/TestClassGeneric.cs
0 → 100644
View file @
469c964b
namespace
NLuaTest.TestTypes
{
/// <summary>
/// Generic class with generic and non-generic methods
/// </summary>
/// <typeparam name="T"></typeparam>
public
class
TestClassGeneric
<
T
>
{
private
object
_PassedValue
;
private
bool
_RegularMethodSuccess
;
public
bool
RegularMethodSuccess
{
get
{
return
_RegularMethodSuccess
;
}
}
private
bool
_GenericMethodSuccess
;
public
bool
GenericMethodSuccess
{
get
{
return
_GenericMethodSuccess
;
}
}
public
void
GenericMethod
(
T
value
)
{
_PassedValue
=
value
;
_GenericMethodSuccess
=
true
;
}
public
void
RegularMethod
()
{
_RegularMethodSuccess
=
true
;
}
/// <summary>
/// Returns true if the generic method was successfully passed a matching value
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public
bool
Validate
(
T
value
)
{
return
value
.
Equals
(
_PassedValue
);
}
}
}
\ No newline at end of file
tests/src/TestTypes/TestClassWithGenericMethod.cs
0 → 100644
View file @
469c964b
namespace
NLuaTest.TestTypes
{
/// <summary>
/// Normal class containing a generic method
/// </summary>
public
class
TestClassWithGenericMethod
{
private
object
_PassedValue
;
public
object
PassedValue
{
get
{
return
_PassedValue
;
}
}
private
bool
_GenericMethodSuccess
;
public
bool
GenericMethodSuccess
{
get
{
return
_GenericMethodSuccess
;
}
}
public
void
GenericMethod
<
T
>(
T
value
)
{
_PassedValue
=
value
;
_GenericMethodSuccess
=
true
;
}
internal
bool
Validate
<
T
>(
T
value
)
{
return
value
.
Equals
(
_PassedValue
);
}
}
}
\ No newline at end of file
tests/src/TestTypes/TestClassWithMethodDefaultParameter.cs
0 → 100644
View file @
469c964b
namespace
NLuaTest.TestTypes
{
public
class
TestClassWithMethodDefaultParameter
{
public
int
x
;
public
void
Func
(
string
param1
,
int
param2
=
0
,
int
param3
=
0
,
string
param
=
null
)
{
if
(
param
==
null
)
x
+=
1
;
else
if
(
param
==
"foo"
)
x
+=
2
;
else
if
(
param
==
""
)
x
+=
4
;
}
public
void
Func2
(
string
param1
,
int
param2
=
0
,
int
param3
=
0
,
string
param
=
"default"
)
{
if
(
param
==
null
)
x
+=
1
;
else
if
(
param
==
"foo"
)
x
+=
2
;
else
if
(
param
==
"default"
)
x
+=
4
;
else
if
(
param
==
""
)
x
+=
8
;
}
}
}
\ No newline at end of file
tests/src/TestTypes/TestClassWithOverloadedMethod.cs
0 → 100644
View file @
469c964b
namespace
NLuaTest.TestTypes
{
class
TestClassWithOverloadedMethod
{
public
int
CallsToStringFunc
{
get
;
set
;
}
public
int
CallsToIntFunc
{
get
;
set
;
}
public
void
Func
(
string
param
)
{
CallsToStringFunc
++;
}
public
void
Func
(
int
param
)
{
CallsToIntFunc
++;
}
}
}
\ No newline at end of file
tests/src/TestTypes/TestClassX.cs
0 → 100644
View file @
469c964b
namespace
NLuaTest.TestTypes
{
public
class
testClass
:
Master
{
public
string
strData
;
public
int
intData
;
public
static
string
read2
()
{
return
"test"
;
}
public
static
string
read
(
int
test
)
{
return
"int-test"
;
}
}
}
\ No newline at end of file
tests/src/TestTypes/TestEnum.cs
0 → 100644
View file @
469c964b
namespace
NLuaTest.TestTypes
{
/// <summary>
/// test enum
/// </summary>
public
enum
TestEnum
{
ValueA
,
ValueB
}
}
\ No newline at end of file
tests/src/TestTypes/TestStruct.cs
0 → 100644
View file @
469c964b
namespace
NLuaTest.TestTypes
{
/// <summary>
/// test structure passing
/// </summary>
public
struct
TestStruct
{
public
TestStruct
(
float
val
)
{
v
=
val
;
}
public
float
v
;
public
float
val
{
get
{
return
v
;
}
set
{
v
=
value
;
}
}
}
}
\ No newline at end of file
tests/src/TestTypes/Vector.cs
0 → 100644
View file @
469c964b
using
System
;
namespace
NLuaTest.TestTypes
{
public
class
Vector
{
public
double
x
;
public
double
y
;
public
static
Vector
operator
*(
float
k
,
Vector
v
)
{
var
r
=
new
Vector
();
r
.
x
=
v
.
x
*
k
;
r
.
y
=
v
.
y
*
k
;
return
r
;
}
public
static
Vector
operator
*(
Vector
v
,
float
k
)
{
var
r
=
new
Vector
();
r
.
x
=
v
.
x
*
k
;
r
.
y
=
v
.
y
*
k
;
return
r
;
}
public
void
Func
()
{
Console
.
WriteLine
(
"Func"
);
}
}
}
\ No newline at end of file
Prev
1
2
3
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment