taf2-curb 0.2.3
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/LICENSE +51 -0
- data/README +128 -0
- data/Rakefile +303 -0
- data/doc.rb +42 -0
- data/ext/curb.c +337 -0
- data/ext/curb.h +40 -0
- data/ext/curb.rb +46 -0
- data/ext/curb_easy.c +2540 -0
- data/ext/curb_easy.h +94 -0
- data/ext/curb_errors.c +518 -0
- data/ext/curb_errors.h +117 -0
- data/ext/curb_macros.h +114 -0
- data/ext/curb_multi.c +323 -0
- data/ext/curb_multi.h +25 -0
- data/ext/curb_postfield.c +499 -0
- data/ext/curb_postfield.h +40 -0
- data/ext/curl.rb +2 -0
- data/ext/extconf.rb +25 -0
- data/tests/helper.rb +71 -0
- data/tests/tc_curl_easy.rb +524 -0
- data/tests/tc_curl_multi.rb +249 -0
- data/tests/tc_curl_postfield.rb +141 -0
- data/tests/unittests.rb +2 -0
- metadata +77 -0
@@ -0,0 +1,249 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'helper')
|
2
|
+
|
3
|
+
class TestCurbCurlMulti < Test::Unit::TestCase
|
4
|
+
def teardown
|
5
|
+
# get a better read on memory loss when running in valgrind
|
6
|
+
ObjectSpace.garbage_collect
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_new_multi_01
|
10
|
+
d1 = ""
|
11
|
+
c1 = Curl::Easy.new($TEST_URL) do |curl|
|
12
|
+
curl.headers["User-Agent"] = "myapp-0.0"
|
13
|
+
curl.on_body {|d| d1 << d; d.length }
|
14
|
+
end
|
15
|
+
|
16
|
+
d2 = ""
|
17
|
+
c2 = Curl::Easy.new($TEST_URL) do |curl|
|
18
|
+
curl.headers["User-Agent"] = "myapp-0.0"
|
19
|
+
curl.on_body {|d| d2 << d; d.length }
|
20
|
+
end
|
21
|
+
|
22
|
+
m = Curl::Multi.new
|
23
|
+
|
24
|
+
m.add( c1 )
|
25
|
+
m.add( c2 )
|
26
|
+
|
27
|
+
m.perform
|
28
|
+
|
29
|
+
assert_match(/^# DO NOT REMOVE THIS COMMENT/, d1)
|
30
|
+
assert_match(/^# DO NOT REMOVE THIS COMMENT/, d2)
|
31
|
+
|
32
|
+
m = nil
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_perform_block
|
37
|
+
c1 = Curl::Easy.new($TEST_URL)
|
38
|
+
c2 = Curl::Easy.new($TEST_URL)
|
39
|
+
|
40
|
+
m = Curl::Multi.new
|
41
|
+
|
42
|
+
m.add( c1 )
|
43
|
+
m.add( c2 )
|
44
|
+
|
45
|
+
m.perform do
|
46
|
+
# idle
|
47
|
+
puts "idling..."
|
48
|
+
end
|
49
|
+
|
50
|
+
assert_match(/^# DO NOT REMOVE THIS COMMENT/, c1.body_str)
|
51
|
+
assert_match(/^# DO NOT REMOVE THIS COMMENT/, c2.body_str)
|
52
|
+
|
53
|
+
m = nil
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_n_requests
|
58
|
+
n = 100
|
59
|
+
m = Curl::Multi.new
|
60
|
+
responses = []
|
61
|
+
n.times do|i|
|
62
|
+
responses[i] = ""
|
63
|
+
c = Curl::Easy.new($TEST_URL) do|curl|
|
64
|
+
curl.on_body{|data| responses[i] << data; data.size }
|
65
|
+
end
|
66
|
+
m.add c
|
67
|
+
end
|
68
|
+
|
69
|
+
m.perform
|
70
|
+
|
71
|
+
assert n, responses.size
|
72
|
+
n.times do|i|
|
73
|
+
assert_match(/^# DO NOT REMOVE THIS COMMENT/, responses[i], "response #{i}")
|
74
|
+
end
|
75
|
+
|
76
|
+
m = nil
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_n_requests_with_break
|
80
|
+
# process n requests then load the handle again and run it again
|
81
|
+
n = 2
|
82
|
+
m = Curl::Multi.new
|
83
|
+
5.times do|it|
|
84
|
+
responses = []
|
85
|
+
n.times do|i|
|
86
|
+
responses[i] = ""
|
87
|
+
c = Curl::Easy.new($TEST_URL) do|curl|
|
88
|
+
curl.on_body{|data| responses[i] << data; data.size }
|
89
|
+
end
|
90
|
+
m.add c
|
91
|
+
end
|
92
|
+
|
93
|
+
m.perform
|
94
|
+
|
95
|
+
assert n, responses.size
|
96
|
+
n.times do|i|
|
97
|
+
assert_match(/^# DO NOT REMOVE THIS COMMENT/, responses[i], "response #{i}")
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
m = nil
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_with_success
|
106
|
+
c1 = Curl::Easy.new($TEST_URL)
|
107
|
+
c2 = Curl::Easy.new($TEST_URL)
|
108
|
+
success_called1 = false
|
109
|
+
success_called2 = false
|
110
|
+
|
111
|
+
c1.on_success do|c|
|
112
|
+
success_called1 = true
|
113
|
+
assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)
|
114
|
+
end
|
115
|
+
|
116
|
+
c2.on_success do|c|
|
117
|
+
success_called2 = true
|
118
|
+
assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)
|
119
|
+
end
|
120
|
+
|
121
|
+
m = Curl::Multi.new
|
122
|
+
|
123
|
+
m.add( c1 )
|
124
|
+
m.add( c2 )
|
125
|
+
|
126
|
+
m.perform do
|
127
|
+
# idle
|
128
|
+
puts "idling..."
|
129
|
+
end
|
130
|
+
|
131
|
+
assert success_called2
|
132
|
+
assert success_called1
|
133
|
+
|
134
|
+
m = nil
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_with_success_cb_with_404
|
138
|
+
c1 = Curl::Easy.new("#{$TEST_URL.gsub(/file:\/\//,'')}/not_here")
|
139
|
+
c2 = Curl::Easy.new($TEST_URL)
|
140
|
+
success_called1 = false
|
141
|
+
success_called2 = false
|
142
|
+
|
143
|
+
c1.on_success do|c|
|
144
|
+
success_called1 = true
|
145
|
+
#puts "success 1 called: #{c.body_str.inspect}"
|
146
|
+
#assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)
|
147
|
+
end
|
148
|
+
|
149
|
+
c1.on_failure do|c|
|
150
|
+
#puts "failure called: #{c.body_str.inspect}"
|
151
|
+
end
|
152
|
+
|
153
|
+
c2.on_success do|c|
|
154
|
+
# puts "success 2 called: #{c.body_str.inspect}"
|
155
|
+
success_called2 = true
|
156
|
+
assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)
|
157
|
+
end
|
158
|
+
|
159
|
+
m = Curl::Multi.new
|
160
|
+
|
161
|
+
#puts "c1: #{c1.url}"
|
162
|
+
m.add( c1 )
|
163
|
+
#puts "c2: #{c2.url}"
|
164
|
+
m.add( c2 )
|
165
|
+
|
166
|
+
#puts "calling"
|
167
|
+
m.perform do
|
168
|
+
# idle
|
169
|
+
end
|
170
|
+
|
171
|
+
assert success_called2
|
172
|
+
assert !success_called1
|
173
|
+
|
174
|
+
m = nil
|
175
|
+
end
|
176
|
+
|
177
|
+
class TestForScope
|
178
|
+
attr_reader :buf
|
179
|
+
|
180
|
+
def t_method
|
181
|
+
@buf = ""
|
182
|
+
@m = Curl::Multi.new
|
183
|
+
10.times do
|
184
|
+
c = Curl::Easy.new($TEST_URL)
|
185
|
+
c.on_success{|b| @buf << b.body_str }
|
186
|
+
ObjectSpace.garbage_collect
|
187
|
+
@m.add(c)
|
188
|
+
ObjectSpace.garbage_collect
|
189
|
+
end
|
190
|
+
ObjectSpace.garbage_collect
|
191
|
+
end
|
192
|
+
|
193
|
+
def t_call
|
194
|
+
@m.perform do
|
195
|
+
ObjectSpace.garbage_collect
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
def self.test
|
200
|
+
ObjectSpace.garbage_collect
|
201
|
+
tfs = TestForScope.new
|
202
|
+
ObjectSpace.garbage_collect
|
203
|
+
tfs.t_method
|
204
|
+
ObjectSpace.garbage_collect
|
205
|
+
tfs.t_call
|
206
|
+
ObjectSpace.garbage_collect
|
207
|
+
|
208
|
+
tfs.buf
|
209
|
+
end
|
210
|
+
|
211
|
+
end
|
212
|
+
|
213
|
+
def test_with_garbage_collect
|
214
|
+
ObjectSpace.garbage_collect
|
215
|
+
buf = TestForScope.test
|
216
|
+
ObjectSpace.garbage_collect
|
217
|
+
assert_match(/^# DO NOT REMOVE THIS COMMENT/, buf)
|
218
|
+
end
|
219
|
+
|
220
|
+
=begin
|
221
|
+
def test_remote_requests
|
222
|
+
responses = {}
|
223
|
+
requests = ["http://google.co.uk/", "http://ruby-lang.org/"]
|
224
|
+
m = Curl::Multi.new
|
225
|
+
# add a few easy handles
|
226
|
+
requests.each do |url|
|
227
|
+
responses[url] = ""
|
228
|
+
responses["#{url}-header"] = ""
|
229
|
+
c = Curl::Easy.new(url) do|curl|
|
230
|
+
curl.follow_location = true
|
231
|
+
curl.on_header{|data| responses["#{url}-header"] << data; data.size }
|
232
|
+
curl.on_body{|data| responses[url] << data; data.size }
|
233
|
+
curl.on_success {
|
234
|
+
puts curl.last_effective_url
|
235
|
+
}
|
236
|
+
end
|
237
|
+
m.add(c)
|
238
|
+
end
|
239
|
+
|
240
|
+
m.perform
|
241
|
+
|
242
|
+
requests.each do|url|
|
243
|
+
puts responses["#{url}-header"].split("\r\n").inspect
|
244
|
+
#puts responses[url].size
|
245
|
+
end
|
246
|
+
end
|
247
|
+
=end
|
248
|
+
|
249
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'helper')
|
2
|
+
|
3
|
+
class TestCurbCurlPostfield < Test::Unit::TestCase
|
4
|
+
def test_private_new
|
5
|
+
assert_raise(NoMethodError) { Curl::PostField.new }
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_new_content_01
|
9
|
+
pf = Curl::PostField.content('foo', 'bar')
|
10
|
+
|
11
|
+
assert_equal 'foo', pf.name
|
12
|
+
assert_equal 'bar', pf.content
|
13
|
+
assert_nil pf.content_type
|
14
|
+
assert_nil pf.local_file
|
15
|
+
assert_nil pf.remote_file
|
16
|
+
assert_nil pf.set_content_proc
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_new_content_02
|
20
|
+
pf = Curl::PostField.content('foo', 'bar', 'text/html')
|
21
|
+
|
22
|
+
assert_equal 'foo', pf.name
|
23
|
+
assert_equal 'bar', pf.content
|
24
|
+
assert_equal 'text/html', pf.content_type
|
25
|
+
assert_nil pf.local_file
|
26
|
+
assert_nil pf.remote_file
|
27
|
+
assert_nil pf.set_content_proc
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_new_content_03
|
31
|
+
l = lambda { |field| "never gets run" }
|
32
|
+
pf = Curl::PostField.content('foo', &l)
|
33
|
+
|
34
|
+
assert_equal 'foo', pf.name
|
35
|
+
assert_nil pf.content
|
36
|
+
assert_nil pf.content_type
|
37
|
+
assert_nil pf.local_file
|
38
|
+
assert_nil pf.remote_file
|
39
|
+
|
40
|
+
# N.B. This doesn't just get the proc, but also removes it.
|
41
|
+
assert_equal l, pf.set_content_proc
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_new_content_04
|
45
|
+
l = lambda { |field| "never gets run" }
|
46
|
+
pf = Curl::PostField.content('foo', 'text/html', &l)
|
47
|
+
|
48
|
+
assert_equal 'foo', pf.name
|
49
|
+
assert_nil pf.content
|
50
|
+
assert_equal 'text/html', pf.content_type
|
51
|
+
assert_nil pf.local_file
|
52
|
+
assert_nil pf.remote_file
|
53
|
+
|
54
|
+
# N.B. This doesn't just get the proc, but also removes it.
|
55
|
+
assert_equal l, pf.set_content_proc
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
def test_new_file_01
|
60
|
+
pf = Curl::PostField.file('foo', 'localname')
|
61
|
+
|
62
|
+
assert_equal 'foo', pf.name
|
63
|
+
assert_equal 'localname', pf.local_file
|
64
|
+
assert_equal 'localname', pf.remote_file
|
65
|
+
assert_nil pf.content_type
|
66
|
+
assert_nil pf.content
|
67
|
+
assert_nil pf.set_content_proc
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_new_file_02
|
71
|
+
pf = Curl::PostField.file('foo', 'localname', 'remotename')
|
72
|
+
|
73
|
+
assert_equal 'foo', pf.name
|
74
|
+
assert_equal 'localname', pf.local_file
|
75
|
+
assert_equal 'remotename', pf.remote_file
|
76
|
+
assert_nil pf.content_type
|
77
|
+
assert_nil pf.content
|
78
|
+
assert_nil pf.set_content_proc
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_new_file_03
|
82
|
+
l = lambda { |field| "never gets run" }
|
83
|
+
pf = Curl::PostField.file('foo', 'remotename', &l)
|
84
|
+
|
85
|
+
assert_equal 'foo', pf.name
|
86
|
+
assert_equal 'remotename', pf.remote_file
|
87
|
+
assert_nil pf.local_file
|
88
|
+
assert_nil pf.content_type
|
89
|
+
assert_nil pf.content
|
90
|
+
|
91
|
+
# N.B. This doesn't just get the proc, but also removes it.
|
92
|
+
assert_equal l, pf.set_content_proc
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_new_file_04
|
96
|
+
assert_raise(ArgumentError) do
|
97
|
+
# no local name, no block
|
98
|
+
Curl::PostField.file('foo')
|
99
|
+
end
|
100
|
+
|
101
|
+
assert_raise(ArgumentError) do
|
102
|
+
# no remote name with block
|
103
|
+
Curl::PostField.file('foo') { |field| "never runs" }
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_new_file_05
|
108
|
+
# local gets ignored when supplying a block, but remote
|
109
|
+
# is still set up properly.
|
110
|
+
l = lambda { |field| "never runs" }
|
111
|
+
pf = Curl::PostField.file('foo', 'local', 'remote', &l)
|
112
|
+
|
113
|
+
assert_equal 'foo', pf.name
|
114
|
+
assert_equal 'remote', pf.remote_file
|
115
|
+
assert_nil pf.local_file
|
116
|
+
assert_nil pf.content_type
|
117
|
+
assert_nil pf.content
|
118
|
+
|
119
|
+
assert_equal l, pf.set_content_proc
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_to_s_01
|
123
|
+
pf = Curl::PostField.content('foo', 'bar')
|
124
|
+
assert_equal "foo=bar", pf.to_s
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_to_s_02
|
128
|
+
pf = Curl::PostField.content('foo', 'bar ton')
|
129
|
+
assert_equal "foo=bar%20ton", pf.to_s
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_to_s_03
|
133
|
+
pf = Curl::PostField.content('foo') { |field| field.name.upcase + "BAR" }
|
134
|
+
assert_equal "foo=FOOBAR", pf.to_s
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_to_s_04
|
138
|
+
pf = Curl::PostField.file('foo.file', 'bar.file')
|
139
|
+
assert_raise(Curl::Err::InvalidPostFieldError) { pf.to_s }
|
140
|
+
end
|
141
|
+
end
|
data/tests/unittests.rb
ADDED
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: taf2-curb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ross Bamford
|
8
|
+
- Todd A. Fisher
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2008-11-03 00:00:00 -08:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: Curb (probably CUrl-RuBy or something) provides Ruby-language bindings for the libcurl(3), a fully-featured client-side URL transfer library. cURL and libcurl live at http://curl.haxx.se/
|
18
|
+
email: todd.fisher@gmail.com
|
19
|
+
executables: []
|
20
|
+
|
21
|
+
extensions: []
|
22
|
+
|
23
|
+
extra_rdoc_files:
|
24
|
+
- LICENSE
|
25
|
+
- README
|
26
|
+
files:
|
27
|
+
- LICENSE
|
28
|
+
- README
|
29
|
+
- Rakefile
|
30
|
+
- doc.rb
|
31
|
+
- ext/curb.h
|
32
|
+
- ext/curb_easy.h
|
33
|
+
- ext/curb_errors.h
|
34
|
+
- ext/curb_macros.h
|
35
|
+
- ext/curb_multi.h
|
36
|
+
- ext/curb_postfield.h
|
37
|
+
- ext/curb.c
|
38
|
+
- ext/curb_easy.c
|
39
|
+
- ext/curb_errors.c
|
40
|
+
- ext/curb_multi.c
|
41
|
+
- ext/curb_postfield.c
|
42
|
+
- ext/curb.rb
|
43
|
+
- ext/curl.rb
|
44
|
+
- ext/extconf.rb
|
45
|
+
has_rdoc: true
|
46
|
+
homepage: http://curb.rubyforge.org/
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options:
|
49
|
+
- --main
|
50
|
+
- README
|
51
|
+
require_paths:
|
52
|
+
- ext
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
version:
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
version:
|
65
|
+
requirements: []
|
66
|
+
|
67
|
+
rubyforge_project: curb
|
68
|
+
rubygems_version: 1.2.0
|
69
|
+
signing_key:
|
70
|
+
specification_version: 2
|
71
|
+
summary: Ruby libcurl bindings
|
72
|
+
test_files:
|
73
|
+
- tests/tc_curl_easy.rb
|
74
|
+
- tests/tc_curl_multi.rb
|
75
|
+
- tests/tc_curl_postfield.rb
|
76
|
+
- tests/unittests.rb
|
77
|
+
- tests/helper.rb
|