X-Git-Url: http://git.scottworley.com/tl-append/blobdiff_plain/d212cd99e7ef72e0add4ef772e328835a972ae6b..refs/heads/master:/tl-append-test.c?ds=sidebyside diff --git a/tl-append-test.c b/tl-append-test.c index e712c6f..b3fa7c4 100644 --- a/tl-append-test.c +++ b/tl-append-test.c @@ -1,3 +1,20 @@ +/* + * tl-append: time-logger appending shell + * Copyright (C) 2023 Scott Worley + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #define _POSIX_C_SOURCE 2 #define _XOPEN_SOURCE #define _GNU_SOURCE @@ -28,9 +45,12 @@ const ex_t CONSUMED = {((time_t)-2), ((time_t)-2), NULL}; static int is_end(ex_t exp) { return exp.a == END.a && exp.b == END.b && exp.message == END.message; } +static void consume(ex_t *exp) { + exp->a = CONSUMED.a; + exp->b = CONSUMED.b; +} static int is_consumed(ex_t exp) { - return exp.a == CONSUMED.a && exp.b == CONSUMED.b && - exp.message == CONSUMED.message; + return exp.a == CONSUMED.a && exp.b == CONSUMED.b; } static ex_t expectation(time_t a, time_t b, const char *message) { ex_t exp; @@ -126,7 +146,7 @@ static void verify_log_contents(const ex_t exps[]) { static void consume_expectation(ex_t exps[], const char *line) { for (size_t i = 0; !is_end(exps[i]); i++) { if (line_problem(&exps[i], line) == NULL) { - exps[i] = CONSUMED; + consume(&exps[i]); return; } } @@ -171,7 +191,7 @@ static void test_encode_time() { if (tt == (time_t)-1) die_err("Can't pack time?"); - const char *encoded = encode_time(tt); + char *encoded = encode_time(tt); /* Loose check to allow for daylight savings time changes between the current * time and the target time. :( */ assert(encoded[0] == '2'); @@ -194,6 +214,7 @@ static void test_encode_time() { assert(encoded[17] == '1'); assert(encoded[18] == '6'); assert(encoded[19] == '\0'); + free(encoded); } static FILE *take_lock(FILE *f, char *lock_type) { @@ -304,6 +325,9 @@ static void write_concurrently() { } results[PARALLELISM] = END; verify_log_contents_unordered(results); + for (int i = 0; i < PARALLELISM; i++) { + free((void *)results[i].message); + } } int main() {