OSDN Git Service

add functions for fixture setUp/tearDown
authortsutsumi <>
Thu, 19 Aug 2010 10:09:28 +0000 (10:09 +0000)
committertsutsumi <>
Thu, 19 Aug 2010 10:09:28 +0000 (10:09 +0000)
src/ccunit/CCUnitMakeSuite.h
src/ccunit/CCUnitPrintSuite.c
src/ccunit/CCUnitReadSuite.c
src/ccunit/CCUnitTestFixture.h
src/ccunit/CCUnitTestSuite.c

index 37b1c1f..2930e4f 100644 (file)
@@ -1,5 +1,5 @@
 /* -*- C -*- */
-/* Copyright (C) 2003 TSUTSUMI Kikuo.
+/* Copyright (C) 2003, 2010 TSUTSUMI Kikuo.
    This file is part of the CCUnit Library.
 
    The CCUnit Library is free software; you can redistribute it and/or
@@ -173,6 +173,8 @@ typedef struct _CCUnitTestFixtureDef
   _CCUnitTestDef testdef;                      /**< super class */
   _CCUnitFuncDef* ctor;                                /**< constructor */
   _CCUnitFuncDef* dtor;                                /**< destructor */
+  _CCUnitFuncDef* setup_setUp;                 /**< fixture setup function */
+  _CCUnitFuncDef* setup_tearDown;              /**< fixture tearDown function */
   _CCUnitFuncDef* setUp;                       /**< test setup function */
   _CCUnitFuncDef* tearDown;                    /**< test tearDown function */
   CCUnitList testCases;                                /**< test case list */
index b6335e3..af2056a 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2003 TSUTSUMI Kikuo.
+/* Copyright (C) 2003, 2010 TSUTSUMI Kikuo.
    This file is part of the CCUnit Library.
 
    The CCUnit Library is free software; you can redistribute it and/or
@@ -82,6 +82,10 @@ static void printPrototypes (FILE* ofp, _CCUnitTestSuiteDef* suitedef)
          ccunit_log ("fixturdef: %s", fdef->testdef.name);
          if (fdef->testdef.name)
            fprintf (ofp, "/* test fixture: %s */\n", fdef->testdef.name);
+         if (fdef->setup_setUp)
+           printPrototype (ofp, "setup_setUp", fdef->setup_setUp);
+         if (fdef->setup_tearDown)
+           printPrototype (ofp, "setup_tearDown", fdef->setup_tearDown);
          if (fdef->setUp)
            printPrototype (ofp, "setUp", fdef->setUp);
          if (fdef->tearDown)
@@ -148,6 +152,8 @@ static void printFixture  (FILE* ofp, _CCUnitTestFixtureDef* fxdef)
           fxdef->testdef.idname,
           ccunitTypeNames[fxdef->testdef.type],
           !fxdef->testdef.name ? "NULL" : fxdef->testdef.name);
+  printTestFunc (ofp, fxdef->setup_setUp);
+  printTestFunc (ofp, fxdef->setup_tearDown);
   printTestFunc (ofp, fxdef->setUp);
   printTestFunc (ofp, fxdef->tearDown);
   fprintf (ofp, "  %s_cases,\n", fxdef->testdef.idname);
index 9ea121f..dd44b4a 100644 (file)
@@ -657,6 +657,18 @@ static void readTestFixture (_CCUnitTestSuiteDef* suite, const char* cname)
          setFixtureFunc (&fixture->tearDown, f);
          safe_free (desc);
        }
+      /* setup_setUp function def */
+      else if ((f = readTestCase ("void", "setup_setUp", desc)) != NULL)
+       {
+         setFixtureFunc (&fixture->setup_setUp, f);
+         safe_free (desc);
+       }
+      /* setup_tearDown function def */
+      else if ((f = readTestCase ("void", "setup_tearDown", desc)) != NULL)
+       {
+         setFixtureFunc (&fixture->setup_tearDown, f);
+         safe_free (desc);
+       }
       /* if test case function def, then read as test case. */
       else if ((f = readTestCase ("void", "test", desc)) != NULL)
        {
index 2277b18..c8ded4a 100644 (file)
@@ -1,5 +1,5 @@
 /* -*- mode: C; -*- */
-/* Copyright (C) 2003 TSUTSUMI Kikuo.
+/* Copyright (C) 2003, 2010 TSUTSUMI Kikuo.
    This file is part of the CCUnit Library.
 
    The CCUnit Library is free software; you can redistribute it and/or
@@ -128,8 +128,10 @@ typedef struct CCUnitTestFixture
 {
   CCUnitTest test;                             /**< super class */
   const char* name;                            /**< test fixture name */
-  CCUnitTestFunc* setUp;                       /**< setUp function */
-  CCUnitTestFunc* tearDown;                    /**< tearDown function */
+  CCUnitTestFunc* setup_setUp;                 /**< setUp for a fixture */
+  CCUnitTestFunc* setup_tearDown;              /**< tearDown for a fixture */
+  CCUnitTestFunc* setUp;                       /**< setUp for each cases */
+  CCUnitTestFunc* tearDown;                    /**< tearDown for each cases */
   CCUnitList testCases;                                /**< test cases */
 } CCUnitTestFixture;
 
@@ -140,8 +142,10 @@ typedef struct CCUnitTestFixtureDfn
 {
   CCUnitTestDfn test;                          /**< super class */
   const char* name;                            /**< test fixture name */
-  CCUnitTestFunc setUp;                                /**< setUp function */
-  CCUnitTestFunc tearDown;                     /**< tearDown function */
+  CCUnitTestFunc setup_setUp;                  /**< setUp for a fixture */
+  CCUnitTestFunc setup_tearDown;               /**< tearDown for a fixture */
+  CCUnitTestFunc setUp;                                /**< setUp for each cases */
+  CCUnitTestFunc tearDown;                     /**< tearDown for each cases */
   CCUnitTestFunc* testCases;                   /**< test cases */
 } CCUnitTestFixtureDfn;
 
@@ -149,8 +153,8 @@ typedef struct CCUnitTestFixtureDfn
  * create new test fixture.
  *
  * @param name test fixture name.
- * @param setUp test fixture setUp function.
- * @param tearDown test fixture tearDown function.
+ * @param setUp test case setUp function.
+ * @param tearDown test case tearDown function.
  * @return new test fixture.
  * @ingroup WritingTestFixture
  */
@@ -159,6 +163,18 @@ extern CCUnitTestFixture* ccunit_newTestFixture (const char* name,
                                                 CCUnitTestFunc* tearDown);
 
 /**
+ * set test fixture setup functions.
+ *
+ * @param name test fixture.
+ * @param setup_setUp test fixture setUp function.
+ * @param setup_tearDown test fixture tearDown function.
+ * @ingroup WritingTestFixture
+ */
+extern inline void ccunit_setTestFixtureSetup (CCUnitTestFixture* fixture,
+                                              CCUnitTestFunc* setup_setUp,
+                                              CCUnitTestFunc* setup_tearDown);
+
+/**
  * add test case to test fixture.
  *
  * @param fixture test fixture.
index 8057086..0df351f 100755 (executable)
@@ -108,6 +108,13 @@ CCUnitTestSuite* ccunit_newTestSuiteFromDfn (const CCUnitTestSuiteDfn* sdp)
                                                          fdp->tearDown.runTest));
          if (fp)
            {
+             CCUnitTestFunc* ssu = ccunit_newTestFunc (fdp->setup_setUp.name,
+                                                       fdp->setup_setUp.desc,
+                                                       fdp->setup_setUp.runTest);
+             CCUnitTestFunc* std = ccunit_newTestFunc (fdp->setup_tearDown.name,
+                                                       fdp->setup_tearDown.desc,
+                                                       fdp->setup_tearDown.runTest);
+             ccunit_setTestFixtureSetup (fp, ssu, std);
              ccunit_addTestFixture (suite, fp);
              for (cd = (CCUnitTestCase*)fdp->testCases; cd->name; cd ++)
                {