ruboto 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. data/Gemfile +1 -1
  2. data/Gemfile.lock +0 -2
  3. data/Rakefile +64 -1
  4. data/assets/rakelib/ruboto.rake +23 -2
  5. data/assets/res/layout/get_ruboto_core.xml +0 -2
  6. data/assets/samples/sample_activity.rb +3 -6
  7. data/assets/samples/sample_broadcast_receiver.rb +9 -5
  8. data/assets/samples/sample_service.rb +0 -3
  9. data/assets/src/InheritingActivity.java +1 -1
  10. data/assets/src/InheritingClass.java +10 -4
  11. data/assets/src/RubotoActivity.java +90 -20
  12. data/assets/src/RubotoBroadcastReceiver.java +59 -23
  13. data/assets/src/RubotoService.java +103 -51
  14. data/assets/src/org/ruboto/EntryPointActivity.java +2 -1
  15. data/assets/src/org/ruboto/JRubyAdapter.java +158 -115
  16. data/assets/src/org/ruboto/Script.java +23 -1
  17. data/assets/src/org/ruboto/test/ActivityTest.java +2 -2
  18. data/assets/src/org/ruboto/test/InstrumentationTestRunner.java +30 -16
  19. data/assets/src/ruboto.rb +1 -0
  20. data/assets/src/ruboto/activity.rb +2 -6
  21. data/assets/src/ruboto/base.rb +9 -7
  22. data/assets/src/ruboto/broadcast_receiver.rb +0 -8
  23. data/assets/src/ruboto/generate.rb +2 -2
  24. data/assets/src/ruboto/service.rb +0 -8
  25. data/assets/src/ruboto/widget.rb +17 -2
  26. data/lib/java_class_gen/android_api.xml +1 -1
  27. data/lib/ruboto/sdk_versions.rb +1 -1
  28. data/lib/ruboto/util/build.rb +11 -10
  29. data/lib/ruboto/util/code_formatting.rb +2 -2
  30. data/lib/ruboto/util/update.rb +20 -7
  31. data/lib/ruboto/util/xml_element.rb +42 -16
  32. data/lib/ruboto/version.rb +1 -1
  33. data/test/activity/call_super_activity.rb +28 -0
  34. data/test/activity/call_super_activity_test.rb +15 -0
  35. data/test/activity/image_button_activity.rb +2 -3
  36. data/test/activity/image_button_and_button_activity.rb +1 -2
  37. data/test/activity/margins_activity.rb +17 -0
  38. data/test/activity/margins_activity_test.rb +25 -0
  39. data/test/activity/navigation_activity.rb +85 -0
  40. data/test/activity/navigation_activity_test.rb +98 -0
  41. data/test/activity/option_menu_activity.rb +0 -2
  42. data/test/activity/psych_activity.rb +2 -3
  43. data/test/activity/stack_activity.rb +3 -2
  44. data/test/activity/stack_activity_test.rb +9 -7
  45. data/test/block_def_activity/margins_activity.rb +17 -0
  46. data/test/block_def_activity/margins_activity_test.rb +25 -0
  47. data/test/block_def_activity/option_menu_activity_test.rb +1 -2
  48. data/test/block_def_activity/stack_activity_test.rb +8 -5
  49. data/test/broadcast_receiver_test.rb +2 -2
  50. data/test/gem_test.rb +12 -0
  51. data/test/handle_activity/margins_activity.rb +15 -0
  52. data/test/handle_activity/margins_activity_test.rb +25 -0
  53. data/test/handle_activity/option_menu_activity.rb +4 -0
  54. data/test/handle_activity/stack_activity.rb +3 -0
  55. data/test/handle_activity/stack_activity_test.rb +9 -6
  56. data/test/minimal_app_test.rb +1 -1
  57. data/test/rake_test.rb +6 -7
  58. data/test/ruboto_gen_test.rb +54 -4
  59. data/test/ruboto_update_test.rb +12 -8
  60. data/test/service_test.rb +1 -6
  61. data/test/test_helper.rb +34 -11
  62. data/test/update_test_methods.rb +22 -0
  63. data/test/view_constants_test.rb +104 -0
  64. metadata +17 -5
@@ -50,7 +50,7 @@ EOF
50
50
  receiver_filename = 'src/click_receiver.rb'
51
51
  receiver_content = File.read(receiver_filename)
52
52
 
53
- assert receiver_content.sub!(/ def on_receive\(context, intent\)\n.*? end\n/m, <<EOF)
53
+ assert receiver_content.sub!(/ def on_receive\(context, intent\)\n.*?^ end\n/m, <<EOF)
54
54
  def on_receive(context, intent)
55
55
  Log.d "RUBOTO TEST", "Changing UI text"
56
56
  context.run_on_ui_thread{$activity.find_view_by_id(42).text = '#{message}'}
@@ -58,7 +58,7 @@ EOF
58
58
  rescue
59
59
  Log.e "RUBOTO TEST", "Exception changing UI text: \#{$!.message}"
60
60
  Log.e "RUBOTO TEST", $!.message
61
- Log.e "RUBOTO TEST", $!.backtrace.join("\n")
61
+ Log.e "RUBOTO TEST", $!.backtrace.join("\\n")
62
62
  end
63
63
  EOF
64
64
  File.open(receiver_filename, 'w') { |f| f << receiver_content }
data/test/gem_test.rb ADDED
@@ -0,0 +1,12 @@
1
+ require File.expand_path("test_helper", File.dirname(__FILE__))
2
+
3
+ class GemTest < Test::Unit::TestCase
4
+ def test_rake_gem
5
+ gem_file = "ruboto-#{Ruboto::VERSION}.gem"
6
+ File.delete(gem_file) if File.exists?(gem_file)
7
+ assert !File.exists?(gem_file)
8
+ system 'rake gem'
9
+ assert File.exists?(gem_file)
10
+ end
11
+
12
+ end
@@ -0,0 +1,15 @@
1
+ require 'ruboto'
2
+
3
+ ruboto_import_widgets :LinearLayout, :TextView
4
+
5
+ $activity.handle_create do |bundle|
6
+ setTitle File.basename(__FILE__).chomp('_activity.rb').split('_').map{|s| "#{s[0..0].upcase}#{s[1..-1]}" }.join(' ')
7
+
8
+ setup_content do
9
+ linear_layout :orientation => LinearLayout::VERTICAL do
10
+ @text_view_margins = text_view :text => 'What hath Matz wrought?', :id => 42, :margins => [100,0,0,0]
11
+ @text_view_layout = text_view :text => 'What hath Matz wrought?', :id => 43, :layout => {:set_margins => [100,0,0,0]}
12
+ @text_view_fieldset = text_view :text => 'What hath Matz wrought?', :id => 44, :layout => {:left_margin= => 100}
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,25 @@
1
+ activity Java::org.ruboto.test_app.MarginsActivity
2
+
3
+ setup do |activity|
4
+ start = Time.now
5
+ loop do
6
+ @text_view_margins = activity.findViewById(42)
7
+ @text_view_layout = activity.findViewById(43)
8
+ @text_view_fieldset = activity.findViewById(44)
9
+ break if @text_view_margins || @text_view_layout || @text_view_fieldset || (Time.now - start > 60)
10
+ sleep 1
11
+ end
12
+ assert @text_view_margins
13
+ assert @text_view_layout
14
+ assert @text_view_fieldset
15
+ end
16
+
17
+ def left_margin(view)
18
+ view.get_layout_params.leftMargin
19
+ end
20
+
21
+ %w(margins layout fieldset).each do |view_type|
22
+ test("margins are set through #{view_type}") do |activity|
23
+ assert_equal 100, left_margin(instance_variable_get("@text_view_#{view_type}"))
24
+ end
25
+ end
@@ -1,3 +1,7 @@
1
+ STACK_DEPTH_SCRIPT = java.lang.Thread.current_thread.stack_trace.length.to_s
2
+
3
+ raise "Stack level: #{STACK_DEPTH_SCRIPT}" rescue puts $!.message + "\n" + $!.backtrace.join("\n")
4
+
1
5
  require 'ruboto'
2
6
 
3
7
  ruboto_import_widgets :ImageButton, :LinearLayout, :TextView
@@ -1,4 +1,7 @@
1
1
  STACK_DEPTH_SCRIPT = java.lang.Thread.current_thread.stack_trace.length.to_s
2
+
3
+ raise "Stack level: #{STACK_DEPTH_SCRIPT}" rescue puts $!.message + "\n" + $!.backtrace.join("\n")
4
+
2
5
  require 'ruboto'
3
6
 
4
7
  ruboto_import_widgets :Button, :LinearLayout, :TextView
@@ -17,16 +17,19 @@ test('stack depth') do |activity|
17
17
  '0.4.7' => [0, 0, 0, 0],
18
18
  '0.4.8.dev' => [0, -1, -1, -1],
19
19
  }[org.ruboto.JRubyAdapter.platform_version_name] || [0, 0, 0, 0]
20
- else
20
+ else # STANDALONE
21
21
  jruby_offset = {
22
22
  '1.7.0.dev' => [1, 1, 1, 1],
23
23
  '1.7.0.preview1' => [0, -1, -1, -1],
24
- '1.7.0.preview2.dev' => [0, -1, -1, -1],
24
+ '1.7.0.preview2' => [0, -1, -1, -1],
25
25
  }[org.jruby.runtime.Constants::VERSION] || [0, 0, 0, 0]
26
26
  end
27
27
  version_message ="ANDROID: #{android.os.Build::VERSION::SDK_INT}, PLATFORM: #{org.ruboto.JRubyAdapter.uses_platform_apk ? org.ruboto.JRubyAdapter.platform_version_name : 'STANDALONE'}, JRuby: #{org.jruby.runtime.Constants::VERSION}"
28
- assert_equal 43 + os_offset + jruby_offset[0], activity.find_view_by_id(42).text.to_i, version_message
29
- assert_equal 67 + os_offset + jruby_offset[1], activity.find_view_by_id(43).text.to_i, version_message
30
- assert_equal 76 + os_offset + jruby_offset[2], activity.find_view_by_id(44).text.to_i, version_message
31
- assert_equal 92 + os_offset + jruby_offset[3], activity.find_view_by_id(45).text.to_i, version_message
28
+ assert_equal [43 + os_offset + jruby_offset[0],
29
+ 67 + os_offset + jruby_offset[1],
30
+ 76 + os_offset + jruby_offset[2],
31
+ 92 + os_offset + jruby_offset[3]], [activity.find_view_by_id(42).text.to_i,
32
+ activity.find_view_by_id(43).text.to_i,
33
+ activity.find_view_by_id(44).text.to_i,
34
+ activity.find_view_by_id(45).text.to_i], version_message
32
35
  end
@@ -18,7 +18,7 @@ if RubotoTest::RUBOTO_PLATFORM == 'STANDALONE'
18
18
  upper_limit = {
19
19
  '1.6.7' => 3.2,
20
20
  '1.7.0.preview1' => ANDROID_TARGET < 15 ? 4.4 : 4.6, # Without dexmaker for Android < 4.0.3
21
- '1.7.0.preview2.dev' => ANDROID_TARGET < 15 ? 4.4 : 4.6, # Without dexmaker for Android < 4.0.3
21
+ '1.7.0.preview2' => ANDROID_TARGET < 15 ? 4.4 : 4.6, # Without dexmaker for Android < 4.0.3
22
22
  }[JRUBY_JARS_VERSION.to_s] || 3.2
23
23
  lower_limit = upper_limit * 0.9
24
24
  version_message ="JRuby: #{JRUBY_JARS_VERSION}, ANDROID_TARGET: #{ANDROID_TARGET}"
data/test/rake_test.rb CHANGED
@@ -26,15 +26,14 @@ class RakeTest < Test::Unit::TestCase
26
26
  File.open(test_filename, 'w') { |f| f << s2 }
27
27
 
28
28
  apk_timestamp = File.ctime("bin/#{APP_NAME}-debug.apk")
29
- system 'rake test:quick'
30
- assert_equal 0, $?
29
+ end
30
+ run_app_tests
31
31
 
32
- # FIXME(uwe): Uncomment this when we can build the test package without building the main package
33
- # assert_equal apk_timestamp, File.ctime("bin/#{APP_NAME}-debug.apk"), 'APK should not have been rebuilt'
34
- # FIXME end
32
+ # FIXME(uwe): Uncomment this when we can build the test package without building the main package
33
+ # assert_equal apk_timestamp, File.ctime("bin/#{APP_NAME}-debug.apk"), 'APK should not have been rebuilt'
34
+ # FIXME end
35
35
 
36
- assert_match %r{^/sdcard/Android/data/#{PACKAGE}/files/scripts$}, `adb shell ls -d /sdcard/Android/data/#{PACKAGE}/files/scripts`.chomp
37
- end
36
+ assert_match %r{^/sdcard/Android/data/#{PACKAGE}/files/scripts$}, `adb shell ls -d /sdcard/Android/data/#{PACKAGE}/files/scripts`.chomp
38
37
  end
39
38
  end
40
39
 
@@ -40,14 +40,14 @@ class RubotoGenTest < Test::Unit::TestCase
40
40
  upper_limit = {
41
41
  '1.6.7' => 5800.0,
42
42
  '1.7.0.preview1' => ANDROID_TARGET < 15 ? 7062.0 : 7308.0,
43
- '1.7.0.preview2.dev' => ANDROID_TARGET < 15 ? 7062.0 : 7308.0,
43
+ '1.7.0.preview2' => ANDROID_TARGET < 15 ? 7062.0 : 7308.0,
44
44
  }[JRUBY_JARS_VERSION.to_s] || 4200.0
45
45
  version << ", JRuby: #{JRUBY_JARS_VERSION.to_s}"
46
46
  else
47
47
  upper_limit = {
48
- 7 => 56.0,
49
- 10 => 60.0,
50
- 15 => 60.0,
48
+ 7 => 62.0,
49
+ 10 => 66.0,
50
+ 15 => 67.0,
51
51
  }[ANDROID_TARGET] || 64.0
52
52
  end
53
53
  lower_limit = upper_limit * 0.9
@@ -55,4 +55,54 @@ class RubotoGenTest < Test::Unit::TestCase
55
55
  assert apk_size >= lower_limit, "APK was smaller than #{'%.1f' % lower_limit}KB: #{'%.1f' % apk_size.floor(1)}KB. You should lower the limit.#{version}"
56
56
  end
57
57
 
58
+ def test_gen_subclass
59
+ Dir.chdir APP_DIR do
60
+ system "#{RUBOTO_CMD} gen subclass android.database.sqlite.SQLiteOpenHelper --name MyDatabaseHelper --method_base on"
61
+ assert_equal 0, $?.exitstatus
62
+ assert File.exists?('src/org/ruboto/test_app/MyDatabaseHelper.java')
63
+ # FIXME(uwe): Add tests and definition script?
64
+ # assert File.exists?('src/my_database_helper.rb')
65
+ # assert File.exists?('test/src/my_database_helper_test.rb')
66
+ system 'rake debug'
67
+ assert_equal 0, $?
68
+ end
69
+ end
70
+
71
+ def test_gen_interface
72
+ Dir.chdir APP_DIR do
73
+ system "#{RUBOTO_CMD} gen interface java.lang.Runnable --name MyRunnable"
74
+ assert_equal 0, $?.exitstatus
75
+ java_source_file = 'src/org/ruboto/test_app/MyRunnable.java'
76
+ assert File.exists?(java_source_file)
77
+ # FIXME(uwe): Add tests and definition script?
78
+ # assert File.exists?('src/my_runnable.rb')
79
+ # assert File.exists?('test/src/my_runnable_test.rb')
80
+
81
+ java_source = File.read(java_source_file)
82
+ File.open(java_source_file, 'w'){|f| f << java_source.gsub(/^\}\n/, " public static void main(String[] args){new MyRunnable().run();}\n}\n")}
83
+
84
+ system 'rake debug'
85
+ assert_equal 0, $?
86
+
87
+ File.open('src/org/ruboto/JRubyAdapter.java', 'w'){|f| f << <<EOF}
88
+ package org.ruboto;
89
+ public class JRubyAdapter {
90
+ public static Object get(String varName){return null;}
91
+ public static boolean isInitialized(){return true;}
92
+ public static boolean isJRubyOneSeven(){return true;}
93
+ public static boolean isJRubyPreOneSeven(){return false;}
94
+ public static void put(String varName, Object value){}
95
+ public static void runRubyMethod(Object receiver, String method){}
96
+ public static boolean runScriptlet(String scriptlet){return false;}
97
+ }
98
+ EOF
99
+ system 'javac -cp bin/classes -d bin/classes src/org/ruboto/JRubyAdapter.java'
100
+ assert_equal 0, $?
101
+ system 'javac -cp bin/classes -d bin/classes src/org/ruboto/test_app/MyRunnable.java'
102
+ assert_equal 0, $?
103
+ system 'java -cp bin/classes org.ruboto.test_app.MyRunnable'
104
+ assert_equal 0, $?
105
+ end
106
+ end
107
+
58
108
  end
@@ -1,14 +1,17 @@
1
- require File.expand_path('updated_example_test_methods', File.dirname(__FILE__))
2
- require File.expand_path('update_test_methods', File.dirname(__FILE__))
1
+ if ENV['SKIP_RUBOTO_UPDATE_TEST']
2
+ puts 'Detected SKIP_RUBOTO_UPDATE_TEST environment variable. Skipping Ruboto update test.'
3
+ else
4
+ require File.expand_path('updated_example_test_methods', File.dirname(__FILE__))
5
+ require File.expand_path('update_test_methods', File.dirname(__FILE__))
3
6
 
4
7
  # TODO(uwe): Delete obsolete examples when we stop supporting updating from them.
5
8
 
6
- Dir.chdir "#{RubotoTest::PROJECT_DIR}/examples/" do
7
- Dir["#{RubotoTest::APP_NAME}_*_tools_r*.tgz"].each do |f|
8
- next unless f =~ /^#{RubotoTest::APP_NAME}_(.*)_tools_r(.*)\.tgz$/
9
- ruboto_version = $1
10
- tools_version = $2
11
- self.class.class_eval <<EOF
9
+ Dir.chdir "#{RubotoTest::PROJECT_DIR}/examples/" do
10
+ Dir["#{RubotoTest::APP_NAME}_*_tools_r*.tgz"].each do |f|
11
+ next unless f =~ /^#{RubotoTest::APP_NAME}_(.*)_tools_r(.*)\.tgz$/
12
+ ruboto_version = $1
13
+ tools_version = $2
14
+ self.class.class_eval <<EOF
12
15
  class RubotoUpdatedExample#{ruboto_version.gsub('.', '_')}Tools#{tools_version}Test < Test::Unit::TestCase
13
16
  include UpdatedExampleTestMethods
14
17
  def setup
@@ -23,5 +26,6 @@ class RubotoUpdate#{ruboto_version.gsub('.', '_')}Tools#{tools_version}Test < Te
23
26
  end
24
27
  end
25
28
  EOF
29
+ end
26
30
  end
27
31
  end
data/test/service_test.rb CHANGED
@@ -71,7 +71,7 @@ require 'ruboto/service'
71
71
 
72
72
  class RubotoTestService
73
73
  TARGET_TEXT = 'What hath Matz wrought!'
74
- include Ruboto::Service
74
+
75
75
  def on_create
76
76
  puts "service on_create"
77
77
  Thread.start do
@@ -89,11 +89,6 @@ class RubotoTestService
89
89
 
90
90
  def on_start_command(intent, flags, start_id)
91
91
  puts "service on_start_command(\#{intent}, \#{flags}, \#{start_id})"
92
- getApplication()
93
- getApplication
94
- get_application
95
- application
96
-
97
92
  $ruboto_test_app_activity.set_title 'on_start_command'
98
93
  $ruboto_test_app_activity.set_text TARGET_TEXT
99
94
 
data/test/test_helper.rb CHANGED
@@ -19,7 +19,7 @@ module RubotoTest
19
19
  Gem.paths = GEM_PATH
20
20
  Gem.refresh
21
21
  `gem query -i -n bundler`
22
- system 'gem install bundler' unless $? == 0
22
+ system 'gem install bundler --no-ri --no-rdoc' unless $? == 0
23
23
  `bundle check`
24
24
  system 'bundle --system' unless $? == 0
25
25
  lib_path = File.expand_path('lib', File.dirname(File.dirname(__FILE__)))
@@ -38,19 +38,17 @@ module RubotoTest
38
38
  '2.3.3' => 'android-10', '2.3.4' => 'android-10',
39
39
  '3.0' => 'android-11', '3.1' => 'android-12', '3.2' => 'android-13',
40
40
  '4.0.1' => 'android-14', '4.0.3' => 'android-15', '4.0.4' => 'android-15',
41
- '4.1' => 'android-16',
41
+ '4.1' => 'android-16', '4.1.1' => 'android-16'
42
42
  }
43
43
 
44
44
  def self.version_from_device
45
45
  puts "Reading OS version from device/emulator"
46
46
  system "adb wait-for-device"
47
- start = Time.now
48
47
  IO.popen('adb bugreport').each_line do |line|
49
48
  if line =~ /sdk-eng (.*?) .*? .*? test-keys/
50
49
  version = $1
51
50
  api_level = VERSION_TO_API_LEVEL[version]
52
51
  raise "Unknown version: #{version}" if api_level.nil?
53
- puts "Getting version from device/emulator took #{(Time.now - start).to_i}s"
54
52
  return api_level
55
53
  end
56
54
  if line =~ /\[ro\.build\.version\.sdk\]: \[(\d+)\]/
@@ -64,7 +62,7 @@ module RubotoTest
64
62
  jars_version_from_env = ENV['JRUBY_JARS_VERSION']
65
63
  version_requirement = "-v #{jars_version_from_env}" if jars_version_from_env
66
64
  `gem query -i -n jruby-jars #{version_requirement}`
67
- system "gem install #{jars_version_from_env.nil? || !File.exists?("jruby-jars-#{jars_version_from_env}.gem") ? '-r' : '-l'} jruby-jars #{version_requirement}" unless $? == 0
65
+ system "gem install #{jars_version_from_env.nil? || !File.exists?("jruby-jars-#{jars_version_from_env}.gem") ? '-r' : '-l'} jruby-jars #{version_requirement} --no-ri --no-rdoc" unless $? == 0
68
66
  raise "install of jruby-jars failed with return code #$?" unless $? == 0
69
67
  if jars_version_from_env
70
68
  exclusion_clause = %Q{-v "!=#{jars_version_from_env}"}
@@ -90,10 +88,12 @@ module RubotoTest
90
88
  def install_ruboto_gem(version)
91
89
  version_requirement = "-v #{version}"
92
90
  `gem query -i -n ^ruboto$ #{version_requirement}`
93
- system "gem install ruboto #{version_requirement}" unless $? == 0
91
+ system "gem install ruboto #{version_requirement} --no-ri --no-rdoc" unless $? == 0
94
92
  raise "install of ruboto #{version} failed with return code #$?" unless $? == 0
95
93
  end
96
94
 
95
+ puts RUBY_DESCRIPTION
96
+
97
97
  ANDROID_OS = (ENV['ANDROID_OS'] || version_from_device).slice(/\d+/).to_i
98
98
  puts "ANDROID_OS: #{ANDROID_OS}"
99
99
  puts "ANDROID_TARGET: #{ANDROID_TARGET}"
@@ -128,9 +128,9 @@ class Test::Unit::TestCase
128
128
  alias old_run run
129
129
 
130
130
  def run(*args, &block)
131
- mark_test_start("#{self.class.name}\##{method_name}")
131
+ mark_test_start("#{self.class.name}\##{respond_to?(:method_name) ? method_name : __name__}")
132
132
  old_run(*args, &block)
133
- mark_test_end("#{self.class.name}\##{method_name}")
133
+ mark_test_end("#{self.class.name}\##{respond_to?(:method_name) ? method_name : __name__}")
134
134
  end
135
135
 
136
136
  def mark_test_start(test_name)
@@ -151,7 +151,7 @@ class Test::Unit::TestCase
151
151
 
152
152
  def log(message = '')
153
153
  puts message
154
- system "adb shell log -t 'RUBOTO TEST' '#{message}'"
154
+ `adb shell log -t 'RUBOTO TEST' '#{message}'`
155
155
  end
156
156
 
157
157
  def generate_app(options = {})
@@ -244,7 +244,30 @@ class Test::Unit::TestCase
244
244
  end
245
245
  check_platform_installation(Dir['libs/jruby-core-*.jar'].any?)
246
246
  Dir.chdir APP_DIR do
247
- system 'rake test:quick'
247
+ # FIXME(uwe): Simplify when we stop supporting JRuby < 1.7.0 which causes the ArrayIndexOutOfBoundsException
248
+ # FIXME(uwe): Simplify if we find a cause for the system crashes.
249
+ # system 'rake test:quick' # This line should replace all those below.
250
+
251
+ retries = 0
252
+ loop do
253
+ output = `rake test:quick`
254
+ puts output
255
+ break if $? == 0
256
+ retries += 1
257
+ # FIXME(uwe): The cause of the system crash is unnown. We should investigate.
258
+ if output =~ /INSTRUMENTATION_ABORTED: System has crashed./
259
+ puts "System crash detected."
260
+ elsif (RUBOTO_PLATFORM == 'CURRENT' || JRUBY_JARS_VERSION < Gem::Version.new('1.7.0')) &&
261
+ output =~ /INSTRUMENTATION_RESULT: longMsg=java.lang.ArrayIndexOutOfBoundsException/
262
+ puts "Known ArrayIndexOutOfBoundsException failure detected. Retrying (#{retries})."
263
+ else
264
+ break
265
+ end
266
+ break if retries >= 3
267
+ puts "Retrying (#{retries})."
268
+ end
269
+ # FIXME end
270
+
248
271
  assert_equal 0, $?, "tests failed with return code #$?"
249
272
  end
250
273
  end
@@ -255,7 +278,7 @@ class Test::Unit::TestCase
255
278
  else
256
279
  if RUBOTO_PLATFORM == 'CURRENT'
257
280
  system "rake platform:current platform:install"
258
- elsif RUBOTO_PLATFORM == 'MASTER'
281
+ elsif RUBOTO_PLATFORM == 'FROM_GEM'
259
282
  system "rake platform:debug platform:install"
260
283
  end
261
284
  end
@@ -25,8 +25,11 @@ module UpdateTestMethods
25
25
  assert File.exists? 'src/dummy_receiver.rb'
26
26
  test_file = 'test/src/dummy_receiver_test.rb'
27
27
  assert File.exists? test_file
28
+
29
+ # FIXME(uwe): NOOP?
28
30
  source = File.read(test_file)
29
31
  File.open(test_file, 'w'){|f| f << source}
32
+
30
33
  update_app
31
34
  end
32
35
  run_app_tests
@@ -46,8 +49,11 @@ module UpdateTestMethods
46
49
  assert File.exists? 'src/dummy_receiver.rb'
47
50
  test_file = 'test/src/dummy_receiver_test.rb'
48
51
  assert File.exists? test_file
52
+
53
+ # FIXME(uwe): NOOP?
49
54
  source = File.read(test_file)
50
55
  File.open(test_file, 'w'){|f| f << source}
56
+
51
57
  update_app
52
58
  update_app
53
59
  end
@@ -56,4 +62,20 @@ module UpdateTestMethods
56
62
  # FIXME end
57
63
  end
58
64
 
65
+ def test_subclass_is_updated
66
+ Dir.chdir APP_DIR do
67
+ puts "Adding a subclass"
68
+ install_ruboto_gem @old_ruboto_version
69
+ system "ruboto _#{@old_ruboto_version}_ gen subclass android.database.sqlite.SQLiteOpenHelper --name MyDatabaseHelper --method_base on"
70
+ fail "Creation of subclass failed" if $? != 0
71
+ assert File.exists? 'src/org/ruboto/test_app/MyDatabaseHelper.java'
72
+ # assert File.exists? 'src/my_database_helper.rb'
73
+ # assert File.exists? 'test/src/my_database_helper_test.rb'
74
+
75
+ update_app
76
+ system 'rake debug'
77
+ assert_equal 0, $?
78
+ end
79
+ end
80
+
59
81
  end
@@ -0,0 +1,104 @@
1
+ require File.expand_path("test_helper", File.dirname(__FILE__))
2
+ require 'fileutils'
3
+
4
+ class ViewConstantsTest < Test::Unit::TestCase
5
+ SRC_DIR = "#{APP_DIR}/src"
6
+
7
+ def setup
8
+ generate_app
9
+ end
10
+
11
+ def teardown
12
+ cleanup_app
13
+ end
14
+
15
+ def test_view_constants
16
+ Dir.chdir APP_DIR do
17
+ activity_filename = "#{SRC_DIR}/ruboto_test_app_activity.rb"
18
+ assert File.exists? activity_filename
19
+ File.open(activity_filename, 'w') { |f| f << <<EOF }
20
+ require 'ruboto/activity'
21
+ require 'ruboto/widget'
22
+
23
+ ruboto_import_widgets :Button, :LinearLayout, :TextView
24
+
25
+ class RubotoTestAppActivity
26
+ include Ruboto::Activity
27
+
28
+ def on_create(bundle)
29
+ $ruboto_test_app_activity = self
30
+ set_title 'Domo arigato, Mr Ruboto!'
31
+
32
+ self.content_view =
33
+ linear_layout :orientation => :vertical do
34
+ @text_view = text_view :text => 'What hath Matz wrought?', :id => 42, :width => :fill_parent,
35
+ :gravity => android.view.Gravity::CENTER, :text_size => 48.0
36
+ button :text => 'M-x butterfly', :width => :fill_parent, :id => 43, :on_click_listener => proc { butterfly }
37
+ end
38
+ rescue
39
+ puts "Exception creating activity: \#{$!}"
40
+ puts $!.backtrace.join("\\n")
41
+ end
42
+
43
+ def set_text(text)
44
+ @text_view.text = text
45
+ end
46
+
47
+ private
48
+
49
+ def butterfly
50
+ puts 'butterfly'
51
+ Thread.start do
52
+ begin
53
+ startService(android.content.Intent.new(application_context, $package.RubotoTestService.java_class))
54
+ rescue Exception
55
+ puts "Exception starting the service: \#{$!}"
56
+ puts $!.backtrace.join("\\n")
57
+ end
58
+ end
59
+ puts 'butterfly OK'
60
+ end
61
+
62
+ end
63
+ EOF
64
+ view_constants_test_filename = "#{APP_DIR}/test/src/ruboto_test_app_activity_test.rb"
65
+ assert File.exists? view_constants_test_filename
66
+
67
+ File.open(view_constants_test_filename, 'w') { |f| f << <<EOF }
68
+ activity Java::org.ruboto.test_app.RubotoTestAppActivity
69
+ java_import "android.view.ViewGroup"
70
+ java_import "android.view.Gravity"
71
+ java_import "android.os.Build"
72
+
73
+ setup do |activity|
74
+ start = Time.now
75
+ loop do
76
+ @text_view = activity.findViewById(42)
77
+ break if @text_view || (Time.now - start > 60)
78
+ sleep 1
79
+ end
80
+ assert @text_view
81
+ end
82
+
83
+ def view_constant(const)
84
+ View.convert_constant(const.downcase.to_sym)
85
+ end
86
+
87
+ test('LayoutParams Constants') do |activity|
88
+ ViewGroup::LayoutParams.constants.each do |const|
89
+ assert_equal ViewGroup::LayoutParams.const_get(const), view_constant(const)
90
+ end
91
+ end
92
+
93
+ test('Gravity Constants') do |activity|
94
+ Gravity.constants.each do |const|
95
+ assert_equal Gravity.const_get(const), view_constant(const)
96
+ end
97
+ end
98
+ EOF
99
+
100
+ end
101
+ run_app_tests
102
+ end
103
+
104
+ end