• R/O
  • HTTP
  • SSH
  • HTTPS

ccunit: Commit

A C Unit Test Library for C language.


Commit MetaInfo

Revisión6a47784aa4074fbd1bad49627b9f25a03b978c8b (tree)
Tiempo2013-07-06 17:31:15
Autortsntsumi <tsntsumi@user...>
Commitertsntsumi

Log Message

Modified the example the test fails.

Cambiar Resumen

Diferencia incremental

--- a/doc/cookbook.dox
+++ b/doc/cookbook.dox
@@ -369,12 +369,12 @@ of @c testComplex.c on purpose.
369369 @endif
370370
371371 @code
372-void test_complex_equals ()
372+void test_complex_new ()
373373 {
374374 ...
375- CCUNIT_ASSERT (complex_equals (c10_1, c10_1_2));
376-/*CCUNIT_ASSERT (complex_equals (c10_1, c1_1) == 0);*/
377- CCUNIT_ASSERT (complex_equals (c10_1, c1_1) != 0);
375+ CCUNIT_ASSERT_EQ_DOUBLE (10, c10_1->real);
376+/*CCUNIT_ASSERT_EQ_DOUBLE (1, c10_1->imaginary);*/
377+ CCUNIT_ASSERT_EQ_DOUBLE (1.1, c10_1->imaginary);
378378 ...
379379 }
380380 @endcode
@@ -382,15 +382,17 @@ void test_complex_equals ()
382382 @code
383383 $ gcc -o runTestCaseRunner runTestCaseRunner.c testComplex.c complex.c -lccunit
384384 $ ./runTestRunner
385-..F
386-Time: 0.000036 sec
385+.F.
386+Time: 0.000051 sec
387387
388388 FAILURES!!!
389389 Test Results:
390390 Run 2, Failures 1
391391 There was 1 failure:
392-testComplex.c:46: complex equals test:
393- complex_equals (c10_1, c1_1) != 0
392+testFailComplex.c:36: complex new test:
393+ 1.1 == c10_1->imaginary
394+ expect: 1.100000
395+ actual: 1.000000
394396 @endcode
395397
396398 @english
@@ -399,12 +401,12 @@ Then, you will see that the second is unsuccessful.
399401 @japanese
400402 この例ではテストケースを 2 個実行して、
401403 ひとつのテストケースで失敗していることがわかります。
402-最初の「<code>..F</code>」では、
403-ふたつ目のテストケースが失敗していることをあらわしています。
404+最初の「 <code>.F.</code>」では、
405+ひとつ目のテストケースが失敗していることをあらわしています。
404406
405407 また上述のように、
406-失敗したファイル名、行番号、テストケースの名前 (<code>complex equals test</code>)、
407-表明した条件の文字列 (<code>complex_equals (c10_1, c1_1) != 0</code>) が表示されます。
408+失敗したファイル名、行番号、テストケースの名前 (<code>complex new test</code>)、
409+表明した条件の文字列 (<code>1.1 == c10_1->imaginary</code>) が表示されます。
408410 @endif
409411
410412 @english
@@ -877,7 +879,7 @@ One file can define the multiple test case.
877879
878880 static complex_t* c10_1;
879881
880-//** test new *\/
882+//** complex new test *\/
881883 void test_complex_new ()
882884 {
883885 ...
--- a/examples/complex/.gitignore
+++ b/examples/complex/.gitignore
@@ -12,5 +12,6 @@ runTestFixture
1212 runTestRunner
1313 runTestSuite
1414 runTestSuiteAuto
15+runTestFailComplex
1516 suiteComplex.c
1617 suiteTestComplex.c
--- a/examples/complex/Makefile.am
+++ b/examples/complex/Makefile.am
@@ -24,6 +24,7 @@ check_PROGRAMS = runTestCase runTestCaseRunner runTestCaseSetup \
2424 runTestSuite runTestSuiteAuto
2525 TESTS = runTestCase runTestCaseRunner runTestCaseSetup \
2626 runTestSuite runTestSuiteAuto
27+noinst_PROGRAMS = runTestFailComplex
2728
2829 libcomplex_a_SOURCES = complex.c complex.h
2930
@@ -41,11 +42,13 @@ runTestSuiteAuto_SOURCES = runTestSuiteAuto.c testComplexSetup.c testComplexArit
4142 nodist_runTestSuiteAuto_SOURCES = suiteTestComplex.c
4243 BUILT_SOURCES = suiteTestComplex.c
4344
45+runTestFailComplex_SOURCES = runTestCaseRunner.c testFailComplex.c
46+
4447 AM_CFLAGS=-Wall -Werror
4548 AM_CPPFLAGS=-I. -I$(top_srcdir)/src -I$(top_builddir)/src
4649 AM_LDFLAGS=-L. -L$(top_builddir)/src/ccunit
4750
48-EXTRA_DIST=
51+EXTRA_DIST=testFailComplex.c
4952
5053 CLEANFILES=*~ .*~ ./\#*\# *.log suiteTestComplex.c
5154
--- a/examples/complex/runTestCase.c
+++ b/examples/complex/runTestCase.c
@@ -35,7 +35,7 @@ int main ()
3535 testCase = ccunit_newTestCase ("complex test");
3636 ccunit_addNewTestFunc (testCase,
3737 "test_complex_new",
38- "test new",
38+ "complex new test",
3939 test_complex_new);
4040 ccunit_addNewTestFunc (testCase,
4141 "test_complex_equals",
--- a/examples/complex/runTestCaseRunner.c
+++ b/examples/complex/runTestCaseRunner.c
@@ -36,7 +36,7 @@ int main ()
3636 testCase = ccunit_newTestCase ("complex test");
3737 ccunit_addNewTestFunc (testCase,
3838 "test_complex_new",
39- "test new",
39+ "complex new test",
4040 test_complex_new);
4141 ccunit_addNewTestFunc (testCase,
4242 "test_complex_equals",
--- a/examples/complex/testComplex.c
+++ b/examples/complex/testComplex.c
@@ -27,16 +27,16 @@
2727
2828 /** TEST CASE: complex number add test */
2929
30-/** test new */
30+/** complex new test */
3131 void test_complex_new ()
3232 {
3333 complex_t* c10_1 = complex_new (10, 1);
34- CCUNIT_ASSERT_TEST (double, 10, ==, c10_1->real);
35- CCUNIT_ASSERT_TEST (double, 1, ==, c10_1->imaginary);
34+ CCUNIT_ASSERT_EQ_DOUBLE (10, c10_1->real);
35+ CCUNIT_ASSERT_EQ_DOUBLE (1, c10_1->imaginary);
3636 complex_delete (c10_1);
3737 }
3838
39-/** test equals */
39+/** complex equals test */
4040 void test_complex_equals ()
4141 {
4242 complex_t* c10_1 = complex_new (10, 1);
@@ -49,7 +49,7 @@ void test_complex_equals ()
4949 complex_delete (c1_1);
5050 }
5151
52-/** test to_string */
52+/** complex to_string test */
5353 void test_complex_to_string ()
5454 {
5555 complex_t* c10_1 = complex_new (10, 1);
--- a/examples/complex/testComplexSetup.c
+++ b/examples/complex/testComplexSetup.c
@@ -42,8 +42,8 @@ void tearDown_test_complex ()
4242 /** test new */
4343 void test_complex_new ()
4444 {
45- CCUNIT_ASSERT_TEST (double, 10, ==, c10_1->real);
46- CCUNIT_ASSERT_TEST (double, 1, ==, c10_1->imaginary);
45+ CCUNIT_ASSERT_EQ_DOUBLE (10, c10_1->real);
46+ CCUNIT_ASSERT_EQ_DOUBLE (1, c10_1->imaginary);
4747 }
4848
4949 /** test equals */
--- /dev/null
+++ b/examples/complex/testFailComplex.c
@@ -0,0 +1,63 @@
1+/* Copyright (C) 2003, 2010 TSUTSUMI Kikuo.
2+ This file is part of the CCUnit Library.
3+
4+ The CCUnit Library is free software; you can redistribute it and/or
5+ modify it under the terms of the GNU Lesser General Public License
6+ as published by the Free Software Foundation; either version 2.1 of
7+ the License, or (at your option) any later version.
8+
9+ The CCUnit Library is distributed in the hope that it will be
10+ useful, but WITHOUT ANY WARRANTY; without even the implied warranty
11+ of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+ GNU Lesser General Public License for more details.
13+
14+ You should have received a copy of the GNU Lesser General Public
15+ License along with the CCUnit Library; see the file COPYING.LESSER.
16+ If not, write to the Free Software Foundation, Inc., 59 Temple
17+ Place - Suite 330, Boston, MA 02111-1307, USA.
18+*/
19+
20+/*
21+ * $Id$
22+ */
23+
24+#include <ccunit/CCUnitAssert.h>
25+
26+#include "complex.h"
27+
28+/** TEST CASE: complex number add test */
29+
30+/** complex new test */
31+void test_complex_new ()
32+{
33+ complex_t* c10_1 = complex_new (10, 1);
34+ CCUNIT_ASSERT_EQ_DOUBLE (10, c10_1->real);
35+/*CCUNIT_ASSERT_EQ_DOUBLE (1, c10_1->imaginary);*/
36+ CCUNIT_ASSERT_EQ_DOUBLE (1.1, c10_1->imaginary);
37+ complex_delete (c10_1);
38+}
39+
40+/** complex equals test */
41+void test_complex_equals ()
42+{
43+ complex_t* c10_1 = complex_new (10, 1);
44+ complex_t* c10_1_2 = complex_new (10, 1);
45+ complex_t* c1_1 = complex_new (1, 1);
46+ CCUNIT_ASSERT (complex_equals (c10_1, c10_1_2));
47+ CCUNIT_ASSERT (complex_equals (c10_1, c1_1) == 0);
48+ complex_delete (c10_1);
49+ complex_delete (c10_1_2);
50+ complex_delete (c1_1);
51+}
52+
53+/** complex to_string test */
54+void test_complex_to_string ()
55+{
56+ complex_t* c10_1 = complex_new (10, 1);
57+ char* s10_1 = complex_to_string (c10_1);
58+ CCUNIT_ASSERT_EQ_STR ("10+1i", s10_1);
59+ complex_delete (c10_1);
60+ free (s10_1);
61+}
62+
63+/** end test case */
Show on old repository browser