From 24a66e41d1f0abcce60324525fc2d098dcd52d69 Mon Sep 17 00:00:00 2001 From: Paul Breugnot Date: Sat, 17 May 2025 12:13:02 +0200 Subject: [PATCH] :white_check_mark: Fix window size test (WM_NORMAL_HINTS handling) --- src/aswm/mapper/mapper.c | 1 - test/CMakeLists.txt | 3 +- test/aswm/aswm.c | 2 + test/aswm/create_windows.h | 11 ---- .../aswm/create_windows/multiple_resizeable.c | 1 + test/aswm/create_windows/single_fixed_size.c | 2 + test/aswm/create_windows/single_resizeable.c | 1 + test/aswm/property.h | 9 +++ test/aswm/property/fix_size.c | 59 +++++++++++++++++++ test/{aswm/create_windows.c => utils.c} | 6 +- test/utils.h | 16 +++++ 11 files changed, 96 insertions(+), 15 deletions(-) create mode 100644 test/aswm/property.h create mode 100644 test/aswm/property/fix_size.c rename test/{aswm/create_windows.c => utils.c} (91%) create mode 100644 test/utils.h diff --git a/src/aswm/mapper/mapper.c b/src/aswm/mapper/mapper.c index dd84480..9592a0c 100644 --- a/src/aswm/mapper/mapper.c +++ b/src/aswm/mapper/mapper.c @@ -144,7 +144,6 @@ void resize_stack(Display* display, Window stack) { for(auto i = 0; i < children_count; i++) { XWindowAttributes child_attributes; XGetWindowAttributes(display, children[i], &child_attributes); - aswm_notice("Resize stack to %lu - %i %i", children[i], child_attributes.width, child_attributes.height); if(child_attributes.map_state != IsUnmapped) { if(child_attributes.width > width) width = child_attributes.width; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8b41852..c7a8b9d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -8,11 +8,12 @@ FetchContent_MakeAvailable(unity) add_compile_definitions(ASWM_TEST_DIR="${CMAKE_CURRENT_SOURCE_DIR}") add_executable(test_aswm test_set_up.c + utils.c aswm/aswm.c - aswm/create_windows.c aswm/create_windows/single_resizeable.c aswm/create_windows/multiple_resizeable.c aswm/create_windows/single_fixed_size.c + aswm/property/fix_size.c ) target_include_directories(test_aswm PUBLIC ${unity_SOURCE_DIR}/src) target_link_libraries(test_aswm libaswm unity) diff --git a/test/aswm/aswm.c b/test/aswm/aswm.c index 25e239b..30a0791 100644 --- a/test/aswm/aswm.c +++ b/test/aswm/aswm.c @@ -3,6 +3,7 @@ #include "../test_set_up.h" #include "create_windows.h" +#include "property.h" void run_aswm(void) { int stat_loc; @@ -20,6 +21,7 @@ int main(void) { RUN_TEST(create_single_resizeable_top_level_window); RUN_TEST(create_multiple_resizeable_top_level_window); RUN_TEST(create_single_fixed_size_top_level_window); + RUN_TEST(fix_size_of_an_existing_single_top_level_window); } tear_down_test_logger(); return UNITY_END(); diff --git a/test/aswm/create_windows.h b/test/aswm/create_windows.h index 694f69d..45dbd24 100644 --- a/test/aswm/create_windows.h +++ b/test/aswm/create_windows.h @@ -1,20 +1,9 @@ #ifndef TEST_ASWM_CREATE_WINDOWS #define TEST_ASWM_CREATE_WINDOWS -#include - #include "aswm/aswm.h" #include "../test_set_up.h" -extern clock_t USER_DELAY; - -XColor red(float intensity); -XColor blue(float intensity); - -Window parent(Display* display, Window window); -int wait_visibility(Display* display, Window window); -void wait_array_visibility(Display* display, int N, Window* windows, int* visibilities); - void create_single_resizeable_top_level_window(void); void create_multiple_resizeable_top_level_window(void); void create_single_fixed_size_top_level_window(void); diff --git a/test/aswm/create_windows/multiple_resizeable.c b/test/aswm/create_windows/multiple_resizeable.c index b562539..448dd11 100644 --- a/test/aswm/create_windows/multiple_resizeable.c +++ b/test/aswm/create_windows/multiple_resizeable.c @@ -1,4 +1,5 @@ #include "../create_windows.h" +#include "../../utils.h" void create_multiple_resizeable_top_level_window(void) { const int N = 10; diff --git a/test/aswm/create_windows/single_fixed_size.c b/test/aswm/create_windows/single_fixed_size.c index 2cf1b48..15bc6eb 100644 --- a/test/aswm/create_windows/single_fixed_size.c +++ b/test/aswm/create_windows/single_fixed_size.c @@ -1,4 +1,5 @@ #include "../create_windows.h" +#include "../../utils.h" void create_single_fixed_size_top_level_window(void) { Window window = XCreateSimpleWindow(test_display, test_root, @@ -61,3 +62,4 @@ void create_single_fixed_size_top_level_window(void) { TEST_ASSERT_EQUAL_INT(0, child_attributes.border_width); TEST_ASSERT_EQUAL_INT(IsViewable, child_attributes.map_state); } + diff --git a/test/aswm/create_windows/single_resizeable.c b/test/aswm/create_windows/single_resizeable.c index 8544f8a..60937d4 100644 --- a/test/aswm/create_windows/single_resizeable.c +++ b/test/aswm/create_windows/single_resizeable.c @@ -1,4 +1,5 @@ #include "../create_windows.h" +#include "../../utils.h" void create_single_resizeable_top_level_window(void) { Window window = XCreateSimpleWindow(test_display, test_root, diff --git a/test/aswm/property.h b/test/aswm/property.h new file mode 100644 index 0000000..26e6f6e --- /dev/null +++ b/test/aswm/property.h @@ -0,0 +1,9 @@ +#ifndef TEST_ASWM_PROPERTY +#define TEST_ASWM_PROPERTY + +#include "aswm/aswm.h" +#include "../test_set_up.h" + +void fix_size_of_an_existing_single_top_level_window(void); + +#endif diff --git a/test/aswm/property/fix_size.c b/test/aswm/property/fix_size.c new file mode 100644 index 0000000..a8c8436 --- /dev/null +++ b/test/aswm/property/fix_size.c @@ -0,0 +1,59 @@ +#include "../property.h" +#include "../../utils.h" + +void fix_size_of_an_existing_single_top_level_window(void) { + Window window = XCreateSimpleWindow(test_display, test_root, + 10 /*x*/, 10 /*y*/, 128 /*w*/, 128 /*h*/, + 0 /*TODO: border width*/, CopyFromParent /*depth*/, blue(1).pixel /* background */); + // The top level window might have children. Those must **not** be altered + // by the Window Manager + Window child = XCreateSimpleWindow(test_display, window, + 0, 0, 25, 30, + 0, CopyFromParent, red(1).pixel); + + XMapWindow(test_display, child); + XMapWindow(test_display, window); + // Ensures the window is mapped before setting WM_NORMAL_HINTS + int visibility = wait_visibility(test_display, window); + + const int fixed_width = 250; + const int fixed_height = 75; + { + XSizeHints* normal_size = XAllocSizeHints(); + normal_size->flags = PMinSize | PMaxSize; + normal_size->min_width = fixed_width; + normal_size->max_width = fixed_width; + normal_size->min_height = fixed_height; + normal_size->max_height = fixed_height; + + XSetWMNormalHints(test_display, window, normal_size); + XFree(normal_size); + } + + visibility = wait_visibility(test_display, window); + + // The top level window if fully visible + XWindowAttributes attributes; + XGetWindowAttributes(test_display, window, &attributes); + TEST_ASSERT_EQUAL_INT(VisibilityUnobscured, visibility); + TEST_ASSERT_EQUAL_INT(IsViewable, attributes.map_state); + + // The top level window has its size preserved + XWindowAttributes window_attributes; + XGetWindowAttributes(test_display, window, &window_attributes); + TEST_ASSERT_EQUAL_INT(fixed_width, window_attributes.width); + TEST_ASSERT_EQUAL_INT(fixed_height, window_attributes.height); + + // Check the child structure is unaltered + TEST_ASSERT_EQUAL(parent(test_display, child), window); + + XWindowAttributes child_attributes; + XGetWindowAttributes(test_display, child, &child_attributes); + + TEST_ASSERT_EQUAL_INT(0, child_attributes.x); + TEST_ASSERT_EQUAL_INT(0, child_attributes.y); + TEST_ASSERT_EQUAL_INT(25, child_attributes.width); + TEST_ASSERT_EQUAL_INT(30, child_attributes.height); + TEST_ASSERT_EQUAL_INT(0, child_attributes.border_width); + TEST_ASSERT_EQUAL_INT(IsViewable, child_attributes.map_state); +} diff --git a/test/aswm/create_windows.c b/test/utils.c similarity index 91% rename from test/aswm/create_windows.c rename to test/utils.c index ef43a90..994230b 100644 --- a/test/aswm/create_windows.c +++ b/test/utils.c @@ -1,8 +1,10 @@ -#include "create_windows.h" +#include "utils.h" +#include "test_set_up.h" #define MAX_COLOR 65535 -clock_t USER_DELAY = 1 * CLOCKS_PER_SEC; +const time_t USER_DELAY_S = 1; +const clock_t USER_DELAY = USER_DELAY_S * CLOCKS_PER_SEC; XColor red(float intensity) { XColor red; diff --git a/test/utils.h b/test/utils.h new file mode 100644 index 0000000..334c88f --- /dev/null +++ b/test/utils.h @@ -0,0 +1,16 @@ +#ifndef TEST_UTILS +#define TEST_UTILS + +#include +#include + +extern const clock_t USER_DELAY; + +XColor red(float intensity); +XColor blue(float intensity); + +Window parent(Display* display, Window window); +int wait_visibility(Display* display, Window window); +void wait_array_visibility(Display* display, int N, Window* windows, int* visibilities); + +#endif