Skip to content

Commit b8230eb

Browse files
committed
Fixed tests and README file
1 parent cf7b5f9 commit b8230eb

File tree

9 files changed

+124
-77
lines changed

9 files changed

+124
-77
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ include(GNUInstallDirs)
1515

1616
option(BUILD_TEST "Build Tests" OFF)
1717

18-
#if using an older VERSION of curl ocsp stapling can be disabled
18+
# if using an older VERSION of curl ocsp stapling can be disabled
1919
set(CURL_MIN_VERSION "7.28.0")
2020

2121
set(DEFAULT_BUILD_TYPE "Release")

README.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Here are some usage examples. You will find more examples in the test folder!
5252
Here's an example of a simple HTTP request to get google web page, using the curl_easy interface:
5353

5454
`````c++
55-
#include "curl_easy.h"
55+
#include "curlcpp/curl_easy.h"
5656

5757
using curl::curl_easy;
5858
using curl::curl_easy_exception;
@@ -82,9 +82,9 @@ int main() {
8282
If you want to get information about the current curl session, you could do:
8383

8484
`````c++
85-
#include "curl_easy.h"
86-
#include "curl_ios.h"
87-
#include "curl_exception.h"
85+
#include "curlcpp/curl_easy.h"
86+
#include "curlcpp/curl_ios.h"
87+
#include "curlcpp/curl_exception.h"
8888

8989
using std::ostringstream;
9090

@@ -140,10 +140,10 @@ Here's instead, the creation of an HTTPS POST login form:
140140
`````c++
141141
#include <string>
142142
143-
#include "curl_easy.h"
144-
#include "curl_pair.h"
145-
#include "curl_form.h"
146-
#include "curl_exception.h"
143+
#include "curlcpp/curl_easy.h"
144+
#include "curlcpp/curl_pair.h"
145+
#include "curlcpp/curl_form.h"
146+
#include "curlcpp/curl_exception.h"
147147
148148
using std::string;
149149
@@ -192,9 +192,9 @@ And if we would like to put the returned content in a file? Nothing easier than:
192192
#include <ostream>
193193
#include <fstream>
194194

195-
#include "curl_easy.h"
196-
#include "curl_ios.h"
197-
#include "curl_exception.h"
195+
#include "curlcpp/curl_easy.h"
196+
#include "curlcpp/curl_ios.h"
197+
#include "curlcpp/curl_exception.h"
198198

199199
using std::cout;
200200
using std::endl;
@@ -241,10 +241,10 @@ Not interested in files? So let's put the request's output in a variable!
241241
#include <iostream>
242242
#include <ostream>
243243
244-
#include "curl_easy.h"
245-
#include "curl_form.h"
246-
#include "curl_ios.h"
247-
#include "curl_exception.h"
244+
#include "curlcpp/curl_easy.h"
245+
#include "curlcpp/curl_form.h"
246+
#include "curlcpp/curl_ios.h"
247+
#include "curlcpp/curl_exception.h"
248248
249249
using std::cout;
250250
using std::endl;
@@ -291,12 +291,12 @@ buffers. For example, a very simple send/receiver would be:
291291
#include <iostream>
292292
#include <string>
293293

294-
#include "curl_easy.h"
295-
#include "curl_form.h"
296-
#include "curl_pair.h"
297-
#include "curl_receiver.h"
298-
#include "curl_exception.h"
299-
#include "curl_sender.h"
294+
#include "curlcpp/curl_easy.h"
295+
#include "curlcpp/curl_form.h"
296+
#include "curlcpp/curl_pair.h"
297+
#include "curlcpp/curl_receiver.h"
298+
#include "curlcpp/curl_exception.h"
299+
#include "curlcpp/curl_sender.h"
300300

301301
using std::cout;
302302
using std::endl;

test/cookie.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#include <iostream>
22

3-
#include "curl_easy.h"
4-
#include "curl_exception.h"
5-
#include "curl_cookie.h"
6-
#include "curl_ios.h"
7-
#include "cookie_datetime.h"
3+
#include "curlcpp/curl_easy.h"
4+
#include "curlcpp/curl_exception.h"
5+
#include "curlcpp/curl_cookie.h"
6+
#include "curlcpp/curl_ios.h"
7+
#include "curlcpp/cookie_datetime.h"
88

99
using std::ostringstream;
1010

@@ -57,17 +57,16 @@ int main() {
5757
// Delete all the memory helded cookies.
5858
cookie_object.erase();
5959

60-
// Print them all!
61-
for (const auto& cook : cookies) {
62-
std::cout<<cook<<std::endl;
63-
}
64-
60+
// Print them all!
61+
for (const auto& cook : cookies) {
62+
std::cout<<cook<<std::endl;
63+
}
6564
} catch (curl_easy_exception &error) {
66-
// If you want to print the last error.
67-
std::cerr<<error.what()<<std::endl;
65+
// If you want to print the last error.
66+
std::cerr<<error.what()<<std::endl;
6867

69-
// If you want to print the entire error stack you can do.
70-
error.print_traceback();
68+
// If you want to print the entire error stack you can do.
69+
error.print_traceback();
7170
}
7271
return 0;
7372
}

test/custom_request.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#include "curl_easy.h"
2-
#include "curl_form.h"
3-
#include "curl_header.h"
1+
#include "curlcpp/curl_easy.h"
2+
#include "curlcpp/curl_form.h"
3+
#include "curlcpp/curl_header.h"
44

55
using curl::curl_easy;
66
using curl::curl_easy_exception;
@@ -33,11 +33,11 @@ int main() {
3333
// Request execution
3434
easy.perform();
3535
} catch (curl_easy_exception &error) {
36-
// If you want to print the last error.
37-
std::cerr<<error.what()<<std::endl;
36+
// If you want to print the last error.
37+
std::cerr<<error.what()<<std::endl;
3838

39-
// If you want to print the entire error stack you can do
40-
error.print_traceback();
39+
// If you want to print the entire error stack you can do
40+
error.print_traceback();
4141
}
4242
return 0;
4343
}

test/easy.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "curl_easy.h"
1+
#include "curlcpp/curl_easy.h"
22

33
using curl::curl_easy;
44
using curl::curl_easy_exception;
@@ -18,7 +18,7 @@ int main() {
1818
try {
1919
easy.perform();
2020
} catch (curl_easy_exception &error) {
21-
// If you want to print the last error.
21+
// If you want to print the last error.
2222
std::cerr<<error.what()<<std::endl;
2323
}
2424
return 0;

test/easy_info.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#include "curl_easy.h"
2-
#include "curl_ios.h"
3-
#include "curl_exception.h"
1+
#include "curlcpp/curl_easy.h"
2+
#include "curlcpp/curl_ios.h"
3+
#include "curlcpp/curl_exception.h"
44

55
using std::ostringstream;
66

@@ -30,22 +30,22 @@ int main(int argc, const char **argv) {
3030
try {
3131
easy.perform();
3232

33-
// Retrieve information about curl current session.
34-
auto x = easy.get_info<CURLINFO_CONTENT_TYPE>();
33+
// Retrieve information about curl current session.
34+
auto x = easy.get_info<CURLINFO_CONTENT_TYPE>();
3535

36-
/**
37-
* get_info returns a curl_easy_info object. With the get method we retrieve
38-
* the std::pair object associated with it: the first item is the return code of the
39-
* request. The second is the element requested by the specified libcurl macro.
40-
*/
41-
std::cout<<x.get()<<std::endl;
36+
/**
37+
* get_info returns a curl_easy_info object. With the get method we retrieve
38+
* the std::pair object associated with it: the first item is the return code of the
39+
* request. The second is the element requested by the specified libcurl macro.
40+
*/
41+
std::cout<<x.get()<<std::endl;
4242

4343
} catch (curl_easy_exception &error) {
44-
// If you want to print the last error.
45-
std::cerr<<error.what()<<std::endl;
44+
// If you want to print the last error.
45+
std::cerr<<error.what()<<std::endl;
4646

47-
// If you want to print the entire error stack you can do
48-
error.print_traceback();
47+
// If you want to print the entire error stack you can do
48+
error.print_traceback();
4949
}
5050
return 0;
5151
}

test/header.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#include "curl_easy.h"
2-
#include "curl_form.h"
3-
#include "curl_header.h"
1+
#include "curlcpp/curl_easy.h"
2+
#include "curlcpp/curl_form.h"
3+
#include "curlcpp/curl_header.h"
44

55
using curl::curl_easy;
66
using curl::curl_easy_exception;
@@ -14,8 +14,8 @@ int main() {
1414
// Easy object to handle the connection.
1515
curl_easy easy;
1616

17-
// Let's create an object which will contain a list of headers.
18-
curl::curl_header header;
17+
// Let's create an object which will contain a list of headers.
18+
curl::curl_header header;
1919
header.add("Accept:");
2020
header.add("Another:yes");
2121
header.add("Host: example.com");
@@ -29,11 +29,11 @@ int main() {
2929
try {
3030
easy.perform();
3131
} catch (curl_easy_exception &error) {
32-
// If you want to print the last error.
33-
std::cerr<<error.what()<<std::endl;
32+
// If you want to print the last error.
33+
std::cerr<<error.what()<<std::endl;
3434

35-
// If you want to print the entire error stack you can do
36-
error.print_traceback();
35+
// If you want to print the entire error stack you can do
36+
error.print_traceback();
3737
}
3838
return 0;
3939
}

test/output_variable.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#include <iostream>
2+
#include <ostream>
3+
4+
#include "curlcpp/curl_easy.h"
5+
#include "curlcpp/curl_form.h"
6+
#include "curlcpp/curl_ios.h"
7+
#include "curlcpp/curl_exception.h"
8+
9+
using std::cout;
10+
using std::endl;
11+
using std::ostringstream;
12+
13+
using curl::curl_easy;
14+
using curl::curl_ios;
15+
using curl::curl_easy_exception;
16+
using curl::curlcpp_traceback;
17+
18+
19+
/**
20+
* This example shows how to put curl output inside a stream (a variable, for
21+
* example)
22+
*/
23+
int main() {
24+
// Create a stringstream object
25+
ostringstream str;
26+
// Create a curl_ios object, passing the stream object.
27+
curl_ios<ostringstream> writer(str);
28+
29+
// Pass the writer to the easy constructor and watch the content returned in that variable!
30+
curl_easy easy(writer);
31+
easy.add<CURLOPT_URL>("https://google.com");
32+
easy.add<CURLOPT_FOLLOWLOCATION>(1L);
33+
34+
try {
35+
easy.perform();
36+
37+
// Print the content of ostringstream.
38+
cout<<str.str()<<endl;
39+
40+
} catch (curl_easy_exception &error) {
41+
// If you want to print the last error.
42+
std::cerr<<error.what()<<std::endl;
43+
44+
// If you want to print the entire error stack you can do
45+
error.print_traceback();
46+
}
47+
return 0;
48+
}

test/recv_header.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#include "curl_easy.h"
2-
#include "curl_form.h"
1+
#include "curlcpp/curl_easy.h"
2+
#include "curlcpp/curl_form.h"
33

44
using curl::curl_easy;
55
using curl::curl_ios;
@@ -36,15 +36,15 @@ int main() {
3636
try {
3737
easy.perform();
3838

39-
// Let's print ONLY the headers.
40-
std::cout<<header_var.str()<<std::endl;
39+
// Let's print ONLY the headers.
40+
std::cout<<header_var.str()<<std::endl;
4141

4242
} catch (curl_easy_exception &error) {
43-
// If you want to print the last error.
44-
std::cerr<<error.what()<<std::endl;
43+
// If you want to print the last error.
44+
std::cerr<<error.what()<<std::endl;
4545

46-
// If you want to print the entire error stack you can do
47-
error.print_traceback();
46+
// If you want to print the entire error stack you can do
47+
error.print_traceback();
4848
}
4949
return 0;
5050
}

0 commit comments

Comments
 (0)