TestWrite Class Reference

## Public Member Functions

void | testWrite ()

## Detailed Description

Definition at line 28 of file WriteFiles.h.

## Member Function Documentation

## testWrite()

void TestWrite::testWrite | ( |  | ) |

Definition at line 37 of file WriteFiles.cpp.

{
GlfFile glfOut;
std::string testFile = "results/MyTestOut1.glf";
assert(glfOut.openForWrite(testFile.c_str(), false));
// Create a glf header.
GlfHeader glfHeader;
GlfRefSection glfSection;
GlfRecord record;
// Test writing refsection with no header - exception
bool caughtException = false;
try
{
assert(glfOut.writeRefSection(glfSection) == false);
}
catch (std::exception& e)
{
caughtException = true;
}
assert(caughtException);
// Test writing record with no header - exception.
caughtException = false;
try
{
assert(glfOut.writeRecord(record) == false);
}
catch (std::exception& e)
{
caughtException = true;
}
assert(caughtException);
// Write the header.
writeHeader(glfOut, 1);
// Test writing record with no refsection - exception.
caughtException = false;
try
{
assert(glfOut.writeRecord(record) == false);
}
catch (std::exception& e)
{
caughtException = true;
}
assert(caughtException);
//////////////////////////////////////////////
writeRefSection1(glfOut);
// Test writing header after refSection - exception
caughtException = false;
try
{
assert(glfOut.writeHeader(glfHeader) == false);
}
catch (std::exception& e)
{
caughtException = true;
}
assert(caughtException);
writeSec1Record1(glfOut);
// Test writing header after record - exception
caughtException = false;
try
{
assert(glfOut.writeHeader(glfHeader) == false);
}
catch (std::exception& e)
{
caughtException = true;
}
assert(caughtException);
writeSec1Record2(glfOut);
writeEndMarker(glfOut);
writeRefSection2(glfOut);
writeSec2Record1(glfOut);
writeEndMarker(glfOut);
////////////////////
// Close the file.
glfOut.close();
//////////////////////////////////////////////
// Validate the just written file.
GlfFile glfIn;
assert(glfIn.openForRead(testFile.c_str()));
readHeader(glfIn, 1);
readRefSection1(glfIn);
readSec1Record1(glfIn);
readSec1Record2(glfIn);
readEndMarker(glfIn);
readRefSection2(glfIn);
readSec2Record1(glfIn);
readEndMarker(glfIn);
checkEOF(glfIn);
////////////////////////////////
// NEW FILE
testFile = "results/MyTestOut2.glf";
assert(glfOut.openForWrite(testFile.c_str()));
writeHeader(glfOut, 2);
writeRefSection1(glfOut);
writeSec1Record1(glfOut);
writeSec1Record2(glfOut);
// Test writing new section without end of section marker - auto-added.
writeRefSection2(glfOut);
writeSec2Record1(glfOut);
// Test closing file with no end of section marker - auto-added.
glfOut.close();
//////////////////////////////////////////////
// Validate the just written file.
assert(glfIn.openForRead(testFile.c_str()));
readHeader(glfIn, 2);
readRefSection1(glfIn);
readSec1Record1(glfIn);
readSec1Record2(glfIn);
readEndMarker(glfIn);
readRefSection2(glfIn);
readSec2Record1(glfIn);
readEndMarker(glfIn);
checkEOF(glfIn);
////////////////////////////////
// NEW FILE
testFile = "results/MyTestOut3.glf";
{
GlfFile glfOutScoped;
assert(glfOutScoped.openForWrite(testFile.c_str()));
writeHeader(glfOutScoped, 3);
writeRefSection1(glfOutScoped);
writeSec1Record1(glfOutScoped);
writeSec1Record2(glfOutScoped);
// Test writing new section without end of section marker - auto-added.
writeRefSection2(glfOutScoped);
writeSec2Record1(glfOutScoped);
// Test just letting the file go out of scope with no end
// of section marker - auto added.
}
//////////////////////////////////////////////
// Validate the just written file.
assert(glfIn.openForRead(testFile.c_str()));
// Test reading refsection with no header - exception.
caughtException = false;
try
{
assert(glfIn.getNextRefSection(glfSection) == false);
}
catch (std::exception& e)
{
caughtException = true;
}
assert(caughtException);
// Test reading record with no header - exception.
caughtException = false;
try
{
assert(glfIn.getNextRecord(record) == false);
}
catch (std::exception& e)
{
caughtException = true;
}
assert(caughtException);
readHeader(glfIn, 3);
// Test reading record with no reference section - exception.
caughtException = false;
try
{
assert(glfIn.getNextRecord(record) == false);
}
catch (std::exception& e)
{
caughtException = true;
}
assert(caughtException);
// Test reading header after already read - exception
caughtException = false;
try
{
assert(glfIn.readHeader(glfHeader) == false);
}
catch (std::exception& e)
{
caughtException = true;
}
assert(caughtException);
readRefSection1(glfIn);
readSec1Record1(glfIn);
readSec1Record2(glfIn);
readEndMarker(glfIn);
readRefSection2(glfIn);
readSec2Record1(glfIn);
readEndMarker(glfIn);
checkEOF(glfIn);
// Read again, but text reading next refsection before
//end of current section - consumes the rest of the records.
assert(glfIn.openForRead(testFile.c_str()));
readHeader(glfIn, 3);
readRefSection1(glfIn);
readRefSection2(glfIn);
readSec2Record1(glfIn);
readEndMarker(glfIn);
checkEOF(glfIn);
}
GlfFile
This class allows a user to easily read/write a GLF file.
Definition: GlfFile.h:29
GlfFile::getNextRefSection
bool getNextRefSection(GlfRefSection &refSection)
Gets the next reference section from the file & stores it in the passed in section,...
Definition: GlfFile.cpp:240
GlfFile::writeRefSection
bool writeRefSection(const GlfRefSection &refSection)
Write the reference section to the file, adding an end marker record if there is a previous section a...
Definition: GlfFile.cpp:308
GlfFile::openForWrite
bool openForWrite(const char *filename, bool compressed=true)
Open a glf file for writing with the specified filename.
Definition: GlfFile.cpp:109
GlfFile::getNextRecord
bool getNextRecord(GlfRecord &record)
Gets the nextrecord from the file & stores it in the passed in record.
Definition: GlfFile.cpp:368
GlfFile::openForRead
bool openForRead(const char *filename)
Open a glf file for reading with the specified filename.
Definition: GlfFile.cpp:66
GlfFile::close
void close()
Close the file if there is one open, adding an end marker record if there is a previous section and o...
Definition: GlfFile.cpp:142
GlfFile::writeHeader
bool writeHeader(GlfHeader &header)
Writes the specified header into the file.
Definition: GlfFile.cpp:200
GlfFile::readHeader
bool readHeader(GlfHeader &header)
Reads the header section from the file and stores it in the passed in header.
Definition: GlfFile.cpp:165
GlfFile::writeRecord
bool writeRecord(const GlfRecord &record)
Writes the specified record into the file.
Definition: GlfFile.cpp:429
GlfHeader
This class allows a user to easily get/set the fields in a GLF header.
Definition: GlfHeader.h:30
GlfRecord
This class allows a user to easily get/set the fields in a GLF record.
Definition: GlfRecord.h:29
GlfRefSection
This class allows a user to easily get/set the fields in a GLF section/chromosome header.
Definition: GlfRefSection.h:32

The documentation for this class was generated from the following files:

- glf/test/WriteFiles.h
- glf/test/WriteFiles.cpp