From 40508a457cd43fc4c0a43d47ce49f91c88460f2a Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 19 May 2019 18:06:58 -0400 Subject: [PATCH] Changed testingSet to use testingprivArray. --- common/uipriv.h | 1 + test/lib/testing.c | 29 ++++++++++------------------- test/lib/testingpriv.h | 1 + 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/common/uipriv.h b/common/uipriv.h index ceee8d6a..bbea1a6d 100644 --- a/common/uipriv.h +++ b/common/uipriv.h @@ -23,6 +23,7 @@ struct uiprivArray { size_t nGrow; const char *what; }; +#define uiprivArrayStaticInit(T, grow, whatstr) { NULL, 0, 0, sizeof (T), grow, whatstr } #define uiprivArrayInit(arr, T, grow, whatstr) \ memset(&(arr), 0, sizeof (uiprivArray)); \ arr.elemsize = sizeof (T); \ diff --git a/test/lib/testing.c b/test/lib/testing.c index 784131db..c63b0b87 100644 --- a/test/lib/testing.c +++ b/test/lib/testing.c @@ -161,37 +161,28 @@ static void initTest(testingT *t, const char *name, void (*f)(testingT *), const t->line = line; } -#define nGrow 32 - struct testingSet { - testingT *tests; - size_t len; - size_t cap; + testingprivArray tests; }; -static testingSet mainTests = { NULL, 0, 0 }; +static testingSet mainTests = { testingprivArrayStaticInit(testingT, 32, "testingT[]") }; void testingprivSetRegisterTest(testingSet **pset, const char *name, void (*f)(testingT *), const char *file, long line) { testingSet *set; + testingT *t; set = &mainTests; if (pset != NULL) { set = *pset; if (set == NULL) { set = testingprivNew(testingSet); + testingprivArrayInit(set->tests, testingT, 32, "testingT[]"); *pset = set; } } - if (set->len == set->cap) { - size_t prevcap; - - prevcap = set->cap; - set->cap += nGrow; - set->tests = testingprivResizeArray(set->tests, testingT, prevcap, set->cap); - } - initTest(set->tests + set->len, name, f, file, line); - set->len++; + t = (testingT *) testingprivArrayAppend(&(set->tests), 1); + initTest(t, name, f, file, line); } static int testcmp(const void *a, const void *b) @@ -234,9 +225,9 @@ static void testingprivSetRun(testingSet *set, const testingOptions *options, in char timerstr[timerDurationStringLen]; int printStatus; - qsort(set->tests, set->len, sizeof (testingT), testcmp); - t = set->tests; - for (i = 0; i < set->len; i++) { + testingprivArrayQsort(&(set->tests), testcmp); + t = (testingT *) (set->tests.buf); + for (i = 0; i < set->tests.len; i++) { if (options->Verbose) outbufPrintf(NULL, indent, "=== RUN %s", t->name); t->indent = indent + 1; @@ -273,7 +264,7 @@ void testingSetRun(testingSet *set, const struct testingOptions *options, int *a set = &mainTests; if (options == NULL) options = &defaultOptions; - if (set->len == 0) + if (set->tests.len == 0) return; testingprivSetRun(set, options, 0, anyFailed); *anyRun = 1; diff --git a/test/lib/testingpriv.h b/test/lib/testingpriv.h index 760620ae..dd9c5132 100644 --- a/test/lib/testingpriv.h +++ b/test/lib/testingpriv.h @@ -18,6 +18,7 @@ struct testingprivArray { size_t nGrow; const char *what; }; +#define testingprivArrayStaticInit(T, grow, whatstr) { NULL, 0, 0, sizeof (T), grow, whatstr } #define testingprivArrayInit(arr, T, grow, whatstr) \ memset(&(arr), 0, sizeof (testingprivArray)); \ arr.elemsize = sizeof (T); \