commit ada0040c36b0e3f0f3351875fd4531ff1e157c5f
parent f6f77a8889830bc24bf5a77045642bd47397fd6f
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Tue, 5 Nov 2019 10:09:58 +0100
Fix test
Diffstat:
1 file changed, 43 insertions(+), 14 deletions(-)
diff --git a/src/test_senc2d_undefined_medium_attr.c b/src/test_senc2d_undefined_medium_attr.c
@@ -17,18 +17,35 @@
#include "senc2d_s2d_wrapper.h"
#include "test_senc2d_utils.h"
-#include <rsys/dynamic_array_uint.h>
#include <rsys/double2.h>
#include <star/s2d.h>
+#include <limits.h>
+
+#define INVALID_INTFACE_ID UINT_MAX
+
+static FINLINE void
+set_null_id(struct mem_allocator* alloc, unsigned* data)
+{
+ ASSERT(data); (void)alloc;
+ *data = INVALID_INTFACE_ID;
+}
+
+#include <rsys/dynamic_array.h>
+#define DARRAY_NAME intface_id
+#define DARRAY_FUNCTOR_INIT set_null_id
+#define DARRAY_DATA unsigned
+#include <rsys/dynamic_array.h>
+
/* Manage interface properties */
struct merge_ctx {
- struct darray_uint global_interf_data;
+ struct darray_intface_id global_interf_data;
const unsigned* current_add_interf_data;
};
-static res_T add_seg
+static res_T
+add_seg
(const unsigned global_id,
const unsigned iseg,
void* context)
@@ -42,28 +59,42 @@ static res_T add_seg
/* Get interface information from ctx */
interf = merge_ctx->current_add_interf_data[iseg];
/* Keep data */
- res = darray_uint_resize(&merge_ctx->global_interf_data, global_id + 1);
+ res = darray_intface_id_resize(&merge_ctx->global_interf_data, global_id + 1);
if (res != RES_OK) return res;
- darray_uint_data_get(&merge_ctx->global_interf_data)[global_id] = interf;
+ darray_intface_id_data_get(&merge_ctx->global_interf_data)[global_id] = interf;
return res;
}
-static res_T merge_seg
+static res_T
+merge_seg
(const unsigned global_id,
const unsigned iseg,
const int reversed_segment,
void* context)
{
+ res_T res = RES_OK;
struct context* ctx = context;
struct merge_ctx* merge_ctx;
+ int need_merge;
unsigned interf;
+ unsigned* interf_data;
ASSERT(ctx); (void)reversed_segment;
merge_ctx = ctx->custom;
+ res = darray_intface_id_resize(&merge_ctx->global_interf_data, global_id + 1);
+ if (res != RES_OK) return res;
/* Get interface information from ctx */
interf = merge_ctx->current_add_interf_data[iseg];
- if (darray_uint_data_get(&merge_ctx->global_interf_data)[global_id] != interf)
- /* Previous interface id is different: no possible merge */
- return RES_BAD_ARG;
+ interf_data = darray_intface_id_data_get(&merge_ctx->global_interf_data);
+
+ need_merge = (interf_data[global_id] != INVALID_INTFACE_ID);
+ if (need_merge) {
+ if (interf_data[global_id] != interf)
+ /* Previous interface id is different: no possible merge */
+ return RES_BAD_ARG;
+ } else {
+ /* Triangle is known, but without interface information: create */
+ interf_data[global_id] = interf;
+ }
/* Same data: no merge needed */
return RES_OK;
}
@@ -84,12 +115,10 @@ test(const int convention)
unsigned i, s, ecount, vcount, scount;
unsigned media[4], interface_ids[4] = { 0, 0, 1, 1, };
unsigned rev_box_indices[sizeof(box_indices) / sizeof(*box_indices)];
- int conv_front;
struct merge_ctx merge_ctx;
+ int conv_front = (convention & SENC2D_CONVENTION_NORMAL_FRONT) != 0;
- conv_front = (convention & SENC2D_CONVENTION_NORMAL_FRONT) != 0;
-
- darray_uint_init(&allocator, &merge_ctx.global_interf_data);
+ darray_intface_id_init(&allocator, &merge_ctx.global_interf_data);
merge_ctx.current_add_interf_data = interface_ids;
/* Create a box with reversed segments */
@@ -320,7 +349,7 @@ test(const int convention)
SENC2D(scene_ref_put(scn));
SENC2D(device_ref_put(dev));
SENC2D(descriptor_ref_put(desc));
- darray_uint_release(&merge_ctx.global_interf_data);
+ darray_intface_id_release(&merge_ctx.global_interf_data);
check_memory_allocator(&allocator);
mem_shutdown_proxy_allocator(&allocator);