ProteoWizard
Reader_Thermo_Test.cpp
Go to the documentation of this file.
1 //
2 // $Id$
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 #include <windows.h>
33 #endif
34 
36 {
37  bool operator() (const string& rawpath) const
38  {
39  return bal::to_lower_copy(BFS_STRING(bfs::path(rawpath).extension())) == ".raw";
40  }
41 };
42 
43 int main(int argc, char* argv[])
44 {
45  TEST_PROLOG(argc, argv)
46 
47  #if defined(PWIZ_READER_THERMO) && !defined(PWIZ_READER_THERMO_TEST_ACCEPT_ONLY)
48  const bool testAcceptOnly = false;
49  #else
50  const bool testAcceptOnly = true;
51  #endif
52 
53  try
54  {
55  #ifdef PWIZ_READER_THERMO
56 
57  using namespace pwiz::msdata;
58  using namespace pwiz::msdata::detail;
59  using namespace pwiz::msdata::detail::Thermo;
60  using namespace pwiz::cv;
61  using namespace pwiz::util;
62 
63  // test that all instrument types are handled by translation functions (skipping the 'Unknown' type)
64  bool allInstrumentTestsPassed = true;
65  for (int i=0; i < (int) InstrumentModelType_Count; ++i)
66  {
67  InstrumentModelType model = (InstrumentModelType) i;
68 
69  try
70  {
72 
73  Component dummySource;
74  vector<InstrumentConfiguration> configurations = createInstrumentConfigurations(dummySource, model);
75 
76  switch (model)
77  {
78  case InstrumentModelType_Tempus_TOF:
79  case InstrumentModelType_Element_2:
80  case InstrumentModelType_Element_XR:
81  case InstrumentModelType_Element_GD:
82  case InstrumentModelType_Delta_Plus_Advantage:
83  case InstrumentModelType_Delta_Plus_XP:
84  case InstrumentModelType_Neptune:
85  case InstrumentModelType_Triton:
86  unit_assert(configurations.empty());
87  break;
88 
89  default:
90  unit_assert(!configurations.empty());
91  break;
92  }
93 
94  // test for ionization types for this instrument
95  vector<IonizationType> ionizationTypes = getIonSourcesForInstrumentModel(model);
96 
97  switch (model)
98  {
99  case InstrumentModelType_Element_XR:
100  case InstrumentModelType_Element_2:
101  case InstrumentModelType_Delta_Plus_Advantage:
102  case InstrumentModelType_Delta_Plus_XP:
103  case InstrumentModelType_Neptune:
104  case InstrumentModelType_Tempus_TOF:
105  case InstrumentModelType_Triton:
106  case InstrumentModelType_MAT253:
107  case InstrumentModelType_MAT900XP:
108  case InstrumentModelType_MAT900XP_Trap:
109  case InstrumentModelType_MAT95XP:
110  case InstrumentModelType_MAT95XP_Trap:
111  case InstrumentModelType_Surveyor_PDA:
112  case InstrumentModelType_Accela_PDA:
113  unit_assert(ionizationTypes.empty());
114  break;
115 
116  default:
117  unit_assert(!ionizationTypes.empty());
118  break;
119  }
120 
121  // test for mass analyzer types for this instrument
122  vector<MassAnalyzerType> massAnalyzerTypes = getMassAnalyzersForInstrumentModel(model);
123 
124  switch (model)
125  {
126  case InstrumentModelType_Element_XR:
127  case InstrumentModelType_Element_2:
128  case InstrumentModelType_Element_GD:
129  case InstrumentModelType_Delta_Plus_Advantage:
130  case InstrumentModelType_Delta_Plus_XP:
131  case InstrumentModelType_Neptune:
132  case InstrumentModelType_Triton:
133  case InstrumentModelType_Surveyor_PDA:
134  case InstrumentModelType_Accela_PDA:
135  unit_assert(massAnalyzerTypes.empty());
136  break;
137 
138  default:
139  unit_assert(!massAnalyzerTypes.empty());
140  break;
141  }
142 
143  // test for detector types for this instrument
144  vector<DetectorType> detectorTypes = getDetectorsForInstrumentModel(model);
145 
146  switch (model)
147  {
148  case InstrumentModelType_Element_GD:
149  case InstrumentModelType_Element_XR:
150  case InstrumentModelType_Element_2:
151  case InstrumentModelType_Delta_Plus_Advantage:
152  case InstrumentModelType_Delta_Plus_XP:
153  case InstrumentModelType_Neptune:
154  case InstrumentModelType_Tempus_TOF:
155  case InstrumentModelType_Triton:
156  case InstrumentModelType_MAT253:
157  case InstrumentModelType_MAT900XP:
158  case InstrumentModelType_MAT900XP_Trap:
159  case InstrumentModelType_MAT95XP:
160  case InstrumentModelType_MAT95XP_Trap:
161  unit_assert(detectorTypes.empty());
162  break;
163 
164  default:
165  unit_assert(!detectorTypes.empty());
166  break;
167  }
168 
169  // test for translation of scan filter mass analyzer type to real mass analyzer type
170  BOOST_FOREACH(MassAnalyzerType realType, massAnalyzerTypes)
171  {
172  bool hasCorrespondingScanFilterType = false;
173  for (int j=0; j < (int) ScanFilterMassAnalyzerType_Count; ++j)
174  if (convertScanFilterMassAnalyzer((ScanFilterMassAnalyzerType) j, model) == realType)
175  hasCorrespondingScanFilterType = true;
176  unit_assert(hasCorrespondingScanFilterType);
177  }
178  }
179  catch (runtime_error& e)
180  {
181  cerr << "Unit test failed for instrument model " << lexical_cast<string>(model) << ":\n" << e.what() << endl;
182  allInstrumentTestsPassed = false;
183  }
184  }
185 
186  unit_assert(allInstrumentTestsPassed);
187  #endif
188 
189  bool requireUnicodeSupport = true;
192  pwiz::util::testReader(reader, testArgs, testAcceptOnly, requireUnicodeSupport, IsRawFile(), config);
193 
194  config.peakPicking = true;
195  pwiz::util::testReader(reader, testArgs, testAcceptOnly, requireUnicodeSupport, IsRawFile(), config);
196 
197  #ifdef PWIZ_READER_THERMO
198  // CONSIDER: do this test in VendorReaderTestHarness for all vendor readers?
199  ::SetThreadLocale(LANG_TURKISH);
200  pwiz::util::testReader(reader, testArgs, testAcceptOnly, requireUnicodeSupport, IsRawFile(), config);
201  #endif
202  }
203  catch (exception& e)
204  {
205  TEST_FAILED(e.what())
206  }
207  catch (...)
208  {
209  TEST_FAILED("Caught unknown exception.")
210  }
211 
213 }
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:131
#define TEST_EPILOG
Definition: unit.hpp:183
bool operator()(const string &rawpath) const
returns true iff the given rawpath is a real path to test/generate
int main(int argc, char *argv[])
PWIZ_API_DECL std::vector< InstrumentConfiguration > createInstrumentConfigurations(pwiz::vendor_api::Bruker::CompassDataPtr rawfile)
toType lexical_cast(const std::string &str, bool &success)
PWIZ_API_DECL int testReader(const pwiz::msdata::Reader &reader, const std::vector< std::string > &args, bool testAcceptOnly, bool requireUnicodeSupport, const TestPathPredicate &isPathTestable, const ReaderTestConfig &config=ReaderTestConfig())
A common test harness for vendor readers;.
#define BFS_STRING(p)
Definition: Filesystem.hpp:58
#define TEST_FAILED(x)
Definition: unit.hpp:177
test implementations derive from this to define which paths should be tested
CVID_Unknown
Definition: cv.hpp:114
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:175
#define unit_assert(x)
Definition: unit.hpp:85
Definition: cv.hpp:108