ProteoWizard
Functions | Variables
IOTest.cpp File Reference
#include "IO.hpp"
#include "Diff.hpp"
#include "examples.hpp"
#include "pwiz/utility/misc/unit.hpp"
#include "pwiz/utility/misc/Std.hpp"

Go to the source code of this file.

Functions

template<typename object_type >
void testObject (const object_type &a)
 
void testCV ()
 
void testUserParam ()
 
void testCVParam ()
 
template<typename object_type >
void testNamedParamContainer ()
 
void testSoftware ()
 
void testTraData ()
 
void test ()
 
int main (int argc, char *argv[])
 

Variables

ostream * os_ = 0
 

Function Documentation

§ testObject()

template<typename object_type >
void testObject ( const object_type &  a)

Definition at line 40 of file IOTest.cpp.

References diff(), os_, pwiz::identdata::IO::read(), unit_assert, and pwiz::identdata::IO::write().

41 {
42  if (os_) *os_ << "testObject(): " << typeid(a).name() << endl;
43 
44  // write 'a' out to a stream
45 
46  ostringstream oss;
47  XMLWriter writer(oss);
48  IO::write(writer, a);
49  if (os_) *os_ << oss.str() << endl;
50 
51  // read 'b' in from stream
52 
53  object_type b;
54  istringstream iss(oss.str());
55  IO::read(iss, b);
56 
57  // compare 'a' and 'b'
58 
60  if (diff && os_) *os_ << "diff:\n" << diff << endl;
61  unit_assert(!diff);
62 
63 
64 }
The XMLWriter class provides simple, tag-level XML syntax writing.
Definition: XMLWriter.hpp:47
Calculate diffs of objects in a ProteoWizard data model hierarchy.
Definition: diff_std.hpp:142
void diff(const string &filename1, const string &filename2)
PWIZ_API_DECL void write(minimxml::XMLWriter &writer, const CV &cv)
PWIZ_API_DECL void read(std::istream &is, CV &cv)
ostream * os_
Definition: IOTest.cpp:38
#define unit_assert(x)
Definition: unit.hpp:85

§ testCV()

void testCV ( )

Definition at line 67 of file IOTest.cpp.

References pwiz::cv::CV::fullName, pwiz::cv::CV::id, testObject(), pwiz::cv::CV::URI, and pwiz::cv::CV::version.

68 {
69  CV a;
70  a.URI = "abcd";
71  a.id = "efgh";
72  a.fullName = "ijkl";
73  a.version = "mnop";
74 
75  testObject(a);
76 }
std::string id
the short label to be used as a reference tag with which to refer to this particular Controlled Vocab...
Definition: cv.hpp:13356
void testObject(const object_type &a)
Definition: IOTest.cpp:41
Information about an ontology or CV source and a short &#39;lookup&#39; tag to refer to.
Definition: cv.hpp:13353
std::string fullName
the usual name for the resource (e.g. The PSI-MS Controlled Vocabulary).
Definition: cv.hpp:13362
std::string URI
the URI for the resource.
Definition: cv.hpp:13359
std::string version
the version of the CV from which the referred-to terms are drawn.
Definition: cv.hpp:13365

§ testUserParam()

void testUserParam ( )

Definition at line 79 of file IOTest.cpp.

References pwiz::data::UserParam::name, testObject(), pwiz::data::UserParam::type, pwiz::data::UserParam::units, UO_minute, and pwiz::data::UserParam::value.

80 {
81  UserParam a;
82  a.name = "abcd";
83  a.value = "efgh";
84  a.type = "ijkl";
85  a.units = UO_minute;
86 
87  testObject(a);
88 }
void testObject(const object_type &a)
Definition: IOTest.cpp:41
std::string value
the value for the parameter, where appropriate.
Definition: ParamTypes.hpp:191
Uncontrolled user parameters (essentially allowing free text). Before using these, one should verify whether there is an appropriate CV term available, and if so, use the CV term instead.
Definition: ParamTypes.hpp:185
std::string type
the datatype of the parameter, where appropriate (e.g.: xsd:float).
Definition: ParamTypes.hpp:194
std::string name
the name for the parameter.
Definition: ParamTypes.hpp:188
UO_minute
minute: A time unit which is equal to 60 seconds.
Definition: cv.hpp:12589
CVID units
an optional CV parameter for the unit term associated with the value, if any (e.g. MS_electron_volt).
Definition: ParamTypes.hpp:197

§ testCVParam()

void testCVParam ( )

Definition at line 91 of file IOTest.cpp.

References MS_m_z, MS_selected_ion_m_z, testObject(), and UO_second.

92 {
93  CVParam a(MS_selected_ion_m_z, "810.48", MS_m_z);
94  testObject(a);
95 
96  CVParam b(UO_second, "123.45");
97  testObject(b);
98 }
void testObject(const object_type &a)
Definition: IOTest.cpp:41
UO_second
second: A time unit which is equal to the duration of 9 192 631 770 periods of the radiation correspo...
Definition: cv.hpp:12526
MS_selected_ion_m_z
selected ion m/z: Mass-to-charge ratio of an selected ion.
Definition: cv.hpp:2749
MS_m_z
m/z: Three-character symbol m/z is used to denote the quantity formed by dividing the mass of an ion ...
Definition: cv.hpp:223
represents a tag-value pair, where the tag comes from the controlled vocabulary
Definition: ParamTypes.hpp:44

§ testNamedParamContainer()

template<typename object_type >
void testNamedParamContainer ( )

Definition at line 102 of file IOTest.cpp.

References MS_ionization_type, MS_m_z, MS_selected_ion_m_z, and testObject().

103 {
104  object_type a;
105  a.userParams.push_back(UserParam("goober", "goo", "peanuts"));
106  a.cvParams.push_back(CVParam(MS_ionization_type, "420"));
107  a.cvParams.push_back(CVParam(MS_selected_ion_m_z, "666", MS_m_z));
108  testObject(a);
109 }
void testObject(const object_type &a)
Definition: IOTest.cpp:41
MS_selected_ion_m_z
selected ion m/z: Mass-to-charge ratio of an selected ion.
Definition: cv.hpp:2749
Uncontrolled user parameters (essentially allowing free text). Before using these, one should verify whether there is an appropriate CV term available, and if so, use the CV term instead.
Definition: ParamTypes.hpp:185
MS_m_z
m/z: Three-character symbol m/z is used to denote the quantity formed by dividing the mass of an ion ...
Definition: cv.hpp:223
MS_ionization_type
ionization type: The method by which gas phase ions are generated from the sample.
Definition: cv.hpp:124
represents a tag-value pair, where the tag comes from the controlled vocabulary
Definition: ParamTypes.hpp:44

§ testSoftware()

void testSoftware ( )

Definition at line 112 of file IOTest.cpp.

References pwiz::tradata::Software::id, MS_ionization_type, pwiz::data::ParamContainer::set(), testObject(), and pwiz::tradata::Software::version.

113 {
114  Software a;
115  a.id = "goober";
117  a.version = "4.20";
118  testObject(a);
119 }
void testObject(const object_type &a)
Definition: IOTest.cpp:41
std::string version
Version of the software program described.
Definition: TraData.hpp:76
std::string id
Identifier for the software to be used for referencing within a document.
Definition: TraData.hpp:73
MS_ionization_type
ionization type: The method by which gas phase ions are generated from the sample.
Definition: cv.hpp:124
void set(CVID cvid, const std::string &value="", CVID units=CVID_Unknown)
set/add a CVParam (not recursive)

§ testTraData()

void testTraData ( )

Definition at line 166 of file IOTest.cpp.

References diff(), pwiz::identdata::examples::initializeTiny(), os_, pwiz::identdata::IO::read(), unit_assert, and pwiz::identdata::IO::write().

Referenced by test().

167 {
168  if (os_) *os_ << "testTraData():\n";
169 
170  TraData a;
172 
173  // write 'a' out to a stream
174 
175  ostringstream oss;
176  XMLWriter writer(oss);
177  IO::write(writer, a);
178  if (os_) *os_ << oss.str() << endl;
179 
180  // read 'b' in from stream
181 
182  TraData b;
183  istringstream iss(oss.str());
184  IO::read(iss, b);
185 
186  // compare 'a' and 'b'
187 
189  if (diff && os_) *os_ << "diff:\n" << diff << endl;
190  unit_assert(!diff);
191 }
The XMLWriter class provides simple, tag-level XML syntax writing.
Definition: XMLWriter.hpp:47
Calculate diffs of objects in a ProteoWizard data model hierarchy.
Definition: diff_std.hpp:142
void diff(const string &filename1, const string &filename2)
PWIZ_API_DECL void write(minimxml::XMLWriter &writer, const CV &cv)
PWIZ_API_DECL void read(std::istream &is, CV &cv)
PWIZ_API_DECL void initializeTiny(IdentData &mzid)
ostream * os_
Definition: IOTest.cpp:38
#define unit_assert(x)
Definition: unit.hpp:85

§ test()

void test ( )

Definition at line 194 of file IOTest.cpp.

References testCV(), testCVParam(), testTraData(), and testUserParam().

195 {
196  testCV();
197  testUserParam();
198  testCVParam();
199  //testNamedParamContainer<Contact>();
200  //testNamedParamContainer<Publication>();
201  /*testInstrument();
202  testConfiguration();
203  testPrecursor();
204  testProduct();*/
205  testTraData();
206 }
void testUserParam()
Definition: IOTest.cpp:158
void testCV()
Definition: IOTest.cpp:93
void testCVParam()
Definition: IOTest.cpp:170
void testTraData()
Definition: IOTest.cpp:166

§ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 209 of file IOTest.cpp.

References os_, test(), TEST_EPILOG, TEST_FAILED, and TEST_PROLOG_EX.

210 {
211  TEST_PROLOG_EX(argc, argv, "_TraData")
212 
213  try
214  {
215  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
216  test();
217  }
218  catch (exception& e)
219  {
220  TEST_FAILED(e.what())
221  }
222  catch (...)
223  {
224  TEST_FAILED("Caught unknown exception.")
225  }
226 
228 }
#define TEST_EPILOG
Definition: unit.hpp:182
#define TEST_PROLOG_EX(argc, argv, suffix)
Definition: unit.hpp:157
#define TEST_FAILED(x)
Definition: unit.hpp:176
ostream * os_
Definition: IOTest.cpp:38
void test()
Definition: IOTest.cpp:860

Variable Documentation

§ os_

ostream* os_ = 0

Definition at line 36 of file IOTest.cpp.