libStatGen Software
1
|
00001 /* 00002 * Copyright (C) 2010 Regents of the University of Michigan 00003 * 00004 * This program is free software: you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation, either version 3 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 */ 00017 00018 #include "SamFileTest.h" 00019 #include "SamFile.h" 00020 00021 void testSamFile() 00022 { 00023 SamFileHeader header; 00024 00025 // Test open for read via the constructor with return. 00026 SamFile samInConstructorReadDefault("testFiles/testSam.sam", 00027 SamFile::READ, 00028 ErrorHandler::RETURN); 00029 assert(samInConstructorReadDefault.WriteHeader(header) == false); 00030 assert(samInConstructorReadDefault.ReadHeader(header) == true); 00031 00032 // Test open for write via the constructor. 00033 SamFile samInConstructorWrite("results/newWrite.sam", SamFile::WRITE, 00034 ErrorHandler::RETURN); 00035 assert(samInConstructorWrite.ReadHeader(header) == false); 00036 assert(samInConstructorWrite.WriteHeader(header) == true); 00037 00038 // Test open for read via the constructor 00039 SamFile samInConstructorRead("testFiles/testSam.sam", SamFile::READ); 00040 bool caughtException = false; 00041 try 00042 { 00043 assert(samInConstructorRead.WriteHeader(header) == false); 00044 } 00045 catch (std::exception& e) 00046 { 00047 caughtException = true; 00048 } 00049 assert(caughtException); 00050 assert(samInConstructorRead.ReadHeader(header) == true); 00051 00052 // Test open for write via child class. 00053 SamFileWriter samWriteConstructor("results/newWrite1.sam"); 00054 caughtException = false; 00055 try 00056 { 00057 assert(samWriteConstructor.ReadHeader(header) == false); 00058 } 00059 catch (std::exception& e) 00060 { 00061 caughtException = true; 00062 } 00063 assert(caughtException); 00064 assert(samWriteConstructor.WriteHeader(header) == true); 00065 00066 // Test open for read via child class. 00067 SamFileReader samReadConstructor("testFiles/testSam.sam"); 00068 caughtException = false; 00069 try 00070 { 00071 assert(samReadConstructor.WriteHeader(header) == false); 00072 } 00073 catch (std::exception& e) 00074 { 00075 caughtException = true; 00076 } 00077 assert(caughtException); 00078 assert(samReadConstructor.ReadHeader(header) == true); 00079 }