tests: update tests using the FFI
authorAlexis Laferrière <alexis.laf@xymus.net>
Mon, 25 May 2015 19:44:47 +0000 (15:44 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Wed, 27 May 2015 02:53:12 +0000 (22:53 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

23 files changed:
tests/string_ffi_ref_test.nit
tests/test_curl.nit
tests/test_ffi_c_accessor.nit
tests/test_ffi_c_callback_extern_receiver.nit
tests/test_ffi_c_callbacks.nit
tests/test_ffi_c_fibonacci.nit
tests/test_ffi_c_lots_of_refs.nit
tests/test_ffi_c_more.nit
tests/test_ffi_c_more_callbacks.nit
tests/test_ffi_c_new.nit
tests/test_ffi_c_new_extern.nit
tests/test_ffi_c_operators.nit
tests/test_ffi_c_super.nit
tests/test_ffi_c_types.nit
tests/test_ffi_cpp_callbacks.nit
tests/test_ffi_cpp_strings.nit
tests/test_ffi_cpp_types.nit
tests/test_ffi_java_callbacks.nit
tests/test_ffi_java_generics.nit
tests/test_ffi_java_string.nit
tests/test_ffi_java_types.nit
tests/test_ffi_objc_types_and_callbacks.nit
tests/test_pretty/test_extern1.nit

index 427d28c..a94d2f0 100644 (file)
@@ -29,10 +29,10 @@ class StringTest
                char* string = "This is a test string";
 
                FlatString ref_string = NativeString_to_s(string);
-               StringTest_ref_test(recv, ref_string);
+               StringTest_ref_test(self, ref_string);
 
                FlatString copy_string = NativeString_to_s_with_copy(string);
-               StringTest_copy_test(recv, copy_string);
+               StringTest_copy_test(self, copy_string);
 
                int same_refs = FlatString_items(copy_string) == FlatString_items(ref_string);
 
index 79cdb5b..1b8bc03 100644 (file)
@@ -99,7 +99,7 @@ assert infoResp:info != null
 info = curl.easy_getinfo_long(new CURLInfoLong.rtsp_server_cseq)
 assert infoResp:info != null
 
-info = curl.easy_getinfo_long(new CURLInfoLong.rtsp_cseq_recv)
+info = curl.easy_getinfo_long(new CURLInfoLong.rtsp_cseq_self)
 assert infoResp:info != null
 
 # Double
index ad76c0a..71634fd 100644 (file)
@@ -21,12 +21,12 @@ class A
 
        fun print_all import String.to_cstring, r, rw `{
                printf( "%s %s\n",
-                       String_to_cstring( A_r( recv ) ),
-                       String_to_cstring( A_rw( recv ) ) );
+                       String_to_cstring( A_r( self ) ),
+                       String_to_cstring( A_rw( self ) ) );
        `}
        fun modify import NativeString.to_s, w=, rw= `{
-               A_w__assign( recv, NativeString_to_s( "w set from native" ) );
-               A_rw__assign( recv, NativeString_to_s( "rw set from native" ) );
+               A_w__assign( self, NativeString_to_s( "w set from native" ) );
+               A_rw__assign( self, NativeString_to_s( "rw set from native" ) );
        `}
 end
 
index 3fe526c..7e05520 100644 (file)
@@ -33,7 +33,7 @@ extern class Test
         int i;
         for(i = 0; i < 2000; ++i) {
             printf("%d\n", i);
-            Test_foo(recv, NativeString_to_s("asdf"));
+            Test_foo(self, NativeString_to_s("asdf"));
         }
     `}
 
index 5445bbf..f84ac24 100644 (file)
@@ -21,7 +21,7 @@ end
 fun foo do print "foo"
 
 fun call_a_fun import foo `{
-       Sys_foo(recv);
+       Sys_foo(self);
 `}
 
 fun call_a_constructor import A, A.bar `{
index db8c50b..1554719 100644 (file)
@@ -21,18 +21,18 @@ class FibonacciEngine
                if ( n == 1 )
                    return 1;
                else
-                   return FibonacciEngine_fibonacci( recv, n-1 ) + FibonacciEngine_fibonacci( recv,  n-2 );
+                   return FibonacciEngine_fibonacci( self, n-1 ) + FibonacciEngine_fibonacci( self,  n-2 );
        `}
 end
 
 redef class Int
        fun fibonacci : Int import fibonacci `{
-               if ( recv == 0 )
+               if ( self == 0 )
                    return 0;
-               else if ( recv == 1 )
+               else if ( self == 1 )
                    return 1;
                else
-                   return Int_fibonacci( recv-1 ) + Int_fibonacci( recv-2 );
+                   return Int_fibonacci( self-1 ) + Int_fibonacci( self-2 );
        `}
 end
 
index 79c2654..d6abce2 100644 (file)
@@ -20,12 +20,12 @@ extern class As `{ A* `}
        `}
 
        fun []=(i: Int, v: A) `{
-               recv[i] = v;
+               self[i] = v;
                A_incr_ref(v);
        `}
 
        fun [](i: Int): A `{
-               return recv[i];
+               return self[i];
        `}
 end
 
index 7e9ec29..24d152d 100644 (file)
@@ -47,7 +47,7 @@ extern class A
        `}
 
        fun p : Int import m `{
-               return A_m( recv ) + 5;
+               return A_m( self ) + 5;
        `}
 
        fun in_language : Int is extern in "C" `{
index 5fb5b35..1b927aa 100644 (file)
@@ -33,7 +33,7 @@ fun in2(i: Float) do print "Back in Nit: in2"
 
 fun out(i: Int, f: Float): Int import in1, in2, A, A.alt, A.to_i `{
        printf("From C, beginning out: %ld\n", i);
-       Sys_in1(recv, i);
+       Sys_in1(self, i);
        A a = new_A();
        A b = new_A_alt(10);
        printf("From C, a=%ld\n", A_to_i(a));
index 6f5a95a..7e826eb 100644 (file)
@@ -32,7 +32,7 @@ extern class A `{int *`}
 
        fun a do print "a"
        fun p `{
-           printf( "allo from %i\n", *recv );
+           printf( "allo from %i\n", *self );
        `}
        fun d : A import d, A `{
         return new_A();
index e9b46d2..1a15da1 100644 (file)
@@ -24,9 +24,9 @@ extern class IntPtr `{ int* `}
        `}
 
        redef fun to_s import NativeString, NativeString.to_s `{
-               int len = snprintf(NULL, 0, "%d", *recv) + 1;
+               int len = snprintf(NULL, 0, "%d", *self) + 1;
                char *c = new_NativeString(len);
-               sprintf(c, "%d", *recv);
+               sprintf(c, "%d", *self);
                return NativeString_to_s(c);
        `}
 end
index 80a3025..d78ceac 100644 (file)
@@ -20,100 +20,100 @@ class A
        init(value: Int) do self.value = value
 
        fun +(other: A): A import value, A `{
-               int s = A_value( recv );
+               int s = A_value( self );
                int o = A_value( other );
 
                return new_A( s + o );
        `}
 
        fun +: A import value, A `{
-               int s = A_value(recv);
+               int s = A_value(self);
                return new_A(+s);
        `}
 
        fun -(other: A): A import value, A `{
-               int s = A_value( recv );
+               int s = A_value( self );
                int o = A_value( other );
 
                return new_A( s - o );
        `}
 
        fun -: A import value, A `{
-               int s = A_value(recv);
+               int s = A_value(self);
                return new_A(-s);
        `}
 
        fun *(by: Int): A import value, A `{
-               int s = A_value( recv );
+               int s = A_value( self );
 
                return new_A( s * by );
        `}
 
        fun /(by: Int): A import value, A `{
-               int s = A_value( recv );
+               int s = A_value( self );
 
                return new_A( s / by );
        `}
 
        redef fun ==(other) import value, nullable Object.as(A) `{
                if ( nullable_Object_is_a_A( other ) &&
-                        A_value( nullable_Object_as_A(other) ) == A_value( recv ) )
+                        A_value( nullable_Object_as_A(other) ) == A_value( self ) )
                        return 1;
                else
                        return 0;
        `}
 
        fun %(other: A): A import value, A `{
-               return new_A( A_value( recv ) % A_value( other ) );
+               return new_A( A_value( self ) % A_value( other ) );
        `}
 
        fun <=>(other: A): A import value, A `{
-               return new_A( A_value( recv )* 1024 );
+               return new_A( A_value( self )* 1024 );
        `}
 
        fun >(other: A): Bool import value `{
-               return A_value( recv ) > A_value( other );
+               return A_value( self ) > A_value( other );
        `}
 
        fun <(other: A): Bool import value `{
-               return A_value( recv ) < A_value( other );
+               return A_value( self ) < A_value( other );
        `}
 
        fun >=(other: A): Bool import value `{
-               return A_value( recv ) >= A_value( other );
+               return A_value( self ) >= A_value( other );
        `}
 
        fun <=(other: A): Bool import value `{
-               return A_value( recv ) <= A_value( other );
+               return A_value( self ) <= A_value( other );
        `}
 
        fun >>(other: A): A import value, value=, A `{
-               int new_val = A_value( recv ) >> A_value( other );
+               int new_val = A_value( self ) >> A_value( other );
                return new_A(new_val);
        `}
 
        fun <<(other: A): A import value, A `{
-               int new_val = A_value( recv ) << A_value( other );
+               int new_val = A_value( self ) << A_value( other );
                return new_A(new_val);
        `}
 
        fun |(other: A): A import value, A `{
-               int new_val = A_value( recv ) | A_value( other );
+               int new_val = A_value( self ) | A_value( other );
                return new_A(new_val);
        `}
 
        fun ^(other: A): A import value, A `{
-               int new_val = A_value( recv ) ^ A_value( other );
+               int new_val = A_value( self ) ^ A_value( other );
                return new_A(new_val);
        `}
 
        fun ~: A import value, A `{
-               int new_val = ~A_value( recv );
+               int new_val = ~A_value( self );
                return new_A(new_val);
        `}
 
        fun &(other: A): A import value, A `{
-               int new_val = A_value( recv ) & A_value( other );
+               int new_val = A_value( self ) & A_value( other );
                return new_A(new_val);
        `}
 
index 8b241ff..e3052cf 100644 (file)
@@ -24,7 +24,7 @@ class B
        redef fun id : String import super, NativeString.to_s, String.to_cstring `{
                char *new_name;
                char *prefix = "B special ";
-               char *super_name = String_to_cstring( B_id___super( recv ) );
+               char *super_name = String_to_cstring( B_id___super( self ) );
 
                new_name = calloc( strlen( prefix )+strlen( super_name )+1, sizeof(char) );
                strcpy( new_name, prefix );
index 071fa86..7607127 100644 (file)
@@ -16,7 +16,7 @@ extern class A in "C" `{struct s_a*`}
                return v;
        `}
        fun p `{
-               printf( "A< %d %d >\n", recv->x, recv->y );
+               printf( "A< %d %d >\n", self->x, self->y );
        `}
 end
 
@@ -32,8 +32,8 @@ extern class B in "C" `{struct s_b*`}
        `}
        redef fun p import super `{
                printf( "B< " );
-               B_p___super(recv);
-               printf( "   %d %d >\n", recv->w, recv->h );
+               B_p___super(self);
+               printf( "   %d %d >\n", self->w, self->h );
        `}
 end
 
@@ -46,7 +46,7 @@ extern class C
                return v;
        `}
        redef fun p `{
-               printf( "C< %d %d >\n", recv->x, recv->y );
+               printf( "C< %d %d >\n", self->x, self->y );
        `}
 end
 
index e212c32..f899a47 100644 (file)
@@ -33,23 +33,23 @@ extern class CppVector in "C++" `{vector<int>*`}
 
        # Adds an element to the end of the vector
        fun push(v: Int) in "C++" `{
-               recv->push_back(v);
+               self->push_back(v);
        `}
 
        # Pops an element from the end of the vector
        fun pop: Int in "C++" `{
-               long val = recv->back();
-               recv->pop_back();
+               long val = self->back();
+               self->pop_back();
                return val;
        `}
 
        fun safe_pop_with_default(default_return: Int): Int import report_error in "C++" `{
-               if (recv->empty()) {
-                       CppVector_report_error(recv);
+               if (self->empty()) {
+                       CppVector_report_error(self);
                        return default_return;
                } else {
-                       long val = recv->back();
-                       recv->pop_back();
+                       long val = self->back();
+                       self->pop_back();
                        return val;
                }
        `}
index 5b6c59f..7b9c3b0 100644 (file)
@@ -35,24 +35,24 @@ extern class CppVector in "C++" `{vector<int>*`}
 
        # Adds an element to the end of the vector
        fun push(v: Int) in "C++" `{
-               recv->push_back(v);
+               self->push_back(v);
        `}
 
        # Pops an element from the end of the vector
        fun pop: Int in "C++" `{
-               long val = recv->back();
-               recv->pop_back();
+               long val = self->back();
+               self->pop_back();
                return val;
        `}
 
        # Uses a callback to report when receiver is empty
        fun safe_pop_with_default(default_return: Int): Int import report_error in "C++" `{
-               if (recv->empty()) {
-                       CppVector_report_error(recv);
+               if (self->empty()) {
+                       CppVector_report_error(self);
                        return default_return;
                } else {
-                       long val = recv->back();
-                       recv->pop_back();
+                       long val = self->back();
+                       self->pop_back();
                        return val;
                }
        `}
@@ -62,13 +62,13 @@ extern class CppVector in "C++" `{vector<int>*`}
 
        # Prints the given string when receiver is empty
        fun safe_pop_with_custom_error(default_return: Int, error_msg: String): Int import String.to_cpp_string in "C++" `{
-               if (recv->empty()) {
+               if (self->empty()) {
                        string *cpp_error_msg = String_to_cpp_string(error_msg);
                        cout << *cpp_error_msg << "\n";
                        return default_return;
                } else {
-                       long val = recv->back();
-                       recv->pop_back();
+                       long val = self->back();
+                       self->pop_back();
                        return val;
                }
        `}
index 6cdd3f5..364ec9e 100644 (file)
@@ -33,13 +33,13 @@ extern class CppVector in "C++" `{vector<int>*`}
 
        # Adds an element to the end of the vector
        fun push(v: Int) in "C++" `{
-               recv->push_back(v);
+               self->push_back(v);
        `}
 
        # Pops an element from the end of the vector
        fun pop: Int in "C++" `{
-               long val = recv->back();
-               recv->pop_back();
+               long val = self->back();
+               self->pop_back();
                return val;
        `}
 end
index 4fcdbf6..6f438be 100644 (file)
@@ -24,8 +24,8 @@ class A
        fun i: Int do return 777
 
        fun foo import bar, i in "Java" `{
-               A_bar(recv);
-               long i = A_i(recv);
+               A_bar(self);
+               long i = A_i(self);
                System.out.println(i);
        `}
 
index 8c968fd..3ceb224 100644 (file)
@@ -28,12 +28,12 @@ extern class JavaQueueOfString in "Java" `{ java.util.Queue<String> `}
                return new LinkedBlockingQueue<String>();
        `}
 
-       fun offer(o: JavaString) in "Java" `{ recv.offer(o); `}
+       fun offer(o: JavaString) in "Java" `{ self.offer(o); `}
 
-       fun remove: JavaString in "Java" `{ return recv.remove(); `}
+       fun remove: JavaString in "Java" `{ return self.remove(); `}
 
        redef fun output in "Java" `{
-               for (String s: recv) {
+               for (String s: self) {
                        System.out.println(s);
                }
        `}
index 5f5819d..40fbf84 100644 (file)
@@ -30,7 +30,7 @@ class A
                System.out.println(input);
 
                // Callback Nit with string
-               String str = A_bar(recv, "Created in Java");
+               String str = A_bar(self, "Created in Java");
                System.out.println(str);
 
                // Send back a string
index 19ca640..cbdfa0f 100644 (file)
@@ -27,16 +27,16 @@ extern class JavaArrayList in "Java" `{ java.util.ArrayList `}
                return new ArrayList();
        `}
 
-       fun add(o: JavaString) in "Java" `{ recv.add(o); `}
+       fun add(o: JavaString) in "Java" `{ self.add(o); `}
 
        redef fun output in "Java" `{
-               for (Object i: recv) {
+               for (Object i: self) {
                        System.out.println((String)i);
                }
        `}
 
        fun sort in "Java" `{
-               Collections.sort(recv);         
+               Collections.sort(self);
        `}
 end
 
index 4512519..6869ac9 100644 (file)
@@ -24,7 +24,7 @@ import bar, String.to_cstring, Int.+ in "ObjC" `{
 
        printf("From Objective-C: %ld %f %s\n", ii, f, cstr);
 
-       Sys_bar(recv, ii, f, s);
+       Sys_bar(self, ii, f, s);
 `}
 
 fun bar(i: Int, f: Float, s: String)
index d2fc373..715ccb0 100644 (file)
@@ -52,7 +52,7 @@ private class A
                printf( "received msg: %s, of length = %d\n", c_msg, msg_len );
 
                /* A_my_attr is a callback to the getter of self.my_attr */
-               printf( "old attr %d\n", A_my_attr(recv) );
+               printf( "old attr %d\n", A_my_attr(self) );
 
                if(chose)
                        truc;
@@ -60,7 +60,7 @@ private class A
                        chose;
 
                /* A_my_attr is a callback to the setter of self.my_attr= */
-               A_my_attr__assign( recv, msg_len );
+               A_my_attr__assign( self, msg_len );
     `}
 end
 
@@ -68,19 +68,19 @@ extern class TimeT `{time_t`}
        new `{ return time(NULL); `}
        new from_i(i: Int) `{ return i; `}
 
-       fun update `{ time(&recv); `}
+       fun update `{ time(&self); `}
 
        fun ctime: String import NativeString.to_s_with_copy `{
-               return NativeString_to_s_with_copy( ctime(&recv) );
+               return NativeString_to_s_with_copy( ctime(&self) );
        `}
 
        # Difference in secondes from start (self if the end time)
-       fun difftime(start: TimeT): Float `{ return difftime(recv, start); `}
+       fun difftime(start: TimeT): Float `{ return difftime(self, start); `}
 
        private fun intern_poll(in_fds: Array[Int], out_fds: Array[Int]) : nullable Int is extern import Array[Int].length, Array[Int].[], Int.as(nullable Int) `{`}
 end
 
 fun address_is_null: Bool is extern "address_is_null"
 
-fun free `{ free(recv); `}
+fun free `{ free(self); `}