ProteoWizard
LegacyAdapterTest.cpp
Go to the documentation of this file.
1 //
2 // $Id: LegacyAdapterTest.cpp 4129 2012-11-20 00:05:37Z chambm $
3 //
4 //
5 // Original author: Darren Kessner <darren@proteowizard.org>
6 //
7 // Copyright 2007 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 
24 #include "LegacyAdapter.hpp"
26 #include "TextWriter.hpp"
28 #include "boost/lambda/lambda.hpp"
29 #include "boost/lambda/bind.hpp"
31 #include <cstring>
32 
33 
34 using namespace pwiz::util;
35 using namespace pwiz::cv;
36 using namespace pwiz::msdata;
37 using namespace boost::lambda;
38 
39 
40 ostream* os_ = 0;
41 
42 
44 {
45  if (os_) *os_ << "testModelAndManufacturer()\n";
46 
47  InstrumentConfiguration instrumentConfiguration;
48  CVTranslator cvTranslator;
49  LegacyAdapter_Instrument adapter(instrumentConfiguration, cvTranslator);
50 
51  unit_assert(instrumentConfiguration.cvParams.empty() && instrumentConfiguration.userParams.empty());
52 
53  adapter.manufacturerAndModel("dummy", "LTQ-FT");
54  if (os_) *os_ << "manufacturer: " << adapter.manufacturer() << endl
55  << "model: " << adapter.model() << endl;
56  unit_assert(instrumentConfiguration.cvParams.size() == 1);
57  unit_assert(instrumentConfiguration.userParams.empty());
58  unit_assert(adapter.manufacturer() == "Thermo Scientific");
59  unit_assert(adapter.model() == "LTQ FT");
60 
61  adapter.manufacturerAndModel("doobie", "420");
62  if (os_) *os_ << "manufacturer: " << adapter.manufacturer() << endl
63  << "model: " << adapter.model() << endl;
64  unit_assert(instrumentConfiguration.cvParams.empty());
65  unit_assert(instrumentConfiguration.userParams.size() == 2);
66  unit_assert(adapter.manufacturer() == "doobie");
67  unit_assert(adapter.model() == "420");
68 
69  adapter.manufacturerAndModel("dummy", "LTQ-FT");
70  if (os_) *os_ << "manufacturer: " << adapter.manufacturer() << endl
71  << "model: " << adapter.model() << endl;
72  unit_assert(instrumentConfiguration.cvParams.size() == 1);
73  unit_assert(instrumentConfiguration.userParams.empty());
74  unit_assert(adapter.manufacturer() == "Thermo Scientific");
75  unit_assert(adapter.model() == "LTQ FT");
76 }
77 
78 
80 {
81  InstrumentConfiguration instrumentConfiguration;
82  instrumentConfiguration.componentList.push_back(Component(ComponentType_Source, 2));
83  CVTranslator cvTranslator;
84  LegacyAdapter_Instrument adapter(instrumentConfiguration, cvTranslator);
85 
86  adapter.ionisation(" esi\t");
87  if (os_) *os_ << "ionisation: " << adapter.ionisation() << endl;
88  unit_assert(instrumentConfiguration.componentList.source(0).cvParams.size() == 1);
89  unit_assert(instrumentConfiguration.componentList.source(0).userParams.empty());
90  unit_assert(adapter.ionisation() == "electrospray ionization");
91 
92  adapter.ionisation("goober");
93  if (os_) *os_ << "ionisation: " << adapter.ionisation() << endl;
94  unit_assert(instrumentConfiguration.componentList.source(0).cvParams.empty());
95  unit_assert(instrumentConfiguration.componentList.source(0).userParams.size() == 1);
96  unit_assert(adapter.ionisation() == "goober");
97 
98  adapter.ionisation(" Electrospray-Ionization");
99  if (os_) *os_ << "ionisation: " << adapter.ionisation() << endl;
100  unit_assert(instrumentConfiguration.componentList.source(0).cvParams.size() == 1);
101  unit_assert(instrumentConfiguration.componentList.source(0).userParams.empty());
102  unit_assert(adapter.ionisation() == "electrospray ionization");
103 }
104 
105 
107 {
108  InstrumentConfiguration instrumentConfiguration;
109  instrumentConfiguration.componentList.push_back(Component(ComponentType_Analyzer, 2));
110  CVTranslator cvTranslator;
111  LegacyAdapter_Instrument adapter(instrumentConfiguration, cvTranslator);
112 
113  adapter.analyzer("IT");
114  if (os_) *os_ << "analyzer: " << adapter.analyzer() << endl;
115  unit_assert(instrumentConfiguration.componentList.analyzer(0).cvParams.size() == 1);
116  unit_assert(instrumentConfiguration.componentList.analyzer(0).userParams.empty());
117  unit_assert(adapter.analyzer() == "ion trap");
118 
119  adapter.analyzer("goober");
120  if (os_) *os_ << "analyzer: " << adapter.analyzer() << endl;
121  unit_assert(instrumentConfiguration.componentList.analyzer(0).cvParams.empty());
122  unit_assert(instrumentConfiguration.componentList.analyzer(0).userParams.size() == 1);
123  unit_assert(adapter.analyzer() == "goober");
124 
125  adapter.analyzer(" qit");
126  if (os_) *os_ << "analyzer: " << adapter.analyzer() << endl;
127  unit_assert(instrumentConfiguration.componentList.analyzer(0).cvParams.size() == 1);
128  unit_assert(instrumentConfiguration.componentList.analyzer(0).userParams.empty());
129  unit_assert(adapter.analyzer() == "quadrupole ion trap");
130 }
131 
132 
134 {
135  InstrumentConfiguration instrumentConfiguration;
136  instrumentConfiguration.componentList.push_back(Component(ComponentType_Detector, 3));
137  CVTranslator cvTranslator;
138  LegacyAdapter_Instrument adapter(instrumentConfiguration, cvTranslator);
139 
140  adapter.detector("emt");
141  if (os_) *os_ << "detector: " << adapter.detector() << endl;
142  unit_assert(instrumentConfiguration.componentList.detector(0).cvParams.size() == 1);
143  unit_assert(instrumentConfiguration.componentList.detector(0).userParams.empty());
144  unit_assert(adapter.detector() == "electron multiplier tube");
145 
146  adapter.detector("goober");
147  if (os_) *os_ << "detector: " << adapter.detector() << endl;
148  unit_assert(instrumentConfiguration.componentList.detector(0).cvParams.empty());
149  unit_assert(instrumentConfiguration.componentList.detector(0).userParams.size() == 1);
150  unit_assert(adapter.detector() == "goober");
151 
152  adapter.detector(" Electron Multiplier ");
153  if (os_) *os_ << "detector: " << adapter.detector() << endl;
154  unit_assert(instrumentConfiguration.componentList.detector(0).cvParams.size() == 1);
155  unit_assert(instrumentConfiguration.componentList.detector(0).userParams.empty());
156  unit_assert(adapter.detector() == "electron multiplier");
157 }
158 
159 
161 {
163  testIonisation();
164  testAnalyzer();
165  testDetector();
166 }
167 
168 
170 {
171  SoftwarePtr software(new Software("abcd"));
172  MSData msd;
173  CVTranslator cvTranslator;
174  LegacyAdapter_Software adapter(software, msd, cvTranslator);
175 
176  adapter.name(" XcaLibur ");
177  if (os_) *os_ << "software name: " << adapter.name() << endl;
178  CVParam softwareParam = software->cvParamChild(MS_software);
179  unit_assert(softwareParam.cvid == MS_Xcalibur);
180  unit_assert(adapter.name() == "Xcalibur");
181 
182  adapter.name("goober");
183  if (os_) *os_ << "software name: " << adapter.name() << endl;
184  softwareParam = software->cvParamChild(MS_software);
185  unit_assert(softwareParam.cvid == CVID_Unknown);
186  unit_assert(adapter.name() == "goober");
187 
188  adapter.version("4.20");
189  if (os_) *os_ << "software version: " << adapter.version() << endl;
190  unit_assert(adapter.version() == "4.20");
191 
192  //adapter.type("acquisition");
193  //if (os_) *os_ << "software type: " << adapter.type() << endl;
194  //unit_assert(adapter.type() == "acquisition");
195 
196  adapter.type("analysis");
197  if (os_) *os_ << "software type: " << adapter.type() << endl;
198  unit_assert(adapter.type() == "analysis");
199 }
200 
201 
202 void test()
203 {
205  testSoftware();
206 }
207 
208 
209 int main(int argc, char* argv[])
210 {
211  TEST_PROLOG(argc, argv)
212 
213  try
214  {
215  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
216  test();
217  }
218  catch (exception& e)
219  {
220  TEST_FAILED(e.what())
221  }
222  catch (...)
223  {
224  TEST_FAILED("Caught unknown exception.")
225  }
226 
228 }
229