ProteoWizard
Functions | Variables
cvtest.cpp File Reference
#include "pwiz/utility/misc/unit.hpp"
#include "cv.hpp"
#include "pwiz/utility/misc/Std.hpp"
#include "boost/thread/thread.hpp"
#include "boost/thread/barrier.hpp"
#include <cstring>

Go to the source code of this file.

Functions

void test ()
 
void testIsA ()
 
void testOtherRelations ()
 
void testSynonyms ()
 
void testIDTranslation ()
 
void testPropertyValues ()
 
void testThreadSafetyWorker (boost::barrier *testBarrier)
 
void testThreadSafety (const int &testThreadCount)
 
int main (int argc, char *argv[])
 

Variables

ostream * os_ = 0
 

Function Documentation

void test ( )

Definition at line 39 of file cvtest.cpp.

References pwiz::cv::cvTermInfo(), pwiz::cv::CVTermInfo::def, MS_binary_data_compression_type, MS_contact_email, MS_instrument, MS_instrument_model, MS_None_____OBSOLETE, MS_polarity, MS_sample_number, MS_zlib_compression, pwiz::cv::CVTermInfo::name, os_, pwiz::cv::CVTermInfo::parentsIsA, pwiz::cv::CVTermInfo::parentsPartOf, and unit_assert.

40 {
41  if (os_)
42  {
43  *os_ << "name: " << cvTermInfo(MS_sample_number).name << endl
44  << "def: " << cvTermInfo(MS_sample_number).def << "\n\n";
45 
46  *os_ << "name: " << cvTermInfo(MS_polarity).name << endl
47  << "def: " << cvTermInfo(MS_polarity).def << endl;
48  }
49 
50  // some simple tests
51  unit_assert(cvTermInfo(MS_sample_number).name == "sample number");
52  unit_assert(cvTermInfo(MS_contact_email).name == "contact email");
53  unit_assert(cvTermInfo(MS_contact_email).def == "Email address of the contact person or organization.");
54 
55  unit_assert(cvTermInfo(MS_zlib_compression).parentsIsA.size() == 1 &&
57 
58  unit_assert(cvTermInfo(MS_instrument_model).parentsPartOf.size() == 1 &&
60 
62 }
void testIsA ( )
void testOtherRelations ( )

Definition at line 82 of file cvtest.cpp.

References pwiz::cv::cvTermInfo(), MS______KR_____P_, MS_accuracy, MS_m_z, MS_Trypsin, pwiz::cv::CVTermInfo::otherRelations, unit_assert, and UO_parts_per_million.

Referenced by testThreadSafetyWorker().

83 {
84  const CVTermInfo& info = cvTermInfo(MS_accuracy);
85  unit_assert(info.otherRelations.size() == 2);
86  unit_assert(info.otherRelations.begin()->first == "has_units");
87  unit_assert(info.otherRelations.begin()->second == MS_m_z);
88  unit_assert(info.otherRelations.rbegin()->first == "has_units");
89  unit_assert(info.otherRelations.rbegin()->second == UO_parts_per_million);
90 
91  const CVTermInfo& info2 = cvTermInfo(MS_Trypsin);
92  unit_assert(info2.otherRelations.size() == 1);
93  unit_assert(info2.otherRelations.begin()->first == "has_regexp");
94  unit_assert(info2.otherRelations.begin()->second == MS______KR_____P_);
95 }
void testSynonyms ( )

Definition at line 98 of file cvtest.cpp.

References CVID_Unknown, pwiz::cv::cvTermInfo(), pwiz::cv::CVTermInfo::exactSynonyms, MS_B, MS_chemical_ionization, MS_fourier_transform_ion_cyclotron_resonance_mass_spectrometer, MS_FT_ICR, MS_QIT, pwiz::cv::CVTermInfo::name, and unit_assert.

Referenced by testThreadSafetyWorker().

99 {
100  const CVTermInfo& info = cvTermInfo(MS_B);
101  unit_assert(info.name == "magnetic field strength");
102  unit_assert(info.exactSynonyms.size() == 1);
103  unit_assert(info.exactSynonyms[0] == "B");
104  unit_assert(cvTermInfo(MS_QIT).exactSynonyms.size() == 3);
105 
106  unit_assert(cvTermInfo(MS_chemical_ionization).shortName() == "CI");
107  unit_assert(cvTermInfo(MS_FT_ICR).shortName() == "FT_ICR");
109  unit_assert(cvTermInfo(CVID_Unknown).shortName() == "Unknown");
110 }
void testIDTranslation ( )

Definition at line 113 of file cvtest.cpp.

References CVID_Unknown, pwiz::cv::cvTermInfo(), MS_B, MS_peak_intensity, unit_assert, and UO_information_unit.

Referenced by testThreadSafetyWorker().

114 {
115  unit_assert(cvTermInfo("MS:1000025").cvid == MS_B);
116  unit_assert(cvTermInfo("MS:1000042").cvid == MS_peak_intensity);
117  unit_assert(cvTermInfo("UO:0000231").cvid == UO_information_unit);
118  unit_assert(cvTermInfo("XX:0000231").cvid == CVID_Unknown);
119  unit_assert(cvTermInfo("FOO:").cvid == CVID_Unknown);
120  unit_assert(cvTermInfo(":FOO").cvid == CVID_Unknown);
121  unit_assert(cvTermInfo("MS").cvid == CVID_Unknown);
122 }
void testPropertyValues ( )

Definition at line 125 of file cvtest.cpp.

References pwiz::cv::cvTermInfo(), pwiz::cv::CVTermInfo::propertyValues, UNIMOD_Phospho, and unit_assert_operator_equal.

Referenced by testThreadSafetyWorker().

126 {
128 
129  unit_assert_operator_equal(1, phospho.propertyValues.count("delta_composition"));
130  unit_assert_operator_equal("H O(3) P", phospho.propertyValues.find("delta_composition")->second);
131 
132  unit_assert_operator_equal(2, phospho.propertyValues.count("spec_1_site"));
133  unit_assert_operator_equal("T", phospho.propertyValues.equal_range("spec_1_site").first->second);
134  unit_assert_operator_equal("S", (--phospho.propertyValues.equal_range("spec_1_site").second)->second);
135 
136  unit_assert_operator_equal(1, phospho.propertyValues.count("spec_2_site"));
137  unit_assert_operator_equal("Y", phospho.propertyValues.find("spec_2_site")->second);
138 }
void testThreadSafetyWorker ( boost::barrier *  testBarrier)

Definition at line 141 of file cvtest.cpp.

References test(), testIDTranslation(), testIsA(), testOtherRelations(), testPropertyValues(), and testSynonyms().

142 {
143  testBarrier->wait(); // wait until all threads have started
144 
145  try
146  {
147  test();
148  testIsA();
150  testSynonyms();
153  }
154  catch (exception& e)
155  {
156  cerr << "Exception in worker thread: " << e.what() << endl;
157  }
158  catch (...)
159  {
160  cerr << "Unhandled exception in worker thread." << endl;
161  }
162 }
void testThreadSafety ( const int &  testThreadCount)

Definition at line 164 of file cvtest.cpp.

References testThreadSafetyWorker().

165 {
166  boost::barrier testBarrier(testThreadCount);
167  boost::thread_group testThreadGroup;
168  for (int i=0; i < testThreadCount; ++i)
169  testThreadGroup.add_thread(new boost::thread(&testThreadSafetyWorker, &testBarrier));
170  testThreadGroup.join_all();
171 }
int main ( int  argc,
char *  argv[] 
)

Definition at line 174 of file cvtest.cpp.

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

175 {
176  TEST_PROLOG(argc, argv)
177 
178  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
179 
180  try
181  {
182  //testThreadSafety(1); // does not test thread-safety of singleton initialization
183  testThreadSafety(2);
184  testThreadSafety(4);
185  testThreadSafety(8);
186  testThreadSafety(16);
187  }
188  catch (exception& e)
189  {
190  TEST_FAILED(e.what())
191  }
192  catch (...)
193  {
194  TEST_FAILED("Caught unknown exception.")
195  }
196 
198 }

Variable Documentation

ostream* os_ = 0

Definition at line 36 of file cvtest.cpp.