libStatGen Software 1
SamFileTest.cpp
1/*
2 * Copyright (C) 2010 Regents of the University of Michigan
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "SamFileTest.h"
19#include "SamFile.h"
20
21void testSamFile()
22{
23 SamFileHeader header;
24
25 // Test open for read via the constructor with return.
26 SamFile samInConstructorReadDefault("testFiles/testSam.sam",
29 assert(samInConstructorReadDefault.WriteHeader(header) == false);
30 assert(samInConstructorReadDefault.ReadHeader(header) == true);
31
32 // Test open for write via the constructor.
33 SamFile samInConstructorWrite("results/newWrite.sam", SamFile::WRITE,
35 assert(samInConstructorWrite.ReadHeader(header) == false);
36 assert(samInConstructorWrite.WriteHeader(header) == true);
37
38 // Test open for read via the constructor
39 SamFile samInConstructorRead("testFiles/testSam.sam", SamFile::READ);
40 bool caughtException = false;
41 try
42 {
43 assert(samInConstructorRead.WriteHeader(header) == false);
44 }
45 catch (std::exception& e)
46 {
47 caughtException = true;
48 }
49 assert(caughtException);
50 assert(samInConstructorRead.ReadHeader(header) == true);
51
52 // Test open for write via child class.
53 SamFileWriter samWriteConstructor("results/newWrite1.sam");
54 caughtException = false;
55 try
56 {
57 assert(samWriteConstructor.ReadHeader(header) == false);
58 }
59 catch (std::exception& e)
60 {
61 caughtException = true;
62 }
63 assert(caughtException);
64 assert(samWriteConstructor.WriteHeader(header) == true);
65
66 // Test open for read via child class.
67 SamFileReader samReadConstructor("testFiles/testSam.sam");
68 caughtException = false;
69 try
70 {
71 assert(samReadConstructor.WriteHeader(header) == false);
72 }
73 catch (std::exception& e)
74 {
75 caughtException = true;
76 }
77 assert(caughtException);
78 assert(samReadConstructor.ReadHeader(header) == true);
79}
@ RETURN
just return failure on the error
Definition: ErrorHandler.h:31
This class allows a user to get/set the fields in a SAM/BAM Header.
Definition: SamFileHeader.h:35
Child class of SamFile for reading files.
Definition: SamFile.h:461
Child class of SamFile for writing files.
Definition: SamFile.h:491
Allows the user to easily read/write a SAM/BAM file.
Definition: SamFile.h:36
@ READ
open for reading.
Definition: SamFile.h:40
@ WRITE
open for writing.
Definition: SamFile.h:41