/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /* * testutil.c * * Utility error handling functions *
*/
#include"testutil.h"
/* * static global variable to keep track of total number of errors for * a particular test suite (eg. all the OID tests)
*/ staticint errCount = 0;
/* * FUNCTION: startTests * DESCRIPTION: * * Prints standard message for starting the test suite with the name pointed * to by "testName". This function should be called in the beginning of every * test suite. * * PARAMETERS: * "testName" * Address of string representing name of test suite. * THREAD SAFETY: * Not Thread Safe - assumes exclusive access to "errCount" * (see Thread Safety Definitions in Programmer's Guide) * RETURNS: * Returns nothing.
*/ void
startTests(char *testName)
{
(void)printf("*START OF TESTS FOR %s:\n", testName);
errCount = 0;
}
/* * FUNCTION: endTests * DESCRIPTION: * * Prints standard message for ending the test suite with the name pointed * to by "testName", followed by a success/failure message. This function * should be called at the end of every test suite. * * PARAMETERS: * "testName" * Address of string representing name of test suite. * THREAD SAFETY: * Not Thread Safe - assumes exclusive access to "errCount" * (see Thread Safety Definitions in Programmer's Guide) * RETURNS: * Returns nothing.
*/ void
endTests(char *testName)
{ char plural = ' ';
(void)printf("*END OF TESTS FOR %s: ", testName); if (errCount > 0) { if (errCount > 1)
plural = 's';
(void)printf("%d SUBTEST%c FAILED.\n\n", errCount, plural);
} else {
(void)printf("ALL TESTS COMPLETED SUCCESSFULLY.\n\n");
}
}
/* * FUNCTION: subTest * DESCRIPTION: * * Prints standard message for starting the subtest with the name pointed to * by "subTestName". This function should be called at the beginning of each * subtest. * * PARAMETERS: * "subTestName" * Address of string representing name of subTest. * THREAD SAFETY: * Thread Safe (see Thread Safety Definitions in Programmer's Guide) * RETURNS: * Returns nothing.
*/ void
subTest(char *subTestName)
{
(void)printf("TESTING: %s ...\n", subTestName);
}
/* * FUNCTION: testErrorUndo * DESCRIPTION: * * Decrements the global variable "errCount" and prints a test failure * expected message followed by the string pointed to by "msg". This function * should be called when an expected error condition is encountered in the * tests. Calling this function *correct* the previous errCount increment. * It should only be called ONCE per subtest. * * PARAMETERS: * "msg" * Address of text of error message. * THREAD SAFETY: * Not Thread Safe - assumes exclusive access to "errCount" * (see Thread Safety Definitions in Programmer's Guide) * RETURNS: * Returns nothing.
*/ void
testErrorUndo(char *msg)
{
--errCount;
(void)printf("TEST FAILURE *** EXPECTED *** :%s\n", msg);
}
/* * FUNCTION: testError * DESCRIPTION: * * Increments the global variable "errCount" and prints a standard test * failure message followed by the string pointed to by "msg". This function * should be called when an unexpected error condition is encountered in the * tests. It should only be called ONCE per subtest. * * PARAMETERS: * "msg" * Address of text of error message. * THREAD SAFETY: * Not Thread Safe - assumes exclusive access to "errCount" * (see Thread Safety Definitions in Programmer's Guide) * RETURNS: * Returns nothing.
*/ void
testError(char *msg)
{
++errCount;
(void)printf("TEST FAILURE: %s\n", msg);
}
/* * FUNCTION: PKIX_String2ASCII * DESCRIPTION: * * Converts String object pointed to by "string" to its ASCII representation * and returns the converted value. Returns NULL upon failure. * * XXX Might want to use ESCASCII_DEBUG to show control characters, etc. * * PARAMETERS: * "string" * Address of String to be converted to ASCII. Must be non-NULL. * "plContext" * Platform-specific context pointer. * THREAD SAFETY: * Thread Safe (see Thread Safety Definitions in Programmer's Guide) * RETURNS: * Returns the ASCII representation of "string" upon success; * NULL upon failure.
*/ char *
PKIX_String2ASCII(PKIX_PL_String *string, void *plContext)
{
PKIX_UInt32 length; char *asciiString = NULL;
PKIX_Error *errorResult;
if (pkixString) { if (PKIX_PL_Object_DecRef((PKIX_PL_Object *)pkixString, plContext)) { return (NULL);
}
}
if (errorResult) { return (NULL);
}
return (asciiString);
}
/* * FUNCTION: PKIX_Object2ASCII * DESCRIPTION: * * Converts Object pointed to by "object" to its ASCII representation and * returns the converted value. Returns NULL upon failure. * * PARAMETERS: * "object" * Address of Object to be converted to ASCII. Must be non-NULL. * THREAD SAFETY: * Thread Safe (see Thread Safety Definitions in Programmer's Guide) * RETURNS: * Returns the ASCII representation of "object" upon success; * NULL upon failure.
*/ char *
PKIX_Object2ASCII(PKIX_PL_Object *object)
{
PKIX_UInt32 length; char *asciiString = NULL;
PKIX_PL_String *pkixString = NULL;
PKIX_Error *errorResult = NULL;
errorResult = PKIX_PL_Object_ToString(object, &pkixString, NULL); if (errorResult) goto cleanup;
if (issuer) { if (PKIX_PL_Object_DecRef((PKIX_PL_Object *)issuer, NULL)) { return (NULL);
}
}
if (subject) { if (PKIX_PL_Object_DecRef((PKIX_PL_Object *)subject, NULL)) { return (NULL);
}
}
if (PKIX_PL_Free((PKIX_PL_Object *)issuerAscii, NULL)) { return (NULL);
}
if (PKIX_PL_Free((PKIX_PL_Object *)subjectAscii, NULL)) { return (NULL);
}
if (errorResult) { return (NULL);
}
return (asciiString);
}
/* * FUNCTION: testHashcodeHelper * DESCRIPTION: * * Computes the hashcode of the Object pointed to by "goodObject" and the * Object pointed to by "otherObject" and compares them. If the result of the * comparison is not the desired match as specified by "match", an error * message is generated. * * PARAMETERS: * "goodObject" * Address of an object. Must be non-NULL. * "otherObject" * Address of another object. Must be non-NULL. * "match" * Boolean value representing the desired comparison result. * "plContext" * Platform-specific context pointer. * THREAD SAFETY: * Thread Safe (see Thread Safety Definitions in Programmer's Guide) * RETURNS: * Returns nothing.
*/ void
testHashcodeHelper(
PKIX_PL_Object *goodObject,
PKIX_PL_Object *otherObject,
PKIX_Boolean match, void *plContext)
{
/* * FUNCTION: testToStringHelper * DESCRIPTION: * * Calls toString on the Object pointed to by "goodObject" and compares the * result to the string pointed to by "expected". If the results are not * equal, an error message is generated. * * PARAMETERS: * "goodObject" * Address of Object. Must be non-NULL. * "expected" * Address of the desired string. * "plContext" * Platform-specific context pointer. * THREAD SAFETY: * Thread Safe (see Thread Safety Definitions in Programmer's Guide) * RETURNS: * Returns nothing.
*/ void
testToStringHelper(
PKIX_PL_Object *goodObject, char *expected, void *plContext)
{
PKIX_PL_String *stringRep = NULL; char *actual = NULL;
PKIX_TEST_STD_VARS();
/* * FUNCTION: testEqualsHelper * DESCRIPTION: * * Checks if the Object pointed to by "goodObject" is Equal to the Object * pointed to by "otherObject". If the result of the check is not the desired * match as specified by "match", an error message is generated. * * PARAMETERS: * "goodObject" * Address of an Object. Must be non-NULL. * "otherObject" * Address of another Object. Must be non-NULL. * "match" * Boolean value representing the desired comparison result. * "plContext" * Platform-specific context pointer. * THREAD SAFETY: * Thread Safe (see Thread Safety Definitions in Programmer's Guide) * RETURNS: * Returns nothing.
*/ void
testEqualsHelper(
PKIX_PL_Object *goodObject,
PKIX_PL_Object *otherObject,
PKIX_Boolean match, void *plContext)
{
/* * FUNCTION: testDuplicateHelper * DESCRIPTION: * Checks if the Object pointed to by "object" is equal to its duplicate. * If the result of the check is not equality, an error message is generated. * PARAMETERS: * "object" * Address of Object. Must be non-NULL. * "plContext" * Platform-specific context pointer. * THREAD SAFETY: * Thread Safe (see Thread Safety Definitions in Programmer's Guide) * RETURNS: * Returns nothing.
*/ void
testDuplicateHelper(PKIX_PL_Object *object, void *plContext)
{
PKIX_PL_Object *newObject = NULL;
PKIX_Boolean cmpResult;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.