Skip to content
This repository
Browse code

Tests for returning int/num/string types.

  • Loading branch information...
commit beb27967dccfcf787f455f9e353f155abc2fdc5b 1 parent 64ca08b
Jonathan Worthington authored January 13, 2012
37  t/03-simple-returns.c
... ...
@@ -0,0 +1,37 @@
  1
+#include <stdio.h>
  2
+
  3
+#ifdef WIN32
  4
+#define DLLEXPORT __declspec(dllexport)
  5
+#else
  6
+#define DLLEXPORT extern
  7
+#endif
  8
+
  9
+DLLEXPORT int ReturnInt()
  10
+{
  11
+    return 101;
  12
+}
  13
+
  14
+DLLEXPORT short ReturnShort()
  15
+{
  16
+    return 102;
  17
+}
  18
+
  19
+DLLEXPORT char ReturnByte()
  20
+{
  21
+    return -103;
  22
+}
  23
+
  24
+DLLEXPORT double ReturnDouble()
  25
+{
  26
+    return 99.9;
  27
+}
  28
+
  29
+DLLEXPORT float ReturnFloat()
  30
+{
  31
+    return (float)-4.5;
  32
+}
  33
+
  34
+DLLEXPORT char * ReturnString()
  35
+{
  36
+    return "epic cuteness";
  37
+}
25  t/03-simple-returns.t
... ...
@@ -0,0 +1,25 @@
  1
+use t::CompileTestLib;
  2
+use NativeCall;
  3
+use Test;
  4
+
  5
+plan(6);
  6
+
  7
+compile_test_lib('03-simple-returns');
  8
+
  9
+sub ReturnInt() returns int32 is native('03-simple-returns') { * }
  10
+is ReturnInt(), 101, 'returning int works';
  11
+
  12
+sub ReturnShort() returns int16  is native('03-simple-returns') { * }
  13
+is ReturnShort(), 102, 'returning short works';
  14
+
  15
+sub ReturnByte() returns int8 is native('03-simple-returns') { * }
  16
+is ReturnByte(), -103, 'returning char works';
  17
+
  18
+sub ReturnDouble() returns num64 is native('03-simple-returns') { * }
  19
+is_approx ReturnDouble(), 99.9e0, 'returning double works';
  20
+
  21
+sub ReturnFloat() returns num32 is native('03-simple-returns') { * }
  22
+is_approx ReturnFloat(), -4.5e0, 'returning float works';
  23
+
  24
+sub ReturnString() returns Str is native('03-simple-returns') { * }
  25
+is ReturnString(), "epic cuteness", 'returning string works';

0 notes on commit beb2796

Please sign in to comment.
Something went wrong with that request. Please try again.