require File.expand_path("test_helper", File.dirname(__FILE__)) require 'fileutils' class ServiceGenClassTest < Minitest::Test SRC_DIR = "#{APP_DIR}/src" def setup generate_app end def teardown cleanup_app end def test_service_startup # FIXME(uwe): Remove when Android L is released or service start is fixed return if ANDROID_OS == 21 # EMXIF Dir.chdir APP_DIR do system "#{RUBOTO_CMD} gen class Service --name RubotoTestService" activity_filename = "#{SRC_DIR}/ruboto_test_app_activity.rb" assert File.exists? activity_filename File.open(activity_filename, 'w') { |f| f << < :vertical do @text_view = text_view :text => 'What hath Matz wrought?', :id => 42, :layout => {:width => :fill_parent}, :gravity => android.view.Gravity::CENTER, :text_size => 48.0 button :text => 'M-x butterfly', :layout => {:width => :fill_parent}, :id => 43, :on_click_listener => proc { butterfly } end rescue puts "Exception creating activity: \#{$!}" puts $!.backtrace.join("\\n") end def set_text(text) @text_view.text = text end private def butterfly puts 'butterfly' Thread.start do begin puts 'activity start service...' start_ruboto_service("RubotoTestService") puts 'activity start service...OK' rescue Exception puts "Exception starting the service: \#{$!}" puts $!.backtrace.join("\\n") end end puts 'butterfly OK' end end EOF service_filename = "#{SRC_DIR}/ruboto_test_service.rb" assert File.exists? service_filename File.open(service_filename, 'w') { |f| f << < 60) sleep 1 end assert @text_view end test 'button changes text', :ui => false do |activity| button = activity.findViewById(43) puts 'Clicking...' activity.run_on_ui_thread{button.performClick} puts 'Clicked!' start = Time.now loop do break if @text_view.text == 'What hath Matz wrought!' || (Time.now - start > 60) sleep 1 end assert_equal 'What hath Matz wrought!', @text_view.text end EOF end run_app_tests end end