Permalink
Browse files

t: update to test overload

  • Loading branch information...
ghedo committed Sep 19, 2012
1 parent 327f1d2 commit 9365c96a5d6e80087079af349c4a365ff06922e5
Showing with 77 additions and 43 deletions.
  1. +1 −1 t/01-argless.c
  2. +4 −3 t/01-argless.t
  3. +25 −17 t/02-simple-args.c
  4. +13 −6 t/02-simple-args.t
  5. +6 −0 t/03-simple-returns.t
  6. +9 −3 t/04-pointers.t
  7. +19 −13 t/05-callbacks.t
View
@@ -1,6 +1,6 @@
#include <stdio.h>
extern void argless() {
- printf("ok 1 - Called argless function\n");
+ printf("ok - argless\n");
fflush(stdout);
}
View
@@ -9,12 +9,13 @@ my $test = '01-argless';
my $source = "./t/$test.c";
my $shared = "./t/$test.so";
-print "1..2\n";
-
CompileTest::compile($source, $shared);
my $argless = FFI::Raw -> new($shared, 'argless', FFI::Raw::void);
$argless -> call;
+$argless -> ();
+
+print "ok - survived the call\n";
-print "ok 2 - survived the call\n";
+print "1..3\n";
View
@@ -2,69 +2,77 @@
extern void take_one_int(int x) {
if (x == 42)
- printf("ok 1 - got passed int 42\n", x);
+ printf("ok - got passed int 42\n", x);
else
- printf("not ok 1 - got passed int 42\n", x);
+ printf("not ok - got passed int 42\n", x);
fflush(stdout);
}
extern void take_two_shorts(short x, short y) {
if (x == 10)
- printf("ok 2 - got passed short 10\n", x);
+ printf("ok - got passed short 10\n", x);
else
- printf("not ok 2 - got passed short 10\n", x);
+ printf("not ok - got passed short 10\n", x);
if (y == 20)
- printf("ok 3 - got passed short 20\n", x);
+ printf("ok - got passed short 20\n", x);
else
- printf("not ok 3 - got passed short 20\n", x);
+ printf("not ok - got passed short 20\n", x);
fflush(stdout);
}
extern void take_misc_ints(int x, short y, char z) {
if (x == 101)
- printf("ok 4 - got passed int 101\n", x);
+ printf("ok - got passed int 101\n", x);
else
- printf("not ok 4 - got passed int 101\n", x);
+ printf("not ok - got passed int 101\n", x);
if (y == 102)
- printf("ok 5 - got passed short 102\n", x);
+ printf("ok - got passed short 102\n", x);
else
- printf("not ok 5 - got passed short 102\n", x);
+ printf("not ok - got passed short 102\n", x);
if (z == 103)
- printf("ok 6 - got passed char 103\n", x);
+ printf("ok - got passed char 103\n", x);
else
- printf("not ok 6 - got passed char 103\n", x);
+ printf("not ok - got passed char 103\n", x);
fflush(stdout);
}
extern void take_one_double(double x) {
if (-6.9 - x < 0.001)
- printf("ok 7 - got passed double -6.9\n", x);
+ printf("ok - got passed double -6.9\n", x);
else
- printf("not ok 7 - got passed double -6.9\n", x);
+ printf("not ok - got passed double -6.9\n", x);
+
+ fflush(stdout);
}
extern void take_one_float(float x) {
if (4.2 - x < 0.001)
- printf("ok 8 - got passed float 4.2\n", x);
+ printf("ok - got passed float 4.2\n", x);
else
- printf("not ok 8 - got passed float 4.2\n", x);
+ printf("not ok - got passed float 4.2\n", x);
+
+ fflush(stdout);
}
extern void take_one_string(char *pass_msg) {
printf("%s\n", pass_msg);
+
+ fflush(stdout);
}
static char *cached_str = NULL;
extern void set_cached_string(char *str) {
- cached_str = str;
+ cached_str = str;
}
extern void print_cached_string() {
printf("%s\n", cached_str);
+
+ fflush(stdout);
}
View
@@ -9,8 +9,6 @@ my $test = '02-simple-args';
my $source = "./t/$test.c";
my $shared = "./t/$test.so";
-print "1..9\n";
-
CompileTest::compile($source, $shared);
# integers
@@ -19,38 +17,47 @@ my $take_one_int = FFI::Raw -> new(
FFI::Raw::void, FFI::Raw::int
);
+$take_one_int -> call(42);
+
my $take_two_shorts = FFI::Raw -> new(
$shared, 'take_two_shorts',
FFI::Raw::void, FFI::Raw::short, FFI::Raw::short
);
+$take_two_shorts -> call(10, 20);
+
my $take_misc_ints = FFI::Raw -> new(
$shared, 'take_misc_ints',
FFI::Raw::void, FFI::Raw::int, FFI::Raw::short, FFI::Raw::char
);
-$take_one_int -> call(42);
-$take_two_shorts -> call(10, 20);
$take_misc_ints -> call(101, 102, 103);
+$take_misc_ints -> (101, 102, 103);
# floats
my $take_one_double = FFI::Raw -> new(
$shared, 'take_one_double',
FFI::Raw::void, FFI::Raw::double
);
+$take_one_double -> call(-6.9e0);
+$take_one_double -> (-6.9e0);
+
my $take_one_float = FFI::Raw -> new(
$shared, 'take_one_float',
FFI::Raw::void, FFI::Raw::float
);
-$take_one_double -> call(-6.9e0);
$take_one_float -> call(4.2e0);
+$take_one_float -> (4.2e0);
# strings
my $take_one_string = FFI::Raw -> new(
$shared, 'take_one_string',
FFI::Raw::void, FFI::Raw::str
);
-$take_one_string -> call('ok 9 - passed a string');
+$take_one_string -> call('ok - passed a string');
+$take_one_string -> ('ok - passed a string');
+
+print "1..15\n";
View
@@ -15,20 +15,26 @@ CompileTest::compile($source, $shared);
my $return_int = FFI::Raw -> new($shared, 'return_int', FFI::Raw::int);
is $return_int -> call, 101;
+is $return_int -> (), 101;
my $return_short = FFI::Raw -> new($shared, 'return_short', FFI::Raw::short);
is $return_short -> call, 102;
+is $return_short -> (), 102;
my $return_char = FFI::Raw -> new($shared, 'return_char', FFI::Raw::char);
is $return_char -> call, -103;
+is $return_char -> (), -103;
my $return_double = FFI::Raw -> new($shared, 'return_double', FFI::Raw::double);
is $return_double -> call, 99.9e0;
+is $return_double -> (), 99.9e0;
my $return_float = FFI::Raw -> new($shared, 'return_float', FFI::Raw::float);
is $return_float -> call, -4.5e0;
+is $return_float -> (), -4.5e0;
my $return_string = FFI::Raw -> new($shared, 'return_string', FFI::Raw::str);
is $return_string -> call, 'epic cuteness';
+is $return_string -> (), 'epic cuteness';
done_testing;
View
@@ -17,16 +17,16 @@ my $get_test_ptr_size = FFI::Raw -> new(
$shared, 'get_test_ptr_size', FFI::Raw::int
);
+my $ptr1 = FFI::Raw::memptr($get_test_ptr_size -> call);
+
my $take_one_pointer = FFI::Raw -> new(
$shared, 'take_one_pointer',
FFI::Raw::void, FFI::Raw::ptr
);
-my $return_pointer = FFI::Raw -> new($shared, 'return_pointer', FFI::Raw::ptr);
-
-my $ptr1 = FFI::Raw::memptr($get_test_ptr_size -> call);
$take_one_pointer -> call($ptr1);
+my $return_pointer = FFI::Raw -> new($shared, 'return_pointer', FFI::Raw::ptr);
my $ptr2 = $return_pointer -> call;
my $return_str_from_ptr = FFI::Raw -> new(
@@ -43,9 +43,15 @@ my $test_str = 'some string';
my $test_int = 42;
is $return_str_from_ptr -> call($ptr1), $test_str;
+is $return_str_from_ptr -> ($ptr1), $test_str;
+
is $return_int_from_ptr -> call($ptr1), $test_int;
+is $return_int_from_ptr -> ($ptr1), $test_int;
is $return_str_from_ptr -> call($ptr2), $test_str;
+is $return_str_from_ptr -> ($ptr2), $test_str;
+
is $return_int_from_ptr -> call($ptr2), $test_int;
+is $return_int_from_ptr -> ($ptr2), $test_int;
done_testing;
View
@@ -9,7 +9,7 @@ my $test = '05-callbacks';
my $source = "./t/$test.c";
my $shared = "./t/$test.so";
-print "1..3\n";
+print "1..6\n";
CompileTest::compile($source, $shared);
@@ -18,30 +18,36 @@ my $take_one_int_callback = FFI::Raw -> new(
FFI::Raw::void, FFI::Raw::ptr
);
-my $return_int_callback = FFI::Raw -> new(
- $shared, 'return_int_callback',
- FFI::Raw::int, FFI::Raw::ptr
-);
-
my $func1 = sub {
my $num = shift;
- print ($num == 42 ? "ok 1\n" : "not ok 1\n");
+ print ($num == 42 ? "ok\n" : "not ok\n");
};
+my $cb1 = FFI::Raw::callback($func1, FFI::Raw::void, FFI::Raw::int);
+
+$take_one_int_callback -> call($cb1);
+$take_one_int_callback -> ($cb1);
+
+print "ok - survived the call\n";
+
+my $return_int_callback = FFI::Raw -> new(
+ $shared, 'return_int_callback',
+ FFI::Raw::int, FFI::Raw::ptr
+);
+
my $func2 = sub {
my $num = shift;
return $num + 15;
};
-my $cb1 = FFI::Raw::callback($func1, FFI::Raw::void, FFI::Raw::int);
my $cb2 = FFI::Raw::callback($func2, FFI::Raw::int, FFI::Raw::int);
-$take_one_int_callback -> call($cb1);
-
-print "ok 2 - survived the call\n";
+my $check1 = $return_int_callback -> call($cb2);
+my $check2 = $return_int_callback -> ($cb2);
-my $check = $return_int_callback -> call($cb2);
+print "ok - survived the call\n";
-print ($check == (42 + 15) ? "ok 3\n" : "not ok 3 - returned $check\n");
+print ($check1 == (42 + 15) ? "ok\n" : "not ok - returned $check1\n");
+print ($check2 == (42 + 15) ? "ok\n" : "not ok - returned $check2\n");

0 comments on commit 9365c96

Please sign in to comment.