--- /dev/null
+#FIXME: Improper way of resolving unjustified metadata conflict
+module complete_simple_android is
+ app_name("test all")
+ java_package("org.nitlanguage.test_all")
+ app_version(1, 0)
+end
+
+import test_bundle
+import test_audio
+import test_shared_preferences
+import test_assets_and_resources
+import test_target_api
import simple
import mnit_android
-import android::bundle
-import android::shared_preferences
-import android::assets_and_resources
-import android::audio
+import serialization
in "Java" `{
import android.content.Context;
`}
redef class App
- var soundsp: Sound
- var soundmp: Sound
-
- redef fun init_window
- do
- super
- manage_audio_mode
- # retrieve sound
- soundsp = load_sound("sound.ogg")
- soundmp = load_music("xylofon.ogg")
- default_mediaplayer.looping = true
- default_mediaplayer.prepare
- soundmp.play
- end
-
redef fun input( ie )
do
if ie isa PointerEvent and ie.depressed then
- do_java_stuff
- test_bundle
- test_shared_preferences
- soundsp.play
- test_assets
- test_resources
+ test_java_ffi
end
return super
end
- #testing the assets manager
- fun test_assets
- do
- assert asset_manager.bitmap("fighter.png") != null
- end
-
- #testing the resources manager
- fun test_resources do
- assert resource_manager.string("string_test") == "string test"
- assert resource_manager.boolean("test_bool") == true
- assert resource_manager.dimension("test_dimen_1") != null
- assert resource_manager.dimension("test_dimen_2") != null
- end
-
- fun test_bundle
- do
- var bundle = new Bundle(self)
-
- bundle["anInt"] = 1
- bundle["aFloat"] = 1.1
- bundle["aString"] = "A string"
- bundle["aBool"] = true
-
- var int_array = new Array[Int]
- var bool_array = new Array[Bool]
-
- var value = true
-
- for i in [0..5] do
- int_array.add(i)
- bool_array.add(value)
- value = not value
- end
-
- bundle["anArrayOfInt"] = int_array
- bundle["anArrayOfBool"] = bool_array
-
- assert bundle.int("anInt", 0) == 1
- assert bundle.int("wrongInt", 0) == 0
- assert bundle.float("aFloat", 0.0) == 1.1
- assert bundle.float("wrongFloat", 0.0) == 0.0
- assert bundle.string("aString") == "A string"
- assert bundle.string("wrongString") == null
- assert bundle.bool("aBool", false)
- assert bundle.bool("wrongBool", false) == false
-
- var int_array_test = bundle.array_of_int("anArrayOfInt")
- var bool_array_test = bundle.array_of_bool("anArrayOfBool")
-
- value = true
-
- for i in [0..5] do
- assert int_array_test[i] == i
- assert bool_array_test[i] == value
- value = not value
- end
-
- assert bundle.size == 6
- assert bundle.has("aBool")
- assert not bundle.is_empty
-
- bundle.remove("aString")
- bundle.remove("anArrayOfBool")
-
- assert bundle.string("aString") == null
- assert bundle.array_of_bool("anArrayOfBool") == null
-
- # Serializable tests
- var p1 = new Point(10, 10)
- bundle["aPoint"] = p1
- var p2 = bundle.deserialize("aPoint")
-
- assert p1.to_s == p2.to_s
-
- var point_array = new Array[Point]
-
- for i in [0..5] do point_array.add(new Point(i, i))
-
- bundle["anArrayOfPoint"] = point_array
-
- var deserialized_point_array = bundle.deserialize_array("anArrayOfPoint")
-
- for i in [0..5] do
- var point = new Point(i, i)
- assert deserialized_point_array[i].to_s == point.to_s
- end
-
- bundle.clear
-
- assert bundle.keys.is_empty
- assert bundle.is_empty
- end
-
- fun test_shared_preferences
- do
- # Private mode tests
- var sp = new SharedPreferences.privately(self, "test")
- sp.add_bool("a_boolean", true)
- sp.add_float("a_float", 66.6)
- sp.add_int("an_int", 666)
- sp.add_int("a_second_int", 666777)
- sp.add_long("a_long", 6666666666)
- sp.add_string("a_string", "A string")
- sp["another_int"] = 85
- sp["yet_another_string"] = "Another string"
- sp.remove("a_second_int")
-
- # Serialized object test
- var my_point = new Point(10, 10)
- sp["a_point"] = my_point
- var my_deserialized_point = sp["a_point"]
- assert my_point.to_s == my_deserialized_point.to_s
-
- assert sp.bool("a_boolean", false) == true
- assert sp.bool("wrong_boolean", false) == false
- assert sp.float("a_float", 0.0) != 0.0
- assert sp.float("wrong_float", 0.0) == 0.0
- assert sp.int("an_int", 0) == 666
- assert sp.int("a_second_int", 0) == 0
- assert sp.long("a_long", 0) == 6666666666
- assert sp.long("wrong_long", 0) == 0
- assert sp.string("a_string", "ERROR!") == "A string"
- assert sp.string("wrong_string", "ERROR!") == "ERROR!"
- assert sp.long("another_int", 0) == 85
- assert sp.string("yet_another_string", "ERROR!") == "Another string"
- assert sp.has("an_int") == true
- assert sp.has("a_second_int") == false
-
- sp.clear
- assert sp.all == null
-
- sp.destroy
- end
-
- fun do_java_stuff import native_activity in "Java" `{
+ fun test_java_ffi import native_activity in "Java" `{
// + Log (no context needed)
android.util.Log.d("mnit_simple", "Java within NIT!!!");
--- /dev/null
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Copyright 2014 Romain Chanoir <romain.chanoir@viacesi.fr>
+#
+# 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 asserts_and_resources module of App.nit framework
+module test_assets_and_resources
+
+import simple_android
+import android::assets_and_resources
+
+redef class App
+ redef fun input( ie )
+ do
+ if ie isa PointerEvent and ie.depressed then
+ test_assets
+ test_resources
+ end
+ return super
+ end
+
+ # Testing the assets manager
+ fun test_assets
+ do
+ assert asset_manager.bitmap("fighter.png") != null
+ end
+
+ # Testing the resources manager
+ fun test_resources do
+ assert resource_manager.string("string_test") == "string test"
+ assert resource_manager.boolean("test_bool") == true
+ assert resource_manager.dimension("test_dimen_1") != null
+ assert resource_manager.dimension("test_dimen_2") != null
+ end
+end
--- /dev/null
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Copyright 2014 Romain Chanoir <romain.chanoir@viacesi.fr>
+#
+# 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 audio module of App.nit framework
+module test_audio
+
+import simple_android
+import android::audio
+
+redef class App
+ var soundsp: Sound
+ var soundmp: Sound
+
+ redef fun init_window
+ do
+ super
+ manage_audio_mode
+
+ # Retrieve sound
+ soundsp = load_sound("sound.ogg")
+ soundmp = load_music("xylofon.ogg")
+ default_mediaplayer.looping = true
+ default_mediaplayer.prepare
+ soundmp.play
+ end
+
+ redef fun input( ie )
+ do
+ if ie isa PointerEvent and ie.depressed then
+ soundsp.play
+ end
+ return super
+ end
+end
--- /dev/null
+# 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 bundle module of App.nit framework
+module test_bundle
+
+import simple_android
+import android::bundle
+
+redef class App
+ redef fun input ( ie )
+ do
+ if ie isa PointerEvent and ie.depressed then
+ test_bundle
+ end
+ return super
+ end
+
+ fun test_bundle
+ do
+ var bundle = new Bundle(self)
+
+ bundle["anInt"] = 1
+ bundle["aFloat"] = 1.1
+ bundle["aString"] = "A string"
+ bundle["aBool"] = true
+
+ var int_array = new Array[Int]
+ var bool_array = new Array[Bool]
+
+ var value = true
+
+ for i in [0..5] do
+ int_array.add(i)
+ bool_array.add(value)
+ value = not value
+ end
+
+ bundle["anArrayOfInt"] = int_array
+ bundle["anArrayOfBool"] = bool_array
+
+ assert bundle.int("anInt", 0) == 1
+ assert bundle.int("wrongInt", 0) == 0
+ assert bundle.float("aFloat", 0.0) == 1.1
+ assert bundle.float("wrongFloat", 0.0) == 0.0
+ assert bundle.string("aString") == "A string"
+ assert bundle.string("wrongString") == null
+ assert bundle.bool("aBool", false)
+ assert bundle.bool("wrongBool", false) == false
+
+ var int_array_test = bundle.array_of_int("anArrayOfInt")
+ var bool_array_test = bundle.array_of_bool("anArrayOfBool")
+
+ value = true
+
+ for i in [0..5] do
+ assert int_array_test[i] == i
+ assert bool_array_test[i] == value
+ value = not value
+ end
+
+ assert bundle.size == 6
+ assert bundle.has("aBool")
+ assert not bundle.is_empty
+
+ bundle.remove("aString")
+ bundle.remove("anArrayOfBool")
+
+ assert bundle.string("aString") == null
+ assert bundle.array_of_bool("anArrayOfBool") == null
+
+ # Serializable tests
+ var p1 = new Point(10, 10)
+ bundle["aPoint"] = p1
+ var p2 = bundle.deserialize("aPoint")
+
+ assert p1.to_s == p2.to_s
+
+ var point_array = new Array[Point]
+
+ for i in [0..5] do point_array.add(new Point(i, i))
+
+ bundle["anArrayOfPoint"] = point_array
+
+ var deserialized_point_array = bundle.deserialize_array("anArrayOfPoint")
+
+ for i in [0..5] do
+ var point = new Point(i, i)
+ assert deserialized_point_array[i].to_s == point.to_s
+ end
+
+ bundle.clear
+
+ assert bundle.keys.is_empty
+ assert bundle.is_empty
+ end
+end
+
--- /dev/null
+# 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 shared_preferences module of App.nit framework
+module test_shared_preferences
+
+import simple_android
+import android::shared_preferences
+
+redef class App
+ redef fun input ( ie )
+ do
+ if ie isa PointerEvent and ie.depressed then
+ test_shared_preferences
+ end
+ return super
+ end
+
+ fun test_shared_preferences
+ do
+ # Private mode tests
+ var sp = new SharedPreferences.privately(self, "test")
+ sp.add_bool("a_boolean", true)
+ sp.add_float("a_float", 66.6)
+ sp.add_int("an_int", 666)
+ sp.add_int("a_second_int", 666777)
+ sp.add_long("a_long", 6666666666)
+ sp.add_string("a_string", "A string")
+ sp["another_int"] = 85
+ sp["yet_another_string"] = "Another string"
+ sp.remove("a_second_int")
+
+ # Serialized object test
+ var my_point = new Point(10, 10)
+ sp["a_point"] = my_point
+ var my_deserialized_point = sp["a_point"]
+ assert my_point.to_s == my_deserialized_point.to_s
+
+ assert sp.bool("a_boolean", false) == true
+ assert sp.bool("wrong_boolean", false) == false
+ assert sp.float("a_float", 0.0) != 0.0
+ assert sp.float("wrong_float", 0.0) == 0.0
+ assert sp.int("an_int", 0) == 666
+ assert sp.int("a_second_int", 0) == 0
+ assert sp.long("a_long", 0) == 6666666666
+ assert sp.long("wrong_long", 0) == 0
+ assert sp.string("a_string", "ERROR!") == "A string"
+ assert sp.string("wrong_string", "ERROR!") == "ERROR!"
+ assert sp["another_int"] == 85
+ assert sp["yet_another_string"] == "Another string"
+ assert sp.has("an_int") == true
+ assert sp.has("a_second_int") == false
+
+ sp.clear
+ assert sp.all == null
+
+ sp.destroy
+ end
+end
# Test for the API level related annotations
module test_target_api is
- min_sdk_version(10)
- max_sdk_version(19)
- target_sdk_version(11)
+ min_api_version(10)
+ max_api_version(19)
+ target_api_version(11)
end
import simple_android