From: Michael D. Lowis Date: Mon, 4 Mar 2019 04:20:11 +0000 (-0500) Subject: moved some macors around X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=a382f770d777b02748a38c6931165e9b8fef1dae;p=projs%2Ftide.git moved some macors around --- diff --git a/Makefile b/Makefile index 7d3c61c..5be212d 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ CC = ./acc INCS = -Iinc/ BINS = bin/tide bin/registrar bin/edit bin/fetch bin/pick +TEST_BINS = tests/libedit MAN1 = docs/tide.1 LIBEDIT_OBJS = \ @@ -13,8 +14,6 @@ LIBEDIT_OBJS = \ src/lib/x11_gc.o \ src/lib/x11_sel.o -TEST_BINS = tests/libedit tests/test_tide - include config.mk .PHONY: all docs clean install uninstall test diff --git a/inc/atf.h b/inc/atf.h index 467b802..ca7b30a 100644 --- a/inc/atf.h +++ b/inc/atf.h @@ -56,9 +56,6 @@ int atf_print_results(void); #define EXPECT_EXIT \ if ((ExitExpected = true, 0 == setjmp(ExitPad))) -#define QCHECK(desc, prop, ...) \ - CHECK(qcheck(desc, prop, __VA_ARGS__)) - /* Function Definitions *****************************************************************************/ #ifdef INCLUDE_DEFS diff --git a/inc/qcheck.h b/inc/qcheck.h index 605e3e8..ff0322b 100644 --- a/inc/qcheck.h +++ b/inc/qcheck.h @@ -1,5 +1,5 @@ /** - QCheck - A minimalistic property based testing framework. + QCheck - A minimal property-based testing framework. Copyright 2019 Michael D. Lowis @@ -53,6 +53,14 @@ typedef QCValue* (*QCGenFn)(void); #define QASSERT(cond) \ if (!(cond)) return 0 +#define QCHECK(desc, prop, ...) \ + CHECK(qcheck(desc, prop, __VA_ARGS__)) + +#ifndef CHECK +#include +#define CHECK assert +#endif + static inline QCValue* qcgetval(int nvals, QCValue** vals, int i) { return vals[i < nvals ? i : nvals-1]; } @@ -93,7 +101,7 @@ QCValue* GenAsciiString(void); #include #include -static int Seed = 0, NTrials = 5000; +static int Seed = 0, NTrials = 1000; void qcinit(int seed) { Seed = (seed ? seed : time(NULL)); @@ -154,6 +162,7 @@ int qcheck(char* desc, QCProp prop, int nvals, ...) { int passed = 0; QCResult result; va_list vals; + #pragma omp parallel for for (int i = 0; i < NTrials; i++) { va_start(vals, nvals); result = vqcheck(prop, nvals, vals); diff --git a/tests/lib/buf.c b/tests/lib/buf.c index d529fa9..55b120b 100644 --- a/tests/lib/buf.c +++ b/tests/lib/buf.c @@ -41,6 +41,14 @@ PROPERTY(getc_returns_putc) { return (IVAL(0) == buf_getc(&TestBuf)); } +PROPERTY(getc_returns_error) { + setup_buffer(); + buf_putc(&TestBuf, IVAL(0)); + TestBuf.selection.end = TestBuf.selection.beg = 0; + printf("0x%08x\n", buf_getc(&TestBuf)); + return (0xFFFD == buf_getc(&TestBuf)); +} + PROPERTY(gets_returns_puts) { setup_buffer(); char* input = VAL(0,char*); @@ -73,18 +81,31 @@ PROPERTY(edit_operations_are_reversible) { return 1; } +void show_codepoint(QCValue* val) { + char buf[UTF_MAX+1] = {0}; + utf8encode(buf, val->data[0]); + printf("0x%08x (%s)\n", (int)(val->data[0]), buf); +} + QCValue* GenCodepoint(void) { - return GenLongR(0, 0x10FFFF); + long cp = 0; + do { cp = qcrandr(32,0x10FFFF); } + while ( + (cp >= 0xD000 && cp <= 0xDFFF) || + (cp >= 0xFDD0 && cp <= 0xFDEF) || + ((cp & 0xFFFE) == 0xFFFE) + ); + return MkLong(cp, show_codepoint); } TEST_SUITE(BufferTests) { TEST(buf should adhere to specific properties) { QCHECK("getc should return the same printable ascii value inserted with putc", getc_returns_putc, 1, GenAsciiChar); -// QCHECK("getc should return the same printable unicode value inserted with putc", -// getc_returns_putc, 1, GenCodepoint); QCHECK("gets should return the same printable ascii string inserted with puts", gets_returns_puts, 1, GenAsciiString); + QCHECK("getc should return the same printable unicode value inserted with putc", + getc_returns_putc, 1, GenCodepoint); QCHECK("edit operations should be reversible", edit_operations_are_reversible, 1, GenAsciiString); } diff --git a/tests/test_tide.c b/tests/test_tide.c deleted file mode 100644 index 513d301..0000000 --- a/tests/test_tide.c +++ /dev/null @@ -1,58 +0,0 @@ -#define TEST -#include "src/tide.c" - -#define INCLUDE_DEFS -#include "qcheck.h" - -/************************************************/ - -void tide_init(void) { - if (!ShellCmd[0]) ShellCmd[0] = getenv("SHELL"); - if (!ShellCmd[0]) ShellCmd[0] = "/bin/sh"; - win_init(Bindings); - view_init(&Regions[TAGS], NULL); - view_init(&Regions[EDIT], NULL); - view_putstr(win_view(TAGS), TagString); - view_resize(win_view(TAGS), 640, 1); - buf_logclear(win_buf(TAGS)); - win_prop_set("TIDE", "", "tide"); - xupdate(NULL); -} - -/************************************************/ - -int divisible_by_two(int nvals, QCValue** vals) { - (void)nvals; - return ((vals[0]->data[0] % 2) == 0); -} - -int resizing_should_not_crash(int nvals, QCValue** vals) { -// int pid = fork(); -// /* test the resize event */ -// if (pid == 0) { -// XEvent e = {0}; -// e.xconfigure.width = vals[0]->data[0]; -// e.xconfigure.height = vals[1]->data[0]; -// tide_init(); -// (X.eventfns[ConfigureNotify])(&X, &e); -// xupdate(NULL); -// } -// switch (fork()) { -// case 0: -// tide_init(); -// break; -// default: -// /* wait for pid to exit */ -// break; -// } - return ((void)vals, (void)nvals, 1); -} - -int main(int argc, char** argv) { - (void)usage; - - qcinit(argc >= 2 ? strtol(argv[1], 0, 0) : 0); - qcheck("all numbers are divisible by 2", divisible_by_two, 1, GenLong); - - return 0; -}