static inline string wbLogEntry_toJSON(wbLogEntry_t elem) { if (elem == NULL) { return ""; } else if (WB_USE_JSON11) { json11::Json json = wbLogEntry_toJSONObject(elem); return json.string_value(); } else { stringstream ss; ss << "{\n"; ss << wbString_quote("id") << ":" << wbString_quote(wbLogEntry_getId(elem)) << ",\n"; ss << wbString_quote("session_id") << ":" << wbString_quote(wbLogEntry_getSessionId(elem)) << ",\n"; ss << wbString_quote("mpi_rank") << ":" << wbString(wbLogEntry_getMPIRank(elem)) << ",\n"; ss << wbString_quote("level") << ":" << wbString_quote(getLevelName(wbLogEntry_getLevel(elem))) << ",\n"; ss << wbString_quote("message") << ":" << wbString_quote(wbLogEntry_getMessage(elem)) << ",\n"; ss << wbString_quote("file") << ":" << wbString_quote(wbLogEntry_getFile(elem)) << ",\n"; ss << wbString_quote("function") << ":" << wbString_quote(wbLogEntry_getFunction(elem)) << ",\n"; ss << wbString_quote("line") << ":" << wbLogEntry_getLine(elem) << ",\n"; ss << wbString_quote("time") << ":" << wbLogEntry_getTime(elem) << "\n"; ss << "}"; return ss.str(); } return ""; }
static wbBool wbSolution_correctQ(char *expectedOutputFile, wbSolution_t sol) { if (expectedOutputFile == NULL) { _solution_correctQ = "Failed to determined the expected output file."; return wbFalse; } else if (!wbFile_existsQ(expectedOutputFile)) { _solution_correctQ = wbString("The file ", expectedOutputFile, " does not exist."); return wbFalse; } else if (wbString_sameQ(wbSolution_getType(sol), "image")) { wbBool res; wbImage_t solutionImage = NULL; wbImage_t expectedImage = wbImport(expectedOutputFile); if (expectedImage == NULL) { _solution_correctQ = "Failed to open expected output file."; res = wbFalse; } else if (wbImage_getWidth(expectedImage) != wbSolution_getWidth(sol)) { _solution_correctQ = "The image width of the expected image does not " "match that of the solution."; res = wbFalse; } else if (wbImage_getHeight(expectedImage) != wbSolution_getHeight(sol)) { _solution_correctQ = "The image height of the expected image does not " "match that of the solution."; res = wbFalse; } else if (wbImage_getChannels(expectedImage) != wbSolution_getChannels(sol)) { _solution_correctQ = "The image channels of the expected image does not " "match that of the solution."; res = wbFalse; } else { solutionImage = (wbImage_t)wbSolution_getData(sol); wbAssert(solutionImage != NULL); res = wbImage_sameQ(solutionImage, expectedImage, _onUnsameImageFunction); } if (expectedImage != NULL) { wbImage_delete(expectedImage); } return res; } else if (wbString_sameQ(wbSolution_getType(sol), "histogram")) { return wbSolution_listCorrectQ<unsigned char>(expectedOutputFile, sol, "Integer"); } else if (wbString_sameQ(wbSolution_getType(sol), "integral_vector")) { return wbSolution_listCorrectQ<int>(expectedOutputFile, sol, "Integer"); } else if (wbString_sameQ(wbSolution_getType(sol), "vector") || wbString_sameQ(wbSolution_getType(sol), "matrix")) { return wbSolution_listCorrectQ<wbReal_t>(expectedOutputFile, sol, "Real"); } else { wbAssert(wbFalse); return wbFalse; } }
static wbBool wbSolution_correctQ(char * expectedOutputFile, wbSolution_t sol) { wbBool res; if (expectedOutputFile == NULL) { _solution_correctQ = json_string("Failed to determined the expected output file."); return wbFalse; } else if (!wbFile_existsQ(expectedOutputFile)) { string str = wbString("The file ", expectedOutputFile, " does not exist."); _solution_correctQ = json_string(str.c_str()); return wbFalse; } else if (wbString_sameQ(wbSolution_getType(sol), "image")) { wbImage_t solutionImage = NULL; wbImage_t expectedImage = wbImport(expectedOutputFile); if (expectedImage == NULL) { _solution_correctQ = json_string("Failed to open expected output file."); res = wbFalse; } else if (wbImage_getWidth(expectedImage) != wbSolution_getWidth(sol)) { _solution_correctQ = json_string("The image width of the expected image does not match that of the solution."); res = wbFalse; } else if (wbImage_getHeight(expectedImage) != wbSolution_getHeight(sol)) { _solution_correctQ = json_string("The image height of the expected image does not match that of the solution."); res = wbFalse; } else { solutionImage = (wbImage_t) wbSolution_getData(sol); wbAssert(solutionImage != NULL); res = wbImage_sameQ(solutionImage, expectedImage, _onUnsameImageFunction); } if (expectedImage != NULL) { wbImage_delete(expectedImage); } return res; } else if (wbString_sameQ(wbSolution_getType(sol), "vector") || wbString_sameQ(wbSolution_getType(sol), "matrix")) { wbReal_t * expectedData; int expectedRows, expectedColumns; expectedData = (wbReal_t *) wbImport(expectedOutputFile, &expectedRows, &expectedColumns); if (expectedData == NULL) { _solution_correctQ = json_string("Failed to open expected output file."); res = wbFalse; } else if (expectedRows != wbSolution_getRows(sol)) { wbLog(TRACE, "Number of rows in the solution is ", wbSolution_getRows(sol), ". Expected number of rows is ", expectedRows, "."); _solution_correctQ = json_string("The number of rows in the solution did not match that of the expected results."); res = wbFalse; } else if (expectedColumns != wbSolution_getColumns(sol)) { wbLog(TRACE, "Number of columns in the solution is ", wbSolution_getColumns(sol), ". Expected number of columns is ", expectedColumns, "."); _solution_correctQ = json_string("The number of columns in the solution did not match that of the expected results."); res = wbFalse; } else { int ii, jj, idx; wbReal_t * solutionData; solutionData = (wbReal_t *) wbSolution_getData(sol); for (ii = 0; ii < expectedRows; ii++) { for (jj = 0; jj < expectedColumns; jj++) { idx = ii * expectedColumns + jj; if (wbUnequalQ(expectedData[idx], solutionData[idx])) { string str; if (expectedColumns == 1) { str = wbString("The solution did not match the expected results at row ", ii, ". Expecting ", expectedData[idx], " but got ", solutionData[idx], "."); } else { str = wbString("The solution did not match the expected results at column ", jj, " and row ", ii, ". Expecting ", expectedData[idx], " but got ", solutionData[idx], "."); } _solution_correctQ = json_string(str.c_str()); res = wbFalse; goto matrixCleanup; } } } res = wbTrue; } matrixCleanup: if (expectedData != NULL) { wbFree(expectedData); } return res; } else { wbAssert(wbFalse); return wbFalse; } }
static wbBool wbSolution_listCorrectQ(const char *expectedOutputFile, wbSolution_t sol, const char *type) { wbBool res; T *expectedData; int expectedRows, expectedColumns; expectedData = (T *)wbImport(expectedOutputFile, &expectedRows, &expectedColumns, type); if (expectedData == NULL) { _solution_correctQ = "Failed to open expected output file."; res = wbFalse; } else if (expectedRows != wbSolution_getRows(sol)) { wbLog(TRACE, "Number of rows in the solution is ", wbSolution_getRows(sol), ". Expected number of rows is ", expectedRows, "."); _solution_correctQ = "The number of rows in the solution did not match " "that of the expected results."; res = wbFalse; } else if (expectedColumns != wbSolution_getColumns(sol)) { wbLog(TRACE, "Number of columns in the solution is ", wbSolution_getColumns(sol), ". Expected number of columns is ", expectedColumns, "."); _solution_correctQ = "The number of columns in the solution did not " "match that of the expected results."; res = wbFalse; } else { int ii, jj, idx; T *solutionData; solutionData = (T *)wbSolution_getData(sol); for (ii = 0; ii < expectedRows; ii++) { for (jj = 0; jj < expectedColumns; jj++) { idx = ii * expectedColumns + jj; if (wbUnequalQ(expectedData[idx], solutionData[idx])) { string str; if (expectedColumns == 1) { str = wbString( "The solution did not match the expected results at row ", ii, ". Expecting ", expectedData[idx], " but got ", solutionData[idx], "."); } else { str = wbString("The solution did not match the expected " "results at column ", jj, " and row ", ii, ". Expecting ", expectedData[idx], " but got ", solutionData[idx], "."); } _solution_correctQ = str; res = wbFalse; goto matrixCleanup; } } } res = wbTrue; matrixCleanup: if (expectedData != NULL) { wbFree(expectedData); } } return res; }
void wbFile_writeLine(wbFile_t file, const char *buffer0) { string buffer = wbString(buffer0, "\n"); wbFile_write(file, buffer.c_str()); }