ValidationTest.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "SamRecord.h"
00019 #include "SamValidation.h"
00020 #include "ValidationTest.h"
00021 #include <assert.h>
00022
00023 void testSamQNAME()
00024 {
00025
00026
00027
00028
00029 char qname[256];
00030 SamFileHeader samHeader;
00031 SamRecord testRecord(ErrorHandler::RETURN);
00032
00033 SamValidationErrors errorList;
00034
00035
00036 qname[0] = 0;
00037
00038 assert(testRecord.setReadName(qname) == false);
00039 assert(strcmp(testRecord.getReadName(), "UNKNOWN") == 0);
00040
00041 assert(SamValidator::isValid(samHeader, testRecord, errorList) == true);
00042 assert(errorList.numErrors() == 0);
00043 assert(errorList.getNextError() == NULL);
00044
00045
00046 memset(qname, '.', 255);
00047 qname[255] = 0;
00048 assert(testRecord.setReadName(qname) == true);
00049 assert(strcmp(testRecord.getReadName(), qname) == 0);
00050 assert(SamValidator::isValid(samHeader, testRecord, errorList) == false);
00051
00052
00053
00054 assert(errorList.numErrors() == 2);
00055 assert(errorList.getNextError()->getType() ==
00056 SamValidationError::INVALID_QNAME);
00057 assert(errorList.getNextError()->getType() ==
00058 SamValidationError::INVALID_QNAME);
00059 assert(errorList.getNextError() == NULL);
00060
00061
00062 errorList.clear();
00063
00064
00065 int bufferBlockSize = 32;
00066
00067 bamRecordStruct* bufferRecordPtr =
00068 (bamRecordStruct *) malloc(bufferBlockSize + sizeof(int));
00069
00070 bufferRecordPtr->myBlockSize = bufferBlockSize;
00071 bufferRecordPtr->myReferenceID = -1;
00072 bufferRecordPtr->myPosition = 1010;
00073
00074 bufferRecordPtr->myReadNameLength = 0;
00075 bufferRecordPtr->myMapQuality = 0;
00076 bufferRecordPtr->myBin = 4681;
00077 bufferRecordPtr->myCigarLength = 0;
00078 bufferRecordPtr->myFlag = 73;
00079 bufferRecordPtr->myReadLength = 0;
00080 bufferRecordPtr->myMateReferenceID = -1;
00081 bufferRecordPtr->myMatePosition = 1010;
00082 bufferRecordPtr->myInsertSize = 0;
00083
00084 assert(testRecord.setBuffer((const char*)bufferRecordPtr,
00085 bufferBlockSize + sizeof(int),
00086 samHeader) == SamStatus::SUCCESS);
00087
00088 assert(SamValidator::isValid(samHeader, testRecord, errorList) == false);
00089 assert(errorList.numErrors() == 1);
00090 assert(errorList.getNextError()->getType() ==
00091 SamValidationError::INVALID_QNAME);
00092 assert(errorList.getNextError() == NULL);
00093
00094
00095 errorList.clear();
00096
00097
00098
00099 bufferBlockSize = 40;
00100 bufferRecordPtr->myBlockSize = bufferBlockSize;
00101
00102 bufferRecordPtr->myReadNameLength = 8;
00103 bufferRecordPtr->myData[0] = 'H';
00104 bufferRecordPtr->myData[1] = 'I';
00105 bufferRecordPtr->myData[2] = 0;
00106
00107 assert(testRecord.setBuffer((const char*)bufferRecordPtr,
00108 bufferBlockSize + sizeof(int),
00109 samHeader) == SamStatus::SUCCESS);
00110
00111
00112 assert(SamValidator::isValid(samHeader, testRecord, errorList) == false);
00113 assert(errorList.numErrors() == 1);
00114 assert(errorList.getNextError()->getType() ==
00115 SamValidationError::INVALID_QNAME);
00116 assert(errorList.getNextError() == NULL);
00117
00118
00119 errorList.clear();
00120
00121
00122
00123 bufferBlockSize = 34;
00124 bufferRecordPtr->myBlockSize = bufferBlockSize;
00125
00126 bufferRecordPtr->myReadNameLength = 2;
00127 bufferRecordPtr->myData[0] = 'H';
00128 bufferRecordPtr->myData[1] = 'I';
00129 bufferRecordPtr->myData[2] = 0;
00130
00131 assert(testRecord.setBuffer((const char*)bufferRecordPtr,
00132 bufferBlockSize + sizeof(int),
00133 samHeader) == SamStatus::SUCCESS);
00134
00135
00136 assert(SamValidator::isValid(samHeader, testRecord, errorList) == false);
00137 assert(errorList.numErrors() == 1);
00138 assert(errorList.getNextError()->getType() ==
00139 SamValidationError::INVALID_QNAME);
00140 assert(errorList.getNextError() == NULL);
00141
00142
00143 errorList.clear();
00144 }
00145
00146
00147 void testBamRID()
00148 {
00149
00150 SamRecord testRecord(ErrorHandler::RETURN);
00151
00152 SamValidationErrors errorList;
00153 SamFileHeader samHeader;
00154
00155
00156 errorList.clear();
00157
00158
00159 int bufferBlockSize = 35;
00160
00161 bamRecordStruct* bufferRecordPtr =
00162 (bamRecordStruct *) malloc(bufferBlockSize + sizeof(int));
00163
00164 bufferRecordPtr->myBlockSize = bufferBlockSize;
00165 bufferRecordPtr->myPosition = 1010;
00166 bufferRecordPtr->myReferenceID = -1;
00167
00168 bufferRecordPtr->myReadNameLength = 3;
00169 bufferRecordPtr->myMapQuality = 0;
00170 bufferRecordPtr->myBin = 4681;
00171 bufferRecordPtr->myCigarLength = 0;
00172 bufferRecordPtr->myFlag = 73;
00173 bufferRecordPtr->myReadLength = 0;
00174 bufferRecordPtr->myMateReferenceID = -1;
00175 bufferRecordPtr->myMatePosition = 1010;
00176 bufferRecordPtr->myInsertSize = 0;
00177 bufferRecordPtr->myData[0] = 'H';
00178 bufferRecordPtr->myData[1] = 'I';
00179 bufferRecordPtr->myData[2] = 0;
00180
00181
00182
00183 bufferRecordPtr->myReferenceID = 100;
00184
00185 assert(testRecord.setBuffer((const char*)bufferRecordPtr,
00186 bufferBlockSize + sizeof(int),
00187 samHeader) == SamStatus::SUCCESS);
00188
00189 assert(SamValidator::isValid(samHeader, testRecord, errorList) == false);
00190 assert(errorList.numErrors() == 1);
00191 assert(errorList.getNextError()->getType() ==
00192 SamValidationError::INVALID_REF_ID);
00193 assert(errorList.getNextError() == NULL);
00194
00195
00196 errorList.clear();
00197
00198
00199
00200 bufferRecordPtr->myReferenceID = -100;
00201
00202 assert(testRecord.setBuffer((const char*)bufferRecordPtr,
00203 bufferBlockSize + sizeof(int),
00204 samHeader) == SamStatus::SUCCESS);
00205
00206 assert(SamValidator::isValid(samHeader, testRecord, errorList) == false);
00207 assert(errorList.numErrors() == 1);
00208 assert(errorList.getNextError()->getType() ==
00209 SamValidationError::INVALID_REF_ID);
00210 assert(errorList.getNextError() == NULL);
00211
00212
00213 errorList.clear();
00214 }
00215
00216
00217 void testEmptyQual()
00218 {
00219
00220 }
00221