tests: adds an extra simple test for the FFI
authorAlexis Laferrière <alexis.laf@xymus.net>
Tue, 25 Sep 2012 01:48:58 +0000 (21:48 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Mon, 5 Aug 2013 17:06:28 +0000 (13:06 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

tests/sav/test_ffi_c_extra_simple.sav [new file with mode: 0644]
tests/test_ffi_c_extra_simple.nit [new file with mode: 0644]

diff --git a/tests/sav/test_ffi_c_extra_simple.sav b/tests/sav/test_ffi_c_extra_simple.sav
new file mode 100644 (file)
index 0000000..122f02b
--- /dev/null
@@ -0,0 +1,7 @@
+foo from C
+bar from C: 144
+From Nit: 242
+From Nit: calling titi
+titi from C: 2.340000
+From Nit: called titi
+true
diff --git a/tests/test_ffi_c_extra_simple.nit b/tests/test_ffi_c_extra_simple.nit
new file mode 100644 (file)
index 0000000..29482c9
--- /dev/null
@@ -0,0 +1,55 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Copyright 2013 Alexis Laferrière <alexis.laf@xymus.net>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Very basic FFI tests
+# Does not use extern methods from other modules
+module test_ffi_c_extra_simple
+
+in "C" `{
+       #include <stdio.h>
+`}
+
+class A
+       fun foo `{
+               printf( "foo from C\n" );
+       `}
+
+       fun bar( other : A, i : Int ) `{
+               printf( "bar from C: %ld\n", i );
+       `}
+
+       fun baz( i : Int ) : Int `{
+               return i * 2;
+       `}
+
+       fun titi( i : Float ) : Float `{
+               printf( "titi from C: %f\n", i );
+               return i*2.0f; // i * 12;
+       `}
+
+       fun bounce( a : A ) : A `{
+               return a;
+       `}
+end
+
+var a = new A
+a.foo
+a.bar( a, 144 )
+print "From Nit: {a.baz( 121 )}"
+print "From Nit: calling titi"
+a.titi( 2.34 )
+print "From Nit: called titi"
+print a == a.bounce( a )