Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
add mangling tests
- Loading branch information
sergot
committed
Feb 24, 2015
1 parent
05bc000
commit 5057b18
Showing
3 changed files
with
69 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
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,27 @@ | ||
| #include <stdlib.h> | ||
|
|
||
| #ifdef WIN32 | ||
| #define DLLEXPORT __declspec(dllexport) | ||
| #else | ||
| #define DLLEXPORT extern | ||
| #endif | ||
|
|
||
| class Foo { | ||
| public: | ||
| Foo(); | ||
| ~Foo(); | ||
| virtual int TakeAVoid(void) { return 0; } | ||
| virtual int TakeABool(bool i) { return 1; } | ||
| virtual int TakeAChar(char i) { return 2; } | ||
| virtual int TakeAShort(short i) { return 3; } | ||
| virtual int TakeAnInt(int i) { return 4; } | ||
| virtual int TakeALong(long i) { return 5; } | ||
| virtual int TakeALongLong(long long i) { return 6; } | ||
| virtual int TakeAFloat(float i) { return 7; } | ||
| virtual int TakeADouble(double i) { return 8; } | ||
| virtual int TakeAString(char *i) { return 9; } | ||
| virtual int TakeAnArray(int *i) { return 10; } | ||
| }; | ||
|
|
||
| Foo::Foo(){}; | ||
| Foo::~Foo(){}; |
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 @@ | ||
| use v6; | ||
| use NativeCall; | ||
| use Test; | ||
|
|
||
| plan 8; | ||
|
|
||
| shell 'g++ --shared -fPIC -o 13-cpp-mangling.so t/04-nativecall/13-cpp-mangling.cpp'; | ||
|
|
||
| class Foo is repr<CPPStruct> { | ||
| has Pointer $.vtable; # TODO : bug - trying to allocate -1 when no attributes given | ||
|
|
||
| method new() is native("./13-cpp-mangling") is nativeconv('thisgnu') { * } # const * | ||
| method TakeAVoid() returns int32 is native("./13-cpp-mangling") { * }; | ||
| # method TakeABool(Bool) returns int32 is native("./13-cpp-mangling") { * }; | ||
| method TakeAChar(int8) returns int32 is native("./13-cpp-mangling") { * }; | ||
| method TakeAShort(int16) returns int32 is native("./13-cpp-mangling") { * }; | ||
| method TakeAnInt(int32) returns int32 is native("./13-cpp-mangling") { * }; | ||
| method TakeALong(long) returns int32 is native("./13-cpp-mangling") { * }; | ||
| method TakeALongLong(longlong) returns int32 is native("./13-cpp-mangling") { * }; | ||
| method TakeAFloat(num32) returns int32 is native("./13-cpp-mangling") { * }; | ||
| method TakeADouble(num64) returns int32 is native("./13-cpp-mangling") { * }; | ||
| method TakeAString(Str) returns int32 is native("./13-cpp-mangling") { * }; | ||
| method TakeAnArray(CArray[int32]) returns int32 is native("./13-cpp-mangling") { * }; | ||
| } | ||
|
|
||
| my $foo = Foo.new; | ||
|
|
||
| is $foo.TakeAVoid(), 0, 'void mangling'; | ||
| #is $foo.TakeABool(True), 1, 'bool mangling'; | ||
| is $foo.TakeAChar(1), 2, 'char mangling'; | ||
| is $foo.TakeAShort(1), 3, 'short mangling'; | ||
| is $foo.TakeAnInt(1), 4, 'int mangling'; | ||
| is $foo.TakeALong(1), 5, 'long mangling'; | ||
| is $foo.TakeALongLong(1), 6, 'long long mangling'; | ||
| is $foo.TakeAFloat(5e0), 7, 'float mangling'; | ||
| is $foo.TakeADouble(6e0), 8, 'double mangling'; | ||
| #is $foo.TakeAString("1"), 9, 'string mangling'; | ||
| #is $foo.TakeAnArray(CArray[int32].new), 10, 'CArray mangling'; | ||
| # TODO : add more |