ProteoWizard
IOTest.cpp
Go to the documentation of this file.
1 //
2 // $Id$
3 //
4 //
5 // Original author: Matt Chambers <matt.chambers .@. vanderbilt.edu>
6 //
7 // Copyright 2009 Vanderbilt University - Nashville, TN 37232
8 //
9 // Licensed under the Apache License, Version 2.0 (the "License");
10 // you may not use this file except in compliance with the License.
11 // You may obtain a copy of the License at
12 //
13 // http://www.apache.org/licenses/LICENSE-2.0
14 //
15 // Unless required by applicable law or agreed to in writing, software
16 // distributed under the License is distributed on an "AS IS" BASIS,
17 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 // See the License for the specific language governing permissions and
19 // limitations under the License.
20 //
21 
22 
23 #include "IO.hpp"
24 #include "Diff.hpp"
25 #include "examples.hpp"
28 
29 using namespace pwiz::cv;
30 using namespace pwiz::util;
31 using namespace pwiz::minimxml;
32 using namespace pwiz::tradata;
33 using boost::iostreams::stream_offset;
34 
35 
36 ostream* os_ = 0;
37 
38 
39 template <typename object_type>
40 void testObject(const object_type& a)
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 }
65 
66 
67 void testCV()
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 }
77 
78 
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 }
89 
90 
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 }
99 
100 
101 template <typename object_type>
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 }
110 
111 
113 {
114  Software a;
115  a.id = "goober";
117  a.version = "4.20";
118  testObject(a);
119 }
120 
121 
122 /*void testInstrument()
123 {
124  Instrument a;
125  a.id = "LCQ Deca";
126  a.cvParams.push_back(MS_LCQ_Deca);
127  a.cvParams.push_back(CVParam(MS_instrument_serial_number, 23433));
128  testObject(a);
129 }
130 
131 void testConfiguration()
132 {
133  Configuration a;
134  a.instrumentPtr = "LCA Deca";
135  a.contactPtr = "Bob";
136  a.cvParams.push_back(CVParam(MS_ionization_type, "420"));
137 }*/
138 
139 
140 /*void testPrecursor()
141 {
142  Precursor a;
143  a.mz = 123.45;
144  a.charge = 2;
145  testObject(a);
146 
147  Precursor b;
148  b.mz = 456.78;
149  testObject(b);
150 }
151 
152 
153 void testProduct()
154 {
155  Product a;
156  a.mz = 123.45;
157  a.charge = 2;
158  testObject(a);
159 
160  Product b;
161  b.mz = 456.78;
162  testObject(b);
163 }*/
164 
165 
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 }
192 
193 
194 void test()
195 {
196  testCV();
197  testUserParam();
198  testCVParam();
199  //testNamedParamContainer<Contact>();
200  //testNamedParamContainer<Publication>();
201  /*testInstrument();
202  testConfiguration();
203  testPrecursor();
204  testProduct();*/
205  testTraData();
206 }
207 
208 
209 int main(int argc, char* argv[])
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 }
229 
pwiz::data::UserParam
Uncontrolled user parameters (essentially allowing free text). Before using these,...
Definition: ParamTypes.hpp:186
pwiz::cv::CV::fullName
std::string fullName
the usual name for the resource (e.g. The PSI-MS Controlled Vocabulary).
Definition: cv.hpp:14924
pwiz::minimxml::XMLWriter
The XMLWriter class provides simple, tag-level XML syntax writing.
Definition: XMLWriter.hpp:48
pwiz::data::UserParam::type
std::string type
the datatype of the parameter, where appropriate (e.g.: xsd:float).
Definition: ParamTypes.hpp:194
testSoftware
void testSoftware()
Definition: IOTest.cpp:264
pwiz::cv::CV
Information about an ontology or CV source and a short 'lookup' tag to refer to.
Definition: cv.hpp:14916
pwiz::cv::CV::URI
std::string URI
the URI for the resource.
Definition: cv.hpp:14921
pwiz::cv
Definition: cv.hpp:108
pwiz::tradata::Software::id
std::string id
Identifier for the software to be used for referencing within a document.
Definition: TraData.hpp:73
testCVParam
void testCVParam()
Definition: IOTest.cpp:170
testTraData
void testTraData()
Definition: IOTest.cpp:166
pwiz::cv::CV::id
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:14918
pwiz::data::UserParam::units
CVID units
an optional CV parameter for the unit term associated with the value, if any (e.g....
Definition: ParamTypes.hpp:197
pwiz::cv::CV::version
std::string version
the version of the CV from which the referred-to terms are drawn.
Definition: cv.hpp:14927
UO_second
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:13833
MS_ionization_type
MS_ionization_type
ionization type: The method by which gas phase ions are generated from the sample.
Definition: cv.hpp:285
pwiz::identdata::IO::write
PWIZ_API_DECL void write(minimxml::XMLWriter &writer, const CV &cv)
pwiz::tradata::Software::version
std::string version
Version of the software program described.
Definition: TraData.hpp:76
pwiz::data::Diff
Calculate diffs of objects in a ProteoWizard data model hierarchy.
Definition: diff_std.hpp:143
pwiz::util
Definition: almost_equal.hpp:33
pwiz::tradata::TraData
Definition: TraData.hpp:351
TEST_EPILOG
#define TEST_EPILOG
Definition: unit.hpp:183
examples.hpp
os_
ostream * os_
Definition: IOTest.cpp:38
Std.hpp
diff
void diff(const string &filename1, const string &filename2)
Definition: FrequencyDataTest.cpp:40
testCV
void testCV()
Definition: IOTest.cpp:93
pwiz::identdata::examples::initializeTiny
PWIZ_API_DECL void initializeTiny(IdentData &mzid)
test
void test()
Definition: IOTest.cpp:860
pwiz::data::UserParam::value
std::string value
the value for the parameter, where appropriate.
Definition: ParamTypes.hpp:191
pwiz::minimxml
Definition: SAXParser.hpp:43
pwiz::tradata::Software
Definition: TraData.hpp:71
testObject
void testObject(const object_type &a)
Definition: IOTest.cpp:41
MS_selected_ion_m_z
MS_selected_ion_m_z
selected ion m/z: Mass-to-charge ratio of an selected ion.
Definition: cv.hpp:2901
TEST_FAILED
#define TEST_FAILED(x)
Definition: unit.hpp:177
pwiz::data::ParamContainer::set
void set(CVID cvid, const std::string &value="", CVID units=CVID_Unknown)
set/add a CVParam (not recursive)
MS_m_z
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:384
main
int main(int argc, char *argv[])
Definition: IOTest.cpp:910
testNamedParamContainer
void testNamedParamContainer()
Definition: IOTest.cpp:192
TEST_PROLOG_EX
#define TEST_PROLOG_EX(argc, argv, suffix)
Definition: unit.hpp:157
testUserParam
void testUserParam()
Definition: IOTest.cpp:158
Diff.hpp
unit.hpp
unit_assert
#define unit_assert(x)
Definition: unit.hpp:85
UO_minute
UO_minute
minute: A time unit which is equal to 60 seconds.
Definition: cv.hpp:13896
pwiz::data::CVParam
represents a tag-value pair, where the tag comes from the controlled vocabulary
Definition: ParamTypes.hpp:45
pwiz::tradata
Definition: DefaultReaderList.hpp:32
pwiz::identdata::IO::read
PWIZ_API_DECL void read(std::istream &is, CV &cv)
pwiz::data::UserParam::name
std::string name
the name for the parameter.
Definition: ParamTypes.hpp:188
IO.hpp