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

§ test()

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_regular_expressions_for_a_GUID, MS_sample_number, MS_scan_polarity, MS_zlib_compression, pwiz::cv::CVTermInfo::name, os_, pwiz::cv::CVTermInfo::parentsIsA, pwiz::cv::CVTermInfo::parentsPartOf, and unit_assert.

Referenced by testThreadSafetyWorker().

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_scan_polarity).name << endl
47  << "def: " << cvTermInfo(MS_scan_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 
63  unit_assert(cvTermInfo(MS_regular_expressions_for_a_GUID).def == "([A-Fa-f0-9]\\{8\\}-([A-Fa-f0-9]\\{4\\}-)\\{3\\}[A-Fa-f0-9]\\{12\\}).");
64 }
ostream * os_
Definition: cvtest.cpp:36
MS_instrument
instrument: Description of the instrument or the mass spectrometer.
Definition: cv.hpp:1831
PWIZ_API_DECL const CVTermInfo & cvTermInfo(CVID cvid)
returns CV term info for the specified CVID
MS_None____OBSOLETE
None ??: None.
Definition: cv.hpp:469
MS_binary_data_compression_type
binary data compression type: Compression Type.
Definition: cv.hpp:2173
std::string def
Definition: cv.hpp:13386
MS_contact_email
contact email: Email address of the contact person or organization.
Definition: cv.hpp:2266
MS_regular_expressions_for_a_GUID
).
Definition: cv.hpp:6982
id_list parentsIsA
Definition: cv.hpp:13390
id_list parentsPartOf
Definition: cv.hpp:13391
std::string name
Definition: cv.hpp:13385
MS_instrument_model
instrument model: Instrument model name not including the vendor&#39;s name.
Definition: cv.hpp:196
MS_sample_number
sample number: A reference number relevant to the sample under study.
Definition: cv.hpp:103
MS_zlib_compression
zlib compression: Zlib.
Definition: cv.hpp:2179
MS_scan_polarity
scan polarity: An acquisition mode to which specifies weather polarity is negative, positive or alternating.
Definition: cv.hpp:1840
#define unit_assert(x)
Definition: unit.hpp:85

§ testIsA()

void testIsA ( )

Definition at line 67 of file cvtest.cpp.

References pwiz::cv::cvIsA(), MS_FT_ICR, MS_ion_trap, MS_linear_ion_trap, MS_m_z, MS_mass_analyzer_type, MS_radial_ejection_linear_ion_trap, unit_assert, UO_dalton, UO_energy_unit, UO_mass_unit, and UO_unit.

Referenced by testThreadSafetyWorker().

68 {
81 }
MS_FT_ICR
FT_ICR (fourier transform ion cyclotron resonance mass spectrometer): A mass spectrometer based on th...
Definition: cv.hpp:376
MS_radial_ejection_linear_ion_trap
radial ejection linear ion trap: A linear ion trap mass spectrometer where ions are ejected along the...
Definition: cv.hpp:397
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
UO_mass_unit
mass unit: A unit which is a standard measure of the amount of matter/energy of a physical object...
Definition: cv.hpp:12502
UO_dalton
dalton: An independently to the base SI units defined mass unit which is equal to one twelfth of the ...
Definition: cv.hpp:13153
UO_unit
unit: A unit of measurement is a standardized quantity of a physical quality.
Definition: cv.hpp:12496
MS_mass_analyzer_type
mass analyzer type: Mass analyzer separates the ions according to their mass-to-charge ratio...
Definition: cv.hpp:1759
UO_energy_unit
energy unit: A unit which is a standard measure of the work done by a certain force (gravitational...
Definition: cv.hpp:12829
MS_linear_ion_trap
linear ion trap: A two dimensional Paul ion trap in which ions are confined in the axial dimension by...
Definition: cv.hpp:1282
MS_ion_trap
ion trap: A device for spatially confining ions using electric and magnetic fields alone or in combin...
Definition: cv.hpp:1126
#define unit_assert(x)
Definition: unit.hpp:85
PWIZ_API_DECL bool cvIsA(CVID child, CVID parent)
returns true iff child IsA parent in the CV

§ testOtherRelations()

void testOtherRelations ( )

Definition at line 84 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().

85 {
86  const CVTermInfo& info = cvTermInfo(MS_accuracy);
87  unit_assert(info.otherRelations.size() == 2);
88  unit_assert(info.otherRelations.begin()->first == "has_units");
89  unit_assert(info.otherRelations.begin()->second == MS_m_z);
90  unit_assert(info.otherRelations.rbegin()->first == "has_units");
91  unit_assert(info.otherRelations.rbegin()->second == UO_parts_per_million);
92 
93  const CVTermInfo& info2 = cvTermInfo(MS_Trypsin);
94  unit_assert(info2.otherRelations.size() == 1);
95  unit_assert(info2.otherRelations.begin()->first == "has_regexp");
96  unit_assert(info2.otherRelations.begin()->second == MS______KR_____P_);
97 }
PWIZ_API_DECL const CVTermInfo & cvTermInfo(CVID cvid)
returns CV term info for the specified CVID
MS______KR_____P_
(?<=[KR])(?!P): Regular expression for Trypsin.
Definition: cv.hpp:3835
MS_Trypsin
Trypsin: Enzyme trypsin.
Definition: cv.hpp:4027
UO_parts_per_million
parts per million: A dimensionless concentration notation which denotes the amount of a given substan...
Definition: cv.hpp:12997
MS_accuracy
accuracy: Accuracy is the degree of conformity of a measured mass to its actual value.
Definition: cv.hpp:142
structure for holding CV term info
Definition: cv.hpp:13381
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
std::multimap< std::string, CVID > otherRelations
Definition: cv.hpp:13392
#define unit_assert(x)
Definition: unit.hpp:85

§ testSynonyms()

void testSynonyms ( )

Definition at line 100 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().

101 {
102  const CVTermInfo& info = cvTermInfo(MS_B);
103  unit_assert(info.name == "magnetic field strength");
104  unit_assert(info.exactSynonyms.size() == 1);
105  unit_assert(info.exactSynonyms[0] == "B");
106  unit_assert(cvTermInfo(MS_QIT).exactSynonyms.size() == 3);
107 
108  unit_assert(cvTermInfo(MS_chemical_ionization).shortName() == "CI");
109  unit_assert(cvTermInfo(MS_FT_ICR).shortName() == "FT_ICR");
111  unit_assert(cvTermInfo(CVID_Unknown).shortName() == "Unknown");
112 }
PWIZ_API_DECL const CVTermInfo & cvTermInfo(CVID cvid)
returns CV term info for the specified CVID
MS_FT_ICR
FT_ICR (fourier transform ion cyclotron resonance mass spectrometer): A mass spectrometer based on th...
Definition: cv.hpp:376
MS_fourier_transform_ion_cyclotron_resonance_mass_spectrometer
fourier transform ion cyclotron resonance mass spectrometer: A mass spectrometer based on the princip...
Definition: cv.hpp:373
MS_B
B (magnetic field strength): A property of space that produces a force on a charged particle equal to...
Definition: cv.hpp:178
structure for holding CV term info
Definition: cv.hpp:13381
std::vector< std::string > exactSynonyms
Definition: cv.hpp:13393
std::string name
Definition: cv.hpp:13385
CVID_Unknown
Definition: cv.hpp:97
MS_QIT
QIT (quadrupole ion trap): Quadrupole Ion Trap mass analyzer captures the ions in a three dimensional...
Definition: cv.hpp:391
#define unit_assert(x)
Definition: unit.hpp:85
MS_chemical_ionization
chemical ionization: The formation of a new ion by the reaction of a neutral species with an ion...
Definition: cv.hpp:334

§ testIDTranslation()

void testIDTranslation ( )

Definition at line 115 of file cvtest.cpp.

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

Referenced by testThreadSafetyWorker().

116 {
117  unit_assert(cvTermInfo("MS:1000025").cvid == MS_B);
118  unit_assert(cvTermInfo("MS:1000042").cvid == MS_peak_intensity);
119  unit_assert(cvTermInfo("UO:0000231").cvid == UO_information_unit);
120  unit_assert(cvTermInfo("XX:0000231").cvid == CVID_Unknown);
121  unit_assert(cvTermInfo("FOO:").cvid == CVID_Unknown);
122  unit_assert(cvTermInfo(":FOO").cvid == CVID_Unknown);
123  unit_assert(cvTermInfo("MS").cvid == CVID_Unknown);
124 }
PWIZ_API_DECL const CVTermInfo & cvTermInfo(CVID cvid)
returns CV term info for the specified CVID
UO_information_unit
information unit: A unit which is a standard measure of the amount of information.
Definition: cv.hpp:13183
MS_B
B (magnetic field strength): A property of space that produces a force on a charged particle equal to...
Definition: cv.hpp:178
MS_peak_intensity
peak intensity: Intensity of ions as measured by the height or area of a peak in a mass spectrum...
Definition: cv.hpp:241
CVID_Unknown
Definition: cv.hpp:97
#define unit_assert(x)
Definition: unit.hpp:85

§ testPropertyValues()

void testPropertyValues ( )

Definition at line 127 of file cvtest.cpp.

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

Referenced by testThreadSafetyWorker().

128 {
130 
131  unit_assert_operator_equal(1, phospho.propertyValues.count("delta_composition"));
132  unit_assert_operator_equal("H O(3) P", phospho.propertyValues.find("delta_composition")->second);
133 
134  unit_assert_operator_equal(2, phospho.propertyValues.count("spec_1_site"));
135  unit_assert_operator_equal("T", phospho.propertyValues.equal_range("spec_1_site").first->second);
136  unit_assert_operator_equal("S", (--phospho.propertyValues.equal_range("spec_1_site").second)->second);
137 
138  unit_assert_operator_equal(1, phospho.propertyValues.count("spec_2_site"));
139  unit_assert_operator_equal("Y", phospho.propertyValues.find("spec_2_site")->second);
140 }
PWIZ_API_DECL const CVTermInfo & cvTermInfo(CVID cvid)
returns CV term info for the specified CVID
std::multimap< std::string, std::string > propertyValues
Definition: cv.hpp:13394
structure for holding CV term info
Definition: cv.hpp:13381
#define unit_assert_operator_equal(expected, actual)
Definition: unit.hpp:92
UNIMOD_Phospho
Phospho: Phosphorylation.
Definition: cv.hpp:8467

§ testThreadSafetyWorker()

void testThreadSafetyWorker ( boost::barrier *  testBarrier)

Definition at line 143 of file cvtest.cpp.

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

Referenced by testThreadSafety().

144 {
145  testBarrier->wait(); // wait until all threads have started
146 
147  try
148  {
149  test();
150  testIsA();
152  testSynonyms();
155  }
156  catch (exception& e)
157  {
158  cerr << "Exception in worker thread: " << e.what() << endl;
159  }
160  catch (...)
161  {
162  cerr << "Unhandled exception in worker thread." << endl;
163  }
164 }
void testOtherRelations()
Definition: cvtest.cpp:84
void testIsA()
Definition: cvtest.cpp:67
void testSynonyms()
Definition: cvtest.cpp:100
void testPropertyValues()
Definition: cvtest.cpp:127
void testIDTranslation()
Definition: cvtest.cpp:115
void test()
Definition: cvtest.cpp:39

§ testThreadSafety()

void testThreadSafety ( const int &  testThreadCount)

Definition at line 166 of file cvtest.cpp.

References testThreadSafetyWorker().

Referenced by main().

167 {
168  boost::barrier testBarrier(testThreadCount);
169  boost::thread_group testThreadGroup;
170  for (int i=0; i < testThreadCount; ++i)
171  testThreadGroup.add_thread(new boost::thread(&testThreadSafetyWorker, &testBarrier));
172  testThreadGroup.join_all();
173 }
void testThreadSafetyWorker(boost::barrier *testBarrier)
Definition: cvtest.cpp:143

§ main()

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

Definition at line 176 of file cvtest.cpp.

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

177 {
178  TEST_PROLOG(argc, argv)
179 
180  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
181 
182  try
183  {
184  //testThreadSafety(1); // does not test thread-safety of singleton initialization
185  testThreadSafety(2);
186  testThreadSafety(4);
187  testThreadSafety(8);
188  testThreadSafety(16);
189  }
190  catch (exception& e)
191  {
192  TEST_FAILED(e.what())
193  }
194  catch (...)
195  {
196  TEST_FAILED("Caught unknown exception.")
197  }
198 
200 }
ostream * os_
Definition: cvtest.cpp:36
#define TEST_EPILOG
Definition: unit.hpp:182
void testThreadSafety(const int &testThreadCount)
Definition: cvtest.cpp:166
#define TEST_FAILED(x)
Definition: unit.hpp:176
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:174

Variable Documentation

§ os_

ostream* os_ = 0

Definition at line 36 of file cvtest.cpp.

Referenced by main(), and test().