scope: refuse `&x` where x is a local variable
[nit.git] / tests / test_jvm.nit
index 27da835..d921bf4 100644 (file)
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# Manipulats the Java Virtual Machine
-#
-# See: http://docs.oracle.com/javase/1.5.0/docs/guide/jni/spec/jniTOC.html
+# No alt works
+# alt1 sets a wrong classpath and should fail on class loading
+# alt2 looks for a non existant class
+# alt3-4 looks for non existant methods
+
 import jvm
 
 redef extern class JniEnv
@@ -38,16 +40,18 @@ print "Initialisation de la JVM ..."
 
 var builder = new JavaVMBuilder
 builder.options.add "-Djava.class.path=."
+#alt1#builder.options.clear
+#alt1#builder.options.add "-Djava.class.path=/tmp/"
 var jvm = builder.create_jvm
-var env = builder.jni_env
-assert env != null
+assert jvm != null
 
-# Test JavaVM::env
-assert not jvm.env.address_is_null
+var env = jvm.env
+assert not env.address_is_null
 
 print "---------------------Test 1----------------------"
 # get the class
 var queue_c = env.find_class("test_jvm/Queue")
+#alt2#queue_c = env.find_class("test_jvm/Queue_error_in_name")
 if queue_c.address_is_null then env.print_error("Queue class not found")
 
 # get the methods of the class
@@ -55,6 +59,8 @@ var f_init = env.get_method_id(queue_c, "<init>", "()V")
 if f_init.address_is_null then env.print_error("fInit not found")
 
 var f_push = env.get_method_id(queue_c, "push", "(Ljava/lang/String;)V")
+#alt3#f_push = env.get_method_id(queue_c, "push_error", "(Ljava/lang/String;)V")
+#alt4#f_push = env.get_method_id(queue_c, "push", "(Ljava/lang/String;ZZZ)V")
 if f_push.address_is_null then env.print_error("fPush not found")
 
 var f_pop = env.get_method_id(queue_c, "pop", "()Ljava/lang/String;")
@@ -121,15 +127,10 @@ if test.address_is_null then env.print_error("object test not initialized")
 
 # Retrieve field value with field ids
 var v_bool = env.get_boolean_field(test, f_bool)
-if v_bool == null then env.print_error("vbool not found")
 var v_char = env.get_char_field(test, f_char)
-if v_char == null then env.print_error("vchar not found")
 var v_i = env.get_int_field(test, f_i)
-if v_i == null then env.print_error("vi not found")
 var v_f = env.get_float_field(test, f_f)
-if v_f == null then env.print_error("vf not found")
 var v_test1 = env.get_object_field(test, f_test)
-if v_test1 == null then env.print_error("vtest1 not found")
 
 # Set the new values for the fields
 env.set_boolean_field(test, f_bool, true)
@@ -144,7 +145,6 @@ v_char = env.call_char_method(test, m_char, null)
 v_i = env.call_int_method(test, m_i, null)
 v_f = env.call_float_method(test, m_f, null)
 var v_test2 = env.call_object_method(test, m_test, null)
-if v_test2 == null then env.print_error("vtest2 not found")
 
 # assert the values of the fields
 print v_bool