FileStore_T.cpp
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // This file is part of GNSSTk, the ARL:UT GNSS Toolkit.
4 //
5 // The GNSSTk is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published
7 // by the Free Software Foundation; either version 3.0 of the License, or
8 // any later version.
9 //
10 // The GNSSTk is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with GNSSTk; if not, write to the Free Software Foundation,
17 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 //
19 // This software was developed by Applied Research Laboratories at the
20 // University of Texas at Austin.
21 // Copyright 2004-2022, The Board of Regents of The University of Texas System
22 //
23 //==============================================================================
24 
25 //==============================================================================
26 //
27 // This software was developed by Applied Research Laboratories at the
28 // University of Texas at Austin, under contract to an agency or agencies
29 // within the U.S. Department of Defense. The U.S. Government retains all
30 // rights to use, duplicate, distribute, disclose, or release this software.
31 //
32 // Pursuant to DoD Directive 523024
33 //
34 // DISTRIBUTION STATEMENT A: This software has been approved for public
35 // release, distribution is unlimited.
36 //
37 //==============================================================================
38 
39 #include "FileStore.hpp"
40 #include "TestUtil.hpp"
41 #include <iostream>
42 
43 using namespace std;
44 using namespace gnsstk;
45 
47 {
48 public:
49 
50  // constructor
52 
53  // destructor
55 
56  // run all tests
57  // @return number of failures, i.e., 0=PASS, !0=FAIL
58  int testEverything();
59 
60 private:
61 
63  {
64  TestHeaderType(int i = 0) : value(i) {}
65  bool operator==(const TestHeaderType& other) const { return (other.value == value); }
66  void dump(std::ostream& os = std::cout) const { os << value << endl; }
67  int value;
68  };
69 
70  // emit a vector of strings to standard output
71  // @param strs vector of strings to emit
72  void dump(const vector<string>& strs);
73 
74 }; // class FileStore_T
75 
76 
77 //---------------------------------------------------------------------------
79 {
80  TestUtil initTester( "FileStore", "initialization", __FILE__, __LINE__ );
81  TestUtil sizeTester( "FileStore", "size", __FILE__, __LINE__ );
82  TestUtil nfilesTester( "FileStore", "nfiles", __FILE__, __LINE__ );
83  TestUtil clearTester( "FileStore", "clear", __FILE__, __LINE__ );
84  TestUtil getTester( "FileStore", "getFilenames", __FILE__, __LINE__ );
85  TestUtil addTester( "FileStore", "addFile", __FILE__, __LINE__ );
86  TestUtil headerTester( "FileStore", "getHeader", __FILE__, __LINE__ );
87 
88  try // default initialization
89  {
91  initTester.assert( true, "unexpected exception", __LINE__ );
92  }
93  catch (...)
94  {
95  initTester.assert( false, "unexpected exception", __LINE__ );
96  }
97 
98  FileStore<TestHeaderType> store; // Use this for the remaining tests
99 
100  try // empty store (size)
101  {
102  sizeTester.assert( (0 == store.size() ), "empty store expected", __LINE__ );
103  }
104  catch (...)
105  {
106  sizeTester.assert( false, "unexpected exception", __LINE__ );
107  }
108 
109  try // empty store (nfiles)
110  {
111  nfilesTester.assert( (0 == store.nfiles() ), "empty store expected", __LINE__ );
112  }
113  catch (...)
114  {
115  nfilesTester.assert( false, "unexpected exception", __LINE__ );
116  }
117 
118  try // empty store (getFilenames)
119  {
120  getTester.assert( (0 == store.getFileNames().size() ), "empty store expected", __LINE__ );
121  }
122  catch (...)
123  {
124  getTester.assert( false, "unexpected exception", __LINE__ );
125  }
126 
127  try // empty store (clear)
128  {
129  store.clear();
130  clearTester.assert( true, "unexpected exception", __LINE__ );
131  }
132  catch (...)
133  {
134  clearTester.assert( false, "unexpected exception", __LINE__ );
135  }
136 
137  try // empty store (getHeader)
138  {
139  const TestHeaderType& header = store.getHeader("filename");
140  headerTester.assert( false, "expected exception", __LINE__ );
141  }
142  catch (InvalidRequest& ire)
143  {
144  headerTester.assert( true, "expected exception", __LINE__ );
145  }
146  catch (...)
147  {
148  headerTester.assert( false, "unexpected exception", __LINE__ );
149  }
150 
151  try // empty store (addFile)
152  {
154  store.addFile("testfile1", header);
155 
156  addTester.assert( true, "unexpected exception", __LINE__ );
157  sizeTester.assert( (1 == store.size() ), "single file expected", __LINE__ );
158  nfilesTester.assert( (1 == store.nfiles() ), "single file expected", __LINE__ );
159 
160  std::vector<std::string> filenames = store.getFileNames();
161  getTester.assert( (1 == filenames.size() ), "single file expected", __LINE__ );
162  if (filenames.size() > 0)
163  {
164  getTester.assert( (0 == filenames[0].compare("testfile1") ), "unexpected filename", __LINE__ );
165  }
166  }
167  catch (...)
168  {
169  addTester.assert( false, "unexpected exception", __LINE__ );
170  }
171 
172  try // non-empty store (getHeader, present)
173  {
174  const TestHeaderType& header = store.getHeader("testfile1");
175  headerTester.assert( true, "unexpected exception", __LINE__ );
176  headerTester.assert( (1 == header.value), "unexpected header", __LINE__ );
177  }
178  catch (...)
179  {
180  headerTester.assert( false, "unexpected exception", __LINE__ );
181  }
182 
183  try // non-empty store (getHeader, absent)
184  {
185  const TestHeaderType& header = store.getHeader("foo");
186  headerTester.assert( false, "expected exception", __LINE__ );
187  }
188  catch (InvalidRequest& ire)
189  {
190  headerTester.assert( true, "expected exception", __LINE__ );
191  }
192  catch (...)
193  {
194  headerTester.assert( false, "unexpected exception", __LINE__ );
195  }
196 
197  try // non-empty store (addFile)
198  {
200  store.addFile("testfile2", header);
201 
202  addTester.assert( true, "unexpected exception", __LINE__ );
203  sizeTester.assert( (2 == store.size() ), "two files expected", __LINE__ );
204  nfilesTester.assert( (2 == store.nfiles() ), "two files expected", __LINE__ );
205 
206  std::vector<std::string> filenames = store.getFileNames();
207  getTester.assert( (2 == filenames.size() ), "two files expected", __LINE__ );
208  }
209  catch (...)
210  {
211  addTester.assert( false, "unexpected exception", __LINE__ );
212  }
213 
214  try // non-empty store (getHeader, present)
215  {
216  const TestHeaderType& header = store.getHeader("testfile2");
217  headerTester.assert( true, "unexpected exception", __LINE__ );
218  headerTester.assert( (2 == header.value), "unexpected header", __LINE__ );
219  }
220  catch (...)
221  {
222  headerTester.assert( false, "unexpected exception", __LINE__ );
223  }
224 
225  try // non-empty store (clear)
226  {
227  store.clear();
228  clearTester.assert( true, "unexpected exception", __LINE__ );
229  sizeTester.assert( (0 == store.size() ), "empty store expected", __LINE__ );
230  nfilesTester.assert( (0 == store.nfiles() ), "empty store expected", __LINE__ );
231  getTester.assert( (0 == store.getFileNames().size() ), "empty store expected", __LINE__ );
232  }
233  catch (...)
234  {
235  clearTester.assert( false, "unexpected exception", __LINE__ );
236  }
237 
238  return initTester.countFails() +
239  sizeTester.countFails() +
240  nfilesTester.countFails() +
241  clearTester.countFails() +
242  getTester.countFails() +
243  addTester.countFails() +
244  headerTester.countFails();
245 }
246 
247 
252 int main(int argc, char *argv[])
253 {
254  int errorTotal = 0;
255 
256  FileStore_T testClass;
257 
258  errorTotal += testClass.testEverything();
259 
260  cout << "Total Failures for " << __FILE__ << ": " << errorTotal << endl;
261 
262  return errorTotal;
263 }
gnsstk::dump
void dump(vector< SatPass > &SatPassList, ostream &os, bool rev, bool dbug)
Definition: SatPassUtilities.cpp:59
gnsstk::FileStore::addFile
void addFile(const std::string &fn, HeaderType &header)
Definition: FileStore.hpp:89
gnsstk::TestUtil::countFails
int countFails(void)
Definition: TestUtil.hpp:771
example3.header
header
Definition: example3.py:22
gnsstk::TestUtil::assert
void assert(bool testExpression, const std::string &testMsg, const int lineNumber)
Definition: TestUtil.hpp:607
FileStore_T::FileStore_T
FileStore_T()
Definition: FileStore_T.cpp:51
FileStore_T::~FileStore_T
~FileStore_T()
Definition: FileStore_T.cpp:54
gnsstk::FileStore::getFileNames
std::vector< std::string > getFileNames() const
Get a list of all the file names in the store, as a vector<string>
Definition: FileStore.hpp:78
FileStore.hpp
FileStore_T::TestHeaderType
Definition: FileStore_T.cpp:62
FileStore_T::TestHeaderType::value
int value
Definition: FileStore_T.cpp:67
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
TestUtil.hpp
FileStore_T::TestHeaderType::operator==
bool operator==(const TestHeaderType &other) const
Definition: FileStore_T.cpp:65
FileStore_T::testEverything
int testEverything()
Definition: FileStore_T.cpp:78
gnsstk::FileStore::clear
void clear() noexcept
Clear the contents of the (filename, header) map.
Definition: FileStore.hpp:134
main
int main(int argc, char *argv[])
Definition: FileStore_T.cpp:252
gnsstk::FileStore::nfiles
unsigned nfiles() const noexcept
Definition: FileStore.hpp:144
gnsstk::FileStore::getHeader
const HeaderType & getHeader(const std::string &fn) const
Definition: FileStore.hpp:101
std
Definition: Angle.hpp:142
gnsstk::FileStore::size
unsigned size() const noexcept
Return the size of the (filename,header) map.
Definition: FileStore.hpp:142
FileStore_T
Definition: FileStore_T.cpp:46
FileStore_T::TestHeaderType::TestHeaderType
TestHeaderType(int i=0)
Definition: FileStore_T.cpp:64
FileStore_T::TestHeaderType::dump
void dump(std::ostream &os=std::cout) const
Definition: FileStore_T.cpp:66
gnsstk::TestUtil
Definition: TestUtil.hpp:265
gnsstk::FileStore
Definition: FileStore.hpp:62


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:39