Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mcpp.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ members = [
"tests/examples/boost-throw-exception",
"tests/examples/boost-type-traits",
"tests/examples/boost-uuid",
"tests/examples/brotli",
"tests/examples/build-mcpp",
"tests/examples/c-ares",
"tests/examples/catch2",
Expand Down
56 changes: 56 additions & 0 deletions pkgs/c/compat.brotli.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
-- Form B C-source compat descriptor for Brotli. The three source globs match
-- upstream v1.2.0's BROTLI_COMMON_SOURCES, BROTLI_DEC_SOURCES, and
-- BROTLI_ENC_SOURCES CMake sets; the CLI, tests, fuzzers, and the optional C++
-- lazy static-initialization implementation are outside those sets.
package = {
spec = "1",
namespace = "compat",
name = "brotli",
description = "Brotli compression library",
licenses = {"MIT"},
repo = "https://github.com/google/brotli",
type = "package",

xpm = {
linux = {
["1.2.0"] = {
url = "https://github.com/google/brotli/archive/refs/tags/v1.2.0.tar.gz",
sha256 = "816c96e8e8f193b40151dad7e8ff37b1221d019dbcb9c35cd3fadbfe6477dfec",
},
},
macosx = {
["1.2.0"] = {
url = "https://github.com/google/brotli/archive/refs/tags/v1.2.0.tar.gz",
sha256 = "816c96e8e8f193b40151dad7e8ff37b1221d019dbcb9c35cd3fadbfe6477dfec",
},
},
windows = {
["1.2.0"] = {
url = "https://github.com/google/brotli/archive/refs/tags/v1.2.0.tar.gz",
sha256 = "816c96e8e8f193b40151dad7e8ff37b1221d019dbcb9c35cd3fadbfe6477dfec",
},
},
},

mcpp = {
language = "c++23",
import_std = false,
c_standard = "c11",
include_dirs = { "*/c/include" },
sources = {
"*/c/common/*.c",
"*/c/dec/*.c",
"*/c/enc/*.c",
},
targets = { ["brotli"] = { kind = "lib" } },
deps = {},

-- Upstream detects libm and propagates it for static builds.
linux = { ldflags = { "-lm" } },
macosx = { ldflags = { "-lm" } },
windows = {
-- This is upstream's only MSVC-specific library definition.
cflags = { "-D_CRT_SECURE_NO_WARNINGS" },
},
},
}
8 changes: 8 additions & 0 deletions tests/examples/brotli/mcpp.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Brotli test project: consumes compat.brotli through the workspace-root
# `compat` index redirect and exercises encoder, decoder, and common code.
[package]
name = "brotli-tests"
version = "0.1.0"

[dependencies.compat]
brotli = "1.2.0"
43 changes: 43 additions & 0 deletions tests/examples/brotli/tests/roundtrip.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <brotli/decode.h>
#include <brotli/encode.h>

#include <cstddef>
#include <cstring>
#include <vector>

int main() {
static constexpr unsigned char original[] =
"Brotli round-trip payload. Brotli round-trip payload. "
"Brotli round-trip payload. Brotli round-trip payload.";
constexpr std::size_t original_size = sizeof(original) - 1;

const std::size_t encoded_capacity = BrotliEncoderMaxCompressedSize(original_size);
if (original_size == 0 || encoded_capacity == 0) return 1;

std::vector<unsigned char> encoded(encoded_capacity);
std::size_t encoded_size = encoded.size();
const BROTLI_BOOL encoded_ok = BrotliEncoderCompress(
BROTLI_DEFAULT_QUALITY,
BROTLI_DEFAULT_WINDOW,
BROTLI_MODE_GENERIC,
original_size,
original,
&encoded_size,
encoded.data());
if (encoded_ok != BROTLI_TRUE || encoded_size == 0) return 2;

std::vector<unsigned char> decoded(original_size);
std::size_t decoded_size = decoded.size();
const BrotliDecoderResult decoded_result = BrotliDecoderDecompress(
encoded_size,
encoded.data(),
&decoded_size,
decoded.data());
if (decoded_result != BROTLI_DECODER_RESULT_SUCCESS) return 3;
if (decoded_size != original_size) return 4;

for (std::size_t i = 0; i < original_size; ++i) {
if (decoded[i] != original[i]) return 5;
}
return std::memcmp(decoded.data(), original, original_size) == 0 ? 0 : 6;
}