diff --git a/test/window_windows.c b/test/window_windows.c new file mode 100644 index 00000000..0b4f1435 --- /dev/null +++ b/test/window_windows.c @@ -0,0 +1,80 @@ +// 24 may 2020 +#include "test_windows.h" + +Test(WindowHasHandleFromStart) +{ + uiWindow *a; + + a = uiNewWindow(); + if (uiWindowsControlHandle(uiControl(a)) == NULL) + TestErrorf("uiWindowsControlHandle(brand new uiWindow) is NULL; should not be"); + uiControlFree(uiControl(a)); +} + +Test(InitialWindowTitleIsEmptyString_OSLevel) +{ + uiWindow *w; + HWND hwnd; + uint16_t *title; + + w = uiNewWindow(); + hwnd = uiWindowsControlHandle(uiControl(w)); + title = testGetWindowText(hwnd); + if (!utf16equal(title, testUTF16Empty)) + utf16diffError("brand new uiWindow has wrong title", title, testUTF16Empty); + free(title); + uiControlFree(uiControl(w)); +} + +static void testSetWindowTitleImplFull(const char *file, long line, const char *title, const uint16_t *want) +{ + uiWindow *w; + HWND hwnd; + uint16_t *got; + + w = uiNewWindow(); + uiWindowSetTitle(w, title); + hwnd = uiWindowsControlHandle(uiControl(w)); + got = testGetWindowText(hwnd); + if (!utf16equal(got, want)) + utf16diffErrorFull(file, line, "GetWindowTextW() reported wrong title after uiWindowSetTitle()", got, want); + free(got); + uiControlFree(uiControl(w)); +} + +#define testSetWindowTitleImpl(title, want) testSetWindowTitleImplFull(__FILE__, __LINE__, title, want) + +Test(SetWindowTitle_OSLevel_Empty) +{ + testSetWindowTitleImpl(testUTF8Empty, testUTF16Empty); +} + +Test(SetWindowTitle_OSLevel_ASCIIOnly) +{ + testSetWindowTitleImpl(testUTF8ASCIIOnly, testUTF16ASCIIOnly); +} + +Test(SetWindowTitle_OSLevel_WithTwoByte) +{ + testSetWindowTitleImpl(testUTF8WithTwoByte, testUTF16WithTwoByte); +} + +Test(SetWindowTitle_OSLevel_WithThreeByte) +{ + testSetWindowTitleImpl(testUTF8WithThreeByte, testUTF16WithThreeByte); +} + +Test(SetWindowTitle_OSLevel_WithFourByte) +{ + testSetWindowTitleImpl(testUTF8WithFourByte, testUTF16WithFourByte); +} + +Test(SetWindowTitle_OSLevel_Combined) +{ + testSetWindowTitleImpl(testUTF8Combined, testUTF16Combined); +} + +Test(SetWindowTitle_OSLevel_Invalid) +{ + testSetWindowTitleImpl(testUTF8InvalidInput, testUTF16InvalidOutput); +}