-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented aliases for exported-functions and variables #9
- Loading branch information
Showing
9 changed files
with
302 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016-2017 Denis Kuzmin <entry.reg@gmail.com> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Conari"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
namespace net.r_eg.Conari.Aliases | ||
{ | ||
public interface IAlias | ||
{ | ||
/// <summary> | ||
/// The final name. | ||
/// </summary> | ||
string Name { get; set; } | ||
|
||
/// <summary> | ||
/// Configuration of alias. | ||
/// </summary> | ||
IAliasCfg Cfg { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016-2017 Denis Kuzmin <entry.reg@gmail.com> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Conari"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
namespace net.r_eg.Conari.Aliases | ||
{ | ||
public interface IAliasCfg | ||
{ | ||
//TODO: PrefixL/R, the rules of mangling, ... | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016-2017 Denis Kuzmin <entry.reg@gmail.com> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Conari"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
using System; | ||
|
||
namespace net.r_eg.Conari.Aliases | ||
{ | ||
public struct ProcAlias: IAlias | ||
{ | ||
/// <summary> | ||
/// The final name. | ||
/// </summary> | ||
public string Name | ||
{ | ||
get { | ||
return _name; | ||
} | ||
set | ||
{ | ||
if(String.IsNullOrWhiteSpace(value)) { | ||
throw new ArgumentException("The value cannot be null or empty."); | ||
} | ||
_name = value; | ||
} | ||
} | ||
private string _name; | ||
|
||
/// <summary> | ||
/// Configuration of alias. | ||
/// </summary> | ||
public IAliasCfg Cfg | ||
{ | ||
get; | ||
private set; | ||
} | ||
|
||
public static implicit operator string(ProcAlias pa) | ||
{ | ||
return pa.Name; | ||
} | ||
|
||
public static implicit operator ProcAlias(string str) | ||
{ | ||
return new ProcAlias() { | ||
Name = str | ||
}; | ||
} | ||
|
||
public ProcAlias(string name) | ||
: this() | ||
{ | ||
Name = name; | ||
} | ||
|
||
// TODO: cfg | ||
public ProcAlias(string name, IAliasCfg cfg) | ||
: this(name) | ||
{ | ||
Cfg = cfg; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
using System; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using net.r_eg.Conari; | ||
using net.r_eg.Conari.Aliases; | ||
using net.r_eg.Conari.Core; | ||
using net.r_eg.Conari.Types; | ||
|
||
namespace net.r_eg.ConariTest | ||
{ | ||
[TestClass] | ||
public class AliasesTest | ||
{ | ||
private const string UNLIB_DLL = "UnLib.dll"; | ||
|
||
[TestMethod] | ||
public void aliasTest1() | ||
{ | ||
// bool net::r_eg::Conari::UnLib::API::getD_True(void) | ||
// ?getD_True@API@UnLib@Conari@r_eg@net@@YA_NXZ | ||
|
||
using(var l = new ConariL(UNLIB_DLL)) | ||
{ | ||
l.Aliases["getD_True"] = new ProcAlias("?getD_True@API@UnLib@Conari@r_eg@net@@YA_NXZ"); | ||
|
||
Assert.AreEqual(true, l.DLR.getD_True<bool>()); | ||
Assert.AreEqual(true, l.bind<Func<bool>>("getD_True")()); | ||
Assert.AreEqual(true, l.bind(Dynamic.GetMethodInfo(typeof(bool)), "getD_True") | ||
.dynamic | ||
.Invoke(null, new object[0])); | ||
} | ||
} | ||
|
||
[TestMethod] | ||
public void aliasTest2() | ||
{ | ||
// unsigned short net::r_eg::Conari::UnLib::API::getD_Seven(void) | ||
// ?getD_Seven@API@UnLib@Conari@r_eg@net@@YAGXZ | ||
|
||
using(var l = new ConariL(UNLIB_DLL)) | ||
{ | ||
l.Aliases["getD_Seven"] = new ProcAlias("?getD_Seven@API@UnLib@Conari@r_eg@net@@YAGXZ"); | ||
|
||
Assert.AreEqual(7, l.DLR.getD_Seven<ushort>()); | ||
Assert.AreEqual(7, l.bind<Func<ushort>>("getD_Seven")()); | ||
Assert.AreEqual((ushort)7, l.bind(Dynamic.GetMethodInfo(typeof(ushort)), "getD_Seven") | ||
.dynamic | ||
.Invoke(null, new object[0])); | ||
} | ||
} | ||
|
||
[TestMethod] | ||
public void aliasTest3() | ||
{ | ||
// char const * net::r_eg::Conari::UnLib::API::getD_HelloWorld(void) | ||
// ?getD_HelloWorld@API@UnLib@Conari@r_eg@net@@YAPBDXZ | ||
|
||
using(var l = new ConariL(UNLIB_DLL)) | ||
{ | ||
string exp = "Hello World !"; | ||
l.Aliases["getD_HelloWorld"] = new ProcAlias("?getD_HelloWorld@API@UnLib@Conari@r_eg@net@@YAPBDXZ"); | ||
|
||
Assert.AreEqual(exp, l.DLR.getD_HelloWorld<CharPtr>()); | ||
Assert.AreEqual(exp, l.bind<Func<CharPtr>>("getD_HelloWorld")()); | ||
|
||
var dyn = l.bind(Dynamic.GetMethodInfo(typeof(CharPtr)), "getD_HelloWorld"); | ||
Assert.AreEqual(exp, (CharPtr)dyn.dynamic.Invoke(null, new object[0])); | ||
} | ||
} | ||
|
||
[TestMethod] | ||
public void multiAliasTest1() | ||
{ | ||
using(var l = new ConariL(UNLIB_DLL)) | ||
{ | ||
l.Aliases["getD_True"] = "?getD_True@API@UnLib@Conari@r_eg@net@@YA_NXZ"; | ||
l.Aliases["getFlag"] = l.Aliases["getD_True"]; | ||
|
||
Assert.AreEqual(true, l.DLR.getD_True<bool>()); | ||
Assert.AreEqual(true, l.DLR.getFlag<bool>()); | ||
Assert.AreEqual(true, l.bind<Func<bool>>("getFlag")()); | ||
Assert.AreEqual(true, l.bind(Dynamic.GetMethodInfo(typeof(bool)), "getFlag") | ||
.dynamic | ||
.Invoke(null, new object[0])); | ||
} | ||
} | ||
|
||
[TestMethod] | ||
public void multiAliasTest2() | ||
{ | ||
using(var l = new ConariL(UNLIB_DLL)) | ||
{ | ||
l.Aliases["d"] = "?getD_True@API@UnLib@Conari@r_eg@net@@YA_NXZ"; | ||
l.Aliases["a"] = l.Aliases["b"] = l.Aliases["c"] = l.Aliases["d"]; | ||
|
||
Assert.AreEqual(true, l.DLR.a<bool>()); | ||
Assert.AreEqual(true, l.DLR.b<bool>()); | ||
Assert.AreEqual(true, l.DLR.c<bool>()); | ||
Assert.AreEqual(true, l.DLR.d<bool>()); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters