Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add tests about mangling of typed pointers
  • Loading branch information
FROGGS committed Feb 24, 2015
1 parent dd53c36 commit 5bc251b
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 42 deletions.
36 changes: 22 additions & 14 deletions t/04-nativecall/13-cpp-mangling.cpp
Expand Up @@ -10,19 +10,27 @@ 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; }
virtual int TakeAPointer(void *i) { return 11; }
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; }
virtual int TakeAPointer(void *i) { return 11; }
virtual int TakeABoolPointer(bool *i) { return 12; }
virtual int TakeACharPointer(char *i) { return 13; }
virtual int TakeAShortPointer(short *i) { return 14; }
virtual int TakeAnIntPointer(int *i) { return 15; }
virtual int TakeALongPointer(long *i) { return 16; }
virtual int TakeALongLongPointer(long long *i) { return 17; }
virtual int TakeAFloatPointer(float *i) { return 18; }
virtual int TakeADoublePointer(double *i) { return 19; }
};

Foo::Foo(){};
Foo::~Foo(){};
Foo::Foo() { };
Foo::~Foo() { };
71 changes: 43 additions & 28 deletions t/04-nativecall/13-cpp-mangling.t
Expand Up @@ -2,40 +2,55 @@ use v6;
use NativeCall;
use Test;

plan 11;
plan 18;

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
has Pointer $.vtable;

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") { * };
method TakeAPointer(Pointer) returns int32 is native("./13-cpp-mangling") { * };
method new() is nativeconv('thisgnu') is native("./13-cpp-mangling") { * }
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") { * }
method TakeAPointer(Pointer) returns int32 is native("./13-cpp-mangling") { * }
# method TakeABoolPointer(Pointer[Bool]) returns int32 is native("./13-cpp-mangling") { * }
method TakeACharPointer(Pointer[int8]) returns int32 is native("./13-cpp-mangling") { * }
method TakeAShortPointer(Pointer[int16]) returns int32 is native("./13-cpp-mangling") { * }
method TakeAnIntPointer(Pointer[int32]) returns int32 is native("./13-cpp-mangling") { * }
method TakeALongPointer(Pointer[long]) returns int32 is native("./13-cpp-mangling") { * }
method TakeALongLongPointer(Pointer[longlong]) returns int32 is native("./13-cpp-mangling") { * }
method TakeAFloatPointer(Pointer[num32]) returns int32 is native("./13-cpp-mangling") { * }
method TakeADoublePointer(Pointer[num64]) 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';
is $foo.TakeAPointer, 11, 'Pointer mangling';
# TODO : add more
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';
is $foo.TakeAPointer, 11, 'Pointer mangling';
#is $foo.TakeABoolPointer(Pointer[Bool].new), 12, 'bool* mangling';
is $foo.TakeACharPointer(Pointer[int8].new), 13, 'char* mangling';
is $foo.TakeAShortPointer(Pointer[int16].new), 14, 'short* mangling';
is $foo.TakeAnIntPointer(Pointer[int32].new), 15, 'int* mangling';
is $foo.TakeALongPointer(Pointer[long].new), 16, 'long* mangling';
is $foo.TakeALongLongPointer(Pointer[longlong].new), 17, 'long long* mangling';
is $foo.TakeAFloatPointer(Pointer[num32].new), 18, 'float* mangling';
is $foo.TakeADoublePointer(Pointer[num64].new), 19, 'double* mangling';

0 comments on commit 5bc251b

Please sign in to comment.