🧪 Failing create fixed size window test
+ test structure improvements
This commit is contained in:
parent
29002b24e0
commit
a888c234a3
9 changed files with 225 additions and 139 deletions
|
@ -8,8 +8,11 @@ FetchContent_MakeAvailable(unity)
|
||||||
add_compile_definitions(ASWM_TEST_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
|
add_compile_definitions(ASWM_TEST_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
|
||||||
add_executable(test_aswm
|
add_executable(test_aswm
|
||||||
test_set_up.c
|
test_set_up.c
|
||||||
aswm/test_aswm.c
|
aswm/aswm.c
|
||||||
aswm/test_aswm_create_windows.c
|
aswm/create_windows.c
|
||||||
|
aswm/create_windows/single_resizeable.c
|
||||||
|
aswm/create_windows/multiple_resizeable.c
|
||||||
|
aswm/create_windows/single_fixed_size.c
|
||||||
)
|
)
|
||||||
target_include_directories(test_aswm PUBLIC ${unity_SOURCE_DIR}/src)
|
target_include_directories(test_aswm PUBLIC ${unity_SOURCE_DIR}/src)
|
||||||
target_link_libraries(test_aswm libaswm unity)
|
target_link_libraries(test_aswm libaswm unity)
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
|
||||||
#include "../test_set_up.h"
|
#include "../test_set_up.h"
|
||||||
#include "test_aswm_create_windows.h"
|
#include "create_windows.h"
|
||||||
|
|
||||||
void run_aswm(void) {
|
void run_aswm(void) {
|
||||||
int stat_loc;
|
int stat_loc;
|
||||||
|
@ -17,8 +17,9 @@ int main(void) {
|
||||||
set_up_test_logger();
|
set_up_test_logger();
|
||||||
if(check_xephyr_available()) {
|
if(check_xephyr_available()) {
|
||||||
RUN_TEST(run_aswm);
|
RUN_TEST(run_aswm);
|
||||||
RUN_TEST(create_single_resizeable_top_level_window);
|
/*RUN_TEST(create_single_resizeable_top_level_window);*/
|
||||||
RUN_TEST(create_multiple_resizeable_top_level_window);
|
/*RUN_TEST(create_multiple_resizeable_top_level_window);*/
|
||||||
|
RUN_TEST(create_single_fixed_size_top_level_window);
|
||||||
}
|
}
|
||||||
tear_down_test_logger();
|
tear_down_test_logger();
|
||||||
return UNITY_END();
|
return UNITY_END();
|
55
test/aswm/create_windows.c
Normal file
55
test/aswm/create_windows.c
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
#include "create_windows.h"
|
||||||
|
|
||||||
|
#define MAX_COLOR 65535
|
||||||
|
|
||||||
|
clock_t USER_DELAY = 1 * CLOCKS_PER_SEC;
|
||||||
|
|
||||||
|
XColor red(float intensity) {
|
||||||
|
XColor red;
|
||||||
|
red.red = intensity * MAX_COLOR;
|
||||||
|
XAllocColor(test_display, XDefaultColormap(test_display, DefaultScreen(test_display)), &red);
|
||||||
|
return red;
|
||||||
|
}
|
||||||
|
|
||||||
|
XColor blue(float intensity) {
|
||||||
|
XColor blue;
|
||||||
|
blue.blue = intensity * MAX_COLOR;
|
||||||
|
XAllocColor(test_display, XDefaultColormap(test_display, DefaultScreen(test_display)), &blue);
|
||||||
|
return blue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int wait_visibility(Display* display, Window window) {
|
||||||
|
int visibility;
|
||||||
|
XSelectInput(test_display, window, VisibilityChangeMask);
|
||||||
|
|
||||||
|
clock_t start = clock();
|
||||||
|
while((clock() - start) < USER_DELAY) {
|
||||||
|
XEvent e;
|
||||||
|
XCheckWindowEvent(test_display, window, VisibilityChangeMask, &e);
|
||||||
|
visibility = e.xvisibility.state;
|
||||||
|
}
|
||||||
|
return visibility;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wait_array_visibility(Display* display, int N, Window* windows, int* visibilities) {
|
||||||
|
for(auto i = 0; i < N; i++)
|
||||||
|
XSelectInput(test_display, windows[i], VisibilityChangeMask);
|
||||||
|
|
||||||
|
clock_t user_time = clock();
|
||||||
|
while((clock() - user_time) < USER_DELAY * N) {
|
||||||
|
for(auto i = 0; i < N; i++) {
|
||||||
|
XEvent e;
|
||||||
|
XCheckWindowEvent(test_display, windows[i], VisibilityChangeMask, &e);
|
||||||
|
visibilities[i] = e.xvisibility.state;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Window parent(Display* display, Window window) {
|
||||||
|
Window _root;
|
||||||
|
Window parent;
|
||||||
|
Window* _children;
|
||||||
|
unsigned int _children_count;
|
||||||
|
XQueryTree(test_display, window, &_root, &parent, &_children, &_children_count);
|
||||||
|
return parent;
|
||||||
|
}
|
25
test/aswm/create_windows.h
Normal file
25
test/aswm/create_windows.h
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
#ifndef TEST_ASWM_CREATE_WINDOWS
|
||||||
|
#define TEST_ASWM_CREATE_WINDOWS
|
||||||
|
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#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);
|
||||||
|
void create_multiple_fixed_size_top_level_window(void);
|
||||||
|
void create_single_fixed_size_top_level_window_on_top_of_resizeable_windows(void);
|
||||||
|
void create_multiple_fixed_size_top_level_window_on_top_of_resizeable_windows(void);
|
||||||
|
|
||||||
|
#endif
|
45
test/aswm/create_windows/multiple_resizeable.c
Normal file
45
test/aswm/create_windows/multiple_resizeable.c
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
#include "../create_windows.h"
|
||||||
|
|
||||||
|
void create_multiple_resizeable_top_level_window(void) {
|
||||||
|
const int N = 10;
|
||||||
|
Window windows[N];
|
||||||
|
Window children[N];
|
||||||
|
|
||||||
|
for(auto i = 0; i < N; i++) {
|
||||||
|
windows[i] = XCreateSimpleWindow(test_display, test_root,
|
||||||
|
10 /*x*/, 10 /*y*/, 128 /*w*/, 128 /*h*/,
|
||||||
|
0 /*TODO: border width*/, CopyFromParent /*depth*/, blue(((float) i+1)/N).pixel /* background */);
|
||||||
|
// The top level windows might have children. Those must **not** be
|
||||||
|
// altered by the Window Manager
|
||||||
|
children[i] = XCreateSimpleWindow(test_display, windows[i],
|
||||||
|
0, 0, 25, 30,
|
||||||
|
0, CopyFromParent, red(1).pixel);
|
||||||
|
XMapWindow(test_display, children[i]);
|
||||||
|
XMapWindow(test_display, windows[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int visibility[N];
|
||||||
|
wait_array_visibility(test_display, N, windows, visibility);
|
||||||
|
|
||||||
|
for(auto i = 0; i < N; i++) {
|
||||||
|
// All top level windows must be fully visible
|
||||||
|
XWindowAttributes attributes;
|
||||||
|
XGetWindowAttributes(test_display, windows[i], &attributes);
|
||||||
|
TEST_ASSERT_EQUAL_INT(VisibilityUnobscured, visibility[i]);
|
||||||
|
TEST_ASSERT_EQUAL_INT(IsViewable, attributes.map_state);
|
||||||
|
|
||||||
|
// Check the children structure is unaltered
|
||||||
|
TEST_ASSERT_EQUAL(parent(test_display, children[i]), windows[i]);
|
||||||
|
|
||||||
|
XWindowAttributes child_attributes;
|
||||||
|
XGetWindowAttributes(test_display, children[i], &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);
|
||||||
|
}
|
||||||
|
}
|
56
test/aswm/create_windows/single_fixed_size.c
Normal file
56
test/aswm/create_windows/single_fixed_size.c
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
#include "../create_windows.h"
|
||||||
|
|
||||||
|
void create_single_fixed_size_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);
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
XMapWindow(test_display, window);
|
||||||
|
|
||||||
|
int 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);
|
||||||
|
|
||||||
|
}
|
35
test/aswm/create_windows/single_resizeable.c
Normal file
35
test/aswm/create_windows/single_resizeable.c
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
#include "../create_windows.h"
|
||||||
|
|
||||||
|
void create_single_resizeable_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);
|
||||||
|
|
||||||
|
int 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);
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
}
|
|
@ -1,131 +0,0 @@
|
||||||
#include "test_aswm_create_windows.h"
|
|
||||||
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
#include "aswm/aswm.h"
|
|
||||||
#include "../test_set_up.h"
|
|
||||||
|
|
||||||
clock_t USER_DELAY = 1 * CLOCKS_PER_SEC;
|
|
||||||
#define MAX_COLOR 65535
|
|
||||||
|
|
||||||
void create_single_resizeable_top_level_window(void) {
|
|
||||||
XColor blue;
|
|
||||||
blue.blue = MAX_COLOR;
|
|
||||||
XAllocColor(test_display, XDefaultColormap(test_display, DefaultScreen(test_display)), &blue);
|
|
||||||
|
|
||||||
XColor red;
|
|
||||||
red.red = MAX_COLOR;
|
|
||||||
XAllocColor(test_display, XDefaultColormap(test_display, DefaultScreen(test_display)), &red);
|
|
||||||
|
|
||||||
Window window = XCreateSimpleWindow(test_display, test_root,
|
|
||||||
10 /*x*/, 10 /*y*/, 128 /*w*/, 128 /*h*/,
|
|
||||||
0 /*TODO: border width*/, CopyFromParent /*depth*/, blue.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.pixel);
|
|
||||||
XSelectInput(test_display, window, VisibilityChangeMask);
|
|
||||||
XMapWindow(test_display, child);
|
|
||||||
XMapWindow(test_display, window);
|
|
||||||
|
|
||||||
int visibility;
|
|
||||||
clock_t start = clock();
|
|
||||||
while((clock() - start) < USER_DELAY) {
|
|
||||||
XEvent e;
|
|
||||||
XCheckWindowEvent(test_display, window, VisibilityChangeMask, &e);
|
|
||||||
visibility = e.xvisibility.state;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
|
|
||||||
// Check the child structure is unaltered
|
|
||||||
Window root;
|
|
||||||
Window parent;
|
|
||||||
Window* children;
|
|
||||||
unsigned int children_count;
|
|
||||||
XQueryTree(test_display, child, &root, &parent, &children, &children_count);
|
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL(parent, 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
void create_multiple_resizeable_top_level_window(void) {
|
|
||||||
XColor red;
|
|
||||||
red.red = MAX_COLOR;
|
|
||||||
XAllocColor(test_display, XDefaultColormap(test_display, DefaultScreen(test_display)), &red);
|
|
||||||
|
|
||||||
const int N = 10;
|
|
||||||
Window windows[N];
|
|
||||||
Window children[N];
|
|
||||||
|
|
||||||
for(auto i = 0; i < N; i++) {
|
|
||||||
XColor blue;
|
|
||||||
blue.blue = (i+1) * MAX_COLOR / N;
|
|
||||||
XAllocColor(test_display, XDefaultColormap(test_display, DefaultScreen(test_display)), &blue);
|
|
||||||
|
|
||||||
windows[i] = XCreateSimpleWindow(test_display, test_root,
|
|
||||||
10 /*x*/, 10 /*y*/, 128 /*w*/, 128 /*h*/,
|
|
||||||
0 /*TODO: border width*/, CopyFromParent /*depth*/, blue.pixel /* background */);
|
|
||||||
// The top level windows might have children. Those must **not** be
|
|
||||||
// altered by the Window Manager
|
|
||||||
children[i] = XCreateSimpleWindow(test_display, windows[i],
|
|
||||||
0, 0, 25, 30,
|
|
||||||
0, CopyFromParent, red.pixel);
|
|
||||||
XSelectInput(test_display, windows[i], VisibilityChangeMask);
|
|
||||||
XMapWindow(test_display, children[i]);
|
|
||||||
XMapWindow(test_display, windows[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
clock_t user_time = clock();
|
|
||||||
int visibility[N];
|
|
||||||
while((clock() - user_time) < USER_DELAY * N) {
|
|
||||||
for(auto i = 0; i < N; i++) {
|
|
||||||
XEvent e;
|
|
||||||
XCheckWindowEvent(test_display, windows[i], VisibilityChangeMask, &e);
|
|
||||||
visibility[i] = e.xvisibility.state;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(auto i = 0; i < N; i++) {
|
|
||||||
// All top level windows must be fully visible
|
|
||||||
XWindowAttributes attributes;
|
|
||||||
XGetWindowAttributes(test_display, windows[i], &attributes);
|
|
||||||
TEST_ASSERT_EQUAL_INT(VisibilityUnobscured, visibility[i]);
|
|
||||||
TEST_ASSERT_EQUAL_INT(IsViewable, attributes.map_state);
|
|
||||||
|
|
||||||
// Check the children structure is unaltered
|
|
||||||
Window _root;
|
|
||||||
Window parent;
|
|
||||||
Window* _children;
|
|
||||||
unsigned int _children_count;
|
|
||||||
XQueryTree(test_display, children[i], &_root, &parent, &_children, &_children_count);
|
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL(parent, windows[i]);
|
|
||||||
|
|
||||||
XWindowAttributes child_attributes;
|
|
||||||
XGetWindowAttributes(test_display, children[i], &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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
|
|
||||||
void create_single_resizeable_top_level_window(void);
|
|
||||||
void create_multiple_resizeable_top_level_window(void);
|
|
Loading…
Add table
Reference in a new issue