MCPcopy Create free account
hub / github.com/FastLED/FastLED / FL_TEST_FILE

Function FL_TEST_FILE

tests/fl/net/http/chunked_encoding.cpp:4–282  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2#include "fl/net/http/chunked_encoding.h"
3
4FL_TEST_FILE(FL_FILEPATH) {
5
6// Helper: wrap a C string as a span for feed()
7static fl::span<const uint8_t> asSpan(const char* s, size_t len) {
8 return fl::span<const uint8_t>(reinterpret_cast<const uint8_t*>(s), len); // ok reinterpret cast
9}
10static fl::span<const uint8_t> asSpan(const char* s) {
11 return asSpan(s, fl::strlen(s));
12}
13
14
15FL_TEST_CASE("ChunkedReader: Parse single chunk") {
16 fl::net::http::ChunkedReader reader;
17
18 // Feed chunk: "5\r\nHello\r\n"
19 const char* data = "5\r\nHello\r\n";
20 reader.feed(asSpan(data));
21
22 FL_REQUIRE(reader.hasChunk());
23 FL_REQUIRE(reader.nextChunkSize() == 5);
24 uint8_t buf[64];
25 auto result = reader.readChunk(buf);
26 FL_REQUIRE(result.hasData());
27 FL_REQUIRE(result.mData.size() == 5);
28 FL_REQUIRE(fl::memcmp(result.mData.data(), "Hello", 5) == 0);
29 FL_REQUIRE(!reader.hasChunk());
30}
31
32FL_TEST_CASE("ChunkedReader: Parse multiple chunks") {
33 fl::net::http::ChunkedReader reader;
34
35 // Feed chunks: "5\r\nHello\r\n5\r\nWorld\r\n"
36 const char* data = "5\r\nHello\r\n5\r\nWorld\r\n";
37 reader.feed(asSpan(data));
38
39 uint8_t buf[64];
40
41 FL_REQUIRE(reader.hasChunk());
42 auto r1 = reader.readChunk(buf);
43 FL_REQUIRE(r1.hasData());
44 FL_REQUIRE(r1.mData.size() == 5);
45 FL_REQUIRE(fl::memcmp(r1.mData.data(), "Hello", 5) == 0);
46
47 FL_REQUIRE(reader.hasChunk());
48 auto r2 = reader.readChunk(buf);
49 FL_REQUIRE(r2.hasData());
50 FL_REQUIRE(r2.mData.size() == 5);
51 FL_REQUIRE(fl::memcmp(r2.mData.data(), "World", 5) == 0);
52
53 FL_REQUIRE(!reader.hasChunk());
54}
55
56FL_TEST_CASE("ChunkedReader: Parse final chunk") {
57 fl::net::http::ChunkedReader reader;
58
59 // Feed chunks: "5\r\nHello\r\n0\r\n\r\n"
60 const char* data = "5\r\nHello\r\n0\r\n\r\n";
61 reader.feed(asSpan(data));

Callers

nothing calls this directly

Calls 15

memcmpFunction · 0.85
strlenFunction · 0.85
hasChunkMethod · 0.80
nextChunkSizeMethod · 0.80
readChunkMethod · 0.80
hasDataMethod · 0.80
writeChunkMethod · 0.80
writeFinalMethod · 0.80
asSpanFunction · 0.70
feedMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected