contrib/crazy_moles: update Makefile to use the new check-android.sh
[nit.git] / examples / mnit_simple / src / test_intent.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2014 Frédéric Vachon <fredvac@gmail.com>
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 # Test for the intent module of App.nit framework
18 module test_intent
19
20 import simple_android
21 import android::intent::intent_api19
22
23 redef class App
24 var intent: Intent
25 redef fun input( ie )
26 do
27 if ie isa PointerEvent and ie.depressed then
28 test_intent
29 end
30 return super
31 end
32
33 fun test_intent
34 do
35 intent = new Intent
36 intent.action = intent_action.view.to_s
37 intent.data = "content://contacts/people/"
38
39 start_activity intent
40 intent.destroy
41
42 intent = new Intent
43 var p1 = new Point(10, 20)
44 intent["a_point"] = p1
45 var p2 = intent["a_point"]
46 assert p1.to_s == p2.to_s
47
48 intent.action = intent_action.main.to_s
49 assert intent.action == intent_action.main.to_s
50
51 intent.add_flags intent_flag.activity_brought_to_front
52 assert intent.flags == intent_flag.activity_brought_to_front
53
54 var bool_array = new Array[Bool]
55 for i in [0..5] do bool_array.add( i % 2 == 0 )
56
57 intent.add_extra_array_of_bool("bools", bool_array)
58 var bool_array2 = intent.extra_bool_array("bools")
59 for i in [0..5] do assert bool_array2[i] == (i%2 ==0)
60
61 var string_array = ["foo", "bar", "baz"]
62 intent.add_extra_array_of_string("strings", string_array)
63 var string_array2 = intent.extra_string_array("strings")
64 for i in [0..string_array2.length[ do assert string_array[i] == string_array2[i]
65
66 intent.add_extra_array_list_of_string("strings", string_array)
67 string_array2 = intent.extra_string_array_list("strings")
68 for i in [0..string_array2.length[ do assert string_array[i] == string_array2[i]
69
70 intent.add_category intent_category.home.to_s
71 var categories = intent.categories
72 assert categories.first == intent_category.home.to_s
73 assert intent.has_category(intent_category.home.to_s)
74
75 intent.destroy
76 end
77 end