From f0182e8d490a0d965223996f12766d1d7d69ff8f Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Sun, 5 Dec 2021 00:31:40 +0500 Subject: [PATCH] Add tests for BasicGeom --- Makefile | 1 + tests/geom_basic_geom.c | 60 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 tests/geom_basic_geom.c diff --git a/Makefile b/Makefile index eac0f1f..bf4842c 100644 --- a/Makefile +++ b/Makefile @@ -36,6 +36,7 @@ DWM_SRC = \ src/dwm/xerror.c TEST_SRC = \ + tests/geom_basic_geom.c \ tests/geom_position.c \ tests/geom_sizes.c diff --git a/tests/geom_basic_geom.c b/tests/geom_basic_geom.c new file mode 100644 index 0000000..de6a914 --- /dev/null +++ b/tests/geom_basic_geom.c @@ -0,0 +1,60 @@ +#include + +#include "../src/geom.h" + +static void test_create(); +static void test_init(); +static void test_create_from_args(); +static void test_init_from_args(); + +void test() { + test_create(); + test_init(); + test_create_from_args(); + test_init_from_args(); +} + +void test_create() +{ + const struct BasicGeom basic_geom = basic_geom_create(); + assert(basic_geom.position.x == 0); + assert(basic_geom.position.y == 0); + assert(basic_geom.sizes.w == 0); + assert(basic_geom.sizes.h == 0); +} + +void test_init() +{ + struct BasicGeom basic_geom = { + .position = { .x = 12, .y = 34 }, + .sizes = { .w = 56, .h = 68 }, + }; + basic_geom_init(&basic_geom); + assert(basic_geom.position.x == 0); + assert(basic_geom.position.y == 0); + assert(basic_geom.sizes.w == 0); + assert(basic_geom.sizes.h == 0); +} + +void test_create_from_args() +{ + const struct BasicGeom basic_geom = + basic_geom_create_from_args(12, 34, 56, 78); + assert(basic_geom.position.x == 12); + assert(basic_geom.position.y == 34); + assert(basic_geom.sizes.w == 56); + assert(basic_geom.sizes.h == 78); +} + +void test_init_from_args() +{ + struct BasicGeom basic_geom = { + .position = { .x = 0, .y = 0 }, + .sizes = { .w = 0, .h = 0 }, + }; + basic_geom_init_from_args(&basic_geom, 12, 34, 56, 78); + assert(basic_geom.position.x == 12); + assert(basic_geom.position.y == 34); + assert(basic_geom.sizes.w == 56); + assert(basic_geom.sizes.h == 78); +}