]> git.mdlowis.com Git - projs/tide.git/commitdiff
moved some macors around
authorMichael D. Lowis <mike@mdlowis.com>
Mon, 4 Mar 2019 04:20:11 +0000 (23:20 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Mon, 4 Mar 2019 04:20:11 +0000 (23:20 -0500)
Makefile
inc/atf.h
inc/qcheck.h
tests/lib/buf.c
tests/test_tide.c [deleted file]

index 7d3c61c64046f97fd967f96a08b189eadc82ff02..5be212d533c42303bae09f78a90a688ac874a2b4 100644 (file)
--- 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
index 467b802bd00f738e850ae43bb5e6b9aea2ccb1c6..ca7b30ac169d7ad05b3a9f3a20b72921c4a17396 100644 (file)
--- 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
index 605e3e8424df05b4fbfc53872d29dbf3a4da8b4a..ff0322b22b9ef3e03a74255e50cd75de2b9c49eb 100644 (file)
@@ -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 <assert.h>
+#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 <stdlib.h>
 #include <stdio.h>
 
-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);
index d529fa94cf4a99caf53f0ab386b3abfc8617018b..55b120b9be95821fc9c527c4fc1685b7f947efe8 100644 (file)
@@ -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 (file)
index 513d301..0000000
+++ /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;
-}