bc89868903ceab05ac82b3007c6ea52c670265f9
1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2013 Matthieu Lucas <lucasmatthieu@gmail.com>
4 # Copyright 2013 Alexis Laferrière <alexis.laf@xymus.net>
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
21 fun error_manager
(err
: CURLCode) do if not err
.is_ok
then print err
23 var url
= "http://example.org/"
25 var curl
= new CCurl.easy_init
26 if not curl
.is_init
then print
"failed init"
29 error
= curl
.easy_setopt
(new CURLOption.url
, url
)
32 error
= curl
.easy_setopt
(new CURLOption.verbose
, 1)
35 error
= curl
.easy_perform
39 var info
:nullable CURLInfoResponseLong
40 info
= curl
.easy_getinfo_long
(new CURLInfoLong.header_size
)
41 assert infoResp
:info
!= null
42 print
"GetinfoLong:: Header size: " + info
.response
.to_s
44 info
= curl
.easy_getinfo_long
(new CURLInfoLong.response_code
)
45 assert infoResp
:info
!= null
46 print
"GetinfoLong:: Response code: " + info
.response
.to_s
48 info
= curl
.easy_getinfo_long
(new CURLInfoLong.http_connectcode
)
49 assert infoResp
:info
!= null
50 print
"GetinfoLong:: http_connectcode: " + info
.response
.to_s
52 info
= curl
.easy_getinfo_long
(new CURLInfoLong.filetime
)
53 assert infoResp
:info
!= null
54 print
"GetinfoLong:: filetime: " + info
.response
.to_s
56 info
= curl
.easy_getinfo_long
(new CURLInfoLong.redirect_count
)
57 assert infoResp
:info
!= null
58 print
"GetinfoLong:: redirect_count: " + info
.response
.to_s
60 info
= curl
.easy_getinfo_long
(new CURLInfoLong.request_size
)
61 assert infoResp
:info
!= null
62 print
"GetinfoLong:: request_size: " + info
.response
.to_s
64 info
= curl
.easy_getinfo_long
(new CURLInfoLong.ssl_verifyresult
)
65 assert infoResp
:info
!= null
66 print
"GetinfoLong:: ssl_verifyresult: " + info
.response
.to_s
68 info
= curl
.easy_getinfo_long
(new CURLInfoLong.httpauth_avail
)
69 assert infoResp
:info
!= null
70 print
"GetinfoLong:: httpauth_avail: " + info
.response
.to_s
72 info
= curl
.easy_getinfo_long
(new CURLInfoLong.proxyauth_avail
)
73 assert infoResp
:info
!= null
74 print
"GetinfoLong:: proxyauth_avail: " + info
.response
.to_s
76 info
= curl
.easy_getinfo_long
(new CURLInfoLong.os_errno
)
77 assert infoResp
:info
!= null
78 print
"GetinfoLong:: os_errno: " + info
.response
.to_s
80 info
= curl
.easy_getinfo_long
(new CURLInfoLong.primary_port
)
81 assert infoResp
:info
!= null
82 print
"GetinfoLong:: primary_port: " + info
.response
.to_s
84 info
= curl
.easy_getinfo_long
(new CURLInfoLong.num_connects
)
85 assert infoResp
:info
!= null
86 print
"GetinfoLong:: num_connects: " + info
.response
.to_s
88 info
= curl
.easy_getinfo_long
(new CURLInfoLong.local_port
)
89 assert infoResp
:info
!= null
90 print
"GetinfoLong:: local_port: " + info
.response
.to_s
92 info
= curl
.easy_getinfo_long
(new CURLInfoLong.lastsocket
)
93 assert infoResp
:info
!= null
94 print
"GetinfoLong:: lastsocket: " + info
.response
.to_s
96 info
= curl
.easy_getinfo_long
(new CURLInfoLong.condition_unmet
)
97 assert infoResp
:info
!= null
98 print
"GetinfoLong:: condition_unmet: " + info
.response
.to_s
100 info
= curl
.easy_getinfo_long
(new CURLInfoLong.rtsp_client_cseq
)
101 assert infoResp
:info
!= null
102 print
"GetinfoLong:: rtsp_client_cseq: " + info
.response
.to_s
104 info
= curl
.easy_getinfo_long
(new CURLInfoLong.rtsp_server_cseq
)
105 assert infoResp
:info
!= null
106 print
"GetinfoLong:: rtsp_server_cseq: " + info
.response
.to_s
108 info
= curl
.easy_getinfo_long
(new CURLInfoLong.rtsp_cseq_recv
)
109 assert infoResp
:info
!= null
110 print
"GetinfoLong:: rtsp_cseq_recv: " + info
.response
.to_s
113 var infoDouble
: nullable CURLInfoResponseDouble
114 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.total_time
)
115 assert infoResp
:infoDouble
!= null
116 print
"GetinfoDouble:: total_time: " + infoDouble
.response
.to_s
118 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.namelookup_time
)
119 assert infoResp
:infoDouble
!= null
120 print
"GetinfoDouble:: namelookup_time: " + infoDouble
.response
.to_s
122 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.connect_time
)
123 assert infoResp
:infoDouble
!= null
124 print
"GetinfoDouble:: connect_time: " + infoDouble
.response
.to_s
126 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.appconnect_time
)
127 assert infoResp
:infoDouble
!= null
128 print
"GetinfoDouble:: appconnect_time: " + infoDouble
.response
.to_s
130 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.pretransfer_time
)
131 assert infoResp
:infoDouble
!= null
132 print
"GetinfoDouble:: pretransfer_time: " + infoDouble
.response
.to_s
134 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.starttransfer_time
)
135 assert infoResp
:infoDouble
!= null
136 print
"GetinfoDouble:: starttransfer_time: " + infoDouble
.response
.to_s
138 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.redirect_time
)
139 assert infoResp
:infoDouble
!= null
140 print
"GetinfoDouble:: redirect_time: " + infoDouble
.response
.to_s
142 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.size_upload
)
143 assert infoResp
:infoDouble
!= null
144 print
"GetinfoDouble:: size_upload: " + infoDouble
.response
.to_s
146 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.size_download
)
147 assert infoResp
:infoDouble
!= null
148 print
"GetinfoDouble:: size_download: " + infoDouble
.response
.to_s
150 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.speed_download
)
151 assert infoResp
:infoDouble
!= null
152 print
"GetinfoDouble:: speed_download: " + infoDouble
.response
.to_s
154 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.speed_upload
)
155 assert infoResp
:infoDouble
!= null
156 print
"GetinfoDouble:: speed_upload: " + infoDouble
.response
.to_s
158 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.content_length_download
)
159 assert infoResp
:infoDouble
!= null
160 print
"GetinfoDouble:: content_length_download: " + infoDouble
.response
.to_s
162 infoDouble
= curl
.easy_getinfo_double
(new CURLInfoDouble.content_length_upload
)
163 assert infoResp
:infoDouble
!= null
164 print
"GetinfoDouble:: content_length_upload: " + infoDouble
.response
.to_s
167 var infoStr
:nullable CURLInfoResponseString
168 infoStr
= curl
.easy_getinfo_chars
(new CURLInfoChars.content_type
)
169 assert infoResp
:infoStr
!= null
170 print
"GetinfoStr:: Content type: " + infoStr
.response
172 infoStr
= curl
.easy_getinfo_chars
(new CURLInfoChars.effective_url
)
173 assert infoResp
:infoStr
!= null
174 print
"GetinfoStr:: Effective url: " + infoStr
.response
176 infoStr
= curl
.easy_getinfo_chars
(new CURLInfoChars.redirect_url
)
177 assert infoResp
:infoStr
!= null
178 print
"GetinfoStr:: Redirect url: " + infoStr
.response
180 infoStr
= curl
.easy_getinfo_chars
(new CURLInfoChars.primary_ip
)
181 assert infoResp
:infoStr
!= null
182 print
( "GetinfoStr:: primary_ip not empty: " + (not infoStr
.response
.is_empty
).to_s
)
184 infoStr
= curl
.easy_getinfo_chars
(new CURLInfoChars.local_ip
)
185 assert infoResp
:infoStr
!= null
186 print
( "GetinfoStr:: local_ip not empty: " + (not infoStr
.response
.is_empty
).to_s
)
188 infoStr
= curl
.easy_getinfo_chars
(new CURLInfoChars.ftp_entry_path
)
189 assert infoResp
:infoStr
!= null
190 print
"GetinfoStr:: ftp_entry_path: " + infoStr
.response
192 infoStr
= curl
.easy_getinfo_chars
(new CURLInfoChars.private_data
)
193 assert infoResp
:infoStr
!= null
194 print
"GetinfoStr:: private_data: " + infoStr
.response
196 infoStr
= curl
.easy_getinfo_chars
(new CURLInfoChars.rtsp_session_id
)
197 assert infoResp
:infoStr
!= null
198 print
"GetinfoStr:: rtsp_session_id: " + infoStr
.response
201 var infoList
:nullable CURLInfoResponseArray
202 infoList
= curl
.easy_getinfo_slist
(new CURLInfoSList.ssl_engines
)
203 assert infoResp
:infoList
!= null
204 print
"GetSList:: ssl_engines: " + infoList
.response
.to_s
206 infoList
= curl
.easy_getinfo_slist
(new CURLInfoSList.cookielist
)
207 assert infoResp
:infoList
!= null
208 print
"GetSList:: cookielist: " + infoList
.response
.to_s
211 var mailList
= new CURLSList.with_str
("titi")
212 mailList
.append
("toto")
213 mailList
.append
("toto2")
214 mailList
.append
("toto3")
215 mailList
.append
("toto4")
216 mailList
.append
("toto9")
217 if mailList
.is_init
then
218 var content
= mailList
.to_a
219 print
"CURLSList to array - content: {content.to_s}"
220 print
"CURLSList to array - length: {content.length.to_s}"
223 print
"CURLSList to array: CURLSList wrong init"
226 # CURLSList from Array
227 var mailRecipientsArray
= new Array[String]
228 mailRecipientsArray
.add
("tata")
229 mailRecipientsArray
.add
("tata2")
230 var mailRecipientsList
: CURLSList = mailRecipientsArray
.to_curlslist
231 if mailRecipientsList
.is_init
then
232 print
"Array to CURLSList - content: {mailRecipientsList.to_a.to_s}"
233 print
"Array to CURLSList - length: {mailRecipientsList.to_a.length.to_s}"
234 mailRecipientsList
.destroy
236 print
"CURLSList to array: CURLSList wrong init"
240 var hashMapRefined
= new HeaderMap
241 hashMapRefined
["hello"] = "toto"
242 hashMapRefined
["hello"] = "tata"
243 hashMapRefined
["allo"] = "foo"
244 print hashMapRefined
.to_url_encoded
(new CCurl.easy_init
)