예제 #1
0
BOOL wbIsWBObj(void *pwbo, BOOL bShowErrors)
{
	if(!pwbo) {
		if(bShowErrors)
			wbError(__FUNCTION__, MB_ICONWARNING, "NULL WinBinder object");
		return FALSE;
	}

	// Is pwbo a valid memory address?

	if(IsBadReadPtr(pwbo, sizeof(WBOBJ))) {
		if(bShowErrors)
			wbError(__FUNCTION__, MB_ICONWARNING, "Invalid memory address");
//		printf("%d\n", pwbo);
		return FALSE;
	}

	// A Windows or menu handle is not a WinBinder object

	if(IsWindow(pwbo) || IsMenu(pwbo)) {
		if(bShowErrors)
			wbError(__FUNCTION__, MB_ICONWARNING, "Not a WinBinder object");
		return FALSE;
	}

	// Does it have a valid handle?

	{
		PWBOBJ pwboTest = wbMalloc(sizeof(WBOBJ));
		if(pwboTest) {
			CopyMemory(pwboTest, pwbo, sizeof(WBOBJ));

			if(!pwboTest->hwnd) {
				wbFree(pwboTest);
				if(bShowErrors)
					wbError(__FUNCTION__, MB_ICONWARNING, "NULL WinBinder object handle");
				return FALSE;
			}
			wbFree(pwboTest);
		}
	}

	if(IsMenu((HMENU)((PWBOBJ)pwbo)->hwnd))
		return TRUE;

	if(IsWindow((HWND)((PWBOBJ)pwbo)->hwnd))
		return TRUE;

	if(bShowErrors)
		wbError(__FUNCTION__, MB_ICONWARNING, "Invalid WinBinder object");

	return FALSE;
}
예제 #2
0
파일: wbLogger.cpp 프로젝트: RustIron/libwb
static inline void wbLogEntry_delete(wbLogEntry_t elem) {
  if (elem != NULL) {
    if (wbLogEntry_getMessage(elem) != NULL) {
      wbFree(wbLogEntry_getMessage(elem));
    }
    wbDelete(elem);
  }
  return;
}
예제 #3
0
wbBool wbSolution(char *expectedOutputFile, char *outputFile, char *type0,
                  void *data, int rows, int columns, int depth) {
  char *type;
  wbBool res;
  wbSolution_t sol;

  if (expectedOutputFile == NULL || data == NULL || type0 == NULL) {
    wbLog(ERROR, "Failed to grade solution");
    return wbFalse;
  }

  type = wbString_toLower(type0);

  if (_solution_correctQ != "") {
    _solution_correctQ = "";
  }

  wbSolution_setOutputFile(sol, outputFile);
  wbSolution_setId(sol, uuid());
  wbSolution_setSessionId(sol, sessionId());
  wbSolution_setType(sol, type);
  wbSolution_setData(sol, data);
  wbSolution_setRows(sol, rows);
  wbSolution_setColumns(sol, columns);
  wbSolution_setDepth(sol, depth);

  res = wbSolution_correctQ(expectedOutputFile, sol);

  if (outputFile != NULL) {
    if (wbString_sameQ(type, "image")) {
      wbImage_t inputImage = (wbImage_t)data;
      wbImage_t img        = wbImage_new(wbImage_getWidth(inputImage),
                                  wbImage_getHeight(inputImage),
                                  wbImage_getChannels(inputImage));
      memcpy(wbImage_getData(img), wbImage_getData(inputImage),
             rows * columns * wbImage_channels * sizeof(wbReal_t));
      wbExport(outputFile, img);
      wbImage_delete(img);
    } else if (wbString_sameQ(type, "integral_vector")) {
      wbExport(outputFile, (int *)data, rows, columns);
    } else if (wbString_sameQ(type, "vector") ||
               wbString_sameQ(type, "matrix")) {
      wbExport(outputFile, (wbReal_t *)data, rows, columns);
    } else if (wbString_sameQ(type, "histogram")) {
      wbExport(outputFile, (unsigned char *)data, rows, columns);
    } else if (wbString_sameQ(type, "text")) {
      wbExport_text(outputFile, (unsigned char *)data, rows * columns);
    }
  }

  wbFree(type);

  return res;
}
예제 #4
0
wbBool wbSolution(char * expectedOutputFile,
                  char * outputFile, char * type0,
                  void * data, int rows, int columns) {
    char * type;
    wbBool res;
    wbSolution_t sol;

    if (expectedOutputFile == NULL ||
        //outputFile == NULL ||
        data == NULL ||
        type0 == NULL) {
        wbLog(ERROR, "Failed to grade solution");
        return wbFalse;
    }

    type = wbString_toLower(type0);

    if (_solution_correctQ != NULL) {
        json_delete(_solution_correctQ);
        _solution_correctQ = NULL;
    }

    wbSolution_setOutputFile(sol, outputFile);
    wbSolution_setType(sol, type);
    wbSolution_setData(sol, data);
    wbSolution_setRows(sol, rows);
    wbSolution_setColumns(sol, columns);

    res = wbSolution_correctQ(expectedOutputFile, sol);

/*
    if (wbString_sameQ(type, "image")) {
        wbImage_t img = wbImage_new(rows, columns);
        memcpy(wbImage_getData(img), data, rows*columns*wbImage_channels*sizeof(wbReal_t));
        wbExport(outputFile, img);
        wbImage_delete(img);
    } else if (wbString_sameQ(type, "vector") ||
               wbString_sameQ(type, "matrix")) {
        wbExport(outputFile, (wbReal_t *) data, rows, columns);
    }
*/

    wbFree(type);

    return res;
}
예제 #5
0
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;
    }
}
예제 #6
0
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;
}