require File.expand_path('test_helper', File.dirname(__FILE__)) require 'bigdecimal' require 'test/app_test_methods' class RubotoGenTest < Test::Unit::TestCase include AppTestMethods def setup generate_app end def teardown cleanup_app end def test_gitignore_is_included_in_new_project Dir.chdir APP_DIR do assert File.exists? '.gitignore' end end def test_icons_are_updated Dir.chdir APP_DIR do assert_equal 3834, File.size('res/drawable-hdpi/ic_launcher.png') assert_equal 2513, File.size('res/drawable-mdpi/ic_launcher.png') assert_equal 1689, File.size('res/drawable-ldpi/ic_launcher.png') end end def test_activity_with_number_in_name Dir.chdir APP_DIR do system "#{RUBOTO_CMD} gen class Activity --name App1Activity" assert_equal 0, $?.exitstatus assert File.exists?('src/org/ruboto/test_app/App1Activity.java') assert File.exists?('src/app1_activity.rb') assert File.exists?('test/src/app1_activity_test.rb') end run_app_tests end def test_gen_class_activity_with_lowercase_should_fail Dir.chdir APP_DIR do system "#{RUBOTO_CMD} gen class activity --name VeryNewActivity" assert_equal 1, $?.exitstatus assert !File.exists?('src/org/ruboto/test_app/VeryNewActivity.java') assert !File.exists?('src/very_new_activity.rb') assert !File.exists?('test/src/very_new_activity_test.rb') assert File.read('AndroidManifest.xml') !~ /VeryNewActivity/ end end # APK was 59.6KB. PLATFORM: CURRENT, ANDROID_TARGET: 10 # APK was 60.2KB. PLATFORM: CURRENT, ANDROID_TARGET: 15 # APK was 74.9KB. PLATFORM: CURRENT, ANDROID_TARGET: 16 # APK was 57.1KB. PLATFORM: FROM_GEM, ANDROID_TARGET: 10 # APK was 8428.4KB. PLATFORM: STANDALONE, ANDROID_TARGET: 10, JRuby: 1.7.4 # APK was 7405.8KB. PLATFORM: STANDALONE, ANDROID_TARGET: 15, JRuby: 1.7.4 # APK was 7420.9KB. PLATFORM: STANDALONE, ANDROID_TARGET: 16, JRuby: 1.7.4 # APK was 8755.5KB. PLATFORM: STANDALONE, ANDROID_TARGET: 15, JRuby: 1.7.5 # APK was 8770.2KB. PLATFORM: STANDALONE, ANDROID_TARGET: 16, JRuby: 1.7.5 # APK was 8766.1KB. PLATFORM: STANDALONE, ANDROID_TARGET: 16, JRuby: 1.7.6 # APK was 8781.6KB. PLATFORM: STANDALONE, ANDROID_TARGET: 16, JRuby: 1.7.8 # APK was 8789.6KB. PLATFORM: STANDALONE, ANDROID_TARGET: 16, JRuby: 1.7.9 # APK was 6689.5KB. PLATFORM: STANDALONE, ANDROID_TARGET: 10, JRuby: 9000.dev # APK was 6962.1KB. PLATFORM: STANDALONE, ANDROID_TARGET: 16, JRuby: 9000.dev def test_new_apk_size_is_within_limits apk_size = BigDecimal(File.size("#{APP_DIR}/bin/RubotoTestApp-debug.apk").to_s) / 1024 version = " PLATFORM: #{RUBOTO_PLATFORM}" version << ", ANDROID_TARGET: #{ANDROID_TARGET}" if RUBOTO_PLATFORM == 'STANDALONE' upper_limit = { '1.7.4' => 8500.0, '1.7.5' => 8800.0, '1.7.6' => 8800.0, '1.7.8' => 8800.0, '1.7.9' => 8800.0, '9000.dev' => 7000.0, }[JRUBY_JARS_VERSION.to_s] || 0.0 version << ", JRuby: #{JRUBY_JARS_VERSION.to_s}" else upper_limit = { 10 => 60.0, 15 => 62.0, 16 => 75.0, }[ANDROID_TARGET] || 75.0 end lower_limit = upper_limit * 0.9 assert apk_size <= upper_limit, "APK was larger than #{'%.1f' % upper_limit}KB: #{'%.1f' % apk_size.ceil(1)}KB.#{version}" 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}" end def test_gen_subclass Dir.chdir APP_DIR do system "#{RUBOTO_CMD} gen subclass android.database.sqlite.SQLiteOpenHelper --name MyDatabaseHelper --method_base on" assert_equal 0, $?.exitstatus assert File.exists?('src/org/ruboto/test_app/MyDatabaseHelper.java') assert File.exists?('src/my_database_helper.rb') assert File.exists?('test/src/my_database_helper_test.rb') system 'rake debug' assert_equal 0, $? end end def test_gen_subclass_of_array_adapter Dir.chdir APP_DIR do system "#{RUBOTO_CMD} gen subclass android.widget.ArrayAdapter --name RubotoArrayAdapter --method_base all" assert_equal 0, $?.exitstatus java_source_file = 'src/org/ruboto/test_app/RubotoArrayAdapter.java' assert File.exists?(java_source_file) # FIXME(uwe): Workaround for Ruboto Issue #246 java_source = File.read(java_source_file) File.open(java_source_file, 'w'){|f| f << java_source.gsub(/^(public class .*ArrayAdapter) (.*ArrayAdapter)/, '\1 \2').gsub(/T.class/, 'Object.class')} # EMXIF assert File.exists?('src/ruboto_array_adapter.rb') assert File.exists?('test/src/ruboto_array_adapter_test.rb') File.open('src/ruboto_test_app_activity.rb', 'w'){|f| f << < 'First row'}, {:image => resources.get_drawable($package.R::drawable::get_ruboto_core), :text1 => 'Second row'}, 'Third row'] adapter = $package.RubotoArrayAdapter.new(self, $package.R::layout::list_item, AndroidIds::text1, records) puts "adapter: \#{adapter.inspect}" self.content_view = linear_layout :orientation => :vertical do @text_view = text_view :text => 'What hath Matz wrought?', :id => 42, :layout => {:width => :match_parent}, :gravity => :center, :text_size => 48.0 list_view :adapter => adapter, :id => 43, :on_item_click_listener => proc{|parent, view, position, id| @text_view.text = 'List item clicked!'} end end end EOF File.open('test/src/ruboto_test_app_activity_test.rb', 'w'){|f| f << < 60) puts "Waiting for adapter: \#{@list_view && @list_view.adapter.inspect}" sleep 1 end assert @text_view assert @list_view assert @list_view.adapter end test('Item click changes text') do |activity| text_view = activity.findViewById(42) list_view = activity.findViewById(43) list_view.perform_item_click(list_view.adapter.get_view(1, nil, nil), 1, 1) assert_equal 'List item clicked!', text_view.text end EOF File.open('src/ruboto_array_adapter.rb', 'w'){|f| f << < EOF end run_app_tests end def test_activity_with_first_letter_lower_case_in_name Dir.chdir APP_DIR do system "#{RUBOTO_CMD} gen class Activity --name appActivity" assert_equal 0, $?.exitstatus assert File.exists?('src/org/ruboto/test_app/AppActivity.java') assert File.exists?('src/app_activity.rb') assert File.exists?('test/src/app_activity_test.rb') end end if RUBOTO_PLATFORM == 'FROM_GEM' def test_gen_jruby Dir.chdir APP_DIR do system "#{RUBOTO_CMD} gen jruby" assert_equal 0, $?.exitstatus assert_equal %W(libs/jruby-core-#{JRUBY_JARS_VERSION.to_s.downcase}.jar), Dir['libs/jruby-core-*.jar'].map(&:downcase) assert_equal %W(libs/jruby-stdlib-#{JRUBY_JARS_VERSION.to_s.downcase}.jar), Dir['libs/jruby-stdlib-*.jar'].map(&:downcase) end end end end