Skip to content

Commit f97f721

Browse files
committed
Add C++20 Streaming API tests for StreamHandle struct
1 parent 8479673 commit f97f721

File tree

12 files changed

+2895
-331
lines changed

12 files changed

+2895
-331
lines changed

.github/workflows/test-stream.yaml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
name: test-stream
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
inputs:
8+
gtest_filter:
9+
description: 'Google Test filter'
10+
test_linux:
11+
description: 'Test on Linux'
12+
type: boolean
13+
default: true
14+
test_macos:
15+
description: 'Test on MacOS'
16+
type: boolean
17+
default: true
18+
test_windows:
19+
description: 'Test on Windows'
20+
type: boolean
21+
default: true
22+
23+
concurrency:
24+
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
25+
cancel-in-progress: true
26+
27+
env:
28+
GTEST_FILTER: ${{ github.event.inputs.gtest_filter || '*' }}
29+
30+
jobs:
31+
ubuntu:
32+
runs-on: ubuntu-24.04
33+
if: >
34+
(github.event_name == 'push') ||
35+
(github.event_name == 'pull_request' &&
36+
github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) ||
37+
(github.event_name == 'workflow_dispatch' && github.event.inputs.test_linux == 'true')
38+
steps:
39+
- name: checkout
40+
uses: actions/checkout@v4
41+
- name: install libraries
42+
run: |
43+
sudo apt-get update
44+
sudo apt-get install -y libssl-dev libcurl4-openssl-dev \
45+
zlib1g-dev libbrotli-dev libzstd-dev
46+
- name: build and run C++20 streaming tests
47+
run: cd test && make test-stream && ./test-stream --gtest_filter="${GTEST_FILTER}"
48+
49+
macos:
50+
runs-on: macos-latest
51+
if: >
52+
(github.event_name == 'push') ||
53+
(github.event_name == 'pull_request' &&
54+
github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) ||
55+
(github.event_name == 'workflow_dispatch' && github.event.inputs.test_macos == 'true')
56+
steps:
57+
- name: checkout
58+
uses: actions/checkout@v4
59+
- name: build and run C++20 streaming tests
60+
run: cd test && make test-stream && ./test-stream --gtest_filter="${GTEST_FILTER}"
61+
62+
windows:
63+
runs-on: windows-latest
64+
if: >
65+
(github.event_name == 'push') ||
66+
(github.event_name == 'pull_request' &&
67+
github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) ||
68+
(github.event_name == 'workflow_dispatch' && github.event.inputs.test_windows == 'true')
69+
strategy:
70+
matrix:
71+
config:
72+
- with_ssl: false
73+
name: without SSL
74+
- with_ssl: true
75+
name: with SSL
76+
name: windows ${{ matrix.config.name }}
77+
steps:
78+
- name: Prepare Git for Checkout on Windows
79+
run: |
80+
git config --global core.autocrlf false
81+
git config --global core.eol lf
82+
- name: Checkout
83+
uses: actions/checkout@v4
84+
- name: Export GitHub Actions cache environment variables
85+
uses: actions/github-script@v7
86+
with:
87+
script: |
88+
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
89+
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
90+
- name: Setup msbuild on windows
91+
uses: microsoft/setup-msbuild@v2
92+
- name: Install vcpkg dependencies
93+
run: vcpkg install gtest curl zlib brotli zstd
94+
- name: Install OpenSSL
95+
if: ${{ matrix.config.with_ssl }}
96+
run: choco install openssl
97+
- name: Configure CMake ${{ matrix.config.name }}
98+
run: >
99+
cmake -B build -S .
100+
-DCMAKE_BUILD_TYPE=Release
101+
-DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake
102+
-DHTTPLIB_TEST=ON
103+
-DHTTPLIB_REQUIRE_ZLIB=ON
104+
-DHTTPLIB_REQUIRE_BROTLI=ON
105+
-DHTTPLIB_REQUIRE_ZSTD=ON
106+
-DHTTPLIB_REQUIRE_OPENSSL=${{ matrix.config.with_ssl && 'ON' || 'OFF' }}
107+
- name: Build ${{ matrix.config.name }}
108+
run: cmake --build build --config Release --target httplib-test-stream
109+
- name: Run C++20 streaming tests ${{ matrix.config.name }}
110+
working-directory: build/test
111+
run: Release\httplib-test-stream.exe
112+
113+
env:
114+
VCPKG_ROOT: "C:/vcpkg"
115+
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ example/benchmark
1616
example/redirect
1717
!example/redirect.*
1818
example/ssecli
19+
!example/ssecli.*
20+
example/ssecli-stream
21+
!example/ssecli-stream.*
1922
example/ssesvr
23+
!example/ssesvr.*
2024
example/upload
2125
!example/upload.*
2226
example/one_time_request
@@ -29,6 +33,7 @@ example/*.pem
2933
test/httplib.cc
3034
test/httplib.h
3135
test/test
36+
test/test-stream
3237
test/server_fuzzer
3338
test/test_proxy
3439
test/test_split

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ target_link_libraries(${PROJECT_NAME} ${_INTERFACE_OR_PUBLIC}
277277
$<$<PLATFORM_ID:Windows>:crypt32>
278278
# Needed for API from MacOS Security framework
279279
"$<$<AND:$<PLATFORM_ID:Darwin>,$<BOOL:${HTTPLIB_IS_USING_OPENSSL}>,$<BOOL:${HTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN}>>:-framework CoreFoundation -framework Security>"
280+
# Needed for non-blocking getaddrinfo on macOS
281+
"$<$<AND:$<PLATFORM_ID:Darwin>,$<BOOL:${HTTPLIB_USE_NON_BLOCKING_GETADDRINFO}>>:-framework CoreFoundation -framework CFNetwork>"
280282
# Can't put multiple targets in a single generator expression or it bugs out.
281283
$<$<BOOL:${HTTPLIB_IS_USING_BROTLI}>:Brotli::common>
282284
$<$<BOOL:${HTTPLIB_IS_USING_BROTLI}>:Brotli::encoder>

0 commit comments

Comments
 (0)