Skip to content

Commit

Permalink
add more tests for nativesizeof()
Browse files Browse the repository at this point in the history
  • Loading branch information
FROGGS committed Oct 8, 2016
1 parent 3ca0f8b commit 677db95
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 29 deletions.
79 changes: 52 additions & 27 deletions t/04-nativecall/12-sizeof.c
Expand Up @@ -44,38 +44,63 @@ typedef struct {
char buz1;
} Buz;

DLLEXPORT int SizeofFoo() {
return sizeof(Foo);
}
struct foo1 {
char *p;
char c;
long x;
};

DLLEXPORT int SizeofBar() {
return sizeof(Bar);
}
struct foo2 {
char *p;
short x;
};

DLLEXPORT int SizeofBaz() {
return sizeof(Baz);
}
struct foo3 {
char *p;
char c;
};

DLLEXPORT int SizeofBuz() {
return sizeof(Buz);
}
struct foo4 {
short s;
char c;
};

DLLEXPORT int SizeofInt() {
return sizeof(int);
}
struct foo5 {
char c;
struct foo2 s;
};

DLLEXPORT int SizeofLng() {
return sizeof(long);
}
struct foo6 {
char c;
struct foo10 *p;
short x;
};

DLLEXPORT int SizeofPtr() {
return sizeof(void *);
}
struct foo7 {
struct foo11 *p;
short x;
char c;
};

DLLEXPORT int SizeofBool() {
return sizeof(bool);
}
struct foo8 {
struct foo2 s;
char c;
};

DLLEXPORT int SizeofSizeT() {
return sizeof(size_t);
}
DLLEXPORT int SizeofFoo() { return sizeof(Foo); }
DLLEXPORT int SizeofBar() { return sizeof(Bar); }
DLLEXPORT int SizeofBaz() { return sizeof(Baz); }
DLLEXPORT int SizeofBuz() { return sizeof(Buz); }
DLLEXPORT int SizeofInt() { return sizeof(int); }
DLLEXPORT int SizeofLng() { return sizeof(long); }
DLLEXPORT int SizeofPtr() { return sizeof(void *); }
DLLEXPORT int SizeofBool() { return sizeof(bool); }
DLLEXPORT int SizeofSizeT() { return sizeof(size_t); }
DLLEXPORT int SizeofFoo1() { return sizeof(struct foo1); }
DLLEXPORT int SizeofFoo2() { return sizeof(struct foo2); }
DLLEXPORT int SizeofFoo3() { return sizeof(struct foo3); }
DLLEXPORT int SizeofFoo4() { return sizeof(struct foo4); }
DLLEXPORT int SizeofFoo5() { return sizeof(struct foo5); }
DLLEXPORT int SizeofFoo6() { return sizeof(struct foo6); }
DLLEXPORT int SizeofFoo7() { return sizeof(struct foo7); }
DLLEXPORT int SizeofFoo8() { return sizeof(struct foo8); }
62 changes: 60 additions & 2 deletions t/04-nativecall/12-sizeof.t
Expand Up @@ -5,7 +5,7 @@ use CompileTestLib;
use NativeCall;
use Test;

plan 9;
plan 17;

compile_test_lib('12-sizeof');

Expand Down Expand Up @@ -38,6 +38,49 @@ class Buz is repr<CStruct> {
has int8 $.bar1;
}

class foo1 is repr<CStruct> {
has Str $.p;
has int8 $.c;
has long $.x;
}

class foo2 is repr<CStruct> {
has Str $.p;
has int16 $.x;
}

class foo3 is repr<CStruct> {
has Str $.p;
has int8 $.c;
}

class foo4 is repr<CStruct> {
has int16 $.s;
has int8 $.c;
}

class foo5 is repr<CStruct> {
has int8 $.c;
HAS foo2 $.s;
};

class foo6 is repr<CStruct> {
has int8 $.c;
has foo6 $.p;
has int16 $.x;
};

class foo7 is repr<CStruct> {
has foo7 $.p;
has int16 $.x;
has int8 $.c;
};

class foo8 is repr<CStruct> {
HAS foo2 $.s;
has int8 $.c;
};

sub SizeofFoo() returns int32 is native('./12-sizeof') { * }
sub SizeofBar() returns int32 is native('./12-sizeof') { * }
sub SizeofBaz() returns int32 is native('./12-sizeof') { * }
Expand All @@ -47,6 +90,14 @@ sub SizeofLng() returns int32 is native('./12-sizeof') { * }
sub SizeofPtr() returns int32 is native('./12-sizeof') { * }
sub SizeofBool() returns int32 is native('./12-sizeof') { * }
sub SizeofSizeT() returns int32 is native('./12-sizeof') { * }
sub SizeofFoo1() returns int32 is native('./12-sizeof') { * }
sub SizeofFoo2() returns int32 is native('./12-sizeof') { * }
sub SizeofFoo3() returns int32 is native('./12-sizeof') { * }
sub SizeofFoo4() returns int32 is native('./12-sizeof') { * }
sub SizeofFoo5() returns int32 is native('./12-sizeof') { * }
sub SizeofFoo6() returns int32 is native('./12-sizeof') { * }
sub SizeofFoo7() returns int32 is native('./12-sizeof') { * }
sub SizeofFoo8() returns int32 is native('./12-sizeof') { * }

is nativesizeof(Foo), SizeofFoo(), 'sizeof(Foo)';
is nativesizeof(Bar), SizeofBar(), 'sizeof(Bar)';
Expand All @@ -57,4 +108,11 @@ is nativesizeof(long), SizeofLng(), 'sizeof(long)';
is nativesizeof(Pointer), SizeofPtr(), 'sizeof(Pointer)';
is nativesizeof(bool), SizeofBool(), 'sizeof(bool)';
is nativesizeof(size_t), SizeofSizeT(), 'sizeof(size_t)';

is nativesizeof(foo1), SizeofFoo1(), 'sizeof(foo1)';
is nativesizeof(foo2), SizeofFoo2(), 'sizeof(foo2)';
is nativesizeof(foo3), SizeofFoo3(), 'sizeof(foo3)';
is nativesizeof(foo4), SizeofFoo4(), 'sizeof(foo4)';
is nativesizeof(foo5), SizeofFoo5(), 'sizeof(foo5)';
is nativesizeof(foo6), SizeofFoo6(), 'sizeof(foo6)';
is nativesizeof(foo7), SizeofFoo7(), 'sizeof(foo7)';
is nativesizeof(foo8), SizeofFoo8(), 'sizeof(foo8)';

0 comments on commit 677db95

Please sign in to comment.