Nektar++
Loading...
Searching...
No Matches
TestFile.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: TestFile.cpp
4//
5// For more information, please see: http://www.nektar.info
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description: Encapsulation of test XML file.
32//
33///////////////////////////////////////////////////////////////////////////////
34
35#include <boost/algorithm/string.hpp>
36#include <boost/core/ignore_unused.hpp>
37
38#include <TestException.hpp>
39#include <TestFile.h>
40
41using namespace std;
42
43namespace Nektar
44{
45
46/**
47 * @brief TestData constructor.
48 *
49 * The class is constructed with the path to the test XML file and a
50 * `po::variables_map` object containing the command-line options passed to the
51 * program.
52 *
53 * @param pFilename
54 * @param pVm
55 */
56
57TestFile::TestFile(const fs::path &pFilename, po::variables_map &pVm)
58 : m_cmdoptions(pVm)
59{
60 // Process test file format.
61 m_doc = new TiXmlDocument(pFilename.string().c_str());
62
63 bool loadOkay = m_doc->LoadFile();
64
65 ASSERTL0(loadOkay,
66 "Failed to load test definition file: " + pFilename.string() +
67 "\n" + string(m_doc->ErrorDesc()));
68
69 Parse(m_doc);
70}
71
73{
74 boost::ignore_unused(pSrc);
75}
76
77/// Parse the test file and populate member variables for the test.
78void TestFile::Parse(TiXmlDocument *pDoc)
79{
80 TiXmlHandle handle(pDoc);
81 TiXmlElement *tmp, *testElement;
82
83 // Check to see whether the .tst file includes multiple <test> elements
84 // contained within the root document.
85 tmp = handle.FirstChildElement("tests").Element();
86 if (tmp)
87 {
88 testElement = tmp->FirstChildElement("test");
89 }
90 else
91 {
92 testElement = handle.FirstChildElement("test").Element();
93 }
94
95 ASSERTL0(testElement, "Cannot find 'test' or 'tests' root element.");
96
97 while (testElement)
98 {
99 m_tests.push_back(new TestData(testElement, m_cmdoptions));
100 testElement = testElement->NextSiblingElement("test");
101 }
102}
103
105{
106 m_doc->SaveFile();
107}
108
109} // namespace Nektar
#define ASSERTL0(condition, msg)
The TestData class is responsible for parsing a test XML file and storing the data.
Definition TestData.h:79
The TestData class is responsible for parsing a test XML file and storing the data.
Definition TestFile.h:59
TestFile(const fs::path &pFilename, po::variables_map &pVm)
TestData constructor.
Definition TestFile.cpp:57
std::vector< TestData * > m_tests
Vector of one or more tests to run.
Definition TestFile.h:78
TiXmlDocument * m_doc
Definition TestFile.h:75
po::variables_map m_cmdoptions
Definition TestFile.h:74
void Parse(TiXmlDocument *pDoc)
Parse the test file and populate member variables for the test.
Definition TestFile.cpp:78
STL namespace.