Skip to content

Commit

Permalink
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
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/NativeCall.pm
Expand Up @@ -461,9 +461,9 @@ sub cpp_param_letter($type, :$R = '', :$P = '', :$K = '') {
when long {
$R ~ $K ~ 'l'
}
#~ when longlong {
#~ $R ~ 'x'
#~ }
when longlong {
$R ~ 'x'
}
when num32 {
$R ~ $K ~ 'f'
}
Expand Down
27 changes: 27 additions & 0 deletions t/04-nativecall/13-cpp-mangling.cpp
@@ -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(){};
39 changes: 39 additions & 0 deletions t/04-nativecall/13-cpp-mangling.t
@@ -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

0 comments on commit 5057b18

Please sign in to comment.