/* * testTargets.c: Test the fuzz targets * * See Copyright for the status of this software. */ #include #include "fuzz.h" #include static int testXPath(void) { xmlXPathObjectPtr obj; const char data[] = "\0\0\0\0count(//node())\\\n" ""; int ret = 0; if (xsltFuzzXPathInit() != 0) { xsltFuzzXPathCleanup(); return 1; } obj = xsltFuzzXPath(data, sizeof(data) - 1); if ((obj == NULL) || (obj->type != XPATH_NUMBER)) { fprintf(stderr, "Expression doesn't evaluate to number\n"); ret = 1; } else if (obj->floatval != 3.0) { fprintf(stderr, "Expression returned %f, expected %f\n", obj->floatval, 3.0); ret = 1; } xsltFuzzXPathFreeObject(obj); xsltFuzzXPathCleanup(); return ret; } static int testXslt(void) { xmlChar *result; const char fuzzData[] = "\0\0\0\0stylesheet.xsl\\\n" "\n" "\n" "\n" " \n" "\n" "\\\n" "document.xml\\\n" ""; int ret = 0; if (xsltFuzzXsltInit() != 0) { xsltFuzzXsltCleanup(); return 1; } result = xsltFuzzXslt(fuzzData, sizeof(fuzzData) - 1); if (result == NULL) { fprintf(stderr, "Result is NULL\n"); ret = 1; } else if (xmlStrcmp(result, BAD_CAST "3\n") != 0) { fprintf(stderr, "Stylesheet returned\n%sexpected \n%s\n", result, "3"); ret = 1; } xmlFree(result); xsltFuzzXsltCleanup(); return ret; } int main(void) { int ret = 0; if (testXPath() != 0) ret = 1; if (testXslt() != 0) ret = 1; return ret; }