ProteoWizard
Reader_Thermo_Test.cpp
Go to the documentation of this file.
1 //
2 // $Id: Reader_Thermo_Test.cpp 7155 2015-02-03 22:38:32Z chambm $
3 //
4 //
5 // Original author: Darren Kessner <darren@proteowizard.org>
6 //
7 // Copyright 2008 Spielberg Family Center for Applied Proteomics
8 // Cedars-Sinai Medical Center, Los Angeles, California 90048
9 //
10 // Licensed under the Apache License, Version 2.0 (the "License");
11 // you may not use this file except in compliance with the License.
12 // You may obtain a copy of the License at
13 //
14 // http://www.apache.org/licenses/LICENSE-2.0
15 //
16 // Unless required by applicable law or agreed to in writing, software
17 // distributed under the License is distributed on an "AS IS" BASIS,
18 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 // See the License for the specific language governing permissions and
20 // limitations under the License.
21 //
22 
23 
25 #include "Reader_Thermo.hpp"
29 
30 #ifdef PWIZ_READER_THERMO
31 #include "Reader_Thermo_Detail.hpp"
32 #endif
33 
35 {
36  bool operator() (const string& rawpath) const
37  {
38  return bal::to_lower_copy(BFS_STRING(bfs::path(rawpath).extension())) == ".raw";
39  }
40 };
41 
42 int main(int argc, char* argv[])
43 {
44  TEST_PROLOG(argc, argv)
45 
46  #if defined(PWIZ_READER_THERMO) && !defined(PWIZ_READER_THERMO_TEST_ACCEPT_ONLY)
47  const bool testAcceptOnly = false;
48  #else
49  const bool testAcceptOnly = true;
50  #endif
51 
52  try
53  {
54  #ifdef PWIZ_READER_THERMO
55 
56  using namespace pwiz::msdata;
57  using namespace pwiz::msdata::detail;
58  using namespace pwiz::msdata::detail::Thermo;
59  using namespace pwiz::cv;
60  using namespace pwiz::util;
61 
62  // test that all instrument types are handled by translation functions (skipping the 'Unknown' type)
63  bool allInstrumentTestsPassed = true;
64  for (int i=0; i < (int) InstrumentModelType_Count; ++i)
65  {
66  InstrumentModelType model = (InstrumentModelType) i;
67 
68  try
69  {
71 
72  Component dummySource;
73  vector<InstrumentConfiguration> configurations = createInstrumentConfigurations(dummySource, model);
74 
75  switch (model)
76  {
77  case InstrumentModelType_Tempus_TOF:
78  case InstrumentModelType_Element_2:
79  case InstrumentModelType_Element_XR:
80  case InstrumentModelType_Element_GD:
81  case InstrumentModelType_Delta_Plus_Advantage:
82  case InstrumentModelType_Delta_Plus_XP:
83  case InstrumentModelType_Neptune:
84  case InstrumentModelType_Triton:
85  unit_assert(configurations.empty());
86  break;
87 
88  default:
89  unit_assert(!configurations.empty());
90  break;
91  }
92 
93  // test for ionization types for this instrument
94  vector<IonizationType> ionizationTypes = getIonSourcesForInstrumentModel(model);
95 
96  switch (model)
97  {
98  case InstrumentModelType_Element_XR:
99  case InstrumentModelType_Element_2:
100  case InstrumentModelType_Delta_Plus_Advantage:
101  case InstrumentModelType_Delta_Plus_XP:
102  case InstrumentModelType_Neptune:
103  case InstrumentModelType_Tempus_TOF:
104  case InstrumentModelType_Triton:
105  case InstrumentModelType_MAT253:
106  case InstrumentModelType_MAT900XP:
107  case InstrumentModelType_MAT900XP_Trap:
108  case InstrumentModelType_MAT95XP:
109  case InstrumentModelType_MAT95XP_Trap:
110  case InstrumentModelType_Surveyor_PDA:
111  case InstrumentModelType_Accela_PDA:
112  unit_assert(ionizationTypes.empty());
113  break;
114 
115  default:
116  unit_assert(!ionizationTypes.empty());
117  break;
118  }
119 
120  // test for mass analyzer types for this instrument
121  vector<MassAnalyzerType> massAnalyzerTypes = getMassAnalyzersForInstrumentModel(model);
122 
123  switch (model)
124  {
125  case InstrumentModelType_Element_XR:
126  case InstrumentModelType_Element_2:
127  case InstrumentModelType_Element_GD:
128  case InstrumentModelType_Delta_Plus_Advantage:
129  case InstrumentModelType_Delta_Plus_XP:
130  case InstrumentModelType_Neptune:
131  case InstrumentModelType_Triton:
132  case InstrumentModelType_Surveyor_PDA:
133  case InstrumentModelType_Accela_PDA:
134  unit_assert(massAnalyzerTypes.empty());
135  break;
136 
137  default:
138  unit_assert(!massAnalyzerTypes.empty());
139  break;
140  }
141 
142  // test for detector types for this instrument
143  vector<DetectorType> detectorTypes = getDetectorsForInstrumentModel(model);
144 
145  switch (model)
146  {
147  case InstrumentModelType_Element_GD:
148  case InstrumentModelType_Element_XR:
149  case InstrumentModelType_Element_2:
150  case InstrumentModelType_Delta_Plus_Advantage:
151  case InstrumentModelType_Delta_Plus_XP:
152  case InstrumentModelType_Neptune:
153  case InstrumentModelType_Tempus_TOF:
154  case InstrumentModelType_Triton:
155  case InstrumentModelType_MAT253:
156  case InstrumentModelType_MAT900XP:
157  case InstrumentModelType_MAT900XP_Trap:
158  case InstrumentModelType_MAT95XP:
159  case InstrumentModelType_MAT95XP_Trap:
160  unit_assert(detectorTypes.empty());
161  break;
162 
163  default:
164  unit_assert(!detectorTypes.empty());
165  break;
166  }
167 
168  // test for translation of scan filter mass analyzer type to real mass analyzer type
169  BOOST_FOREACH(MassAnalyzerType realType, massAnalyzerTypes)
170  {
171  bool hasCorrespondingScanFilterType = false;
172  for (int j=0; j < (int) ScanFilterMassAnalyzerType_Count; ++j)
173  if (convertScanFilterMassAnalyzer((ScanFilterMassAnalyzerType) j, model) == realType)
174  hasCorrespondingScanFilterType = true;
175  unit_assert(hasCorrespondingScanFilterType);
176  }
177  }
178  catch (runtime_error& e)
179  {
180  cerr << "Unit test failed for instrument model " << lexical_cast<string>(model) << ":\n" << e.what() << endl;
181  allInstrumentTestsPassed = false;
182  }
183  }
184 
185  unit_assert(allInstrumentTestsPassed);
186  #endif
187 
188  bool requireUnicodeSupport = true;
189  pwiz::util::testReader(pwiz::msdata::Reader_Thermo(), testArgs, testAcceptOnly, requireUnicodeSupport, IsRawFile());
190  }
191  catch (exception& e)
192  {
193  TEST_FAILED(e.what())
194  }
195  catch (...)
196  {
197  TEST_FAILED("Caught unknown exception.")
198  }
199 
201 }
PWIZ_API_DECL CVID translateAsInstrumentModel(InstrumentModelType instrumentModelType)
A component of an instrument corresponding to a source (i.e. ion source), an analyzer (i...
Definition: MSData.hpp:130
#define TEST_EPILOG
Definition: unit.hpp:182
bool operator()(const string &rawpath) const
returns true iff the given rawpath is a real path to test/generate
float lexical_cast(const std::string &str)
int main(int argc, char *argv[])
PWIZ_API_DECL std::vector< InstrumentConfiguration > createInstrumentConfigurations(pwiz::vendor_api::Bruker::CompassDataPtr rawfile)
PWIZ_API_DECL int testReader(const pwiz::msdata::Reader &reader, const std::vector< std::string > &args, bool testAcceptOnly, bool requireUnicodeSupport, const TestPathPredicate &isPathTestable)
A common test harness for vendor readers;.
#define BFS_STRING(p)
Definition: Filesystem.hpp:53
#define TEST_FAILED(x)
Definition: unit.hpp:176
test implementations derive from this to define which paths should be tested
CVID_Unknown
Definition: cv.hpp:97
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:174
#define unit_assert(x)
Definition: unit.hpp:85
Definition: cv.hpp:91