* This file is part of the GROMACS molecular simulation package.
*
* Copyright (c) 2011-2018, The GROMACS development team.
- * Copyright (c) 2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2019,2020,2021, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
* Implements classes and functions from refdata.h.
*
* \author Teemu Murtola <teemu.murtola@gmail.com>
+ * \author Mark Abraham <mark.j.abraham@gmail.com>
* \ingroup module_testutils
*/
#include "gmxpre.h"
-#include "refdata.h"
+#include "testutils/refdata.h"
#include <cctype>
#include <cstdlib>
#include <algorithm>
#include <limits>
+#include <optional>
#include <string>
#include <gtest/gtest.h>
+#include "gromacs/math/vectypes.h"
#include "gromacs/options/basicoptions.h"
#include "gromacs/options/ioptionscontainer.h"
#include "gromacs/utility/any.h"
#include "gromacs/utility/real.h"
#include "gromacs/utility/stringutil.h"
-#include "testutils/refdata_checkers.h"
-#include "testutils/refdata_impl.h"
-#include "testutils/refdata_xml.h"
#include "testutils/testasserts.h"
#include "testutils/testexceptions.h"
#include "testutils/testfilemanager.h"
+#include "refdata_checkers.h"
+#include "refdata_impl.h"
+#include "refdata_xml.h"
+
namespace gmx
{
namespace test
{
public:
//! Initializes a checker in the given mode.
- TestReferenceDataImpl(ReferenceDataMode mode, bool bSelfTestMode);
+ TestReferenceDataImpl(ReferenceDataMode mode, bool bSelfTestMode, std::optional<std::string> testNameOverride);
//! Performs final reference data processing when test ends.
- void onTestEnd(bool testPassed);
+ void onTestEnd(bool testPassed) const;
//! Full path of the reference data file.
std::string fullFilename_;
}
//! Returns a reference to the global reference data object.
-TestReferenceDataImplPointer initReferenceDataInstance()
+TestReferenceDataImplPointer initReferenceDataInstance(std::optional<std::string> testNameOverride)
{
GMX_RELEASE_ASSERT(!g_referenceData, "Test cannot create multiple TestReferenceData instances");
- g_referenceData.reset(new internal::TestReferenceDataImpl(getReferenceDataMode(), false));
+ g_referenceData.reset(new internal::TestReferenceDataImpl(
+ getReferenceDataMode(), false, std::move(testNameOverride)));
return g_referenceData;
}
g_referenceData->onTestEnd(true);
g_referenceData.reset();
}
- g_referenceData.reset(new internal::TestReferenceDataImpl(mode, true));
+ g_referenceData.reset(new internal::TestReferenceDataImpl(mode, true, std::nullopt));
return g_referenceData;
}
namespace internal
{
-TestReferenceDataImpl::TestReferenceDataImpl(ReferenceDataMode mode, bool bSelfTestMode) :
- updateMismatchingEntries_(false),
- bSelfTestMode_(bSelfTestMode),
- bInUse_(false)
+TestReferenceDataImpl::TestReferenceDataImpl(ReferenceDataMode mode,
+ bool bSelfTestMode,
+ std::optional<std::string> testNameOverride) :
+ updateMismatchingEntries_(false), bSelfTestMode_(bSelfTestMode), bInUse_(false)
{
- const std::string dirname = bSelfTestMode ? TestFileManager::getGlobalOutputTempDirectory()
- : TestFileManager::getInputDataDirectory();
- const std::string filename = TestFileManager::getTestSpecificFileName(".xml");
+ const std::string dirname = bSelfTestMode ? TestFileManager::getGlobalOutputTempDirectory()
+ : TestFileManager::getInputDataDirectory();
+ const std::string filename = testNameOverride.has_value()
+ ? testNameOverride.value()
+ : TestFileManager::getTestSpecificFileName(".xml");
fullFilename_ = Path::join(dirname, "refdata", filename);
switch (mode)
}
}
-void TestReferenceDataImpl::onTestEnd(bool testPassed)
+void TestReferenceDataImpl::onTestEnd(bool testPassed) const
{
if (!bInUse_)
{
std::string appendPath(const char* id) const;
//! Creates an entry with given parameters and fills it with \p checker.
- ReferenceDataEntry::EntryPointer createEntry(const char* type,
- const char* id,
- const IReferenceDataEntryChecker& checker) const
+ static ReferenceDataEntry::EntryPointer createEntry(const char* type,
+ const char* id,
+ const IReferenceDataEntryChecker& checker)
{
ReferenceDataEntry::EntryPointer entry(new ReferenceDataEntry(type, id));
checker.fillEntry(entry.get());
return entry;
}
//! Checks an entry for correct type and using \p checker.
- ::testing::AssertionResult checkEntry(const ReferenceDataEntry& entry,
- const std::string& fullId,
- const char* type,
- const IReferenceDataEntryChecker& checker) const
+ static ::testing::AssertionResult checkEntry(const ReferenceDataEntry& entry,
+ const std::string& fullId,
+ const char* type,
+ const IReferenceDataEntryChecker& checker)
{
if (entry.type() != type)
{
* TestReferenceData
*/
-TestReferenceData::TestReferenceData() : impl_(initReferenceDataInstance()) {}
+TestReferenceData::TestReferenceData() : impl_(initReferenceDataInstance(std::nullopt)) {}
+
+TestReferenceData::TestReferenceData(std::string testNameOverride) :
+ impl_(initReferenceDataInstance(std::move(testNameOverride)))
+{
+}
TestReferenceData::TestReferenceData(ReferenceDataMode mode) :
impl_(initReferenceDataInstanceForSelfTest(mode))
return TestReferenceChecker(new TestReferenceChecker::Impl(true));
}
impl_->compareRootEntry_->setChecked();
- return TestReferenceChecker(new TestReferenceChecker::Impl(
- "", impl_->compareRootEntry_.get(), impl_->outputRootEntry_.get(),
- impl_->updateMismatchingEntries_, impl_->bSelfTestMode_, defaultRealTolerance()));
+ return TestReferenceChecker(new TestReferenceChecker::Impl("",
+ impl_->compareRootEntry_.get(),
+ impl_->outputRootEntry_.get(),
+ impl_->updateMismatchingEntries_,
+ impl_->bSelfTestMode_,
+ defaultRealTolerance()));
}
}
}
+void TestReferenceChecker::disableUnusedEntriesCheck()
+{
+ if (impl_->compareRootEntry_)
+ {
+ impl_->compareRootEntry_->setCheckedIncludingChildren();
+ }
+}
+
bool TestReferenceChecker::checkPresent(bool bPresent, const char* id)
{
{
impl_->outputRootEntry_->addChild(entry->cloneToOutputEntry());
}
- return TestReferenceChecker(new Impl(fullId, entry, entry->correspondingOutputEntry(),
- impl_->updateMismatchingEntries_, impl_->bSelfTestMode_,
+ return TestReferenceChecker(new Impl(fullId,
+ entry,
+ entry->correspondingOutputEntry(),
+ impl_->updateMismatchingEntries_,
+ impl_->bSelfTestMode_,
impl_->defaultTolerance_));
}
void TestReferenceChecker::checkBoolean(bool value, const char* id)
{
- EXPECT_PLAIN(impl_->processItem(Impl::cBooleanNodeName, id,
- ExactStringChecker(value ? "true" : "false")));
+ EXPECT_PLAIN(impl_->processItem(
+ Impl::cBooleanNodeName, id, ExactStringChecker(value ? "true" : "false")));
}
void TestReferenceChecker::checkUChar(unsigned char value, const char* id)
{
- EXPECT_PLAIN(impl_->processItem(Impl::cUCharNodeName, id,
- ExactStringChecker(formatString("%d", value))));
+ EXPECT_PLAIN(impl_->processItem(
+ Impl::cUCharNodeName, id, ExactStringChecker(formatString("%d", value))));
}
void TestReferenceChecker::checkInteger(int value, const char* id)
{
- EXPECT_PLAIN(impl_->processItem(Impl::cIntegerNodeName, id,
- ExactStringChecker(formatString("%d", value))));
+ EXPECT_PLAIN(impl_->processItem(
+ Impl::cIntegerNodeName, id, ExactStringChecker(formatString("%d", value))));
}
void TestReferenceChecker::checkInt32(int32_t value, const char* id)
{
- EXPECT_PLAIN(impl_->processItem(Impl::cInt32NodeName, id,
- ExactStringChecker(formatString("%" PRId32, value))));
+ EXPECT_PLAIN(impl_->processItem(
+ Impl::cInt32NodeName, id, ExactStringChecker(formatString("%" PRId32, value))));
}
void TestReferenceChecker::checkUInt32(uint32_t value, const char* id)
{
- EXPECT_PLAIN(impl_->processItem(Impl::cUInt32NodeName, id,
- ExactStringChecker(formatString("%" PRIu32, value))));
+ EXPECT_PLAIN(impl_->processItem(
+ Impl::cUInt32NodeName, id, ExactStringChecker(formatString("%" PRIu32, value))));
}
void TestReferenceChecker::checkInt64(int64_t value, const char* id)
{
- EXPECT_PLAIN(impl_->processItem(Impl::cInt64NodeName, id,
- ExactStringChecker(formatString("%" PRId64, value))));
+ EXPECT_PLAIN(impl_->processItem(
+ Impl::cInt64NodeName, id, ExactStringChecker(formatString("%" PRId64, value))));
}
void TestReferenceChecker::checkUInt64(uint64_t value, const char* id)
{
- EXPECT_PLAIN(impl_->processItem(Impl::cUInt64NodeName, id,
- ExactStringChecker(formatString("%" PRIu64, value))));
+ EXPECT_PLAIN(impl_->processItem(
+ Impl::cUInt64NodeName, id, ExactStringChecker(formatString("%" PRIu64, value))));
}
void TestReferenceChecker::checkDouble(double value, const char* id)
}
-void TestReferenceChecker::checkVector(const int value[3], const char* id)
+void TestReferenceChecker::checkVector(const BasicVector<int>& value, const char* id)
{
TestReferenceChecker compound(checkCompound(Impl::cVectorType, id));
compound.checkInteger(value[0], "X");
}
-void TestReferenceChecker::checkVector(const float value[3], const char* id)
+void TestReferenceChecker::checkVector(const BasicVector<float>& value, const char* id)
{
TestReferenceChecker compound(checkCompound(Impl::cVectorType, id));
compound.checkReal(value[0], "X");
}
-void TestReferenceChecker::checkVector(const double value[3], const char* id)
+void TestReferenceChecker::checkVector(const BasicVector<double>& value, const char* id)
{
TestReferenceChecker compound(checkCompound(Impl::cVectorType, id));
compound.checkReal(value[0], "X");
}
+void TestReferenceChecker::checkVector(const int value[3], const char* id)
+{
+ checkVector(BasicVector<int>(value), id);
+}
+
+
+void TestReferenceChecker::checkVector(const float value[3], const char* id)
+{
+ checkVector(BasicVector<float>(value), id);
+}
+
+
+void TestReferenceChecker::checkVector(const double value[3], const char* id)
+{
+ checkVector(BasicVector<double>(value), id);
+}
+
+
void TestReferenceChecker::checkAny(const Any& any, const char* id)
{
if (any.isType<bool>())