// Adds the rows supposed to go into the natural join relation void addRows(_Relation* naturalJoin, _Relation* crossRelation) { vector<string> names; for (int i = 0; i < crossRelation->Columns.size(); ++i) { names.push_back(crossRelation->Columns[i].Name); } for (int i = 0; i < crossRelation->Columns[0].Rows.size(); ++i) { bool addRow; addRow = compareRow(crossRelation, i); if (addRow) { addRowToNJ(naturalJoin, crossRelation, i); } } }
bool QgsRasterChecker::runTest( QString theVerifiedKey, QString theVerifiedUri, QString theExpectedKey, QString theExpectedUri ) { bool ok = true; mReport += "\n\n"; //QgsRasterDataProvider* verifiedProvider = QgsRasterLayer::loadProvider( theVerifiedKey, theVerifiedUri ); QgsRasterDataProvider* verifiedProvider = ( QgsRasterDataProvider* ) QgsProviderRegistry::instance()->provider( theVerifiedKey, theVerifiedUri ); if ( !verifiedProvider || !verifiedProvider->isValid() ) { error( QString( "Cannot load provider %1 with URI: %2" ).arg( theVerifiedKey ).arg( theVerifiedUri ), mReport ); ok = false; } //QgsRasterDataProvider* expectedProvider = QgsRasterLayer::loadProvider( theExpectedKey, theExpectedUri ); QgsRasterDataProvider* expectedProvider = ( QgsRasterDataProvider* ) QgsProviderRegistry::instance()->provider( theExpectedKey, theExpectedUri ); if ( !expectedProvider || !expectedProvider->isValid() ) { error( QString( "Cannot load provider %1 with URI: %2" ).arg( theExpectedKey ).arg( theExpectedUri ), mReport ); ok = false; } if ( !ok ) return false; mReport += QString( "Verified URI: %1<br>" ).arg( theVerifiedUri.replace( "&", "&" ) ); mReport += QString( "Expected URI: %1<br>" ).arg( theExpectedUri.replace( "&", "&" ) ); mReport += "<br>"; mReport += QString( "<table style='%1'>\n" ).arg( mTabStyle ); mReport += compareHead(); compare( "Band count", verifiedProvider->bandCount(), expectedProvider->bandCount(), mReport, ok ); compare( "Width", verifiedProvider->xSize(), expectedProvider->xSize(), mReport, ok ); compare( "Height", verifiedProvider->ySize(), expectedProvider->ySize(), mReport, ok ); compareRow( "Extent", verifiedProvider->extent().toString(), expectedProvider->extent().toString(), mReport, verifiedProvider->extent() == expectedProvider->extent() ); if ( verifiedProvider->extent() != expectedProvider->extent() ) ok = false; mReport += "</table>\n"; if ( !ok ) return false; bool allOk = true; for ( int band = 1; band <= expectedProvider->bandCount(); band++ ) { bool bandOk = true; mReport += QString( "<h3>Band %1</h3>\n" ).arg( band ); mReport += QString( "<table style='%1'>\n" ).arg( mTabStyle ); mReport += compareHead(); // Data types may differ (?) bool typesOk = true; compare( "Source data type", verifiedProvider->srcDataType( band ), expectedProvider->srcDataType( band ), mReport, typesOk ); compare( "Data type", verifiedProvider->dataType( band ), expectedProvider->dataType( band ), mReport, typesOk ) ; // TODO: not yet sure if noDataValue() should exist at all //compare( "No data (NULL) value", verifiedProvider->noDataValue( band ), expectedProvider->noDataValue( band ), mReport, typesOk ); bool statsOk = true; QgsRasterBandStats verifiedStats = verifiedProvider->bandStatistics( band ); QgsRasterBandStats expectedStats = expectedProvider->bandStatistics( band ); // Min/max may 'slightly' differ, for big numbers however, the difference may // be quite big, for example for Float32 with max -3.332e+38, the difference is 1.47338e+24 double tol = tolerance( expectedStats.minimumValue ); compare( "Minimum value", verifiedStats.minimumValue, expectedStats.minimumValue, mReport, statsOk, tol ); tol = tolerance( expectedStats.maximumValue ); compare( "Maximum value", verifiedStats.maximumValue, expectedStats.maximumValue, mReport, statsOk, tol ); // TODO: enable once fixed (WCS excludes nulls but GDAL does not) //compare( "Cells count", verifiedStats.elementCount, expectedStats.elementCount, mReport, statsOk ); tol = tolerance( expectedStats.mean ); compare( "Mean", verifiedStats.mean, expectedStats.mean, mReport, statsOk, tol ); // stdDev usually differ significantly tol = tolerance( expectedStats.stdDev, 1 ); compare( "Standard deviation", verifiedStats.stdDev, expectedStats.stdDev, mReport, statsOk, tol ); mReport += "</table>"; mReport += "<br>"; if ( !bandOk ) { allOk = false; continue; } if ( !statsOk || !typesOk ) { allOk = false; // create values table anyway so that values are available } mReport += "<table><tr>"; mReport += "<td>Data comparison</td>"; mReport += QString( "<td style='%1 %2 border: 1px solid'>correct value</td>" ).arg( mCellStyle ).arg( mOkStyle ); mReport += "<td></td>"; mReport += QString( "<td style='%1 %2 border: 1px solid'>wrong value<br>expected value</td></tr>" ).arg( mCellStyle ).arg( mErrStyle ); mReport += "</tr></table>"; mReport += "<br>"; int width = expectedProvider->xSize(); int height = expectedProvider->ySize(); QgsRasterBlock *expectedBlock = expectedProvider->block( band, expectedProvider->extent(), width, height ); QgsRasterBlock *verifiedBlock = verifiedProvider->block( band, expectedProvider->extent(), width, height ); if ( !expectedBlock || !expectedBlock->isValid() || !verifiedBlock || !verifiedBlock->isValid() ) { allOk = false; mReport += "cannot read raster block"; continue; } // compare data values QString htmlTable = QString( "<table style='%1'>" ).arg( mTabStyle ); for ( int row = 0; row < height; row ++ ) { htmlTable += "<tr>"; for ( int col = 0; col < width; col ++ ) { bool cellOk = true; double verifiedVal = verifiedBlock->value( row, col ); double expectedVal = expectedBlock->value( row, col ); QString valStr; if ( compare( verifiedVal, expectedVal, 0 ) ) { valStr = QString( "%1" ).arg( verifiedVal ); } else { cellOk = false; allOk = false; valStr = QString( "%1<br>%2" ).arg( verifiedVal ).arg( expectedVal ); } htmlTable += QString( "<td style='%1 %2'>%3</td>" ).arg( mCellStyle ).arg( cellOk ? mOkStyle : mErrStyle ).arg( valStr ); } htmlTable += "</tr>"; } htmlTable += "</table>"; mReport += htmlTable; delete expectedBlock; delete verifiedBlock; } delete verifiedProvider; delete expectedProvider; return allOk; }
void QgsRasterChecker::compare( QString theParamName, double verifiedVal, double expectedVal, QString &theReport, bool &theOk, double theTolerance ) { bool ok = compare( verifiedVal, expectedVal, theTolerance ); compareRow( theParamName, QString::number( verifiedVal ), QString::number( expectedVal ), theReport, ok, QString::number( verifiedVal - expectedVal ), QString::number( theTolerance ) ); if ( !ok ) theOk = false; }
void QgsRasterChecker::compare( QString theParamName, int verifiedVal, int expectedVal, QString &theReport, bool &theOk ) { bool ok = verifiedVal == expectedVal; compareRow( theParamName, QString::number( verifiedVal ), QString::number( expectedVal ), theReport, ok, QString::number( verifiedVal - expectedVal ) ); if ( !ok ) theOk = false; }
int16_t vt100_compareVD(const char *pFileName) { int16_t i=0, j=0; // for loops parsing strings of text, etc. char lineBuffer[LINE_BUFFER_SIZE]; // Vir. Display (40 chars wide) allocate extra char *ptrSC = NULL; // pointer to play with special chars arrays int16_t numSpecChars = 0; // count # of defined Special Chars with non-zero bitmaps int16_t numSpecCols = 0; // number of vertical bitmap columns in this special character int16_t specCharNumber = 0; // which special character are we processing int valueSC = 0; // pull value from the array for compare int16_t errorSC = 0; // flag an SC error int16_t compareStage = COMPARE_TEXT; // 8 stages of compares: 1st one: text, then attribs, tabs, parms, cursor, Spec chars int16_t compareResult = 0; int row = 0; // for text and attribute compares int col = 0; // " " " " int err = 0; // for file I/O error returns static FILE *pFile; // FILE Handle static VIRTUAL_DISPLAY *VD_ptr; // our VIRTUAL DISPLAY int16_t lineCounter = 0; char **pTextArray = vDisplay.pText; // set up the malloc'd data area pointers char **pAttribsArray = vDisplay.pAttribs; char *pRowText = NULL; char *pRowAttribs = NULL; USERINT_PARAM *pOtherParms = NULL; int fileParmValue = 0; char errorBuffer[100] = { '\0','\0','\0','\0','\0','\0' }; // buffer for error string generation - put a few zero bytes to show not used yet VD_ptr = &vDisplay; if( (pFile = fopen(pFileName, "r" )) == NULL) { return( vt100_set_errorCode(ERR_01_FILE_OPEN) ); } // Concept - like a state machine with 5 stages: // 1. Compare the text array // 2. Compare the attributes array // 3. Compare the Tabs array // 4. Compare the other data parameters // 5. Compare the Cursor Position (row and column) // 6. Compare the Special Char # of columns per SC array // 7. Compare the Special Character Bitmaps per each SC // 8. Compare Completed OKAY! // //pthread_mutex_lock(&vDisplay.mutex); usleep(11000); while ( compareStage < COMPARE_COMPLETE ) { // read a line at a time to compare with the VD if( fgets(lineBuffer, LINE_LENGTH, pFile ) == (char *) 0 ) { // end of file break; } if( lineBuffer[0] == '#' ) // bypass comment lines { #if DEBUG_ON & DEBUG_PARM_MATCH if( compareStage == COMPARE_PARMS ) printf("\n %s", lineBuffer); #endif continue; // bypass comments - get next line into buffer } lineCounter++; // only counting good data lines and not comments #if DEBUG_ON & DEBUG_PARM_MATCH // #if DEBUG_ON & DEBUG_SPECIAL printf("\n %d: %s", lineCounter, lineBuffer); #endif if( (compareStage == COMPARE_TEXT) || (compareStage == COMPARE_ATTRIBS) ) { // Compare the Text are and the Attributes row by row first // compare the file's line to the display row (text or attributes) if( compareStage == COMPARE_TEXT ) { pRowText = pTextArray[row]; compareResult = compareRow(pRowText, lineBuffer, numCols); } else // compare stage == COMPARE_ATTRIBS { pRowAttribs = pAttribsArray[row]; compareResult = compareRow(pRowAttribs, lineBuffer, numCols); } if( compareResult != 0 ) { // this row did not compare vt100_set_errorCode(ERR_11_VD_MATCH_ERR); if(compareStage == COMPARE_TEXT){ sprintf(errorBuffer,"ERR_11: VD Text differs: row # %d: %s ", row, pRowText); } else { sprintf(errorBuffer,"ERR_11: VD Attrib differs: row # %d: %s ", row, pRowAttribs); } #if DEBUG_ON printf("\n %s \n", errorBuffer); #endif vt100_set_errorText(errorBuffer); break; } // set up for next row if not at end of text if( row == numRows - 1) { // just processed the last row - if text, switch to attribs if( compareStage == COMPARE_ATTRIBS ) { // all done processing attributes - now compare other data items compareStage = COMPARE_TABS; } else { // switch over to the attributes array compare for rows & columns compareStage = COMPARE_ATTRIBS; row = 0; } } else if( row < (numRows -1)) { // do next row row++; } else { /// should never ever hit here ; #if DEBUG_ON printf("\n vt100_compareVD: out of bounds error - row # %d, compareStage = %d \n", row, compareStage); #endif } } // end - text & attributes area - stages 1 & 2 else if( (compareStage > COMPARE_ATTRIBS) & (compareStage <= COMPARE_CURSOR) ) { // Compare Tabs and other parameters - stages 3, 4 & 5 if(compareStage == COMPARE_TABS) { // compare Tabs array #if DEBUGON & DEBUG_TABS printf("\n TABS: file %s \n : VD %s \n", lineBuffer, tabStops); #endif for(col = 0; col < numCols ; col++ ) { if(lineBuffer[col] != tabStops[col]) { vt100_set_errorCode(ERR_11_VD_MATCH_ERR); sprintf(errorBuffer,"ERR_11: VD TabStops Differ at col %d: %s ", col, tabStops); vt100_set_errorText(errorBuffer); compareResult = 1; // mismatch break; } } if( compareResult == 0 ){ // good compare on Tabs pOtherParms = vt100_get_otherParameters(); compareStage = COMPARE_PARMS; } else { break; } } // endif - compare Tabs else if(compareStage == COMPARE_PARMS ) { // OTHER PARAMETERS COMPARE // compare the other parameters of the VD against the file values if( pOtherParms->pUI_value == NULL ) // at the end of the list? { // compareResult = 0; // should already be = 0 ; good result - all values compare okay compareStage = COMPARE_CURSOR; } else { sscanf(lineBuffer, "%d", &fileParmValue); #if DEBUG_ON & DEBUG_PARM_MATCH printf("\nPARAM %s: VD value: %d, file value: %d", pOtherParms->pUI_name, (int) pOtherParms->pUI_value[0], (int) fileParmValue); #endif if(pOtherParms->pUI_value[0] != fileParmValue ) { vt100_set_errorCode(ERR_11_VD_MATCH_ERR); sprintf(errorBuffer,"ERR_11: VD Param %s differs: VD: %d ; file value: %d:", pOtherParms->pUI_name, (int) pOtherParms->pUI_value[0], (int) fileParmValue); #if DEBUG_ON & DEBUG_PARM_MATCH printf("\n PARAM miscompare on %s : errorBuffer: %s \n", pOtherParms->pUI_name, errorBuffer); #endif vt100_set_errorText(errorBuffer); compareResult = 1; // mismatch in parameter compare break; } else { #if DEBUG_ON & DEBUG_PARM_MATCH printf("\n vt100_compare: VD parameter: %s value %d matches file value: %d \n", pOtherParms->pUI_name, (int) pOtherParms->pUI_value[0], fileParmValue); #endif pOtherParms++; // go to next parameter } } // end - else } // end if - compare other Parameters #if DEBUG_ON & DEBUG_PARM_MATCH printf("\nvt100_compare - lineCounter = %d , compareStage = %d, lineBuffer: %s ", lineCounter, compareStage, lineBuffer ); #endif // go right into compare cursor because the line has already been read // and we ran out of parameters (reached the "NULL, NULL" entry! if (compareStage == COMPARE_CURSOR) { sscanf(lineBuffer, "%d,%d", &row, &col); if( (row != cursorPos.cp_row +1 ) || (col != cursorPos.cp_col +1) ) { vt100_set_errorCode(ERR_11_VD_MATCH_ERR); sprintf(errorBuffer,"ERR_11: VD Cursor Position differs: VD: %d,%d ; file value: %d, %d ", cursorPos.cp_row + 1, cursorPos.cp_col + 1, row, col); #if DEBUG_ON & DEBUG_PARM_MATCH printf("\n vt100_compareVD: %s ", errorBuffer); printf("\n lineBuffer is: %s", lineBuffer); #endif vt100_set_errorText(errorBuffer); #if DEBUG_ON printf("\n vt100_compareVD: get ErrorText returns: %s \n", vt100_get_errorText() ); #endif compareResult = 1; // mismatch in parameter compare break; // stop the insanity - get out now! } else { compareStage = COMPARE_SPEC_SIZES; // have to absorb the "Saved Cursor Pos" line // not a compared value } } // endif - compare cursor position } // endelse - Tabs, Parms & Cursor else if( compareStage > COMPARE_CURSOR ) { if(compareStage == COMPARE_SPEC_SIZES ) { // have to absorb the first line (saved cursor position) // our lines start out with a space character if( lineBuffer[0] == ' ') // first time through will see a 1,1 saved cursor and will bypass { ptrSC = &lineBuffer[3]; errorSC = 0; numSpecChars = 0; #if DEBUG_ON & DEBUG_SPECIAL printf("\n Compare Special array column sizes: %s", lineBuffer); #endif for(i = 0; i < NUMBER_OF_SPEC_CHARS; i++) { sscanf(ptrSC, "%1d,", &valueSC); if( valueSC != specialCharColumns[i] ) // are they the same size (# of vertical columns?) { errorSC = TRUE; vt100_set_errorCode(ERR_11_VD_MATCH_ERR); sprintf(errorBuffer,"ERR_11: VD SpecChar %d differs in # of cols. VD: %d ; file value: %d", i+1, specialCharColumns[i], valueSC ); #if DEBUG_ON & DEBUG_SPECIAL printf("\n vt100_compareVD: %s ", errorBuffer); printf("\n lineBuffer is: %s", lineBuffer); #endif vt100_set_errorText(errorBuffer); break; } else { if( specialCharColumns[i] > 0 ) { numSpecChars++; } ptrSC += 3; /// move to next col value - 1 digit, 1 comma, 1 space char } } // end - for loop on sizes (# of cols) if( errorSC) { compareResult = 1; break; } else { if( numSpecChars > 0 ) { compareStage = COMPARE_SPEC_BITMAPS; } else { compareStage = COMPARE_GRAPHIC_MODE; } } } #if DEBUG_ON & DEBUG_SPECIAL printf("\n COMPARE: - number of special characters found = %d : %s ", numSpecChars, lineBuffer); #endif } // endif - COMPARE_SPEC_SIZES else if( compareStage == COMPARE_SPEC_BITMAPS ) // COMPARE the Bit-Mapped Special Chars { errorSC = FALSE; specCharNumber = (int16_t) (lineBuffer[3] - (uint8_t) 0x30); numSpecCols = (int16_t) (lineBuffer[9] - (uint8_t) 0x30); ptrSC = &lineBuffer[13]; #if DEBUG_ON & DEBUG_SPECIAL printf("\n BITMAP SC # %d, # cols %d:\n line: %s ", specCharNumber, numSpecCols, lineBuffer); #endif for(j = 0; j < numSpecCols; j++) { sscanf(ptrSC, "%d", &valueSC); if( valueSC != specialChars[specCharNumber - 1][j] ) { errorSC = TRUE; vt100_set_errorCode(ERR_11_VD_MATCH_ERR); sprintf(errorBuffer,"ERR_11: VD SpecChar %d bitmap mismatch; Pn col# %d. VD: %d ; file value: %d", specCharNumber, j+1, specialChars[specCharNumber - 1][j], valueSC ); #if DEBUG_ON & DEBUG_SPECIAL printf("\n :::::::::::::::::::::::::::::::::::::::::::"); printf("\n Bitmap miscompare on col # %d: err msg: %s ", j+1, errorBuffer); printf("\n Special Char # %d col value is %d [0x%02x] ", specCharNumber, specialChars[specCharNumber - 1][j], specialChars[specCharNumber - 1][j] ); printf("\n lineBuffer is: %s", lineBuffer); printf("\n :::::::::::::::::::::::::::::::::::::::::::"); #endif vt100_set_errorText(errorBuffer); break; } else { ptrSC += 4; /// move to next col value - 3 digits plus 1 space char } } // end for loop on bitmaps if( errorSC ) { compareResult = 1; break; } else { numSpecChars--; if( numSpecChars <= 0 ) { compareStage = COMPARE_GRAPHIC_MODE; } } } else if (compareStage == COMPARE_GRAPHIC_MODE) { sscanf(lineBuffer, "%x", &fileParmValue); if( graphicModeFlags != fileParmValue ) { vt100_set_errorCode(ERR_11_VD_MATCH_ERR); sprintf(errorBuffer,"ERR_11: VD Graphic Mode differs: VD: %02x ; file value: %02x:", (int) graphicModeFlags, (int) fileParmValue); vt100_set_errorText(errorBuffer); compareResult = 1; // mismatch in parameter compare #if DEBUG_ON printf("\n vt100_compareVD: get ErrorText returns: %s \n", vt100_get_errorText() ); #endif break; } else { compareStage = COMPARE_COMPLETE; } } } // endif - compareStage > COMPARE_CURSOR } // end - while ( 1) //pthread_mutex_unlock(&vDisplay.mutex); if( compareStage != COMPARE_COMPLETE) // check for incomplete "compare file" without all the "stages" { if( errorBuffer[0] == '\0') // not here because of a break on a prior error { vt100_set_errorCode(ERR_12_COMPARE_FILE); sprintf(errorBuffer,"ERR_12: compare file '%s' problem - premature termination of compares. File may be incomplete.", pFileName); vt100_set_errorText(errorBuffer); compareResult = 1; // mismatch in parameter compare } } if( (err = fclose(pFile ))!= 0 ) { #if DEBUG_ON & DEBUG_FILE_IO printf("\n vt100_compareVD - file close error %d \n", err ); #endif return( vt100_set_errorCode(ERR_04_FILE_CLOSE) ); } return(compareResult); } // end vt100_compareVD()