Skip to content

Commit

Permalink
Merge branch 'fix/wkb_capi' into 'master'
Browse files Browse the repository at this point in the history
fix(capi): wkb was copied as a string not as a binary array. Add test

See merge request sfcgal/SFCGAL!322
  • Loading branch information
lbartoletti committed Jun 12, 2024
2 parents 5545926 + 03af9b1 commit 7d6e41f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/capi/sfcgal_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ sfcgal_geometry_as_wkb(const sfcgal_geometry_t *pgeom, char **buffer,
reinterpret_cast<const SFCGAL::Geometry *>(pgeom)->asWkb(
boost::endian::order::native, false);
*buffer = (char *)sfcgal_alloc_handler(wkb.size() + 1); *len = wkb.size();
strncpy(*buffer, wkb.c_str(), *len);)
memcpy(*buffer, wkb.data(), *len);)
}

extern "C" void
Expand Down
24 changes: 23 additions & 1 deletion test/unit/SFCGAL/capi/sfcgal_cTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* License along with this library; if not, see
<http://www.gnu.org/licenses/>.
*/
#include "SFCGAL/capi/sfcgal_c.h"
#include "SFCGAL/GeometryCollection.h"
#include "SFCGAL/LineString.h"
#include "SFCGAL/MultiLineString.h"
Expand All @@ -30,7 +31,6 @@
#include "SFCGAL/Solid.h"
#include "SFCGAL/Triangle.h"
#include "SFCGAL/TriangulatedSurface.h"
#include "SFCGAL/capi/sfcgal_c.h"
#include "SFCGAL/io/wkt.h"

#include <boost/test/unit_test.hpp>
Expand Down Expand Up @@ -76,6 +76,28 @@ BOOST_AUTO_TEST_CASE(testErrorOnBadGeometryType)
BOOST_CHECK(hasError == true);
}

BOOST_AUTO_TEST_CASE(testAsWkb)
{
sfcgal_set_error_handlers(printf, on_error);

// retrieve wkb from geometry via C++ api
std::unique_ptr<Geometry> const geom(
io::readWkt("POLYGON((0 0, 20 0, 20 10, 0 10, 0 0))"));

std::string strGeom;
strGeom = geom->asWkb();

// retrieve wkb from C api
char *wkbApi;
size_t wkbLen;
sfcgal_geometry_as_wkb(geom.get(), &wkbApi, &wkbLen);
std::string strApi(wkbApi, wkbLen);

// check
BOOST_CHECK_EQUAL(strGeom, strApi);
delete[] wkbApi;
}

BOOST_AUTO_TEST_CASE(testStraightSkeletonPolygon)
{
sfcgal_set_error_handlers(printf, on_error);
Expand Down

0 comments on commit 7d6e41f

Please sign in to comment.