diff --git a/test/test.h b/test/test.h index 4e9786c3..085a663d 100644 --- a/test/test.h +++ b/test/test.h @@ -97,8 +97,8 @@ extern const char testUTF8Combined[]; extern const char testUTF8InvalidInput[]; extern const char testUTF8InvalidOutput[]; extern bool utf8equal(const char *s, const char *t); -extern void utf8diffErrorfFull(const char *file, long line, const char *msg, const char *got, const char *want); -#define utf8diffErrorf(msg, got, want) utf8diffErrorfFull(__FILE__, __LINE__, msg, got, want) +extern void utf8diffErrorFull(const char *file, long line, const char *msg, const char *got, const char *want); +#define utf8diffError(msg, got, want) utf8diffErrorFull(__FILE__, __LINE__, msg, got, want) #ifdef __cplusplus } diff --git a/test/utf8.c b/test/utf8.c index 62153265..8a073e80 100644 --- a/test/utf8.c +++ b/test/utf8.c @@ -83,7 +83,7 @@ static void utf8hexdump(char buf[64], const char *s) } } -void utf8diffErrorfFull(const char *file, long line, const char *msg, const char *got, const char *want) +void utf8diffErrorFull(const char *file, long line, const char *msg, const char *got, const char *want) { char a[64], b[64]; diff --git a/test/window.c b/test/window.c index cae1efb2..ece8343e 100644 --- a/test/window.c +++ b/test/window.c @@ -26,13 +26,59 @@ Test(InitialWindowTitleIsEmptyString) w = uiNewWindow(); title = uiWindowTitle(w); - // TODO have a utf8cmp() - if (*title != 0) - // TODO have a diffUTF8 - TestErrorf("brand new uiWindow has wrong title:" diff("%s"), - title, "(empty string)"); + if (!utf8equal(title, testUTF8Empty)) + utf8diffError("brand new uiWindow has wrong title", title, testUTF8Empty); uiControlFree(uiControl(w)); } -// TODO check that SetTitle works, and also that it sanitizes -// TODO for all the above, check that the underlying title was also set appropriately +static void testSetWindowTitleImplFull(const char *file, long line, const char *title, const char *want) +{ + uiWindow *w; + const char *got; + + w = uiNewWindow(); + uiWindowSetTitle(w, title); + got = uiWindowTitle(w); + if (!utf8equal(got, want)) + utf8diffErrorFull(file, line, "uiWindowTitle() reported wrong title after uiWindowSetTitle()", got, want); + uiControlFree(uiControl(w)); +} + +#define testSetWindowTitleImpl(title, want) testSetWindowTitleImplFull(__FILE__, __LINE__, title, want) + +Test(SetWindowTitle_Empty) +{ + testSetWindowTitleImpl(testUTF8Empty, testUTF8Empty); +} + +Test(SetWindowTitle_ASCIIOnly) +{ + testSetWindowTitleImpl(testUTF8ASCIIOnly, testUTF8ASCIIOnly); +} + +Test(SetWindowTitle_WithTwoByte) +{ + testSetWindowTitleImpl(testUTF8WithTwoByte, testUTF8WithTwoByte); +} + +Test(SetWindowTitle_WithThreeByte) +{ + testSetWindowTitleImpl(testUTF8WithThreeByte, testUTF8WithThreeByte); +} + +Test(SetWindowTitle_WithFourByte) +{ + testSetWindowTitleImpl(testUTF8WithFourByte, testUTF8WithFourByte); +} + +Test(SetWindowTitle_Combined) +{ + testSetWindowTitleImpl(testUTF8Combined, testUTF8Combined); +} + +Test(SetWindowTitle_Invalid) +{ + testSetWindowTitleImpl(testUTF8InvalidInput, testUTF8InvalidOutput); +} + +// TODO for all the above, check that the underlying OS-level title was also set appropriately