From 3a83787add779b2c14998ddcaf5975299d76998b Mon Sep 17 00:00:00 2001 From: Matthieu Lucas Date: Wed, 31 Jul 2013 15:42:26 +0200 Subject: [PATCH] lib: fixing tests programs of curl Signed-off-by: Matthieu Lucas --- examples/curl_http.nit | 5 ++++- tests/sav/curl_http_args2.sav | 2 +- tests/test_curl.nit | 10 ++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/examples/curl_http.nit b/examples/curl_http.nit index aa84120..fb0b56c 100644 --- a/examples/curl_http.nit +++ b/examples/curl_http.nit @@ -24,6 +24,7 @@ class MyHttpFetcher super CurlCallbacks var curl: Curl + var our_body: String = "" init do self.curl = new Curl @@ -39,7 +40,7 @@ class MyHttpFetcher end # Body callback - redef fun body_callback(line: String) do print "Body_callback : {line}" + redef fun body_callback(line: String) do self.our_body = "{self.our_body}{line}" # Stream callback - Cf : No one is registered redef fun stream_callback(buffer: String, size: Int, count: Int) do print "Stream_callback : {buffer} - {size} - {count}" @@ -88,6 +89,8 @@ else postContentRequest.verbose = false var postResponse = postContentRequest.execute + print "Our body from the callback : {myHttpFetcher.our_body}" + if postResponse isa CurlResponseSuccess then print "*** Answer ***" print "Status code : {postResponse.status_code}" diff --git a/tests/sav/curl_http_args2.sav b/tests/sav/curl_http_args2.sav index 76528dd..a7b3f76 100644 --- a/tests/sav/curl_http_args2.sav +++ b/tests/sav/curl_http_args2.sav @@ -1,4 +1,4 @@ -Body_callback : +Our body from the callback : Example Domain diff --git a/tests/test_curl.nit b/tests/test_curl.nit index 6401706..79cdb5b 100644 --- a/tests/test_curl.nit +++ b/tests/test_curl.nit @@ -18,6 +18,12 @@ module test_curl import curl +class CallbackManager + super CurlCallbacks + + redef fun body_callback(line: String) do end +end + fun error_manager(err: CURLCode) do if not err.is_ok then print err var url = "http://example.org/" @@ -33,6 +39,10 @@ error_manager(error) #error = curl.easy_setopt(new CURLOption.verbose, 1) #error_manager(error) +var cbManager = new CallbackManager +error = curl.register_callback(cbManager, new CURLCallbackType.body) +error_manager(error) + error = curl.easy_perform error_manager(error) -- 1.7.9.5