1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2014 Frédéric Vachon <fredvac@gmail.com>
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 # Test for the bundle module of App.nit framework
21 import android
::bundle
24 redef fun input
( ie
)
26 if ie
isa PointerEvent and ie
.depressed
then
34 var bundle
= new Bundle(self)
37 bundle
["aFloat"] = 1.1
38 bundle
["aString"] = "A string"
39 bundle
["aBool"] = true
41 var int_array
= new Array[Int]
42 var bool_array
= new Array[Bool]
52 bundle
["anArrayOfInt"] = int_array
53 bundle
["anArrayOfBool"] = bool_array
55 assert bundle
.int
("anInt", 0) == 1
56 assert bundle
.int
("wrongInt", 0) == 0
57 assert bundle
.float
("aFloat", 0.0) == 1.1
58 assert bundle
.float
("wrongFloat", 0.0) == 0.0
59 assert bundle
.string
("aString") == "A string"
60 assert bundle
.string
("wrongString") == null
61 assert bundle
.bool
("aBool", false)
62 assert bundle
.bool
("wrongBool", false) == false
64 var int_array_test
= bundle
.array_of_int
("anArrayOfInt")
65 var bool_array_test
= bundle
.array_of_bool
("anArrayOfBool")
70 assert int_array_test
[i
] == i
71 assert bool_array_test
[i
] == value
75 assert bundle
.size
== 6
76 assert bundle
.has
("aBool")
77 assert not bundle
.is_empty
79 bundle
.remove
("aString")
80 bundle
.remove
("anArrayOfBool")
82 assert bundle
.string
("aString") == null
83 assert bundle
.array_of_bool
("anArrayOfBool") == null
86 var p1
= new Point(10, 10)
88 var p2
= bundle
.deserialize
("aPoint")
90 assert p1
.to_s
== p2
.to_s
92 var point_array
= new Array[Point]
94 for i
in [0..5] do point_array
.add
(new Point(i
, i
))
96 bundle
["anArrayOfPoint"] = point_array
98 var deserialized_point_array
= bundle
.deserialize_array
("anArrayOfPoint")
101 var point
= new Point(i
, i
)
102 assert deserialized_point_array
[i
].to_s
== point
.to_s
107 assert bundle
.keys
.is_empty
108 assert bundle
.is_empty