lib/android: Added Intent API tests to mnit_simple
authorFrédéric Vachon <fredvac@gmail.com>
Mon, 4 Aug 2014 23:51:09 +0000 (19:51 -0400)
committerFrédéric Vachon <fredvac@gmail.com>
Wed, 13 Aug 2014 01:07:01 +0000 (21:07 -0400)
Signed-off-by: Frédéric Vachon <fredvac@gmail.com>

examples/mnit_simple/src/complete_simple_android.nit
examples/mnit_simple/src/test_intent.nit [new file with mode: 0644]
examples/mnit_simple/src/test_target_api.nit

index 9ee8b06..2f4f467 100644 (file)
@@ -16,6 +16,7 @@
 
 module complete_simple_android is
        java_package("org.nitlanguage.test_all")
+       target_api_version(19)
 end
 
 import test_bundle
@@ -23,3 +24,4 @@ import test_audio
 import test_shared_preferences
 import test_assets_and_resources
 import test_target_api
+import test_intent
diff --git a/examples/mnit_simple/src/test_intent.nit b/examples/mnit_simple/src/test_intent.nit
new file mode 100644 (file)
index 0000000..3265258
--- /dev/null
@@ -0,0 +1,77 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Copyright 2014 Frédéric Vachon <fredvac@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.
+
+# Test for the intent module of App.nit framework
+module test_intent
+
+import simple_android
+import android::intent::intent_api19
+
+redef class App
+       var intent: Intent
+       redef fun input( ie )
+       do
+               if ie isa PointerEvent and ie.depressed then
+                       test_intent
+               end
+               return super
+       end
+
+       fun test_intent
+       do
+               intent = new Intent(self)
+               intent.action = intent_action.view.to_s
+               intent.data   = "content://contacts/people/"
+
+               intent.launch_activity
+               intent.destroy
+
+               intent = new Intent(self)
+               var p1 = new Point(10, 20)
+               intent["a_point"] = p1
+               var p2 = intent["a_point"]
+               assert p1.to_s == p2.to_s
+
+               intent.action = intent_action.main.to_s
+               assert intent.action == intent_action.main.to_s
+
+               intent.add_flags intent_flag.activity_brought_to_front
+               assert intent.flags == intent_flag.activity_brought_to_front
+
+               var bool_array = new Array[Bool]
+               for i in [0..5] do bool_array.add( i % 2 == 0 )
+
+               intent.add_extra_array_of_bool("bools", bool_array)
+               var bool_array2 = intent.extra_bool_array("bools")
+               for i in [0..5] do assert bool_array2[i] == (i%2 ==0)
+
+               var string_array = ["foo", "bar", "baz"]
+               intent.add_extra_array_of_string("strings", string_array)
+               var string_array2 = intent.extra_string_array("strings")
+               for i in [0..string_array2.length[ do assert string_array[i] == string_array2[i]
+
+               intent.add_extra_array_list_of_string("strings", string_array)
+               string_array2 = intent.extra_string_array_list("strings")
+               for i in [0..string_array2.length[ do assert string_array[i] == string_array2[i]
+
+               intent.add_category intent_category.home.to_s
+               var categories = intent.categories
+               assert categories.first == intent_category.home.to_s
+               assert intent.has_category(intent_category.home.to_s)
+
+               intent.destroy
+       end
+end
index d5d27ac..6a2503a 100644 (file)
@@ -18,7 +18,6 @@
 module test_target_api is
        min_api_version(10)
        max_api_version(19)
-       target_api_version(11)
 end
 
 import simple_android