semilla 0.0.3 → 0.0.4

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/README.md ADDED
@@ -0,0 +1,56 @@
1
+
2
+ # Semilla Gem #
3
+
4
+ This gem adds some rake tasks for testing ActionScript applications with the FlexUnit4 testing framework.
5
+
6
+
7
+ ## Installation ##
8
+
9
+ To install with rake:
10
+
11
+ $ rake
12
+
13
+ To install with gem:
14
+
15
+ $ gem build semilla.gemspec
16
+ $ gem install semilla-VERSION.gem
17
+
18
+
19
+ ## Usage ##
20
+
21
+ Generate a TestRunner
22
+
23
+ Semilla::test_runner "outputfile.as", FileList["test-src/**/*Test.as"], 1026
24
+
25
+
26
+ Run the test and obtain a report.
27
+
28
+ Semilla::flex_unit :taskname => [dependencies]] do |t|
29
+ t.serverPort = 1026
30
+ t.swf = "app.swf"
31
+ t.reportpath = "reports"
32
+ t.timeout = 10
33
+ end
34
+
35
+ ## MIT License ##
36
+
37
+ <pre>
38
+ Copyright (c)2011-2012 Victor G. Rosales
39
+
40
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
41
+ this software and associated documentation files (the "Software"), to deal in
42
+ the Software without restriction, including without limitation the rights to
43
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
44
+ the Software, and to permit persons to whom the Software is furnished to do so,
45
+ subject to the following conditions:
46
+
47
+ The above copyright notice and this permission notice shall be included in all
48
+ copies or substantial portions of the Software.
49
+
50
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
51
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
52
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
53
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
54
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
55
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
56
+ </pre>
@@ -0,0 +1,21 @@
1
+ require_relative "platform"
2
+
3
+ module Semilla
4
+
5
+ def self.run_player(flashbin, swf)
6
+
7
+ command = ""
8
+
9
+ if is_mac?
10
+ command = "open -a \"#{flashbin}\" \"#{swf}\""
11
+ else
12
+ command = "\"#{flashbin}\" \"#{swf}\""
13
+ end
14
+
15
+ puts command
16
+
17
+ return %x[#{command}]
18
+
19
+ end
20
+
21
+ end
@@ -0,0 +1,15 @@
1
+ module Semilla
2
+
3
+ def self.is_mac?
4
+ RUBY_PLATFORM.downcase.include?("darwin")
5
+ end
6
+
7
+ def self.is_windows?
8
+ RUBY_PLATFORM.downcase.include?("mswin")
9
+ end
10
+
11
+ def self.is_linux?
12
+ RUBY_PLATFORM.downcase.include?("linux")
13
+ end
14
+
15
+ end
@@ -1,153 +1,153 @@
1
- require "socket"
2
- require "timeout"
3
-
4
- module Semilla
5
-
6
- class FlexUnitReportServer
7
-
8
- attr_accessor :results
9
- attr_reader :error
10
-
11
- START_ACK = "<startOfTestRunAck/>"
12
- END_TEST = "<endOfTestRun/>"
13
- END_TEST_ACK = "<endOfTestRunAck/>"
14
- POLICY_REQUEST = "<policy-file-request/>"
15
- EOF = "\0"
16
- SOCKET_POLICY_FILE = <<EOS
17
- <?xml version="1.0"?>
18
- <!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
19
- <cross-domain-policy>
20
- <allow-access-from domain="*" to-ports="@@@"/>
21
- </cross-domain-policy>
22
- EOS
23
-
24
-
25
- def initialize(port=1026)
26
- @port = port
27
- @addr = "127.0.0.1"
28
- @server = nil #This will be our socket server
29
- @error = false
30
- end
31
-
32
-
33
- def start(timeout=10)
34
- @server = TCPServer.new(@addr, @port)
35
- #view server data
36
- puts @server.addr
37
-
38
- #open the socket
39
- puts "Opening server at port #{@port}"
40
-
41
- #--------------------------------------------------------------
42
- #the report result will be here
43
- report = ""
44
-
45
- loop {
46
- puts "Waiting for client..."
47
-
48
- begin
49
- #Wait with a timeout
50
- client = Timeout::timeout timeout do
51
- @server.accept
52
- end
53
- #No client connected within the time limit, bail out
54
- rescue Timeout::Error
55
- puts "Timeout!!, no client connected!!!"
56
- @error = true
57
- break
58
- end
59
- puts "Client connected..."
60
- puts "Receiving data"
61
- #Tell FlexUnit to start sending stuff
62
- client.puts START_ACK + EOF
63
- #puts "[OUT] #{START_ACK}"
64
- report = "<report>"
65
- error = false
66
- while received = receiveWithTimeout(client, timeout)
67
- unless received != ""
68
- finished = true
69
- puts "empty data!!"
70
- error = true
71
- break
72
- end
73
- #puts received
74
- putc '.'
75
- #clean up the text
76
- received.rstrip!
77
- received.chomp!
78
-
79
- #print out for debug
80
- #puts "[IN] #{received}"
81
-
82
- #check for policy file
83
- if received.include? POLICY_REQUEST
84
- self.sendPolicyFile client
85
- client.close
86
- puts "[OUT] Sending policy File"
87
- break
88
- end
89
-
90
- if received.include? END_TEST
91
-
92
- #the last message may contain some data as well
93
- report = report + received.sub(END_TEST, "")
94
-
95
- puts
96
- puts "Closing connection"
97
- #Test ended, send ACK to client
98
- client.puts END_TEST_ACK + EOF
99
- client.flush
100
- client.close
101
- finished = true
102
- report = report + "</report>"
103
- break
104
- end
105
-
106
- report = report + received
107
-
108
- end
109
-
110
- if error
111
- report = nil
112
- end
113
- break if finished
114
-
115
-
116
- }
117
- #Parse the xml from flexunit and generate the report files.
118
- puts "bye bye"
119
- #sanitize the results string
120
- @results = report.delete "\000" unless report.nil?
121
- #---------------------------------------------------------------
122
-
123
- end
124
-
125
-
126
- def policyFile
127
- return SOCKET_POLICY_FILE.sub "@@@", @port #replace the @@@ for the port number
128
- end
129
-
130
-
131
- def sendPolicyFile(client)
132
- puts "Sending policy file."
133
- #Send policy stuff
134
- client.puts self.policyFile
135
- client.flush
136
- end
137
-
138
-
139
- def receiveWithTimeout(client, timeout)
140
-
141
- begin
142
- r = Timeout::timeout timeout do
143
- client.recv(1024)
144
- end
145
- rescue Timeout::Error
146
- "" #Timed out, return an empty string
147
- end
148
-
149
- end
150
-
151
- end
152
-
1
+ require "socket"
2
+ require "timeout"
3
+
4
+ module Semilla
5
+
6
+ class FlexUnitReportServer
7
+
8
+ attr_accessor :results
9
+ attr_reader :error
10
+
11
+ START_ACK = "<startOfTestRunAck/>"
12
+ END_TEST = "<endOfTestRun/>"
13
+ END_TEST_ACK = "<endOfTestRunAck/>"
14
+ POLICY_REQUEST = "<policy-file-request/>"
15
+ EOF = "\0"
16
+ SOCKET_POLICY_FILE = <<EOS
17
+ <?xml version="1.0"?>
18
+ <!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
19
+ <cross-domain-policy>
20
+ <allow-access-from domain="*" to-ports="@@@"/>
21
+ </cross-domain-policy>
22
+ EOS
23
+
24
+
25
+ def initialize(port=1026)
26
+ @port = port
27
+ @addr = "127.0.0.1"
28
+ @server = nil #This will be our socket server
29
+ @error = false
30
+ end
31
+
32
+
33
+ def start(timeout=10)
34
+ @server = TCPServer.new(@addr, @port)
35
+ #view server data
36
+ puts @server.addr
37
+
38
+ #open the socket
39
+ puts "Opening server at port #{@port}"
40
+
41
+ #--------------------------------------------------------------
42
+ #the report result will be here
43
+ report = ""
44
+
45
+ loop {
46
+ puts "Waiting for client..."
47
+
48
+ begin
49
+ #Wait with a timeout
50
+ client = Timeout::timeout timeout do
51
+ @server.accept
52
+ end
53
+ #No client connected within the time limit, bail out
54
+ rescue Timeout::Error
55
+ puts "Timeout!!, no client connected!!!"
56
+ @error = true
57
+ break
58
+ end
59
+ puts "Client connected..."
60
+ puts "Receiving data"
61
+ #Tell FlexUnit to start sending stuff
62
+ client.puts START_ACK + EOF
63
+ #puts "[OUT] #{START_ACK}"
64
+ report = "<report>"
65
+ error = false
66
+ while received = receiveWithTimeout(client, timeout)
67
+ unless received != ""
68
+ finished = true
69
+ puts "empty data!!"
70
+ error = true
71
+ break
72
+ end
73
+ #puts received
74
+ putc '.'
75
+ #clean up the text
76
+ received.rstrip!
77
+ received.chomp!
78
+
79
+ #print out for debug
80
+ #puts "[IN] #{received}"
81
+
82
+ #check for policy file
83
+ if received.include? POLICY_REQUEST
84
+ self.sendPolicyFile client
85
+ client.close
86
+ puts "[OUT] Sending policy File"
87
+ break
88
+ end
89
+
90
+ if received.include? END_TEST
91
+
92
+ #the last message may contain some data as well
93
+ report = report + received.sub(END_TEST, "")
94
+
95
+ puts
96
+ puts "Closing connection"
97
+ #Test ended, send ACK to client
98
+ client.puts END_TEST_ACK + EOF
99
+ client.flush
100
+ client.close
101
+ finished = true
102
+ report = report + "</report>"
103
+ break
104
+ end
105
+
106
+ report = report + received
107
+
108
+ end
109
+
110
+ if error
111
+ report = nil
112
+ end
113
+ break if finished
114
+
115
+
116
+ }
117
+ #Parse the xml from flexunit and generate the report files.
118
+ puts "bye bye"
119
+ #sanitize the results string
120
+ @results = report.delete "\000" unless report.nil?
121
+ #---------------------------------------------------------------
122
+
123
+ end
124
+
125
+
126
+ def policyFile
127
+ return SOCKET_POLICY_FILE.sub "@@@", @port #replace the @@@ for the port number
128
+ end
129
+
130
+
131
+ def sendPolicyFile(client)
132
+ puts "Sending policy file."
133
+ #Send policy stuff
134
+ client.puts self.policyFile
135
+ client.flush
136
+ end
137
+
138
+
139
+ def receiveWithTimeout(client, timeout)
140
+
141
+ begin
142
+ r = Timeout::timeout timeout do
143
+ client.recv(1024)
144
+ end
145
+ rescue Timeout::Error
146
+ "" #Timed out, return an empty string
147
+ end
148
+
149
+ end
150
+
151
+ end
152
+
153
153
  end