ruby-proxy 0.0.1

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/lib/atu/key.rb ADDED
@@ -0,0 +1,218 @@
1
+ require 'java'
2
+ require 'iconv'
3
+ #require 'drb'
4
+ java_import 'java.awt.event.InputEvent'
5
+ class String
6
+ def to_unicode
7
+ begin
8
+ Iconv.iconv("UNICODEBIG//", "utf-8", self)[0]
9
+ rescue Exception
10
+ puts $!.class
11
+ puts $!.message
12
+ self
13
+ end
14
+ end
15
+ end
16
+
17
+ module ATU
18
+ ##
19
+ # The Shift key modifier constant.
20
+ # This equals to java.awt.event.InputEvent.SHIFT_MASK.
21
+ KEY_SHIFT = InputEvent::SHIFT_MASK
22
+ ##
23
+ # The Ctrl key modifier constant.
24
+ # This equals to java.awt.event.InputEvent.CTRL_MASK.
25
+ KEY_CTRL = InputEvent::CTRL_MASK
26
+ ##
27
+ # The Meta/Windows/Apple key modifier constant.
28
+ # This equals to java.awt.event.InputEvent.META_MASK.
29
+ KEY_META = InputEvent::META_MASK
30
+ ##
31
+ # The Apple(Command) key modifier constant.
32
+ # This equals to java.awt.event.InputEvent.META_MASK.
33
+ KEY_CMD = InputEvent::META_MASK
34
+ ##
35
+ # The Windows key modifier constant.
36
+ # This equals to java.awt.event.InputEvent.META_MASK.
37
+ KEY_WIN = InputEvent::META_MASK
38
+ ##
39
+ # The Alt key modifier constant.
40
+ # This equals to java.awt.event.InputEvent.ALT_MASK.
41
+ KEY_ALT = InputEvent::ALT_MASK
42
+
43
+ ##
44
+ # class Key contains the constants of all special keys.
45
+ class Key
46
+ include DRb::DRbUndumped
47
+ ##
48
+ # ENTER
49
+ ENTER = "\n"
50
+ ##
51
+ # BACKSPACE
52
+ BACKSPACE = "\b"
53
+ ##
54
+ # TAB
55
+ TAB = "\t"
56
+ ##
57
+ # ESC
58
+ ESC = "\u001b".to_unicode
59
+ ##
60
+ # UP
61
+ UP = "\ue000".to_unicode
62
+ ##
63
+ # RIGHT
64
+ RIGHT = "\ue001".to_unicode
65
+ ##
66
+ # DOWN
67
+ DOWN = "\ue002".to_unicode
68
+ ##
69
+ # LEFT
70
+ LEFT = "\ue003".to_unicode
71
+ ##
72
+ # PAGE_UP
73
+ PAGE_UP = "\ue004".to_unicode
74
+ ##
75
+ # PAGE_DOWN
76
+ PAGE_DOWN = "\ue005".to_unicode
77
+ ##
78
+ # DELETE
79
+ DELETE = "\ue006".to_unicode
80
+ ##
81
+ # END
82
+ KEY_END = "\ue007".to_unicode
83
+ ##
84
+ # HOME
85
+ HOME = "\ue008".to_unicode
86
+ ##
87
+ # INSERT
88
+ INSERT = "\ue009".to_unicode
89
+ ##
90
+ # F1
91
+ F1 = "\ue011".to_unicode
92
+ ##
93
+ # F2
94
+ F2 = "\ue012".to_unicode
95
+ ##
96
+ # F3
97
+ F3 = "\ue013".to_unicode
98
+ ##
99
+ # F4
100
+ F4 = "\ue014".to_unicode
101
+ ##
102
+ # F5
103
+ F5 = "\ue015".to_unicode
104
+ ##
105
+ # F6
106
+ F6 = "\ue016".to_unicode
107
+ ##
108
+ # F7
109
+ F7 = "\ue017".to_unicode
110
+ ##
111
+ # F8
112
+ F8 = "\ue018".to_unicode
113
+ ##
114
+ # F9
115
+ F9 = "\ue019".to_unicode
116
+ ##
117
+ # F10
118
+ F10 = "\ue01A".to_unicode
119
+ ##
120
+ # F11
121
+ F11 = "\ue01B".to_unicode
122
+ ##
123
+ # F12
124
+ F12 = "\ue01C".to_unicode
125
+ ##
126
+ # F13
127
+ F13 = "\ue01D".to_unicode
128
+ ##
129
+ # F14
130
+ F14 = "\ue01E".to_unicode
131
+ ##
132
+ # F15
133
+ F15 = "\ue01F".to_unicode
134
+ ##
135
+ # SHIFT
136
+ SHIFT = "\ue020".to_unicode
137
+ ##
138
+ # CTRL
139
+ CTRL = "\ue021".to_unicode
140
+ ##
141
+ # ALT
142
+ ALT = "\ue022".to_unicode
143
+ ##
144
+ # META
145
+ META = "\ue023".to_unicode
146
+ ##
147
+ # META
148
+ CMD = "\ue023".to_unicode
149
+ ##
150
+ # META
151
+ WIN = "\ue023".to_unicode
152
+
153
+ ##
154
+ # PRINTSCREEN
155
+ PRINTSCREEN = "\ue024".to_unicode
156
+ ##
157
+ # SCROLL_LOCK
158
+ SCROLL_LOCK = "\ue025".to_unicode
159
+ ##
160
+ # PAUSE
161
+ PAUSE = "\ue026".to_unicode
162
+ ##
163
+ # CAPS_LOCK
164
+ CAPS_LOCK = "\ue027".to_unicode
165
+
166
+ ##
167
+ # NUM0
168
+ NUM0 = "\ue030".to_unicode
169
+ ##
170
+ # NUM1
171
+ NUM1 = "\ue031".to_unicode
172
+ ##
173
+ # NUM2
174
+ NUM2 = "\ue032".to_unicode
175
+ ##
176
+ # NUM3
177
+ NUM3 = "\ue033".to_unicode
178
+ ##
179
+ # NUM4
180
+ NUM4 = "\ue034".to_unicode
181
+ ##
182
+ # NUM5
183
+ NUM5 = "\ue035".to_unicode
184
+ ##
185
+ # NUM6
186
+ NUM6 = "\ue036".to_unicode
187
+ ##
188
+ # NUM7
189
+ NUM7 = "\ue037".to_unicode
190
+ ##
191
+ # NUM8
192
+ NUM8 = "\ue038".to_unicode
193
+ ##
194
+ # NUM9
195
+ NUM9 = "\ue039".to_unicode
196
+ ##
197
+ # SEPARATOR (numpad)
198
+ SEPARATOR = "\ue03A".to_unicode
199
+ ##
200
+ # NUM_LOCK
201
+ NUM_LOCK = "\ue03B".to_unicode
202
+ ##
203
+ # ADD (numpad)
204
+ ADD = "\ue03C".to_unicode
205
+ ##
206
+ # MINUS (numpad)
207
+ MINUS = "\ue03D".to_unicode
208
+ ##
209
+ # MULTIPLY (numpad)
210
+ MULTIPLY = "\ue03E".to_unicode
211
+ ##
212
+ # DIVIDE (numpad)
213
+ DIVIDE = "\ue03F".to_unicode
214
+ end
215
+ end
216
+
217
+ if __FILE__ == $0
218
+ end
Binary file
data/lib/atu/sikuli.rb ADDED
@@ -0,0 +1,33 @@
1
+ require 'rubygems'
2
+ require 'java'
3
+ #$CLASSPATH << "/Applications/Sikuli-IDE.app/Contents/Resources/Java/"
4
+ #This is key to making it work under ruby. The path above is the default
5
+ #installation location on the Mac which contains all of the
6
+ #relevant sikuli jar files.
7
+ require "sikuli-script.jar"
8
+
9
+ module B
10
+ class C
11
+ end
12
+ end
13
+
14
+
15
+ #~ include Java
16
+ module ATU
17
+ module Sikuli
18
+ java_import 'org.sikuli.script.Region'
19
+ java_import 'org.sikuli.script.Screen'
20
+ java_import 'org.sikuli.script.Settings'
21
+ java_import 'org.sikuli.script.SikuliEvent'
22
+ java_import 'org.sikuli.script.SikuliScript'
23
+ include Java::OrgSikuliScript
24
+ include B
25
+ end
26
+ #Sikuli = Java::OrgSikuliScript
27
+ end
28
+ if __FILE__ == $0
29
+ puts ATU::Sikuli
30
+ @region = ATU::Sikuli::Region.new(0, 0, 1440, 900)
31
+ puts @region.class
32
+ puts ATU::Sikuli::C.new.class
33
+ end
data/lib/ruby_proxy.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'ruby_proxy/client'
2
+ require 'ruby_proxy/version'
@@ -0,0 +1,199 @@
1
+ require 'drb'
2
+ require 'timeout'
3
+ require 'socket'
4
+ require 'logger'
5
+
6
+ module ATU
7
+ #entry
8
+ def self.const_missing(name)
9
+ name = self.name.to_s + "::" + name.to_s
10
+ type = RubyProxy::DRbClient.client.proxy_type(name.to_s)
11
+ make_kclass(name,type)
12
+ end
13
+
14
+ def self.make_kclass(name,type)
15
+ puts "make_kclass: #{name}, #{type}"
16
+ case type
17
+ when "Class"
18
+ RubyProxy::KlassFactory.make_class(name) do |klass|
19
+ klass.class_eval do
20
+ def initialize(*arg)
21
+ #puts self.class.to_s
22
+ @proxy = RubyProxy::DRbClient.client.proxy(self.class.to_s,"new",*arg)
23
+ end
24
+ def method_missing(name,*arg)
25
+ #return if @proxy.nil?
26
+ #puts "#{@proxy.methods(false)}"
27
+ #puts "proxy = #{@proxy} method=#{name} arg=#{arg.join(',')}"
28
+ @proxy.__send__(name.to_s,*arg)
29
+ end
30
+ def self.const_missing(name)
31
+ name = self.name.to_s + "::" + name.to_s
32
+ type = RubyProxy::DRbClient.client.proxy_type(name.to_s)
33
+ ret = ATU::make_kclass(name,type)
34
+ case type
35
+ when "Module","Class"
36
+ return ret
37
+ end
38
+ RubyProxy::DRbClient.client.proxy(name.to_s)
39
+ end
40
+
41
+ # block not support now
42
+ def self.method_missing(name,*arg)
43
+ RubyProxy::DRbClient.client.proxy(self.name.to_s,name.to_s,*arg)
44
+ end
45
+
46
+ end
47
+ end
48
+ when "Module"
49
+ RubyProxy::KlassFactory.make_module(name) do |mod|
50
+ mod.class_eval do
51
+ def self.method_missing(name,*arg)
52
+ RubyProxy::DRbClient.client.proxy(self.name.to_s,name.to_s,*arg)
53
+ end
54
+
55
+ def self.const_missing(name)
56
+ name = self.name.to_s + "::" + name.to_s
57
+ #puts "in module const_missing : #{name}"
58
+ type = RubyProxy::DRbClient.client.proxy_type(name.to_s)
59
+ ret = ATU::make_kclass(name,type)
60
+ case type
61
+ when "Module","Class"
62
+ return ret
63
+ end
64
+ RubyProxy::DRbClient.client.proxy(name.to_s)
65
+ end
66
+ end
67
+ end
68
+ else
69
+
70
+ end
71
+
72
+ end
73
+
74
+ end
75
+
76
+
77
+
78
+ module RubyProxy
79
+ class KlassFactory
80
+ def self.make_klass(klass_name,type)
81
+ case type
82
+ when "Class"
83
+ make_class(klass_name)
84
+ when "Module"
85
+ make_module(klass_name)
86
+ else
87
+ raise TypeError,"wrong make_klass type: #{type}"
88
+ end
89
+ end
90
+
91
+ #生成类,返回类常量
92
+ def self.make_class(klass_name)
93
+ klass_name = klass_name.to_s
94
+ name_ok?(klass_name)
95
+ eval <<-EOF
96
+ class #{klass_name}
97
+ end
98
+ EOF
99
+ klass = eval(klass_name)
100
+ yield klass
101
+ klass
102
+ end
103
+
104
+ def self.make_module(klass_name)
105
+ klass_name = klass_name.to_s
106
+ name_ok?(klass_name)
107
+ eval <<-EOF
108
+ module #{klass_name}
109
+ end
110
+ EOF
111
+ klass = eval(klass_name)
112
+ yield klass
113
+ klass
114
+ end
115
+
116
+ def self.name_ok?(name)
117
+ raise TypeError," name #{name} can't be class or module name." unless name =~ /^[A-Z][a-zA-Z_0-9]*/
118
+ end
119
+ end
120
+ class DRbClient
121
+ @client = nil
122
+ @port = 9000
123
+ @ip = "127.0.0.1"
124
+ @@logger = Logger.new(STDOUT)
125
+ @@logger.level= Logger::DEBUG
126
+ class <<self
127
+ def client
128
+ begin
129
+ stop_service if @client.nil?
130
+ @client ||= DRbObject.new(nil,"druby://#{@ip}:#{@port}")
131
+ alive?
132
+ @client
133
+ rescue Exception
134
+ start_service
135
+ @client ||= DRbObject.new(nil,"druby://#{@ip}:#{@port}")
136
+ @client
137
+ end
138
+ end
139
+
140
+ def alive?
141
+ @client.respond_to?("any_thing")
142
+ @client
143
+ rescue DRb::DRbConnError
144
+ raise
145
+ end
146
+
147
+ attr_accessor :ip,:port
148
+
149
+ def proxy_load(dir_or_file)
150
+ client.proxy_load(dir_or_file)
151
+ end
152
+
153
+ def start_service(t=5)
154
+ message = nil
155
+ @start_service_log_path = File.join(File.dirname(__FILE__),'start_service.log')
156
+
157
+ server_thread = Thread.new do
158
+ @@logger.info "start jruby proxy server..."
159
+ org_path = Dir.pwd
160
+ Dir.chdir(File.join(File.dirname(__FILE__),'..')) do
161
+ system("start /I /B jruby ruby_proxy/server.rb #{@ip} #{@port} #{org_path} ")#> #{@start_service_log_path} 2>&1")
162
+ end
163
+ end
164
+ wait_until_server_start_time(t)
165
+ end
166
+
167
+ def stop_service(t=5)
168
+ TCPSocket.new(@ip,@port)
169
+ @client ||= DRbObject.new(nil,"druby://#{@ip}:#{@port}")
170
+ @client.stop_proxy
171
+ sleep 1
172
+ rescue
173
+ @@logger.debug "service not start,stop fail!"
174
+ @@logger.debug "#{$!}"
175
+ ensure
176
+ @client = nil
177
+ end
178
+
179
+ def wait_until_server_start_time(t)
180
+ t.times do |tt|
181
+ begin
182
+ TCPSocket.new(@ip,@port)
183
+ @@logger.info "server is starting"
184
+ return true
185
+ rescue Exception
186
+ sleep 1
187
+ end
188
+ end
189
+ raise RuntimeError,"start drbserver fail, reason: #{File.read(@start_service_log_path) rescue nil}"
190
+ end
191
+
192
+ end
193
+ end
194
+ end
195
+
196
+ if $0 == __FILE__
197
+ a = ATU::Hello.new
198
+ puts a.return_1
199
+ end
@@ -0,0 +1,60 @@
1
+ require 'logger'
2
+ require 'drb'
3
+ require 'ruby_proxy/proxy_load'
4
+
5
+ module RubyProxy
6
+ class Proxy
7
+ # loading proxy class, default folder: atu
8
+ # you can use Proxy.load_path << "" to add load path
9
+ ProxyLoad.load
10
+ @@logger = Logger.new(STDOUT)
11
+ @@logger.level = Logger::DEBUG
12
+
13
+ def self.proxy(klass_name,method=nil,*arg)
14
+ @@logger.debug "klass_name= #{klass_name}"
15
+ @@logger.debug "method = #{method}"
16
+ @@logger.debug "arg = #{arg.join(',')}"
17
+ if method.nil?
18
+ return proxy_module(klass_name)
19
+ else
20
+ return proxy_module(klass_name).send(method,*arg)
21
+ end
22
+ end
23
+
24
+ def self.proxy_load(dir_or_file)
25
+ ProxyLoad.load_path << dir_or_file
26
+ ProxyLoad.load
27
+ end
28
+
29
+ def self.proxy_type(klass_name)
30
+ #@@logger.debug "proxy_type: #{proxy_const_get(klass_name).name} type is #{proxy_const_get(klass_name).class.to_s}"
31
+ return proxy_const_get(klass_name).class.to_s
32
+ end
33
+
34
+ def self.proxy_module(klass_name)
35
+ m = proxy_const_get(klass_name)
36
+ m.class_eval { include DRb::DRbUndumped } if ( m.class.to_s == "Class" or m.class.to_s == "Module" ) and ! m.include?(DRb::DRbUndumped)
37
+ return m
38
+ end
39
+
40
+ def self.proxy_const_get(klass_name)
41
+ #@@logger.debug "const_get klass_name = #{klass_name}"
42
+ atu = nil
43
+ klass_name_array = klass_name.split('::')
44
+ klass_name_array.shift if klass_name_array[0] == "ATU"
45
+ klass_name_array.each do |m|
46
+ if atu.nil?
47
+ atu = ATU.const_get(m)
48
+ else
49
+ atu = atu.const_get(m)
50
+ end
51
+ end
52
+ atu
53
+ end
54
+
55
+ def self.stop_proxy
56
+ DRb.stop_service
57
+ end
58
+
59
+ end
60
+ end
@@ -0,0 +1,33 @@
1
+ require 'logger'
2
+ module RubyProxy
3
+ class ProxyLoad
4
+ @@logger = Logger.new(STDOUT)
5
+ @@logger.level = Logger::DEBUG
6
+ @load_path = ['atu']
7
+ class <<self
8
+ attr_accessor :load_path
9
+ def load
10
+ load_path.uniq.each do |p|
11
+ if File.directory?(p)
12
+ Dir[p.chomp("/") + "/*.rb"].each do |file|
13
+ load_file(file)
14
+ end
15
+ elsif File.file?(p)
16
+ load_file(p)
17
+ else
18
+ @@logger.warn("path: #{p} not exist ,ignore")
19
+ end
20
+
21
+ end
22
+ end
23
+
24
+ def load_file(file)
25
+ @@logger.debug "require file : #{file}"
26
+ Kernel.require file
27
+ rescue LoadError
28
+ @@logger.warn "require file : #{file} fail,exception:"
29
+ @@logger.warn "#{$!}"
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,32 @@
1
+ require 'drb'
2
+ require 'ruby_proxy/proxy'
3
+ module RubyProxy
4
+ class DRbServer
5
+ @ip = "127.0.0.1"
6
+ @port = 9000
7
+ class << self
8
+ attr_writer :ip,:port
9
+ end
10
+ def self.start_service
11
+ DRb.start_service("druby://#{@ip}:#{@port}",Proxy)
12
+ DRb.thread.join
13
+ end
14
+ def self.stop_service
15
+ DRb.stop_service
16
+ end
17
+ end
18
+ end
19
+
20
+ if $0 == __FILE__
21
+ ['INT'].each do |signal|
22
+ trap(signal) {
23
+ RubyProxy::DRbServer.stop_service
24
+ }
25
+ end
26
+ puts "start server ip:#{ARGV[0]}"
27
+ puts "start server port:#{ARGV[1]}"
28
+ RubyProxy::DRbServer.ip = ARGV[0] unless ARGV[0].nil?
29
+ RubyProxy::DRbServer.port = ARGV[1] unless ARGV[1].nil?
30
+ Dir.chdir ARGV[2] unless ARGV[2].nil?
31
+ RubyProxy::DRbServer.start_service
32
+ end
@@ -0,0 +1,3 @@
1
+ module RubyProxy
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,3 @@
1
+ require 'setup'
2
+
3
+ $all_tests.each { |f| require f }
@@ -0,0 +1,9 @@
1
+
2
+ $LOAD_PATH.unshift File.join(__FILE__,'..','..','lib') unless $LOADED
3
+ $LOADED = true
4
+
5
+ require 'test/unit'
6
+
7
+ require 'ruby_proxy'
8
+
9
+ $all_tests = Dir['test_*.rb']
@@ -0,0 +1,94 @@
1
+ module B
2
+ def b
3
+ return "b"
4
+ end
5
+ class H
6
+ end
7
+ end
8
+
9
+
10
+ module ATU
11
+ class Hello
12
+ def initialize
13
+ end
14
+
15
+ def return_1
16
+ 1
17
+ end
18
+ def return_str_1
19
+ "1"
20
+ end
21
+
22
+ def return_with_2ps(a,b)
23
+ return a,b
24
+ end
25
+
26
+ def return_vars(*a)
27
+ return a[0],a[1]
28
+ end
29
+
30
+
31
+ end
32
+
33
+ class Hello2
34
+ def return_1
35
+ "hello2"
36
+ end
37
+
38
+ end
39
+
40
+ class Hello3
41
+ def initialize(a,b)
42
+ end
43
+ def method_missing(m,*arg)
44
+ return m.to_s
45
+ end
46
+
47
+ end
48
+
49
+ module M1
50
+
51
+ def self.m
52
+ "m"
53
+ end
54
+
55
+ class Hello4
56
+ def test
57
+ return "test"
58
+ end
59
+ def one(p)
60
+ return "one"
61
+ end
62
+ end
63
+ class Hello5
64
+ def ok
65
+ 1
66
+ end
67
+ end
68
+
69
+ class Hello6
70
+ include B
71
+ C = 1
72
+ def self.a(*arg)
73
+ return arg
74
+ end
75
+
76
+ def a(*arg)
77
+ var = 1
78
+ yield var
79
+ end
80
+ def b(*arg)
81
+ var = 1
82
+ yield var if block_given?
83
+ arg
84
+ end
85
+
86
+ def self.file_exist?(path)
87
+ File.exist?(path)
88
+ end
89
+ end
90
+
91
+ end
92
+
93
+ end
94
+
Binary file
Binary file
@@ -0,0 +1,130 @@
1
+ require 'setup'
2
+
3
+ class Me
4
+ def a
5
+ "a"
6
+ end
7
+
8
+ end
9
+
10
+
11
+ class TestDrbProxy < Test::Unit::TestCase
12
+ @@atu = nil
13
+ def setup
14
+ return unless @@atu.nil?
15
+ @@atu = File.expand_path(File.join(__FILE__,'..','support','atu'))
16
+ RubyProxy::DRbClient.proxy_load(@@atu)
17
+ end
18
+
19
+ def test_server_start_auto
20
+ assert_kind_of(DRbObject,RubyProxy::DRbClient.client)
21
+ end
22
+ def test_atu_ok
23
+ a = ATU::Hello.new
24
+ puts "aaa= #{a}"
25
+ assert_equal(1,a.return_1)
26
+ assert_equal("1",a.return_str_1)
27
+ end
28
+
29
+ def test_mutli_new
30
+ a = ATU::Hello.new
31
+ assert_equal(1,a.return_1)
32
+ b = ATU::Hello.new
33
+ assert_equal(1,a.return_1)
34
+ a2 = ATU::Hello2.new
35
+ assert_equal("hello2",a2.return_1)
36
+ end
37
+
38
+ def test_pars
39
+ a = ATU::Hello.new
40
+ assert_equal([1,"1"],a.return_with_2ps(1,"1"))
41
+ end
42
+
43
+ #可变参测试
44
+ def test_vars
45
+ a = Me.new
46
+ assert_equal("a",a.a)
47
+ a = ATU::Hello.new
48
+ assert_equal([1,"1"],a.return_vars(1,"1",3,4))
49
+ assert_equal([1,"1"],a.return_vars(1,"1",3,4))
50
+ assert_equal([1,"1"],a.return_vars(1,"1",3,4))
51
+ assert_equal([1,"1"],a.return_vars(1,"1",3,4))
52
+ assert_equal([1,"1"],a.return_vars(1,"1",3,4))
53
+ assert_equal([1,"1"],a.return_vars(1,"1",3,4))
54
+ end
55
+
56
+ def test_support_thread
57
+ a = Me.new
58
+ assert_equal("a",a.a)
59
+ t = Thread.new do
60
+ a = ATU::Hello.new
61
+ for i in 1..100 do
62
+ assert_equal(1,a.return_1)
63
+ assert_equal(1,a.return_1)
64
+
65
+ #sleep 1
66
+ end
67
+ end
68
+ b = ATU::Hello.new
69
+ assert_equal(1,b.return_1)
70
+ assert_equal("1",b.return_str_1)
71
+ #sleep 20
72
+
73
+ assert_equal("1",b.return_str_1)
74
+ t.join
75
+ c = ATU::Hello.new
76
+ assert_equal(1,c.return_1)
77
+ end
78
+
79
+ def test_method_missing1
80
+ a = ATU::Hello3.new(1,"2")
81
+ i=1
82
+ 1.upto(100) do |i|
83
+ assert_equal("method#{i}",a.send("method#{i}"))
84
+ end
85
+ end
86
+
87
+
88
+
89
+
90
+ def test_atu_gue
91
+ assert_raise(NameError) do
92
+ ATU::ExistNo.new
93
+ end
94
+ end
95
+
96
+ def test_atu_sikuli
97
+ screen = ATU::Sikuli::Region.new(0,0,1440,900)
98
+ assert_not_nil(screen)
99
+ end
100
+ #多个模块内的调用
101
+ def test_multi_m
102
+ a = ATU::M1::Hello4.new
103
+ assert_equal("one",a.one("test"))
104
+ end
105
+
106
+ def test_include_other_module
107
+ a = ATU::M1::Hello6.new
108
+ assert("b",a.b)
109
+ end
110
+ def test_constant_should_ok
111
+ assert(1,ATU::M1::Hello6::C)
112
+ end
113
+
114
+ def test_class_module_function_should_ok
115
+ assert([1,"1"],ATU::M1::Hello6.a(1,"1"))
116
+ assert("m",ATU::M1::m)
117
+ end
118
+ # failed, fix me
119
+ def test_block_ok
120
+ a = ATU::M1::Hello6.new
121
+ assert_equal(1,a.a() {|i| i})
122
+ end
123
+
124
+ def test_file_path
125
+ assert_equal([__FILE__],ATU::M1::Hello6.a(__FILE__))
126
+ path = File.join(__FILE__,'..','support','atu','hello.rb')
127
+ assert_equal(true,ATU::M1::Hello6.file_exist?(path))
128
+ end
129
+
130
+ end
@@ -0,0 +1,33 @@
1
+ require 'setup'
2
+
3
+ class TestSikuliApi < Test::Unit::TestCase
4
+ @@image_path = nil
5
+ def setup
6
+ @@image_path ||= File.join(__FILE__,'..','support','image')
7
+ end
8
+ def test_sikuli_module
9
+ screen = ATU::Sikuli::Screen.new
10
+ assert_equal(0,screen.x)
11
+ assert_equal(0,screen.y)
12
+ assert_equal(true,screen.w > 0)
13
+ assert_equal(true,screen.h > 0)
14
+ end
15
+
16
+ def test_screen_click
17
+ #region = ATU::Sikuli::Region.new(0,0,1440,900)
18
+ region = ATU::Sikuli::Screen.new
19
+ assert_equal(0,region.x)
20
+ assert_equal(0,region.y)
21
+ assert_equal(true,File.exist?(File.join(@@image_path,"start.png")))
22
+ region.click(File.expand_path(File.join(@@image_path, "start.png")),0)
23
+ assert_nothing_raised do
24
+ region.wait(File.expand_path(File.join(@@image_path,"search.png")),10)
25
+ end
26
+ #~ region.type(ATU::Key.ESC)
27
+ #~ assert_nothing_raised do
28
+ #~ region.waitVanish(File.expand_path(File.join(@@image_path,"search.png")),10)
29
+ #~ end
30
+ end
31
+
32
+
33
+ end
@@ -0,0 +1,26 @@
1
+ require 'setup'
2
+ require 'atu/sikuli'
3
+ class TestSikuliApi < Test::Unit::TestCase
4
+ @@image_path = nil
5
+ def setup
6
+ @@image_path ||= File.join(__FILE__,'..','support','image')
7
+ end
8
+ def test_sikuli_module
9
+ screen = ATU::Sikuli::Screen.new
10
+ assert_equal(0,screen.x)
11
+ assert_equal(0,screen.y)
12
+ assert_equal(true,screen.w > 0)
13
+ assert_equal(true,screen.h > 0)
14
+ end
15
+
16
+ def test_region_offen_used
17
+ region = ATU::Sikuli::Region.new(0,0,1440,900)
18
+ assert_equal(0,region.x)
19
+ assert_equal(0,region.y)
20
+ assert_equal(true,File.exist?(File.join(@@image_path,"start.png")))
21
+ region.click(File.join(@@image_path, "start.png"),0)
22
+ puts region.wait(File.join(@@image_path,"search.png"),10)
23
+ end
24
+
25
+
26
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-proxy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - yafei Li
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2011-08-10 00:00:00 +08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Ruby Proxy for Jruby.
17
+ email: lyfi2003@sina.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/atu
26
+ - lib/atu/key.rb
27
+ - lib/atu/sikuli-script.jar
28
+ - lib/atu/sikuli.rb
29
+ - lib/ruby_proxy
30
+ - lib/ruby_proxy/client.rb
31
+ - lib/ruby_proxy/proxy.rb
32
+ - lib/ruby_proxy/proxy_load.rb
33
+ - lib/ruby_proxy/server.rb
34
+ - lib/ruby_proxy/version.rb
35
+ - lib/ruby_proxy.rb
36
+ has_rdoc: false
37
+ homepage: https://github.com/windy/ruby_proxy
38
+ post_install_message:
39
+ rdoc_options: []
40
+
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ requirements: []
56
+
57
+ rubyforge_project: ruby-proxy
58
+ rubygems_version: 1.3.1
59
+ signing_key:
60
+ specification_version: 2
61
+ summary: Ruby Proxy for Jruby.
62
+ test_files:
63
+ - unittests/all_tests.rb
64
+ - unittests/setup.rb
65
+ - unittests/support
66
+ - unittests/support/atu
67
+ - unittests/support/atu/hello.rb
68
+ - unittests/support/image
69
+ - unittests/support/image/search.png
70
+ - unittests/support/image/start.png
71
+ - unittests/test_drb_proxy.rb
72
+ - unittests/test_sikuli_api.rb
73
+ - unittests/your_jruby_sikuli_config_ok.rb