From 4179ff86c2bb11009067c9c7168e696b2f84ce94 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sat, 3 Mar 2018 17:01:40 -0500 Subject: [PATCH] Added more test cases. Also more TODOs in testing_testing.c. --- common/opentype_test.c | 77 ++++++++++++++++++++++++++++++++++++++-- common/testing_testing.c | 2 ++ 2 files changed, 76 insertions(+), 3 deletions(-) diff --git a/common/opentype_test.c b/common/opentype_test.c index c374154e..0c96108c 100644 --- a/common/opentype_test.c +++ b/common/opentype_test.c @@ -27,15 +27,86 @@ static void freeOpenType(void *otf) testingTest(OpenTypeFeaturesAddGet) { uiOpenTypeFeatures *otf; + int got; uint32_t value; otf = uiNewOpenTypeFeatures(); testingTDefer(t, freeOpenType, otf); uiOpenTypeFeaturesAdd(otf, 'a', 'b', 'c', 'd', 12345); - if (!uiOpenTypeFeaturesGet(otf, 'a', 'b', 'c', 'd', &value)) - testingTFatalf(t, "uiOpenTypeFeaturesGet() failed to get feature we added"); + got = uiOpenTypeFeaturesGet(otf, 'a', 'b', 'c', 'd', &value); + + if (!got) + testingTErrorf(t, "uiOpenTypeFeaturesGet() failed to get feature we added"); + else if (value != 12345) + testingTErrorf(t, "feature abcd: got %" PRIu32 ", want 12345", value); +} + +testingTest(OpenTypeFeaturesRemove) +{ + uiOpenTypeFeatures *otf; + uint32_t value; + + otf = uiNewOpenTypeFeatures(); + testingTDefer(t, freeOpenType, otf); + uiOpenTypeFeaturesAdd(otf, 'a', 'b', 'c', 'd', 12345); + uiOpenTypeFeaturesRemove(otf, 'a', 'b', 'c', 'd'); + + if (uiOpenTypeFeaturesGet(otf, 'a', 'b', 'c', 'd', &value)) + testingTErrorf(t, "uiOpenTypeFeaturesGet() succeeded in getting deleted feature; value %" PRIu32, value); +} + +testingTest(OpenTypeFeaturesCloneAdd) +{ + uiOpenTypeFeatures *otf, *otf2; + uint32_t value; + + otf = uiNewOpenTypeFeatures(); + testingTDefer(t, freeOpenType, otf); + uiOpenTypeFeaturesAdd(otf, 'a', 'b', 'c', 'd', 12345); + otf2 = uiOpenTypeFeaturesClone(otf); + testingTDefer(t, freeOpenType, otf2); + uiOpenTypeFeaturesAdd(otf2, 'q', 'w', 'e', 'r', 56789); + + if (uiOpenTypeFeaturesGet(otf, 'q', 'w', 'e', 'r', &value)) + testingTErrorf(t, "uiOpenTypeFeaturesGet() on original succeeded in getting feature added to clone; value %" PRIu32, value); +} + +testingTest(OpenTypeFeaturesCloneModify) +{ + uiOpenTypeFeatures *otf, *otf2; + uint32_t value; + + otf = uiNewOpenTypeFeatures(); + testingTDefer(t, freeOpenType, otf); + uiOpenTypeFeaturesAdd(otf, 'a', 'b', 'c', 'd', 12345); + otf2 = uiOpenTypeFeaturesClone(otf); + testingTDefer(t, freeOpenType, otf2); + uiOpenTypeFeaturesAdd(otf2, 'a', 'b', 'c', 'd', 56789); + + uiOpenTypeFeaturesGet(otf, 'a', 'b', 'c', 'd', &value); if (value != 12345) - testingTFatalf(t, "feature abcd: got %" PRIu32 ", want 12345", value); + testingTErrorf(t, "uiOpenTypeFeaturesGet() on original: got %" PRIu32 ", want 12345", value); + uiOpenTypeFeaturesGet(otf2, 'a', 'b', 'c', 'd', &value); + if (value != 56789) + testingTErrorf(t, "uiOpenTypeFeaturesGet() on clone: got %" PRIu32 ", want 56789", value); +} + +testingTest(OpenTypeFeaturesCloneRemove) +{ + uiOpenTypeFeatures *otf, *otf2; + uint32_t value; + + otf = uiNewOpenTypeFeatures(); + testingTDefer(t, freeOpenType, otf); + uiOpenTypeFeaturesAdd(otf, 'a', 'b', 'c', 'd', 12345); + otf2 = uiOpenTypeFeaturesClone(otf); + testingTDefer(t, freeOpenType, otf2); + uiOpenTypeFeaturesRemove(otf2, 'a', 'b', 'c', 'd'); + + if (uiOpenTypeFeaturesGet(otf2, 'a', 'b', 'c', 'd', &value)) + testingTErrorf(t, "uiOpenTypeFeaturesGet() on clone succeeded in getting feature removed from clone; value %" PRIu32, value); + if (!uiOpenTypeFeaturesGet(otf, 'a', 'b', 'c', 'd', &value)) + testingTErrorf(t, "uiOpenTypeFeaturesGet() on original failed to get feature removed from clone"); } int main(void) diff --git a/common/testing_testing.c b/common/testing_testing.c index 6139ef75..eb334648 100644 --- a/common/testing_testing.c +++ b/common/testing_testing.c @@ -36,6 +36,7 @@ void testingprivRegisterTest(const char *name, void (*f)(testingT *)) t->skipped = 0; t->defers = NULL; t->defersRun = 0; + // TODO add in the order called t->next = tests; tests = t; } @@ -137,6 +138,7 @@ void testingTDefer(testingT *t, void (*f)(void *data), void *data) d = testingprivNew(struct defer); d->f = f; d->data = data; + // add to the head of the list so defers are run in reverse order of how they were added d->next = t->defers; t->defers = d; }