Add pseudo unit test helper for C bindings and convert all C binding tests#3342
Add pseudo unit test helper for C bindings and convert all C binding tests#3342SahilSonar-04 wants to merge 47 commits into
Conversation
mwestphal
left a comment
There was a problem hiding this comment.
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
d1e3172 to
328ef63
Compare
|
\ci fast |
| { | ||
| if (!img || !reference) | ||
| { | ||
| return 1; |
There was a problem hiding this comment.
[DELETED because of AI policy breach]
There was a problem hiding this comment.
@SahilSonar-04 do NOT use GenAI to write comments. I've deleted it as per our AI policy: https://f3d.app/dev/AI_POLICY
| f3d_test_check(test, label, actual == expected); | ||
| } | ||
|
|
||
| static inline int f3d_test_result(const f3d_test_t* test) |
| 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); |
| 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"); |
There was a problem hiding this comment.
definitely not a valid path on all platforms though, use F3D_TESTING_TEMP_DIR
| int load_native = f3d_engine_load_plugin("native"); | ||
| f3d_test_check_int(&test, "loading the native plugin succeeds", load_native, 1); |
There was a problem hiding this comment.
| 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); |
There was a problem hiding this comment.
unless im missing something, you can use this pattern everywhere
| &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 |
There was a problem hiding this comment.
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
| f3d_test_check(&test, "get_content returns non-null buffer", content != NULL); | ||
| if (content) | ||
| { | ||
| // just a roundtrip, no observable state change beyond not crashing |
There was a problem hiding this comment.
then maybe better to create a new image and check pointers are different
| 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"); |
| 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); |
| 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]); |
| 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); |
| 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); | ||
|
|
There was a problem hiding this comment.
missing some methods it looks like
|
Please check the checkboxes in the description, especially the AI disclosure part. |
|
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:
|
0b24cf5 to
8a290eb
Compare
fff0be8 to
787b754
Compare
Co-authored-by: Michael MIGLIORE <mcmigliore@gmail.com>
…defines instead of __linux__
787b754 to
a273322
Compare
Describe your changes
Issue ticket number and link if any
Checklist for finalizing the PR
.github/workflows/versions.json, I have updateddocker_timestampAI Disclosure
Continuous integration
Please write a comment to run CI, eg:
\ci fast.See here for more info.