File tree 7 files changed +90
-2
lines changed
7 files changed +90
-2
lines changed Original file line number Diff line number Diff line change @@ -23,5 +23,9 @@ endif()
23
23
24
24
if (BENONI_TESTS)
25
25
enable_testing ()
26
- add_subdirectory (test )
26
+ add_subdirectory (test /unit)
27
+
28
+ if (PROJECT_IS_TOP_LEVEL)
29
+ add_subdirectory (test /packaging)
30
+ endif ()
27
31
endif ()
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ configure: .always
14
14
$(CMAKE ) -B build -DBENONI_TESTS:BOOL=ON -DBENONI_EXAMPLES:BOOL=ON
15
15
16
16
build : .always
17
- $(CLANG_FORMAT ) --style=file -i include/benoni/http.h src/apple/http.mm src/win32/http.cc src/linux/http.cc examples/http_example.cc test/postman-echo-get.cc
17
+ $(CLANG_FORMAT ) --style=file -i include/benoni/http.h src/apple/http.mm src/win32/http.cc src/linux/http.cc examples/http_example.cc test/unit/ postman-echo-get.cc test/packaging/project/project .cc
18
18
$(CMAKE ) --build build
19
19
20
20
example : .always
Original file line number Diff line number Diff line change
1
+ add_test (NAME packaging.project_configure COMMAND
2
+ "${CMAKE_COMMAND} "
3
+ -S "${CMAKE_CURRENT_SOURCE_DIR} /project"
4
+ -B "${CMAKE_CURRENT_BINARY_DIR} /project"
5
+ "-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} " )
6
+
7
+ add_test (NAME packaging.project_build COMMAND
8
+ "${CMAKE_COMMAND} "
9
+ --build "${CMAKE_CURRENT_BINARY_DIR} /project" )
10
+
11
+ set_tests_properties (packaging.project_build
12
+ PROPERTIES DEPENDS packaging.project_configure)
Original file line number Diff line number Diff line change
1
+ cmake_minimum_required (VERSION 3.18)
2
+ project (project VERSION 0.0.1 LANGUAGES CXX DESCRIPTION "Project" )
3
+
4
+ set (CMAKE_CXX_STANDARD 20)
5
+
6
+ add_subdirectory (
7
+ "${PROJECT_SOURCE_DIR} /../../.."
8
+ "${CMAKE_CURRENT_BINARY_DIR} /benoni_build" )
9
+
10
+ add_executable (project project.cc)
11
+ target_link_libraries (project PRIVATE benoni)
Original file line number Diff line number Diff line change
1
+ #include < benoni/http.h>
2
+
3
+ #if defined(__APPLE__)
4
+ #include < CoreFoundation/CoreFoundation.h>
5
+ #elif defined(linux)
6
+ #include < glib.h>
7
+ #endif
8
+
9
+ #include < iostream>
10
+ #include < variant>
11
+
12
+ using benoni::Method;
13
+ using benoni::request;
14
+ using benoni::RequestOptions;
15
+ using benoni::RequestOptionsBuilder;
16
+ using benoni::Response;
17
+
18
+ int main () {
19
+ #if defined(linux)
20
+ GMainLoop *loop = g_main_loop_new (nullptr , FALSE );
21
+ #endif
22
+
23
+ std::string url{" https://postman-echo.com/get" };
24
+ std::cout << " sending request to: \" " << url << " \" " << std::endl;
25
+
26
+ request (std::move (url), RequestOptionsBuilder{}.build (),
27
+ [](std::variant<std::string, Response> result) {
28
+ // This callback is run in a background thread on Windows and Apple
29
+ // and on the main thread on Gtk Linux.
30
+ if (std::holds_alternative<std::string>(result)) {
31
+ std::cerr << " error: [" << std::get<std::string>(result) << " ]"
32
+ << std::endl;
33
+ exit (EXIT_FAILURE);
34
+ }
35
+
36
+ Response response{std::get<Response>(result)};
37
+
38
+ std::cout << " response status: " << response.status << std::endl;
39
+ std::cout << " response headers: [" << std::endl;
40
+ for (const auto &[key, value] : response.headers ) {
41
+ std::cout << " \" " << key << " \" : \" " << value << " \" ,"
42
+ << std::endl;
43
+ }
44
+ std::cout << " ]" << std::endl;
45
+ std::cout << " response body: \" " << response.body << " \" "
46
+ << std::endl;
47
+ exit (EXIT_SUCCESS);
48
+ });
49
+
50
+ #if defined(__APPLE__)
51
+ CFRunLoopRun ();
52
+ #elif defined(linux)
53
+ g_main_loop_run (loop);
54
+ g_main_loop_unref (loop);
55
+ #else
56
+ while (true )
57
+ ;
58
+ #endif
59
+
60
+ return 0 ;
61
+ }
File renamed without changes.
File renamed without changes.
You can’t perform that action at this time.
0 commit comments