/[escript]/trunk/tools/CppUnitTest/src/TestResult.h
ViewVC logotype

Annotation of /trunk/tools/CppUnitTest/src/TestResult.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1387 - (hide annotations)
Fri Jan 11 07:45:26 2008 UTC (12 years, 1 month ago) by trankine
Original Path: temp/tools/CppUnitTest/src/TestResult.h
File MIME type: text/plain
File size: 7872 byte(s)
Restore the trunk that existed before the windows changes were committed to the (now moved to branches) old trunk.
1 gross 700 //
2     // Permission to reproduce and create derivative works from the Software ("Software Derivative Works")
3     // is hereby granted to you under the copyright of Michael Feathers. Michael Feathers also grants you
4     // the right to distribute the Software and Software Derivative Works.
5     //
6     // Michael Feathers licenses the Software to you on an "AS IS" basis, without warranty of any kind.
7     // Michael Feathers HEREBY EXPRESSLY DISCLAIMS ALL WARRANTIES OR CONDITIONS, EITHER EXPRESS OR IMPLIED,
8     // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OR CONDITIONS OF MERCHANTABILITY, NON INFRINGEMENT
9     // AND FITNESS FOR A PARTICULAR PURPOSE.  You are solely responsible for determining the appropriateness
10     // of using the Software and assume all risks associated with the use and distribution of this Software,
11     // including but not limited to the risks of program errors, damage to or loss of data, programs or
12     // equipment, and unavailability or interruption of operations.  MICHAEL FEATHERS WILL NOT BE
13     // LIABLE FOR ANY DIRECT DAMAGES OR FOR ANY SPECIAL, INCIDENTAL, OR INDIRECT DAMAGES OR FOR ANY ECONOMIC
14     // CONSEQUENTIAL DAMAGES (INCLUDING LOST PROFITS OR SAVINGS), EVEN IF MICHAEL FEATHERS HAD BEEN ADVISED
15     // OF THE POSSIBILITY OF SUCH DAMAGE.  Michael Feathers will not be liable for the loss of, or damage
16     // to, your records or data, or any damages claimed by you based on a third party claim.
17     //
18     // You agree to distribute the Software and any Software Derivatives under a license agreement that:
19     //
20     // 1) is sufficient to notify all licensees of the Software and Software Derivatives that Michael
21     // Feathers assumes no liability for any claim that may arise regarding the Software or
22     // Software Derivatives, and
23     // 2) that disclaims all warranties, both express and implied, from Michael Feathers regarding the
24     // Software and Software Derivatives.  (If you include this Agreement with any distribution
25     // of the Software and Software Derivatives you will have meet this requirement) You agree that
26     // you will not delete any copyright notices in the Software.
27     //
28     // This Agreement is the exclusive statement of your rights in the Software as provided by Michael
29     // Feathers. Except for the licenses granted to you in the second paragraph above, no other licenses
30     // are granted hereunder, by estoppel, implication or otherwise.
31     //
32 jgs 82 #ifndef CPPUNIT_TESTRESULT_H
33     #define CPPUNIT_TESTRESULT_H
34    
35     #include <vector>
36    
37 gross 700 #include "Guards.h"
38     #include "TestFailure.h"
39     #include "CppUnitTestNamespace.h"
40 jgs 82 BEGIN_NAMESPACE_CPPUNITTEST
41    
42     class CppUnitException;
43     class Test;
44    
45    
46     /*
47     * A TestResult collects the results of executing a test case. It is an
48     * instance of the Collecting Parameter pattern.
49     *
50     * The test framework distinguishes between failures and errors.
51     * A failure is anticipated and checked for with assertions. Errors are
52     * unanticipated problems signified by exceptions that are not generated
53     * by the framework.
54     *
55     * TestResult supplies a template method 'setSynchronizationObject ()'
56     * so that subclasses can provide mutual exclusion in the face of multiple
57     * threads. This can be useful when tests execute in one thread and
58     * they fill a subclass of TestResult which effects change in another
59     * thread. To have mutual exclusion, override setSynchronizationObject ()
60     * and make sure that you create an instance of ExclusiveZone at the
61     * beginning of each method.
62     *
63     * see Test
64     */
65    
66     class TestResult
67     {
68     REFERENCEOBJECT (TestResult)
69    
70     public:
71     TestResult ();
72     virtual ~TestResult ();
73    
74     virtual void addError (Test *test, CppUnitException *e);
75     virtual void addFailure (Test *test, CppUnitException *e);
76     virtual void startTest (Test *test);
77     virtual void endTest (Test *test);
78     virtual int runTests ();
79     virtual int testErrors ();
80     virtual int testFailures ();
81     virtual bool wasSuccessful ();
82     virtual bool shouldStop ();
83     virtual void stop ();
84    
85     virtual std::vector<TestFailure *>& errors ();
86     virtual std::vector<TestFailure *>& failures ();
87    
88    
89     class SynchronizationObject
90     {
91     public:
92     SynchronizationObject () {}
93     virtual ~SynchronizationObject () {}
94    
95     virtual void lock () {}
96     virtual void unlock () {}
97     };
98    
99     class ExclusiveZone
100     {
101     SynchronizationObject *m_syncObject;
102    
103     public:
104     ExclusiveZone (SynchronizationObject *syncObject)
105     : m_syncObject (syncObject)
106     { m_syncObject->lock (); }
107    
108     ~ExclusiveZone ()
109     { m_syncObject->unlock (); }
110     };
111    
112     protected:
113     virtual void setSynchronizationObject (SynchronizationObject *syncObject);
114    
115     std::vector<TestFailure *> m_errors;
116     std::vector<TestFailure *> m_failures;
117     int m_runTests;
118     bool m_stop;
119     SynchronizationObject *m_syncObject;
120    
121     };
122    
123    
124    
125     // Construct a TestResult
126     inline TestResult::TestResult ()
127     : m_syncObject (new SynchronizationObject ())
128     { m_runTests = 0; m_stop = false; }
129    
130    
131     // Adds an error to the list of errors. The passed in exception
132     // caused the error
133     inline void TestResult::addError (Test *test, CppUnitException *e)
134     { ExclusiveZone zone (m_syncObject); m_errors.push_back (new TestFailure (test, e)); }
135    
136    
137     // Adds a failure to the list of failures. The passed in exception
138     // caused the failure.
139     inline void TestResult::addFailure (Test *test, CppUnitException *e)
140     { ExclusiveZone zone (m_syncObject); m_failures.push_back (new TestFailure (test, e)); }
141    
142    
143     // Informs the result that a test will be started.
144     inline void TestResult::startTest (Test *test)
145     { ExclusiveZone zone (m_syncObject); m_runTests++; }
146    
147    
148     // Informs the result that a test was completed.
149     inline void TestResult::endTest (Test *test)
150     { ExclusiveZone zone (m_syncObject); }
151    
152    
153     // Gets the number of run tests.
154     inline int TestResult::runTests ()
155     { ExclusiveZone zone (m_syncObject); return m_runTests; }
156    
157    
158     // Gets the number of detected errors.
159     inline int TestResult::testErrors ()
160     { ExclusiveZone zone (m_syncObject); return m_errors.size (); }
161    
162    
163     // Gets the number of detected failures.
164     inline int TestResult::testFailures ()
165     { ExclusiveZone zone (m_syncObject); return m_failures.size (); }
166    
167    
168     // Returns whether the entire test was successful or not.
169     inline bool TestResult::wasSuccessful ()
170     { ExclusiveZone zone (m_syncObject); return m_failures.size () == 0 && m_errors.size () == 0; }
171    
172    
173     // Returns a vector of the errors.
174     inline std::vector<TestFailure *>& TestResult::errors ()
175     { ExclusiveZone zone (m_syncObject); return m_errors; }
176    
177    
178     // Returns a vector of the failures.
179     inline std::vector<TestFailure *>& TestResult::failures ()
180     { ExclusiveZone zone (m_syncObject); return m_failures; }
181    
182    
183     // Returns whether testing should be stopped
184     inline bool TestResult::shouldStop ()
185     { ExclusiveZone zone (m_syncObject); return m_stop; }
186    
187    
188     // Stop testing
189     inline void TestResult::stop ()
190     { ExclusiveZone zone (m_syncObject); m_stop = true; }
191    
192    
193     // Accept a new synchronization object for protection of this instance
194     // TestResult assumes ownership of the object
195     inline void TestResult::setSynchronizationObject (SynchronizationObject *syncObject)
196     { delete m_syncObject; m_syncObject = syncObject; }
197    
198     END_NAMESPACE_CPPUNITTEST
199    
200     #endif
201    
202    
203    
204    
205    
206    
207    
208    

Properties

Name Value
svn:eol-style native
svn:executable *
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26