void MapComparer::compare() { ASSERT_NE((void *) actual, (void *) expected); //should not point to the same object ASSERT_TRUE(actual != nullptr) << "Actual map is not defined"; ASSERT_TRUE(expected != nullptr) << "Expected map is not defined"; compareHeader(); compareOptions(); compareObjects(); compareTerrain(); }
/** * Return the file format of a file by reading its header. * @param filename name of the file to test * @return file format or 0 (if no match found), or error code (<0). */ static int fromHeader(const char* filename) { const int maxheader = 8; uint8_t header[maxheader]; int nbread; FILE* file = NULL; file = fopen(filename, "rb"); if(file == NULL) { printf("Unable to open file '%s'\n", filename); return -1; } nbread = fread(header, sizeof(uint8_t), maxheader, file); fclose(file); /*test PNG*/ if(compareHeader(header, nbread, png_header, sizeof(png_header))) { return FTYPE_PNG; } /*test PXM*/ if((nbread >= 2) && (header[0] == 'P') && (header[1] >= '1') && (header[1] <= '6')) { int type = header[1]-'0'; if(type > 3) { type -= 3; } return FTYPE_PBM + type - 1; } return 0; }
Boolean FindDialog::compareMessage(DtMailMessageHandle handle) { Boolean found = False; register unsigned int offset; // // Check for something to do. // for (offset = 0; offset < _num_text_fields; offset++) { if (_text_values[offset] != NULL) { break; } } // If all fields are empty then we match anything if (offset >= _num_text_fields) { return TRUE; } if (offset < _num_text_fields && handle != NULL) { // TODO - CHECK ERROR!!! DtMailEnv error; // // Get the mail box. // DtMail::MailBox * mbox = _roamWindow->mailbox(); // // Get the DtMail::Message and Envelope for this handle. // DtMail::Message * message = mbox->getMessage(error, handle); DtMail::Envelope * envelope = message->getEnvelope(error); // // Get the meassage header. // DtMailValueSeq header; for (offset = 0; offset < _num_text_fields; offset++) { if (_text_values[offset] != NULL) { if (_text_abstract_name[offset] != NULL) { envelope->getHeader(error, _text_abstract_name[offset], DTM_TRUE, header); found = TRUE; } else { envelope->getHeader(error, _text_names[offset], DTM_FALSE, header); found = TRUE; } if (!compareHeader(error, header, _text_values[offset])) { found = False; break; } else { // Problem: if we have multiple search fields ... and use // the same "header" array ... "compareHeader" looks for // each "find" field in each (available) header field. // So, make sure only one is available for searching. // Really "offset" should be passed to "compareHeader" ... // That way, correct comparison can be done and the // memory for this array can be released correctly via the // destructor .... since "remove" fails to do so. header.remove(0); } } } if (offset > _num_text_fields) { found = TRUE; } } return(found); }
int KMailBox::countMail() { QFile mbox(_file); char *buffer = new char[MAXSTR]; int count=0, msgCount=0; bool inHeader = false; bool hasContentLen = false; bool msgRead = false; long contentLength=0; if( isLocked() ){ // debug("countMail: locked. returning."); delete[] buffer; return _numMessages; } if(!mbox.open(IO_ReadOnly)) { warning(i18n("countMail: file open error")); emit fileError(); delete[]buffer; return 0; } buffer[MAXSTR-1] = 0; while(mbox.readLine(buffer, MAXSTR-2) > 0) { if( !strchr(buffer, '\n') && !mbox.atEnd() ){ int c; while( (c=mbox.getch()) >=0 && c !='\n' ) ; } if( !inHeader && realfrom(buffer) ) { hasContentLen = false; inHeader = true; msgRead = false; } else if ( inHeader ){ if (compareHeader(buffer, "Content-Length")){ hasContentLen = true; contentLength = atol(buffer+15); } if (compareHeader(buffer, "Status")) { const char *field = buffer; field += 7; while(field && (*field== ' '||*field == '\t')) field++; if ( *field == 'N' || *field == 'U' ) msgRead = false; else msgRead = true; } else if (buffer[0] == '\n' ) { if( hasContentLen ) mbox.at( mbox.at() + contentLength); inHeader = false; if ( !msgRead ) count++; } }//in header if(++msgCount >= 100 ) { qApp->processEvents(); msgCount = 0; } }//while mbox.close(); delete[] buffer; return count; }//countMail