2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2011,2012,2013,2014, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
37 * Tests utilities for test reference data.
39 * \author Teemu Murtola <teemu.murtola@gmail.com>
40 * \ingroup module_testutils
44 #include "testutils/refdata.h"
48 #include <gtest/gtest-spi.h>
49 #include <gtest/gtest.h>
54 TEST(ReferenceDataTest
, HandlesSimpleData
)
56 using gmx::test::TestReferenceData
;
57 using gmx::test::TestReferenceChecker
;
60 TestReferenceData
data(gmx::test::erefdataUpdateAll
);
61 TestReferenceChecker
checker(data
.rootChecker());
62 checker
.checkBoolean(true, "int");
63 checker
.checkInteger(1, "int");
64 checker
.checkInt64(1ULL<<42, "int64");
65 checker
.checkUInt64(1ULL<<42, "uint64");
66 checker
.checkDouble(0.5, "real");
67 checker
.checkString("Test", "string");
70 TestReferenceData
data(gmx::test::erefdataCompare
);
71 TestReferenceChecker
checker(data
.rootChecker());
72 checker
.checkBoolean(true, "int");
73 checker
.checkInteger(1, "int");
74 checker
.checkInt64(1ULL<<42, "int64");
75 checker
.checkUInt64(1ULL<<42, "uint64");
76 checker
.checkDouble(0.5, "real");
77 checker
.checkString("Test", "string");
81 TEST(ReferenceDataTest
, HandlesFloatingPointData
)
83 using gmx::test::TestReferenceData
;
84 using gmx::test::TestReferenceChecker
;
85 const float floatValue
= 4.0f
/3.0f
;
86 const double doubleValue
= 4.0/3.0;
89 TestReferenceData
data(gmx::test::erefdataUpdateAll
);
90 TestReferenceChecker
checker(data
.rootChecker());
91 checker
.checkDouble(doubleValue
, "double");
92 checker
.checkReal(doubleValue
, "real");
93 checker
.checkFloat(floatValue
, "float");
96 TestReferenceData
data(gmx::test::erefdataCompare
);
97 TestReferenceChecker
checker(data
.rootChecker());
98 checker
.checkDouble(doubleValue
, "double");
99 checker
.checkReal(floatValue
, "real");
100 checker
.checkReal(doubleValue
, "real");
101 checker
.checkFloat(floatValue
, "float");
105 TEST(ReferenceDataTest
, HandlesPresenceChecks
)
107 using gmx::test::TestReferenceData
;
108 using gmx::test::TestReferenceChecker
;
111 TestReferenceData
data(gmx::test::erefdataUpdateAll
);
112 TestReferenceChecker
checker(data
.rootChecker());
113 EXPECT_TRUE(checker
.checkPresent(true, "present"));
114 checker
.checkInteger(1, "present");
115 EXPECT_FALSE(checker
.checkPresent(false, "absent"));
118 TestReferenceData
data(gmx::test::erefdataCompare
);
119 TestReferenceChecker
checker(data
.rootChecker());
120 // Assigned to avoid warnings about potentially uninitialized value.
122 EXPECT_TRUE(checker
.checkPresent(true, "present"));
123 checker
.checkInteger(1, "present");
124 EXPECT_NONFATAL_FAILURE(bRet
= checker
.checkPresent(false, "present"), "");
126 EXPECT_NONFATAL_FAILURE(bRet
= checker
.checkPresent(true, "absent"), "");
128 EXPECT_FALSE(checker
.checkPresent(false, "absent"));
133 TEST(ReferenceDataTest
, HandlesStringBlockData
)
135 using gmx::test::TestReferenceData
;
136 using gmx::test::TestReferenceChecker
;
139 TestReferenceData
data(gmx::test::erefdataUpdateAll
);
140 TestReferenceChecker
checker(data
.rootChecker());
141 checker
.checkStringBlock("Line1\nLine2\n", "block");
142 checker
.checkString("Test", "string");
145 TestReferenceData
data(gmx::test::erefdataCompare
);
146 TestReferenceChecker
checker(data
.rootChecker());
147 checker
.checkStringBlock("Line1\nLine2\n", "block");
148 EXPECT_NONFATAL_FAILURE(checker
.checkString("Line1\nLine2\n", "block"), "");
149 EXPECT_NONFATAL_FAILURE(checker
.checkStringBlock("Test", "string"), "");
154 TEST(ReferenceDataTest
, HandlesVectorData
)
156 using gmx::test::TestReferenceData
;
157 using gmx::test::TestReferenceChecker
;
158 int veci
[3] = { -1, 3, 5 };
159 float vecf
[3] = { -2.3f
, 1.43f
, 2.5f
};
160 double vecd
[3] = { -2.3, 1.43, 2.5 };
163 TestReferenceData
data(gmx::test::erefdataUpdateAll
);
164 TestReferenceChecker
checker(data
.rootChecker());
165 checker
.checkVector(veci
, "ivec");
166 checker
.checkVector(vecf
, "fvec");
167 checker
.checkVector(vecd
, "dvec");
170 TestReferenceData
data(gmx::test::erefdataCompare
);
171 TestReferenceChecker
checker(data
.rootChecker());
172 checker
.checkVector(veci
, "ivec");
173 checker
.checkVector(vecf
, "fvec");
174 checker
.checkVector(vecd
, "dvec");
179 TEST(ReferenceDataTest
, HandlesSequenceData
)
181 using gmx::test::TestReferenceData
;
182 using gmx::test::TestReferenceChecker
;
183 const int seq
[5] = { -1, 3, 5, 2, 4 };
186 TestReferenceData
data(gmx::test::erefdataUpdateAll
);
187 TestReferenceChecker
checker(data
.rootChecker());
188 checker
.checkSequenceArray(5, seq
, "seq");
191 TestReferenceData
data(gmx::test::erefdataCompare
);
192 TestReferenceChecker
checker(data
.rootChecker());
193 checker
.checkSequenceArray(5, seq
, "seq");
198 TEST(ReferenceDataTest
, HandlesIncorrectData
)
200 using gmx::test::TestReferenceData
;
201 using gmx::test::TestReferenceChecker
;
202 int seq
[5] = { -1, 3, 5, 2, 4 };
205 TestReferenceData
data(gmx::test::erefdataUpdateAll
);
206 TestReferenceChecker
checker(data
.rootChecker());
207 checker
.checkInteger(1, "int");
208 checker
.checkDouble(0.5, "real");
209 checker
.checkString("Test", "string");
210 checker
.checkSequenceArray(5, seq
, "seq");
213 TestReferenceData
data(gmx::test::erefdataCompare
);
214 TestReferenceChecker
checker(data
.rootChecker());
215 EXPECT_NONFATAL_FAILURE(checker
.checkInteger(2, "int"), "");
216 EXPECT_NONFATAL_FAILURE(checker
.checkDouble(0.3, "real"), "");
217 EXPECT_NONFATAL_FAILURE(checker
.checkString("Test2", "string"), "");
218 EXPECT_NONFATAL_FAILURE(checker
.checkSequenceArray(4, seq
, "seq"), "");
220 EXPECT_NONFATAL_FAILURE(checker
.checkSequenceArray(5, seq
, "seq"), "");
225 TEST(ReferenceDataTest
, HandlesMissingData
)
227 using gmx::test::TestReferenceData
;
228 using gmx::test::TestReferenceChecker
;
229 const int seq
[5] = { -1, 3, 5, 2, 4 };
232 TestReferenceData
data(gmx::test::erefdataUpdateAll
);
233 TestReferenceChecker
checker(data
.rootChecker());
234 checker
.checkInteger(1, "int");
235 checker
.checkSequenceArray(5, seq
, "seq");
238 TestReferenceData
data(gmx::test::erefdataCompare
);
239 TestReferenceChecker
checker(data
.rootChecker());
240 EXPECT_NONFATAL_FAILURE(checker
.checkInteger(1, "missing"), "");
241 EXPECT_NONFATAL_FAILURE(checker
.checkSequenceArray(5, seq
, "missing"), "");
246 TEST(ReferenceDataTest
, HandlesMissingReferenceDataFile
)
248 using gmx::test::TestReferenceData
;
249 using gmx::test::TestReferenceChecker
;
250 const int seq
[5] = { -1, 3, 5, 2, 4 };
252 EXPECT_NONFATAL_FAILURE({
253 TestReferenceData
data(gmx::test::erefdataCompare
);
254 TestReferenceChecker
checker(data
.rootChecker());
255 checker
.checkInteger(1, "int");
256 checker
.checkDouble(0.5, "real");
257 checker
.checkString("Test", "string");
258 checker
.checkSequenceArray(5, seq
, "seq");
263 TEST(ReferenceDataTest
, HandlesSpecialCharactersInStrings
)
265 using gmx::test::TestReferenceData
;
266 using gmx::test::TestReferenceChecker
;
269 TestReferenceData
data(gmx::test::erefdataUpdateAll
);
270 TestReferenceChecker
checker(data
.rootChecker());
271 checker
.checkString("\"<'>\n \r &\\/;", "string");
272 // \r is not handled correctly
273 checker
.checkStringBlock("\"<'>\n ]]> &\\/;", "stringblock");
276 TestReferenceData
data(gmx::test::erefdataCompare
);
277 TestReferenceChecker
checker(data
.rootChecker());
278 checker
.checkString("\"<'>\n \r &\\/;", "string");
279 checker
.checkStringBlock("\"<'>\n ]]> &\\/;", "stringblock");
284 TEST(ReferenceDataTest
, HandlesSequenceItemIndices
)
286 using gmx::test::TestReferenceData
;
287 using gmx::test::TestReferenceChecker
;
288 int seq
[5] = { -1, 3, 5, 2, 4 };
291 TestReferenceData
data(gmx::test::erefdataUpdateAll
);
292 TestReferenceChecker
checker(data
.rootChecker());
293 checker
.checkSequenceArray(5, seq
, "seq");
294 checker
.checkSequenceArray(5, seq
, "seq2");
297 TestReferenceData
data(gmx::test::erefdataCompare
);
298 TestReferenceChecker
checker(data
.rootChecker());
300 EXPECT_NONFATAL_FAILURE(checker
.checkSequenceArray(5, seq
, "seq"), "seq/[0]");
303 EXPECT_NONFATAL_FAILURE(checker
.checkSequenceArray(5, seq
, "seq"), "seq/[3]");
304 EXPECT_NONFATAL_FAILURE(checker
.checkSequenceArray(5, seq
, "seq2"), "seq2/[3]");
309 TEST(ReferenceDataTest
, HandlesMultipleChecksAgainstSameData
)
311 using gmx::test::TestReferenceData
;
312 using gmx::test::TestReferenceChecker
;
315 TestReferenceData
data(gmx::test::erefdataUpdateAll
);
316 TestReferenceChecker
checker(data
.rootChecker());
317 checker
.checkString("Test", "string");
318 EXPECT_NONFATAL_FAILURE(checker
.checkString("Test2", "string"), "");
319 checker
.checkStringBlock("TestString", "stringblock");
320 EXPECT_NONFATAL_FAILURE(checker
.checkStringBlock("TestString2", "stringblock"), "");
323 TestReferenceData
data(gmx::test::erefdataCompare
);
324 TestReferenceChecker
checker(data
.rootChecker());
325 checker
.checkString("Test", "string");
326 EXPECT_NONFATAL_FAILURE(checker
.checkString("Test2", "string"), "");
327 checker
.checkStringBlock("TestString", "stringblock");
328 EXPECT_NONFATAL_FAILURE(checker
.checkStringBlock("TestString2", "stringblock"), "");
333 TEST(ReferenceDataTest
, HandlesMultipleNullIds
)
335 using gmx::test::TestReferenceData
;
336 using gmx::test::TestReferenceChecker
;
339 TestReferenceData
data(gmx::test::erefdataUpdateAll
);
340 TestReferenceChecker
checker(data
.rootChecker());
341 checker
.checkString("Test", NULL
);
342 checker
.checkString("Test2", NULL
);
345 TestReferenceData
data(gmx::test::erefdataCompare
);
346 TestReferenceChecker
checker(data
.rootChecker());
347 checker
.checkString("Test", NULL
);
348 checker
.checkString("Test2", NULL
);
349 EXPECT_NONFATAL_FAILURE(checker
.checkString("Test", NULL
), "");