ADB 0.1 → 0.2

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.
data/ChangeLog CHANGED
@@ -1,4 +1,10 @@
1
- === 0.1 / 2012-8-10
1
+ === Release 0.2 / 2012-8-18
2
+ * Enhancements
3
+ * Added forward method
4
+ * Added shell method
5
+ * Added helper method to format dates for Android
6
+
7
+ === Release 0.1 / 2012-8-10
2
8
  Initial release of the gem. It has support for the following commands
3
9
  * start-server => start_server
4
10
  * kill-server => stop_server
@@ -22,3 +22,14 @@ Feature: Using the ADB module
22
22
  Given the adb server is started
23
23
  And I am connected to the local device
24
24
  Then I should be able to uninstall the sample application
25
+
26
+ Scenario: Use shell to update the system date
27
+ Given the adb server is started
28
+ And I am connected to the local device
29
+ When I change the devices date and time to 08/10/2012 11:25
30
+ Then the device time should be Aug 10 11:25:00 EDT 2012
31
+
32
+ Scenario: Forwarding ports
33
+ Given the adb server is started
34
+ And I am connected to the local device
35
+ Then I should be able to forward "tcp:7777" to "tcp:5555"
@@ -32,3 +32,18 @@ Then /^I should be able to uninstall the sample application$/ do
32
32
  uninstall 'com.example.android.apis', {:serial => sn}
33
33
  last_stdout.should include 'Success'
34
34
  end
35
+
36
+ When /^I change the devices date and time to (.*?)$/ do |date_arg|
37
+ sn = devices[0]
38
+ date = DateTime.strptime(date_arg, '%m/%d/%C%y %I:%M')
39
+ shell("date -s #{format_date_for_adb(date)}", {:serial => sn}, 60)
40
+ end
41
+
42
+ Then /^the device time should be Aug (.*?)$/ do |date_str|
43
+ last_stdout.should include date_str
44
+ end
45
+
46
+ Then /^I should be able to forward "(.*?)" to "(.*?)"$/ do |source, target|
47
+ sn = devices[0]
48
+ forward(source, target, {:serial => sn})
49
+ end
data/lib/ADB.rb CHANGED
@@ -110,6 +110,42 @@ module ADB
110
110
  raise ADBError, "Could not uninstall #{package}" unless stdout_contains "Success"
111
111
  end
112
112
 
113
+ #
114
+ # execute shell command
115
+ #
116
+ # @param [String] command to be passed to the shell command
117
+ # @param [Hash] which device to wait for. Valid keys are :device,
118
+ # :emulator, and :serial.
119
+ # @param timeout value for the command to complete. Defaults to 30
120
+ # seconds.
121
+ #
122
+ def shell(command, target={}, timeout=30)
123
+ execute_adb_with(timeout, "#{which_one(target)} wait-for-device shell #{command}")
124
+ end
125
+
126
+ #
127
+ # format a date for adb shell date command
128
+ #
129
+ # @param date to format. Defaults current date
130
+ #
131
+ def format_date_for_adb(date=Date.new)
132
+ date.strftime("%C%y%m%d.%H%M00")
133
+ end
134
+
135
+ #
136
+ # setup port forwarding
137
+ #
138
+ # @param the source protocol:port
139
+ # @param the destination protocol:port
140
+ # @param [Hash] which device to wait for. Valid keys are :device,
141
+ # :emulator, and :serial.
142
+ # @param timeout value for the command to complete. Defaults to 30
143
+ # seconds.
144
+ #
145
+ def forward(source, destination, target={}, timeout=30)
146
+ execute_adb_with(timeout, "#{which_one(target)} forward #{source} #{destination}")
147
+ end
148
+
113
149
  private
114
150
 
115
151
  def execute_adb_with(timeout, arguments)
@@ -1,3 +1,3 @@
1
1
  module ADB
2
- VERSION = "0.1"
2
+ VERSION = "0.2"
3
3
  end
@@ -29,6 +29,23 @@ describe ADB do
29
29
  ADB.devices
30
30
  end
31
31
 
32
+ context "when executing a shell command" do
33
+ it "should be able to check the device date and time" do
34
+ should_call_adb_with('wait-for-device', 'shell', 'date')
35
+ ADB.shell('date')
36
+ end
37
+ end
38
+
39
+ it "should be able to build an date formatted for adb shell date command" do
40
+ date = DateTime.strptime('04/23/2012 13:24', '%m/%d/%C%y %H:%M')
41
+ ADB.format_date_for_adb(date).should eq "20120423.132400"
42
+ end
43
+
44
+ it "should setup port forwarding" do
45
+ should_call_adb_with('forward', 'src', 'dest')
46
+ ADB.forward('src', 'dest')
47
+ end
48
+
32
49
  context "when connecting to a device" do
33
50
  before(:each) do
34
51
  ADB.should_receive(:last_stdout).and_return("connected to localhost")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ADB
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-11 00:00:00.000000000 Z
12
+ date: 2012-08-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: childprocess
@@ -100,7 +100,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
100
100
  version: '0'
101
101
  segments:
102
102
  - 0
103
- hash: 1303897695555104367
103
+ hash: -1607274235838869715
104
104
  required_rubygems_version: !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
109
  version: '0'
110
110
  segments:
111
111
  - 0
112
- hash: 1303897695555104367
112
+ hash: -1607274235838869715
113
113
  requirements: []
114
114
  rubyforge_project:
115
115
  rubygems_version: 1.8.24