From c855bc7af05ed9e09d4b0fcf2933942a9681835e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Molinari?= Date: Mon, 27 Jan 2025 14:28:39 +0100 Subject: [PATCH] tests: Port all test clients to the new test asserts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit gets rid of libc's abort() usage in the test suite using test asserts instead. Asserts run in the server as plugins aren't converted because they are shared between server and client. Co-authored-by: Daniel Stone Signed-off-by: Loïc Molinari --- tests/alpha-blending-test.c | 15 +- tests/assert-test.c | 12 +- tests/bad-buffer-test.c | 7 +- tests/buffer-transforms-test.c | 5 +- tests/color-icc-output-test.c | 35 +-- tests/color-lcms-optimizer-test.c | 85 ++++---- tests/color-management-parametric-test.c | 75 ++++--- tests/color-management-test.c | 61 +++--- tests/color-metadata-errors-test.c | 32 +-- tests/color-metadata-parsing-test.c | 58 ++--- tests/color_util.c | 13 +- tests/constraints-test.c | 77 +++---- tests/custom-env-test.c | 12 +- tests/devices-test.c | 79 +++---- tests/drm-formats-test.c | 107 +++++----- tests/drm-smoke-test.c | 7 +- tests/drm-writeback-screenshot-test.c | 13 +- tests/event-test.c | 31 +-- tests/image-iter.h | 9 +- tests/input-timestamps-helper.c | 24 +-- tests/internal-screenshot-test.c | 13 +- tests/iterate-debug-scopes-test.c | 9 +- tests/ivi-layout-test-client.c | 19 +- tests/ivi-shell-app-test.c | 10 +- tests/keyboard-test.c | 31 +-- tests/kiosk-shell-test.c | 224 +++++++++++--------- tests/lcms-util-test.c | 5 +- tests/lcms_util.c | 22 +- tests/linux-explicit-synchronization-test.c | 49 ++--- tests/matrix-test.c | 3 +- tests/matrix-transform-test.c | 82 +++---- tests/output-capture-protocol-test.c | 86 ++++---- tests/output-damage-test.c | 5 +- tests/output-decorations-test.c | 3 +- tests/output-transforms-test.c | 5 +- tests/paint-node-test.c | 83 ++++---- tests/plugin-registry-test.c | 39 ++-- tests/pointer-shot-test.c | 9 +- tests/pointer-test.c | 154 +++++++------- tests/presentation-test.c | 20 +- tests/roles-test.c | 34 +-- tests/safe-signal-output-removal-test.c | 1 - tests/safe-signal-test.c | 1 - tests/shm-buffer-test.c | 67 +++--- tests/single-pixel-buffer-test.c | 5 +- tests/string-test.c | 38 ++-- tests/subsurface-shot-test.c | 27 +-- tests/subsurface-test.c | 57 ++--- tests/surface-global-test.c | 36 ++-- tests/surface-test.c | 12 +- tests/text-test.c | 19 +- tests/touch-test.c | 29 +-- tests/vertex-clip-test.c | 13 +- tests/viewporter-shot-test.c | 3 +- tests/viewporter-test.c | 22 +- tests/weston-test-client-helper.c | 175 ++++++++------- tests/weston-test-client-helper.h | 5 +- tests/weston-test-fixture-compositor.c | 34 +-- tests/weston-test-runner.c | 6 +- tests/weston-test.c | 1 + tests/weston-testsuite-data.h | 3 +- tests/xcb-client-helper.c | 16 +- tests/xcb-client-helper.h | 7 +- tests/xwayland-test.c | 40 ++-- 64 files changed, 1197 insertions(+), 1082 deletions(-) diff --git a/tests/alpha-blending-test.c b/tests/alpha-blending-test.c index 31880b734..17221342b 100644 --- a/tests/alpha-blending-test.c +++ b/tests/alpha-blending-test.c @@ -31,6 +31,7 @@ #include "weston-test-client-helper.h" #include "weston-test-fixture-compositor.h" +#include "weston-test-assert.h" #include "image-iter.h" #include "color_util.h" @@ -105,8 +106,8 @@ fill_alpha_pattern(struct buffer *buf) struct image_header ih = image_header_from(buf->image); int y; - assert(ih.pixman_format == PIXMAN_a8r8g8b8); - assert(ih.width == BLOCK_WIDTH * ALPHA_STEPS); + test_assert_enum(ih.pixman_format, PIXMAN_a8r8g8b8); + test_assert_int_eq(ih.width, BLOCK_WIDTH * ALPHA_STEPS); for (y = 0; y < ih.height; y++) { uint32_t *row = image_header_get_row_u32(&ih, y); @@ -193,8 +194,8 @@ get_middle_row(struct buffer *buf) { struct image_header ih = image_header_from(buf->image); - assert(ih.width >= BLOCK_WIDTH * ALPHA_STEPS); - assert(ih.height >= BLOCK_WIDTH); + test_assert_int_ge(ih.width, BLOCK_WIDTH * ALPHA_STEPS); + test_assert_int_ge(ih.height, BLOCK_WIDTH); return image_header_get_row_u32(&ih, (BLOCK_WIDTH - 1) / 2); } @@ -351,10 +352,10 @@ TEST(alpha_blend) move_client(client, 0, 0); shot = capture_screenshot_of_output(client, NULL); - assert(shot); + test_assert_ptr_not_null(shot); match = verify_image(shot->image, "alpha_blend", seq_no, NULL, seq_no); - assert(check_blend_pattern(bg, fg, shot, space)); - assert(match); + test_assert_true(check_blend_pattern(bg, fg, shot, space)); + test_assert_true(match); buffer_destroy(shot); diff --git a/tests/assert-test.c b/tests/assert-test.c index 42736fbd4..655d69e41 100644 --- a/tests/assert-test.c +++ b/tests/assert-test.c @@ -28,14 +28,13 @@ #include #include -#define custom_assert_fail_ test_assert_report - #include "shared/weston-assert.h" #include "weston-test-runner.h" __attribute__((format(printf, 2, 3))) -static void -test_assert_report(const struct weston_compositor *compositor, const char *fmt, ...) +static inline void +test_assert_report(const struct weston_compositor *compositor, + const char *fmt, ...) { va_list ap; @@ -44,6 +43,11 @@ test_assert_report(const struct weston_compositor *compositor, const char *fmt, va_end(ap); } +#ifdef custom_assert_fail_ +#undef custom_assert_fail_ +#endif +#define custom_assert_fail_ test_assert_report + static void abort_if_not(bool cond) { diff --git a/tests/bad-buffer-test.c b/tests/bad-buffer-test.c index 6d7bff6e5..bb4c3e549 100644 --- a/tests/bad-buffer-test.c +++ b/tests/bad-buffer-test.c @@ -35,6 +35,7 @@ #include "shared/os-compatibility.h" #include "weston-test-client-helper.h" #include "weston-test-fixture-compositor.h" +#include "weston-test-assert.h" static enum test_result_code fixture_setup(struct weston_test_harness *harness) @@ -151,7 +152,7 @@ create_bad_shm_buffer(struct client *client, int width, int height) int fd; fd = create_anonymous_file_without_seals(size); - assert(fd >= 0); + test_assert_int_ge(fd, 0); pool = wl_shm_create_pool(shm, fd, size); buffer = wl_shm_pool_create_buffer(pool, 0, width, height, stride, @@ -161,7 +162,7 @@ create_bad_shm_buffer(struct client *client, int width, int height) /* Truncate the file to a small size, so that the compositor * will access it out-of-bounds, and hit SIGBUS. */ - assert(ftruncate(fd, 12) == 0); + test_assert_int_eq(ftruncate(fd, 12), 0); close(fd); return buffer; @@ -176,7 +177,7 @@ TEST(test_truncated_shm_file) int frame; client = create_client_and_test_surface(46, 76, 111, 134); - assert(client); + test_assert_ptr_not_null(client); surface = client->surface->wl_surface; bad_buffer = create_bad_shm_buffer(client, 200, 200); diff --git a/tests/buffer-transforms-test.c b/tests/buffer-transforms-test.c index f7ec51e11..844ca93bd 100644 --- a/tests/buffer-transforms-test.c +++ b/tests/buffer-transforms-test.c @@ -31,6 +31,7 @@ #include "weston-test-client-helper.h" #include "weston-test-fixture-compositor.h" +#include "weston-test-assert.h" #define TRANSFORM(x) WL_OUTPUT_TRANSFORM_ ## x, #x #define RENDERERS(s, t) \ @@ -122,7 +123,7 @@ TEST_P(buffer_transform, my_buffer_args) ret = asprintf(&refname, "output_%d-%s_buffer_%d-%s", oargs->scale, oargs->transform_name, bargs->scale, bargs->transform_name); - assert(ret); + test_assert_int_gt(ret, 0); testlog("%s: %s\n", get_test_name(), refname); @@ -144,7 +145,7 @@ TEST_P(buffer_transform, my_buffer_args) move_client(client, 19, 19); match = verify_screen_content(client, refname, 0, NULL, 0, NULL); - assert(match); + test_assert_true(match); client_destroy(client); free(refname); diff --git a/tests/color-icc-output-test.c b/tests/color-icc-output-test.c index 5cd10afbb..72be452aa 100644 --- a/tests/color-icc-output-test.c +++ b/tests/color-icc-output-test.c @@ -29,6 +29,7 @@ #include #include "weston-test-client-helper.h" +#include "weston-test-assert.h" #include "image-iter.h" #include "lcms_util.h" @@ -197,10 +198,10 @@ build_output_icc_profile(const struct setup_args *arg, const char *filename) bool saved; profile = build_lcms_profile_output(arg); - assert(profile); + test_assert_ptr_not_null(profile); saved = cmsSaveProfileToFile(profile, filename); - assert(saved); + test_assert_true(saved); cmsCloseProfile(profile); } @@ -341,8 +342,8 @@ process_pipeline_comparison(const struct buffer *src_buf, bool ok; /* no point to compare different images */ - assert(ih_src.width == ih_shot.width); - assert(ih_src.height == ih_shot.height); + test_assert_int_eq(ih_src.width, ih_shot.width); + test_assert_int_eq(ih_src.height, ih_shot.height); for (y = 0; y < ih_src.height; y++) { uint32_t *row_ptr = image_header_get_row_u32(&ih_src, y); @@ -406,7 +407,7 @@ TEST(opaque_pixel_conversion) bool match; client = create_client_and_test_surface(0, 0, width, height); - assert(client); + test_assert_ptr_not_null(client); surface = client->surface->wl_surface; buf = create_shm_buffer_a8r8g8b8(client, width, height); @@ -417,12 +418,12 @@ TEST(opaque_pixel_conversion) wl_surface_commit(surface); shot = capture_screenshot_of_output(client, NULL); - assert(shot); + test_assert_ptr_not_null(shot); match = verify_image(shot->image, "shaper_matrix", arg->ref_image_index, NULL, seq_no); - assert(process_pipeline_comparison(buf, shot, arg)); - assert(match); + test_assert_true(process_pipeline_comparison(buf, shot, arg)); + test_assert_true(match); buffer_destroy(shot); buffer_destroy(buf); client_destroy(client); @@ -451,7 +452,7 @@ compare_blend(const struct lcms_pipeline *pip, unsigned i; /* convert sources to straight alpha */ - assert(bg.a == 1.0f); + test_assert_f32_eq(bg.a, 1.0f); fg = color_float_unpremult(fg); bg = convert_to_blending_space(pip, bg); @@ -480,8 +481,8 @@ get_middle_row(struct buffer *buf) { struct image_header ih = image_header_from(buf->image); - assert(ih.width >= BLOCK_WIDTH * ALPHA_STEPS); - assert(ih.height >= BLOCK_WIDTH); + test_assert_int_ge(ih.width, BLOCK_WIDTH * ALPHA_STEPS); + test_assert_int_ge(ih.height, BLOCK_WIDTH); return image_header_get_row_u32(&ih, (BLOCK_WIDTH - 1) / 2); } @@ -545,8 +546,8 @@ fill_alpha_pattern(struct buffer *buf) struct image_header ih = image_header_from(buf->image); int y; - assert(ih.pixman_format == PIXMAN_a8r8g8b8); - assert(ih.width == BLOCK_WIDTH * ALPHA_STEPS); + test_assert_enum(ih.pixman_format, PIXMAN_a8r8g8b8); + test_assert_int_eq(ih.width, BLOCK_WIDTH * ALPHA_STEPS); for (y = 0; y < ih.height; y++) { uint32_t *row = image_header_get_row_u32(&ih, y); @@ -638,11 +639,11 @@ TEST(output_icc_alpha_blend) move_client(client, 0, 0); shot = capture_screenshot_of_output(client, NULL); - assert(shot); + test_assert_ptr_not_null(shot); match = verify_image(shot->image, "output_icc_alpha_blend", arg->ref_image_index, NULL, seq_no); - assert(check_blend_pattern(bg, fg, shot, arg)); - assert(match); + test_assert_true(check_blend_pattern(bg, fg, shot, arg)); + test_assert_true(match); buffer_destroy(shot); @@ -682,7 +683,7 @@ TEST(output_icc_decorations) match = verify_image(img, "output-icc-decorations", arg->ref_image_index, NULL, seq_no); - assert(match); + test_assert_true(match); pixman_image_unref(img); buffer_destroy(shot); diff --git a/tests/color-lcms-optimizer-test.c b/tests/color-lcms-optimizer-test.c index 0393077b7..99db8c071 100644 --- a/tests/color-lcms-optimizer-test.c +++ b/tests/color-lcms-optimizer-test.c @@ -28,6 +28,7 @@ #include #include "weston-test-client-helper.h" +#include "weston-test-assert.h" #include "libweston/color-lcms/color-lcms.h" #include "libweston/color-lcms/color-curve-segments.h" @@ -90,10 +91,10 @@ pipeline_context_new(void) struct pipeline_context ret; ret.context_id = cmsCreateContext(NULL, NULL); - assert(ret.context_id); + test_assert_ptr_not_null(ret.context_id); ret.pipeline = cmsPipelineAlloc(ret.context_id, N_CHANNELS, N_CHANNELS); - assert(ret.pipeline); + test_assert_ptr_not_null(ret.pipeline); return ret; } @@ -115,15 +116,15 @@ add_curve(struct pipeline_context *pc, cmsInt32Number type, unsigned int i; curve = cmsBuildParametricToneCurve(pc->context_id, type, params); - assert(curve); + test_assert_ptr_not_null(curve); for (i = 0; i < N_CHANNELS; i++) curveset[i] = curve; stage = cmsStageAllocToneCurves(pc->context_id, ARRAY_LENGTH(curveset), curveset); - assert(stage); + test_assert_ptr_not_null(stage); - assert(cmsPipelineInsertStage(pc->pipeline, cmsAT_END, stage)); + test_assert_true(cmsPipelineInsertStage(pc->pipeline, cmsAT_END, stage)); cmsFreeToneCurve(curve); } @@ -134,9 +135,9 @@ add_identity_curve(struct pipeline_context *pc) cmsStage *stage; stage = cmsStageAllocToneCurves(pc->context_id, N_CHANNELS, NULL); - assert(stage); + test_assert_ptr_not_null(stage); - assert(cmsPipelineInsertStage(pc->pipeline, cmsAT_END, stage)); + test_assert_true(cmsPipelineInsertStage(pc->pipeline, cmsAT_END, stage)); } static void @@ -146,9 +147,9 @@ add_matrix(struct pipeline_context *pc, cmsStage *stage; stage = cmsStageAllocMatrix(pc->context_id, N_CHANNELS, N_CHANNELS, matrix, NULL); - assert(stage); + test_assert_ptr_not_null(stage); - assert(cmsPipelineInsertStage(pc->pipeline, cmsAT_END, stage)); + test_assert_true(cmsPipelineInsertStage(pc->pipeline, cmsAT_END, stage)); } static bool @@ -176,11 +177,11 @@ TEST(keep_regular_matrix) lcms_optimize_pipeline(&pc.pipeline, pc.context_id); elem = cmsPipelineGetPtrToFirstStage(pc.pipeline); - assert(elem); + test_assert_ptr_not_null(elem); data = cmsStageData(elem); - assert(are_matrices_equal(regular_matrix, data->Double)); + test_assert_true(are_matrices_equal(regular_matrix, data->Double)); - assert(!cmsStageNext(elem)); + test_assert_ptr_null(cmsStageNext(elem)); pipeline_context_release(&pc); } @@ -194,7 +195,7 @@ TEST(drop_identity_matrix) lcms_optimize_pipeline(&pc.pipeline, pc.context_id); - assert(cmsPipelineStageCount(pc.pipeline) == 0); + test_assert_u32_eq(cmsPipelineStageCount(pc.pipeline), 0); pipeline_context_release(&pc); } @@ -210,7 +211,7 @@ TEST(drop_inverse_matrices) lcms_optimize_pipeline(&pc.pipeline, pc.context_id); - assert(cmsPipelineStageCount(pc.pipeline) == 0); + test_assert_u32_eq(cmsPipelineStageCount(pc.pipeline), 0); pipeline_context_release(&pc); } @@ -227,7 +228,7 @@ TEST(drop_identity_and_inverse_matrices) lcms_optimize_pipeline(&pc.pipeline, pc.context_id); - assert(cmsPipelineStageCount(pc.pipeline) == 0); + test_assert_u32_eq(cmsPipelineStageCount(pc.pipeline), 0); pipeline_context_release(&pc); } @@ -247,11 +248,11 @@ TEST(only_drop_inverse_matrices) lcms_optimize_pipeline(&pc.pipeline, pc.context_id); elem = cmsPipelineGetPtrToFirstStage(pc.pipeline); - assert(elem); + test_assert_ptr_not_null(elem); data = cmsStageData(elem); - assert(are_matrices_equal(regular_matrix, data->Double)); + test_assert_true(are_matrices_equal(regular_matrix, data->Double)); - assert(!cmsStageNext(elem)); + test_assert_ptr_null(cmsStageNext(elem)); pipeline_context_release(&pc); } @@ -270,11 +271,11 @@ TEST(only_drop_inverse_matrices_another_order) lcms_optimize_pipeline(&pc.pipeline, pc.context_id); elem = cmsPipelineGetPtrToFirstStage(pc.pipeline); - assert(elem); + test_assert_ptr_not_null(elem); data = cmsStageData(elem); - assert(are_matrices_equal(regular_matrix, data->Double)); + test_assert_true(are_matrices_equal(regular_matrix, data->Double)); - assert(!cmsStageNext(elem)); + test_assert_ptr_null(cmsStageNext(elem)); pipeline_context_release(&pc); } @@ -288,7 +289,7 @@ TEST(drop_identity_curve) lcms_optimize_pipeline(&pc.pipeline, pc.context_id); - assert(cmsPipelineStageCount(pc.pipeline) == 0); + test_assert_u32_eq(cmsPipelineStageCount(pc.pipeline), 0); pipeline_context_release(&pc); } @@ -304,7 +305,7 @@ TEST(drop_inverse_curves) lcms_optimize_pipeline(&pc.pipeline, pc.context_id); - assert(cmsPipelineStageCount(pc.pipeline) == 0); + test_assert_u32_eq(cmsPipelineStageCount(pc.pipeline), 0); pipeline_context_release(&pc); } @@ -321,7 +322,7 @@ TEST(drop_identity_and_inverse_curves) lcms_optimize_pipeline(&pc.pipeline, pc.context_id); - assert(cmsPipelineStageCount(pc.pipeline) == 0); + test_assert_u32_eq(cmsPipelineStageCount(pc.pipeline), 0); pipeline_context_release(&pc); } @@ -337,7 +338,7 @@ TEST(drop_identity_and_inverse_curves_another_order) lcms_optimize_pipeline(&pc.pipeline, pc.context_id); - assert(cmsPipelineStageCount(pc.pipeline) == 0); + test_assert_u32_eq(cmsPipelineStageCount(pc.pipeline), 0); pipeline_context_release(&pc); } @@ -355,7 +356,7 @@ are_curveset_curves_equal_to_curve(struct pipeline_context *pc, cmsBuildParametricToneCurve(pc->context_id, curve->type, curve->params); - assert(curveset_data->nCurves == N_CHANNELS); + test_assert_u32_eq(curveset_data->nCurves, N_CHANNELS); for (i = 0; i < N_CHANNELS; i++) { if (!are_curves_equal(curveset_data->TheCurves[i], cms_curve)) { @@ -380,11 +381,11 @@ TEST(keep_regular_curve) lcms_optimize_pipeline(&pc.pipeline, pc.context_id); stage = cmsPipelineGetPtrToFirstStage(pc.pipeline); - assert(stage); - assert(are_curveset_curves_equal_to_curve(&pc, cmsStageData(stage), - &power_law_curve_A)); + test_assert_ptr_not_null(stage); + test_assert_true(are_curveset_curves_equal_to_curve(&pc, cmsStageData(stage), + &power_law_curve_A)); - assert(!cmsStageNext(stage)); + test_assert_ptr_null(cmsStageNext(stage)); pipeline_context_release(&pc); } @@ -404,11 +405,11 @@ TEST(do_not_merge_identity_with_parametric) lcms_optimize_pipeline(&pc.pipeline, pc.context_id); stage = cmsPipelineGetPtrToFirstStage(pc.pipeline); - assert(stage); - assert(are_curveset_curves_equal_to_curve(&pc, cmsStageData(stage), - &srgb_curve)); + test_assert_ptr_not_null(stage); + test_assert_true(are_curveset_curves_equal_to_curve(&pc, cmsStageData(stage), + &srgb_curve)); - assert(!cmsStageNext(stage)); + test_assert_ptr_null(cmsStageNext(stage)); pipeline_context_release(&pc); } @@ -430,11 +431,11 @@ TEST(merge_power_law_curves_with_itself) lcms_optimize_pipeline(&pc.pipeline, pc.context_id); stage = cmsPipelineGetPtrToFirstStage(pc.pipeline); - assert(stage); - assert(are_curveset_curves_equal_to_curve(&pc, cmsStageData(stage), - &result_curve)); + test_assert_ptr_not_null(stage); + test_assert_true(are_curveset_curves_equal_to_curve(&pc, cmsStageData(stage), + &result_curve)); - assert(!cmsStageNext(stage)); + test_assert_ptr_null(cmsStageNext(stage)); pipeline_context_release(&pc); } @@ -456,11 +457,11 @@ TEST(merge_power_law_curves_with_another) lcms_optimize_pipeline(&pc.pipeline, pc.context_id); stage = cmsPipelineGetPtrToFirstStage(pc.pipeline); - assert(stage); - assert(are_curveset_curves_equal_to_curve(&pc, cmsStageData(stage), - &result_curve)); + test_assert_ptr_not_null(stage); + test_assert_true(are_curveset_curves_equal_to_curve(&pc, cmsStageData(stage), + &result_curve)); - assert(!cmsStageNext(stage)); + test_assert_ptr_null(cmsStageNext(stage)); pipeline_context_release(&pc); } diff --git a/tests/color-management-parametric-test.c b/tests/color-management-parametric-test.c index 346c447cf..591ee65d4 100644 --- a/tests/color-management-parametric-test.c +++ b/tests/color-management-parametric-test.c @@ -26,6 +26,7 @@ #include "config.h" #include "weston-test-client-helper.h" +#include "weston-test-assert.h" #include "shared/xalloc.h" #include "color-management-v1-client-protocol.h" @@ -595,41 +596,45 @@ color_manager_init(struct color_manager *cm, struct client *client) client_roundtrip(client); /* Weston supports all color features. */ - assert(cm->supported_features == ((1 << WP_COLOR_MANAGER_V1_FEATURE_ICC_V2_V4) | - (1 << WP_COLOR_MANAGER_V1_FEATURE_PARAMETRIC) | - (1 << WP_COLOR_MANAGER_V1_FEATURE_SET_PRIMARIES) | - (1 << WP_COLOR_MANAGER_V1_FEATURE_SET_LUMINANCES) | - (1 << WP_COLOR_MANAGER_V1_FEATURE_SET_TF_POWER) | - (1 << WP_COLOR_MANAGER_V1_FEATURE_SET_MASTERING_DISPLAY_PRIMARIES) | - (1 << WP_COLOR_MANAGER_V1_FEATURE_EXTENDED_TARGET_VOLUME))); + test_assert_u32_eq(cm->supported_features, + (1 << WP_COLOR_MANAGER_V1_FEATURE_ICC_V2_V4) | + (1 << WP_COLOR_MANAGER_V1_FEATURE_PARAMETRIC) | + (1 << WP_COLOR_MANAGER_V1_FEATURE_SET_PRIMARIES) | + (1 << WP_COLOR_MANAGER_V1_FEATURE_SET_LUMINANCES) | + (1 << WP_COLOR_MANAGER_V1_FEATURE_SET_TF_POWER) | + (1 << WP_COLOR_MANAGER_V1_FEATURE_SET_MASTERING_DISPLAY_PRIMARIES) | + (1 << WP_COLOR_MANAGER_V1_FEATURE_EXTENDED_TARGET_VOLUME)); /* Weston supports all rendering intents. */ - assert(cm->supported_rendering_intents == ((1 << WP_COLOR_MANAGER_V1_RENDER_INTENT_PERCEPTUAL) | - (1 << WP_COLOR_MANAGER_V1_RENDER_INTENT_RELATIVE) | - (1 << WP_COLOR_MANAGER_V1_RENDER_INTENT_SATURATION) | - (1 << WP_COLOR_MANAGER_V1_RENDER_INTENT_ABSOLUTE) | - (1 << WP_COLOR_MANAGER_V1_RENDER_INTENT_RELATIVE_BPC))); + test_assert_u32_eq(cm->supported_rendering_intents, + (1 << WP_COLOR_MANAGER_V1_RENDER_INTENT_PERCEPTUAL) | + (1 << WP_COLOR_MANAGER_V1_RENDER_INTENT_RELATIVE) | + (1 << WP_COLOR_MANAGER_V1_RENDER_INTENT_SATURATION) | + (1 << WP_COLOR_MANAGER_V1_RENDER_INTENT_ABSOLUTE) | + (1 << WP_COLOR_MANAGER_V1_RENDER_INTENT_RELATIVE_BPC)); /* Weston supports all primaries. */ - assert(cm->supported_color_primaries == ((1 << WP_COLOR_MANAGER_V1_PRIMARIES_SRGB) | - (1 << WP_COLOR_MANAGER_V1_PRIMARIES_PAL_M) | - (1 << WP_COLOR_MANAGER_V1_PRIMARIES_PAL) | - (1 << WP_COLOR_MANAGER_V1_PRIMARIES_NTSC) | - (1 << WP_COLOR_MANAGER_V1_PRIMARIES_GENERIC_FILM) | - (1 << WP_COLOR_MANAGER_V1_PRIMARIES_BT2020) | - (1 << WP_COLOR_MANAGER_V1_PRIMARIES_CIE1931_XYZ) | - (1 << WP_COLOR_MANAGER_V1_PRIMARIES_DCI_P3) | - (1 << WP_COLOR_MANAGER_V1_PRIMARIES_DISPLAY_P3) | - (1 << WP_COLOR_MANAGER_V1_PRIMARIES_ADOBE_RGB))); + test_assert_u32_eq(cm->supported_color_primaries, + (1 << WP_COLOR_MANAGER_V1_PRIMARIES_SRGB) | + (1 << WP_COLOR_MANAGER_V1_PRIMARIES_PAL_M) | + (1 << WP_COLOR_MANAGER_V1_PRIMARIES_PAL) | + (1 << WP_COLOR_MANAGER_V1_PRIMARIES_NTSC) | + (1 << WP_COLOR_MANAGER_V1_PRIMARIES_GENERIC_FILM) | + (1 << WP_COLOR_MANAGER_V1_PRIMARIES_BT2020) | + (1 << WP_COLOR_MANAGER_V1_PRIMARIES_CIE1931_XYZ) | + (1 << WP_COLOR_MANAGER_V1_PRIMARIES_DCI_P3) | + (1 << WP_COLOR_MANAGER_V1_PRIMARIES_DISPLAY_P3) | + (1 << WP_COLOR_MANAGER_V1_PRIMARIES_ADOBE_RGB)); /* Weston supports only a few transfer functions, and we make use of * them in our tests. */ - assert(cm->supported_tf == ((1 << WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_GAMMA22) | - (1 << WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_GAMMA28) | - (1 << WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_SRGB) | - (1 << WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_ST2084_PQ))); + test_assert_u32_eq(cm->supported_tf, + (1 << WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_GAMMA22) | + (1 << WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_GAMMA28) | + (1 << WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_SRGB) | + (1 << WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_ST2084_PQ)); - assert(cm->done); + test_assert_true(cm->done); } static void @@ -665,8 +670,8 @@ TEST_P(create_parametric_image_description, good_test_cases) struct image_description *image_desc = NULL; /* No good test case should have expected error. */ - assert(args->error_point == ERROR_POINT_NONE); - assert(args->expected_error == NOT_SET); + test_assert_enum(args->error_point, ERROR_POINT_NONE); + test_assert_enum(args->expected_error, NOT_SET); client = create_client(); color_manager_init(&cm, client); @@ -716,8 +721,8 @@ TEST_P(create_parametric_image_description, good_test_cases) image_desc_creator_param = NULL; while (image_desc->status == CM_IMAGE_DESC_NOT_CREATED) - assert(wl_display_dispatch(client->wl_display) >= 0); - assert(image_desc->status == CM_IMAGE_DESC_READY); + test_assert_int_ge(wl_display_dispatch(client->wl_display), 0); + test_assert_enum(image_desc->status, CM_IMAGE_DESC_READY); image_description_destroy(image_desc); color_manager_fini(&cm); @@ -830,13 +835,13 @@ TEST_P(fail_to_create_parametric_image_description, bad_test_cases) } while (image_desc->status == CM_IMAGE_DESC_NOT_CREATED) - assert(wl_display_dispatch(client->wl_display) >= 0); + test_assert_int_ge(wl_display_dispatch(client->wl_display), 0); /* This TEST() is for bad params, so we shouldn't be able to * successfully create an image description. */ - assert(args->error_point == ERROR_POINT_GRACEFUL_FAILURE); - assert(image_desc->status == CM_IMAGE_DESC_FAILED); - assert(image_desc->failure_reason == args->expected_error); + test_assert_enum(args->error_point, ERROR_POINT_GRACEFUL_FAILURE); + test_assert_enum(image_desc->status, CM_IMAGE_DESC_FAILED); + test_assert_enum(image_desc->failure_reason, args->expected_error); out: if (image_desc) diff --git a/tests/color-management-test.c b/tests/color-management-test.c index 701e23db5..c24f63880 100644 --- a/tests/color-management-test.c +++ b/tests/color-management-test.c @@ -28,6 +28,7 @@ #include "color-properties.h" #include "weston-test-client-helper.h" #include "weston-test-fixture-compositor.h" +#include "weston-test-assert.h" #include "shared/xalloc.h" #include "lcms_util.h" @@ -170,9 +171,7 @@ static void image_descr_info_received(struct image_description_info *image_descr_info, enum image_descr_info_event ev) { - /* TODO: replace this assert with weston_assert_uint32_mask_bit_is_clear - * when we start using weston-assert in the test suite. */ - assert(!((image_descr_info->events_received >> ev) & 1)); + test_assert_bit_not_set(image_descr_info->events_received, 1 << ev); image_descr_info->events_received |= (1 << ev); } @@ -444,7 +443,7 @@ image_descr_info_done(void *data, testlog("Image description info %p done:\n", wp_image_description_info_v1); - assert(are_events_received_valid(image_descr_info)); + test_assert_true(are_events_received_valid(image_descr_info)); /* ICC based image description */ if ((image_descr_info->events_received >> IMAGE_DESCR_INFO_EVENT_ICC_FD) & 1) { @@ -596,22 +595,24 @@ color_manager_init(struct color_manager *cm, struct client *client) client_roundtrip(client); /* Weston supports all color features. */ - assert(cm->supported_features == ((1 << WP_COLOR_MANAGER_V1_FEATURE_ICC_V2_V4) | - (1 << WP_COLOR_MANAGER_V1_FEATURE_PARAMETRIC) | - (1 << WP_COLOR_MANAGER_V1_FEATURE_SET_PRIMARIES) | - (1 << WP_COLOR_MANAGER_V1_FEATURE_SET_TF_POWER) | - (1 << WP_COLOR_MANAGER_V1_FEATURE_SET_LUMINANCES) | - (1 << WP_COLOR_MANAGER_V1_FEATURE_SET_MASTERING_DISPLAY_PRIMARIES) | - (1 << WP_COLOR_MANAGER_V1_FEATURE_EXTENDED_TARGET_VOLUME))); + test_assert_u32_eq(cm->supported_features, + (1 << WP_COLOR_MANAGER_V1_FEATURE_ICC_V2_V4) | + (1 << WP_COLOR_MANAGER_V1_FEATURE_PARAMETRIC) | + (1 << WP_COLOR_MANAGER_V1_FEATURE_SET_PRIMARIES) | + (1 << WP_COLOR_MANAGER_V1_FEATURE_SET_TF_POWER) | + (1 << WP_COLOR_MANAGER_V1_FEATURE_SET_LUMINANCES) | + (1 << WP_COLOR_MANAGER_V1_FEATURE_SET_MASTERING_DISPLAY_PRIMARIES) | + (1 << WP_COLOR_MANAGER_V1_FEATURE_EXTENDED_TARGET_VOLUME)); /* Weston supports all rendering intents. */ - assert(cm->supported_rendering_intents == ((1 << WP_COLOR_MANAGER_V1_RENDER_INTENT_PERCEPTUAL) | - (1 << WP_COLOR_MANAGER_V1_RENDER_INTENT_RELATIVE) | - (1 << WP_COLOR_MANAGER_V1_RENDER_INTENT_SATURATION) | - (1 << WP_COLOR_MANAGER_V1_RENDER_INTENT_ABSOLUTE) | - (1 << WP_COLOR_MANAGER_V1_RENDER_INTENT_RELATIVE_BPC))); + test_assert_u32_eq(cm->supported_rendering_intents, + (1 << WP_COLOR_MANAGER_V1_RENDER_INTENT_PERCEPTUAL) | + (1 << WP_COLOR_MANAGER_V1_RENDER_INTENT_RELATIVE) | + (1 << WP_COLOR_MANAGER_V1_RENDER_INTENT_SATURATION) | + (1 << WP_COLOR_MANAGER_V1_RENDER_INTENT_ABSOLUTE) | + (1 << WP_COLOR_MANAGER_V1_RENDER_INTENT_RELATIVE_BPC)); - assert(cm->done); + test_assert_true(cm->done); } static void @@ -670,9 +671,9 @@ create_icc_based_image_description(struct color_manager *cm, struct stat st; icc_fd = open(icc_path, O_RDONLY); - assert(icc_fd >= 0); + test_assert_s32_ge(icc_fd, 0); - assert(fstat(icc_fd, &st) == 0); + test_assert_int_eq(fstat(icc_fd, &st), 0); wp_image_description_creator_icc_v1_set_icc_file(image_descr_creator_icc, icc_fd, 0, st.st_size); @@ -698,10 +699,10 @@ build_sRGB_icc_profile(const char *filename) profile = build_lcms_matrix_shaper_profile_output(NULL, &pipeline_sRGB, vcgt_exponents); - assert(profile); + test_assert_ptr_not_null(profile); saved = cmsSaveProfileToFile(profile, filename); - assert(saved); + test_assert_true(saved); cmsCloseProfile(profile); } @@ -723,7 +724,7 @@ fixture_setup(struct weston_test_harness *harness) tmp = output_filename_for_test_program(THIS_TEST_NAME, NULL, "icm"); - assert(strlen(tmp) < ARRAY_LENGTH(srgb_icc_profile_path)); + test_assert_int_lt(strlen(tmp), ARRAY_LENGTH(srgb_icc_profile_path)); strcpy(srgb_icc_profile_path, tmp); free(tmp); @@ -781,9 +782,9 @@ wait_until_image_description_ready(struct client *client, struct image_description *image_descr) { while (image_descr->status == CM_IMAGE_DESC_NOT_CREATED) - assert(wl_display_dispatch(client->wl_display) >= 0); + test_assert_int_ge(wl_display_dispatch(client->wl_display), 0); - assert(image_descr->status == CM_IMAGE_DESC_READY); + test_assert_enum(image_descr->status, CM_IMAGE_DESC_READY); } TEST(output_get_image_description) @@ -877,8 +878,8 @@ TEST(set_unreadable_icc_fd) /* The file is being open with WRITE, not READ permission. So the * compositor should complain. */ icc_fd = open(srgb_icc_profile_path, O_WRONLY); - assert(icc_fd >= 0); - assert(fstat(icc_fd, &st) == 0); + test_assert_s32_ge(icc_fd, 0); + test_assert_int_eq(fstat(icc_fd, &st), 0); /* Try setting the bad ICC file fd, it should fail. */ wp_image_description_creator_icc_v1_set_icc_file(image_descr_creator_icc, @@ -906,7 +907,7 @@ TEST(set_bad_icc_size_zero) wp_color_manager_v1_create_icc_creator(cm.manager); icc_fd = open(srgb_icc_profile_path, O_RDONLY); - assert(icc_fd >= 0); + test_assert_s32_ge(icc_fd, 0); /* Try setting ICC file with a bad size, it should fail. */ wp_image_description_creator_icc_v1_set_icc_file(image_descr_creator_icc, @@ -934,7 +935,7 @@ TEST(set_bad_icc_non_seekable) wp_color_manager_v1_create_icc_creator(cm.manager); /* We need a non-seekable file, and pipes are non-seekable. */ - assert(pipe(fds) >= 0); + test_assert_int_ge(pipe(fds), 0); /* Pretend that it has a valid size of 1024 bytes. That still should * fail because the fd is non-seekable. */ @@ -965,8 +966,8 @@ TEST(set_icc_twice) wp_color_manager_v1_create_icc_creator(cm.manager); icc_fd = open(srgb_icc_profile_path, O_RDONLY); - assert(icc_fd >= 0); - assert(fstat(icc_fd, &st) == 0); + test_assert_s32_ge(icc_fd, 0); + test_assert_int_eq(fstat(icc_fd, &st), 0); wp_image_description_creator_icc_v1_set_icc_file(image_descr_creator_icc, icc_fd, 0, st.st_size); diff --git a/tests/color-metadata-errors-test.c b/tests/color-metadata-errors-test.c index 32b8281d4..c971f4d22 100644 --- a/tests/color-metadata-errors-test.c +++ b/tests/color-metadata-errors-test.c @@ -26,11 +26,11 @@ #include "config.h" #include -#include #include #include "weston-test-client-helper.h" #include "weston-test-fixture-compositor.h" +#include "weston-test-assert.h" #include "weston-private.h" #include "libweston-internal.h" @@ -225,17 +225,17 @@ TEST_P(color_characteristics_config_error, config_cases) wc = create_config(t); section = weston_config_get_section(wc, "output", "name", "mockoutput"); - assert(section); + test_assert_ptr_not_null(section); retval = wet_output_set_color_characteristics(&mock_output, wc, section); - assert(fclose(logfile) == 0); + test_assert_int_eq(fclose(logfile), 0); logfile = NULL; testlog("retval %d, logs:\n%s\n", retval, logbuf); - assert(retval == t->expected_retval); - assert(strcmp(logbuf, t->expected_error) == 0); + test_assert_int_eq(retval, t->expected_retval); + test_assert_int_eq(strcmp(logbuf, t->expected_error), 0); weston_config_destroy(wc); free(logbuf); @@ -264,7 +264,7 @@ TEST(weston_output_set_color_characteristics_null) mock_output.color_characteristics.group_mask = 1; weston_output_set_color_characteristics(&mock_output, NULL); - assert(mock_output.color_characteristics.group_mask == 0); + test_assert_u32_eq(mock_output.color_characteristics.group_mask, 0); weston_output_release(&mock_output); weston_idalloc_destroy(mock_compositor.color_profile_id_generator); @@ -347,10 +347,10 @@ TEST_P(hdr_metadata_type1_errors, value_cases) wl_list_init(&mock_compositor.plane_list); weston_output_init(&mock_output, &mock_compositor, "mockoutput"); - assert(t->field_index < ARRAY_LENGTH(fields)); + test_assert_uint_lt(t->field_index, ARRAY_LENGTH(fields)); *fields[t->field_index] = t->value; ret = weston_output_set_color_outcome(&mock_output); - assert(ret == t->retval); + test_assert_int_eq(ret, t->retval); weston_output_color_outcome_destroy(&mock_output.color_outcome); weston_output_release(&mock_output); @@ -393,7 +393,7 @@ TEST(hdr_metadata_type1_ignore_unflagged) weston_output_init(&mock_output, &mock_compositor, "mockoutput"); ret = weston_output_set_color_outcome(&mock_output); - assert(ret); + test_assert_true(ret); weston_output_color_outcome_destroy(&mock_output.color_outcome); weston_output_release(&mock_output); @@ -633,14 +633,14 @@ TEST_P(mode_config_error, mode_config_cases) weston_head_set_supported_eotf_mask(&mock_head, t->supported_eotf_mask); weston_head_set_supported_colorimetry_mask(&mock_head, t->supported_colorimetry_mask); attached = weston_output_attach_head(&mock_output, &mock_head); - assert(attached == 0); + test_assert_int_eq(attached, 0); logfile = open_memstream(&logbuf, &logsize); weston_log_set_handler(logger, logger); wc = create_mode_config(t); section = weston_config_get_section(wc, "output", "name", "mockoutput"); - assert(section); + test_assert_ptr_not_null(section); retval = wet_output_set_eotf_mode(&mock_output, section, t->color_management); if (retval == 0) { @@ -648,15 +648,15 @@ TEST_P(mode_config_error, mode_config_cases) t->color_management); } - assert(fclose(logfile) == 0); + test_assert_int_eq(fclose(logfile), 0); logfile = NULL; testlog("retval %d, logs:\n%s\n", retval, logbuf); - assert(retval == t->expected_retval); - assert(strcmp(logbuf, t->expected_error) == 0); - assert(weston_output_get_eotf_mode(&mock_output) == t->expected_eotf_mode); - assert(weston_output_get_colorimetry_mode(&mock_output) == t->expected_colorimetry_mode); + test_assert_int_eq(retval, t->expected_retval); + test_assert_int_eq(strcmp(logbuf, t->expected_error), 0); + test_assert_enum(weston_output_get_eotf_mode(&mock_output), t->expected_eotf_mode); + test_assert_enum(weston_output_get_colorimetry_mode(&mock_output), t->expected_colorimetry_mode); weston_config_destroy(wc); free(logbuf); diff --git a/tests/color-metadata-parsing-test.c b/tests/color-metadata-parsing-test.c index 236248c05..8c5675940 100644 --- a/tests/color-metadata-parsing-test.c +++ b/tests/color-metadata-parsing-test.c @@ -26,10 +26,10 @@ #include "config.h" #include -#include #include "weston-test-client-helper.h" #include "weston-test-fixture-compositor.h" +#include "weston-test-assert.h" #include "backend.h" #include "color.h" @@ -86,41 +86,41 @@ PLUGIN_TEST(color_characteristics_from_weston_ini) } } - assert(output); + test_assert_ptr_not_null(output); mode = weston_output_get_eotf_mode(output); - assert(mode == WESTON_EOTF_MODE_ST2084); + test_assert_enum(mode, WESTON_EOTF_MODE_ST2084); colorimetry_mode = weston_output_get_colorimetry_mode(output); - assert(colorimetry_mode == WESTON_COLORIMETRY_MODE_BT2020_RGB); + test_assert_enum(colorimetry_mode, WESTON_COLORIMETRY_MODE_BT2020_RGB); cc = weston_output_get_color_characteristics(output); - assert(cc->group_mask == WESTON_COLOR_CHARACTERISTICS_GROUP_ALL_MASK); - assert(cc->primary[0].x == 0.9999f); - assert(cc->primary[0].y == 0.3f); - assert(cc->primary[1].x == 0.1771f); - assert(cc->primary[1].y == 0.80001f); - assert(cc->primary[2].x == 0.1f); - assert(cc->primary[2].y == 0.11f); - assert(cc->white.x == 0.313f); - assert(cc->white.y == 0.323f); - assert(cc->min_luminance == 0.0001f); - assert(cc->max_luminance == 65535.0f); - assert(cc->maxFALL == 1000.0f); + test_assert_enum(cc->group_mask, WESTON_COLOR_CHARACTERISTICS_GROUP_ALL_MASK); + test_assert_f32_eq(cc->primary[0].x, 0.9999f); + test_assert_f32_eq(cc->primary[0].y, 0.3f); + test_assert_f32_eq(cc->primary[1].x, 0.1771f); + test_assert_f32_eq(cc->primary[1].y, 0.80001f); + test_assert_f32_eq(cc->primary[2].x, 0.1f); + test_assert_f32_eq(cc->primary[2].y, 0.11f); + test_assert_f32_eq(cc->white.x, 0.313f); + test_assert_f32_eq(cc->white.y, 0.323f); + test_assert_f32_eq(cc->min_luminance, 0.0001f); + test_assert_f32_eq(cc->max_luminance, 65535.0f); + test_assert_f32_eq(cc->maxFALL, 1000.0f); /* The below is color manager policy. */ hdr_meta = weston_output_get_hdr_metadata_type1(output); - assert(hdr_meta->group_mask == WESTON_HDR_METADATA_TYPE1_GROUP_ALL_MASK); - assert(hdr_meta->primary[0].x == 0.9999f); - assert(hdr_meta->primary[0].y == 0.3f); - assert(hdr_meta->primary[1].x == 0.1771f); - assert(hdr_meta->primary[1].y == 0.80001f); - assert(hdr_meta->primary[2].x == 0.1f); - assert(hdr_meta->primary[2].y == 0.11f); - assert(hdr_meta->white.x == 0.313f); - assert(hdr_meta->white.y == 0.323f); - assert(hdr_meta->minDML == 0.0001f); - assert(hdr_meta->maxDML == 65535.0f); - assert(hdr_meta->maxCLL == 65535.0f); - assert(hdr_meta->maxFALL == 1000.0f); + test_assert_enum(hdr_meta->group_mask, WESTON_HDR_METADATA_TYPE1_GROUP_ALL_MASK); + test_assert_f32_eq(hdr_meta->primary[0].x, 0.9999f); + test_assert_f32_eq(hdr_meta->primary[0].y, 0.3f); + test_assert_f32_eq(hdr_meta->primary[1].x, 0.1771f); + test_assert_f32_eq(hdr_meta->primary[1].y, 0.80001f); + test_assert_f32_eq(hdr_meta->primary[2].x, 0.1f); + test_assert_f32_eq(hdr_meta->primary[2].y, 0.11f); + test_assert_f32_eq(hdr_meta->white.x, 0.313f); + test_assert_f32_eq(hdr_meta->white.y, 0.323f); + test_assert_f32_eq(hdr_meta->minDML, 0.0001f); + test_assert_f32_eq(hdr_meta->maxDML, 65535.0f); + test_assert_f32_eq(hdr_meta->maxCLL, 65535.0f); + test_assert_f32_eq(hdr_meta->maxFALL, 1000.0f); } diff --git a/tests/color_util.c b/tests/color_util.c index 5db692e5a..d18800935 100644 --- a/tests/color_util.c +++ b/tests/color_util.c @@ -35,6 +35,7 @@ #include #include "color_util.h" #include "weston-test-runner.h" +#include "weston-test-assert.h" #include "shared/helpers.h" static_assert(sizeof(struct color_float) == 4 * sizeof(float), @@ -117,7 +118,7 @@ transfer_fn_invert(enum transfer_fn fn) case TRANSFER_FN_SRGB_EOTF_INVERSE: return TRANSFER_FN_SRGB_EOTF; } - assert(0 && "bad transfer_fn"); + test_assert_not_reached("bad transfer_fn"); return 0; } @@ -140,7 +141,7 @@ transfer_fn_name(enum transfer_fn fn) case TRANSFER_FN_SRGB_EOTF_INVERSE: return "inverse sRGB EOTF"; } - assert(0 && "bad transfer_fn"); + test_assert_not_reached("bad transfer_fn"); return 0; } @@ -155,10 +156,10 @@ ensure_unit_range(float v) const float lim_lo = -tol; const float lim_hi = 1.0f + tol; - assert(v >= lim_lo); + test_assert_f32_ge(v, lim_lo); if (v < 0.0f) return 0.0f; - assert(v <= lim_hi); + test_assert_f32_le(v, lim_hi); if (v > 1.0f) return 1.0f; return v; @@ -389,7 +390,7 @@ lcmsMAT3_invert(struct lcmsMAT3 *result, const struct lcmsMAT3 *mat) weston_matrix_from_lcmsMAT3(&w, mat); ret = weston_matrix_invert(&inv, &w); - assert(ret == 0); + test_assert_int_eq(ret, 0); lcmsMAT3_from_weston_matrix(result, &inv); } @@ -489,7 +490,7 @@ rgb_diff_stat_print(const struct rgb_diff_stat *stat, float scale = exp2f(scaling_bits) - 1.0f; unsigned i; - assert(scaling_bits > 0); + test_assert_uint_gt(scaling_bits, 0); testlog("%s error statistics, %u samples, value range 0.0 - %.1f:\n", title, stat->two_norm.count, scale); diff --git a/tests/constraints-test.c b/tests/constraints-test.c index d4476c399..655873fcb 100644 --- a/tests/constraints-test.c +++ b/tests/constraints-test.c @@ -32,6 +32,7 @@ #include "shared/timespec-util.h" #include "weston-test-client-helper.h" #include "weston-test-client-protocol.h" +#include "weston-test-assert.h" struct constraints { struct zwp_pointer_constraints_v1 *zwp_pointer_constraints; @@ -76,7 +77,7 @@ pointer_locked_event(void *data, struct zwp_locked_pointer_v1 *locked_pointer) { struct constraints *cs = data; - assert(locked_pointer == cs->zwp_locked_pointer); + test_assert_ptr_eq(locked_pointer, cs->zwp_locked_pointer); cs->pointer_is_locked = true; } @@ -85,7 +86,7 @@ pointer_unlocked_event(void *data, struct zwp_locked_pointer_v1 *locked_pointer) { struct constraints *cs = data; - assert(locked_pointer == cs->zwp_locked_pointer); + test_assert_ptr_eq(locked_pointer, cs->zwp_locked_pointer); cs->pointer_is_locked = false; } @@ -99,7 +100,7 @@ pointer_confined_event(void *data, struct zwp_confined_pointer_v1 *confined_poin { struct constraints *cs = data; - assert(confined_pointer == cs->zwp_confined_pointer); + test_assert_ptr_eq(confined_pointer, cs->zwp_confined_pointer); cs->pointer_is_confined = true; } @@ -108,7 +109,7 @@ pointer_unconfined_event(void *data, struct zwp_confined_pointer_v1 *confined_po { struct constraints *cs = data; - assert(confined_pointer == cs->zwp_confined_pointer); + test_assert_ptr_eq(confined_pointer, cs->zwp_confined_pointer); cs->pointer_is_confined = false; } @@ -173,7 +174,7 @@ constraints_init(struct constraints *cs, struct client *client) cs->zwp_pointer_constraints = bind_to_singleton_global(client, &zwp_pointer_constraints_v1_interface, 1); - assert(cs->zwp_pointer_constraints); + test_assert_ptr_not_null(cs->zwp_pointer_constraints); } static void @@ -208,25 +209,25 @@ TEST(constraints_events) /* receive confined events for oneshot lifetime */ confine_pointer(&cs, client, &confined_pointer_listener, NULL, ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ONESHOT); - assert(cs.pointer_is_confined); + test_assert_true(cs.pointer_is_confined); confine_destroy(&cs, client); /* receive confined events for persistent lifetime */ confine_pointer(&cs, client, &confined_pointer_listener, NULL, ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_PERSISTENT); - assert(cs.pointer_is_confined); + test_assert_true(cs.pointer_is_confined); confine_destroy(&cs, client); /* receive locked events for oneshot lifetime */ lock_pointer(&cs, client, &locked_pointer_listener, NULL, ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ONESHOT); - assert(cs.pointer_is_locked); + test_assert_true(cs.pointer_is_locked); lock_destroy(&cs, client); /* receive locked events for persistent lifetime */ lock_pointer(&cs, client, &locked_pointer_listener, NULL, ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_PERSISTENT); - assert(cs.pointer_is_locked); + test_assert_true(cs.pointer_is_locked); lock_destroy(&cs, client); constraint_deinit(&cs); @@ -248,40 +249,40 @@ TEST(constraints_confined_boundaries_input_region) /* confine to whole surface */ confine_pointer(&cs, client, &confined_pointer_listener, NULL, ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ONESHOT); - assert(cs.pointer_is_confined); + test_assert_true(cs.pointer_is_confined); /* move to boundary */ move_pointer(client, 100, 100); /* x-1 (outside boundary) */ move_pointer(client, client->surface->x-1, client->surface->y); - assert(client->input->pointer->focus == client->surface); - assert(client->test->pointer_x == client->surface->x); + test_assert_ptr_eq(client->input->pointer->focus, client->surface); + test_assert_int_eq(client->test->pointer_x, client->surface->x); /* y-1 (outside boundary) */ move_pointer(client, client->surface->x, client->surface->y-1); - assert(client->input->pointer->focus == client->surface); - assert(client->test->pointer_y == client->surface->y); + test_assert_ptr_eq(client->input->pointer->focus, client->surface); + test_assert_int_eq(client->test->pointer_y, client->surface->y); /* x+width (outside boundary) */ move_pointer(client, client->surface->x+client->surface->width, client->surface->y); - assert(client->input->pointer->focus == client->surface); - assert(client->test->pointer_x == - client->surface->x+client->surface->width-1); + test_assert_ptr_eq(client->input->pointer->focus, client->surface); + test_assert_int_eq(client->test->pointer_x, + client->surface->x+client->surface->width-1); /* y+height (outside boundary) */ move_pointer(client, client->surface->x, client->surface->y+client->surface->height); - assert(client->input->pointer->focus == client->surface); - assert(client->test->pointer_y == - client->surface->y+client->surface->height-1); + test_assert_ptr_eq(client->input->pointer->focus, client->surface); + test_assert_int_eq(client->test->pointer_y, + client->surface->y+client->surface->height-1); confine_destroy(&cs, client); /* x-1 (after unconfinement) */ move_pointer(client, client->surface->x-1, client->surface->y); - assert(client->input->pointer->focus != client->surface); - assert(client->test->pointer_x == client->surface->x-1); + test_assert_ptr_ne(client->input->pointer->focus, client->surface); + test_assert_int_eq(client->test->pointer_x, client->surface->x-1); constraint_deinit(&cs); client_destroy(client); @@ -301,23 +302,23 @@ TEST(constraints_locked_boundaries_input_region) lock_pointer(&cs, client, &locked_pointer_listener, NULL, ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ONESHOT); - assert(cs.pointer_is_locked); + test_assert_true(cs.pointer_is_locked); /* x-1 (outside surface) */ move_pointer(client, client->surface->x-1, client->surface->y); - assert(client->input->pointer->focus == client->surface); - assert(client->test->pointer_x == client->surface->x); + test_assert_ptr_eq(client->input->pointer->focus, client->surface); + test_assert_int_eq(client->test->pointer_x, client->surface->x); /* x+1 (inside surface) */ move_pointer(client, client->surface->x+1, client->surface->y); - assert(client->input->pointer->focus == client->surface); - assert(client->test->pointer_x == client->surface->x); + test_assert_ptr_eq(client->input->pointer->focus, client->surface); + test_assert_int_eq(client->test->pointer_x, client->surface->x); lock_destroy(&cs, client); /* x-1 (after unlocking) */ move_pointer(client, client->surface->x-1, client->surface->y); - assert(client->input->pointer->focus != client->surface); - assert(client->test->pointer_x == client->surface->x-1); + test_assert_ptr_ne(client->input->pointer->focus, client->surface); + test_assert_int_eq(client->test->pointer_x, client->surface->x-1); constraint_deinit(&cs); client_destroy(client); @@ -338,7 +339,7 @@ TEST(constraints_already_constrained) /* try to lock an already confined pointer */ confine_pointer(&cs, client, &confined_pointer_listener, NULL, ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ONESHOT); - assert(cs.pointer_is_confined); + test_assert_true(cs.pointer_is_confined); cs.zwp_locked_pointer = zwp_pointer_constraints_v1_lock_pointer(cs.zwp_pointer_constraints, client->surface->wl_surface, @@ -362,7 +363,7 @@ TEST(constraints_already_constrained) /* try to confine an already locked pointer */ lock_pointer(&cs, client, &locked_pointer_listener, NULL, ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ONESHOT); - assert(cs.pointer_is_locked); + test_assert_true(cs.pointer_is_locked); cs.zwp_confined_pointer = zwp_pointer_constraints_v1_confine_pointer(cs.zwp_pointer_constraints, client->surface->wl_surface, @@ -396,7 +397,7 @@ TEST(constraints_shell_activate_input) confine_pointer(&cs, client, &confined_pointer_listener, NULL, ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ONESHOT); - assert(!cs.pointer_is_confined); + test_assert_false(cs.pointer_is_confined); /* * This mimics the desktop shell when activating input for the view in @@ -405,12 +406,12 @@ TEST(constraints_shell_activate_input) weston_test_activate_surface(client->test->weston_test, client->surface->wl_surface); client_roundtrip(client); - assert(!cs.pointer_is_confined); + test_assert_false(cs.pointer_is_confined); /* activation that comes from clicking inside the surface */ click_pointer(client); client_roundtrip(client); - assert(cs.pointer_is_confined); + test_assert_true(cs.pointer_is_confined); constraint_deinit(&cs); client_destroy(client); @@ -426,7 +427,7 @@ TEST(constraints_pointer_focus) confine_pointer(&cs, client, &confined_pointer_listener, NULL, ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ONESHOT); - assert(!cs.pointer_is_confined); + test_assert_false(cs.pointer_is_confined); /* focus out */ move_pointer(client, 0, 0); @@ -434,15 +435,15 @@ TEST(constraints_pointer_focus) /* focus in: should not confine */ move_pointer(client, 150, 150); client_roundtrip(client); - assert(!cs.pointer_is_confined); + test_assert_false(cs.pointer_is_confined); /* confine */ click_pointer(client); - assert(cs.pointer_is_confined); + test_assert_true(cs.pointer_is_confined); /* focus out: should not unconfine */ move_pointer(client, 0, 0); - assert(cs.pointer_is_confined); + test_assert_true(cs.pointer_is_confined); constraint_deinit(&cs); client_destroy(client); diff --git a/tests/custom-env-test.c b/tests/custom-env-test.c index 3a5161907..12894e8b8 100644 --- a/tests/custom-env-test.c +++ b/tests/custom-env-test.c @@ -25,7 +25,6 @@ #include "config.h" -#include #include #include #include @@ -39,12 +38,13 @@ #include "shared/string-helpers.h" #include "weston-test-runner.h" +#include "weston-test-assert.h" #define ASSERT_STR_MATCH(_as, _bs) do { \ const char *as = _as; \ const char *bs = _bs; \ - assert(!!as == !!bs); \ - assert(!as || strcmp(as, bs) == 0); \ + test_assert_true(!!as == !!bs); \ + test_assert_true(!as || strcmp(as, bs) == 0); \ } while (0) #define ASSERT_STR_ARRAY_MATCH(_name, _aa, _ba) do { \ @@ -84,7 +84,7 @@ TEST(basic_env) custom_env_set_env_var(&env, "ENV5", "five"); custom_env_set_env_var(&env, "ENV3", "four"); ASSERT_STR_ARRAY_MATCH("envp", custom_env_get_envp(&env), envp); - assert(env.env_finalized); + test_assert_true(env.env_finalized); custom_env_fini(&env); } @@ -99,9 +99,9 @@ TEST(basic_env_arg) custom_env_add_arg(&env, "arg3"); ASSERT_STR_ARRAY_MATCH("envp", custom_env_get_envp(&env), DEFAULT_ENVP); - assert(env.env_finalized); + test_assert_true(env.env_finalized); ASSERT_STR_ARRAY_MATCH("argp", custom_env_get_argp(&env), argp); - assert(env.arg_finalized); + test_assert_true(env.arg_finalized); custom_env_fini(&env); } diff --git a/tests/devices-test.c b/tests/devices-test.c index 311451c2e..92dbf1101 100644 --- a/tests/devices-test.c +++ b/tests/devices-test.c @@ -28,6 +28,7 @@ #include #include "weston-test-client-helper.h" #include "weston-test-fixture-compositor.h" +#include "weston-test-assert.h" static enum test_result_code fixture_setup(struct weston_test_harness *harness) @@ -60,25 +61,25 @@ DECLARE_FIXTURE_SETUP(fixture_setup); TEST(seat_capabilities_test) { struct client *cl = create_client_and_test_surface(100, 100, 100, 100); - assert(cl->input->caps == WL_SEAT_CAPABILITY_ALL); + test_assert_enum(cl->input->caps, WL_SEAT_CAPABILITY_ALL); - assert(cl->input->pointer); + test_assert_ptr_not_null(cl->input->pointer); weston_test_device_release(cl->test->weston_test, "pointer"); client_roundtrip(cl); - assert(!cl->input->pointer); - assert(!(cl->input->caps & WL_SEAT_CAPABILITY_POINTER)); + test_assert_ptr_null(cl->input->pointer); + test_assert_bit_not_set(cl->input->caps, WL_SEAT_CAPABILITY_POINTER); - assert(cl->input->keyboard); + test_assert_ptr_not_null(cl->input->keyboard); weston_test_device_release(cl->test->weston_test, "keyboard"); client_roundtrip(cl); - assert(!cl->input->keyboard); - assert(!(cl->input->caps & WL_SEAT_CAPABILITY_KEYBOARD)); + test_assert_ptr_null(cl->input->keyboard); + test_assert_bit_not_set(cl->input->caps, WL_SEAT_CAPABILITY_KEYBOARD); - assert(cl->input->touch); + test_assert_ptr_not_null(cl->input->touch); weston_test_device_release(cl->test->weston_test, "touch"); client_roundtrip(cl); - assert(!cl->input->touch); - assert(!(cl->input->caps & WL_SEAT_CAPABILITY_TOUCH)); + test_assert_ptr_null(cl->input->touch); + test_assert_bit_not_set(cl->input->caps, WL_SEAT_CAPABILITY_TOUCH); /* restore previous state */ weston_test_device_add(cl->test->weston_test, "keyboard"); @@ -86,9 +87,9 @@ TEST(seat_capabilities_test) weston_test_device_add(cl->test->weston_test, "touch"); client_roundtrip(cl); - assert(cl->input->pointer); - assert(cl->input->keyboard); - assert(cl->input->touch); + test_assert_ptr_not_null(cl->input->pointer); + test_assert_ptr_not_null(cl->input->keyboard); + test_assert_ptr_not_null(cl->input->touch); /* add extra devices */ weston_test_device_add(cl->test->weston_test, "keyboard"); @@ -104,11 +105,11 @@ TEST(seat_capabilities_test) /* we still should have all the capabilities, since the devices * were doubled */ - assert(cl->input->caps == WL_SEAT_CAPABILITY_ALL); + test_assert_enum(cl->input->caps, WL_SEAT_CAPABILITY_ALL); - assert(cl->input->pointer); - assert(cl->input->keyboard); - assert(cl->input->touch); + test_assert_ptr_not_null(cl->input->pointer); + test_assert_ptr_not_null(cl->input->keyboard); + test_assert_ptr_not_null(cl->input->touch); client_destroy(cl); } @@ -128,11 +129,11 @@ TEST(multiple_device_add_and_remove) client_roundtrip(cl); - assert(cl->input->pointer); - assert(cl->input->keyboard); - assert(cl->input->touch); + test_assert_ptr_not_null(cl->input->pointer); + test_assert_ptr_not_null(cl->input->keyboard); + test_assert_ptr_not_null(cl->input->touch); - assert(cl->input->caps == WL_SEAT_CAPABILITY_ALL); + test_assert_enum(cl->input->caps, WL_SEAT_CAPABILITY_ALL); /* release all new devices */ for (i = 0; i < COUNT; ++i) { @@ -144,11 +145,11 @@ TEST(multiple_device_add_and_remove) client_roundtrip(cl); /* there is still one from each device left */ - assert(cl->input->caps == WL_SEAT_CAPABILITY_ALL); + test_assert_enum(cl->input->caps, WL_SEAT_CAPABILITY_ALL); - assert(cl->input->pointer); - assert(cl->input->keyboard); - assert(cl->input->touch); + test_assert_ptr_not_null(cl->input->pointer); + test_assert_ptr_not_null(cl->input->keyboard); + test_assert_ptr_not_null(cl->input->touch); client_destroy(cl); } @@ -180,7 +181,7 @@ device_release_before_destroy(void) weston_test_device_release(cl->test->weston_test, "touch"); client_roundtrip(cl); - assert(cl->input->caps == 0); + test_assert_enum(cl->input->caps, 0); /* restore previous state */ weston_test_device_add(cl->test->weston_test, "pointer"); @@ -188,7 +189,7 @@ device_release_before_destroy(void) weston_test_device_add(cl->test->weston_test, "touch"); client_roundtrip(cl); - assert(cl->input->caps == WL_SEAT_CAPABILITY_ALL); + test_assert_enum(cl->input->caps, WL_SEAT_CAPABILITY_ALL); client_destroy(cl); } @@ -229,7 +230,7 @@ device_release_after_destroy(void) client_roundtrip(cl); - assert(cl->input->caps == 0); + test_assert_enum(cl->input->caps, 0); /* restore previous state */ weston_test_device_add(cl->test->weston_test, "pointer"); @@ -237,7 +238,7 @@ device_release_after_destroy(void) weston_test_device_add(cl->test->weston_test, "touch"); client_roundtrip(cl); - assert(cl->input->caps == WL_SEAT_CAPABILITY_ALL); + test_assert_enum(cl->input->caps, WL_SEAT_CAPABILITY_ALL); client_destroy(cl); } @@ -283,7 +284,7 @@ get_device_after_destroy(void) * exactly simulate our situation */ weston_test_device_release(cl->test->weston_test, "pointer"); wl_pointer = wl_seat_get_pointer(cl->input->wl_seat); - assert(wl_pointer); + test_assert_ptr_not_null(wl_pointer); /* this should be ignored */ wl_pointer_set_cursor(wl_pointer, 0, NULL, 0, 0); @@ -294,13 +295,13 @@ get_device_after_destroy(void) weston_test_device_release(cl->test->weston_test, "keyboard"); wl_keyboard = wl_seat_get_keyboard(cl->input->wl_seat); - assert(wl_keyboard); + test_assert_ptr_not_null(wl_keyboard); wl_keyboard_release(wl_keyboard); client_roundtrip(cl); weston_test_device_release(cl->test->weston_test, "touch"); wl_touch = wl_seat_get_touch(cl->input->wl_seat); - assert(wl_touch); + test_assert_ptr_not_null(wl_touch); wl_touch_release(wl_touch); client_roundtrip(cl); @@ -310,7 +311,7 @@ get_device_after_destroy(void) weston_test_device_add(cl->test->weston_test, "touch"); client_roundtrip(cl); - assert(cl->input->caps == WL_SEAT_CAPABILITY_ALL); + test_assert_enum(cl->input->caps, WL_SEAT_CAPABILITY_ALL); client_destroy(cl); } @@ -332,7 +333,7 @@ TEST(seats_have_names) struct input *input; wl_list_for_each(input, &cl->inputs, link) { - assert(input->seat_name); + test_assert_ptr_not_null(input->seat_name); } client_destroy(cl); @@ -346,7 +347,7 @@ TEST(seat_destroy_and_recreate) /* Roundtrip to receive and handle the seat global removal event */ client_roundtrip(cl); - assert(!cl->input); + test_assert_ptr_null(cl->input); weston_test_device_add(cl->test->weston_test, "seat"); /* First roundtrip to send request and receive new seat global */ @@ -354,10 +355,10 @@ TEST(seat_destroy_and_recreate) /* Second roundtrip to handle seat events and set up input devices */ client_roundtrip(cl); - assert(cl->input); - assert(cl->input->pointer); - assert(cl->input->keyboard); - assert(cl->input->touch); + test_assert_ptr_not_null(cl->input); + test_assert_ptr_not_null(cl->input->pointer); + test_assert_ptr_not_null(cl->input->keyboard); + test_assert_ptr_not_null(cl->input->touch); client_destroy(cl); } diff --git a/tests/drm-formats-test.c b/tests/drm-formats-test.c index b4e4a17aa..7a463ac5e 100644 --- a/tests/drm-formats-test.c +++ b/tests/drm-formats-test.c @@ -25,14 +25,13 @@ #include "config.h" -#include - #include #include #include "shared/weston-drm-fourcc.h" #include "weston-test-client-helper.h" #include "weston-test-fixture-compositor.h" +#include "weston-test-assert.h" /* Add multiple formats to weston_drm_format_array and add the same set of * modifiers to each format. */ @@ -63,11 +62,11 @@ format_array_add_format_and_modifiers(struct weston_drm_format_array *formats, int ret; fmt = weston_drm_format_array_add_format(formats, format); - assert(fmt); + test_assert_ptr_not_null(fmt); for (i = 0; i < num_modifiers; i++) { ret = weston_drm_format_add_modifier(fmt, modifiers[i]); - assert(ret == 0); + test_assert_int_eq(ret, 0); } } @@ -81,19 +80,20 @@ TEST(basic_operations) weston_drm_format_array_init(&format_array); - assert(weston_drm_format_array_count_pairs(&format_array) == 0); + test_assert_int_eq(weston_drm_format_array_count_pairs(&format_array), 0); ADD_FORMATS_AND_MODS(&format_array, formats, modifiers); for (i = 0; i < ARRAY_LENGTH(formats); i++) { fmt = weston_drm_format_array_find_format(&format_array, formats[i]); - assert(fmt && fmt->format == formats[i]); + test_assert_ptr_not_null(fmt); + test_assert_u32_eq(fmt->format, formats[i]); for (j = 0; j < ARRAY_LENGTH(modifiers); j++) - assert(weston_drm_format_has_modifier(fmt, modifiers[j])); + test_assert_true(weston_drm_format_has_modifier(fmt, modifiers[j])); } - assert(weston_drm_format_array_count_pairs(&format_array) == - ARRAY_LENGTH(formats) * ARRAY_LENGTH(modifiers)); + test_assert_uint_eq(weston_drm_format_array_count_pairs(&format_array), + ARRAY_LENGTH(formats) * ARRAY_LENGTH(modifiers)); weston_drm_format_array_fini(&format_array); } @@ -108,12 +108,12 @@ TEST(compare_arrays_same_content) weston_drm_format_array_init(&format_array_B); /* Both are empty arrays, so they have the same content. */ - assert(weston_drm_format_array_equal(&format_array_A, &format_array_B)); + test_assert_true(weston_drm_format_array_equal(&format_array_A, &format_array_B)); /* Test non-empty arrays with same content. */ ADD_FORMATS_AND_MODS(&format_array_A, formats, modifiers); ADD_FORMATS_AND_MODS(&format_array_B, formats, modifiers); - assert(weston_drm_format_array_equal(&format_array_A, &format_array_B)); + test_assert_true(weston_drm_format_array_equal(&format_array_A, &format_array_B)); /* Test non-empty arrays with same content, but add elements to B in * reverse order. This is important as in the future we may keep @@ -121,7 +121,7 @@ TEST(compare_arrays_same_content) weston_drm_format_array_fini(&format_array_B); weston_drm_format_array_init(&format_array_B); ADD_FORMATS_AND_MODS_REVERSE(&format_array_B, formats, modifiers); - assert(weston_drm_format_array_equal(&format_array_A, &format_array_B)); + test_assert_true(weston_drm_format_array_equal(&format_array_A, &format_array_B)); weston_drm_format_array_fini(&format_array_A); weston_drm_format_array_fini(&format_array_B); @@ -141,7 +141,8 @@ TEST(compare_arrays_exclusive_content) /* Arrays with formats that are mutually exclusive. */ ADD_FORMATS_AND_MODS(&format_array_A, formats_A, modifiers_A); ADD_FORMATS_AND_MODS(&format_array_B, formats_B, modifiers_B); - assert(!weston_drm_format_array_equal(&format_array_A, &format_array_B)); + test_assert_false(weston_drm_format_array_equal(&format_array_A, + &format_array_B)); weston_drm_format_array_fini(&format_array_A); weston_drm_format_array_fini(&format_array_B); @@ -161,8 +162,8 @@ TEST(replace_array) * have the same content. */ ADD_FORMATS_AND_MODS(&format_array_A, formats, modifiers); ret = weston_drm_format_array_replace(&format_array_B, &format_array_A); - assert(ret == 0); - assert(weston_drm_format_array_equal(&format_array_A, &format_array_B)); + test_assert_int_eq(ret, 0); + test_assert_true(weston_drm_format_array_equal(&format_array_A, &format_array_B)); weston_drm_format_array_fini(&format_array_A); weston_drm_format_array_fini(&format_array_B); @@ -185,12 +186,12 @@ TEST(remove_from_array) ADD_FORMATS_AND_MODS(&format_array_A, formats_A, modifiers); ADD_FORMATS_AND_MODS(&format_array_B, formats_B, modifiers); weston_drm_format_array_remove_latest_format(&format_array_A); - assert(weston_drm_format_array_equal(&format_array_A, &format_array_B)); + test_assert_true(weston_drm_format_array_equal(&format_array_A, &format_array_B)); /* Add 6 to the format array A, so it should be equal to C. */ ADD_FORMATS_AND_MODS(&format_array_A, (uint32_t[]){6}, modifiers); ADD_FORMATS_AND_MODS(&format_array_C, formats_C, modifiers); - assert(weston_drm_format_array_equal(&format_array_A, &format_array_C)); + test_assert_true(weston_drm_format_array_equal(&format_array_A, &format_array_C)); weston_drm_format_array_fini(&format_array_A); weston_drm_format_array_fini(&format_array_B); @@ -215,7 +216,7 @@ TEST(join_arrays) ADD_FORMATS_AND_MODS(&format_array_A, formats_A, modifiers_A); ADD_FORMATS_AND_MODS(&format_array_B, formats_B, modifiers_B); ret = weston_drm_format_array_join(&format_array_A, &format_array_B); - assert(ret == 0); + test_assert_int_eq(ret, 0); /* The result of the joint (which is saved in A) should have * the same content as C. */ @@ -226,7 +227,7 @@ TEST(join_arrays) ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){7}, modifiers_B); ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){9}, modifiers_join); ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){10}, modifiers_join); - assert(weston_drm_format_array_equal(&format_array_A, &format_array_C)); + test_assert_true(weston_drm_format_array_equal(&format_array_A, &format_array_C)); weston_drm_format_array_fini(&format_array_A); weston_drm_format_array_fini(&format_array_B); @@ -245,21 +246,21 @@ TEST(join_arrays_same_content) /* Joint of empty arrays must be empty. */ ret = weston_drm_format_array_join(&format_array_A, &format_array_B); - assert(ret == 0); - assert(format_array_A.arr.size == 0); + test_assert_int_eq(ret, 0); + test_assert_u64_eq(format_array_A.arr.size, 0); /* Join B, which is empty, with A, which is non-empty. The joint (which * is saved in B) should have the same content as A. */ ADD_FORMATS_AND_MODS(&format_array_A, formats, modifiers); ret = weston_drm_format_array_join(&format_array_B, &format_array_A); - assert(ret == 0); - assert(weston_drm_format_array_equal(&format_array_A, &format_array_B)); + test_assert_int_eq(ret, 0); + test_assert_true(weston_drm_format_array_equal(&format_array_A, &format_array_B)); /* Now A and B are non-empty and have the same content. The joint (which * is saved in A) should not change its content. */ ret = weston_drm_format_array_join(&format_array_A, &format_array_B); - assert(ret == 0); - assert(weston_drm_format_array_equal(&format_array_A, &format_array_B)); + test_assert_int_eq(ret, 0); + test_assert_true(weston_drm_format_array_equal(&format_array_A, &format_array_B)); weston_drm_format_array_fini(&format_array_A); weston_drm_format_array_fini(&format_array_B); @@ -284,8 +285,8 @@ TEST(join_arrays_exclusive_content) ADD_FORMATS_AND_MODS(&format_array_B, formats_B, modifiers); ADD_FORMATS_AND_MODS(&format_array_C, formats_C, modifiers); ret = weston_drm_format_array_join(&format_array_A, &format_array_B); - assert(ret == 0); - assert(weston_drm_format_array_equal(&format_array_A, &format_array_C)); + test_assert_int_eq(ret, 0); + test_assert_true(weston_drm_format_array_equal(&format_array_A, &format_array_C)); weston_drm_format_array_fini(&format_array_A); weston_drm_format_array_fini(&format_array_B); @@ -312,8 +313,8 @@ TEST(join_arrays_modifier_invalid) ADD_FORMATS_AND_MODS(&format_array_B, (uint32_t[]){1}, regular_modifiers); ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){1}, regular_modifiers_plus_invalid); ret = weston_drm_format_array_join(&format_array_A, &format_array_B); - assert(ret == 0); - assert(weston_drm_format_array_equal(&format_array_A, &format_array_C)); + test_assert_int_eq(ret, 0); + test_assert_true(weston_drm_format_array_equal(&format_array_A, &format_array_C)); weston_drm_format_array_fini(&format_array_A); weston_drm_format_array_fini(&format_array_B); @@ -338,14 +339,14 @@ TEST(intersect_arrays) ADD_FORMATS_AND_MODS(&format_array_A, formats_A, modifiers_A); ADD_FORMATS_AND_MODS(&format_array_B, formats_B, modifiers_B); ret = weston_drm_format_array_intersect(&format_array_A, &format_array_B); - assert(ret == 0); + test_assert_int_eq(ret, 0); /* The result of the intersection (stored in A) should have the same * content as C. */ ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){2}, modifiers_intersect); ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){9}, modifiers_intersect); ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){10}, modifiers_intersect); - assert(weston_drm_format_array_equal(&format_array_A, &format_array_C)); + test_assert_true(weston_drm_format_array_equal(&format_array_A, &format_array_C)); weston_drm_format_array_fini(&format_array_A); weston_drm_format_array_fini(&format_array_B); @@ -365,18 +366,18 @@ TEST(intersect_arrays_same_content) /* The intersection between two empty arrays must be an * empty array. */ ret = weston_drm_format_array_intersect(&format_array_A, &format_array_B); - assert(ret == 0); - assert(format_array_A.arr.size == 0); + test_assert_int_eq(ret, 0); + test_assert_u64_eq(format_array_A.arr.size, 0); /* DRM-format arrays A and B have the same content, so the intersection * should be equal to them. A keeps the result of the intersection, and B * does not change. So we compare them. */ ADD_FORMATS_AND_MODS(&format_array_A, formats, modifiers); ret = weston_drm_format_array_replace(&format_array_B, &format_array_A); - assert(ret == 0); + test_assert_int_eq(ret, 0); ret = weston_drm_format_array_intersect(&format_array_A, &format_array_B); - assert(ret == 0); - assert(weston_drm_format_array_equal(&format_array_A, &format_array_B)); + test_assert_int_eq(ret, 0); + test_assert_true(weston_drm_format_array_equal(&format_array_A, &format_array_B)); weston_drm_format_array_fini(&format_array_A); weston_drm_format_array_fini(&format_array_B); @@ -398,8 +399,8 @@ TEST(intersect_arrays_exclusive_formats) ADD_FORMATS_AND_MODS(&format_array_A, formats_A, modifiers); ADD_FORMATS_AND_MODS(&format_array_B, formats_B, modifiers); ret = weston_drm_format_array_intersect(&format_array_A, &format_array_B); - assert(ret == 0); - assert(format_array_A.arr.size == 0); + test_assert_int_eq(ret, 0); + test_assert_u64_eq(format_array_A.arr.size, 0); weston_drm_format_array_fini(&format_array_A); weston_drm_format_array_fini(&format_array_B); @@ -423,8 +424,8 @@ TEST(intersect_arrays_exclusive_modifiers) ADD_FORMATS_AND_MODS(&format_array_A, (uint32_t[]){1}, modifiers_A); ADD_FORMATS_AND_MODS(&format_array_B, (uint32_t[]){1}, modifiers_B); ret = weston_drm_format_array_intersect(&format_array_A, &format_array_B); - assert(ret == 0); - assert(format_array_A.arr.size == 0); + test_assert_int_eq(ret, 0); + test_assert_u64_eq(format_array_A.arr.size, 0); weston_drm_format_array_fini(&format_array_A); weston_drm_format_array_fini(&format_array_B); @@ -448,7 +449,7 @@ TEST(subtract_arrays) ADD_FORMATS_AND_MODS(&format_array_A, formats_A, modifiers_A); ADD_FORMATS_AND_MODS(&format_array_B, formats_B, modifiers_B); ret = weston_drm_format_array_subtract(&format_array_A, &format_array_B); - assert(ret == 0); + test_assert_int_eq(ret, 0); /* The result of the subtraction (which is saved in A) should have * the same content as C. */ @@ -457,7 +458,7 @@ TEST(subtract_arrays) ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){6}, modifiers_A); ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){9}, modifiers_subtract); ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){10}, modifiers_subtract); - assert(weston_drm_format_array_equal(&format_array_A, &format_array_C)); + test_assert_true(weston_drm_format_array_equal(&format_array_A, &format_array_C)); weston_drm_format_array_fini(&format_array_A); weston_drm_format_array_fini(&format_array_B); @@ -478,10 +479,10 @@ TEST(subtract_arrays_same_content) * (which is saved in A) should be an empty array. */ ADD_FORMATS_AND_MODS(&format_array_A, formats, modifiers); ret = weston_drm_format_array_replace(&format_array_B, &format_array_A); - assert(ret == 0); + test_assert_int_eq(ret, 0); ret = weston_drm_format_array_subtract(&format_array_A, &format_array_B); - assert(ret == 0); - assert(format_array_A.arr.size == 0); + test_assert_int_eq(ret, 0); + test_assert_u64_eq(format_array_A.arr.size, 0); weston_drm_format_array_fini(&format_array_A); weston_drm_format_array_fini(&format_array_B); @@ -505,11 +506,11 @@ TEST(subtract_arrays_exclusive_formats) ADD_FORMATS_AND_MODS(&format_array_A, formats_A, modifiers); ADD_FORMATS_AND_MODS(&format_array_B, formats_B, modifiers); ret = weston_drm_format_array_replace(&format_array_C, &format_array_A); - assert(ret == 0); + test_assert_int_eq(ret, 0); ret = weston_drm_format_array_subtract(&format_array_A, &format_array_B); - assert(ret == 0); - assert(weston_drm_format_array_equal(&format_array_A, &format_array_C)); + test_assert_int_eq(ret, 0); + test_assert_true(weston_drm_format_array_equal(&format_array_A, &format_array_C)); weston_drm_format_array_fini(&format_array_A); weston_drm_format_array_fini(&format_array_B); @@ -534,11 +535,11 @@ TEST(subtract_arrays_exclusive_modifiers) ADD_FORMATS_AND_MODS(&format_array_A, (uint32_t[]){1}, modifiers_A); ADD_FORMATS_AND_MODS(&format_array_B, (uint32_t[]){1}, modifiers_B); ret = weston_drm_format_array_replace(&format_array_C, &format_array_A); - assert(ret == 0); + test_assert_int_eq(ret, 0); ret = weston_drm_format_array_subtract(&format_array_A, &format_array_B); - assert(ret == 0); - assert(weston_drm_format_array_equal(&format_array_A, &format_array_C)); + test_assert_int_eq(ret, 0); + test_assert_true(weston_drm_format_array_equal(&format_array_A, &format_array_C)); weston_drm_format_array_fini(&format_array_A); weston_drm_format_array_fini(&format_array_B); @@ -564,8 +565,8 @@ TEST(subtract_arrays_modifier_invalid) ADD_FORMATS_AND_MODS(&format_array_A, (uint32_t[]){1}, modifier_invalid); ADD_FORMATS_AND_MODS(&format_array_B, (uint32_t[]){1}, regular_modifiers_plus_invalid); ret = weston_drm_format_array_subtract(&format_array_A, &format_array_B); - assert(ret == 0); - assert(format_array_A.arr.size == 0); + test_assert_int_eq(ret, 0); + test_assert_u64_eq(format_array_A.arr.size, 0); weston_drm_format_array_fini(&format_array_A); weston_drm_format_array_fini(&format_array_B); diff --git a/tests/drm-smoke-test.c b/tests/drm-smoke-test.c index c662afddb..3357e0daf 100644 --- a/tests/drm-smoke-test.c +++ b/tests/drm-smoke-test.c @@ -27,6 +27,7 @@ #include "weston-test-client-helper.h" #include "weston-test-fixture-compositor.h" +#include "weston-test-assert.h" static enum test_result_code fixture_setup(struct weston_test_harness *harness) @@ -53,7 +54,7 @@ TEST(drm_smoke) { color_rgb888(&red, 255, 0, 0); client = create_client_and_test_surface(0, 0, 200, 200); - assert(client); + test_assert_ptr_not_null(client); surface = client->surface->wl_surface; buffer = create_shm_buffer_a8r8g8b8(client, 200, 200); @@ -78,7 +79,7 @@ TEST(drm_screenshot_no_damage) { bool ret; client = create_client_and_test_surface(0, 0, 200, 200); - assert(client); + test_assert_ptr_not_null(client); /* * DRM-backend has an optimization to not even call the renderer if @@ -92,7 +93,7 @@ TEST(drm_screenshot_no_damage) { for (i = 0; i < 5; i++) { ret = verify_screen_content(client, "drm_screenshot_no_damage", 0, NULL, i, "Virtual-1"); - assert(ret); + test_assert_true(ret); } client_destroy(client); diff --git a/tests/drm-writeback-screenshot-test.c b/tests/drm-writeback-screenshot-test.c index 8a261ecf3..06106a43f 100644 --- a/tests/drm-writeback-screenshot-test.c +++ b/tests/drm-writeback-screenshot-test.c @@ -28,6 +28,7 @@ #include "weston-test-client-helper.h" #include "weston-test-fixture-compositor.h" #include "weston-output-capture-client-protocol.h" +#include "weston-test-assert.h" static enum test_result_code fixture_setup(struct weston_test_harness *harness) @@ -65,7 +66,7 @@ draw_stuff(pixman_image_t *image) stride = pixman_image_get_stride(image); pixels = pixman_image_get_data(image); - assert(PIXMAN_FORMAT_BPP(fmt) == 32); + test_assert_int_eq(PIXMAN_FORMAT_BPP(fmt), 32); for (x = 0; x < w; x++) for (y = 0; y < h; y++) { @@ -93,7 +94,7 @@ TEST(drm_writeback_screenshot) { /* create client */ testlog("Creating client for test\n"); client = create_client_and_test_surface(100, 100, 100, 100); - assert(client); + test_assert_ptr_not_null(client); surface = client->surface->wl_surface; /* move pointer away from image so it does not interfere with the @@ -113,7 +114,7 @@ TEST(drm_writeback_screenshot) { testlog("Taking a screenshot\n"); screenshot = client_capture_output(client, client->output, WESTON_CAPTURE_V1_SOURCE_WRITEBACK); - assert(screenshot); + test_assert_ptr_not_null(screenshot); buffer_destroy(screenshot); /* take another screenshot; this is important to ensure the @@ -121,13 +122,13 @@ TEST(drm_writeback_screenshot) { testlog("Taking another screenshot\n"); screenshot = client_capture_output(client, client->output, WESTON_CAPTURE_V1_SOURCE_WRITEBACK); - assert(screenshot); + test_assert_ptr_not_null(screenshot); /* load reference image */ fname = screenshot_reference_filename("drm-writeback-screenshot", 0); testlog("Loading good reference image %s\n", fname); reference = load_image_from_png(fname); - assert(reference); + test_assert_ptr_not_null(reference); free(fname); /* check if they match - only the colored square matters, so the @@ -151,5 +152,5 @@ TEST(drm_writeback_screenshot) { buffer_destroy(buffer); client_destroy(client); - assert(match); + test_assert_true(match); } diff --git a/tests/event-test.c b/tests/event-test.c index 371162435..b3302be7a 100644 --- a/tests/event-test.c +++ b/tests/event-test.c @@ -28,6 +28,7 @@ #include "weston-test-client-helper.h" #include "weston-test-fixture-compositor.h" +#include "weston-test-assert.h" static enum test_result_code fixture_setup(struct weston_test_harness *harness) @@ -60,9 +61,9 @@ check_client_move(struct client *client, int x, int y) move_client_offscreenable(client, x, y); if (output_contains_client(client)) { - assert(client->surface->output == client->output); + test_assert_ptr_eq(client->surface->output, client->output); } else { - assert(client->surface->output == NULL); + test_assert_ptr_null(client->surface->output); } } @@ -72,9 +73,9 @@ TEST(test_surface_output) int x, y; client = create_client_and_test_surface(100, 100, 100, 100); - assert(client); + test_assert_ptr_not_null(client); - assert(output_contains_client(client)); + test_assert_true(output_contains_client(client)); /* not visible */ x = 0; @@ -99,17 +100,17 @@ TEST(test_surface_output) /* visible */ check_client_move(client, --x, y); - assert(output_contains_client(client)); + test_assert_true(output_contains_client(client)); /* not visible */ x = 0; y = client->output->height; check_client_move(client, x, y); - assert(!output_contains_client(client)); + test_assert_false(output_contains_client(client)); /* visible */ check_client_move(client, x, --y); - assert(output_contains_client(client)); + test_assert_true(output_contains_client(client)); client_destroy(client); } @@ -139,7 +140,7 @@ TEST(buffer_release) int frame; client = create_client_and_test_surface(100, 100, 100, 100); - assert(client); + test_assert_ptr_not_null(client); surface = client->surface->wl_surface; buf1 = create_shm_buffer_a8r8g8b8(client, 100, 100); @@ -161,25 +162,25 @@ TEST(buffer_release) frame_callback_set(surface, &frame); wl_surface_commit(surface); frame_callback_wait(client, &frame); - assert(buf1_released == 0); + test_assert_int_eq(buf1_released, 0); /* buf2 may or may not be released */ - assert(buf3_released == 0); + test_assert_int_eq(buf3_released, 0); wl_surface_attach(surface, buf3->proxy, 0, 0); frame_callback_set(surface, &frame); wl_surface_commit(surface); frame_callback_wait(client, &frame); - assert(buf1_released == 0); - assert(buf2_released == 1); + test_assert_int_eq(buf1_released, 0); + test_assert_int_eq(buf2_released, 1); /* buf3 may or may not be released */ wl_surface_attach(surface, client->surface->buffer->proxy, 0, 0); frame_callback_set(surface, &frame); wl_surface_commit(surface); frame_callback_wait(client, &frame); - assert(buf1_released == 0); - assert(buf2_released == 1); - assert(buf3_released == 1); + test_assert_int_eq(buf1_released, 0); + test_assert_int_eq(buf2_released, 1); + test_assert_int_eq(buf3_released, 1); buffer_destroy(buf1); buffer_destroy(buf2); diff --git a/tests/image-iter.h b/tests/image-iter.h index ab9b08303..572c10155 100644 --- a/tests/image-iter.h +++ b/tests/image-iter.h @@ -28,7 +28,8 @@ #include #include -#include + +#include "weston-test-assert.h" /** A collection of basic information extracted from a pixman_image_t */ struct image_header { @@ -67,9 +68,9 @@ image_header_from(pixman_image_t *image) static inline uint32_t * image_header_get_row_u32(const struct image_header *header, int y) { - assert(y >= 0); - assert(y < header->height); - assert(PIXMAN_FORMAT_BPP(header->pixman_format) == 32); + test_assert_int_ge(y, 0); + test_assert_int_lt(y, header->height); + test_assert_int_eq(PIXMAN_FORMAT_BPP(header->pixman_format), 32); return (uint32_t *)(header->data + y * header->stride_bytes); } diff --git a/tests/input-timestamps-helper.c b/tests/input-timestamps-helper.c index 05cafec44..a06257392 100644 --- a/tests/input-timestamps-helper.c +++ b/tests/input-timestamps-helper.c @@ -25,7 +25,6 @@ #include "config.h" -#include #include #include #include @@ -35,6 +34,7 @@ #include "shared/timespec-util.h" #include #include "weston-test-client-helper.h" +#include "weston-test-assert.h" struct input_timestamps { struct zwp_input_timestamps_v1 *proxy; @@ -51,18 +51,18 @@ get_input_timestamps_manager(struct client *client) if (strcmp(g->interface, zwp_input_timestamps_manager_v1_interface.name)) continue; - if (global_ts) - assert(!"Multiple input timestamp managers"); + /* Can't have multiple input timestamp managers. */ + test_assert_ptr_null(global_ts); global_ts = g; } - assert(global_ts); - assert(global_ts->version == 1); + test_assert_ptr_not_null(global_ts); + test_assert_u32_eq(global_ts->version, 1); ts = wl_registry_bind(client->wl_registry, global_ts->name, &zwp_input_timestamps_manager_v1_interface, 1); - assert(ts); + test_assert_ptr_not_null(ts); return ts; } @@ -97,12 +97,12 @@ input_timestamps_create_for_keyboard(struct client *client) struct input_timestamps *input_ts; input_ts = zalloc(sizeof *input_ts); - assert(input_ts); + test_assert_ptr_not_null(input_ts); input_ts->proxy = zwp_input_timestamps_manager_v1_get_keyboard_timestamps( manager, client->input->keyboard->wl_keyboard); - assert(input_ts->proxy); + test_assert_ptr_not_null(input_ts->proxy); zwp_input_timestamps_v1_add_listener(input_ts->proxy, &input_timestamps_listener, @@ -124,12 +124,12 @@ input_timestamps_create_for_pointer(struct client *client) struct input_timestamps *input_ts; input_ts = zalloc(sizeof *input_ts); - assert(input_ts); + test_assert_ptr_not_null(input_ts); input_ts->proxy = zwp_input_timestamps_manager_v1_get_pointer_timestamps( manager, client->input->pointer->wl_pointer); - assert(input_ts->proxy); + test_assert_ptr_not_null(input_ts->proxy); zwp_input_timestamps_v1_add_listener(input_ts->proxy, &input_timestamps_listener, @@ -151,12 +151,12 @@ input_timestamps_create_for_touch(struct client *client) struct input_timestamps *input_ts; input_ts = zalloc(sizeof *input_ts); - assert(input_ts); + test_assert_ptr_not_null(input_ts); input_ts->proxy = zwp_input_timestamps_manager_v1_get_touch_timestamps( manager, client->input->touch->wl_touch); - assert(input_ts->proxy); + test_assert_ptr_not_null(input_ts->proxy); zwp_input_timestamps_v1_add_listener(input_ts->proxy, &input_timestamps_listener, diff --git a/tests/internal-screenshot-test.c b/tests/internal-screenshot-test.c index 96236b9b2..7977ab386 100644 --- a/tests/internal-screenshot-test.c +++ b/tests/internal-screenshot-test.c @@ -30,6 +30,7 @@ #include "weston-test-client-helper.h" #include "weston-test-fixture-compositor.h" +#include "weston-test-assert.h" #include "image-iter.h" #include "test-config.h" @@ -90,7 +91,7 @@ TEST(internal_screenshot) /* Create the client */ testlog("Creating client for test\n"); client = create_client_and_test_surface(100, 100, 100, 100); - assert(client); + test_assert_ptr_not_null(client); surface = client->surface->wl_surface; /* @@ -120,20 +121,20 @@ TEST(internal_screenshot) /* Take a snapshot. Result will be in screenshot->wl_buffer. */ testlog("Taking a screenshot\n"); screenshot = capture_screenshot_of_output(client, NULL); - assert(screenshot); + test_assert_ptr_not_null(screenshot); /* Load good reference image */ fname = screenshot_reference_filename("internal-screenshot-good", 0); testlog("Loading good reference image %s\n", fname); reference_good = load_image_from_png(fname); - assert(reference_good); + test_assert_ptr_not_null(reference_good); free(fname); /* Load bad reference image */ fname = screenshot_reference_filename("internal-screenshot-bad", 0); testlog("Loading bad reference image %s\n", fname); reference_bad = load_image_from_png(fname); - assert(reference_bad); + test_assert_ptr_not_null(reference_bad); free(fname); /* Test check_images_match() without a clip. @@ -141,7 +142,7 @@ TEST(internal_screenshot) */ match = check_images_match(screenshot->image, reference_bad, NULL, NULL); testlog("Screenshot %s reference image\n", match? "equal to" : "different from"); - assert(!match); + test_assert_false(match); pixman_image_unref(reference_bad); /* Test check_images_match() with clip. @@ -174,7 +175,7 @@ TEST(internal_screenshot) buffer_destroy(screenshot); testlog("Test complete\n"); - assert(match); + test_assert_true(match); buffer_destroy(buf); client_destroy(client); diff --git a/tests/iterate-debug-scopes-test.c b/tests/iterate-debug-scopes-test.c index 82c6c5c8f..ae030be3c 100644 --- a/tests/iterate-debug-scopes-test.c +++ b/tests/iterate-debug-scopes-test.c @@ -25,7 +25,6 @@ #include "config.h" #include -#include #include #include #include @@ -33,7 +32,7 @@ #include #include "weston-test-client-helper.h" #include "weston-test-fixture-compositor.h" - +#include "weston-test-assert.h" static enum test_result_code fixture_setup(struct weston_test_harness *harness) @@ -63,10 +62,10 @@ iterate_debug_scopes(struct weston_compositor *compositor) const char *desc_name; scope_name = weston_log_scope_get_name(nscope); - assert(scope_name); + test_assert_ptr_not_null(scope_name); desc_name = weston_log_scope_get_description(nscope); - assert(desc_name); + test_assert_ptr_not_null(desc_name); weston_log("\tscope name: %s, desc: %s\n", scope_name, desc_name); @@ -75,7 +74,7 @@ iterate_debug_scopes(struct weston_compositor *compositor) } weston_log("\n"); - assert(found_test_harness_debug_scope); + test_assert_true(found_test_harness_debug_scope); } PLUGIN_TEST(iterate_default_debug_scopes) diff --git a/tests/ivi-layout-test-client.c b/tests/ivi-layout-test-client.c index b49701cc8..7af8a43b2 100644 --- a/tests/ivi-layout-test-client.c +++ b/tests/ivi-layout-test-client.c @@ -35,6 +35,7 @@ #include "ivi-application-client-protocol.h" #include "ivi-test.h" #include "weston-test-fixture-compositor.h" +#include "weston-test-assert.h" static enum test_result_code fixture_setup(struct weston_test_harness *harness) @@ -82,19 +83,19 @@ client_create_runner(struct client *client) continue; if (global_runner) - assert(0 && "multiple weston_test_runner objects"); + test_assert_not_reached("multiple weston_test_runner objects"); global_runner = g; } - assert(global_runner && "no weston_test_runner found"); - assert(global_runner->version == 1); + test_assert_ptr_not_null(global_runner); + test_assert_u32_eq(global_runner->version, 1); runner->test_runner = wl_registry_bind(client->wl_registry, global_runner->name, &weston_test_runner_interface, 1); - assert(runner->test_runner); + test_assert_ptr_not_null(runner->test_runner); weston_test_runner_add_listener(runner->test_runner, &test_runner_listener, runner); @@ -120,7 +121,7 @@ runner_run(struct runner *runner, const char *test_name) while (!runner->done) { if (wl_display_dispatch(runner->client->wl_display) < 0) - assert(0 && "runner wait"); + test_assert_not_reached("runner wait"); } } @@ -136,18 +137,18 @@ get_ivi_application(struct client *client) continue; if (global_iviapp) - assert(0 && "multiple ivi_application objects"); + test_assert_not_reached("multiple ivi_application objects"); global_iviapp = g; } - assert(global_iviapp && "no ivi_application found"); + test_assert_ptr_not_null(global_iviapp); - assert(global_iviapp->version == 1); + test_assert_u32_eq(global_iviapp->version, 1); iviapp = wl_registry_bind(client->wl_registry, global_iviapp->name, &ivi_application_interface, 1); - assert(iviapp); + test_assert_ptr_not_null(iviapp); return iviapp; } diff --git a/tests/ivi-shell-app-test.c b/tests/ivi-shell-app-test.c index 3420e8687..9346d31fd 100644 --- a/tests/ivi-shell-app-test.c +++ b/tests/ivi-shell-app-test.c @@ -31,6 +31,7 @@ #include "weston-test-client-helper.h" #include "ivi-application-client-protocol.h" #include "weston-test-fixture-compositor.h" +#include "weston-test-assert.h" #include "test-config.h" static enum test_result_code @@ -158,18 +159,19 @@ get_ivi_application(struct client *client) continue; if (global_iviapp) - assert(0 && "multiple ivi_application objects"); + test_assert_not_reached("multiple ivi_application objects"); global_iviapp = g; } - assert(global_iviapp && "no ivi_application found"); + /* No ivi_application found. */ + test_assert_ptr_not_null(global_iviapp); - assert(global_iviapp->version == 1); + test_assert_int_eq(global_iviapp->version, 1); iviapp = wl_registry_bind(client->wl_registry, global_iviapp->name, &ivi_application_interface, 1); - assert(iviapp); + test_assert_ptr_not_null(iviapp); return iviapp; } diff --git a/tests/keyboard-test.c b/tests/keyboard-test.c index 0f415a9af..9cb330801 100644 --- a/tests/keyboard-test.c +++ b/tests/keyboard-test.c @@ -31,6 +31,7 @@ #include "shared/timespec-util.h" #include "weston-test-client-helper.h" #include "weston-test-fixture-compositor.h" +#include "weston-test-assert.h" static enum test_result_code fixture_setup(struct weston_test_harness *harness) @@ -53,7 +54,7 @@ static struct client * create_client_with_keyboard_focus(void) { struct client *cl = create_client_and_test_surface(10, 10, 1, 1); - assert(cl); + test_assert_ptr_not_null(cl); weston_test_activate_surface(cl->test->weston_test, cl->surface->wl_surface); @@ -83,9 +84,9 @@ TEST(simple_keyboard_test) uint32_t expect_state = 0; while (1) { - assert(keyboard->key == expect_key); - assert(keyboard->state == expect_state); - assert(keyboard->focus == expect_focus); + test_assert_u32_eq(keyboard->key, expect_key); + test_assert_u32_eq(keyboard->state, expect_state); + test_assert_ptr_eq(keyboard->focus, expect_focus); if (keyboard->state == WL_KEYBOARD_KEY_STATE_PRESSED) { expect_state = WL_KEYBOARD_KEY_STATE_RELEASED; @@ -119,12 +120,12 @@ TEST(keyboard_key_event_time) input_timestamps_create_for_keyboard(client); send_key(client, &t1, 1, WL_KEYBOARD_KEY_STATE_PRESSED); - assert(keyboard->key_time_msec == timespec_to_msec(&t1)); - assert(timespec_eq(&keyboard->key_time_timespec, &t1)); + test_assert_s64_eq(keyboard->key_time_msec, timespec_to_msec(&t1)); + test_assert_true(timespec_eq(&keyboard->key_time_timespec, &t1)); send_key(client, &t2, 1, WL_KEYBOARD_KEY_STATE_RELEASED); - assert(keyboard->key_time_msec == timespec_to_msec(&t2)); - assert(timespec_eq(&keyboard->key_time_timespec, &t2)); + test_assert_s64_eq(keyboard->key_time_msec, timespec_to_msec(&t2)); + test_assert_true(timespec_eq(&keyboard->key_time_timespec, &t2)); input_timestamps_destroy(input_ts); @@ -139,14 +140,14 @@ TEST(keyboard_timestamps_stop_after_input_timestamps_object_is_destroyed) input_timestamps_create_for_keyboard(client); send_key(client, &t1, 1, WL_KEYBOARD_KEY_STATE_PRESSED); - assert(keyboard->key_time_msec == timespec_to_msec(&t1)); - assert(timespec_eq(&keyboard->key_time_timespec, &t1)); + test_assert_s64_eq(keyboard->key_time_msec, timespec_to_msec(&t1)); + test_assert_true(timespec_eq(&keyboard->key_time_timespec, &t1)); input_timestamps_destroy(input_ts); send_key(client, &t2, 1, WL_KEYBOARD_KEY_STATE_RELEASED); - assert(keyboard->key_time_msec == timespec_to_msec(&t2)); - assert(timespec_is_zero(&keyboard->key_time_timespec)); + test_assert_s64_eq(keyboard->key_time_msec, timespec_to_msec(&t2)); + test_assert_true(timespec_is_zero(&keyboard->key_time_timespec)); client_destroy(client); } @@ -159,8 +160,8 @@ TEST(keyboard_timestamps_stop_after_client_releases_wl_keyboard) input_timestamps_create_for_keyboard(client); send_key(client, &t1, 1, WL_KEYBOARD_KEY_STATE_PRESSED); - assert(keyboard->key_time_msec == timespec_to_msec(&t1)); - assert(timespec_eq(&keyboard->key_time_timespec, &t1)); + test_assert_s64_eq(keyboard->key_time_msec, timespec_to_msec(&t1)); + test_assert_true(timespec_eq(&keyboard->key_time_timespec, &t1)); wl_keyboard_release(client->input->keyboard->wl_keyboard); @@ -171,7 +172,7 @@ TEST(keyboard_timestamps_stop_after_client_releases_wl_keyboard) * event and checking for it here may lead to false negatives. */ keyboard->input_timestamp = t_other; send_key(client, &t2, 1, WL_KEYBOARD_KEY_STATE_RELEASED); - assert(timespec_eq(&keyboard->input_timestamp, &t_other)); + test_assert_true(timespec_eq(&keyboard->input_timestamp, &t_other)); input_timestamps_destroy(input_ts); diff --git a/tests/kiosk-shell-test.c b/tests/kiosk-shell-test.c index 9ab401b69..832240eae 100644 --- a/tests/kiosk-shell-test.c +++ b/tests/kiosk-shell-test.c @@ -34,6 +34,7 @@ #include "shared/xalloc.h" #include "weston-test-client-helper.h" #include "weston-test-fixture-compositor.h" +#include "weston-test-assert.h" #include "xdg-shell-client-protocol.h" static enum test_result_code @@ -179,9 +180,9 @@ create_xdg_surface(struct xdg_client *xdg_client) { struct xdg_surface_data *xdg_surface = xzalloc(sizeof(*xdg_surface)); - assert(xdg_surface); + test_assert_ptr_not_null(xdg_surface); xdg_surface->surface = create_test_surface(xdg_client->client); - assert(xdg_surface->surface); + test_assert_ptr_not_null(xdg_surface->surface); xdg_surface->xdg_surface = xdg_wm_base_get_xdg_surface(xdg_client->xdg_wm_base, @@ -208,7 +209,7 @@ xdg_surface_make_toplevel(struct xdg_surface_data *xdg_surface, { xdg_surface->xdg_toplevel = xdg_surface_get_toplevel(xdg_surface->xdg_surface); - assert(xdg_surface->xdg_toplevel); + test_assert_ptr_not_null(xdg_surface->xdg_toplevel); xdg_toplevel_add_listener(xdg_surface->xdg_toplevel, &xdg_toplevel_listener, xdg_surface); xdg_toplevel_set_app_id(xdg_surface->xdg_toplevel, app_id); @@ -220,7 +221,7 @@ xdg_surface_wait_configure(struct xdg_surface_data *xdg_surface) { wl_surface_commit(xdg_surface->surface->wl_surface); wl_display_roundtrip(xdg_surface->surface->client->wl_display); - assert(xdg_surface->configure.serial > 0); + test_assert_u32_gt(xdg_surface->configure.serial, 0); } static void @@ -234,7 +235,7 @@ xdg_surface_commit_solid(struct xdg_surface_data *xdg_surface, buf = create_shm_buffer_a8r8g8b8(xdg_surface->surface->client, width, height); - assert(buf); + test_assert_ptr_not_null(buf); xdg_surface->surface->buffer = buf; color_rgb888(&color, r, g, b); @@ -261,14 +262,14 @@ create_xdg_client(void) { struct xdg_client *xdg_client = xzalloc(sizeof(*xdg_client)); - assert(xdg_client); + test_assert_ptr_not_null(xdg_client); xdg_client->client = create_client(); - assert(xdg_client->client); + test_assert_ptr_not_null(xdg_client->client); xdg_client->xdg_wm_base = bind_to_singleton_global(xdg_client->client, &xdg_wm_base_interface, 5); - assert(xdg_client->xdg_wm_base); + test_assert_ptr_not_null(xdg_client->xdg_wm_base); xdg_wm_base_add_listener(xdg_client->xdg_wm_base, &xdg_wm_base_listener, xdg_client); @@ -300,23 +301,24 @@ DECLARE_LIST_ITERATOR(view_from_surface, struct weston_surface, views, static void assert_resource_is_proxy(struct wet_testsuite_data *suite_data, struct wl_resource *r, void *p) { - assert(r); - assert(wl_resource_get_client(r) == suite_data->wl_client); - assert(wl_resource_get_id(r) == wl_proxy_get_id((struct wl_proxy *) p)); + test_assert_ptr_not_null(r); + test_assert_ptr_eq(wl_resource_get_client(r), suite_data->wl_client); + test_assert_u32_eq(wl_resource_get_id(r), + wl_proxy_get_id((struct wl_proxy *) p)); } static void assert_surface_matches(struct wet_testsuite_data *suite_data, struct weston_surface *s, struct surface *c) { - assert(s); - assert(c); + test_assert_ptr_not_null(s); + test_assert_ptr_not_null(c); assert_resource_is_proxy(suite_data, s->resource, c->wl_surface); - assert(s->width == c->width); - assert(s->height == c->height); + test_assert_s32_eq(s->width, c->width); + test_assert_s32_eq(s->height, c->height); - assert(s->buffer_ref.buffer); - assert(c->buffer); + test_assert_ptr_not_null(s->buffer_ref.buffer); + test_assert_ptr_not_null(c->buffer); assert_resource_is_proxy(suite_data, s->buffer_ref.buffer->resource, c->buffer->proxy); } @@ -327,8 +329,8 @@ static void assert_output_matches(struct wet_testsuite_data *suite_data, struct weston_head *head; bool found_client_resource = false; - assert(s); - assert(c); + test_assert_ptr_not_null(s); + test_assert_ptr_not_null(c); wl_list_for_each(head, &s->head_list, output_link) { struct wl_resource *res; @@ -341,10 +343,10 @@ static void assert_output_matches(struct wet_testsuite_data *suite_data, } } } - assert(found_client_resource); + test_assert_true(found_client_resource); - assert(s->width == c->width); - assert(s->height == c->height); + test_assert_s32_eq(s->width, c->width); + test_assert_s32_eq(s->height, c->height); } static void * @@ -354,10 +356,10 @@ get_server_res_from_proxy(struct wet_testsuite_data *suite_data, uint32_t id = wl_proxy_get_id((struct wl_proxy *) p); struct wl_resource *res; - assert(p); - assert(id > 0); + test_assert_ptr_not_null(p); + test_assert_u32_gt(id, 0); res = wl_client_get_object(suite_data->wl_client, id); - assert(res); + test_assert_ptr_not_null(res); return wl_resource_get_user_data(res); } @@ -367,15 +369,15 @@ assert_surface_is_background(struct wet_testsuite_data *suite_data, { char lbl[128]; - assert(!surface->resource); - assert(surface->buffer_ref.buffer); - assert(surface->buffer_ref.buffer->type == WESTON_BUFFER_SOLID); - assert(surface->output); - assert(surface->width == surface->output->width); - assert(surface->height == surface->output->height); - assert(surface->get_label && - surface->get_label(surface, lbl, sizeof(lbl)) && - strcmp(lbl, "kiosk shell background surface") == 0); + test_assert_ptr_null(surface->resource); + test_assert_ptr_not_null(surface->buffer_ref.buffer); + test_assert_enum(surface->buffer_ref.buffer->type, WESTON_BUFFER_SOLID); + test_assert_ptr_not_null(surface->output); + test_assert_s32_eq(surface->width, surface->output->width); + test_assert_s32_eq(surface->height, surface->output->height); + test_assert_ptr_not_null(surface->get_label); + test_assert_int_ne(surface->get_label(surface, lbl, sizeof(lbl)), 0); + test_assert_str_eq(lbl, "kiosk shell background surface"); } TEST(two_surface_switching) @@ -385,19 +387,21 @@ TEST(two_surface_switching) struct xdg_surface_data *xdg_surface1, *xdg_surface2; struct input *input; - assert(xdg_client); + test_assert_ptr_not_null(xdg_client); /* move the pointer clearly away from our screenshooting area */ weston_test_move_pointer(xdg_client->client->test->weston_test, 0, 1, 0, 2, 30); xdg_surface1 = create_xdg_surface(xdg_client); - assert(xdg_surface1); + test_assert_ptr_not_null(xdg_surface1); xdg_surface_make_toplevel(xdg_surface1, "weston.test.kiosk", "one"); xdg_surface_wait_configure(xdg_surface1); - assert(xdg_surface1->configure.fullscreen); - assert(xdg_surface1->configure.width == xdg_client->client->output->width); - assert(xdg_surface1->configure.height == xdg_client->client->output->height); + test_assert_true(xdg_surface1->configure.fullscreen); + test_assert_int_eq(xdg_surface1->configure.width, + xdg_client->client->output->width); + test_assert_int_eq(xdg_surface1->configure.height, + xdg_client->client->output->height); client_push_breakpoint(xdg_client->client, suite_data, WESTON_TEST_BREAKPOINT_POST_REPAINT, @@ -416,37 +420,43 @@ TEST(two_surface_switching) struct weston_desktop_surface *wds = weston_surface_get_desktop_surface(surface); - assert(breakpoint->template_->breakpoint == - WESTON_TEST_BREAKPOINT_POST_REPAINT); + test_assert_enum(breakpoint->template_->breakpoint, + WESTON_TEST_BREAKPOINT_POST_REPAINT); assert_output_matches(suite_data, output, xdg_client->client->output); - assert(pnode && surface && wds && view && buffer); + test_assert_ptr_not_null(pnode); + test_assert_ptr_not_null(surface); + test_assert_ptr_not_null(wds); + test_assert_ptr_not_null(view); + test_assert_ptr_not_null(buffer); /* check that our surface is top of the paint node list */ assert_surface_matches(suite_data, surface, xdg_surface1->surface); - assert(strcmp(weston_desktop_surface_get_title(wds), "one") == 0); - assert(weston_view_is_mapped(view)); - assert(weston_surface_is_mapped(surface)); + test_assert_str_eq(weston_desktop_surface_get_title(wds), "one"); + test_assert_true(weston_view_is_mapped(view)); + test_assert_true(weston_surface_is_mapped(surface)); /* the background should be under that */ pnode = next_pnode_from_z(output, pnode); - assert(pnode); + test_assert_ptr_not_null(pnode); assert_surface_is_background(suite_data, pnode->view->surface); } wl_display_roundtrip(xdg_client->client->wl_display); input = container_of(xdg_client->client->inputs.next, struct input, link); - assert(input); - assert(input->keyboard); - assert(input->keyboard->focus == xdg_surface1->surface); + test_assert_ptr_not_null(input); + test_assert_ptr_not_null(input->keyboard); + test_assert_ptr_eq(input->keyboard->focus, xdg_surface1->surface); xdg_surface2 = create_xdg_surface(xdg_client); - assert(xdg_surface2); + test_assert_ptr_not_null(xdg_surface2); xdg_surface_make_toplevel(xdg_surface2, "weston.test.kiosk", "two"); xdg_surface_wait_configure(xdg_surface2); - assert(xdg_surface2->configure.fullscreen); - assert(xdg_surface2->configure.width == xdg_client->client->output->width); - assert(xdg_surface2->configure.height == xdg_client->client->output->height); + test_assert_true(xdg_surface2->configure.fullscreen); + test_assert_int_eq(xdg_surface2->configure.width, + xdg_client->client->output->width); + test_assert_int_eq(xdg_surface2->configure.height, + xdg_client->client->output->height); client_push_breakpoint(xdg_client->client, suite_data, WESTON_TEST_BREAKPOINT_POST_REPAINT, @@ -465,26 +475,30 @@ TEST(two_surface_switching) struct weston_desktop_surface *wds = weston_surface_get_desktop_surface(surface); - assert(breakpoint->template_->breakpoint == - WESTON_TEST_BREAKPOINT_POST_REPAINT); + test_assert_enum(breakpoint->template_->breakpoint, + WESTON_TEST_BREAKPOINT_POST_REPAINT); assert_output_matches(suite_data, output, xdg_client->client->output); - assert(pnode && surface && wds && view && buffer); + test_assert_ptr_not_null(pnode); + test_assert_ptr_not_null(surface); + test_assert_ptr_not_null(wds); + test_assert_ptr_not_null(view); + test_assert_ptr_not_null(buffer); /* check that our surface is top of the paint node list */ assert_surface_matches(suite_data, surface, xdg_surface2->surface); - assert(strcmp(weston_desktop_surface_get_title(wds), "two") == 0); - assert(weston_surface_is_mapped(surface)); - assert(weston_view_is_mapped(view)); + test_assert_str_eq(weston_desktop_surface_get_title(wds), "two"); + test_assert_true(weston_surface_is_mapped(surface)); + test_assert_true(weston_view_is_mapped(view)); /* the background should be under that */ pnode = next_pnode_from_z(output, pnode); - assert(pnode); + test_assert_ptr_not_null(pnode); assert_surface_is_background(suite_data, pnode->view->surface); } wl_display_roundtrip(xdg_client->client->wl_display); - assert(input->keyboard->focus == xdg_surface2->surface); + test_assert_ptr_eq(input->keyboard->focus, xdg_surface2->surface); destroy_xdg_surface(xdg_surface2); client_push_breakpoint(xdg_client->client, suite_data, @@ -502,22 +516,26 @@ TEST(two_surface_switching) struct weston_desktop_surface *wds = weston_surface_get_desktop_surface(surface); - assert(breakpoint->template_->breakpoint == - WESTON_TEST_BREAKPOINT_POST_REPAINT); + test_assert_enum(breakpoint->template_->breakpoint, + WESTON_TEST_BREAKPOINT_POST_REPAINT); assert_output_matches(suite_data, output, xdg_client->client->output); - assert(pnode && surface && wds && view && buffer); + test_assert_ptr_not_null(pnode); + test_assert_ptr_not_null(surface); + test_assert_ptr_not_null(wds); + test_assert_ptr_not_null(view); + test_assert_ptr_not_null(buffer); /* check that our surface is top of the paint node list */ assert_surface_matches(suite_data, surface, xdg_surface1->surface); - assert(surface->resource); - assert(weston_view_is_mapped(view)); - assert(weston_surface_is_mapped(surface)); - assert(strcmp(weston_desktop_surface_get_title(wds), "one") == 0); + test_assert_ptr_not_null(surface->resource); + test_assert_true(weston_view_is_mapped(view)); + test_assert_true(weston_surface_is_mapped(surface)); + test_assert_str_eq(weston_desktop_surface_get_title(wds), "one"); } wl_display_roundtrip(xdg_client->client->wl_display); - assert(input->keyboard->focus == xdg_surface1->surface); + test_assert_ptr_eq(input->keyboard->focus, xdg_surface1->surface); destroy_xdg_surface(xdg_surface1); xdg_client_destroy(xdg_client); @@ -530,8 +548,8 @@ TEST(top_surface_present_in_output_repaint) struct xdg_client *xdg_client = create_xdg_client(); struct xdg_surface_data *xdg_surface = create_xdg_surface(xdg_client); - assert(xdg_client); - assert(xdg_surface); + test_assert_ptr_not_null(xdg_client); + test_assert_ptr_not_null(xdg_surface); /* move the pointer clearly away from our screenshooting area */ weston_test_move_pointer(xdg_client->client->test->weston_test, @@ -539,9 +557,11 @@ TEST(top_surface_present_in_output_repaint) xdg_surface_make_toplevel(xdg_surface, "weston.test.kiosk", "one"); xdg_surface_wait_configure(xdg_surface); - assert(xdg_surface->configure.fullscreen); - assert(xdg_surface->configure.width == xdg_client->client->output->width); - assert(xdg_surface->configure.height == xdg_client->client->output->height); + test_assert_true(xdg_surface->configure.fullscreen); + test_assert_int_eq(xdg_surface->configure.width, + xdg_client->client->output->width); + test_assert_int_eq(xdg_surface->configure.height, + xdg_client->client->output->height); client_push_breakpoint(xdg_client->client, suite_data, WESTON_TEST_BREAKPOINT_POST_REPAINT, @@ -558,15 +578,18 @@ TEST(top_surface_present_in_output_repaint) struct weston_surface *surface = view->surface; struct weston_buffer *buffer = surface->buffer_ref.buffer; - assert(breakpoint->template_->breakpoint == - WESTON_TEST_BREAKPOINT_POST_REPAINT); + test_assert_enum(breakpoint->template_->breakpoint, + WESTON_TEST_BREAKPOINT_POST_REPAINT); assert_output_matches(suite_data, output, xdg_client->client->output); - assert(pnode && surface && view && buffer); + test_assert_ptr_not_null(pnode); + test_assert_ptr_not_null(surface); + test_assert_ptr_not_null(view); + test_assert_ptr_not_null(buffer); /* check that our surface is top of the paint node list */ assert_surface_matches(suite_data, surface, xdg_surface->surface); - assert(weston_view_is_mapped(view)); - assert(weston_surface_is_mapped(surface)); + test_assert_true(weston_view_is_mapped(view)); + test_assert_true(weston_surface_is_mapped(surface)); } destroy_xdg_surface(xdg_surface); @@ -579,8 +602,8 @@ TEST(test_surface_unmaps_on_null) struct xdg_client *xdg_client = create_xdg_client(); struct xdg_surface_data *xdg_surface = create_xdg_surface(xdg_client);; - assert(xdg_client); - assert(xdg_surface); + test_assert_ptr_not_null(xdg_client); + test_assert_ptr_not_null(xdg_surface); /* move the pointer clearly away from our screenshooting area */ weston_test_move_pointer(xdg_client->client->test->weston_test, @@ -588,9 +611,11 @@ TEST(test_surface_unmaps_on_null) xdg_surface_make_toplevel(xdg_surface, "weston.test.kiosk", "one"); xdg_surface_wait_configure(xdg_surface); - assert(xdg_surface->configure.fullscreen); - assert(xdg_surface->configure.width == xdg_client->client->output->width); - assert(xdg_surface->configure.height == xdg_client->client->output->height); + test_assert_true(xdg_surface->configure.fullscreen); + test_assert_int_eq(xdg_surface->configure.width, + xdg_client->client->output->width); + test_assert_int_eq(xdg_surface->configure.height, + xdg_client->client->output->height); client_push_breakpoint(xdg_client->client, suite_data, WESTON_TEST_BREAKPOINT_POST_REPAINT, @@ -607,14 +632,16 @@ TEST(test_surface_unmaps_on_null) struct weston_surface *surface = view->surface; /* Check that our surface is being shown on top */ - assert(breakpoint->template_->breakpoint == - WESTON_TEST_BREAKPOINT_POST_REPAINT); - assert(pnode && surface && view); + test_assert_enum(breakpoint->template_->breakpoint, + WESTON_TEST_BREAKPOINT_POST_REPAINT); + test_assert_ptr_not_null(pnode); + test_assert_ptr_not_null(surface); + test_assert_ptr_not_null(view); assert_surface_matches(suite_data, surface, xdg_surface->surface); assert_output_matches(suite_data, surface->output, xdg_client->client->output); - assert(weston_view_is_mapped(view)); - assert(weston_surface_is_mapped(surface)); + test_assert_true(weston_view_is_mapped(view)); + test_assert_true(weston_surface_is_mapped(surface)); } wl_surface_attach(xdg_surface->surface->wl_surface, NULL, 0, 0); @@ -633,23 +660,26 @@ TEST(test_surface_unmaps_on_null) struct weston_surface *surface = view->surface; struct weston_buffer *buffer = surface->buffer_ref.buffer; - assert(breakpoint->template_->breakpoint == - WESTON_TEST_BREAKPOINT_POST_REPAINT); + test_assert_enum(breakpoint->template_->breakpoint, + WESTON_TEST_BREAKPOINT_POST_REPAINT); /* Check that the background is being shown on top. */ - assert(pnode && surface && view && buffer); + test_assert_ptr_not_null(pnode); + test_assert_ptr_not_null(surface); + test_assert_ptr_not_null(view); + test_assert_ptr_not_null(buffer); assert_surface_is_background(suite_data, surface); /* Check that kiosk-shell's view of our surface has been * unmapped, and that there aren't any more views. */ surface = get_server_res_from_proxy(suite_data, xdg_surface->surface->wl_surface); - assert(!weston_surface_is_mapped(surface)); - assert(!surface->buffer_ref.buffer); - assert(!surface->output); + test_assert_false(weston_surface_is_mapped(surface)); + test_assert_ptr_null(surface->buffer_ref.buffer); + test_assert_ptr_null(surface->output); view = next_view_from_surface(surface, NULL); - assert(!weston_view_is_mapped(view)); - assert(!next_view_from_surface(surface, view)); + test_assert_false(weston_view_is_mapped(view)); + test_assert_ptr_null(next_view_from_surface(surface, view)); } destroy_xdg_surface(xdg_surface); diff --git a/tests/lcms-util-test.c b/tests/lcms-util-test.c index e7d8b69ee..04e8677a2 100644 --- a/tests/lcms-util-test.c +++ b/tests/lcms-util-test.c @@ -29,6 +29,7 @@ #include #include "weston-test-client-helper.h" +#include "weston-test-assert.h" #include "color_util.h" #include "lcms_util.h" @@ -78,8 +79,8 @@ TEST_P(build_MPE_curves, build_MPE_curves_test_set) testlog("Transfer function %s as a segmented curve element, error:\n", transfer_fn_name(*fn)); scalar_stat_print_float(&stat); - assert(fabs(stat.max) < 1e-7); - assert(fabs(stat.min) < 1e-7); + test_assert_f64_lt(fabs(stat.max), 1e-7); + test_assert_f64_lt(fabs(stat.min), 1e-7); cmsPipelineFree(pipeline); } diff --git a/tests/lcms_util.c b/tests/lcms_util.c index eef32e619..3fe606329 100644 --- a/tests/lcms_util.c +++ b/tests/lcms_util.c @@ -29,13 +29,13 @@ #include #include -#include #include #include #include "shared/helpers.h" #include "color_util.h" #include "lcms_util.h" +#include "weston-test-assert.h" static const cmsCIExyY wp_d65 = { 0.31271, 0.32902, 1.0 }; @@ -184,7 +184,7 @@ build_MPE_curve(cmsContext ctx, enum transfer_fn fn) case TRANSFER_FN_SRGB_EOTF_INVERSE: return build_MPE_curve_sRGB_inv(ctx); default: - assert(0 && "unimplemented MPE curve"); + test_assert_not_reached("unimplemented MPE curve"); } return NULL; @@ -199,7 +199,7 @@ build_MPE_curve_stage(cmsContext context_id, enum transfer_fn fn) c = build_MPE_curve(context_id, fn); stage = cmsStageAllocToneCurves(context_id, 3, (cmsToneCurve *[3]){ c, c, c }); - assert(stage); + test_assert_ptr_not_null(stage); cmsFreeToneCurve(c); return stage; @@ -278,7 +278,7 @@ roundtrip_verification(cmsPipeline *DToB, cmsPipeline *BToD, float tolerance) cmsPipelineFree(pip); rgb_diff_stat_print(&stat, "DToB->BToD roundtrip", 8); - assert(stat.two_norm.max < tolerance); + test_assert_f32_lt(stat.two_norm.max, tolerance); } static const struct weston_vector ZEROS = { @@ -377,7 +377,7 @@ create_cLUT_from_transform(cmsContext context_id, const cmsHTRANSFORM t, struct transform_sampler_context tsc; cmsStage *cLUT_stage; - assert(dim_size); + test_assert_int_ne(dim_size, 0); tsc.t = t; tsc.dir = dir; @@ -412,7 +412,7 @@ vcgt_tag_add_to_profile(cmsContext context_id, cmsHPROFILE profile, for (i = 0; i < COLOR_CHAN_NUM; i++) vcgt_tag_curves[i] = cmsBuildGamma(context_id, vcgt_exponents[i]); - assert(cmsWriteTag(profile, cmsSigVcgtTag, vcgt_tag_curves)); + test_assert_true(cmsWriteTag(profile, cmsSigVcgtTag, vcgt_tag_curves)); cmsFreeToneCurveTriple(vcgt_tag_curves); } @@ -443,7 +443,7 @@ build_lcms_clut_profile_output(cmsContext context_id, linear_device = cmsCreateRGBProfileTHR(context_id, &wp_d65, &pipeline->prim_output, identity_curves); - assert(cmsIsMatrixShaper(linear_device)); + test_assert_true(cmsIsMatrixShaper(linear_device)); cmsFreeToneCurve(identity_curves[0]); pcs = cmsCreateXYZProfileTHR(context_id); @@ -551,8 +551,8 @@ build_lcms_matrix_shaper_profile_output(cmsContext context_id, int type_inverse_tone_curve; double inverse_tone_curve_param[5]; - assert(find_tone_curve_type(pipeline->post_fn, &type_inverse_tone_curve, - inverse_tone_curve_param)); + test_assert_true(find_tone_curve_type(pipeline->post_fn, &type_inverse_tone_curve, + inverse_tone_curve_param)); /* * We are creating output profile and therefore we can use the following: @@ -569,10 +569,10 @@ build_lcms_matrix_shaper_profile_output(cmsContext context_id, (-1) * type_inverse_tone_curve, inverse_tone_curve_param); - assert(arr_curves[0]); + test_assert_ptr_not_null(arr_curves[0]); hRGB = cmsCreateRGBProfileTHR(context_id, &wp_d65, &pipeline->prim_output, arr_curves); - assert(hRGB); + test_assert_ptr_not_null(hRGB); vcgt_tag_add_to_profile(context_id, hRGB, vcgt_exponents); diff --git a/tests/linux-explicit-synchronization-test.c b/tests/linux-explicit-synchronization-test.c index 0798b35d8..3dc18d1a0 100644 --- a/tests/linux-explicit-synchronization-test.c +++ b/tests/linux-explicit-synchronization-test.c @@ -32,6 +32,7 @@ #include "weston-test-client-helper.h" #include "wayland-server-protocol.h" #include "weston-test-fixture-compositor.h" +#include "weston-test-assert.h" static enum test_result_code fixture_setup(struct weston_test_harness *harness) @@ -65,18 +66,18 @@ get_linux_explicit_synchronization(struct client *client) continue; if (global_sync) - assert(!"Multiple linux explicit sync objects"); + test_assert_not_reached("Multiple linux explicit sync objects"); global_sync = g; } - assert(global_sync); - assert(global_sync->version == 2); + test_assert_ptr_not_null(global_sync); + test_assert_u32_eq(global_sync->version, 2); sync = wl_registry_bind( client->wl_registry, global_sync->name, &zwp_linux_explicit_synchronization_v1_interface, 2); - assert(sync); + test_assert_ptr_not_null(sync); return sync; } @@ -85,7 +86,7 @@ static struct client * create_test_client(void) { struct client *cl = create_client_and_test_surface(0, 0, 100, 100); - assert(cl); + test_assert_ptr_not_null(cl); return cl; } @@ -127,7 +128,7 @@ TEST(set_acquire_fence_with_invalid_fence_raises_error) sync, client->surface->wl_surface); int pipefd[2] = { -1, -1 }; - assert(pipe(pipefd) == 0); + test_assert_int_eq(pipe(pipefd), 0); zwp_linux_surface_synchronization_v1_set_acquire_fence(surface_sync, pipefd[0]); @@ -153,7 +154,7 @@ TEST(set_acquire_fence_on_destroyed_surface_raises_error) sync, client->surface->wl_surface); int pipefd[2] = { -1, -1 }; - assert(pipe(pipefd) == 0); + test_assert_int_eq(pipe(pipefd), 0); wl_surface_destroy(client->surface->wl_surface); client->surface->wl_surface = NULL; @@ -288,7 +289,7 @@ buffer_release_fenced_handler(void *data, struct zwp_linux_buffer_release_v1 *buffer_release, int32_t fence) { - assert(!"Fenced release not supported yet"); + test_assert_not_reached("Fenced release not supported yet"); } static void @@ -340,7 +341,7 @@ TEST(get_release_events_are_emitted_for_different_buffers) frame_callback_wait(client, &frame); /* No release event should have been emitted yet (we are using the * pixman renderer, which holds buffers until they are replaced). */ - assert(buf_released1 == 0); + test_assert_int_eq(buf_released1, 0); buffer_release2 = zwp_linux_surface_synchronization_v1_get_release(surface_sync); @@ -353,8 +354,8 @@ TEST(get_release_events_are_emitted_for_different_buffers) frame_callback_wait(client, &frame); /* Check that exactly one buffer_release event was emitted for the * previous commit (buf1). */ - assert(buf_released1 == 1); - assert(buf_released2 == 0); + test_assert_int_eq(buf_released1, 1); + test_assert_int_eq(buf_released2, 0); wl_surface_attach(surface, buf1->proxy, 0, 0); frame_callback_set(surface, &frame); @@ -362,8 +363,8 @@ TEST(get_release_events_are_emitted_for_different_buffers) frame_callback_wait(client, &frame); /* Check that exactly one buffer_release event was emitted for the * previous commit (buf2). */ - assert(buf_released1 == 1); - assert(buf_released2 == 1); + test_assert_int_eq(buf_released1, 1); + test_assert_int_eq(buf_released2, 1); buffer_destroy(buf2); buffer_destroy(buf1); @@ -401,7 +402,7 @@ TEST(get_release_events_are_emitted_for_same_buffer_on_surface) frame_callback_wait(client, &frame); /* No release event should have been emitted yet (we are using the * pixman renderer, which holds buffers until they are replaced). */ - assert(buf_released1 == 0); + test_assert_int_eq(buf_released1, 0); buffer_release2 = zwp_linux_surface_synchronization_v1_get_release(surface_sync); @@ -414,8 +415,8 @@ TEST(get_release_events_are_emitted_for_same_buffer_on_surface) frame_callback_wait(client, &frame); /* Check that exactly one buffer_release event was emitted for the * previous commit (buf). */ - assert(buf_released1 == 1); - assert(buf_released2 == 0); + test_assert_int_eq(buf_released1, 1); + test_assert_int_eq(buf_released2, 0); wl_surface_attach(surface, buf->proxy, 0, 0); frame_callback_set(surface, &frame); @@ -423,8 +424,8 @@ TEST(get_release_events_are_emitted_for_same_buffer_on_surface) frame_callback_wait(client, &frame); /* Check that exactly one buffer_release event was emitted for the * previous commit (buf again). */ - assert(buf_released1 == 1); - assert(buf_released2 == 1); + test_assert_int_eq(buf_released1, 1); + test_assert_int_eq(buf_released2, 1); buffer_destroy(buf); zwp_linux_buffer_release_v1_destroy(buffer_release2); @@ -479,8 +480,8 @@ TEST(get_release_events_are_emitted_for_same_buffer_on_different_surfaces) wl_surface_commit(surface2); frame_callback_wait(client, &frame); - assert(buf_released1 == 0); - assert(buf_released2 == 0); + test_assert_int_eq(buf_released1, 0); + test_assert_int_eq(buf_released2, 0); /* Attach buf2 to surface1, and check that a buffer_release event for * the previous commit (buf1) for that surface is emitted. */ @@ -489,8 +490,8 @@ TEST(get_release_events_are_emitted_for_same_buffer_on_different_surfaces) wl_surface_commit(surface1); frame_callback_wait(client, &frame); - assert(buf_released1 == 1); - assert(buf_released2 == 0); + test_assert_int_eq(buf_released1, 1); + test_assert_int_eq(buf_released2, 0); /* Attach buf2 to surface2, and check that a buffer_release event for * the previous commit (buf1) for that surface is emitted. */ @@ -499,8 +500,8 @@ TEST(get_release_events_are_emitted_for_same_buffer_on_different_surfaces) wl_surface_commit(surface2); frame_callback_wait(client, &frame); - assert(buf_released1 == 1); - assert(buf_released2 == 1); + test_assert_int_eq(buf_released1, 1); + test_assert_int_eq(buf_released2, 1); buffer_destroy(buf2); buffer_destroy(buf1); diff --git a/tests/matrix-test.c b/tests/matrix-test.c index 11c840daa..2b8bd30b2 100644 --- a/tests/matrix-test.c +++ b/tests/matrix-test.c @@ -28,6 +28,7 @@ #include #include #include "weston-test-client-helper.h" +#include "weston-test-assert.h" /* * A helper to lay out a matrix in the natural writing order in code @@ -266,6 +267,6 @@ TEST_P(matrix_inversion_precision, matrices) if (err > tm->err_limit) { testlog("Error is too high for matrix\n"); print_matrix(&tm->M); - assert(0); + test_assert_true(false); } } diff --git a/tests/matrix-transform-test.c b/tests/matrix-transform-test.c index 920e13d92..6c94e70d8 100644 --- a/tests/matrix-transform-test.c +++ b/tests/matrix-transform-test.c @@ -25,7 +25,6 @@ #include "config.h" -#include #include #include #include @@ -37,15 +36,16 @@ #include "libweston/matrix.h" #include "weston-test-client-helper.h" +#include "weston-test-assert.h" static void transform_expect(struct weston_matrix *a, bool valid, enum wl_output_transform ewt) { enum wl_output_transform wt; - assert(weston_matrix_to_transform(a, &wt) == valid); + test_assert_true(weston_matrix_to_transform(a, &wt) == valid); if (valid) - assert(wt == ewt); + test_assert_true(wt == ewt); } TEST(transformation_matrix) @@ -57,26 +57,26 @@ TEST(transformation_matrix) weston_matrix_init(&b); weston_matrix_multiply(&a, &b); - assert(a.type == 0); + test_assert_uint_eq(a.type, 0); /* Make b a matrix that rotates a surface on the x,y plane by 90 * degrees counter-clockwise */ weston_matrix_rotate_xy(&b, 0, -1); - assert(b.type == WESTON_MATRIX_TRANSFORM_ROTATE); + test_assert_enum(b.type, WESTON_MATRIX_TRANSFORM_ROTATE); for (i = 0; i < 10; i++) { weston_matrix_multiply(&a, &b); transform_expect(&a, true, WL_OUTPUT_TRANSFORM_90); weston_matrix_multiply(&a, &b); - assert(a.type == WESTON_MATRIX_TRANSFORM_ROTATE); + test_assert_enum(a.type, WESTON_MATRIX_TRANSFORM_ROTATE); transform_expect(&a, true, WL_OUTPUT_TRANSFORM_180); weston_matrix_multiply(&a, &b); - assert(a.type == WESTON_MATRIX_TRANSFORM_ROTATE); + test_assert_enum(a.type, WESTON_MATRIX_TRANSFORM_ROTATE); transform_expect(&a, true, WL_OUTPUT_TRANSFORM_270); weston_matrix_multiply(&a, &b); - assert(a.type == WESTON_MATRIX_TRANSFORM_ROTATE); + test_assert_enum(a.type, WESTON_MATRIX_TRANSFORM_ROTATE); transform_expect(&a, true, WL_OUTPUT_TRANSFORM_NORMAL); } @@ -86,38 +86,38 @@ TEST(transformation_matrix) * standard transform and a rotation that fails to match any * known rotations. */ weston_matrix_rotate_xy(&b, cos(-M_PI / 4.0), sin(-M_PI / 4.0)); - assert(b.type == WESTON_MATRIX_TRANSFORM_ROTATE); + test_assert_enum(b.type, WESTON_MATRIX_TRANSFORM_ROTATE); for (i = 0; i < 10; i++) { weston_matrix_multiply(&a, &b); - assert(a.type == WESTON_MATRIX_TRANSFORM_ROTATE); + test_assert_enum(a.type, WESTON_MATRIX_TRANSFORM_ROTATE); transform_expect(&a, false, 0); weston_matrix_multiply(&a, &b); - assert(a.type == WESTON_MATRIX_TRANSFORM_ROTATE); + test_assert_enum(a.type, WESTON_MATRIX_TRANSFORM_ROTATE); transform_expect(&a, true, WL_OUTPUT_TRANSFORM_90); weston_matrix_multiply(&a, &b); - assert(a.type == WESTON_MATRIX_TRANSFORM_ROTATE); + test_assert_enum(a.type, WESTON_MATRIX_TRANSFORM_ROTATE); transform_expect(&a, false, 0); weston_matrix_multiply(&a, &b); - assert(a.type == WESTON_MATRIX_TRANSFORM_ROTATE); + test_assert_enum(a.type, WESTON_MATRIX_TRANSFORM_ROTATE); transform_expect(&a, true, WL_OUTPUT_TRANSFORM_180); weston_matrix_multiply(&a, &b); - assert(a.type == WESTON_MATRIX_TRANSFORM_ROTATE); + test_assert_enum(a.type, WESTON_MATRIX_TRANSFORM_ROTATE); transform_expect(&a, false, 0); weston_matrix_multiply(&a, &b); - assert(a.type == WESTON_MATRIX_TRANSFORM_ROTATE); + test_assert_enum(a.type, WESTON_MATRIX_TRANSFORM_ROTATE); transform_expect(&a, true, WL_OUTPUT_TRANSFORM_270); weston_matrix_multiply(&a, &b); - assert(a.type == WESTON_MATRIX_TRANSFORM_ROTATE); + test_assert_enum(a.type, WESTON_MATRIX_TRANSFORM_ROTATE); transform_expect(&a, false, 0); weston_matrix_multiply(&a, &b); - assert(a.type == WESTON_MATRIX_TRANSFORM_ROTATE); + test_assert_enum(a.type, WESTON_MATRIX_TRANSFORM_ROTATE); transform_expect(&a, true, WL_OUTPUT_TRANSFORM_NORMAL); } @@ -136,35 +136,35 @@ TEST(transformation_matrix) * matches a standard wl_output_transform should not need * filtering when used to transform images - but any * matrix that fails to match will. */ - assert(weston_matrix_needs_filtering(&a)); + test_assert_true(weston_matrix_needs_filtering(&a)); weston_matrix_multiply(&a, &b); transform_expect(&a, true, WL_OUTPUT_TRANSFORM_FLIPPED_90); - assert(!weston_matrix_needs_filtering(&a)); + test_assert_false(weston_matrix_needs_filtering(&a)); weston_matrix_multiply(&a, &b); transform_expect(&a, false, 0); - assert(weston_matrix_needs_filtering(&a)); + test_assert_true(weston_matrix_needs_filtering(&a)); weston_matrix_multiply(&a, &b); transform_expect(&a, true, WL_OUTPUT_TRANSFORM_FLIPPED_180); - assert(!weston_matrix_needs_filtering(&a)); + test_assert_false(weston_matrix_needs_filtering(&a)); weston_matrix_multiply(&a, &b); transform_expect(&a, false, 0); - assert(weston_matrix_needs_filtering(&a)); + test_assert_true(weston_matrix_needs_filtering(&a)); weston_matrix_multiply(&a, &b); transform_expect(&a, true, WL_OUTPUT_TRANSFORM_FLIPPED_270); - assert(!weston_matrix_needs_filtering(&a)); + test_assert_false(weston_matrix_needs_filtering(&a)); weston_matrix_multiply(&a, &b); transform_expect(&a, false, 0); - assert(weston_matrix_needs_filtering(&a)); + test_assert_true(weston_matrix_needs_filtering(&a)); weston_matrix_multiply(&a, &b); transform_expect(&a, true, WL_OUTPUT_TRANSFORM_FLIPPED); - assert(!weston_matrix_needs_filtering(&a)); + test_assert_false(weston_matrix_needs_filtering(&a)); } weston_matrix_init(&a); @@ -206,35 +206,35 @@ TEST(transformation_matrix) for (i = 0; i < 100; i++) { weston_matrix_multiply(&a, &b); transform_expect(&a, false, 0); - assert(weston_matrix_needs_filtering(&a)); + test_assert_true(weston_matrix_needs_filtering(&a)); weston_matrix_multiply(&a, &b); transform_expect(&a, true, WL_OUTPUT_TRANSFORM_FLIPPED_90); - assert(weston_matrix_needs_filtering(&a)); + test_assert_true(weston_matrix_needs_filtering(&a)); weston_matrix_multiply(&a, &b); transform_expect(&a, false, 0); - assert(weston_matrix_needs_filtering(&a)); + test_assert_true(weston_matrix_needs_filtering(&a)); weston_matrix_multiply(&a, &b); transform_expect(&a, true, WL_OUTPUT_TRANSFORM_FLIPPED); - assert(weston_matrix_needs_filtering(&a)); + test_assert_true(weston_matrix_needs_filtering(&a)); weston_matrix_multiply(&a, &b); transform_expect(&a, false, 0); - assert(weston_matrix_needs_filtering(&a)); + test_assert_true(weston_matrix_needs_filtering(&a)); weston_matrix_multiply(&a, &b); transform_expect(&a, true, WL_OUTPUT_TRANSFORM_FLIPPED_270); - assert(weston_matrix_needs_filtering(&a)); + test_assert_true(weston_matrix_needs_filtering(&a)); weston_matrix_multiply(&a, &b); transform_expect(&a, false, 0); - assert(weston_matrix_needs_filtering(&a)); + test_assert_true(weston_matrix_needs_filtering(&a)); weston_matrix_multiply(&a, &b); transform_expect(&a, true, WL_OUTPUT_TRANSFORM_FLIPPED_180); - assert(weston_matrix_needs_filtering(&a)); + test_assert_true(weston_matrix_needs_filtering(&a)); } /* Flipping Y should return us from here to normal */ @@ -250,19 +250,19 @@ TEST(transformation_matrix) for (i = 0; i < 100; i++) { weston_matrix_multiply(&a, &b); transform_expect(&a, true, WL_OUTPUT_TRANSFORM_NORMAL); - assert(weston_matrix_needs_filtering(&a)); + test_assert_true(weston_matrix_needs_filtering(&a)); weston_matrix_multiply(&a, &b); transform_expect(&a, true, WL_OUTPUT_TRANSFORM_NORMAL); - assert(weston_matrix_needs_filtering(&a)); + test_assert_true(weston_matrix_needs_filtering(&a)); weston_matrix_multiply(&a, &b); transform_expect(&a, true, WL_OUTPUT_TRANSFORM_NORMAL); - assert(weston_matrix_needs_filtering(&a)); + test_assert_true(weston_matrix_needs_filtering(&a)); weston_matrix_multiply(&a, &b); transform_expect(&a, true, WL_OUTPUT_TRANSFORM_NORMAL); - assert(!weston_matrix_needs_filtering(&a)); + test_assert_false(weston_matrix_needs_filtering(&a)); } weston_matrix_init(&b); @@ -270,19 +270,19 @@ TEST(transformation_matrix) for (i = 0; i < 10; i++) { weston_matrix_multiply(&a, &b); transform_expect(&a, true, WL_OUTPUT_TRANSFORM_NORMAL); - assert(weston_matrix_needs_filtering(&a)); + test_assert_true(weston_matrix_needs_filtering(&a)); } weston_matrix_invert(&b, &b); for (i = 0; i < 9; i++) { weston_matrix_multiply(&a, &b); transform_expect(&a, true, WL_OUTPUT_TRANSFORM_NORMAL); - assert(weston_matrix_needs_filtering(&a)); + test_assert_true(weston_matrix_needs_filtering(&a)); } /* Last step should bring us back to a matrix that doesn't need * a filter */ weston_matrix_multiply(&a, &b); transform_expect(&a, true, WL_OUTPUT_TRANSFORM_NORMAL); - assert(!weston_matrix_needs_filtering(&a)); + test_assert_false(weston_matrix_needs_filtering(&a)); } static void @@ -443,7 +443,7 @@ output_test_all_transforms(struct weston_output *output, weston_matrix_transform(&output->matrix, &v); sv = simple_transform_vector(output, t); for (i = 0; i < 4; i++) - assert (sv.f[i] == v.f[i]); + test_assert_f32_eq (sv.f[i], v.f[i]); } } diff --git a/tests/output-capture-protocol-test.c b/tests/output-capture-protocol-test.c index 8cd8a4ced..69a826c8d 100644 --- a/tests/output-capture-protocol-test.c +++ b/tests/output-capture-protocol-test.c @@ -29,6 +29,7 @@ #include "weston-test-fixture-compositor.h" #include "shared/xalloc.h" #include "weston-output-capture-client-protocol.h" +#include "weston-test-assert.h" #include "shared/weston-drm-fourcc.h" struct setup_args { @@ -96,7 +97,7 @@ capture_source_handle_format(void *data, { struct capturer *capt = data; - assert(capt->source == proxy); + test_assert_ptr_eq(capt->source, proxy); capt->events.format = true; capt->drm_format = drm_format; @@ -109,7 +110,7 @@ capture_source_handle_size(void *data, { struct capturer *capt = data; - assert(capt->source == proxy); + test_assert_ptr_eq(capt->source, proxy); capt->events.size = true; capt->width = width; @@ -122,8 +123,8 @@ capture_source_handle_complete(void *data, { struct capturer *capt = data; - assert(capt->source == proxy); - assert(capt->state == CAPTURE_TASK_PENDING); + test_assert_ptr_eq(capt->source, proxy); + test_assert_enum(capt->state, CAPTURE_TASK_PENDING); capt->state = CAPTURE_TASK_COMPLETE; capt->events.reply = true; } @@ -134,8 +135,8 @@ capture_source_handle_retry(void *data, { struct capturer *capt = data; - assert(capt->source == proxy); - assert(capt->state == CAPTURE_TASK_PENDING); + test_assert_ptr_eq(capt->source, proxy); + test_assert_enum(capt->state, CAPTURE_TASK_PENDING); capt->state = CAPTURE_TASK_RETRY; capt->events.reply = true; } @@ -147,8 +148,8 @@ capture_source_handle_failed(void *data, { struct capturer *capt = data; - assert(capt->source == proxy); - assert(capt->state == CAPTURE_TASK_PENDING); + test_assert_ptr_eq(capt->source, proxy); + test_assert_enum(capt->state, CAPTURE_TASK_PENDING); capt->state = CAPTURE_TASK_FAILED; capt->events.reply = true; @@ -210,22 +211,22 @@ TEST(simple_shot) WESTON_CAPTURE_V1_SOURCE_FRAMEBUFFER); client_roundtrip(client); - assert(capt->events.format); - assert(capt->events.size); - assert(capt->state == CAPTURE_TASK_PENDING); - assert(capt->drm_format == fix->expected_drm_format); - assert(capt->width > 0); - assert(capt->height > 0); - assert(!capt->events.reply); + test_assert_true(capt->events.format); + test_assert_true(capt->events.size); + test_assert_enum(capt->state, CAPTURE_TASK_PENDING); + test_assert_u32_eq(capt->drm_format, fix->expected_drm_format); + test_assert_int_gt(capt->width, 0); + test_assert_int_gt(capt->height, 0); + test_assert_false(capt->events.reply); buf = create_shm_buffer(client, capt->width, capt->height, fix->expected_drm_format); weston_capture_source_v1_capture(capt->source, buf->proxy); while (!capt->events.reply) - assert(wl_display_dispatch(client->wl_display) >= 0); + test_assert_int_ge(wl_display_dispatch(client->wl_display), 0); - assert(capt->state == CAPTURE_TASK_COMPLETE); + test_assert_enum(capt->state, CAPTURE_TASK_COMPLETE); capturer_destroy(capt); buffer_destroy(buf); @@ -248,21 +249,24 @@ TEST(retry_on_wrong_format) WESTON_CAPTURE_V1_SOURCE_FRAMEBUFFER); client_roundtrip(client); - assert(capt->events.format); - assert(capt->events.size); - assert(capt->state == CAPTURE_TASK_PENDING); - assert(capt->drm_format != drm_format && "fix this test"); - assert(capt->width > 0); - assert(capt->height > 0); - assert(!capt->events.reply); + test_assert_true(capt->events.format); + test_assert_true(capt->events.size); + test_assert_enum(capt->state, CAPTURE_TASK_PENDING); + + /* Fix this test if triggered. */ + test_assert_u32_ne(capt->drm_format, drm_format); + + test_assert_int_gt(capt->width, 0); + test_assert_int_gt(capt->height, 0); + test_assert_false(capt->events.reply); buf = create_shm_buffer(client, capt->width, capt->height, drm_format); weston_capture_source_v1_capture(capt->source, buf->proxy); while (!capt->events.reply) - assert(wl_display_dispatch(client->wl_display) >= 0); + test_assert_int_ge(wl_display_dispatch(client->wl_display), 0); - assert(capt->state == CAPTURE_TASK_RETRY); + test_assert_enum(capt->state, CAPTURE_TASK_RETRY); capturer_destroy(capt); buffer_destroy(buf); @@ -284,21 +288,21 @@ TEST(retry_on_wrong_size) WESTON_CAPTURE_V1_SOURCE_FRAMEBUFFER); client_roundtrip(client); - assert(capt->events.format); - assert(capt->events.size); - assert(capt->state == CAPTURE_TASK_PENDING); - assert(capt->width > 5); - assert(capt->height > 5); - assert(!capt->events.reply); + test_assert_true(capt->events.format); + test_assert_true(capt->events.size); + test_assert_enum(capt->state, CAPTURE_TASK_PENDING); + test_assert_int_gt(capt->width, 5); + test_assert_int_gt(capt->height, 5); + test_assert_false(capt->events.reply); buf = create_shm_buffer(client, capt->width - 3, capt->height - 3, capt->drm_format); weston_capture_source_v1_capture(capt->source, buf->proxy); while (!capt->events.reply) - assert(wl_display_dispatch(client->wl_display) >= 0); + test_assert_int_ge(wl_display_dispatch(client->wl_display), 0); - assert(capt->state == CAPTURE_TASK_RETRY); + test_assert_enum(capt->state, CAPTURE_TASK_RETRY); capturer_destroy(capt); buffer_destroy(buf); @@ -321,18 +325,18 @@ TEST(writeback_on_headless_fails) WESTON_CAPTURE_V1_SOURCE_WRITEBACK); client_roundtrip(client); - assert(!capt->events.format); - assert(!capt->events.size); - assert(capt->state == CAPTURE_TASK_PENDING); + test_assert_false(capt->events.format); + test_assert_false(capt->events.size); + test_assert_enum(capt->state, CAPTURE_TASK_PENDING); /* Trying pixel source that is not available should fail immediately */ weston_capture_source_v1_capture(capt->source, buf->proxy); client_roundtrip(client); - assert(!capt->events.format); - assert(!capt->events.size); - assert(capt->state == CAPTURE_TASK_FAILED); - assert(strcmp(capt->last_failure, "source unavailable") == 0); + test_assert_false(capt->events.format); + test_assert_false(capt->events.size); + test_assert_enum(capt->state, CAPTURE_TASK_FAILED); + test_assert_str_eq(capt->last_failure, "source unavailable"); capturer_destroy(capt); buffer_destroy(buf); diff --git a/tests/output-damage-test.c b/tests/output-damage-test.c index fca6cb5f2..a01b7d07d 100644 --- a/tests/output-damage-test.c +++ b/tests/output-damage-test.c @@ -31,6 +31,7 @@ #include "weston-test-client-helper.h" #include "weston-test-fixture-compositor.h" +#include "weston-test-assert.h" #define RENDERERS(s, t) \ { \ @@ -199,7 +200,7 @@ TEST(output_damage) ret = asprintf(&refname, "output-damage_%d-%s", oargs->scale, oargs->transform_name); - assert(ret); + test_assert_int_ne(ret, 0); testlog("%s: %s\n", get_test_name(), refname); @@ -226,7 +227,7 @@ TEST(output_damage) match = false; } - assert(match); + test_assert_true(match); for (i = 0; i < COUNT_BUFS; i++) buffer_destroy(buf[i]); diff --git a/tests/output-decorations-test.c b/tests/output-decorations-test.c index e24f68528..c08c141b8 100644 --- a/tests/output-decorations-test.c +++ b/tests/output-decorations-test.c @@ -27,6 +27,7 @@ #include "weston-test-client-helper.h" #include "weston-test-fixture-compositor.h" +#include "weston-test-assert.h" static enum test_result_code fixture_setup(struct weston_test_harness *harness) @@ -76,7 +77,7 @@ TEST(output_decorations) img = image_convert_to_a8r8g8b8(shot->image); match = verify_image(img, "output-decorations", 0, NULL, 0); - assert(match); + test_assert_true(match); pixman_image_unref(img); buffer_destroy(shot); diff --git a/tests/output-transforms-test.c b/tests/output-transforms-test.c index 006ab35ae..21f640dca 100644 --- a/tests/output-transforms-test.c +++ b/tests/output-transforms-test.c @@ -31,6 +31,7 @@ #include "weston-test-client-helper.h" #include "weston-test-fixture-compositor.h" +#include "weston-test-assert.h" #define TRANSFORM(x) WL_OUTPUT_TRANSFORM_ ## x, #x #define RENDERERS(s, t) \ @@ -122,7 +123,7 @@ TEST_P(output_transform, my_buffer_args) ret = asprintf(&refname, "output_%d-%s_buffer_%d-%s", oargs->scale, oargs->transform_name, bargs->scale, bargs->transform_name); - assert(ret); + test_assert_int_ne(ret, 0); testlog("%s: %s\n", get_test_name(), refname); @@ -144,7 +145,7 @@ TEST_P(output_transform, my_buffer_args) move_client(client, 19, 19); match = verify_screen_content(client, refname, 0, NULL, 0, NULL); - assert(match); + test_assert_true(match); client_destroy(client); free(refname); diff --git a/tests/paint-node-test.c b/tests/paint-node-test.c index 33807a3cd..d269125b1 100644 --- a/tests/paint-node-test.c +++ b/tests/paint-node-test.c @@ -32,6 +32,7 @@ #include "libweston-internal.h" #include "weston-test-client-helper.h" #include "weston-test-fixture-compositor.h" +#include "weston-test-assert.h" static enum test_result_code fixture_setup(struct weston_test_harness *harness) @@ -90,7 +91,7 @@ TEST(top_surface_present_in_output_repaint) color_rgb888(&red, 255, 0, 0); client = create_client_and_test_surface(100, 50, 100, 100); - assert(client); + test_assert_ptr_not_null(client); /* move the pointer clearly away from our screenshooting area */ weston_test_move_pointer(client->test->weston_test, 0, 1, 0, 2, 30); @@ -110,31 +111,31 @@ TEST(top_surface_present_in_output_repaint) struct weston_surface *surface; struct weston_buffer *buffer; - assert(breakpoint->template_->breakpoint == - WESTON_TEST_BREAKPOINT_POST_REPAINT); + test_assert_enum(breakpoint->template_->breakpoint, + WESTON_TEST_BREAKPOINT_POST_REPAINT); compositor = breakpoint->compositor; head = breakpoint->resource; output = next_output(compositor, NULL); - assert(output == head->output); - assert(strcmp(output->name, "headless") == 0); - assert(!next_output(compositor, output)); + test_assert_ptr_eq(output, head->output); + test_assert_str_eq(output->name, "headless"); + test_assert_ptr_null(next_output(compositor, output)); /* check that our surface is top of the paint node list */ pnode = next_pnode_from_z(output, NULL); - assert(pnode); + test_assert_ptr_not_null(pnode); view = pnode->view; surface = view->surface; buffer = surface->buffer_ref.buffer; - assert(surface->resource); - assert(wl_resource_get_client(surface->resource) == - suite_data->wl_client); - assert(weston_view_is_mapped(view)); - assert(weston_surface_is_mapped(surface)); - assert(surface->width == 100); - assert(surface->height == 100); - assert(buffer->width == surface->width); - assert(buffer->height == surface->height); - assert(buffer->type == WESTON_BUFFER_SHM); + test_assert_ptr_not_null(surface->resource); + test_assert_ptr_eq(wl_resource_get_client(surface->resource), + suite_data->wl_client); + test_assert_true(weston_view_is_mapped(view)); + test_assert_true(weston_surface_is_mapped(surface)); + test_assert_s32_eq(surface->width, 100); + test_assert_s32_eq(surface->height, 100); + test_assert_s32_eq(buffer->width, surface->width); + test_assert_s32_eq(buffer->height, surface->height); + test_assert_enum(buffer->type, WESTON_BUFFER_SHM); } buffer_destroy(buf); @@ -151,7 +152,7 @@ TEST(test_surface_unmaps_on_null) color_rgb888(&red, 255, 0, 0); client = create_client_and_test_surface(100, 50, 100, 100); - assert(client); + test_assert_ptr_not_null(client); /* move the pointer clearly away from our screenshooting area */ weston_test_move_pointer(client->test->weston_test, 0, 1, 0, 2, 30); @@ -171,30 +172,30 @@ TEST(test_surface_unmaps_on_null) struct weston_surface *surface; struct weston_buffer *buffer; - assert(breakpoint->template_->breakpoint == - WESTON_TEST_BREAKPOINT_POST_REPAINT); + test_assert_enum(breakpoint->template_->breakpoint, + WESTON_TEST_BREAKPOINT_POST_REPAINT); compositor = breakpoint->compositor; head = breakpoint->resource; output = next_output(compositor, NULL); - assert(output == head->output); - assert(strcmp(output->name, "headless") == 0); - assert(!next_output(compositor, output)); + test_assert_ptr_eq(output, head->output); + test_assert_str_eq(output->name, "headless"); + test_assert_ptr_null(next_output(compositor, output)); /* check that our surface is top of the paint node list */ pnode = next_pnode_from_z(output, NULL); - assert(pnode); + test_assert_ptr_not_null(pnode); view = pnode->view; surface = view->surface; buffer = surface->buffer_ref.buffer; - assert(wl_resource_get_client(surface->resource) == - suite_data->wl_client); - assert(weston_view_is_mapped(view)); - assert(weston_surface_is_mapped(surface)); - assert(surface->width == 100); - assert(surface->height == 100); - assert(buffer->width == surface->width); - assert(buffer->height == surface->height); - assert(buffer->type == WESTON_BUFFER_SHM); + test_assert_ptr_eq(wl_resource_get_client(surface->resource), + suite_data->wl_client); + test_assert_true(weston_view_is_mapped(view)); + test_assert_true(weston_surface_is_mapped(surface)); + test_assert_s32_eq(surface->width, 100); + test_assert_s32_eq(surface->height, 100); + test_assert_s32_eq(buffer->width, surface->width); + test_assert_s32_eq(buffer->height, surface->height); + test_assert_enum(buffer->type, WESTON_BUFFER_SHM); REARM_BREAKPOINT(breakpoint); } @@ -211,24 +212,24 @@ TEST(test_surface_unmaps_on_null) struct weston_surface *surface; struct weston_buffer *buffer; - assert(breakpoint->template_->breakpoint == - WESTON_TEST_BREAKPOINT_POST_REPAINT); + test_assert_enum(breakpoint->template_->breakpoint, + WESTON_TEST_BREAKPOINT_POST_REPAINT); compositor = breakpoint->compositor; head = breakpoint->resource; output = next_output(compositor, NULL); - assert(output == head->output); - assert(strcmp(output->name, "headless") == 0); - assert(!next_output(compositor, output)); + test_assert_ptr_eq(output, head->output); + test_assert_str_eq(output->name, "headless"); + test_assert_ptr_null(next_output(compositor, output)); /* check that our NULL-buffer commit removed the surface from * view */ pnode = next_pnode_from_z(output, NULL); - assert(pnode); + test_assert_ptr_not_null(pnode); view = pnode->view; surface = view->surface; buffer = surface->buffer_ref.buffer; - assert(!surface->resource); - assert(buffer->type == WESTON_BUFFER_SOLID); + test_assert_ptr_null(surface->resource); + test_assert_enum(buffer->type, WESTON_BUFFER_SOLID); } buffer_destroy(buf); diff --git a/tests/plugin-registry-test.c b/tests/plugin-registry-test.c index 4c2468194..aea583293 100644 --- a/tests/plugin-registry-test.c +++ b/tests/plugin-registry-test.c @@ -25,13 +25,12 @@ #include "config.h" -#include - #include #include #include "weston-test-runner.h" #include "weston-test-fixture-compositor.h" +#include "weston-test-assert.h" static enum test_result_code fixture_setup(struct weston_test_harness *harness) @@ -65,20 +64,23 @@ static const struct my_api { static void init_tests(struct weston_compositor *compositor) { - assert(weston_plugin_api_get(compositor, MY_API_NAME, - sizeof(my_test_api)) == NULL); + test_assert_ptr_null(weston_plugin_api_get(compositor, MY_API_NAME, + sizeof(my_test_api))); - assert(weston_plugin_api_register(compositor, MY_API_NAME, &my_test_api, - sizeof(my_test_api)) == 0); + test_assert_int_eq(weston_plugin_api_register(compositor, MY_API_NAME, + &my_test_api, + sizeof(my_test_api)), 0); - assert(weston_plugin_api_register(compositor, MY_API_NAME, &my_test_api, - sizeof(my_test_api)) == -2); + test_assert_int_eq(weston_plugin_api_register(compositor, MY_API_NAME, + &my_test_api, + sizeof(my_test_api)), -2); - assert(weston_plugin_api_get(compositor, MY_API_NAME, - sizeof(my_test_api)) == &my_test_api); + test_assert_ptr_eq(weston_plugin_api_get(compositor, MY_API_NAME, + sizeof(my_test_api)), &my_test_api); - assert(weston_plugin_api_register(compositor, "another", &my_test_api, - sizeof(my_test_api)) == 0); + test_assert_int_eq(weston_plugin_api_register(compositor, "another", + &my_test_api, + sizeof(my_test_api)), 0); } PLUGIN_TEST(plugin_registry_test) @@ -89,14 +91,15 @@ PLUGIN_TEST(plugin_registry_test) init_tests(compositor); - assert(weston_plugin_api_get(compositor, MY_API_NAME, sz) == - &my_test_api); + test_assert_ptr_eq(weston_plugin_api_get(compositor, MY_API_NAME, sz), + &my_test_api); - assert(weston_plugin_api_get(compositor, MY_API_NAME, sz - 4) == - &my_test_api); + test_assert_ptr_eq(weston_plugin_api_get(compositor, MY_API_NAME, sz - 4), + &my_test_api); - assert(weston_plugin_api_get(compositor, MY_API_NAME, sz + 4) == NULL); + test_assert_ptr_null(weston_plugin_api_get(compositor, MY_API_NAME, sz + 4)); api = weston_plugin_api_get(compositor, MY_API_NAME, sz); - assert(api && api->func2 == dummy_func); + test_assert_ptr_not_null(api); + test_assert_ptr_eq(api->func2, dummy_func); } diff --git a/tests/pointer-shot-test.c b/tests/pointer-shot-test.c index 1ce806ccb..085eba53c 100644 --- a/tests/pointer-shot-test.c +++ b/tests/pointer-shot-test.c @@ -32,6 +32,7 @@ #include "shared/timespec-util.h" #include "weston-test-client-helper.h" #include "weston-test-fixture-compositor.h" +#include "weston-test-assert.h" struct setup_args { struct fixture_metadata meta; @@ -93,7 +94,7 @@ surface_commit_color(struct client *client, struct surface *surface, wl_surface_damage(surface->wl_surface, 0, 0, width, height); wl_surface_commit(surface->wl_surface); - assert(!surface->buffer); + test_assert_ptr_null(surface->buffer); surface->buffer = buf; return buf; @@ -151,7 +152,7 @@ TEST(pointer_cursor_retains_committed_buffer_after_reenter) main_cursor_surface->wl_surface, 0, 0); match = verify_screen_content(client, "pointer_cursor_reenter", 0, NULL, 0, NULL); - assert(match); + test_assert_true(match); /* Move the cursor just outside the main surface. */ send_motion(client, &t2, 150, 150); @@ -160,7 +161,7 @@ TEST(pointer_cursor_retains_committed_buffer_after_reenter) back_cursor_surface->wl_surface, 0, 0); match = verify_screen_content(client, "pointer_cursor_reenter", 1, NULL, 1, NULL); - assert(match); + test_assert_true(match); /* And back in the main surface again. */ send_motion(client, &t3, 149, 149); @@ -169,7 +170,7 @@ TEST(pointer_cursor_retains_committed_buffer_after_reenter) main_cursor_surface->wl_surface, 0, 0); match = verify_screen_content(client, "pointer_cursor_reenter", 2, NULL, 2, NULL); - assert(match); + test_assert_true(match); surface_destroy(back_cursor_surface); surface_destroy(main_cursor_surface); diff --git a/tests/pointer-test.c b/tests/pointer-test.c index c6f76b5a1..6ddb8d7d9 100644 --- a/tests/pointer-test.c +++ b/tests/pointer-test.c @@ -32,6 +32,7 @@ #include "shared/timespec-util.h" #include "weston-test-client-helper.h" #include "weston-test-fixture-compositor.h" +#include "weston-test-assert.h" static enum test_result_code fixture_setup(struct weston_test_harness *harness) @@ -92,13 +93,14 @@ check_pointer(struct client *client, int x, int y) int sx, sy; /* check that the client got the global pointer update */ - assert(client->test->pointer_x == x); - assert(client->test->pointer_y == y); + test_assert_int_eq(client->test->pointer_x, x); + test_assert_int_eq(client->test->pointer_y, y); /* Does global pointer map onto the surface? */ if (surface_contains(client->surface, x, y)) { /* check that the surface has the pointer focus */ - assert(client->input->pointer->focus == client->surface); + test_assert_ptr_eq(client->input->pointer->focus, + client->surface); /* * check that the local surface pointer maps @@ -106,14 +108,14 @@ check_pointer(struct client *client, int x, int y) */ sx = client->input->pointer->x + client->surface->x; sy = client->input->pointer->y + client->surface->y; - assert(sx == x); - assert(sy == y); + test_assert_int_eq(sx, x); + test_assert_int_eq(sy, y); } else { /* * The global pointer does not map onto surface. So * check that it doesn't have the pointer focus. */ - assert(client->input->pointer->focus == NULL); + test_assert_ptr_null(client->input->pointer->focus); } } @@ -128,7 +130,7 @@ static struct client * create_client_with_pointer_focus(int x, int y, int w, int h) { struct client *cl = create_client_and_test_surface(x, y, w, h); - assert(cl); + test_assert_ptr_not_null(cl); /* Move the pointer inside the surface to ensure that the surface * has the pointer focus. */ check_pointer_move(cl, x, y); @@ -141,22 +143,22 @@ TEST(test_pointer_top_left) int x, y; client = create_client_and_test_surface(46, 76, 111, 134); - assert(client); + test_assert_ptr_not_null(client); /* move pointer outside top left */ x = client->surface->x - 1; y = client->surface->y - 1; - assert(!surface_contains(client->surface, x, y)); + test_assert_false(surface_contains(client->surface, x, y)); check_pointer_move(client, x, y); /* move pointer on top left */ x += 1; y += 1; - assert(surface_contains(client->surface, x, y)); + test_assert_true(surface_contains(client->surface, x, y)); check_pointer_move(client, x, y); /* move pointer outside top left */ x -= 1; y -= 1; - assert(!surface_contains(client->surface, x, y)); + test_assert_false(surface_contains(client->surface, x, y)); check_pointer_move(client, x, y); client_destroy(client); @@ -168,22 +170,22 @@ TEST(test_pointer_bottom_left) int x, y; client = create_client_and_test_surface(99, 100, 100, 98); - assert(client); + test_assert_ptr_not_null(client); /* move pointer outside bottom left */ x = client->surface->x - 1; y = client->surface->y + client->surface->height; - assert(!surface_contains(client->surface, x, y)); + test_assert_false(surface_contains(client->surface, x, y)); check_pointer_move(client, x, y); /* move pointer on bottom left */ x += 1; y -= 1; - assert(surface_contains(client->surface, x, y)); + test_assert_true(surface_contains(client->surface, x, y)); check_pointer_move(client, x, y); /* move pointer outside bottom left */ x -= 1; y += 1; - assert(!surface_contains(client->surface, x, y)); + test_assert_false(surface_contains(client->surface, x, y)); check_pointer_move(client, x, y); client_destroy(client); @@ -195,22 +197,22 @@ TEST(test_pointer_top_right) int x, y; client = create_client_and_test_surface(48, 100, 67, 100); - assert(client); + test_assert_ptr_not_null(client); /* move pointer outside top right */ x = client->surface->x + client->surface->width; y = client->surface->y - 1; - assert(!surface_contains(client->surface, x, y)); + test_assert_false(surface_contains(client->surface, x, y)); check_pointer_move(client, x, y); /* move pointer on top right */ x -= 1; y += 1; - assert(surface_contains(client->surface, x, y)); + test_assert_true(surface_contains(client->surface, x, y)); check_pointer_move(client, x, y); /* move pointer outside top right */ x += 1; y -= 1; - assert(!surface_contains(client->surface, x, y)); + test_assert_false(surface_contains(client->surface, x, y)); check_pointer_move(client, x, y); client_destroy(client); @@ -222,22 +224,22 @@ TEST(test_pointer_bottom_right) int x, y; client = create_client_and_test_surface(100, 123, 100, 69); - assert(client); + test_assert_ptr_not_null(client); /* move pointer outside bottom right */ x = client->surface->x + client->surface->width; y = client->surface->y + client->surface->height; - assert(!surface_contains(client->surface, x, y)); + test_assert_false(surface_contains(client->surface, x, y)); check_pointer_move(client, x, y); /* move pointer on bottom right */ x -= 1; y -= 1; - assert(surface_contains(client->surface, x, y)); + test_assert_true(surface_contains(client->surface, x, y)); check_pointer_move(client, x, y); /* move pointer outside bottom right */ x += 1; y += 1; - assert(!surface_contains(client->surface, x, y)); + test_assert_false(surface_contains(client->surface, x, y)); check_pointer_move(client, x, y); client_destroy(client); @@ -249,22 +251,22 @@ TEST(test_pointer_top_center) int x, y; client = create_client_and_test_surface(100, 201, 100, 50); - assert(client); + test_assert_ptr_not_null(client); /* move pointer outside top center */ x = client->surface->x + client->surface->width/2; y = client->surface->y - 1; - assert(!surface_contains(client->surface, x, y)); + test_assert_false(surface_contains(client->surface, x, y)); check_pointer_move(client, x, y); /* move pointer on top center */ y += 1; - assert(surface_contains(client->surface, x, y)); + test_assert_true(surface_contains(client->surface, x, y)); check_pointer_move(client, x, y); /* move pointer outside top center */ y -= 1; - assert(!surface_contains(client->surface, x, y)); + test_assert_false(surface_contains(client->surface, x, y)); check_pointer_move(client, x, y); client_destroy(client); @@ -276,22 +278,22 @@ TEST(test_pointer_bottom_center) int x, y; client = create_client_and_test_surface(100, 45, 67, 100); - assert(client); + test_assert_ptr_not_null(client); /* move pointer outside bottom center */ x = client->surface->x + client->surface->width/2; y = client->surface->y + client->surface->height; - assert(!surface_contains(client->surface, x, y)); + test_assert_false(surface_contains(client->surface, x, y)); check_pointer_move(client, x, y); /* move pointer on bottom center */ y -= 1; - assert(surface_contains(client->surface, x, y)); + test_assert_true(surface_contains(client->surface, x, y)); check_pointer_move(client, x, y); /* move pointer outside bottom center */ y += 1; - assert(!surface_contains(client->surface, x, y)); + test_assert_false(surface_contains(client->surface, x, y)); check_pointer_move(client, x, y); client_destroy(client); @@ -303,22 +305,22 @@ TEST(test_pointer_left_center) int x, y; client = create_client_and_test_surface(167, 45, 78, 100); - assert(client); + test_assert_ptr_not_null(client); /* move pointer outside left center */ x = client->surface->x - 1; y = client->surface->y + client->surface->height/2; - assert(!surface_contains(client->surface, x, y)); + test_assert_false(surface_contains(client->surface, x, y)); check_pointer_move(client, x, y); /* move pointer on left center */ x += 1; - assert(surface_contains(client->surface, x, y)); + test_assert_true(surface_contains(client->surface, x, y)); check_pointer_move(client, x, y); /* move pointer outside left center */ x -= 1; - assert(!surface_contains(client->surface, x, y)); + test_assert_false(surface_contains(client->surface, x, y)); check_pointer_move(client, x, y); client_destroy(client); @@ -330,22 +332,22 @@ TEST(test_pointer_right_center) int x, y; client = create_client_and_test_surface(110, 37, 100, 46); - assert(client); + test_assert_ptr_not_null(client); /* move pointer outside right center */ x = client->surface->x + client->surface->width; y = client->surface->y + client->surface->height/2; - assert(!surface_contains(client->surface, x, y)); + test_assert_false(surface_contains(client->surface, x, y)); check_pointer_move(client, x, y); /* move pointer on right center */ x -= 1; - assert(surface_contains(client->surface, x, y)); + test_assert_true(surface_contains(client->surface, x, y)); check_pointer_move(client, x, y); /* move pointer outside right center */ x += 1; - assert(!surface_contains(client->surface, x, y)); + test_assert_false(surface_contains(client->surface, x, y)); check_pointer_move(client, x, y); client_destroy(client); @@ -356,15 +358,15 @@ TEST(test_pointer_surface_move) struct client *client; client = create_client_and_test_surface(100, 100, 100, 100); - assert(client); + test_assert_ptr_not_null(client); /* move pointer outside of client */ - assert(!surface_contains(client->surface, 50, 50)); + test_assert_false(surface_contains(client->surface, 50, 50)); check_pointer_move(client, 50, 50); /* move client center to pointer */ move_client_frame_sync(client, 0, 0); - assert(surface_contains(client->surface, 50, 50)); + test_assert_true(surface_contains(client->surface, 50, 50)); check_pointer(client, 50, 50); client_destroy(client); @@ -379,10 +381,10 @@ TEST(pointer_motion_events) input_timestamps_create_for_pointer(client); send_motion(client, &t1, 150, 150); - assert(pointer->x == 50); - assert(pointer->y == 50); - assert(pointer->motion_time_msec == timespec_to_msec(&t1)); - assert(timespec_eq(&pointer->motion_time_timespec, &t1)); + test_assert_int_eq(pointer->x, 50); + test_assert_int_eq(pointer->y, 50); + test_assert_s64_eq(pointer->motion_time_msec, timespec_to_msec(&t1)); + test_assert_true(timespec_eq(&pointer->motion_time_timespec, &t1)); input_timestamps_destroy(input_ts); @@ -397,20 +399,20 @@ TEST(pointer_button_events) struct input_timestamps *input_ts = input_timestamps_create_for_pointer(client); - assert(pointer->button == 0); - assert(pointer->state == 0); + test_assert_u32_eq(pointer->button, 0); + test_assert_u32_eq(pointer->state, 0); send_button(client, &t1, BTN_LEFT, WL_POINTER_BUTTON_STATE_PRESSED); - assert(pointer->button == BTN_LEFT); - assert(pointer->state == WL_POINTER_BUTTON_STATE_PRESSED); - assert(pointer->button_time_msec == timespec_to_msec(&t1)); - assert(timespec_eq(&pointer->button_time_timespec, &t1)); + test_assert_enum(pointer->button, BTN_LEFT); + test_assert_enum(pointer->state, WL_POINTER_BUTTON_STATE_PRESSED); + test_assert_s64_eq(pointer->button_time_msec, timespec_to_msec(&t1)); + test_assert_true(timespec_eq(&pointer->button_time_timespec, &t1)); send_button(client, &t2, BTN_LEFT, WL_POINTER_BUTTON_STATE_RELEASED); - assert(pointer->button == BTN_LEFT); - assert(pointer->state == WL_POINTER_BUTTON_STATE_RELEASED); - assert(pointer->button_time_msec == timespec_to_msec(&t2)); - assert(timespec_eq(&pointer->button_time_timespec, &t2)); + test_assert_enum(pointer->button, BTN_LEFT); + test_assert_enum(pointer->state, WL_POINTER_BUTTON_STATE_RELEASED); + test_assert_s64_eq(pointer->button_time_msec, timespec_to_msec(&t2)); + test_assert_true(timespec_eq(&pointer->button_time_timespec, &t2)); input_timestamps_destroy(input_ts); @@ -426,15 +428,15 @@ TEST(pointer_axis_events) input_timestamps_create_for_pointer(client); send_axis(client, &t1, 1, 1.0); - assert(pointer->axis == 1); - assert(pointer->axis_value == 1.0); - assert(pointer->axis_time_msec == timespec_to_msec(&t1)); - assert(timespec_eq(&pointer->axis_time_timespec, &t1)); + test_assert_u32_eq(pointer->axis, 1); + test_assert_f64_eq(pointer->axis_value, 1.0); + test_assert_s64_eq(pointer->axis_time_msec, timespec_to_msec(&t1)); + test_assert_true(timespec_eq(&pointer->axis_time_timespec, &t1)); send_axis(client, &t2, 2, 0.0); - assert(pointer->axis == 2); - assert(pointer->axis_stop_time_msec == timespec_to_msec(&t2)); - assert(timespec_eq(&pointer->axis_stop_time_timespec, &t2)); + test_assert_u32_eq(pointer->axis, 2); + test_assert_s64_eq(pointer->axis_stop_time_msec, timespec_to_msec(&t2)); + test_assert_true(timespec_eq(&pointer->axis_stop_time_timespec, &t2)); input_timestamps_destroy(input_ts); @@ -450,18 +452,18 @@ TEST(pointer_timestamps_stop_after_input_timestamps_object_is_destroyed) input_timestamps_create_for_pointer(client); send_button(client, &t1, BTN_LEFT, WL_POINTER_BUTTON_STATE_PRESSED); - assert(pointer->button == BTN_LEFT); - assert(pointer->state == WL_POINTER_BUTTON_STATE_PRESSED); - assert(pointer->button_time_msec == timespec_to_msec(&t1)); - assert(timespec_eq(&pointer->button_time_timespec, &t1)); + test_assert_enum(pointer->button, BTN_LEFT); + test_assert_enum(pointer->state, WL_POINTER_BUTTON_STATE_PRESSED); + test_assert_s64_eq(pointer->button_time_msec, timespec_to_msec(&t1)); + test_assert_true(timespec_eq(&pointer->button_time_timespec, &t1)); input_timestamps_destroy(input_ts); send_button(client, &t2, BTN_LEFT, WL_POINTER_BUTTON_STATE_RELEASED); - assert(pointer->button == BTN_LEFT); - assert(pointer->state == WL_POINTER_BUTTON_STATE_RELEASED); - assert(pointer->button_time_msec == timespec_to_msec(&t2)); - assert(timespec_is_zero(&pointer->button_time_timespec)); + test_assert_enum(pointer->button, BTN_LEFT); + test_assert_enum(pointer->state, WL_POINTER_BUTTON_STATE_RELEASED); + test_assert_s64_eq(pointer->button_time_msec, timespec_to_msec(&t2)); + test_assert_true(timespec_is_zero(&pointer->button_time_timespec)); client_destroy(client); } @@ -475,10 +477,10 @@ TEST(pointer_timestamps_stop_after_client_releases_wl_pointer) input_timestamps_create_for_pointer(client); send_motion(client, &t1, 150, 150); - assert(pointer->x == 50); - assert(pointer->y == 50); - assert(pointer->motion_time_msec == timespec_to_msec(&t1)); - assert(timespec_eq(&pointer->motion_time_timespec, &t1)); + test_assert_int_eq(pointer->x, 50); + test_assert_int_eq(pointer->y, 50); + test_assert_s64_eq(pointer->motion_time_msec, timespec_to_msec(&t1)); + test_assert_true(timespec_eq(&pointer->motion_time_timespec, &t1)); wl_pointer_release(client->input->pointer->wl_pointer); @@ -489,7 +491,7 @@ TEST(pointer_timestamps_stop_after_client_releases_wl_pointer) * event and checking for it here may lead to false negatives. */ pointer->input_timestamp = t_other; send_motion(client, &t2, 175, 175); - assert(timespec_eq(&pointer->input_timestamp, &t_other)); + test_assert_true(timespec_eq(&pointer->input_timestamp, &t_other)); input_timestamps_destroy(input_ts); diff --git a/tests/presentation-test.c b/tests/presentation-test.c index 3ffedd1f4..22707ad24 100644 --- a/tests/presentation-test.c +++ b/tests/presentation-test.c @@ -29,7 +29,6 @@ #include #include #include -#include #include #include "shared/helpers.h" @@ -38,6 +37,7 @@ #include "weston-test-client-helper.h" #include "presentation-time-client-protocol.h" #include "weston-test-fixture-compositor.h" +#include "weston-test-assert.h" static enum test_result_code fixture_setup(struct weston_test_harness *harness) @@ -64,18 +64,18 @@ get_presentation(struct client *client) continue; if (global_pres) - assert(0 && "multiple presentation objects"); + test_assert_not_reached("multiple presentation objects"); global_pres = g; } - assert(global_pres && "no presentation found"); + test_assert_ptr_not_null(global_pres); - assert(global_pres->version == 1); + test_assert_u32_eq(global_pres->version, 1); pres = wl_registry_bind(client->wl_registry, global_pres->name, &wp_presentation_interface, 1); - assert(pres); + test_assert_ptr_not_null(pres); return pres; } @@ -104,7 +104,7 @@ feedback_sync_output(void *data, { struct feedback *fb = data; - assert(fb->result == FB_PENDING); + test_assert_enum(fb->result, FB_PENDING); if (output) fb->sync_output = output; @@ -123,7 +123,7 @@ feedback_presented(void *data, { struct feedback *fb = data; - assert(fb->result == FB_PENDING); + test_assert_enum(fb->result, FB_PENDING); fb->result = FB_PRESENTED; fb->seq = u64_from_u32s(seq_hi, seq_lo); timespec_from_proto(&fb->time, tv_sec_hi, tv_sec_lo, tv_nsec); @@ -137,7 +137,7 @@ feedback_discarded(void *data, { struct feedback *fb = data; - assert(fb->result == FB_PENDING); + test_assert_enum(fb->result, FB_PENDING); fb->result = FB_DISCARDED; } @@ -166,7 +166,7 @@ static void feedback_wait(struct feedback *fb) { while (fb->result == FB_PENDING) { - assert(wl_display_dispatch(fb->client->wl_display) >= 0); + test_assert_int_ge(wl_display_dispatch(fb->client->wl_display), 0); } } @@ -231,7 +231,7 @@ TEST(test_presentation_feedback_simple) struct wp_presentation *pres; client = create_client_and_test_surface(100, 50, 123, 77); - assert(client); + test_assert_ptr_not_null(client); pres = get_presentation(client); wl_surface_attach(client->surface->wl_surface, diff --git a/tests/roles-test.c b/tests/roles-test.c index d687ee225..ce2e56e7a 100644 --- a/tests/roles-test.c +++ b/tests/roles-test.c @@ -27,10 +27,10 @@ #include #include -#include #include "weston-test-client-helper.h" #include "weston-test-fixture-compositor.h" +#include "weston-test-assert.h" #include "xdg-shell-client-protocol.h" @@ -60,18 +60,18 @@ get_subcompositor(struct client *client) continue; if (global_sub) - assert(0 && "multiple wl_subcompositor objects"); + test_assert_not_reached("multiple wl_subcompositor objects"); global_sub = g; } - assert(global_sub && "no wl_subcompositor found"); + test_assert_ptr_not_null(global_sub); - assert(global_sub->version == 1); + test_assert_u32_eq(global_sub->version, 1); sub = wl_registry_bind(client->wl_registry, global_sub->name, &wl_subcompositor_interface, 1); - assert(sub); + test_assert_ptr_not_null(sub); return sub; } @@ -88,16 +88,16 @@ get_xdg_wm_base(struct client *client) continue; if (global) - assert(0 && "multiple xdg_wm_base objects"); + test_assert_not_reached("multiple xdg_wm_base objects"); global = g; } - assert(global && "no xdg_wm_base found"); + test_assert_ptr_not_null(global); xdg_wm_base = wl_registry_bind(client->wl_registry, global->name, &xdg_wm_base_interface, 1); - assert(xdg_wm_base); + test_assert_ptr_not_null(xdg_wm_base); return xdg_wm_base; } @@ -112,19 +112,19 @@ TEST(test_role_conflict_sub_wlshell) struct xdg_surface *xdg_surface; client = create_client_and_test_surface(100, 50, 123, 77); - assert(client); + test_assert_ptr_not_null(client); subco = get_subcompositor(client); xdg_wm_base = get_xdg_wm_base(client); child = wl_compositor_create_surface(client->wl_compositor); - assert(child); + test_assert_ptr_not_null(child); sub = wl_subcompositor_get_subsurface(subco, child, client->surface->wl_surface); - assert(sub); + test_assert_ptr_not_null(sub); xdg_surface = xdg_wm_base_get_xdg_surface(xdg_wm_base, child); - assert(xdg_surface); + test_assert_ptr_not_null(xdg_surface); expect_protocol_error(client, &xdg_wm_base_interface, XDG_WM_BASE_ERROR_ROLE); @@ -148,21 +148,21 @@ TEST(test_role_conflict_wlshell_sub) struct xdg_toplevel *xdg_toplevel; client = create_client_and_test_surface(100, 50, 123, 77); - assert(client); + test_assert_ptr_not_null(client); subco = get_subcompositor(client); xdg_wm_base = get_xdg_wm_base(client); child = wl_compositor_create_surface(client->wl_compositor); - assert(child); + test_assert_ptr_not_null(child); xdg_surface = xdg_wm_base_get_xdg_surface(xdg_wm_base, child); - assert(xdg_surface); + test_assert_ptr_not_null(xdg_surface); xdg_toplevel = xdg_surface_get_toplevel(xdg_surface); - assert(xdg_toplevel); + test_assert_ptr_not_null(xdg_toplevel); sub = wl_subcompositor_get_subsurface(subco, child, client->surface->wl_surface); - assert(sub); + test_assert_ptr_not_null(sub); expect_protocol_error(client, &wl_subcompositor_interface, WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE); diff --git a/tests/safe-signal-output-removal-test.c b/tests/safe-signal-output-removal-test.c index c5baafd39..5385b5c9e 100644 --- a/tests/safe-signal-output-removal-test.c +++ b/tests/safe-signal-output-removal-test.c @@ -25,7 +25,6 @@ #include "config.h" #include -#include #include #include diff --git a/tests/safe-signal-test.c b/tests/safe-signal-test.c index 50ca10852..4fa4bc72f 100644 --- a/tests/safe-signal-test.c +++ b/tests/safe-signal-test.c @@ -25,7 +25,6 @@ #include "config.h" #include -#include #include #include diff --git a/tests/shm-buffer-test.c b/tests/shm-buffer-test.c index bb2c97cca..2ccd00746 100644 --- a/tests/shm-buffer-test.c +++ b/tests/shm-buffer-test.c @@ -106,13 +106,13 @@ shm_buffer_create(struct client *client, buf->height = height; fd = os_create_anonymous_file(buf->bytes); - assert(fd >= 0); + test_assert_int_ge(fd, 0); buf->data = mmap(NULL, buf->bytes, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (buf->data == MAP_FAILED) { close(fd); - assert(buf->data != MAP_FAILED); + test_assert_not_reached("mmap() failed"); } pool = wl_shm_create_pool(client->wl_shm, fd, buf->bytes); @@ -128,7 +128,7 @@ static void shm_buffer_destroy(struct shm_buffer *buf) { wl_buffer_destroy(buf->proxy); - assert(munmap(buf->data, buf->bytes) == 0); + test_assert_int_eq(munmap(buf->data, buf->bytes), 0); free(buf); } @@ -199,7 +199,7 @@ rgba4444_create_buffer(struct client *client, idx = 3; break; default: - assert(0 && "Invalid format!"); + test_assert_not_reached("Invalid format!"); }; buf = shm_buffer_create(client, src.width * src.height * 2, src.width, @@ -248,10 +248,10 @@ rgba5551_create_buffer(struct client *client, int x, y; uint16_t a; - assert(drm_format == DRM_FORMAT_RGBX5551 || - drm_format == DRM_FORMAT_RGBA5551 || - drm_format == DRM_FORMAT_BGRX5551 || - drm_format == DRM_FORMAT_BGRA5551); + test_assert_true(drm_format == DRM_FORMAT_RGBX5551 || + drm_format == DRM_FORMAT_RGBA5551 || + drm_format == DRM_FORMAT_BGRX5551 || + drm_format == DRM_FORMAT_BGRA5551); buf = shm_buffer_create(client, src.width * src.height * 2, src.width, src.height, src.width * 2, drm_format); @@ -296,8 +296,8 @@ rgb565_create_buffer(struct client *client, struct shm_buffer *buf; int x, y; - assert(drm_format == DRM_FORMAT_RGB565 || - drm_format == DRM_FORMAT_BGR565); + test_assert_true(drm_format == DRM_FORMAT_RGB565 || + drm_format == DRM_FORMAT_BGR565); buf = shm_buffer_create(client, src.width * src.height * 2, src.width, src.height, src.width * 2, drm_format); @@ -336,8 +336,8 @@ rgb888_create_buffer(struct client *client, struct shm_buffer *buf; int x, y; - assert(drm_format == DRM_FORMAT_RGB888 || - drm_format == DRM_FORMAT_BGR888); + test_assert_true(drm_format == DRM_FORMAT_RGB888 || + drm_format == DRM_FORMAT_BGR888); buf = shm_buffer_create(client, src.width * src.height * 3, src.width, src.height, src.width * 3, drm_format); @@ -433,7 +433,7 @@ rgba8888_create_buffer(struct client *client, idx = 3; break; default: - assert(0 && "Invalid format!"); + test_assert_not_reached("Invalid format!"); }; buf = shm_buffer_create(client, src.width * src.height * 4, src.width, @@ -482,10 +482,10 @@ rgba2101010_create_buffer(struct client *client, int x, y; uint32_t a; - assert(drm_format == DRM_FORMAT_XRGB2101010 || - drm_format == DRM_FORMAT_ARGB2101010 || - drm_format == DRM_FORMAT_XBGR2101010 || - drm_format == DRM_FORMAT_ABGR2101010); + test_assert_true(drm_format == DRM_FORMAT_XRGB2101010 || + drm_format == DRM_FORMAT_ARGB2101010 || + drm_format == DRM_FORMAT_XBGR2101010 || + drm_format == DRM_FORMAT_ABGR2101010); buf = shm_buffer_create(client, src.width * src.height * 4, src.width, src.height, src.width * 4, drm_format); @@ -558,7 +558,7 @@ rgba16161616_create_buffer(struct client *client, idx = 1; break; default: - assert(0 && "Invalid format!"); + test_assert_not_reached("Invalid format!"); }; buf = shm_buffer_create(client, src.width * src.height * 8, src.width, @@ -654,7 +654,7 @@ rgba16161616f_create_buffer(struct client *client, idx = 1; break; default: - assert(0 && "Invalid format!"); + test_assert_not_reached("Invalid format!"); }; buf = shm_buffer_create(client, src.width * src.height * 8, src.width, @@ -739,7 +739,8 @@ x8r8g8b8_to_ycbcr16_bt709(uint32_t xrgb, int depth, /* Rec. ITU-R BT.709-6 defines D as 1 or 4 for 8-bit or 10-bit * quantization respectively. We extrapolate here to [9, 16]-bit depths * by setting D to 2^(depth - 8). */ - assert(depth >= 9 && depth <= 16); + test_assert_int_ge(depth, 9); + test_assert_int_le(depth, 16); d = 1 << (depth - 8); /* normalize to [0.0, 1.0] */ @@ -796,10 +797,10 @@ y_u_v_create_buffer(struct client *client, int sub = (drm_format == DRM_FORMAT_YUV420 || drm_format == DRM_FORMAT_YVU420) ? 2 : 1; - assert(drm_format == DRM_FORMAT_YUV420 || - drm_format == DRM_FORMAT_YVU420 || - drm_format == DRM_FORMAT_YUV444 || - drm_format == DRM_FORMAT_YVU444); + test_assert_true(drm_format == DRM_FORMAT_YUV420 || + drm_format == DRM_FORMAT_YVU420 || + drm_format == DRM_FORMAT_YUV444 || + drm_format == DRM_FORMAT_YVU444); /* Full size Y plus quarter U and V */ bytes = rgb.width * rgb.height + @@ -817,7 +818,7 @@ y_u_v_create_buffer(struct client *client, v_base = y_base + rgb.width * rgb.height; u_base = v_base + (rgb.width / sub) * (rgb.height / sub); } else { - assert(0 && "Invalid format!"); + test_assert_not_reached("Invalid format!"); } for (y = 0; y < rgb.height; y++) { @@ -895,7 +896,7 @@ nv12_create_buffer(struct client *client, idx = 1; break; default: - assert(0 && "Invalid format!"); + test_assert_not_reached("Invalid format!"); }; /* Full size Y, quarter UV */ @@ -982,7 +983,7 @@ nv16_create_buffer(struct client *client, idx = 1; break; default: - assert(0 && "Invalid format!"); + test_assert_not_reached("Invalid format!"); }; /* Full size Y, horizontally subsampled UV */ @@ -1069,7 +1070,7 @@ nv24_create_buffer(struct client *client, idx = 1; break; default: - assert(0 && "Invalid format!"); + test_assert_not_reached("Invalid format!"); }; /* Full size Y, non-subsampled UV */ @@ -1157,7 +1158,7 @@ yuyv_create_buffer(struct client *client, idx = 3; break; default: - assert(0 && "Invalid format!"); + test_assert_not_reached("Invalid format!"); }; /* Full size Y, horizontally subsampled UV, 2 pixels in 32 bits */ @@ -1211,7 +1212,7 @@ xyuv8888_create_buffer(struct client *client, uint8_t cb; uint8_t y0; - assert(drm_format == DRM_FORMAT_XYUV8888); + test_assert_enum(drm_format, DRM_FORMAT_XYUV8888); /* Full size, 32 bits per pixel */ bytes = rgb.width * rgb.height * sizeof(uint32_t); @@ -1290,7 +1291,7 @@ p016_create_buffer(struct client *client, depth = 10; break; default: - assert(0 && "Invalid format!"); + test_assert_not_reached("Invalid format!"); }; /* Full size Y, quarter UV */ @@ -1450,7 +1451,7 @@ TEST_P(shm_buffer, shm_cases) fname = image_filename("chocolate-cake"); img = load_image_from_png(fname); free(fname); - assert(img); + test_assert_ptr_not_null(img); client = create_client(); client->surface = create_test_surface(client); @@ -1464,7 +1465,7 @@ TEST_P(shm_buffer, shm_cases) match = verify_screen_content(client, "shm-buffer", my_case->ref_seq_no, NULL, 0, NULL); - assert(match); + test_assert_true(match); shm_buffer_destroy(buf); diff --git a/tests/single-pixel-buffer-test.c b/tests/single-pixel-buffer-test.c index b091a1743..c39dc51bf 100644 --- a/tests/single-pixel-buffer-test.c +++ b/tests/single-pixel-buffer-test.c @@ -33,6 +33,7 @@ #include "weston-test-client-helper.h" #include "weston-test-fixture-compositor.h" +#include "weston-test-assert.h" #include "single-pixel-buffer-v1-client-protocol.h" #include "shared/os-compatibility.h" #include "shared/xalloc.h" @@ -92,7 +93,7 @@ TEST(solid_buffer_argb_u32) 0x8fffffff, /* g */ 0x4fffffff, /* b */ 0xffffffff /* a */); - assert(buffer); + test_assert_ptr_not_null(buffer); weston_test_move_surface(client->test->weston_test, client->surface->wl_surface, @@ -104,7 +105,7 @@ TEST(solid_buffer_argb_u32) frame_callback_wait(client, &done); match = verify_screen_content(client, "single-pixel-buffer", 0, NULL, 0, NULL); - assert(match); + test_assert_true(match); wl_buffer_destroy(buffer); wp_viewport_destroy(viewport); diff --git a/tests/string-test.c b/tests/string-test.c index 5571b5282..fe00cbf62 100644 --- a/tests/string-test.c +++ b/tests/string-test.c @@ -29,11 +29,11 @@ #include #include #include -#include #include "shared/string-helpers.h" #include "weston-test-client-helper.h" +#include "weston-test-assert.h" TEST(strtol_conversions) { @@ -43,46 +43,46 @@ TEST(strtol_conversions) str = ""; val = -1; ret = safe_strtoint(str, &val); - assert(ret == false); - assert(val == -1); + test_assert_false(ret); + test_assert_s32_eq(val, -1); str = "."; val = -1; ret = safe_strtoint(str, &val); - assert(ret == false); - assert(val == -1); + test_assert_false(ret); + test_assert_s32_eq(val, -1); str = "42"; val = -1; ret = safe_strtoint(str, &val); - assert(ret == true); - assert(val == 42); + test_assert_true(ret); + test_assert_s32_eq(val, 42); str = "-42"; val = -1; ret = safe_strtoint(str, &val); - assert(ret == true); - assert(val == -42); + test_assert_true(ret); + test_assert_s32_eq(val, -42); str = "0042"; val = -1; ret = safe_strtoint(str, &val); - assert(ret == true); - assert(val == 42); + test_assert_true(ret); + test_assert_s32_eq(val, 42); str = "x42"; val = -1; ret = safe_strtoint(str, &val); - assert(ret == false); - assert(val == -1); + test_assert_false(ret); + test_assert_s32_eq(val, -1); str = "42x"; val = -1; ret = safe_strtoint(str, &val); - assert(ret == false); - assert(val == -1); + test_assert_false(ret); + test_assert_s32_eq(val, -1); str = "0x42424242"; val = -1; ret = safe_strtoint(str, &val); - assert(ret == false); - assert(val == -1); + test_assert_false(ret); + test_assert_s32_eq(val, -1); str = "424748364789L"; val = -1; ret = safe_strtoint(str, &val); - assert(ret == false); - assert(val == -1); + test_assert_false(ret); + test_assert_s32_eq(val, -1); } diff --git a/tests/subsurface-shot-test.c b/tests/subsurface-shot-test.c index 5acb613f0..d3f9899ee 100644 --- a/tests/subsurface-shot-test.c +++ b/tests/subsurface-shot-test.c @@ -32,6 +32,7 @@ #include "weston-test-client-helper.h" #include "weston-test-fixture-compositor.h" +#include "weston-test-assert.h" struct setup_args { struct fixture_metadata meta; @@ -78,18 +79,18 @@ get_subcompositor(struct client *client) continue; if (global_sub) - assert(0 && "multiple wl_subcompositor objects"); + test_assert_not_reached("multiple wl_subcompositor objects"); global_sub = g; } - assert(global_sub && "no wl_subcompositor found"); + test_assert_ptr_not_null(global_sub); - assert(global_sub->version == 1); + test_assert_u32_eq(global_sub->version, 1); sub = wl_registry_bind(client->wl_registry, global_sub->name, &wl_subcompositor_interface, 1); - assert(sub); + test_assert_ptr_not_null(sub); return sub; } @@ -145,7 +146,7 @@ TEST(subsurface_recursive_unmap) color_rgb888(&green, 0, 255, 0); client = create_client_and_test_surface(100, 50, 100, 100); - assert(client); + test_assert_ptr_not_null(client); subco = get_subcompositor(client); /* move the pointer clearly away from our screenshooting area */ @@ -196,7 +197,7 @@ TEST(subsurface_recursive_unmap) surf[1] = NULL; fail += check_screen(client, "subsurface_z_order", 0, &clip, 0); - assert(fail == 0); + test_assert_int_eq(fail, 0); for (i = 0; i < ARRAY_LENGTH(sub); i++) if (sub[i]) @@ -235,7 +236,7 @@ TEST(subsurface_z_order) color_rgb888(&green, 0, 255, 0); client = create_client_and_test_surface(100, 50, 100, 100); - assert(client); + test_assert_ptr_not_null(client); subco = get_subcompositor(client); /* move the pointer clearly away from our screenshooting area */ @@ -287,7 +288,7 @@ TEST(subsurface_z_order) fail += check_screen(client, "subsurface_z_order", 4, &clip, 4); - assert(fail == 0); + test_assert_int_eq(fail, 0); for (i = 0; i < ARRAY_LENGTH(sub); i++) if (sub[i]) @@ -324,7 +325,7 @@ TEST(subsurface_sync_damage_buffer) color_rgb888(&green, 0, 255, 0); client = create_client_and_test_surface(100, 50, 100, 100); - assert(client); + test_assert_ptr_not_null(client); subco = get_subcompositor(client); /* move the pointer clearly away from our screenshooting area */ @@ -354,7 +355,7 @@ TEST(subsurface_sync_damage_buffer) fail += check_screen(client, "subsurface_sync_damage_buffer", 2, &clip, 2); - assert(fail == 0); + test_assert_int_eq(fail, 0); for (i = 0; i < ARRAY_LENGTH(sub); i++) if (sub[i]) @@ -394,7 +395,7 @@ TEST(subsurface_empty_mapping) color_rgb888(&green, 0, 255, 0); client = create_client_and_test_surface(100, 50, 100, 100); - assert(client); + test_assert_ptr_not_null(client); subco = get_subcompositor(client); viewporter = bind_to_singleton_global(client, &wp_viewporter_interface, 1); @@ -483,7 +484,7 @@ TEST(subsurface_empty_mapping) fail += check_screen(client, "subsurface_empty_mapping", 1, &clip, 11); - assert(fail == 0); + test_assert_int_eq(fail, 0); wp_viewport_destroy(viewport); @@ -520,7 +521,7 @@ TEST(subsurface_desync_commit) color_rgb888(&green, 0, 255, 0); client = create_client_and_test_surface(100, 50, 100, 100); - assert(client); + test_assert_ptr_not_null(client); subco = get_subcompositor(client); /* make the parent surface red */ diff --git a/tests/subsurface-test.c b/tests/subsurface-test.c index 9f790ffc7..3d80c9a76 100644 --- a/tests/subsurface-test.c +++ b/tests/subsurface-test.c @@ -30,6 +30,7 @@ #include "weston-test-client-helper.h" #include "weston-test-fixture-compositor.h" +#include "weston-test-assert.h" #define VERBOSE 0 @@ -67,18 +68,18 @@ get_subcompositor(struct client *client) continue; if (global_sub) - assert(0 && "multiple wl_subcompositor objects"); + test_assert_not_reached("multiple wl_subcompositor objects"); global_sub = g; } - assert(global_sub && "no wl_subcompositor found"); + test_assert_ptr_not_null(global_sub); - assert(global_sub->version == 1); + test_assert_u32_eq(global_sub->version, 1); sub = wl_registry_bind(client->wl_registry, global_sub->name, &wl_subcompositor_interface, 1); - assert(sub); + test_assert_ptr_not_null(sub); return sub; } @@ -125,7 +126,7 @@ TEST(test_subsurface_basic_protocol) struct compound_surface com2; client = create_client_and_test_surface(100, 50, 123, 77); - assert(client); + test_assert_ptr_not_null(client); populate_compound_surface(&com1, client); populate_compound_surface(&com2, client); @@ -144,7 +145,7 @@ TEST(test_subsurface_position_protocol) int i; client = create_client_and_test_surface(100, 50, 123, 77); - assert(client); + test_assert_ptr_not_null(client); populate_compound_surface(&com, client); for (i = 0; i < NUM_SUBSURFACES; i++) @@ -163,7 +164,7 @@ TEST(test_subsurface_placement_protocol) struct compound_surface com; client = create_client_and_test_surface(100, 50, 123, 77); - assert(client); + test_assert_ptr_not_null(client); populate_compound_surface(&com, client); @@ -186,7 +187,7 @@ TEST(test_subsurface_paradox) struct wl_subsurface *sub; client = create_client_and_test_surface(100, 50, 123, 77); - assert(client); + test_assert_ptr_not_null(client); subco = get_subcompositor(client); parent = wl_compositor_create_surface(client->wl_compositor); @@ -210,7 +211,7 @@ TEST(test_subsurface_identical_link) struct wl_subsurface *sub; client = create_client_and_test_surface(100, 50, 123, 77); - assert(client); + test_assert_ptr_not_null(client); populate_compound_surface(&com, client); @@ -233,7 +234,7 @@ TEST(test_subsurface_change_link) struct wl_subsurface *sub; client = create_client_and_test_surface(100, 50, 123, 77); - assert(client); + test_assert_ptr_not_null(client); stranger = wl_compositor_create_surface(client->wl_compositor); populate_compound_surface(&com, client); @@ -258,7 +259,7 @@ TEST(test_subsurface_nesting) struct wl_subsurface *sub; client = create_client_and_test_surface(100, 50, 123, 77); - assert(client); + test_assert_ptr_not_null(client); stranger = wl_compositor_create_surface(client->wl_compositor); populate_compound_surface(&com, client); @@ -282,7 +283,7 @@ TEST(test_subsurface_nesting_parent) struct wl_subsurface *sub; client = create_client_and_test_surface(100, 50, 123, 77); - assert(client); + test_assert_ptr_not_null(client); stranger = wl_compositor_create_surface(client->wl_compositor); populate_compound_surface(&com, client); @@ -307,7 +308,7 @@ TEST(test_subsurface_loop_paradox) unsigned i; client = create_client_and_test_surface(100, 50, 123, 77); - assert(client); + test_assert_ptr_not_null(client); subco = get_subcompositor(client); surface[0] = wl_compositor_create_surface(client->wl_compositor); @@ -340,7 +341,7 @@ TEST(test_subsurface_place_above_nested_parent) struct wl_subsurface *sub; client = create_client_and_test_surface(100, 50, 123, 77); - assert(client); + test_assert_ptr_not_null(client); populate_compound_surface(&com, client); @@ -368,7 +369,7 @@ TEST(test_subsurface_place_above_grandparent) struct wl_subcompositor *subco; client = create_client_and_test_surface(100, 50, 123, 77); - assert(client); + test_assert_ptr_not_null(client); populate_compound_surface(&com, client); @@ -398,7 +399,7 @@ TEST(test_subsurface_place_above_great_aunt) struct wl_subcompositor *subco; client = create_client_and_test_surface(100, 50, 123, 77); - assert(client); + test_assert_ptr_not_null(client); populate_compound_surface(&com, client); @@ -428,7 +429,7 @@ TEST(test_subsurface_place_above_child) struct wl_subsurface *sub; client = create_client_and_test_surface(100, 50, 123, 77); - assert(client); + test_assert_ptr_not_null(client); populate_compound_surface(&com, client); @@ -458,7 +459,7 @@ TEST(test_subsurface_place_below_nested_parent) struct wl_subsurface *sub; client = create_client_and_test_surface(100, 50, 123, 77); - assert(client); + test_assert_ptr_not_null(client); populate_compound_surface(&com, client); @@ -486,7 +487,7 @@ TEST(test_subsurface_place_below_grandparent) struct wl_subcompositor *subco; client = create_client_and_test_surface(100, 50, 123, 77); - assert(client); + test_assert_ptr_not_null(client); populate_compound_surface(&com, client); @@ -516,7 +517,7 @@ TEST(test_subsurface_place_below_great_aunt) struct wl_subcompositor *subco; client = create_client_and_test_surface(100, 50, 123, 77); - assert(client); + test_assert_ptr_not_null(client); populate_compound_surface(&com, client); @@ -546,7 +547,7 @@ TEST(test_subsurface_place_below_child) struct wl_subsurface *sub; client = create_client_and_test_surface(100, 50, 123, 77); - assert(client); + test_assert_ptr_not_null(client); populate_compound_surface(&com, client); @@ -574,7 +575,7 @@ TEST(test_subsurface_place_above_stranger) struct wl_surface *stranger; client = create_client_and_test_surface(100, 50, 123, 77); - assert(client); + test_assert_ptr_not_null(client); stranger = wl_compositor_create_surface(client->wl_compositor); populate_compound_surface(&com, client); @@ -597,7 +598,7 @@ TEST(test_subsurface_place_below_stranger) struct wl_surface *stranger; client = create_client_and_test_surface(100, 50, 123, 77); - assert(client); + test_assert_ptr_not_null(client); stranger = wl_compositor_create_surface(client->wl_compositor); populate_compound_surface(&com, client); @@ -620,7 +621,7 @@ TEST(test_subsurface_place_above_foreign) struct compound_surface com2; client = create_client_and_test_surface(100, 50, 123, 77); - assert(client); + test_assert_ptr_not_null(client); populate_compound_surface(&com1, client); populate_compound_surface(&com2, client); @@ -643,7 +644,7 @@ TEST(test_subsurface_place_below_foreign) struct compound_surface com2; client = create_client_and_test_surface(100, 50, 123, 77); - assert(client); + test_assert_ptr_not_null(client); populate_compound_surface(&com1, client); populate_compound_surface(&com2, client); @@ -665,7 +666,7 @@ TEST(test_subsurface_destroy_protocol) struct compound_surface com; client = create_client_and_test_surface(100, 50, 123, 77); - assert(client); + test_assert_ptr_not_null(client); populate_compound_surface(&com, client); @@ -720,7 +721,7 @@ create_subsurface_tree(struct client *client, struct wl_surface **surfs, switch (n) { default: - assert(0); + test_assert_not_reached("Unreachable"); break; #define SUB_LINK(s,p) \ @@ -879,7 +880,7 @@ TEST(test_subsurface_destroy_permutations) int i; client = create_client_and_test_surface(100, 50, 123, 77); - assert(client); + test_assert_ptr_not_null(client); permu_init(&per, test_size * 2 - 1); while (permu_next(&per) != -1) { diff --git a/tests/surface-global-test.c b/tests/surface-global-test.c index 216ff3807..0ad5c34ec 100644 --- a/tests/surface-global-test.c +++ b/tests/surface-global-test.c @@ -25,13 +25,13 @@ #include "config.h" -#include #include #include #include "libweston-internal.h" #include "weston-test-runner.h" #include "weston-test-fixture-compositor.h" +#include "weston-test-assert.h" static enum test_result_code fixture_setup(struct weston_test_harness *harness) @@ -54,9 +54,9 @@ PLUGIN_TEST(surface_to_from_global) struct weston_coord_surface cs; surface = weston_surface_create(compositor); - assert(surface); + test_assert_ptr_not_null(surface); view = weston_view_create(surface); - assert(view); + test_assert_ptr_not_null(view); surface->width = 50; surface->height = 50; cg.c = weston_coord(5, 10); @@ -65,39 +65,49 @@ PLUGIN_TEST(surface_to_from_global) cs = weston_coord_surface(33, 22, surface); cg = weston_coord_surface_to_global(view, cs); - assert(cg.c.x == 38 && cg.c.y == 32); + test_assert_f64_eq(cg.c.x, 38); + test_assert_f64_eq(cg.c.y, 32); cs = weston_coord_surface(-8, -2, surface); cg = weston_coord_surface_to_global(view, cs); - assert(cg.c.x == -3 && cg.c.y == 8); + test_assert_f64_eq(cg.c.x, -3); + test_assert_f64_eq(cg.c.y, 8); cs = weston_coord_surface_from_fixed(wl_fixed_from_int(12), wl_fixed_from_int(5), surface); cg = weston_coord_surface_to_global(view, cs); - assert(wl_fixed_from_double(cg.c.x) == wl_fixed_from_int(17) && - wl_fixed_from_double(cg.c.y) == wl_fixed_from_int(15)); + test_assert_s32_eq(wl_fixed_from_double(cg.c.x), + wl_fixed_from_int(17)); + test_assert_s32_eq(wl_fixed_from_double(cg.c.y), + wl_fixed_from_int(15)); cg.c = weston_coord(38, 32); cs = weston_coord_global_to_surface(view, cg); - assert(cs.c.x == 33 && cs.c.y == 22); + test_assert_f64_eq(cs.c.x, 33); + test_assert_f64_eq(cs.c.y, 22); cg.c = weston_coord(42, 5); cs = weston_coord_global_to_surface(view, cg); - assert(cs.c.x == 37 && cs.c.y == -5); + test_assert_f64_eq(cs.c.x, 37); + test_assert_f64_eq(cs.c.y, -5); cg.c = weston_coord_from_fixed(wl_fixed_from_int(21), wl_fixed_from_int(100)); cs = weston_coord_global_to_surface(view, cg); - assert(wl_fixed_from_double(cs.c.x) == wl_fixed_from_int(16) && - wl_fixed_from_double(cs.c.y) == wl_fixed_from_int(90)); + test_assert_s32_eq(wl_fixed_from_double(cs.c.x), + wl_fixed_from_int(16)); + test_assert_s32_eq(wl_fixed_from_double(cs.c.y), + wl_fixed_from_int(90)); cg.c = weston_coord(0, 0); cs = weston_coord_global_to_surface(view, cg); - assert(cs.c.x == -5 && cs.c.y == -10); + test_assert_f64_eq(cs.c.x, -5); + test_assert_f64_eq(cs.c.y, -10); cg.c = weston_coord(5, 10); cs = weston_coord_global_to_surface(view, cg); - assert(cs.c.x == 0 && cs.c.y == 0); + test_assert_f64_eq(cs.c.x, 0); + test_assert_f64_eq(cs.c.y, 0); /* Destroys all views too. */ weston_surface_unref(surface); diff --git a/tests/surface-test.c b/tests/surface-test.c index 6410b4778..75b6d5e69 100644 --- a/tests/surface-test.c +++ b/tests/surface-test.c @@ -26,11 +26,11 @@ #include "config.h" #include -#include #include #include "weston-test-runner.h" #include "weston-test-fixture-compositor.h" +#include "weston-test-assert.h" static enum test_result_code fixture_setup(struct weston_test_harness *harness) @@ -53,9 +53,9 @@ PLUGIN_TEST(surface_transform) struct weston_coord_global coord_g; surface = weston_surface_create(compositor); - assert(surface); + test_assert_ptr_not_null(surface); view = weston_view_create(surface); - assert(view); + test_assert_ptr_not_null(view); surface->width = 200; surface->height = 200; coord_g.c = weston_coord(100, 100); @@ -65,14 +65,16 @@ PLUGIN_TEST(surface_transform) coord_g = weston_coord_surface_to_global(view, coord_s); fprintf(stderr, "20,20 maps to %f, %f\n", coord_g.c.x, coord_g.c.y); - assert(coord_g.c.x == 120 && coord_g.c.y == 120); + test_assert_f64_eq(coord_g.c.x, 120); + test_assert_f64_eq(coord_g.c.y, 120); coord_g.c = weston_coord(150, 300); weston_view_set_position(view, coord_g); weston_view_update_transform(view); coord_s = weston_coord_surface(50, 40, surface); coord_g = weston_coord_surface_to_global(view, coord_s); - assert(coord_g.c.x == 200 && coord_g.c.y == 340); + test_assert_f64_eq(coord_g.c.x, 200); + test_assert_f64_eq(coord_g.c.y, 340); /* Destroys all views too. */ weston_surface_unref(surface); diff --git a/tests/text-test.c b/tests/text-test.c index d34e77f7f..afb7e4596 100644 --- a/tests/text-test.c +++ b/tests/text-test.c @@ -32,6 +32,7 @@ #include "weston-test-client-helper.h" #include "text-input-unstable-v1-client-protocol.h" #include "weston-test-fixture-compositor.h" +#include "weston-test-assert.h" static enum test_result_code fixture_setup(struct weston_test_harness *harness) @@ -188,7 +189,7 @@ TEST(text_test) struct text_input_state state; client = create_client_and_test_surface(100, 100, 100, 100); - assert(client); + test_assert_ptr_not_null(client); factory = NULL; wl_list_for_each(global, &client->global_list, link) { @@ -198,7 +199,7 @@ TEST(text_test) &zwp_text_input_manager_v1_interface, 1); } - assert(factory); + test_assert_ptr_not_null(factory); memset(&state, 0, sizeof state); text_input = zwp_text_input_manager_v1_create_text_input(factory); @@ -210,29 +211,33 @@ TEST(text_test) weston_test_activate_surface(client->test->weston_test, client->surface->wl_surface); client_roundtrip(client); - assert(client->input->keyboard->focus == client->surface); + test_assert_ptr_eq(client->input->keyboard->focus, client->surface); /* Activate test model and make sure we get enter event. */ zwp_text_input_v1_activate(text_input, client->input->wl_seat, client->surface->wl_surface); client_roundtrip(client); - assert(state.activated == 1 && state.deactivated == 0); + test_assert_int_eq(state.activated, 1); + test_assert_int_eq(state.deactivated, 0); /* Deactivate test model and make sure we get leave event. */ zwp_text_input_v1_deactivate(text_input, client->input->wl_seat); client_roundtrip(client); - assert(state.activated == 1 && state.deactivated == 1); + test_assert_int_eq(state.activated, 1); + test_assert_int_eq(state.deactivated, 1); /* Activate test model again. */ zwp_text_input_v1_activate(text_input, client->input->wl_seat, client->surface->wl_surface); client_roundtrip(client); - assert(state.activated == 2 && state.deactivated == 1); + test_assert_int_eq(state.activated, 2); + test_assert_int_eq(state.deactivated, 1); /* Take keyboard focus away and verify we get leave event. */ weston_test_activate_surface(client->test->weston_test, NULL); client_roundtrip(client); - assert(state.activated == 2 && state.deactivated == 2); + test_assert_int_eq(state.activated, 2); + test_assert_int_eq(state.deactivated, 2); zwp_text_input_v1_destroy(text_input); zwp_text_input_manager_v1_destroy(factory); diff --git a/tests/touch-test.c b/tests/touch-test.c index 2cf0b8942..2e1c1675f 100644 --- a/tests/touch-test.c +++ b/tests/touch-test.c @@ -32,6 +32,7 @@ #include "weston-test-client-helper.h" #include "wayland-server-protocol.h" #include "weston-test-fixture-compositor.h" +#include "weston-test-assert.h" static enum test_result_code fixture_setup(struct weston_test_harness *harness) @@ -55,7 +56,7 @@ static struct client * create_touch_test_client(void) { struct client *cl = create_client_and_test_surface(0, 0, 100, 100); - assert(cl); + test_assert_ptr_not_null(cl); return cl; } @@ -112,16 +113,16 @@ TEST(touch_events) input_timestamps_create_for_touch(client); send_touch(client, &t1, WL_TOUCH_DOWN); - assert(touch->down_time_msec == timespec_to_msec(&t1)); - assert(timespec_eq(&touch->down_time_timespec, &t1)); + test_assert_s64_eq(touch->down_time_msec, timespec_to_msec(&t1)); + test_assert_true(timespec_eq(&touch->down_time_timespec, &t1)); send_touch(client, &t2, WL_TOUCH_MOTION); - assert(touch->motion_time_msec == timespec_to_msec(&t2)); - assert(timespec_eq(&touch->motion_time_timespec, &t2)); + test_assert_s64_eq(touch->motion_time_msec, timespec_to_msec(&t2)); + test_assert_true(timespec_eq(&touch->motion_time_timespec, &t2)); send_touch(client, &t3, WL_TOUCH_UP); - assert(touch->up_time_msec == timespec_to_msec(&t3)); - assert(timespec_eq(&touch->up_time_timespec, &t3)); + test_assert_s64_eq(touch->up_time_msec, timespec_to_msec(&t3)); + test_assert_true(timespec_eq(&touch->up_time_timespec, &t3)); input_timestamps_destroy(input_ts); @@ -136,14 +137,14 @@ TEST(touch_timestamps_stop_after_input_timestamps_object_is_destroyed) input_timestamps_create_for_touch(client); send_touch(client, &t1, WL_TOUCH_DOWN); - assert(touch->down_time_msec == timespec_to_msec(&t1)); - assert(timespec_eq(&touch->down_time_timespec, &t1)); + test_assert_s64_eq(touch->down_time_msec, timespec_to_msec(&t1)); + test_assert_true(timespec_eq(&touch->down_time_timespec, &t1)); input_timestamps_destroy(input_ts); send_touch(client, &t2, WL_TOUCH_UP); - assert(touch->up_time_msec == timespec_to_msec(&t2)); - assert(timespec_is_zero(&touch->up_time_timespec)); + test_assert_s64_eq(touch->up_time_msec, timespec_to_msec(&t2)); + test_assert_true(timespec_is_zero(&touch->up_time_timespec)); client_destroy(client); } @@ -156,8 +157,8 @@ TEST(touch_timestamps_stop_after_client_releases_wl_touch) input_timestamps_create_for_touch(client); send_touch(client, &t1, WL_TOUCH_DOWN); - assert(touch->down_time_msec == timespec_to_msec(&t1)); - assert(timespec_eq(&touch->down_time_timespec, &t1)); + test_assert_s64_eq(touch->down_time_msec, timespec_to_msec(&t1)); + test_assert_true(timespec_eq(&touch->down_time_timespec, &t1)); wl_touch_release(client->input->touch->wl_touch); @@ -168,7 +169,7 @@ TEST(touch_timestamps_stop_after_client_releases_wl_touch) * event and checking for it here may lead to false negatives. */ touch->input_timestamp = t_other; send_touch(client, &t2, WL_TOUCH_UP); - assert(timespec_eq(&touch->input_timestamp, &t_other)); + test_assert_true(timespec_eq(&touch->input_timestamp, &t_other)); input_timestamps_destroy(input_ts); diff --git a/tests/vertex-clip-test.c b/tests/vertex-clip-test.c index 8983d2eb4..b10c31bb9 100644 --- a/tests/vertex-clip-test.c +++ b/tests/vertex-clip-test.c @@ -31,6 +31,7 @@ #include "config.h" #include "weston-test-runner.h" +#include "weston-test-assert.h" #include "vertex-clipping.h" #define BOX(x1,y1,x2,y2) { { x1, y1 }, { x2, y2 } } @@ -59,7 +60,7 @@ assert_vertices(const struct clipper_vertex *clipped, int clipped_n, int first, i, j; /* Is the number of clipped vertices correct? */ - assert(clipped_n == expected_n); + test_assert_int_eq(clipped_n, expected_n); for (first = 0; first < clipped_n; first++) if (clipper_float_difference(clipped[first].x, expected[0].x) == 0.0f && @@ -67,13 +68,13 @@ assert_vertices(const struct clipper_vertex *clipped, int clipped_n, break; /* Have we found the first expected vertex? */ - assert(!clipped_n || first != clipped_n); + test_assert_true(!clipped_n || first != clipped_n); /* Do the remaining vertices match? */ for (i = 1; i < clipped_n; i++) { j = (i + first) % clipped_n; - assert(clipper_float_difference(clipped[j].x, expected[i].x) == 0.0f && - clipper_float_difference(clipped[j].y, expected[i].y) == 0.0f); + test_assert_f32_eq(clipper_float_difference(clipped[j].x, expected[i].x), 0.0f); + test_assert_f32_eq(clipper_float_difference(clipped[j].y, expected[i].y), 0.0f); } } @@ -762,10 +763,10 @@ TEST_P(quad_clip_box32_expected, quad_clip_box32_expected_data) TEST(float_difference_different) { - assert(clipper_float_difference(1.0f, 0.0f) == 1.0f); + test_assert_f32_eq(clipper_float_difference(1.0f, 0.0f), 1.0f); } TEST(float_difference_same) { - assert(clipper_float_difference(1.0f, 1.0f) == 0.0f); + test_assert_f32_eq(clipper_float_difference(1.0f, 1.0f), 0.0f); } diff --git a/tests/viewporter-shot-test.c b/tests/viewporter-shot-test.c index 1f9bca85b..75adb30fb 100644 --- a/tests/viewporter-shot-test.c +++ b/tests/viewporter-shot-test.c @@ -32,6 +32,7 @@ #include "weston-test-client-helper.h" #include "weston-test-fixture-compositor.h" +#include "weston-test-assert.h" struct setup_args { struct fixture_metadata meta; @@ -93,7 +94,7 @@ TEST(viewport_upscale_solid) match = verify_screen_content(client, "viewport_upscale_solid", 0, NULL, 0, NULL); - assert(match); + test_assert_true(match); wp_viewport_destroy(viewport); client_destroy(client); diff --git a/tests/viewporter-test.c b/tests/viewporter-test.c index 6f5ef669a..c10e1c629 100644 --- a/tests/viewporter-test.c +++ b/tests/viewporter-test.c @@ -28,13 +28,13 @@ #include #include #include -#include #include #include "shared/helpers.h" #include "shared/xalloc.h" #include "weston-test-client-helper.h" #include "weston-test-fixture-compositor.h" +#include "weston-test-assert.h" static enum test_result_code fixture_setup(struct weston_test_harness *harness) @@ -316,20 +316,20 @@ TEST(test_viewporter_source_buffer_params) const int max_scale = 2; /* buffer_scale requirement */ - assert(WIN_W % max_scale == 0); - assert(WIN_H % max_scale == 0); + test_assert_int_eq(WIN_W % max_scale, 0); + test_assert_int_eq(WIN_H % max_scale, 0); /* source rect must fit inside regardless of scale and transform */ - assert(SRC_W < WIN_W / max_scale); - assert(SRC_H < WIN_H / max_scale); - assert(SRC_W < WIN_H / max_scale); - assert(SRC_H < WIN_W / max_scale); + test_assert_int_lt(SRC_W, WIN_W / max_scale); + test_assert_int_lt(SRC_H, WIN_H / max_scale); + test_assert_int_lt(SRC_W, WIN_H / max_scale); + test_assert_int_lt(SRC_H, WIN_W / max_scale); /* If buffer scale was ignored, source rect should be inside instead */ - assert(WIN_W / max_scale + SRC_W + MRG < WIN_W); - assert(WIN_H / max_scale + SRC_H + MRG < WIN_H); - assert(WIN_W / max_scale + SRC_H + MRG < WIN_W); - assert(WIN_H / max_scale + SRC_W + MRG < WIN_H); + test_assert_int_lt(WIN_W / max_scale + SRC_W + MRG, WIN_W); + test_assert_int_lt(WIN_H / max_scale + SRC_H + MRG, WIN_H); + test_assert_int_lt(WIN_W / max_scale + SRC_H + MRG, WIN_W); + test_assert_int_lt(WIN_H / max_scale + SRC_W + MRG, WIN_H); } static const struct source_buffer_args bad_source_buffer_args[] = { diff --git a/tests/weston-test-client-helper.c b/tests/weston-test-client-helper.c index c4ddbad06..a52e3d457 100644 --- a/tests/weston-test-client-helper.c +++ b/tests/weston-test-client-helper.c @@ -45,6 +45,7 @@ #include "shared/xalloc.h" #include #include "weston-test-client-helper.h" +#include "weston-test-assert.h" #include "image-iter.h" #include "weston-output-capture-client-protocol.h" @@ -498,12 +499,12 @@ create_shm_buffer(struct client *client, int width, int height, size_t bytes_pp; uint32_t shm_format; - assert(width > 0); - assert(height > 0); + test_assert_int_gt(width, 0); + test_assert_int_gt(height, 0); pfmt = pixel_format_get_info(drm_format); - assert(pfmt); - assert(pixel_format_get_plane_count(pfmt) == 1); + test_assert_ptr_not_null(pfmt); + test_assert_uint_eq(pixel_format_get_plane_count(pfmt), 1); shm_format = pixel_format_get_shm_format(pfmt); if (!support_shm_format(client, shm_format)) @@ -515,18 +516,18 @@ create_shm_buffer(struct client *client, int width, int height, stride_bytes = width * bytes_pp; /* round up to multiple of 4 bytes for Pixman */ stride_bytes = (stride_bytes + 3) & ~3u; - assert(stride_bytes / bytes_pp >= (unsigned)width); + test_assert_u64_ge(stride_bytes / bytes_pp, width); buf->len = stride_bytes * height; - assert(buf->len / stride_bytes == (unsigned)height); + test_assert_u64_eq(buf->len / stride_bytes, height); fd = os_create_anonymous_file(buf->len); - assert(fd >= 0); + test_assert_int_ge(fd, 0); data = mmap(NULL, buf->len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (data == MAP_FAILED) { close(fd); - assert(data != MAP_FAILED); + test_assert_not_reached("Unreachable"); } pool = wl_shm_create_pool(shm, fd, buf->len); @@ -540,8 +541,8 @@ create_shm_buffer(struct client *client, int width, int height, width, height, data, stride_bytes); - assert(buf->proxy); - assert(buf->image); + test_assert_ptr_not_null(buf->proxy); + test_assert_ptr_not_null(buf->image); return buf; } @@ -557,13 +558,13 @@ create_pixman_buffer(int width, int height, pixman_format_code_t pixman_format) { struct buffer *buf; - assert(width > 0); - assert(height > 0); + test_assert_int_gt(width, 0); + test_assert_int_gt(height, 0); buf = xzalloc(sizeof *buf); buf->image = pixman_image_create_bits(pixman_format, width, height, NULL, 0); - assert(buf->image); + test_assert_ptr_not_null(buf->image); return buf; } @@ -577,10 +578,10 @@ buffer_destroy(struct buffer *buf) if (buf->proxy) { wl_buffer_destroy(buf->proxy); - assert(munmap(pixels, buf->len) == 0); + test_assert_int_eq(munmap(pixels, buf->len), 0); } - assert(pixman_image_unref(buf->image)); + test_assert_true(pixman_image_unref(buf->image)); free(buf); } @@ -710,12 +711,12 @@ seat_handle_name(void *data, struct wl_seat *seat, const char *name) struct input *input = data; input->seat_name = strdup(name); - assert(input->seat_name && "No memory"); + test_assert_ptr_not_null(input->seat_name); /* We only update the devices and set client input for the test seat */ if (strcmp(name, "test-seat") == 0) { - assert(!input->client->input && - "Multiple test seats detected!"); + /* Can't have multiple test seats. */ + test_assert_ptr_null(input->client->input); input_update_devices(input); input->client->input = input; @@ -807,7 +808,7 @@ static const struct wl_output_listener output_listener = { static void output_destroy(struct output *output) { - assert(wl_proxy_get_version((struct wl_proxy *)output->wl_output) >= 3); + test_assert_u32_ge(wl_proxy_get_version((struct wl_proxy *)output->wl_output), 3); wl_output_release(output->wl_output); wl_list_remove(&output->link); free(output->name); @@ -828,7 +829,7 @@ handle_global(void *data, struct wl_registry *registry, global = xzalloc(sizeof *global); global->name = id; global->interface = strdup(interface); - assert(interface); + test_assert_ptr_not_null(interface); global->version = version; wl_list_insert(client->global_list.prev, &global->link); @@ -918,7 +919,9 @@ handle_global_remove(void *data, struct wl_registry *registry, uint32_t name) struct input *input; global = client_find_global_with_name(client, name); - assert(global && "Request to remove unknown global"); + + /* Unknown global. */ + test_assert_ptr_not_null(global); if (strcmp(global->interface, "wl_seat") == 0) { input = client_find_input_with_name(client, name); @@ -971,8 +974,11 @@ expect_protocol_error(struct client *client, err = wl_display_get_error(client->wl_display); - assert(err && "Expected protocol error but nothing came"); - assert(err == EPROTO && "Expected protocol error but got local error"); + /* Expected protocol error but nothing came. */ + test_assert_int_ne(err, 0); + + /* Expected protocol error but got local error. */ + test_assert_enum(err, EPROTO); errcode = wl_display_get_protocol_error(client->wl_display, &interface, &id); @@ -1030,7 +1036,7 @@ create_client(void) /* connect to display */ client = xzalloc(sizeof *client); client->wl_display = wl_display_connect(NULL); - assert(client->wl_display); + test_assert_ptr_not_null(client->wl_display); wl_array_init(&client->shm_formats); wl_list_init(&client->global_list); wl_list_init(&client->inputs); @@ -1048,20 +1054,20 @@ create_client(void) client_roundtrip(client); /* must have WL_SHM_FORMAT_*RGB8888 */ - assert(support_shm_format(client, WL_SHM_FORMAT_ARGB8888)); - assert(support_shm_format(client, WL_SHM_FORMAT_XRGB8888)); + test_assert_true(support_shm_format(client, WL_SHM_FORMAT_ARGB8888)); + test_assert_true(support_shm_format(client, WL_SHM_FORMAT_XRGB8888)); /* must have weston_test interface */ - assert(client->test); + test_assert_ptr_not_null(client->test); /* must have an output */ - assert(client->output); + test_assert_ptr_not_null(client->output); /* the output must be initialized */ - assert(client->output->initialized == 1); + test_assert_int_eq(client->output->initialized, 1); /* must have seat set */ - assert(client->input); + test_assert_ptr_not_null(client->input); return client; } @@ -1076,7 +1082,7 @@ create_test_surface(struct client *client) surface->client = client; surface->wl_surface = wl_compositor_create_surface(client->wl_compositor); - assert(surface->wl_surface); + test_assert_ptr_not_null(surface->wl_surface); wl_surface_add_listener(surface->wl_surface, &surface_listener, surface); @@ -1180,7 +1186,7 @@ client_destroy(struct client *client) if (client->wl_display) { ret = wl_display_roundtrip(client->wl_display); - assert(client->errored_ok || ret >= 0); + test_assert_true(client->errored_ok || ret >= 0); wl_display_disconnect(client->wl_display); } @@ -1223,9 +1229,11 @@ char * image_filename(const char *basename) { char *filename; + int ret; + + ret = asprintf(&filename, "%s/%s.png", reference_path(), basename); + test_assert_int_ge(ret, 0); - if (asprintf(&filename, "%s/%s.png", reference_path(), basename) < 0) - assert(0); return filename; } @@ -1243,8 +1251,8 @@ output_filename_for_test_program(const char *test_program, const char *suffix, { char *filename; - assert(test_program); - assert(file_ext); + test_assert_ptr_not_null(test_program); + test_assert_ptr_not_null(file_ext); if (suffix) str_printf(&filename, "%s/%s-%s.%s", output_path(), test_program, @@ -1253,7 +1261,7 @@ output_filename_for_test_program(const char *test_program, const char *suffix, str_printf(&filename, "%s/%s.%s", output_path(), test_program, file_ext); - assert(filename); + test_assert_ptr_not_null(filename); return filename; } @@ -1274,9 +1282,9 @@ output_filename_for_fixture(const char *test_program, int fixture_number; char *filename; - assert(test_program); - assert(harness); - assert(file_ext); + test_assert_ptr_not_null(test_program); + test_assert_ptr_not_null(harness); + test_assert_ptr_not_null(file_ext); fixture_number = get_test_fixture_number_from_harness(harness); @@ -1287,7 +1295,7 @@ output_filename_for_fixture(const char *test_program, str_printf(&filename, "%s/%s-f%02d.%s", output_path(), test_program, fixture_number, file_ext); - assert(filename); + test_assert_ptr_not_null(filename); return filename; } @@ -1309,7 +1317,7 @@ output_filename_for_test_case(const char *suffix, uint32_t seq_number, { char *filename; - assert(file_ext); + test_assert_ptr_not_null(file_ext); if (suffix) str_printf(&filename, "%s/%s-%s-%02d.%s", output_path(), get_test_name(), @@ -1318,7 +1326,7 @@ output_filename_for_test_case(const char *suffix, uint32_t seq_number, str_printf(&filename, "%s/%s-%02d.%s", output_path(), get_test_name(), seq_number, file_ext); - assert(filename); + test_assert_ptr_not_null(filename); return filename; } @@ -1373,7 +1381,9 @@ format_cairo2pixman(cairo_format_t fmt) if (format_map[i].cairo == fmt) return format_map[i].pixman; - assert(0 && "unknown Cairo pixel format"); + test_assert_not_reached("unknown Cairo pixel format"); + + return 0; } static cairo_format_t @@ -1385,7 +1395,9 @@ format_pixman2cairo(pixman_format_code_t fmt) if (format_map[i].pixman == fmt) return format_map[i].cairo; - assert(0 && "unknown Pixman pixel format"); + test_assert_not_reached("unknown Pixman pixel format"); + + return 0; } /** @@ -1402,7 +1414,7 @@ range_get(const struct range *r) if (!r) return (struct range){ 0, 0 }; - assert(r->a <= r->b); + test_assert_int_le(r->a, r->b); return *r; } @@ -1442,14 +1454,14 @@ image_check_get_roi(const struct image_header *ih_a, box.y2 = max(ih_a->height, ih_b->height); } - assert(box.x1 >= 0); - assert(box.y1 >= 0); - assert(box.x2 > box.x1); - assert(box.y2 > box.y1); - assert(box.x2 <= ih_a->width); - assert(box.x2 <= ih_b->width); - assert(box.y2 <= ih_a->height); - assert(box.y2 <= ih_b->height); + test_assert_s32_ge(box.x1, 0); + test_assert_s32_ge(box.y1, 0); + test_assert_s32_gt(box.x2, box.x1); + test_assert_s32_gt(box.y2, box.y1); + test_assert_s32_le(box.x2, ih_a->width); + test_assert_s32_le(box.x2, ih_b->width); + test_assert_s32_le(box.y2, ih_a->height); + test_assert_s32_le(box.y2, ih_b->height); return box; } @@ -1703,7 +1715,7 @@ image_convert_to_a8r8g8b8(pixman_image_t *image) ret = pixman_image_create_bits_no_clear(PIXMAN_a8r8g8b8, ih.width, ih.height, NULL, 0); - assert(ret); + test_assert_ptr_not_null(ret); pixman_image_composite32(PIXMAN_OP_SRC, image, NULL, ret, 0, 0, 0, 0, 0, 0, ih.width, ih.height); @@ -1764,7 +1776,7 @@ load_image_from_png(const char *fname) /* The Cairo surface will own the data, so we keep it around. */ image = pixman_image_create_bits_no_clear(pixman_fmt, width, height, data, stride); - assert(image); + test_assert_ptr_not_null(image); pixman_image_set_destroy_function(image, destroy_cairo_surface, reference_cairo_surface); @@ -1820,7 +1832,7 @@ static void output_capturer_handle_retry(void *data, struct weston_capture_source_v1 *proxy) { - assert(0 && "output capture retry in tests indicates a race"); + test_assert_not_reached("output capture retry in tests indicates a race"); } static void @@ -1829,7 +1841,8 @@ output_capturer_handle_failed(void *data, const char *msg) { testlog("output capture failed: %s", msg ? msg : "?"); - assert(0 && "output capture failed"); + + test_assert_not_reached("output capture failed"); } static const struct weston_capture_source_v1_listener output_capturer_source_handlers = { @@ -1860,15 +1873,17 @@ client_capture_output(struct client *client, client_roundtrip(client); - assert(capt.width != 0 && capt.height != 0 && capt.drm_format != 0 && - "capture source not available"); + test_assert_true(capt.width != 0 && + capt.height != 0 && + capt.drm_format != 0 && + "capture source not available"); buf = create_shm_buffer(client, capt.width, capt.height, capt.drm_format); weston_capture_source_v1_capture(capt.source, buf->proxy); while (!capt.complete) - assert(wl_display_dispatch(client->wl_display) >= 0); + test_assert_int_ge(wl_display_dispatch(client->wl_display), 0); weston_capture_source_v1_destroy(capt.source); weston_capture_v1_destroy(capt.factory); @@ -1912,7 +1927,7 @@ capture_screenshot_of_output(struct client *client, const char *output_name) } } - assert(output); + test_assert_ptr_not_null(output); } else { output = client->output; } @@ -2049,7 +2064,7 @@ verify_screen_content(struct client *client, bool match; shot = capture_screenshot_of_output(client, output_name); - assert(shot); + test_assert_ptr_not_null(shot); match = verify_image(shot->image, ref_image, ref_seq_no, clip, seq_no); buffer_destroy(shot); @@ -2078,12 +2093,12 @@ client_buffer_from_image_file(struct client *client, int buf_w, buf_h; pixman_transform_t scaling; - assert(scale >= 1); + test_assert_int_ge(scale, 1); fname = image_filename(basename); img = load_image_from_png(fname); free(fname); - assert(img); + test_assert_ptr_not_null(img); buf_w = scale * pixman_image_get_width(img); buf_h = scale * pixman_image_get_height(img); @@ -2134,14 +2149,16 @@ bind_to_singleton_global(struct client *client, if (strcmp(tmp->interface, iface->name)) continue; - assert(!g && "multiple singleton objects"); + /* Multiple singleton objects. */ + test_assert_ptr_null(g); g = tmp; } - assert(g && "singleton not found"); + /* Singleton not found. */ + test_assert_ptr_not_null(g); proxy = wl_registry_bind(client->wl_registry, g->name, iface, version); - assert(proxy); + test_assert_ptr_not_null(proxy); return proxy; } @@ -2162,7 +2179,7 @@ client_create_viewport(struct client *client) &wp_viewporter_interface, 1); viewport = wp_viewporter_get_viewport(viewporter, client->surface->wl_surface); - assert(viewport); + test_assert_ptr_not_null(viewport); wp_viewporter_destroy(viewporter); return viewport; @@ -2252,14 +2269,14 @@ client_wait_breakpoint(struct client *client, { struct wet_test_active_breakpoint *active_bp; - assert(suite_data); - assert(!suite_data->breakpoints.in_client_break); + test_assert_ptr_not_null(suite_data); + test_assert_false(suite_data->breakpoints.in_client_break); wl_display_flush(client->wl_display); wet_test_wait_sem(&suite_data->breakpoints.client_break); active_bp = suite_data->breakpoints.active_bp; - assert(active_bp); + test_assert_ptr_not_null(active_bp); suite_data->breakpoints.in_client_break = true; return active_bp; } @@ -2270,14 +2287,14 @@ get_resource_data_from_proxy(struct wet_testsuite_data *suite_data, { struct wl_resource *resource; - assert(suite_data->breakpoints.in_client_break); + test_assert_true(suite_data->breakpoints.in_client_break); if (!proxy) return NULL; resource = wl_client_get_object(suite_data->wl_client, wl_proxy_get_id(proxy)); - assert(resource); + test_assert_ptr_not_null(resource); return wl_resource_get_user_data(resource); } @@ -2302,7 +2319,7 @@ client_insert_breakpoint(struct client *client, { struct wet_test_pending_breakpoint *bp; - assert(suite_data->breakpoints.in_client_break); + test_assert_true(suite_data->breakpoints.in_client_break); bp = xzalloc(sizeof(*bp)); bp->breakpoint = breakpoint; @@ -2331,7 +2348,7 @@ client_remove_breakpoint(struct client *client, struct wet_test_pending_breakpoint *bp, *tmp; void *resource = get_resource_data_from_proxy(suite_data, proxy); - assert(suite_data->breakpoints.in_client_break); + test_assert_true(suite_data->breakpoints.in_client_break); wl_list_for_each_safe(bp, tmp, &suite_data->breakpoints.list, link) { @@ -2339,13 +2356,13 @@ client_remove_breakpoint(struct client *client, continue; if (bp->resource != resource) continue; - assert(bp != suite_data->breakpoints.active_bp->template_); + test_assert_ptr_ne(bp, suite_data->breakpoints.active_bp->template_); wl_list_remove(&bp->link); free(bp); return; } - assert(!"couldn't find breakpoint to remove"); + test_assert_not_reached("couldn't find breakpoint to remove"); } /** @@ -2360,7 +2377,7 @@ client_release_breakpoint(struct client *client, struct wet_testsuite_data *suite_data, struct wet_test_active_breakpoint *active_bp) { - assert(suite_data->breakpoints.active_bp == active_bp); + test_assert_ptr_eq(suite_data->breakpoints.active_bp, active_bp); if (active_bp->rearm_on_release) { wl_list_insert(&suite_data->breakpoints.list, diff --git a/tests/weston-test-client-helper.h b/tests/weston-test-client-helper.h index 0346948a2..32d6065d2 100644 --- a/tests/weston-test-client-helper.h +++ b/tests/weston-test-client-helper.h @@ -28,7 +28,6 @@ #include "config.h" -#include #include #include #include @@ -241,7 +240,7 @@ void move_client_offscreenable(struct client *client, int x, int y); #define client_roundtrip(c) do { \ - assert(wl_display_roundtrip((c)->wl_display) >= 0); \ + test_assert_int_ge(wl_display_roundtrip((c)->wl_display), 0); \ } while (0) struct wl_callback * @@ -250,7 +249,7 @@ frame_callback_set(struct wl_surface *surface, int *done); int frame_callback_wait_nofail(struct client *client, int *done); -#define frame_callback_wait(c, d) assert(frame_callback_wait_nofail((c), (d))) +#define frame_callback_wait(c, d) test_assert_true(frame_callback_wait_nofail((c), (d))) void expect_protocol_error(struct client *client, diff --git a/tests/weston-test-fixture-compositor.c b/tests/weston-test-fixture-compositor.c index 45e6eac0b..cb396a54b 100644 --- a/tests/weston-test-fixture-compositor.c +++ b/tests/weston-test-fixture-compositor.c @@ -26,7 +26,6 @@ #include "config.h" #include -#include #include #include #include @@ -40,6 +39,7 @@ #include "shared/helpers.h" #include "shared/string-helpers.h" #include "weston-test-fixture-compositor.h" +#include "weston-test-assert.h" #include "weston.h" #include "test-config.h" @@ -62,12 +62,12 @@ prog_args_init(struct prog_args *p) static void prog_args_take(struct prog_args *p, char *arg) { - assert(arg); + test_assert_ptr_not_null(arg); if (p->argc == p->alloc) { p->alloc += 10; p->argv = realloc(p->argv, sizeof(char *) * p->alloc); - assert(p->argv); + test_assert_ptr_not_null(p->argv); } p->argv[p->argc++] = arg; @@ -80,10 +80,10 @@ prog_args_take(struct prog_args *p, char *arg) static void prog_args_save(struct prog_args *p) { - assert(p->saved == NULL); + test_assert_ptr_null(p->saved); p->saved = calloc(p->argc, sizeof(char *)); - assert(p->saved); + test_assert_true(p->saved); memcpy(p->saved, p->argv, sizeof(char *) * p->argc); } @@ -216,7 +216,7 @@ backend_to_str(enum weston_compositor_backend b) [WESTON_BACKEND_WAYLAND] = "wayland", [WESTON_BACKEND_X11] = "x11", }; - assert(b >= 0 && b < ARRAY_LENGTH(names)); + test_assert_true(b >= 0 && b < ARRAY_LENGTH(names)); return names[b]; } @@ -228,7 +228,7 @@ renderer_to_str(enum weston_renderer_type t) [WESTON_RENDERER_PIXMAN] = "pixman", [WESTON_RENDERER_GL] = "gl", }; - assert(t >= 0 && t <= ARRAY_LENGTH(names)); + test_assert_true(t >= 0 && t <= ARRAY_LENGTH(names)); return names[t]; } @@ -242,7 +242,7 @@ shell_to_str(enum shell_type t) [SHELL_IVI] = "ivi", [SHELL_KIOSK] = "kiosk", }; - assert(t >= 0 && t < ARRAY_LENGTH(names)); + test_assert_true(t >= 0 && t < ARRAY_LENGTH(names)); return names[t]; } @@ -260,7 +260,7 @@ transform_to_str(enum wl_output_transform t) [WL_OUTPUT_TRANSFORM_FLIPPED_270] = "flipped-rotate-270", }; - assert(t < ARRAY_LENGTH(names) && names[t]); + test_assert_true(t < ARRAY_LENGTH(names) && names[t]); return names[t]; } @@ -436,11 +436,11 @@ write_cfg(va_list entry_list, FILE *weston_ini) { char *entry = va_arg(entry_list, char *); int ret; - assert(entry); + test_assert_ptr_not_null(entry); while (entry) { ret = fprintf(weston_ini, "%s\n", entry); - assert(ret >= 0); + test_assert_int_ge(ret, 0); free(entry); entry = va_arg(entry_list, char *); } @@ -452,10 +452,10 @@ open_ini_file(struct compositor_setup *setup) char *wd, *tmp_path = NULL; FILE *weston_ini = NULL; - assert(!setup->config_file); + test_assert_ptr_null(setup->config_file); wd = realpath(".", NULL); - assert(wd); + test_assert_ptr_not_null(wd); str_printf(&tmp_path, "%s/%s.ini", wd, setup->testset_name); if (!tmp_path) { @@ -464,7 +464,7 @@ open_ini_file(struct compositor_setup *setup) } weston_ini = fopen(tmp_path, "w"); - assert(weston_ini); + test_assert_ptr_not_null(weston_ini); setup->config_file = tmp_path; out: @@ -480,14 +480,14 @@ weston_ini_setup_(struct compositor_setup *setup, ...) va_list entry_list; weston_ini = open_ini_file(setup); - assert(weston_ini); + test_assert_ptr_not_null(weston_ini); va_start(entry_list, setup); write_cfg(entry_list, weston_ini); va_end(entry_list); ret = fclose(weston_ini); - assert(ret != EOF); + test_assert_int_ne(ret, EOF); } char * @@ -499,7 +499,7 @@ cfgln(const char *fmt, ...) va_start(ap, fmt); ret = vasprintf(&str, fmt, ap); - assert(ret >= 0); + test_assert_int_ge(ret, 0); va_end(ap); return str; diff --git a/tests/weston-test-runner.c b/tests/weston-test-runner.c index 8b5085bc2..05cc3d728 100644 --- a/tests/weston-test-runner.c +++ b/tests/weston-test-runner.c @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include @@ -38,6 +37,7 @@ #include "test-config.h" #include "weston-test-runner.h" +#include "weston-test-assert.h" #include "weston-testsuite-data.h" #include "shared/string-helpers.h" @@ -274,7 +274,7 @@ result_to_str(enum test_result_code ret) #endif }; - assert(ret >= 0 && ret < ARRAY_LENGTH(names)); + test_assert_true(ret >= 0 && ret < ARRAY_LENGTH(names)); return names[ret]; } @@ -458,7 +458,7 @@ weston_test_harness_create(int argc, char **argv) struct weston_test_harness *harness; harness = zalloc(sizeof(*harness)); - assert(harness); + test_assert_ptr_not_null(harness); harness->fixt_ind = -1; harness->case_ind = -1; diff --git a/tests/weston-test.c b/tests/weston-test.c index 420ec5a04..1e1bbf2d5 100644 --- a/tests/weston-test.c +++ b/tests/weston-test.c @@ -229,6 +229,7 @@ test_seat_release(struct weston_test *test) assert(test->is_seat_initialized && "Trying to release already released test seat"); + test->is_seat_initialized = false; weston_seat_release(&test->seat); memset(&test->seat, 0, sizeof test->seat); diff --git a/tests/weston-testsuite-data.h b/tests/weston-testsuite-data.h index 59a25afd5..fb7cd54a4 100644 --- a/tests/weston-testsuite-data.h +++ b/tests/weston-testsuite-data.h @@ -26,10 +26,11 @@ #ifndef WESTON_TESTSUITE_DATA_H #define WESTON_TESTSUITE_DATA_H -#include #include #include +#include "weston-test-assert.h" + /** Standard return codes * * Both Autotools and Meson use these codes as test program exit codes diff --git a/tests/xcb-client-helper.c b/tests/xcb-client-helper.c index c2249c2e2..a2ca33f25 100644 --- a/tests/xcb-client-helper.c +++ b/tests/xcb-client-helper.c @@ -223,7 +223,7 @@ handle_unmap_notify(xcb_generic_event_t *e, struct window_x11 *window) if (ce->window != window->win_id && ce->window != window->frame_id) return false; - assert(window_state_has_flag(window, MAPPED)); + test_assert_true(window_state_has_flag(window, MAPPED)); window_state_set_flag(window, UNMAPPED); return true; @@ -251,7 +251,7 @@ handle_destroy_notify(xcb_generic_event_t *e, struct window_x11 *window) if (window->win_id != dn->window) return false; - assert(window_state_has_flag(window, CREATED)); + test_assert_true(window_state_has_flag(window, CREATED)); window_state_set_flag(window, DESTROYED); return true; @@ -383,8 +383,8 @@ window_x11_unmap(struct window_x11 *window) static void window_x11_set_cursor(struct window_x11 *window, const char *cursor_name) { - assert(window); - assert(window->ctx == NULL); + test_assert_ptr_not_null(window); + test_assert_ptr_null(window->ctx); if (xcb_cursor_context_new(window->conn->connection, window->screen, &window->ctx) < 0) { @@ -447,7 +447,7 @@ handle_events_x11(struct window_x11 *window) xcb_generic_event_t *ev; int ret = 0; - assert(window->handle_in_progress == false); + test_assert_false(window->handle_in_progress); window->handle_in_progress = true; do { @@ -601,7 +601,7 @@ create_x11_window(int width, int height, int pos_x, int pos_y, xcb_generic_error_t *error_create; const struct xcb_setup_t *xcb_setup; - assert(conn); + test_assert_ptr_not_null(conn); window = xzalloc(sizeof(*window)); window->conn = conn; @@ -624,7 +624,7 @@ create_x11_window(int width, int height, int pos_x, int pos_y, cookie = xcb_alloc_color(window->conn->connection, colormap, bg_color.red, bg_color.blue, bg_color.green); reply = xcb_alloc_color_reply(window->conn->connection, cookie, NULL); - assert(reply); + test_assert_ptr_not_null(reply); colorpixel = reply->pixel; free(reply); @@ -666,7 +666,7 @@ create_x11_window(int width, int height, int pos_x, int pos_y, window->screen->root_visual, mask, values); error_create = xcb_request_check(window->conn->connection, cookie_create); - assert(error_create == NULL); + test_assert_ptr_null(error_create); window_state_set_flag(window, CREATED); window_x11_set_cursor(window, "left_ptr"); diff --git a/tests/xcb-client-helper.h b/tests/xcb-client-helper.h index e8684bec7..633db84c4 100644 --- a/tests/xcb-client-helper.h +++ b/tests/xcb-client-helper.h @@ -27,7 +27,6 @@ #include "config.h" -#include #include #include #include @@ -39,6 +38,8 @@ #include #include +#include "weston-test-assert.h" + enum w_state { CREATED = 1 << 0, MAPPED = 1 << 1, @@ -188,8 +189,8 @@ handle_events_and_check_flags(struct window_x11 *win, enum w_state flag) if ((wstate->pending_state & flag) == flag) found_pending_flag = true; } - assert(found_pending_flag); + test_assert_true(found_pending_flag); handle_events_x11(win); - assert(window_state_has_flag(win, flag)); + test_assert_true(window_state_has_flag(win, flag)); } diff --git a/tests/xwayland-test.c b/tests/xwayland-test.c index bba2571d0..4f663b16e 100644 --- a/tests/xwayland-test.c +++ b/tests/xwayland-test.c @@ -37,7 +37,6 @@ #include "config.h" #include -#include #include #include #include @@ -46,6 +45,7 @@ #include "weston-test-fixture-compositor.h" #include "shared/string-helpers.h" #include "weston-test-client-helper.h" +#include "weston-test-assert.h" #include "xcb-client-helper.h" static enum test_result_code @@ -73,12 +73,12 @@ get_x11_window_name(struct window_x11 *window, xcb_drawable_t win) struct atom_x11 *atoms = window_get_atoms(window); reply = window_x11_dump_prop(window, win, atoms->net_wm_name); - assert(reply); + test_assert_ptr_not_null(reply); - assert(reply->type == atoms->string || - reply->type == atoms->utf8_string); + test_assert_true(reply->type == atoms->string || + reply->type == atoms->utf8_string); reply_len = xcb_get_property_value_length(reply); - assert(reply_len > 0); + test_assert_int_gt(reply_len, 0); str_printf(&name, "%.*s", reply_len, (char *) xcb_get_property_value(reply)); @@ -100,9 +100,9 @@ get_wm_name(struct window_x11 *window) atoms->net_supporting_wm_check, XCB_ATOM_WINDOW, 0, 1024); reply = xcb_get_property_reply(conn, prop_cookie, &error); - assert(reply); - assert(reply->type == XCB_ATOM_WINDOW); - assert(reply->format == 32); + test_assert_ptr_not_null(reply); + test_assert_enum(reply->type, XCB_ATOM_WINDOW); + test_assert_u8_eq(reply->format, 32); xcb_window_t wm_id = *(xcb_window_t *) xcb_get_property_value(reply); wm_name = get_x11_window_name(window, wm_id); @@ -124,12 +124,12 @@ TEST(xwayland_client_test) color_rgb888(&bg_color, 255, 0, 0); - assert(getenv("DISPLAY")); + test_assert_ptr_not_null(getenv("DISPLAY")); conn = create_x11_connection(); - assert(conn); + test_assert_ptr_not_null(conn); window = create_x11_window(100, 100, 100, 100, conn, bg_color, NULL); - assert(window); + test_assert_ptr_not_null(window); window_x11_set_win_name(window, "Xwayland Test Window"); handle_events_and_check_flags(window, PROPERTY_NAME); @@ -149,27 +149,27 @@ TEST(xwayland_client_test) * _NET_SUPPORTING_WM_CHECK * */ atoms = window_get_atoms(window); - assert(atoms->net_supporting_wm_check != XCB_ATOM_NONE); - assert(atoms->wl_surface_id != XCB_ATOM_NONE); - assert(atoms->net_wm_name != XCB_ATOM_NONE); - assert(atoms->utf8_string != XCB_ATOM_NONE); + test_assert_false(atoms->net_supporting_wm_check == XCB_ATOM_NONE); + test_assert_false(atoms->wl_surface_id == XCB_ATOM_NONE); + test_assert_false(atoms->net_wm_name == XCB_ATOM_NONE); + test_assert_false(atoms->utf8_string == XCB_ATOM_NONE); reply = window_x11_dump_prop(window, window->root_win_id, atoms->net_supporting_wm_check); - assert(reply); - assert(reply->type == XCB_ATOM_WINDOW); + test_assert_ptr_not_null(reply); + test_assert_u8_eq(reply->type, XCB_ATOM_WINDOW); free(reply); window_x11_map(window); handle_events_and_check_flags(window, MAPPED); win_name = get_x11_window_name(window, window->win_id); - assert(strcmp(win_name, "Xwayland Test Window") == 0); + test_assert_str_eq(win_name, "Xwayland Test Window"); free(win_name); wm_name = get_wm_name(window); - assert(wm_name); - assert(strcmp(wm_name, "Weston WM") == 0); + test_assert_ptr_not_null(wm_name); + test_assert_str_eq(wm_name, "Weston WM"); free(wm_name); window_x11_unmap(window);