From: Michael D. Lowis Date: Fri, 1 Mar 2019 21:28:03 +0000 (-0500) Subject: added new property X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=d2aa108479f0330cb9c3822405f7c4aab4823ed5;p=projs%2Ftide.git added new property --- diff --git a/config.mk b/config.mk index 0611cdd..f8994f2 100644 --- a/config.mk +++ b/config.mk @@ -33,8 +33,8 @@ ARFLAGS = rcs #LDFLAGS += -g -fsanitize=address,undefined # GCC - Enable Sanitizers -#CFLAGS += -g -fsanitize=address,undefined -#LDFLAGS += -g -fsanitize=address,undefined -lasan +CFLAGS += -g -fsanitize=address,undefined +LDFLAGS += -g -fsanitize=address,undefined -lasan # GCC/Clang Profiling #CFLAGS += -pg diff --git a/src/lib/buf.c b/src/lib/buf.c index 51c7307..712386d 100644 --- a/src/lib/buf.c +++ b/src/lib/buf.c @@ -81,6 +81,8 @@ void buf_init(Buf* buf) { if (buf->bufstart) { free(buf->bufstart); buf->bufstart = NULL; + free(buf->path); + buf->path = NULL; buf_logclear(buf); } diff --git a/tests/lib/buf.c b/tests/lib/buf.c index 6be91e5..e05c87e 100644 --- a/tests/lib/buf.c +++ b/tests/lib/buf.c @@ -5,6 +5,10 @@ #include #include "config.h" +#pragma GCC diagnostic ignored "-Wunused-function" +#pragma GCC diagnostic ignored "-Wunused-parameter" + +static char* Output = NULL; static Buf TestBuf = {0}; static void set_buffer_text(char* str) { @@ -12,28 +16,58 @@ static void set_buffer_text(char* str) { buf_puts(&TestBuf, str); } +static int buffer_equals(char* str) { + free(Output), Output = NULL; + buf_selall(&TestBuf); + Output = buf_gets(&TestBuf); + return (!strcmp(str, Output)); +} + + #define QCHECK(desc, prop, ...) \ CHECK(qcheck(desc, prop, __VA_ARGS__)) +#define QASSERT(cond) \ + if (!(cond)) return 0 + +void setup_buffer(void) { + free(Output), Output = NULL; + buf_init(&TestBuf); +} + int getc_returns_putc(int nvals, QCValue** vals) { - (void)nvals; - Buf buf = {0}; - buf_init(&buf); - buf_putc(&buf, vals[0]->data[0]); - buf.selection.end = buf.selection.beg = 0; - return (vals[0]->data[0] == buf_getc(&buf)); + setup_buffer(); + buf_putc(&TestBuf, vals[0]->data[0]); + TestBuf.selection.end = TestBuf.selection.beg = 0; + return (vals[0]->data[0] == buf_getc(&TestBuf)); } int gets_returns_puts(int nvals, QCValue** vals) { - (void)nvals; - Buf buf = {0}; - buf_init(&buf); + setup_buffer(); + char* input = (char*)(vals[0]->data); + buf_puts(&TestBuf, input); + QASSERT(buffer_equals(input)); + return 1; +} + +int edit_operations_are_reversible(int nvals, QCValue** vals) { + setup_buffer(); char* input = (char*)(vals[0]->data); - buf_puts(&buf, input); - buf.selection.beg = 0; - buf.selection.end = buf_end(&buf); - char* output = buf_gets(&buf); - return (!strcmp(input,output)); + buf_logstart(&TestBuf); + buf_puts(&TestBuf, input); + buf_logstop(&TestBuf); + QASSERT(buffer_equals(input)); +// buf_putc(&TestBuf, 'A'); +// TestBuf.selection.end = buf_byrune(&TestBuf, TestBuf.selection.end, LEFT); +// /* selection equals 'A' */ +// buf_del(&TestBuf); // delete 'A' +// buf_undo(&TestBuf); +// QASSERT(buffer_equals(input)); + buf_undo(&TestBuf); + QASSERT(buffer_equals("")); + buf_redo(&TestBuf); + QASSERT(buffer_equals(input)); + return 1; } TEST_SUITE(BufferTests) { @@ -42,6 +76,8 @@ TEST_SUITE(BufferTests) { getc_returns_putc, 1, GenAsciiChar); QCHECK("gets should return the same printable ascii string inserted with puts", gets_returns_puts, 1, GenAsciiString); + QCHECK("edit operations should be reversible", + edit_operations_are_reversible, 1, GenAsciiString); } /* Initializing @@ -123,6 +159,7 @@ TEST_SUITE(BufferTests) { TEST(buf_reload should reload the file from disk) { buf_init(&TestBuf); buf_load(&TestBuf, "testdocs/waf"); + free(TestBuf.path); TestBuf.path = "testdocs/lorem.txt"; buf_reload(&TestBuf); CHECK(TestBuf.status != MODIFIED);