Compare commits

..

No commits in common. "29002b24e05bd1a07eda499d47eb0cad01c211df" and "b47ccfd93a239d83ed33fecc002df6d08c94b14a" have entirely different histories.

5 changed files with 145 additions and 157 deletions

View file

@ -10,6 +10,12 @@ set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fsanitize=address -pg")
include(FetchContent)
FetchContent_Declare(
unity
GIT_REPOSITORY https://github.com/ThrowTheSwitch/Unity.git
GIT_TAG v2.6.1
)
FetchContent_Declare(
zlog
GIT_REPOSITORY https://github.com/HardySimpson/zlog.git
@ -22,7 +28,7 @@ FetchContent_Declare(
GIT_TAG 682d4520b4bc2b646cdfcf078b2fed00b3d2da30
)
FetchContent_MakeAvailable(zlog argparse)
FetchContent_MakeAvailable(unity zlog argparse)
add_library(libaswm
src/aswm/aswm.c
@ -45,4 +51,13 @@ add_executable(aswm src/aswm/main.c ${argparse_SOURCE_DIR}/argparse.c)
target_include_directories(aswm PUBLIC ${argparse_SOURCE_DIR})
target_link_libraries(aswm libaswm)
add_subdirectory(test)
add_compile_definitions(ASWM_TEST_DIR="${CMAKE_CURRENT_SOURCE_DIR}/test/")
add_executable(test_aswm
test/test_set_up.c
test/aswm/test_aswm.c
)
target_include_directories(test_aswm PUBLIC ${unity_SOURCE_DIR}/src)
target_link_libraries(test_aswm libaswm unity)
enable_testing()
add_test(aswm test_aswm)

View file

@ -1,18 +0,0 @@
FetchContent_Declare(
unity
GIT_REPOSITORY https://github.com/ThrowTheSwitch/Unity.git
GIT_TAG v2.6.1
)
FetchContent_MakeAvailable(unity)
add_compile_definitions(ASWM_TEST_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
add_executable(test_aswm
test_set_up.c
aswm/test_aswm.c
aswm/test_aswm_create_windows.c
)
target_include_directories(test_aswm PUBLIC ${unity_SOURCE_DIR}/src)
target_link_libraries(test_aswm libaswm unity)
enable_testing()
add_test(aswm test_aswm)

View file

@ -1,8 +1,12 @@
#include "aswm/aswm.h"
#include <sys/wait.h>
#include "../test_set_up.h"
#include "test_aswm_create_windows.h"
#include <sys/wait.h>
#include <time.h>
#include <stdlib.h>
clock_t USER_DELAY = 1 * CLOCKS_PER_SEC;
#define MAX_COLOR 65535
void run_aswm(void) {
int stat_loc;
@ -11,6 +15,127 @@ void run_aswm(void) {
TEST_ASSERT_EQUAL_INT(0, waitpid(aswm_pid, &stat_loc, WNOHANG));
}
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);
}
}
// not needed when using generate_test_runner.rb
int main(void) {
UNITY_BEGIN();

View file

@ -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);
}
}

View file

@ -1,3 +0,0 @@
void create_single_resizeable_top_level_window(void);
void create_multiple_resizeable_top_level_window(void);