Debian Codegraph @

packages/stk/stk_unit_tests/stk_util/environment/UnitTestLogControl.cpp

raw
1 // Copyright 2002 - 2008, 2010, 2011 National Technology Engineering
2 // Solutions of Sandia, LLC (NTESS). Under the terms of Contract
3 // DE-NA0003525 with NTESS, the U.S. Government retains certain rights
4 // in this software.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are
8 // met:
9 //
10 // * Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 //
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following
15 // disclaimer in the documentation and/or other materials provided
16 // with the distribution.
17 //
18 // * Neither the name of NTESS nor the names of its contributors
19 // may be used to endorse or promote products derived from this
20 // software without specific prior written permission.
21 //
22 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 //
34
35 #include "gtest/gtest.h"
36 #include "stk_util/environment/LogControl.hpp" // for LogControlRuleInterval, LogControl, RuleMap
37 #include <iostream> // for basic_ostream::operator<<, operator<<
38 #include <string> // for char_traits, operator==, string, basic_st...
39
40
41
42 namespace {
43
44 std::ostringstream os;
45
46 } // namespace <empty>
47
48 TEST(UnitTestLogControl, UnitTest)
49 {
50 stk::RuleMap rule_map;
51
52 rule_map.addLogControlRule("system", stk::LogControlRuleInterval(2));
53 // rule_map.addLogControlRule("transient", stk::LogControlRuleInterval(3));
54 rule_map.addLogControlRule("nonlinear", stk::LogControlRuleInterval(5));
55
56 int work_count = 0;
57
58 stk::LogControl log_control_i(os, *rule_map.getLogControlRule("system"));
59 for (int i = 0; i < 10; ++i) {
60 log_control_i.next();
61
62 os << "Running system " << i << std::endl;
63
64 stk::LogControl log_control_j(os, stk::LogControlRuleInterval(3));
65 for (int j = 0; j < 10; ++j) {
66 log_control_j.next();
67
68 os << " Running transient " << j << std::endl;
69
70 stk::LogControl log_control_k(os, *rule_map.getLogControlRule("nonlinear"));
71 for (int k = 0; k < 10; ++k) {
72 log_control_k.next();
73
74 os << " Running nonlinear " << k << std::endl;
75
76 os << " Work count " << work_count << std::endl;
77
78 ++work_count;
79 }
80 }
81 }
82
83 std::string result =
84 "Running system 0\n"
85 " Running transient 0\n"
86 " Running nonlinear 0\n"
87 " Work count 0\n"
88 " Running nonlinear 5\n"
89 " Work count 5\n"
90 " Running nonlinear 9\n"
91 " Work count 9\n"
92 " Running transient 3\n"
93 " Running nonlinear 0\n"
94 " Work count 30\n"
95 " Running nonlinear 5\n"
96 " Work count 35\n"
97 " Running nonlinear 9\n"
98 " Work count 39\n"
99 " Running transient 6\n"
100 " Running nonlinear 0\n"
101 " Work count 60\n"
102 " Running nonlinear 5\n"
103 " Work count 65\n"
104 " Running nonlinear 9\n"
105 " Work count 69\n"
106 " Running transient 9\n"
107 " Running nonlinear 0\n"
108 " Work count 90\n"
109 " Running nonlinear 5\n"
110 " Work count 95\n"
111 " Running nonlinear 9\n"
112 " Work count 99\n"
113 "Running system 2\n"
114 " Running transient 0\n"
115 " Running nonlinear 0\n"
116 " Work count 200\n"
117 " Running nonlinear 5\n"
118 " Work count 205\n"
119 " Running nonlinear 9\n"
120 " Work count 209\n"
121 " Running transient 3\n"
122 " Running nonlinear 0\n"
123 " Work count 230\n"
124 " Running nonlinear 5\n"
125 " Work count 235\n"
126 " Running nonlinear 9\n"
127 " Work count 239\n"
128 " Running transient 6\n"
129 " Running nonlinear 0\n"
130 " Work count 260\n"
131 " Running nonlinear 5\n"
132 " Work count 265\n"
133 " Running nonlinear 9\n"
134 " Work count 269\n"
135 " Running transient 9\n"
136 " Running nonlinear 0\n"
137 " Work count 290\n"
138 " Running nonlinear 5\n"
139 " Work count 295\n"
140 " Running nonlinear 9\n"
141 " Work count 299\n"
142 "Running system 4\n"
143 " Running transient 0\n"
144 " Running nonlinear 0\n"
145 " Work count 400\n"
146 " Running nonlinear 5\n"
147 " Work count 405\n"
148 " Running nonlinear 9\n"
149 " Work count 409\n"
150 " Running transient 3\n"
151 " Running nonlinear 0\n"
152 " Work count 430\n"
153 " Running nonlinear 5\n"
154 " Work count 435\n"
155 " Running nonlinear 9\n"
156 " Work count 439\n"
157 " Running transient 6\n"
158 " Running nonlinear 0\n"
159 " Work count 460\n"
160 " Running nonlinear 5\n"
161 " Work count 465\n"
162 " Running nonlinear 9\n"
163 " Work count 469\n"
164 " Running transient 9\n"
165 " Running nonlinear 0\n"
166 " Work count 490\n"
167 " Running nonlinear 5\n"
168 " Work count 495\n"
169 " Running nonlinear 9\n"
170 " Work count 499\n"
171 "Running system 6\n"
172 " Running transient 0\n"
173 " Running nonlinear 0\n"
174 " Work count 600\n"
175 " Running nonlinear 5\n"
176 " Work count 605\n"
177 " Running nonlinear 9\n"
178 " Work count 609\n"
179 " Running transient 3\n"
180 " Running nonlinear 0\n"
181 " Work count 630\n"
182 " Running nonlinear 5\n"
183 " Work count 635\n"
184 " Running nonlinear 9\n"
185 " Work count 639\n"
186 " Running transient 6\n"
187 " Running nonlinear 0\n"
188 " Work count 660\n"
189 " Running nonlinear 5\n"
190 " Work count 665\n"
191 " Running nonlinear 9\n"
192 " Work count 669\n"
193 " Running transient 9\n"
194 " Running nonlinear 0\n"
195 " Work count 690\n"
196 " Running nonlinear 5\n"
197 " Work count 695\n"
198 " Running nonlinear 9\n"
199 " Work count 699\n"
200 "Running system 8\n"
201 " Running transient 0\n"
202 " Running nonlinear 0\n"
203 " Work count 800\n"
204 " Running nonlinear 5\n"
205 " Work count 805\n"
206 " Running nonlinear 9\n"
207 " Work count 809\n"
208 " Running transient 3\n"
209 " Running nonlinear 0\n"
210 " Work count 830\n"
211 " Running nonlinear 5\n"
212 " Work count 835\n"
213 " Running nonlinear 9\n"
214 " Work count 839\n"
215 " Running transient 6\n"
216 " Running nonlinear 0\n"
217 " Work count 860\n"
218 " Running nonlinear 5\n"
219 " Work count 865\n"
220 " Running nonlinear 9\n"
221 " Work count 869\n"
222 " Running transient 9\n"
223 " Running nonlinear 0\n"
224 " Work count 890\n"
225 " Running nonlinear 5\n"
226 " Work count 895\n"
227 " Running nonlinear 9\n"
228 " Work count 899\n";
229
230 ASSERT_EQ((result == os.str()), true);
231 }
232