Skip to content

Add pseudo unit test helper for C bindings and convert all C binding tests#3342

Open
SahilSonar-04 wants to merge 47 commits into
f3d-app:masterfrom
SahilSonar-04:c-bindings-test-framework
Open

Add pseudo unit test helper for C bindings and convert all C binding tests#3342
SahilSonar-04 wants to merge 47 commits into
f3d-app:masterfrom
SahilSonar-04:c-bindings-test-framework

Conversation

@SahilSonar-04

@SahilSonar-04 SahilSonar-04 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Describe your changes

Issue ticket number and link if any

Checklist for finalizing the PR

  • I have performed a self-review of my code
  • I have added tests for new features and bugfixes
  • I have added documentation for new features
  • If it is a modifying the libf3d API, I have updated bindings
  • If it is a modifying the .github/workflows/versions.json, I have updated docker_timestamp

AI Disclosure

  • I did not use AI to generate any of the content of that pull request
  • I used AI to generate code in that pull request, if yes please disclose which part of the code was generated and with which model.
  • ...

Continuous integration

Please write a comment to run CI, eg: \ci fast.
See here for more info.

@SahilSonar-04 SahilSonar-04 changed the title Add C pseudo unit test helper with self-test Add pseudo unit test helper for C bindings and convert all C binding tests Jul 7, 2026
@SahilSonar-04
SahilSonar-04 marked this pull request as ready for review July 7, 2026 05:54
@SahilSonar-04
SahilSonar-04 requested a review from a team as a code owner July 7, 2026 05:54

@mwestphal mwestphal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good at first glance, will do a deep review later.
Also please make sure to rebase on master regularly and add any new tests that may be needed

Comment thread c/testing/test_context.c Outdated
Comment thread c/testing/test_image.c Outdated
Comment thread c/testing/test_interactor.c Outdated
Comment thread c/testing/test_interactor.c Outdated
Comment thread c/testing/test_options.c Outdated
Comment thread c/testing/test_options.c Outdated
@mwestphal
mwestphal requested a review from Meakk July 7, 2026 06:05
@SahilSonar-04
SahilSonar-04 requested a review from mwestphal July 7, 2026 11:57
Comment thread c/testing/test_camera.c Outdated
Comment thread c/testing/test_context.c Outdated
Comment thread c/testing/test_context.c Outdated
@SahilSonar-04
SahilSonar-04 force-pushed the c-bindings-test-framework branch from d1e3172 to 328ef63 Compare July 7, 2026 15:19
@SahilSonar-04
SahilSonar-04 requested a review from Meakk July 7, 2026 16:17
@SahilSonar-04

Copy link
Copy Markdown
Contributor Author

\ci fast

Comment thread c/image_c_api.cxx
{
if (!img || !reference)
{
return 1;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this one wrong too ?

@SahilSonar-04 SahilSonar-04 Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[DELETED because of AI policy breach]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SahilSonar-04 do NOT use GenAI to write comments. I've deleted it as per our AI policy: https://f3d.app/dev/AI_POLICY

Comment thread c/testing/pseudo_unit_test.h Outdated
f3d_test_check(test, label, actual == expected);
}

static inline int f3d_test_result(const f3d_test_t* test)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing a doc

Comment thread c/testing/pseudo_unit_test.h Outdated
Comment thread c/testing/test_camera.c Outdated
Comment on lines +91 to +101
f3d_test_check(&test, "transform bindings reach the camera and change its state",
state_after_transforms.position[0] != state_before_transforms.position[0] ||
state_after_transforms.position[1] != state_before_transforms.position[1] ||
state_after_transforms.position[2] != state_before_transforms.position[2] ||
state_after_transforms.focal_point[0] != state_before_transforms.focal_point[0] ||
state_after_transforms.focal_point[1] != state_before_transforms.focal_point[1] ||
state_after_transforms.focal_point[2] != state_before_transforms.focal_point[2] ||
state_after_transforms.view_up[0] != state_before_transforms.view_up[0] ||
state_after_transforms.view_up[1] != state_before_transforms.view_up[1] ||
state_after_transforms.view_up[2] != state_before_transforms.view_up[2] ||
state_after_transforms.view_angle != state_before_transforms.view_angle);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the vector version ?

Comment thread c/testing/test_engine.c Outdated
f3d_test_check(&test, "interactor retrieved from windowed engine", interactor != NULL);

f3d_engine_set_cache_path(engine, "/tmp/f3d_test_cache");
int cache_ret = f3d_engine_set_cache_path(engine, "/tmp/f3d_test_cache");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

definitely not a valid path on all platforms though, use F3D_TESTING_TEMP_DIR

Comment thread c/testing/test_engine.c Outdated
Comment on lines +37 to +38
int load_native = f3d_engine_load_plugin("native");
f3d_test_check_int(&test, "loading the native plugin succeeds", load_native, 1);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int load_native = f3d_engine_load_plugin("native");
f3d_test_check_int(&test, "loading the native plugin succeeds", load_native, 1);
f3d_test_check_int(&test, "loading the native plugin succeeds", f3d_engine_load_plugin("native"), 1);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless im missing something, you can use this pattern everywhere

Comment thread c/testing/test_engine.c Outdated
&test, "get_readers_info() returns at least one reader", readers && reader_count > 0);
f3d_engine_free_readers_info(readers);

// set_options with the engine's own options has no distinct observable effect to check

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then maybe create a new options?

f3d_options_t* standalone_options = f3d_options_create(); you can then check get it again and check pointers are different

Comment thread c/testing/test_image.c Outdated
f3d_test_check(&test, "get_content returns non-null buffer", content != NULL);
if (content)
{
// just a roundtrip, no observable state change beyond not crashing

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then maybe better to create a new image and check pointers are different

Comment thread c/testing/test_interactor.c Outdated
int play_ret = f3d_interactor_play_interaction(interactor, "/nonexistent.log", 1.0 / 30.0);
f3d_test_check(&test, "playing a nonexistent interaction file reports failure", play_ret == 0);

int record_ret = f3d_interactor_record_interaction(interactor, "/tmp/test_interaction.log");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use proper temp dir

Comment thread c/testing/test_options.c Outdated
f3d_test_check_int(&test, "double vector count matches", (long)out_count, 3);
f3d_test_check_double(&test, "double vector[0] matches", out_vec[0], vec_values[0], 1e-9);
f3d_test_check_double(&test, "double vector[1] matches", out_vec[1], vec_values[1], 1e-9);
f3d_test_check_double(&test, "double vector[2] matches", out_vec[2], vec_values[2], 1e-9);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use vector version

Comment thread c/testing/test_options.c
f3d_options_get_as_int_vector(options, "scene.animation.indices", out_int_vec, &out_int_count);
f3d_test_check_int(&test, "int vector count matches", (long)out_int_count, 2);
f3d_test_check_int(&test, "int vector[0] matches", out_int_vec[0], int_vec_values[0]);
f3d_test_check_int(&test, "int vector[1] matches", out_int_vec[1], int_vec_values[1]);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use vector version

Comment thread c/testing/test_options.c Outdated
f3d_test_check_int(&test, "parsed double vector count matches", (long)parsed_dvec_count, 3);
f3d_test_check_double(&test, "parsed double vector[0] matches", parsed_dvec[0], 1.0, 1e-9);
f3d_test_check_double(&test, "parsed double vector[1] matches", parsed_dvec[1], 2.0, 1e-9);
f3d_test_check_double(&test, "parsed double vector[2] matches", parsed_dvec[2], 3.0, 1e-9);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use vector version

f3d_test_init(&boundary);
f3d_test_check_double(&boundary, "exactly at tolerance boundary fails", 1.1, 1.0, 0.1);
int boundary_ok = (boundary.fail_count == 1);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing some methods it looks like

@mwestphal mwestphal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes needed

@mwestphal

Copy link
Copy Markdown
Member

Please check the checkboxes in the description, especially the AI disclosure part.

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

Style Checks CI failed:

diff --git a/c/testing/pseudo_unit_test.h b/c/testing/pseudo_unit_test.h
index 78d6c0d..b3e7b03 100644
--- a/c/testing/pseudo_unit_test.h
+++ b/c/testing/pseudo_unit_test.h
@@ -1,10 +1,10 @@
 #ifndef f3d_pseudo_unit_test_h
 #define f3d_pseudo_unit_test_h
 
+#include <float.h>
 #include <math.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <float.h>
 #include <string.h>
 
 typedef struct
@@ -43,8 +43,7 @@ static inline void f3d_test_check_double(
 }
 
 // check equality of two integers
-static inline void f3d_test_check_int(
-  f3d_test_t* test, const char* label, int actual, int expected)
+static inline void f3d_test_check_int(f3d_test_t* test, const char* label, int actual, int expected)
 {
   f3d_test_check(test, label, actual == expected);
 }
@@ -57,15 +56,12 @@ static inline void f3d_test_check_vec3(
   char full_label[256];
 
   snprintf(full_label, sizeof(full_label),
-    "%s (actual=[%.6g, %.6g, %.6g], expected=[%.6g, %.6g, %.6g])",
-    label,
-    actual[0], actual[1], actual[2],
-    expected[0], expected[1], expected[2]);
+    "%s (actual=[%.6g, %.6g, %.6g], expected=[%.6g, %.6g, %.6g])", label, actual[0], actual[1],
+    actual[2], expected[0], expected[1], expected[2]);
 
   f3d_test_check(test, full_label,
-    fabs(actual[0] - expected[0]) < tol &&
-    fabs(actual[1] - expected[1]) < tol &&
-    fabs(actual[2] - expected[2]) < tol);
+    fabs(actual[0] - expected[0]) < tol && fabs(actual[1] - expected[1]) < tol &&
+      fabs(actual[2] - expected[2]) < tol);
 }
 
 // check equality of two strings
@@ -87,18 +83,16 @@ static inline void f3d_test_check_string(
 }
 
 // check that a pointer is not NULL
-static inline void f3d_test_check_ptr(
-  f3d_test_t* test, const char* label, const void* ptr)
+static inline void f3d_test_check_ptr(f3d_test_t* test, const char* label, const void* ptr)
 {
   f3d_test_check(test, label, ptr != NULL);
 }
 
 // check that a pointer is NULL
-static inline void f3d_test_check_null(
-  f3d_test_t* test, const char* label, const void* ptr)
+static inline void f3d_test_check_null(f3d_test_t* test, const char* label, const void* ptr)
 {
   f3d_test_check(test, label, ptr == NULL);
-} 
+}
 
 // check equality of two size_t values
 static inline void f3d_test_check_size(

You can copy the patch above and apply it locally with:

Platform Command
X xclip -o -selection clipboard | git apply -v
Wayland wl-paste | git apply -v
Powershell Get-Clipboard -Raw | git apply -v
macOS pbpaste | git apply -v

@SahilSonar-04
SahilSonar-04 force-pushed the c-bindings-test-framework branch 2 times, most recently from 0b24cf5 to 8a290eb Compare July 14, 2026 13:24
@SahilSonar-04
SahilSonar-04 force-pushed the c-bindings-test-framework branch from fff0be8 to 787b754 Compare July 17, 2026 18:32
@SahilSonar-04
SahilSonar-04 force-pushed the c-bindings-test-framework branch from 787b754 to a273322 Compare July 17, 2026 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants