Skip to content

Commit

Permalink
(#23942) sdf: refactor test package
Browse files Browse the repository at this point in the history
* sdf: refactor test package

* evade UB

* use sdf function

* minimal test with img_data null

* remove stb from conanfile

* fix

* remove stb from test_v1

* fix
  • Loading branch information
ErniGH authored May 24, 2024
1 parent a78bd93 commit 25fa812
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 37 deletions.
3 changes: 1 addition & 2 deletions recipes/sdf/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ cmake_minimum_required(VERSION 3.1)
project(test_package LANGUAGES C)

find_package(sdf REQUIRED CONFIG)
find_package(stb REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE sdf::sdf stb::stb)
target_link_libraries(${PROJECT_NAME} PRIVATE sdf::sdf)
4 changes: 1 addition & 3 deletions recipes/sdf/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def layout(self):

def requirements(self):
self.requires(self.tested_reference_str)
self.requires("stb/cci.20210910")

def build(self):
cmake = CMake(self)
Expand All @@ -24,5 +23,4 @@ def build(self):
def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
img_path = os.path.join(self.source_folder, "test.png")
self.run(f"{bin_path} {img_path}", env="conanrun")
self.run(bin_path, env="conanrun")
Binary file removed recipes/sdf/all/test_package/test.png
Binary file not shown.
29 changes: 4 additions & 25 deletions recipes/sdf/all/test_package/test_package.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,14 @@
#define SDF_IMPLEMENTATION
#include "sdf.h"

#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"

int main(int argc, char **argv)
{
if (argc < 2) {
fprintf(stderr, "Need at least one argument\n");
return 1;
}

int width, height, bpp;
unsigned char* img_data = stbi_load(argv[1], &width, &height, &bpp, 0);
if(img_data == NULL)
{
fprintf(stderr, "Could not load image: %s\n", stbi_failure_reason());
return 1;
}

unsigned char* dest_data = malloc(width * height * bpp);
if(dest_data == NULL)
{
stbi_image_free(img_data);
return 1;
}

sdfBuildDistanceField(dest_data, width, 2.0f, img_data, width, height, width);
unsigned char* dest_data = malloc(0);
int result = sdfBuildDistanceField(dest_data, 0, 2.0f, NULL, 0, 0, 0);
printf("Result: %d\n", result);
printf("Test");

free(dest_data);
stbi_image_free(img_data);

return 0;
}
3 changes: 1 addition & 2 deletions recipes/sdf/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

find_package(sdf REQUIRED CONFIG)
find_package(stb REQUIRED CONFIG)

add_executable(${PROJECT_NAME} ../test_package/test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE sdf::sdf stb::stb)
target_link_libraries(${PROJECT_NAME} PRIVATE sdf::sdf)
6 changes: 1 addition & 5 deletions recipes/sdf/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"

def requirements(self):
self.requires("stb/cci.20210910")

def build(self):
cmake = CMake(self)
cmake.configure()
Expand All @@ -17,5 +14,4 @@ def build(self):
def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
img_path = os.path.join(self.source_folder, os.pardir, "test_package", "test.png")
self.run(f"{bin_path} {img_path}", run_environment=True)
self.run(bin_path, run_environment=True)

0 comments on commit 25fa812

Please sign in to comment.