Debian Codegraph @

tests/CppUTestExt/IEEE754PluginTest.cpp

raw symbols SCIP
1 /*
2 * Copyright (c) 2015, Michael Feathers, James Grenning, Bas Vodde
3 * and Arnd R. Strube. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the <organization> nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #include "CppUTest/CommandLineTestRunner.h"
29 #include "CppUTest/TestHarness.h"
30 #include "CppUTest/TestRegistry.h"
31 #include "CppUTest/TestTestingFixture.h"
32 #include "CppUTestExt/IEEE754ExceptionsPlugin.h"
33
34 #ifdef CPPUTEST_HAVE_FENV
35 #if CPPUTEST_FENV_IS_WORKING_PROPERLY
36
37 extern "C"
38 {
39 #include "IEEE754PluginTest_c.h"
40 }
41
42 TEST_GROUP(FE__with_Plugin)
43 {
44 TestTestingFixture fixture;
45 IEEE754ExceptionsPlugin ieee754Plugin;
46 void setup(void) _override
47 {
48 fixture.installPlugin(&ieee754Plugin);
49 }
50 };
51
52 TEST(FE__with_Plugin, should_fail____when__FE_DIVBYZERO__is_set)
53 {
54 fixture.setTestFunction(set_divisionbyzero_c);
55 fixture.runAllTests();
56 fixture.assertPrintContains("IEEE754_CHECK_CLEAR(FE_DIVBYZERO) failed");
57 }
58
59 TEST(FE__with_Plugin, should_fail____when__FE_OVERFLOW___is_set)
60 {
61 fixture.setTestFunction(set_overflow_c);
62 fixture.runAllTests();
63 fixture.assertPrintContains("IEEE754_CHECK_CLEAR(FE_OVERFLOW) failed");
64 }
65
66 TEST(FE__with_Plugin, should_fail____when__FE_UNDERFLOW__is_set)
67 {
68 fixture.setTestFunction(set_underflow_c);
69 fixture.runAllTests();
70 fixture.assertPrintContains("IEEE754_CHECK_CLEAR(FE_UNDERFLOW) failed");
71 }
72
73 TEST(FE__with_Plugin, should_fail____when__FE_INEXACT____is_set_and_enabled)
74 {
75 IEEE754ExceptionsPlugin::enableInexact();
76 fixture.setTestFunction(set_inexact_c);
77 fixture.runAllTests();
78 fixture.assertPrintContains("IEEE754_CHECK_CLEAR(FE_INEXACT) failed");
79 }
80
81 TEST(FE__with_Plugin, should_succeed_when__FE_INEXACT____is_set_and_disabled)
82 {
83 IEEE754ExceptionsPlugin::enableInexact();
84 IEEE754ExceptionsPlugin::disableInexact();
85 fixture.setTestFunction(set_inexact_c);
86 fixture.runAllTests();
87 fixture.assertPrintContains("OK");
88 }
89
90 TEST(FE__with_Plugin, should_succeed_with_5_checks_when_no_flags_are_set)
91 {
92 IEEE754ExceptionsPlugin::enableInexact();
93 fixture.setTestFunction(set_nothing_c);
94 fixture.runAllTests();
95 fixture.assertPrintContains("OK (1 tests, 1 ran, 5 checks, 0 ignored, 0 filtered out");
96 IEEE754ExceptionsPlugin::disableInexact();
97 }
98
99 TEST(FE__with_Plugin, should_check_five_times_when_all_flags_are_set)
100 {
101 fixture.setTestFunction(set_everything_c);
102 fixture.runAllTests();
103 LONGS_EQUAL(5, fixture.getCheckCount());
104 }
105
106 TEST(FE__with_Plugin, should_fail_only_once_when_all_flags_are_set)
107 {
108 fixture.setTestFunction(set_everything_c);
109 fixture.runAllTests();
110 LONGS_EQUAL(1, fixture.getFailureCount());
111 }
112
113 static void set_everything_but_already_failed(void)
114 {
115 set_everything_c();
116 CHECK(1 == 2);
117 }
118
119 TEST(FE__with_Plugin, should_not_fail_again_when_test_has_already_failed)
120 {
121 fixture.setTestFunction(set_everything_but_already_failed);
122 fixture.runAllTests();
123 CHECK(IEEE754ExceptionsPlugin::checkIeee754OverflowExceptionFlag());
124 CHECK(IEEE754ExceptionsPlugin::checkIeee754UnderflowExceptionFlag());
125 CHECK(IEEE754ExceptionsPlugin::checkIeee754InexactExceptionFlag());
126 CHECK(IEEE754ExceptionsPlugin::checkIeee754DivByZeroExceptionFlag());
127 LONGS_EQUAL(1, fixture.getCheckCount());
128 LONGS_EQUAL(1, fixture.getFailureCount());
129 }
130
131 static IEEE754ExceptionsPlugin ip;
132
133 TEST_GROUP(IEEE754ExceptionsPlugin2)
134 {
135 void setup(void) _override
136 {
137 TestRegistry::getCurrentRegistry()->installPlugin(&ip);
138 }
139 };
140
141 IGNORE_TEST(IEEE754ExceptionsPlugin2, should_not_fail_in_ignored_test)
142 {
143 set_everything_c();
144 }
145
146 #endif
147 #endif