Skip to content

Commit 2afb61f

Browse files
Test 32bit
1 parent 85b5cdd commit 2afb61f

File tree

3 files changed

+59
-4
lines changed

3 files changed

+59
-4
lines changed

.github/workflows/test.yaml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,30 @@ jobs:
4747
(github.event_name == 'pull_request' &&
4848
github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) ||
4949
(github.event_name == 'workflow_dispatch' && github.event.inputs.test_linux == 'true')
50+
strategy:
51+
matrix:
52+
config:
53+
- arch_flags: -m32
54+
arch_suffix: :i386
55+
name: (32-bit)
56+
- arch_flags:
57+
arch_suffix:
58+
name: (64-bit)
59+
name: ubuntu ${{ matrix.config.name }}
5060
steps:
5161
- name: checkout
5262
uses: actions/checkout@v4
5363
- name: install libraries
54-
run: sudo apt-get update && sudo apt-get install -y libbrotli-dev libcurl4-openssl-dev
64+
run: |
65+
sudo dpkg --add-architecture i386
66+
sudo apt-get update
67+
sudo apt-get install -y libc6-dev${{ matrix.config.arch_suffix }} libstdc++-13-dev${{ matrix.config.arch_suffix }} \
68+
libssl-dev${{ matrix.config.arch_suffix }} libcurl4-openssl-dev${{ matrix.config.arch_suffix }} \
69+
zlib1g-dev${{ matrix.config.arch_suffix }} libbrotli-dev${{ matrix.config.arch_suffix }}
5570
- name: build and run tests
56-
run: cd test && make
71+
run: cd test && make EXTRA_CXXFLAGS="${{ matrix.config.arch_flags }}"
5772
- name: run fuzz test target
58-
run: cd test && make fuzz_test
73+
run: cd test && make EXTRA_CXXFLAGS="${{ matrix.config.arch_flags }}" fuzz_test
5974

6075
macos:
6176
runs-on: macos-latest

test/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
CXX = clang++
2-
CXXFLAGS = -g -std=c++11 -I. -Wall -Wextra -Wtype-limits -Wconversion -Wshadow # -fno-exceptions -DCPPHTTPLIB_NO_EXCEPTIONS -fsanitize=address
2+
CXXFLAGS = -g -std=c++11 -I. -Wall -Wextra -Wtype-limits -Wconversion -Wshadow $(EXTRA_CXXFLAGS) # -fno-exceptions -DCPPHTTPLIB_NO_EXCEPTIONS -fsanitize=address
33

44
PREFIX ?= $(shell brew --prefix)
55

test/test.cc

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6084,6 +6084,46 @@ TEST_F(PayloadMaxLengthTest, ExceedLimit) {
60846084
EXPECT_EQ(StatusCode::OK_200, res->status);
60856085
}
60866086

6087+
TEST(PayloadMaxLengthTest2, LimitOn32bit) {
6088+
Server svr;
6089+
char data[1024]{0};
6090+
svr.Get("/", [&](const Request &, Response &res) {
6091+
constexpr uint64_t size = std::numeric_limits<uint32_t>::max() + 1ull;
6092+
res.set_content_provider(
6093+
size, "text/plain",
6094+
[&](size_t /*offset*/, size_t length, DataSink &sink) {
6095+
sink.write(data, std::min(length, sizeof(data)));
6096+
return true;
6097+
});
6098+
});
6099+
6100+
auto listen_thread = std::thread([&svr]() { svr.listen(HOST, PORT); });
6101+
auto se = detail::scope_exit([&] {
6102+
svr.stop();
6103+
listen_thread.join();
6104+
ASSERT_FALSE(svr.is_running());
6105+
});
6106+
svr.wait_until_ready();
6107+
6108+
Client cli(HOST, PORT);
6109+
uint64_t expected_size = static_cast<uint64_t>(-1);
6110+
uint64_t total_size = 0;
6111+
auto res = cli.Get(
6112+
"/", Headers(),
6113+
[&](const Response &response) {
6114+
EXPECT_EQ(StatusCode::OK_200, response.status);
6115+
expected_size = response.get_header_value_u64("Content-Length", 0);
6116+
return true;
6117+
},
6118+
[&](const char */*data*/, size_t data_length) {
6119+
total_size += data_length;
6120+
return true;
6121+
});
6122+
6123+
ASSERT_TRUE(res);
6124+
ASSERT_EQ(total_size, expected_size);
6125+
}
6126+
60876127
TEST(HostAndPortPropertiesTest, NoSSL) {
60886128
httplib::Client cli("www.google.com", 1234);
60896129
ASSERT_EQ("www.google.com", cli.host());

0 commit comments

Comments
 (0)