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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
cmake_minimum_required(VERSION 3.27)

# This is the current version of this C++ project
project(c2pa-c VERSION 0.18.1)
project(c2pa-c VERSION 0.18.2)

# Set the version of the c2pa_rs library used
set(C2PA_VERSION "0.78.4")
Expand Down
5 changes: 5 additions & 0 deletions include/c2pa.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,11 @@ namespace c2pa
[[deprecated("Use Builder(IContextProvider& context, manifest_json) instead")]]
Builder(const std::string &manifest_json);

/// @brief Create a Builder from a raw C FFI builder.
/// @param builder Raw C2paBuilder pointer to wrap.
/// @throws C2paException if builder is nullptr.
explicit Builder(C2paBuilder *builder);

Builder(const Builder&) = delete;

Builder& operator=(const Builder&) = delete;
Expand Down
9 changes: 9 additions & 0 deletions src/c2pa_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@

namespace c2pa
{
Builder::Builder(C2paBuilder *builder)
: builder(builder)
{
if (this->builder == nullptr)
{
throw C2paException("Invalid builder pointer");
}
}

Builder::Builder(IContextProvider& context)
: builder(nullptr)
{
Expand Down
16 changes: 16 additions & 0 deletions tests/builder.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,22 @@ TEST_F(BuilderTest, exposes_raw_pointer) {
ASSERT_NE(builder.c2pa_builder(), nullptr);
}

TEST_F(BuilderTest, wraps_c_ffi_builder) {
fs::path current_dir = fs::path(__FILE__).parent_path();
fs::path manifest_path = current_dir / "../tests/fixtures/training.json";
auto manifest = c2pa_test::read_text_file(manifest_path);

C2paBuilder* ffi_builder = c2pa_builder_from_json(manifest.c_str());
ASSERT_NE(ffi_builder, nullptr);

auto builder = c2pa::Builder(ffi_builder);
EXPECT_EQ(builder.c2pa_builder(), ffi_builder);
}

TEST_F(BuilderTest, wraps_null_c_ffi_builder_throws) {
EXPECT_THROW(c2pa::Builder(nullptr), c2pa::C2paException);
}

// Test fixture for basic signature validations with automatic cleanup
class BuilderSmokeSignTest : public BuilderTest, public ::testing::WithParamInterface<std::string> {
public:
Expand Down
Loading