Skip to content

Commit

Permalink
Add test_unit to all tests
Browse files Browse the repository at this point in the history
Currently it only ensure we do not buffer `stdout`.
  • Loading branch information
wismill committed Feb 21, 2024
1 parent e7570bc commit e325e65
Show file tree
Hide file tree
Showing 23 changed files with 55 additions and 2 deletions.
2 changes: 2 additions & 0 deletions test/atom.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ main(void)
struct atom_table *table;
xkb_atom_t atom1, atom2, atom3;

test_init();

table = atom_table_new();
assert(table);

Expand Down
2 changes: 2 additions & 0 deletions test/buffercomp.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ test_recursive(void)
int
main(int argc, char *argv[])
{
test_init();

struct xkb_context *ctx = test_get_context(0);
struct xkb_keymap *keymap;
char *original, *dump;
Expand Down
11 changes: 9 additions & 2 deletions test/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@

#include "tools/tools-common.h"


/* Setup test */
void
test_init(void)
{
/* Make stdout always unbuffered, to ensure we always get it entirely */
setbuf(stdout, NULL);
}

/*
* Test a sequence of keysyms, resulting from a sequence of key presses,
* against the keysyms they're supposed to generate.
Expand Down Expand Up @@ -298,8 +307,6 @@ test_get_context(enum test_context_flags test_flags)
struct xkb_context *ctx;
char *path;

setbuf(stdout, NULL);

ctx_flags = XKB_CONTEXT_NO_DEFAULT_INCLUDES;
if (test_flags & CONTEXT_ALLOW_ENVIRONMENT_NAMES) {
unsetenv("XKB_DEFAULT_RULES");
Expand Down
2 changes: 2 additions & 0 deletions test/compose.c
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,8 @@ main(int argc, char *argv[])
{
struct xkb_context *ctx;

test_init();

ctx = test_get_context(CONTEXT_NO_FLAG);
assert(ctx);

Expand Down
2 changes: 2 additions & 0 deletions test/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ test_include_order(void)
int
main(void)
{
test_init();

struct xkb_context *context = test_get_context(0);
xkb_atom_t atom;

Expand Down
2 changes: 2 additions & 0 deletions test/filecomp.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ test_file(struct xkb_context *ctx, const char *path_rel)
int
main(void)
{
test_init();

struct xkb_context *ctx = test_get_context(0);

assert(test_file(ctx, "keymaps/basic.xkb"));
Expand Down
2 changes: 2 additions & 0 deletions test/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ test_multiple_keysyms_per_level(void)
int
main(void)
{
test_init();

test_garbage_key();
test_keymap();
test_numeric_keysyms();
Expand Down
2 changes: 2 additions & 0 deletions test/keyseq.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
int
main(void)
{
test_init();

struct xkb_context *ctx = test_get_context(0);
struct xkb_keymap *keymap;

Expand Down
2 changes: 2 additions & 0 deletions test/keysym.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ test_utf32_to_keysym(uint32_t ucs, xkb_keysym_t expected)
int
main(void)
{
test_init();

/* Bounds */
assert(XKB_KEYSYM_MIN == 0);
assert(XKB_KEYSYM_MIN < XKB_KEYSYM_MAX);
Expand Down
2 changes: 2 additions & 0 deletions test/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ main(void)
struct xkb_context *ctx;
int ret;

test_init();

ret = setenv("XKB_LOG_LEVEL", "warn", 1);
assert(ret == 0);
ret = setenv("XKB_LOG_VERBOSITY", "5", 1);
Expand Down
2 changes: 2 additions & 0 deletions test/messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,7 @@ test_message_get(void)
int
main(void)
{
test_init();

test_message_get();
}
2 changes: 2 additions & 0 deletions test/modifiers.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ test_modmap_none(void)
int
main(void)
{
test_init();

test_modmap_none();

return 0;
Expand Down
2 changes: 2 additions & 0 deletions test/registry.c
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,8 @@ test_invalid_include(void)
int
main(void)
{
test_init();

test_no_include_paths();
test_invalid_include();
test_load_basic();
Expand Down
2 changes: 2 additions & 0 deletions test/rules-file-includes.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ main(int argc, char *argv[])
{
struct xkb_context *ctx;

test_init();

setenv("XKB_CONFIG_ROOT", TEST_XKB_CONFIG_ROOT, 1);

ctx = test_get_context(0);
Expand Down
2 changes: 2 additions & 0 deletions test/rules-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ main(int argc, char *argv[])
{
struct xkb_context *ctx;

test_init();

ctx = test_get_context(0);
assert(ctx);

Expand Down
2 changes: 2 additions & 0 deletions test/rulescomp.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ test_rmlvo_env(struct xkb_context *ctx, const char *rules, const char *model,
int
main(int argc, char *argv[])
{
test_init();

struct xkb_context *ctx = test_get_context(CONTEXT_ALLOW_ENVIRONMENT_NAMES);

assert(ctx);
Expand Down
2 changes: 2 additions & 0 deletions test/state.c
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,8 @@ test_ctrl_string_transformation(struct xkb_keymap *keymap)
int
main(void)
{
test_init();

struct xkb_context *context = test_get_context(0);
struct xkb_keymap *keymap;

Expand Down
2 changes: 2 additions & 0 deletions test/stringcomp.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
int
main(int argc, char *argv[])
{
test_init();

struct xkb_context *ctx = test_get_context(0);
struct xkb_keymap *keymap;
char *original, *dump, *dump2;
Expand Down
3 changes: 3 additions & 0 deletions test/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
assert_printf(streq_not_null(expected, got), \
test_name ". Expected \"%s\", got: \"%s\"\n", expected, got)

void
test_init(void);

/* The offset between KEY_* numbering, and keycodes in the XKB evdev
* dataset. */
#define EVDEV_OFFSET 8
Expand Down
3 changes: 3 additions & 0 deletions test/utf8.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <stddef.h>
#include <string.h>

#include "test.h"
#include "utf8.h"
#include "utils.h"

Expand Down Expand Up @@ -180,6 +181,8 @@ test_utf32_to_utf8(void)
int
main(void)
{
test_init();

test_is_valid_utf8();
test_utf32_to_utf8();

Expand Down
2 changes: 2 additions & 0 deletions test/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ main(void)
{
char buffer[10];

test_init();

assert(!snprintf_safe(buffer, 0, "foo"));
assert(!snprintf_safe(buffer, 1, "foo"));
assert(!snprintf_safe(buffer, 3, "foo"));
Expand Down
2 changes: 2 additions & 0 deletions test/x11.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,7 @@ X11_TEST(test_basic)
}

int main(void) {
test_init();

return x11_tests_run();
}
2 changes: 2 additions & 0 deletions test/x11comp.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,7 @@ X11_TEST(test_basic)
}

int main(void) {
test_init();

return x11_tests_run();
}

0 comments on commit e325e65

Please sign in to comment.