ruboto-core 0.2.1 → 0.3.3

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.
@@ -1,4 +1,5 @@
1
1
  require 'ruboto/api'
2
+ require 'yaml'
2
3
 
3
4
  module Ruboto
4
5
  module Util
@@ -18,6 +19,16 @@ module Ruboto
18
19
  File.open("AndroidManifest.xml", 'w') {|f| verify_manifest.document.write(f, 4)}
19
20
  end
20
21
 
22
+ def verify_test_manifest
23
+ abort "cannot find your test AndroidManifest.xml to extract info from it. Make sure you're in the root directory of your app" \
24
+ unless File.exists? 'test/AndroidManifest.xml'
25
+ @manifest ||= REXML::Document.new(File.read('test/AndroidManifest.xml')).root
26
+ end
27
+
28
+ def save_test_manifest
29
+ File.open("test/AndroidManifest.xml", 'w') {|f| verify_test_manifest.document.write(f, 4)}
30
+ end
31
+
21
32
  def verify_package
22
33
  verify_manifest
23
34
  @package ||= @manifest.attribute('package').value
@@ -58,6 +69,19 @@ module Ruboto
58
69
  def verify_api
59
70
  Ruboto::API.api
60
71
  end
72
+
73
+ def verify_ruboto_config
74
+ if File.exists? 'ruboto.yml'
75
+ @ruboto_config ||= YAML::load_file('ruboto.yml')
76
+ else
77
+ @ruboto_config = {}
78
+ end
79
+ end
80
+
81
+ def save_ruboto_config
82
+ File.open("ruboto.yml", 'w') {|f| YAML.dump verify_ruboto_config}
83
+ end
84
+
61
85
  end
62
86
  end
63
87
  end
@@ -156,9 +156,8 @@ module Ruboto
156
156
 
157
157
  params = parameters
158
158
  args = ""
159
- if params.size > 3
160
- args = ", args"
161
- rv << "Object[] args = {" + params.map{|i| i[0]}.join(", ") + "};"
159
+ if params.size > 1
160
+ args = ", new Object[]{" + params.map{|i| i[0]}.join(", ") + "}"
162
161
  elsif params.size > 0
163
162
  args = ", " + params.map{|i| i[0]}.join(", ")
164
163
  end
@@ -177,13 +176,7 @@ module Ruboto
177
176
  convert_return = ", #{return_class}.class"
178
177
  end
179
178
 
180
- if return_class == 'Integer'
181
- # TODO(uwe): This is a fix for JRUBY-5937 Remove when the issue is fixed.
182
- rv << "#{return_cast}((Number)getRuby().callMethod(callbackProcs[#{constant_string}], \"call\" #{args}#{convert_return})).intValue();"
183
- # TODO end
184
- else
185
179
  rv << "#{return_cast}getRuby().callMethod(callbackProcs[#{constant_string}], \"call\" #{args}#{convert_return});"
186
- end
187
180
  rv
188
181
  end
189
182
 
@@ -1,4 +1,4 @@
1
- activity Java::org.ruboto.test_app.RubotoTestAppActivity
1
+ activity Java::org.ruboto.test_app.ImageButtonActivity
2
2
 
3
3
  setup do |activity|
4
4
  start = Time.now
@@ -21,11 +21,4 @@ $activity.handle_create do |bundle|
21
21
  end
22
22
  end
23
23
 
24
- # handle_image_click do |view|
25
- # if view.id == 43
26
- # @text_view.text = 'Image button pressed'
27
- # elsif view.id == 44
28
- # @text_view.text = 'Button pressed'
29
- # end
30
- # end
31
24
  end
@@ -1,4 +1,4 @@
1
- activity Java::org.ruboto.test_app.RubotoTestAppActivity
1
+ activity Java::org.ruboto.test_app.ImageButtonAndButtonActivity
2
2
 
3
3
  setup do |activity|
4
4
  start = Time.now
@@ -0,0 +1,21 @@
1
+ require 'ruboto'
2
+
3
+ ruboto_import_widgets :ImageButton, :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 = text_view :text => 'What hath Matz wrought?', :id => 42
11
+ end
12
+ end
13
+
14
+ handle_create_options_menu do |menu|
15
+ add_menu('Test') do
16
+ @text_view.setText 'What hath Matz wrought!'
17
+ toast 'Flipped a bit via butterfly'
18
+ end
19
+ true
20
+ end
21
+ end
@@ -0,0 +1,20 @@
1
+ activity Java::org.ruboto.test_app.OptionMenuActivity
2
+
3
+ setup do |activity|
4
+ start = Time.now
5
+ loop do
6
+ @text_view = activity.findViewById(42)
7
+ break if @text_view || (Time.now - start > 60)
8
+ sleep 1
9
+ end
10
+ assert @text_view
11
+ end
12
+
13
+ test('initial setup') do |activity|
14
+ assert_equal "What hath Matz wrought?", @text_view.text
15
+ end
16
+
17
+ test('option_menu changes text') do |activity|
18
+ activity.window.performPanelIdentifierAction(android.view.Window::FEATURE_OPTIONS_PANEL, 0, 0)
19
+ assert_equal "What hath Matz wrought!", @text_view.text
20
+ end
@@ -8,47 +8,40 @@ module AppTestMethods
8
8
  puts "Skipping instrumentation tests on #{ANDROID_OS} since they don't work."
9
9
  end
10
10
  else
11
- def test_that_tests_work_on_new_project
12
- run_app_tests
13
- end
14
-
15
- if not ON_JRUBY_JARS_1_5_6
16
- def test_that_yaml_loads
17
- assert_code "with_large_stack{require 'yaml'}"
11
+ def test_activity_tests
12
+ if not ON_JRUBY_JARS_1_5_6
13
+ assert_code 'YamlLoads', "with_large_stack{require 'yaml'}"
14
+ else
15
+ puts "Skipping YAML tests on jruby-jars-1.5.6"
18
16
  end
19
- else
20
- puts "Skipping YAML tests on jruby-jars-1.5.6"
21
- end
22
17
 
23
- def test_file_read_source_file
24
- assert_code "File.read(__FILE__)"
25
- end
18
+ assert_code 'ReadSourceFile', "File.read(__FILE__)"
26
19
 
27
- Dir.chdir File.expand_path('activity', File.dirname(__FILE__)) do
28
- Dir['*_test.rb'].each do |test|
29
- class_eval %Q{
30
- def test_#{test.chomp('_test.rb')}
31
- filename = "#{APP_DIR}/assets/scripts/ruboto_test_app_activity.rb"
32
- test_filename = "#{APP_DIR}/test/assets/scripts/ruboto_test_app_activity_test.rb"
33
- File.open(filename, 'w') { |f| f << File.read('#{PROJECT_DIR}/test/activity/#{test.gsub('_test', '')}') }
34
- File.open(test_filename, 'w') { |f| f << File.read('#{PROJECT_DIR}/test/activity/#{test}') }
35
- run_app_tests
20
+ Dir[File.expand_path('activity/*_test.rb', File.dirname(__FILE__))].each do |test_src|
21
+ snake_name = test_src.chomp('_test.rb')
22
+ activity_name = File.basename(snake_name).split('_').map { |s| "#{s[0..0].upcase}#{s[1..-1]}" }.join
23
+ Dir.chdir APP_DIR do
24
+ system "#{RUBOTO_CMD} gen class Activity --name #{activity_name}"
25
+ FileUtils.cp "#{snake_name}.rb", "assets/scripts/"
26
+ FileUtils.cp test_src, "test/assets/scripts/"
36
27
  end
37
- }
38
- puts "Creating test from file #{PROJECT_DIR}/test/activity/#{test}"
39
28
  end
29
+ run_app_tests
40
30
  end
41
31
 
42
32
  private
43
33
 
44
- def assert_code(code)
45
- filename = "#{APP_DIR}/assets/scripts/ruboto_test_app_activity.rb"
46
- s = File.read(filename)
47
- s.gsub!(/(require 'ruboto')/, "\\1\n#{code}")
48
- File.open(filename, 'w') { |f| f << s }
49
- run_app_tests
34
+ def assert_code(activity_name, code)
35
+ snake_name = activity_name.scan(/[A-Z]+[a-z]+/).map { |s| s.downcase }.join('_')
36
+ filename = "assets/scripts/#{snake_name}_activity.rb"
37
+ Dir.chdir APP_DIR do
38
+ system "#{RUBOTO_CMD} gen class Activity --name #{activity_name}Activity"
39
+ s = File.read(filename)
40
+ s.gsub!(/(require 'ruboto')/, "\\1\n#{code}")
41
+ File.open(filename, 'w') { |f| f << s }
42
+ end
50
43
  end
51
44
 
52
45
  end
53
46
 
54
- end
47
+ end
@@ -0,0 +1,22 @@
1
+ require File.expand_path("test_helper", File.dirname(__FILE__))
2
+
3
+ class MinimalAppTest < Test::Unit::TestCase
4
+ def setup
5
+ generate_app :excluded_stdlibs => %w{ant cgi digest dl drb ffi irb net optparse racc rbconfig rdoc rexml rinda rss rubygems runit shell soap test uri webrick win32 wsdl xmlrpc xsd}
6
+ end
7
+
8
+ def teardown
9
+ cleanup_app
10
+ end
11
+
12
+ def test_minimal_apk_is_less_than_3_mb
13
+ apk_size = File.size("#{APP_DIR}/bin/RubotoTestApp-debug.apk").to_f / (1024 * 1024)
14
+ limit = 3.0
15
+ assert apk_size < limit, "APK was larger than #{'%.1f' % limit}MB: #{'%.1f' % apk_size}MB"
16
+ end
17
+
18
+ def test_minimal_apk_succeeds_tests
19
+ run_app_tests
20
+ end
21
+
22
+ end
data/test/rake_test.rb CHANGED
@@ -1,7 +1,4 @@
1
1
  require File.expand_path("test_helper", File.dirname(__FILE__))
2
- require 'fileutils'
3
-
4
- $stdout.sync = true
5
2
 
6
3
  class RakeTest < Test::Unit::TestCase
7
4
  def setup
@@ -18,7 +15,7 @@ class RakeTest < Test::Unit::TestCase
18
15
  File.open("#{APP_DIR}/AndroidManifest.xml", 'w') { |f| f << manifest }
19
16
 
20
17
  Dir.chdir APP_DIR do
21
- system 'rake install:restart:clean'
18
+ system 'rake install:clean start'
22
19
  assert_equal 0, $?
23
20
  end
24
21
 
@@ -31,23 +28,11 @@ class RakeTest < Test::Unit::TestCase
31
28
  else
32
29
  def test_that_update_scripts_task_copies_files_to_app_directory_when_permissions_are_not_set
33
30
  Dir.chdir APP_DIR do
34
- system 'rake install:restart:clean'
31
+ system 'rake install:clean start'
35
32
  assert_equal 0, $?
36
33
  end
37
34
  wait_for_dir("/data/data/#{PACKAGE}/files/scripts")
38
35
  end
39
36
  end
40
37
 
41
- private
42
-
43
- def wait_for_dir(dir)
44
- puts "Waiting for app to generate script directory: #{dir}"
45
- start = Time.now
46
- loop do
47
- break if `adb shell ls -d #{dir}`.chomp =~ %r{^#{dir}$}
48
- flunk 'Timeout waiting for scripts directory to appear' if Time.now > start + 60
49
- sleep 1
50
- end
51
- end
52
-
53
38
  end
@@ -1,5 +1,4 @@
1
1
  require File.expand_path("test_helper", File.dirname(__FILE__))
2
- require 'fileutils'
3
2
  require 'test/app_test_methods'
4
3
 
5
4
  class RubotoGenTest < Test::Unit::TestCase
@@ -12,20 +11,32 @@ class RubotoGenTest < Test::Unit::TestCase
12
11
  def teardown
13
12
  cleanup_app
14
13
  end
14
+
15
+ def test_icons_are_updated
16
+ Dir.chdir APP_DIR do
17
+ assert_equal 4032, File.size('res/drawable-hdpi/icon.png')
18
+ end
19
+ end
20
+
21
+ def test_gen_class_activity_with_lowercase_should_fail
22
+ Dir.chdir APP_DIR do
23
+ system "#{RUBOTO_CMD} gen class activity --name VeryNewActivity"
24
+ assert_equal 1, $?.exitstatus
25
+ assert !File.exists?('src/org/ruboto/test_app/VeryNewActivity.java')
26
+ assert !File.exists?('assets/scripts/very_new_activity.rb')
27
+ assert !File.exists?('test/assets/scripts/very_new_activity_test.rb')
28
+ assert File.read('AndroidManifest.xml') !~ /VeryNewActivity/
29
+ end
30
+ end
31
+
15
32
  end
16
33
 
17
34
  if not RubotoTest::ON_JRUBY_JARS_1_5_6
18
- class RubotoGenWithPsychTest < Test::Unit::TestCase
19
- include AppTestMethods
20
-
35
+ class RubotoGenWithPsychTest < RubotoGenTest
21
36
  def setup
22
37
  generate_app :with_psych => true
23
38
  end
24
39
 
25
- def teardown
26
- cleanup_app
27
- end
28
-
29
40
  def test_psych_jar_exists
30
41
  assert File.exists?("#{APP_DIR}/libs/psych.jar"), "Failed to generate psych jar"
31
42
  end
@@ -1,28 +1,11 @@
1
1
  require File.expand_path("test_helper", File.dirname(__FILE__))
2
- require 'fileutils'
3
2
  require 'test/app_test_methods'
4
3
 
5
4
  module UpdateTestMethods
6
5
  include RubotoTest
7
6
 
8
7
  def setup(with_psych = false)
9
- Dir.mkdir TMP_DIR unless File.exists? TMP_DIR
10
- FileUtils.rm_rf APP_DIR if File.exists? APP_DIR
11
- Dir.chdir TMP_DIR do
12
- system "tar xzf #{PROJECT_DIR}/examples/RubotoTestApp_0.1.0_jruby_1.6.3.dev.tgz"
13
- end
14
- if ENV['ANDROID_HOME']
15
- android_home = ENV['ANDROID_HOME']
16
- else
17
- android_home = File.dirname(File.dirname(`which adb`))
18
- end
19
- File.open("#{APP_DIR}/local.properties", 'w'){|f| f.puts "sdk.dir=#{android_home}"}
20
- File.open("#{APP_DIR}/test/local.properties", 'w'){|f| f.puts "sdk.dir=#{android_home}"}
21
- Dir.chdir APP_DIR do
22
- FileUtils.touch "libs/psych.jar" if with_psych
23
- system "#{RUBOTO_CMD} update app"
24
- assert_equal 0, $?, "update app failed with return code #$?"
25
- end
8
+ generate_app(:with_psych => with_psych, :update => true)
26
9
  end
27
10
 
28
11
  def teardown
@@ -35,6 +18,13 @@ module UpdateTestMethods
35
18
  assert_equal 1, File.readlines('test/build.xml').grep(/<macrodef name="run-tests-helper">/).size, 'Duplicate macro in build.xml'
36
19
  end
37
20
  end
21
+
22
+ def test_icons_are_untouched
23
+ Dir.chdir APP_DIR do
24
+ assert_equal 4100, File.size('res/drawable-hdpi/icon.png')
25
+ end
26
+ end
27
+
38
28
  end
39
29
 
40
30
  class RubotoUpdateTest < Test::Unit::TestCase
data/test/service_test.rb CHANGED
@@ -2,8 +2,6 @@ require File.expand_path("test_helper", File.dirname(__FILE__))
2
2
  require 'fileutils'
3
3
 
4
4
  class ServiceTest < Test::Unit::TestCase
5
- include RubotoTest
6
-
7
5
  def setup
8
6
  generate_app
9
7
  end
@@ -44,6 +42,6 @@ EOF
44
42
  File.open(activity_filename, 'w') { |f| f << s }
45
43
  end
46
44
  run_app_tests
47
- end
45
+ end
48
46
 
49
- end
47
+ end
data/test/test_helper.rb CHANGED
@@ -1,11 +1,17 @@
1
1
  require 'test/unit'
2
2
  require 'rubygems'
3
+ require 'fileutils'
4
+ require 'yaml'
3
5
 
4
6
  module RubotoTest
5
7
  PROJECT_DIR = File.expand_path('..', File.dirname(__FILE__))
6
8
  $LOAD_PATH << PROJECT_DIR
7
9
 
8
- gem_spec = Gem.searcher.find('jruby-jars')
10
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.8.0')
11
+ gem_spec = Gem::Specification.find_by_path 'jruby-jars'
12
+ else
13
+ gem_spec = Gem.searcher.find('jruby-jars')
14
+ end
9
15
  raise StandardError.new("Can't find Gem specification jruby-jars.") unless gem_spec
10
16
  JRUBY_JARS_VERSION = gem_spec.version
11
17
  ON_JRUBY_JARS_1_5_6 = JRUBY_JARS_VERSION == Gem::Version.new('1.5.6')
@@ -35,6 +41,9 @@ module RubotoTest
35
41
  puts "Getting version from device/emulator took #{(Time.now - start).to_i}s"
36
42
  return api_level
37
43
  end
44
+ if line =~ /\[ro\.build\.version\.sdk\]: \[(\d+)\]/
45
+ return $1
46
+ end
38
47
  end
39
48
  raise "Unable to read device/emulator apilevel"
40
49
  end
@@ -77,19 +86,47 @@ class Test::Unit::TestCase
77
86
 
78
87
  def generate_app(options = {})
79
88
  with_psych = options.delete(:with_psych) || false
89
+ update = options.delete(:update) || false
90
+ excluded_stdlibs = options.delete(:excluded_stdlibs)
80
91
  raise "Unknown options: #{options.inspect}" unless options.empty?
81
92
  Dir.mkdir TMP_DIR unless File.exists? TMP_DIR
82
93
  FileUtils.rm_rf APP_DIR if File.exists? APP_DIR
83
- template_dir = "#{APP_DIR}_template_#{$$}#{'_with_psych' if with_psych}"
94
+ template_dir = "#{APP_DIR}_template_#{$$}#{'_with_psych' if with_psych}#{'_updated' if update}#{"_without_#{excluded_stdlibs.join('_')}" if excluded_stdlibs}"
84
95
  if File.exists?(template_dir)
85
96
  puts "Copying app from template #{template_dir}"
86
97
  FileUtils.cp_r template_dir, APP_DIR, :preserve => true
87
98
  else
88
- puts "Generating app #{APP_DIR}"
89
- system "#{RUBOTO_CMD} gen app --package #{PACKAGE} --path #{APP_DIR} --name #{APP_NAME} --min_sdk #{ANDROID_TARGET} #{'--with-psych' if with_psych}"
90
- if $? != 0
91
- FileUtils.rm_rf template_dir
92
- raise "gen app failed with return code #$?"
99
+ if update
100
+ Dir.chdir TMP_DIR do
101
+ system "tar xzf #{PROJECT_DIR}/examples/RubotoTestApp_0.1.0_jruby_1.6.3.dev.tgz"
102
+ end
103
+ if ENV['ANDROID_HOME']
104
+ android_home = ENV['ANDROID_HOME']
105
+ else
106
+ android_home = File.dirname(File.dirname(`which adb`))
107
+ end
108
+ Dir.chdir APP_DIR do
109
+ File.open('local.properties', 'w'){|f| f.puts "sdk.dir=#{android_home}"}
110
+ File.open('test/local.properties', 'w'){|f| f.puts "sdk.dir=#{android_home}"}
111
+ FileUtils.touch "libs/psych.jar" if with_psych
112
+ exclude_stdlibs(excluded_stdlibs) if excluded_stdlibs
113
+ system "#{RUBOTO_CMD} update app"
114
+ assert_equal 0, $?, "update app failed with return code #$?"
115
+ end
116
+ else
117
+ puts "Generating app #{APP_DIR}"
118
+ system "#{RUBOTO_CMD} gen app --package #{PACKAGE} --path #{APP_DIR} --name #{APP_NAME} --target #{ANDROID_TARGET} #{'--with-psych' if with_psych}"
119
+ if $? != 0
120
+ FileUtils.rm_rf APP_DIR
121
+ raise "gen app failed with return code #$?"
122
+ end
123
+ if excluded_stdlibs
124
+ Dir.chdir APP_DIR do
125
+ exclude_stdlibs(excluded_stdlibs)
126
+ system "#{RUBOTO_CMD} update jruby --force"
127
+ raise "update jruby failed with return code #$?" if $? != 0
128
+ end
129
+ end
93
130
  end
94
131
  Dir.chdir APP_DIR do
95
132
  system 'rake debug'
@@ -111,4 +148,19 @@ class Test::Unit::TestCase
111
148
  end
112
149
  end
113
150
 
151
+ def wait_for_dir(dir)
152
+ puts "Waiting for app to generate script directory: #{dir}"
153
+ start = Time.now
154
+ loop do
155
+ break if `adb shell ls -d #{dir}`.chomp =~ %r{^#{dir}$}
156
+ flunk 'Timeout waiting for scripts directory to appear' if Time.now > start + 120
157
+ sleep 1
158
+ end
159
+ end
160
+
161
+ def exclude_stdlibs(excluded_stdlibs)
162
+ puts "Adding ruboto.yml: #{excluded_stdlibs.join(' ')}"
163
+ File.open('ruboto.yml', 'w'){|f| f << YAML.dump({:excluded_stdlibs => excluded_stdlibs})}
164
+ end
165
+
114
166
  end