ProteoWizard
TraDataFileTest.cpp
Go to the documentation of this file.
1//
2// $Id$
3//
4//
5// Original author: Matt Chambers <matt.chambers .@. vanderbilt.edu>
6//
7// Copyright 2009 Vanderbilt University - Nashville, TN 37232
8//
9// Licensed under the Apache License, Version 2.0 (the "License");
10// you may not use this file except in compliance with the License.
11// You may obtain a copy of the License at
12//
13// http://www.apache.org/licenses/LICENSE-2.0
14//
15// Unless required by applicable law or agreed to in writing, software
16// distributed under the License is distributed on an "AS IS" BASIS,
17// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18// See the License for the specific language governing permissions and
19// limitations under the License.
20//
21
22
23#include "TraDataFile.hpp"
24#include "Diff.hpp"
25#include "IO.hpp"
26#include "examples.hpp"
30#include <boost/iostreams/filtering_stream.hpp>
31#include <boost/iostreams/filter/gzip.hpp>
32#include <boost/iostreams/device/file_descriptor.hpp>
33#include <boost/iostreams/copy.hpp>
34
35
36using namespace pwiz::util;
37using namespace pwiz::cv;
38using namespace pwiz::data;
39using namespace pwiz::tradata;
40
41
42ostream* os_ = 0;
43
44
45string filenameBase_ = "temp.TraDataFileTest";
46
48{
49 // remove metadata ptrs appended on read
50 //vector<SourceFilePtr>& sfs = msd.fileDescription.sourceFilePtrs;
51 //if (!sfs.empty()) sfs.erase(sfs.end()-1);
52 vector<SoftwarePtr>& sws = td.softwarePtrs;
53 if (!sws.empty()) sws.erase(sws.end()-1);
54}
55
56void test()
57{
58 TraDataFile::WriteConfig writeConfig;
59
60 if (os_) *os_ << "test()\n " << writeConfig << endl;
61
62 string filename1 = filenameBase_ + ".1";
63 string filename2 = filenameBase_ + ".2";
64
65 {
66 // create TraData object in memory
67 TraData tiny;
69
70 // write to file #1 (static)
71 TraDataFile::write(tiny, filename1, writeConfig);
72
73 // read back into an TraDataFile object
76
77 // compare
79 if (diff && os_) *os_ << diff << endl;
81
82 // write to file #2 (member)
83 td1.write(filename2, writeConfig);
84
85 // read back into another TraDataFile object
86 TraDataFile td2(filename2);
88
89 // compare
90 diff(tiny, td2);
91 if (diff && os_) *os_ << diff << endl;
93
94 // now give the gzip read a workout
95 bio::filtering_istream tinyGZ(bio::gzip_compressor() | bio::file_descriptor_source(filename1));
96 bio::copy(tinyGZ, bio::file_descriptor_sink(filename1+".gz", ios::out|ios::binary));
97
100
101 // compare
102 diff(tiny, td3);
103 if (diff && os_) *os_ << diff << endl;
105 }
106
107 // remove temp files
108 boost::filesystem::remove(filename1);
109 boost::filesystem::remove(filename2);
110 boost::filesystem::remove(filename1 + ".gz");
111}
112
113
114int main(int argc, char* argv[])
115{
116 TEST_PROLOG(argc, argv)
117
118 try
119 {
120 if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
121 test();
122 }
123 catch (exception& e)
124 {
125 TEST_FAILED(e.what())
126 }
127 catch (...)
128 {
129 TEST_FAILED("Caught unknown exception.")
130 }
131
133}
void diff(const string &filename1, const string &filename2)
string filename1
int main(int argc, char *argv[])
void hackInMemoryTraData(TraData &td)
ostream * os_
void test()
string filenameBase_
PWIZ_API_DECL void initializeTiny(ProteomeData &pd)
Calculate diffs of objects in a ProteoWizard data model hierarchy.
Definition diff_std.hpp:143
TraData object plus file I/O.
static void write(const TraData &msd, const std::string &filename, const WriteConfig &config=WriteConfig())
static write function for any TraData object;
std::vector< SoftwarePtr > softwarePtrs
List of software packages used in the generation of one of more transitions described in the document...
Definition TraData.hpp:369
#define unit_assert(x)
Definition unit.hpp:85
#define TEST_EPILOG
Definition unit.hpp:183
#define TEST_FAILED(x)
Definition unit.hpp:177
#define TEST_PROLOG(argc, argv)
Definition unit.hpp:175