Return-Path: X-Original-To: apmail-corinthia-commits-archive@minotaur.apache.org Delivered-To: apmail-corinthia-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3C5329F8A for ; Fri, 19 Dec 2014 15:09:45 +0000 (UTC) Received: (qmail 8067 invoked by uid 500); 19 Dec 2014 15:09:45 -0000 Delivered-To: apmail-corinthia-commits-archive@corinthia.apache.org Received: (qmail 8050 invoked by uid 500); 19 Dec 2014 15:09:44 -0000 Mailing-List: contact commits-help@corinthia.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@corinthia.incubator.apache.org Delivered-To: mailing list commits@corinthia.incubator.apache.org Received: (qmail 8041 invoked by uid 99); 19 Dec 2014 15:09:44 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 19 Dec 2014 15:09:44 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Fri, 19 Dec 2014 15:09:42 +0000 Received: (qmail 7825 invoked by uid 99); 19 Dec 2014 15:09:22 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 19 Dec 2014 15:09:22 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 289FBA2F43C; Fri, 19 Dec 2014 15:09:22 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: pmkelly@apache.org To: commits@corinthia.incubator.apache.org Date: Fri, 19 Dec 2014 15:09:22 -0000 Message-Id: <0cca7d12e801422982c11192fed14b4d@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [01/12] incubator-corinthia git commit: Reference data tests by name X-Virus-Checked: Checked by ClamAV on apache.org Repository: incubator-corinthia Updated Branches: refs/heads/master 76d9bc38e -> d72983d4d Reference data tests by name In dfutil, determine the function to execute for a test by looking through the TestGroup/TestCase structures using the newly-added utlookup() function, instead of having direct references to the test functions from within dfutil itself. This allows us to make the test functions internal to the library itself, and provides a more scalable means of adding new tests (we don't need to modify dfutil/dftest each time). All test functions invoked from dfutil are now static within the files they're defined in; references to them can only be obtained via the TestGroup structures. The names used in the *.test data files have not been changed; they still use a rather haphazard naming scheme, instead of the module.testname system we use now. For example, some of the Word tests reference Word_testCreate, which is now accessed as ooxml.word.create (that is, the "create" function in the "ooxml.word" group). Until we change the *.test data files, we use a substitution table which knows the old name of each function, and uses it to look up the new name. Project: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/commit/7b11cb66 Tree: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/tree/7b11cb66 Diff: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/diff/7b11cb66 Branch: refs/heads/master Commit: 7b11cb66f55c00670e84141258a059b6e2880e4c Parents: 76d9bc3 Author: Peter Kelly Authored: Fri Dec 19 21:28:41 2014 +0700 Committer: Peter Kelly Committed: Fri Dec 19 21:29:52 2014 +0700 ---------------------------------------------------------------------- DocFormats/core/tests/common/BDTTests.c | 12 ++- DocFormats/core/tests/css/CSSTests.c | 11 +-- DocFormats/core/tests/html/HTMLTests.c | 11 +-- DocFormats/filters/latex/tests/LaTeXTests.c | 8 +- DocFormats/filters/ooxml/tests/word/WordTests.c | 23 +++-- DocFormats/unittest/DFUnitTest.c | 19 ++++ DocFormats/unittest/DFUnitTest.h | 1 + consumers/dfutil/src/TestFunctions.c | 91 +++++++++++--------- 8 files changed, 99 insertions(+), 77 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/7b11cb66/DocFormats/core/tests/common/BDTTests.c ---------------------------------------------------------------------- diff --git a/DocFormats/core/tests/common/BDTTests.c b/DocFormats/core/tests/common/BDTTests.c index 83204d6..75f1107 100644 --- a/DocFormats/core/tests/common/BDTTests.c +++ b/DocFormats/core/tests/common/BDTTests.c @@ -369,7 +369,7 @@ int BDT_Test(int argc, const char **argv) return 0; } -void test_move(void) +static void test_move(void) { if (utgetargc() < 3) { DFBufferFormat(utgetoutput(),"move: insufficient arguments"); @@ -386,7 +386,7 @@ void test_move(void) DFBufferRelease(output); } -void test_removeChildren(void) +static void test_removeChildren(void) { int *indices = (int *)malloc(utgetargc()*sizeof(int)); @@ -402,3 +402,11 @@ void test_removeChildren(void) free(indices); } + +TestGroup BDTTests = { + "core.bdt", { + { "move", DataTest, test_move }, + { "removeChildren", DataTest, test_removeChildren }, + { NULL, PlainTest, NULL } + } +}; http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/7b11cb66/DocFormats/core/tests/css/CSSTests.c ---------------------------------------------------------------------- diff --git a/DocFormats/core/tests/css/CSSTests.c b/DocFormats/core/tests/css/CSSTests.c index c4e1d2b..ea2bbc1 100644 --- a/DocFormats/core/tests/css/CSSTests.c +++ b/DocFormats/core/tests/css/CSSTests.c @@ -20,7 +20,7 @@ #include #include -void test_CSS_setHeadingNumbering(void) +static void test_setHeadingNumbering(void) { const char *inputCSS = DFHashTableLookup(utgetdata(),"input.css"); if (inputCSS == NULL) { @@ -42,7 +42,7 @@ void test_CSS_setHeadingNumbering(void) CSSSheetRelease(styleSheet); } -void test_CSS_parse(void) +static void test_parse(void) { const char *inputCSS = DFHashTableLookup(utgetdata(),"input.css"); if (inputCSS == NULL) { @@ -62,13 +62,10 @@ void test_CSS_parse(void) CSSSheetRelease(styleSheet); } -static void test_sample(void) -{ -} - TestGroup CSSTests = { "core.css", { - { "sample", PlainTest, test_sample }, + { "setHeadingNumbering", DataTest, test_setHeadingNumbering }, + { "parse", DataTest, test_parse }, { NULL, PlainTest, NULL } } }; http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/7b11cb66/DocFormats/core/tests/html/HTMLTests.c ---------------------------------------------------------------------- diff --git a/DocFormats/core/tests/html/HTMLTests.c b/DocFormats/core/tests/html/HTMLTests.c index 5097cc0..540f2af 100644 --- a/DocFormats/core/tests/html/HTMLTests.c +++ b/DocFormats/core/tests/html/HTMLTests.c @@ -21,7 +21,7 @@ #include "DFChanges.h" #include -void test_HTML_testNormalize(void) +static void test_normalize(void) { const char *inputHtml = DFHashTableLookup(utgetdata(),"input.html"); if (inputHtml == NULL) { @@ -43,7 +43,7 @@ void test_HTML_testNormalize(void) DFDocumentRelease(doc); } -void test_HTML_showChanges(void) +static void test_showChanges(void) { const char *input1 = DFHashTableLookup(utgetdata(),"input1.html"); if (input1 == NULL) { @@ -82,13 +82,10 @@ void test_HTML_showChanges(void) DFDocumentRelease(doc2); } -static void test_sample(void) -{ -} - TestGroup HTMLTests = { "core.html", { - { "sample", PlainTest, test_sample }, + { "normalize", DataTest, test_normalize }, + { "showChanges", DataTest, test_showChanges }, { NULL, PlainTest, NULL } } }; http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/7b11cb66/DocFormats/filters/latex/tests/LaTeXTests.c ---------------------------------------------------------------------- diff --git a/DocFormats/filters/latex/tests/LaTeXTests.c b/DocFormats/filters/latex/tests/LaTeXTests.c index 2373dae..2336651 100644 --- a/DocFormats/filters/latex/tests/LaTeXTests.c +++ b/DocFormats/filters/latex/tests/LaTeXTests.c @@ -18,7 +18,7 @@ #include "DFHTMLNormalization.h" #include -void test_LaTeX_testCreate(void) +static void test_create(void) { DFError *error = NULL; DFStorage *htmlStorage = DFStorageNewMemory(DFFileFormatHTML); @@ -37,13 +37,9 @@ void test_LaTeX_testCreate(void) DFDocumentRelease(htmlDoc); } -static void test_sample(void) -{ -} - TestGroup LaTeXTests = { "latex", { - { "sample", PlainTest, test_sample }, + { "create", DataTest, test_create }, { NULL, PlainTest, NULL } } }; http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/7b11cb66/DocFormats/filters/ooxml/tests/word/WordTests.c ---------------------------------------------------------------------- diff --git a/DocFormats/filters/ooxml/tests/word/WordTests.c b/DocFormats/filters/ooxml/tests/word/WordTests.c index 6686ae5..fc6df68 100644 --- a/DocFormats/filters/ooxml/tests/word/WordTests.c +++ b/DocFormats/filters/ooxml/tests/word/WordTests.c @@ -23,7 +23,7 @@ #include #include -void test_Word_testCollapseBookmarks(void) +static void test_collapseBookmarks(void) { DFError *error = NULL; DFStorage *storage = TestCaseOpenPackage(&error); @@ -51,8 +51,7 @@ void test_Word_testCollapseBookmarks(void) DFStorageRelease(storage); } - -void test_Word_testExpandBookmarks(void) +static void test_expandBookmarks(void) { DFError *error = NULL; DFStorage *storage = TestCaseOpenPackage(&error); @@ -80,7 +79,7 @@ void test_Word_testExpandBookmarks(void) DFStorageRelease(storage); } -void test_Word_testGet(void) +static void test_get(void) { DFError *error = NULL; DFStorage *abstractStorage = NULL; @@ -147,7 +146,7 @@ static DFHashTable *getFlags(void) return set; } -void test_Word_testCreate(void) +static void test_create(void) { DFError *error = NULL; DFDocument *htmlDoc = NULL; @@ -187,7 +186,7 @@ end: free(wordPlain); } -void test_Word_testUpdate(void) +static void test_put(void) { DFError *error = NULL; DFDocument *htmlDoc = NULL; @@ -237,13 +236,13 @@ end: free(wordPlain); } -static void test_sample(void) -{ -} - TestGroup WordTests = { - "word", { - { "sample", PlainTest, test_sample }, + "ooxml.word", { + { "collapseBookmarks", DataTest, test_collapseBookmarks }, + { "expandBookmarks", DataTest, test_expandBookmarks }, + { "get", DataTest, test_get }, + { "create", DataTest, test_create }, + { "put", DataTest, test_put }, { NULL, PlainTest, NULL } } }; http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/7b11cb66/DocFormats/unittest/DFUnitTest.c ---------------------------------------------------------------------- diff --git a/DocFormats/unittest/DFUnitTest.c b/DocFormats/unittest/DFUnitTest.c index b3442b7..d222ff9 100644 --- a/DocFormats/unittest/DFUnitTest.c +++ b/DocFormats/unittest/DFUnitTest.c @@ -76,6 +76,25 @@ void utfail(const char *reason) curtest.reason = strdup(reason); } +TestCase *utlookup(TestGroup **groups, const char *name) +{ + for (int gi = 0; groups[gi]; gi++) { + TestGroup *group = groups[gi]; + if (!strncmp(name,group->name,strlen(group->name)) && + (name[strlen(group->name)] == '.')) { + const char *testName = &name[strlen(group->name)+1]; + for (int ti = 0; group->tests[ti].name; ti++) { + TestCase *test = &group->tests[ti]; + if (!strcmp(test->name,testName)) { + return test; + } + } + return NULL; + } + } + return NULL; +} + static const char *testPath = NULL; static struct DFHashTable *testData = NULL; static int testArgc = 0; http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/7b11cb66/DocFormats/unittest/DFUnitTest.h ---------------------------------------------------------------------- diff --git a/DocFormats/unittest/DFUnitTest.h b/DocFormats/unittest/DFUnitTest.h index 24e9c3b..08b1729 100644 --- a/DocFormats/unittest/DFUnitTest.h +++ b/DocFormats/unittest/DFUnitTest.h @@ -72,6 +72,7 @@ struct TestGroup { struct DFHashTable; struct DFBuffer; +TestCase *utlookup(TestGroup **groups, const char *name); void utsetup(const char *path, struct DFHashTable *data, int argc, const char **argv, struct DFBuffer *output); void utteardown(void); void utrun(TestGroup **groups, int plain, int data, const char **filenames); http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/7b11cb66/consumers/dfutil/src/TestFunctions.c ---------------------------------------------------------------------- diff --git a/consumers/dfutil/src/TestFunctions.c b/consumers/dfutil/src/TestFunctions.c index 5a2d601..e264126 100644 --- a/consumers/dfutil/src/TestFunctions.c +++ b/consumers/dfutil/src/TestFunctions.c @@ -34,59 +34,64 @@ #include #include -// BDTTests.c -void test_move(void); -void test_removeChildren(void); +extern TestGroup APITests; +extern TestGroup CSSTests; +extern TestGroup HTMLTests; +extern TestGroup LibTests; +extern TestGroup XMLTests; +extern TestGroup LaTeXTests; +extern TestGroup ODFTests; +extern TestGroup WordTests; +extern TestGroup PlatformTests; +extern TestGroup BDTTests; -// CSSTests.c -void test_CSS_setHeadingNumbering(void); -void test_CSS_parse(void); - -// WordTests.c -void test_Word_testCollapseBookmarks(void); -void test_Word_testExpandBookmarks(void); -void test_Word_testGet(void); -void test_Word_testCreate(void); -void test_Word_testUpdate(void); - -// LaTeXTests.c -void test_LaTeX_testCreate(void); - -// HTMLTests.c -void test_HTML_testNormalize(void); -void test_HTML_showChanges(void); - - - -typedef void (*TestFunction)(void); +TestGroup *allGroups[] = { + &APITests, + &BDTTests, + &CSSTests, + &HTMLTests, + &LibTests, + &XMLTests, + &LaTeXTests, + &ODFTests, + &WordTests, + &PlatformTests, + NULL +}; static struct { - const char *name; - TestFunction fun; -} testFunctions[] = { - { "CSS_setHeadingNumbering", test_CSS_setHeadingNumbering }, - { "Word_testCollapseBookmarks", test_Word_testCollapseBookmarks }, - { "Word_testExpandBookmarks", test_Word_testExpandBookmarks }, - { "Word_testGet", test_Word_testGet }, - { "Word_testCreate", test_Word_testCreate }, - { "Word_testUpdate", test_Word_testUpdate }, - { "LaTeX_testCreate", test_LaTeX_testCreate }, - { "HTML_testNormalize", test_HTML_testNormalize }, - { "HTML_showChanges", test_HTML_showChanges }, - { "CSS_test", test_CSS_parse }, - { "move", test_move }, - { "remove", test_removeChildren }, + const char *oldName; + const char *newName; +} substitutions[] = { + { "CSS_setHeadingNumbering", "core.css.setHeadingNumbering" }, + { "Word_testCollapseBookmarks", "ooxml.word.collapseBookmarks" }, + { "Word_testExpandBookmarks", "ooxml.word.expandBookmarks" }, + { "Word_testGet", "ooxml.word.get" }, + { "Word_testCreate", "ooxml.word.create" }, + { "Word_testUpdate", "ooxml.word.put" }, + { "LaTeX_testCreate", "latex.create" }, + { "HTML_testNormalize", "core.html.normalize" }, + { "HTML_showChanges", "core.html.showChanges" }, + { "CSS_test", "core.css.parse" }, + { "move", "core.bdt.move" }, + { "remove", "core.bdt.removeChildren" }, { NULL, NULL }, }; void runTest(const char *name) { - for (int i = 0; testFunctions[i].name != NULL; i++) { - if (!strcmp(testFunctions[i].name,name)) { - testFunctions[i].fun(); - return; + const char *actualName = name; + for (int i = 0; substitutions[i].oldName != NULL; i++) { + if (!strcmp(name,substitutions[i].oldName)) { + actualName = substitutions[i].newName; } } + TestCase *tc = utlookup(allGroups,actualName); + if (tc != NULL) { + tc->fun(); + return; + } + printf("runTest %s\n",name); for (int i = 0; i < utgetargc(); i++) { printf(" utgetargv()[%d] = %s\n",i,utgetargv()[i]);