ProteoWizard
Functions | Variables
Serializer_FASTA_Test.cpp File Reference
#include "Serializer_FASTA.hpp"
#include "Diff.hpp"
#include "examples.hpp"
#include "pwiz/data/common/BinaryIndexStream.hpp"
#include "pwiz/utility/misc/unit.hpp"
#include "pwiz/utility/misc/Std.hpp"
#include "boost/thread/thread.hpp"
#include "boost/thread/barrier.hpp"

Go to the source code of this file.

Functions

void testWriteRead (const Serializer_FASTA::Config &config)
 
void testWriteRead ()
 
void testThreadSafetyWorker (pair< boost::barrier *, ProteomeData * > *args)
 
void testThreadSafety (const int &testThreadCount)
 
void testDuplicateId ()
 
int main (int argc, char *argv[])
 

Variables

ostream * os_ = 0
 

Function Documentation

◆ testWriteRead() [1/2]

void testWriteRead ( const Serializer_FASTA::Config config)

Definition at line 41 of file Serializer_FASTA_Test.cpp.

42{
43 ProteomeData pd;
45
46 Serializer_FASTA serializer(config);
47
48 ostringstream oss;
49 serializer.write(oss, pd, NULL);
50
51 if (os_) *os_ << "oss:\n" << oss.str() << endl;
52
53 shared_ptr<istringstream> iss(new istringstream(oss.str()));
54 ProteomeData pd2;
55 serializer.read(iss, pd2);
56
58 if (os_ && diff) *os_ << diff << endl;
60}
void diff(const string &filename1, const string &filename2)
ostream * os_
ProteomeData <-> FASTA stream serialization.
PWIZ_API_DECL void initializeTiny(ProteomeData &pd)
Calculate diffs of objects in a ProteoWizard data model hierarchy.
Definition diff_std.hpp:143
#define unit_assert(x)
Definition unit.hpp:85

References diff(), pwiz::proteome::examples::initializeTiny(), os_, pwiz::proteome::Serializer_FASTA::read(), unit_assert, and pwiz::proteome::Serializer_FASTA::write().

◆ testWriteRead() [2/2]

void testWriteRead ( )

Definition at line 63 of file Serializer_FASTA_Test.cpp.

64{
65 if (os_) *os_ << "testWriteRead() MemoryIndex" << endl;
67 testWriteRead(config);
68
69 if (os_) *os_ << "testWriteRead() BinaryIndexStream" << endl;
70 shared_ptr<stringstream> indexStringStream(new stringstream);
71 config.indexPtr.reset(new BinaryIndexStream(indexStringStream));
72 testWriteRead(config);
73}
void testWriteRead()
index implementation in a stream (intended for fstreams but any iostream works); find(string id) is O...
Serializer_FASTA configuration.

References pwiz::proteome::Serializer_FASTA::Config::indexPtr, os_, and testWriteRead().

Referenced by main(), testThreadSafetyWorker(), and testWriteRead().

◆ testThreadSafetyWorker()

void testThreadSafetyWorker ( pair< boost::barrier *, ProteomeData * > *  args)

Definition at line 76 of file Serializer_FASTA_Test.cpp.

77{
78 args->first->wait(); // wait until all threads have started
79
80 try
81 {
83
84 for (int i=0; i < 3; ++i)
85 {
86 for (size_t j=0; j < args->second->proteinListPtr->size(); ++j)
87 unit_assert(args->second->proteinListPtr->protein(j)->index == j);
88 }
89 }
90 catch (exception& e)
91 {
92 cerr << "Exception in worker thread: " << e.what() << endl;
93 }
94 catch (...)
95 {
96 cerr << "Unhandled exception in worker thread." << endl;
97 }
98}

References testWriteRead(), and unit_assert.

Referenced by testThreadSafety().

◆ testThreadSafety()

void testThreadSafety ( const int &  testThreadCount)

Definition at line 100 of file Serializer_FASTA_Test.cpp.

101{
102 ProteomeData pd;
104
105 boost::barrier testBarrier(testThreadCount);
106 boost::thread_group testThreadGroup;
107 for (int i=0; i < testThreadCount; ++i)
108 testThreadGroup.add_thread(new boost::thread(&testThreadSafetyWorker, new pair<boost::barrier*, ProteomeData*>(&testBarrier, &pd)));
109 testThreadGroup.join_all();
110}
void testThreadSafetyWorker(pair< boost::barrier *, ProteomeData * > *args)

References pwiz::proteome::examples::initializeTiny(), and testThreadSafetyWorker().

◆ testDuplicateId()

void testDuplicateId ( )

Definition at line 112 of file Serializer_FASTA_Test.cpp.

113{
114 ProteomeData pd;
115 pd.id = "tiny";
116
117 shared_ptr<ProteinListSimple> proteinListPtr(new ProteinListSimple);
118 pd.proteinListPtr = proteinListPtr;
119
120 proteinListPtr->proteins.push_back(ProteinPtr(new Protein("ABC123", 0, "One two three.", "ELVISLIVES")));
121 proteinListPtr->proteins.push_back(ProteinPtr(new Protein("ZEBRA", 1, "Has stripes:", "BLACKANDWHITE")));
122 proteinListPtr->proteins.push_back(ProteinPtr(new Protein("DEFCON42", 2, "", "DNTPANIC")));
123 proteinListPtr->proteins.push_back(ProteinPtr(new Protein("ZEBRA", 1, "Black and white", "STRIPES")));
124
125 Serializer_FASTA serializer;
126
127 ostringstream oss;
128 serializer.write(oss, pd, NULL);
129
130 if (os_) *os_ << "oss:\n" << oss.str() << endl;
131
132 shared_ptr<istringstream> iss(new istringstream(oss.str()));
133 ProteomeData pd2;
134
135 unit_assert_throws_what(serializer.read(iss, pd2), runtime_error,
136 "[ProteinList_FASTA::createIndex] duplicate protein id \"ZEBRA\"");
137}
void read(boost::shared_ptr< std::istream > is, ProteomeData &pd) const
read in ProteomeData object from a FASTA istream
void write(std::ostream &os, const ProteomeData &pd, const pwiz::util::IterationListenerRegistry *iterationListenerRegistry) const
write ProteomeData object to ostream as FASTA
boost::shared_ptr< Protein > ProteinPtr
#define unit_assert_throws_what(x, exception, whatStr)
Definition unit.hpp:119

References pwiz::proteome::ProteomeData::id, os_, pwiz::proteome::ProteomeData::proteinListPtr, pwiz::proteome::Serializer_FASTA::read(), unit_assert_throws_what, and pwiz::proteome::Serializer_FASTA::write().

Referenced by main().

◆ main()

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

Definition at line 140 of file Serializer_FASTA_Test.cpp.

141{
142 TEST_PROLOG(argc, argv)
143
144 try
145 {
146 if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
152 }
153 catch (exception& e)
154 {
155 TEST_FAILED(e.what())
156 }
157 catch (...)
158 {
159 TEST_FAILED("Caught unknown exception.")
160 }
161
163}
void testThreadSafety()
void testDuplicateId()
#define TEST_EPILOG
Definition unit.hpp:183
#define TEST_FAILED(x)
Definition unit.hpp:177
#define TEST_PROLOG(argc, argv)
Definition unit.hpp:175

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

Variable Documentation

◆ os_

ostream* os_ = 0

Definition at line 38 of file Serializer_FASTA_Test.cpp.

Referenced by main(), testDuplicateId(), testWriteRead(), and testWriteRead().