ProteoWizard
Functions | Variables
KwCVMapTest.cpp File Reference
#include "KwCVMap.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

void testCVMap ()
 
void testRegexCVMap ()
 
void testCVMapIO ()
 
void testRegexCVMapIO ()
 
void testVectorIO ()
 
void test ()
 
int main (int argc, char *argv[])
 

Variables

ostream * os_ = 0
 

Function Documentation

§ testCVMap()

void testCVMap ( )

Definition at line 35 of file KwCVMapTest.cpp.

References pwiz::identdata::CVMap::cvid, pwiz::identdata::CVMap::keyword, MS_sample_name, os_, and unit_assert.

Referenced by test().

36 {
37  if (os_) (*os_) << "\ntestCVMap()\n";
38 
39  CVMap map("sample name", MS_sample_name,
40  "/mzIdentML/AnalysisSampleCollection/Sample/cvParam");
41 
42  unit_assert(map.keyword == "sample name");
43  unit_assert(map.cvid == MS_sample_name);
44  unit_assert(map("sample name"));
45  unit_assert(!map("potato"));
46 }
MS_sample_name
sample name: A reference string relevant to the sample under study.
Definition: cv.hpp:106
ostream * os_
Definition: KwCVMapTest.cpp:32
#define unit_assert(x)
Definition: unit.hpp:85

§ testRegexCVMap()

void testRegexCVMap ( )

Definition at line 48 of file KwCVMapTest.cpp.

References pwiz::identdata::CVMap::cvid, MS_sample_name, os_, and unit_assert.

Referenced by test().

49 {
50  if (os_) (*os_) << "\ntestRegexCVMap()\n";
51 
52  RegexCVMap rx("[Ss]ample[ ]+[Nn]ame", MS_sample_name,
53  "/mzIdentML/AnalysisSampleCollection/Sample/cvParam");
54 
55  //unit_assert(map.keyword == "sample name");
56  unit_assert(rx.cvid == MS_sample_name);
57  unit_assert(rx("sample name"));
58  unit_assert(rx("Sample name"));
59  unit_assert(rx("sample Name"));
60  unit_assert(rx("Sample Name"));
61  unit_assert(!rx("turnip"));
62 }
MS_sample_name
sample name: A reference string relevant to the sample under study.
Definition: cv.hpp:106
ostream * os_
Definition: KwCVMapTest.cpp:32
#define unit_assert(x)
Definition: unit.hpp:85

§ testCVMapIO()

void testCVMapIO ( )

Definition at line 64 of file KwCVMapTest.cpp.

References MS_sample_name, os_, and unit_assert.

Referenced by test().

65 {
66  if (os_) (*os_) << "\ntestCVMapIO()\n";
67 
68  CVMap map("sample name", MS_sample_name,
69  "/mzIdentML/AnalysisSampleCollection/Sample/cvParam");
70  stringstream ss;
71 
72  ss << map;
73 
74  if (os_) (*os_) << "insertion operator:\n" << ss.str();
75  unit_assert(ss.str() == "plain\tsample name\tMS:1000002"
76  "\t/mzIdentML/AnalysisSampleCollection/Sample/cvParam\n");
77 
78  // Test CVMapPtr extraction
79  CVMapPtr cvmPtr;
80  ss >> cvmPtr;
81 
82  if (os_) (*os_) << "NULL pointer returned?"
83  << (cvmPtr.get() == NULL) << endl;
84  unit_assert(cvmPtr.get());
85 
86  if (os_) (*os_) << typeid(cvmPtr.get()).name() << endl;
87  unit_assert(typeid(cvmPtr.get()).name() == typeid(CVMap*).name());
88 
89  if (os_) (*os_) << "keyword: " << cvmPtr->keyword << endl;
90  if (os_) (*os_) << "cvid: " << cvmPtr->cvid << endl;
91  unit_assert(cvmPtr->keyword == "sample name");
92  unit_assert(cvmPtr->cvid == MS_sample_name);
93 }
MS_sample_name
sample name: A reference string relevant to the sample under study.
Definition: cv.hpp:106
boost::shared_ptr< CVMap > CVMapPtr
Definition: KwCVMap.hpp:58
ostream * os_
Definition: KwCVMapTest.cpp:32
#define unit_assert(x)
Definition: unit.hpp:85

§ testRegexCVMapIO()

void testRegexCVMapIO ( )

Definition at line 95 of file KwCVMapTest.cpp.

References MS_sample_name, os_, and unit_assert.

Referenced by test().

96 {
97  if (os_) (*os_) << "\ntestRegexCVMapIO()\n";
98 
99  RegexCVMap map("[Ss]ample [Nn]ame", MS_sample_name,
100  "/mzIdentML/AnalysisSampleCollection/Sample/cvParam");
101  stringstream ss;
102 
103  ss << map;
104 
105  if (os_) (*os_) << "insertion operator:\n" << ss.str();
106  unit_assert(ss.str() == "regex\t[Ss]ample [Nn]ame\tMS:1000002\t"
107  "/mzIdentML/AnalysisSampleCollection/Sample/cvParam\n");
108 
109  // Test CVMapPtr extraction
110  CVMapPtr cvmPtr;
111  ss >> cvmPtr;
112 
113  if (os_) (*os_) << "NULL pointer returned?"
114  << (cvmPtr.get() == NULL) << endl;
115  unit_assert(cvmPtr.get());
116 
117  if (os_) (*os_) << typeid(cvmPtr.get()).name() << endl;
118  unit_assert(typeid(cvmPtr.get()).name() == typeid(CVMap*).name());
119 
120  if (os_) (*os_) << "keyword: " << cvmPtr->keyword << endl;
121  if (os_) (*os_) << "cvid: " << cvmPtr->cvid << endl;
122  unit_assert(cvmPtr->keyword == "[Ss]ample [Nn]ame");
123  unit_assert(cvmPtr->cvid == MS_sample_name);
124 }
MS_sample_name
sample name: A reference string relevant to the sample under study.
Definition: cv.hpp:106
boost::shared_ptr< CVMap > CVMapPtr
Definition: KwCVMap.hpp:58
ostream * os_
Definition: KwCVMapTest.cpp:32
#define unit_assert(x)
Definition: unit.hpp:85

§ testVectorIO()

void testVectorIO ( )

Definition at line 126 of file KwCVMapTest.cpp.

References os_, and unit_assert.

Referenced by test().

127 {
128  if (os_) (*os_) << "\ntestVectorIO()\n";
129 
130  const char* file =
131  "plain\tsample name\tMS:1000002\t/mzIdentML/AnalysisSampleCollection/Sample/cvParam\n"
132  "regex\t[Aa]ccuracy[ ]*\tMS:1000014\t/mzIdentML\n"
133  "regex\t[Ss]can start time[\\.]?\tMS:1000016\t/mzIdentML\n";
134 
135  if (os_) (*os_) << "file used:\n" << file << endl;
136  istringstream iss(file);
137 
138  vector<CVMapPtr> mappings;
139  iss >> mappings;
140 
141  if (os_) (*os_) << "Records read in:\n";
142  for (vector<CVMapPtr>::iterator i=mappings.begin(); i!=mappings.end(); i++)
143  {
144  if (os_) (*os_) << *i;
145  }
146 
147  // TODO add some record specific checking here.
148 
149  ostringstream oss;
150 
151  oss << mappings;
152 
153  if (os_) (*os_) << "\nResulting vector output:\n";
154  if (os_) (*os_) << oss.str() << endl;
155  unit_assert(oss.str() == file);
156 }
ostream * os_
Definition: KwCVMapTest.cpp:32
#define unit_assert(x)
Definition: unit.hpp:85

§ test()

void test ( )

Definition at line 158 of file KwCVMapTest.cpp.

References testCVMap(), testCVMapIO(), testRegexCVMap(), testRegexCVMapIO(), and testVectorIO().

Referenced by main().

159 {
160  testCVMap();
161  testRegexCVMap();
162  testCVMapIO();
164  testVectorIO();
165 }
void testVectorIO()
void testCVMap()
Definition: KwCVMapTest.cpp:35
void testRegexCVMap()
Definition: KwCVMapTest.cpp:48
void testRegexCVMapIO()
Definition: KwCVMapTest.cpp:95
void testCVMapIO()
Definition: KwCVMapTest.cpp:64

§ main()

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

Definition at line 167 of file KwCVMapTest.cpp.

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

168 {
169  TEST_PROLOG(argc, argv)
170 
171  try
172  {
173  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
174  test();
175  }
176  catch (exception& e)
177  {
178  TEST_FAILED(e.what())
179  }
180  catch (...)
181  {
182  TEST_FAILED("Caught unknown exception.")
183  }
184 
186 }
#define TEST_EPILOG
Definition: unit.hpp:182
void test()
#define TEST_FAILED(x)
Definition: unit.hpp:176
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:174
ostream * os_
Definition: KwCVMapTest.cpp:32

Variable Documentation

§ os_

ostream* os_ = 0