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 shared_preferences module of App.nit framework
18 module test_shared_preferences
21 import android
::shared_preferences
24 redef fun input
( ie
)
26 if ie
isa PointerEvent and ie
.depressed
then
27 test_shared_preferences
32 fun test_shared_preferences
35 var sp
= new SharedPreferences.privately
(self, "test")
36 sp
.add_bool
("a_boolean", true)
37 sp
.add_float
("a_float", 66.6)
38 sp
.add_int
("an_int", 666)
39 sp
.add_int
("a_second_int", 666777)
40 sp
.add_long
("a_long", 6666666666)
41 sp
.add_string
("a_string", "A string")
42 sp
["another_int"] = 85
43 sp
["yet_another_string"] = "Another string"
44 sp
.remove
("a_second_int")
46 # Serialized object test
47 var my_point
= new Point(10, 10)
48 sp
["a_point"] = my_point
49 var my_deserialized_point
= sp
["a_point"]
50 assert my_point
.to_s
== my_deserialized_point
.to_s
52 assert sp
.bool
("a_boolean", false) == true
53 assert sp
.bool
("wrong_boolean", false) == false
54 assert sp
.float
("a_float", 0.0) != 0.0
55 assert sp
.float
("wrong_float", 0.0) == 0.0
56 assert sp
.int
("an_int", 0) == 666
57 assert sp
.int
("a_second_int", 0) == 0
59 # FIXME getting long from Java on Android is broken
60 # The C FFI (underlying the Java FFI) version of Int is a `long` which is on 32 bits on Android.
61 #assert sp.long("a_long", 0) == 6666666666
63 assert sp
.long
("wrong_long", 0) == 0
64 assert sp
.string
("a_string", "ERROR!") == "A string"
65 assert sp
.string
("wrong_string", "ERROR!") == "ERROR!"
66 assert sp
["another_int"] == 85
67 assert sp
["yet_another_string"] == "Another string"
68 assert sp
.has
("an_int") == true
69 assert sp
.has
("a_second_int") == false