Skip to content

Commit 7be5ecc

Browse files
authored
feat: Construct a builder from a FFI builder (#189)
* feat: Construct a builder from a FFI builder * test: add tests * chore: bump from 1.18.1 to 1.18.2
1 parent 7243e47 commit 7be5ecc

4 files changed

Lines changed: 31 additions & 1 deletion

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
cmake_minimum_required(VERSION 3.27)
1515

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

1919
# Set the version of the c2pa_rs library used
2020
set(C2PA_VERSION "0.78.4")

include/c2pa.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,11 @@ namespace c2pa
840840
[[deprecated("Use Builder(IContextProvider& context, manifest_json) instead")]]
841841
Builder(const std::string &manifest_json);
842842

843+
/// @brief Create a Builder from a raw C FFI builder.
844+
/// @param builder Raw C2paBuilder pointer to wrap.
845+
/// @throws C2paException if builder is nullptr.
846+
explicit Builder(C2paBuilder *builder);
847+
843848
Builder(const Builder&) = delete;
844849

845850
Builder& operator=(const Builder&) = delete;

src/c2pa_builder.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@
2121

2222
namespace c2pa
2323
{
24+
Builder::Builder(C2paBuilder *builder)
25+
: builder(builder)
26+
{
27+
if (this->builder == nullptr)
28+
{
29+
throw C2paException("Invalid builder pointer");
30+
}
31+
}
32+
2433
Builder::Builder(IContextProvider& context)
2534
: builder(nullptr)
2635
{

tests/builder.test.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,22 @@ TEST_F(BuilderTest, exposes_raw_pointer) {
166166
ASSERT_NE(builder.c2pa_builder(), nullptr);
167167
}
168168

169+
TEST_F(BuilderTest, wraps_c_ffi_builder) {
170+
fs::path current_dir = fs::path(__FILE__).parent_path();
171+
fs::path manifest_path = current_dir / "../tests/fixtures/training.json";
172+
auto manifest = c2pa_test::read_text_file(manifest_path);
173+
174+
C2paBuilder* ffi_builder = c2pa_builder_from_json(manifest.c_str());
175+
ASSERT_NE(ffi_builder, nullptr);
176+
177+
auto builder = c2pa::Builder(ffi_builder);
178+
EXPECT_EQ(builder.c2pa_builder(), ffi_builder);
179+
}
180+
181+
TEST_F(BuilderTest, wraps_null_c_ffi_builder_throws) {
182+
EXPECT_THROW(c2pa::Builder(nullptr), c2pa::C2paException);
183+
}
184+
169185
// Test fixture for basic signature validations with automatic cleanup
170186
class BuilderSmokeSignTest : public BuilderTest, public ::testing::WithParamInterface<std::string> {
171187
public:

0 commit comments

Comments
 (0)