stdlib : String, added test for copy constructor
authorLucas Bajolet <lucas.bajolet@hotmail.com>
Mon, 10 Jun 2013 23:48:37 +0000 (19:48 -0400)
committerLucas Bajolet <lucas.bajolet@hotmail.com>
Thu, 13 Jun 2013 15:27:06 +0000 (11:27 -0400)
Signed-off-by: Lucas Bajolet <lucas.bajolet@hotmail.com>

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

diff --git a/tests/sav/string_ffi_ref_test.sav b/tests/sav/string_ffi_ref_test.sav
new file mode 100644 (file)
index 0000000..e9856d5
--- /dev/null
@@ -0,0 +1,3 @@
+This is a test string
+This is a test string
+Do the strings have the same NativeString reference ? False
diff --git a/tests/string_ffi_ref_test.nit b/tests/string_ffi_ref_test.nit
new file mode 100644 (file)
index 0000000..d2c6277
--- /dev/null
@@ -0,0 +1,67 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Copyright 2013 Lucas Bajolet <lucas.bajolet@gmail.com>
+#
+# 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.
+
+module string_ffi_ref_test
+
+class StringTest
+
+       var copied_str: nullable String
+
+       var referenced_str: nullable String
+
+       init
+       do
+               copied_str = null
+               referenced_str = null
+       end
+
+       fun get_c_string import String::items, String::from_cstring, String::copy_from_native, StringTest::ref_test, StringTest::copy_test `{
+               char* string = "This is a test string";
+
+               String ref_string = new_String_from_cstring(string);
+               StringTest_ref_test(recv, ref_string);
+
+               String copy_string = new_String_copy_from_native(string);
+               StringTest_copy_test(recv, copy_string);
+
+               int same_refs = String_items(copy_string) == String_items(ref_string);
+
+               printf("Do the strings have the same NativeString reference ? ");
+
+               if(same_refs){
+                       printf("True\n");
+               }else{
+                       printf("False\n");
+               }
+       `}
+
+       private fun ref_test(referenced: String)
+       do
+               print referenced
+               referenced_str = referenced
+       end
+
+       private fun copy_test(copied: String)
+       do
+               print copied
+               copied_str = copied
+       end
+
+end
+
+var str_test = new StringTest
+
+str_test.get_c_string