summaryrefslogtreecommitdiff
path: root/nss/cmd/libpkix/testutil/testutil.h
diff options
context:
space:
mode:
Diffstat (limited to 'nss/cmd/libpkix/testutil/testutil.h')
-rw-r--r--[-rwxr-xr-x]nss/cmd/libpkix/testutil/testutil.h240
1 files changed, 114 insertions, 126 deletions
diff --git a/nss/cmd/libpkix/testutil/testutil.h b/nss/cmd/libpkix/testutil/testutil.h
index 9ef6719..9c594fa 100755..100644
--- a/nss/cmd/libpkix/testutil/testutil.h
+++ b/nss/cmd/libpkix/testutil/testutil.h
@@ -49,9 +49,9 @@ extern "C" {
* declarations after statements). PKIX_TEST_STD_VARS declares and initializes
* several variables needed by the other test macros.
*/
-#define PKIX_TEST_STD_VARS() \
- PKIX_Error *pkixTestErrorResult = NULL; \
- char *pkixTestErrorMsg = NULL;
+#define PKIX_TEST_STD_VARS() \
+ PKIX_Error *pkixTestErrorResult = NULL; \
+ char *pkixTestErrorMsg = NULL;
/*
* PKIX_TEST_EXPECT_NO_ERROR should be used to wrap a standard PKIX function
@@ -64,12 +64,12 @@ extern "C" {
*/
#define PKIX_TEST_EXPECT_NO_ERROR(func) \
- do { \
- pkixTestErrorResult = (func); \
- if (pkixTestErrorResult) { \
- goto cleanup; \
- } \
- } while (0)
+ do { \
+ pkixTestErrorResult = (func); \
+ if (pkixTestErrorResult) { \
+ goto cleanup; \
+ } \
+ } while (0)
/*
* PKIX_TEST_EXPECT_ERROR should be used to wrap a standard PKIX function call
@@ -82,16 +82,16 @@ extern "C" {
* Example Usage: PKIX_TEST_EXPECT_ERROR(pkixFunc_expected_to_fail(...));
*/
-#define PKIX_TEST_EXPECT_ERROR(func) \
- do { \
- pkixTestErrorResult = (func); \
- if (!pkixTestErrorResult){ \
- pkixTestErrorMsg = \
- "Should have thrown an error here."; \
- goto cleanup; \
- } \
- PKIX_TEST_DECREF_BC(pkixTestErrorResult); \
- } while (0)
+#define PKIX_TEST_EXPECT_ERROR(func) \
+ do { \
+ pkixTestErrorResult = (func); \
+ if (!pkixTestErrorResult) { \
+ pkixTestErrorMsg = \
+ "Should have thrown an error here."; \
+ goto cleanup; \
+ } \
+ PKIX_TEST_DECREF_BC(pkixTestErrorResult); \
+ } while (0)
/*
* PKIX_TEST_DECREF_BC is a convenience macro which should only be called
@@ -101,15 +101,13 @@ extern "C" {
* This macro MUST NOT be called after the "cleanup" label.
*/
-#define PKIX_TEST_DECREF_BC(obj) \
- do { \
- if (obj){ \
- PKIX_TEST_EXPECT_NO_ERROR \
- (PKIX_PL_Object_DecRef \
- ((PKIX_PL_Object*)(obj), plContext)); \
- obj = NULL; \
- } \
- } while (0)
+#define PKIX_TEST_DECREF_BC(obj) \
+ do { \
+ if (obj) { \
+ PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_DecRef((PKIX_PL_Object *)(obj), plContext)); \
+ obj = NULL; \
+ } \
+ } while (0)
/*
* PKIX_TEST_DECREF_AC is a convenience macro which should only be called
@@ -122,18 +120,17 @@ extern "C" {
* DecRef failure is fatal and may be indicative of memory corruption.
*/
-#define PKIX_TEST_DECREF_AC(obj) \
- do { \
- if (obj){ \
- PKIX_Error *pkixTestTempResult = NULL; \
- pkixTestTempResult = \
- PKIX_PL_Object_DecRef \
- ((PKIX_PL_Object*)(obj), plContext); \
- if (pkixTestTempResult) \
- pkixTestErrorResult = pkixTestTempResult; \
- obj = NULL; \
- } \
- } while (0)
+#define PKIX_TEST_DECREF_AC(obj) \
+ do { \
+ if (obj) { \
+ PKIX_Error *pkixTestTempResult = NULL; \
+ pkixTestTempResult = \
+ PKIX_PL_Object_DecRef((PKIX_PL_Object *)(obj), plContext); \
+ if (pkixTestTempResult) \
+ pkixTestErrorResult = pkixTestTempResult; \
+ obj = NULL; \
+ } \
+ } while (0)
/*
* PKIX_TEST_RETURN must always be AFTER the "cleanup" label. It does nothing
@@ -144,30 +141,27 @@ extern "C" {
* as an input and the error is DecRef'd. In the case of unexpected success
* testError is called with a standard string.
*/
-#define PKIX_TEST_RETURN() \
- { \
- if (pkixTestErrorMsg){ \
- testError(pkixTestErrorMsg); \
- } else if (pkixTestErrorResult){ \
- pkixTestErrorMsg = \
- PKIX_Error2ASCII \
- (pkixTestErrorResult, plContext); \
- if (pkixTestErrorMsg) { \
- testError(pkixTestErrorMsg); \
- PKIX_PL_Free \
- ((PKIX_PL_Object *)pkixTestErrorMsg, \
- plContext); \
- } else { \
- testError("PKIX_Error2ASCII Failed"); \
- } \
- if (pkixTestErrorResult != PKIX_ALLOC_ERROR()){ \
- PKIX_PL_Object_DecRef \
- ((PKIX_PL_Object*)pkixTestErrorResult, \
- plContext); \
- pkixTestErrorResult = NULL; \
- } \
- } \
- }
+#define PKIX_TEST_RETURN() \
+ { \
+ if (pkixTestErrorMsg) { \
+ testError(pkixTestErrorMsg); \
+ } else if (pkixTestErrorResult) { \
+ pkixTestErrorMsg = \
+ PKIX_Error2ASCII(pkixTestErrorResult, plContext); \
+ if (pkixTestErrorMsg) { \
+ testError(pkixTestErrorMsg); \
+ PKIX_PL_Free((PKIX_PL_Object *)pkixTestErrorMsg, \
+ plContext); \
+ } else { \
+ testError("PKIX_Error2ASCII Failed"); \
+ } \
+ if (pkixTestErrorResult != PKIX_ALLOC_ERROR()) { \
+ PKIX_PL_Object_DecRef((PKIX_PL_Object *)pkixTestErrorResult, \
+ plContext); \
+ pkixTestErrorResult = NULL; \
+ } \
+ } \
+ }
/*
* PKIX_TEST_EQ_HASH_TOSTR_DUP is a convenience macro which executes the
@@ -185,44 +179,40 @@ extern "C" {
* Note: If goodObj uses the default Equals and Hashcode functions, then
* for goodObj and equalObj to be equal, they must have the same pointer value.
*/
-#define PKIX_TEST_EQ_HASH_TOSTR_DUP(goodObj, equalObj, diffObj, \
- expAscii, type, checkDuplicate) \
- do { \
- subTest("PKIX_PL_" #type "_Equals <match>"); \
- testEqualsHelper \
- ((PKIX_PL_Object *)(goodObj), \
- (PKIX_PL_Object *)(equalObj), \
- PKIX_TRUE, \
- plContext); \
- subTest("PKIX_PL_" #type "_Hashcode <match>"); \
- testHashcodeHelper \
- ((PKIX_PL_Object *)(goodObj), \
- (PKIX_PL_Object *)(equalObj), \
- PKIX_TRUE, \
- plContext); \
- subTest("PKIX_PL_" #type "_Equals <non-match>"); \
- testEqualsHelper \
- ((PKIX_PL_Object *)(goodObj), \
- (PKIX_PL_Object *)(diffObj), \
- PKIX_FALSE, \
- plContext); \
- subTest("PKIX_PL_" #type "_Hashcode <non-match>"); \
- testHashcodeHelper \
- ((PKIX_PL_Object *)(goodObj), \
- (PKIX_PL_Object *)(diffObj), \
- PKIX_FALSE, \
- plContext); \
- if (expAscii){ \
- subTest("PKIX_PL_" #type "_ToString"); \
- testToStringHelper \
- ((PKIX_PL_Object *)(goodObj), \
- (expAscii), \
- plContext); } \
- if (checkDuplicate){ \
- subTest("PKIX_PL_" #type "_Duplicate"); \
- testDuplicateHelper \
- ((PKIX_PL_Object *)goodObj, plContext); } \
- } while (0)
+#define PKIX_TEST_EQ_HASH_TOSTR_DUP(goodObj, equalObj, diffObj, \
+ expAscii, type, checkDuplicate) \
+ do { \
+ subTest("PKIX_PL_" #type "_Equals <match>"); \
+ testEqualsHelper((PKIX_PL_Object *)(goodObj), \
+ (PKIX_PL_Object *)(equalObj), \
+ PKIX_TRUE, \
+ plContext); \
+ subTest("PKIX_PL_" #type "_Hashcode <match>"); \
+ testHashcodeHelper((PKIX_PL_Object *)(goodObj), \
+ (PKIX_PL_Object *)(equalObj), \
+ PKIX_TRUE, \
+ plContext); \
+ subTest("PKIX_PL_" #type "_Equals <non-match>"); \
+ testEqualsHelper((PKIX_PL_Object *)(goodObj), \
+ (PKIX_PL_Object *)(diffObj), \
+ PKIX_FALSE, \
+ plContext); \
+ subTest("PKIX_PL_" #type "_Hashcode <non-match>"); \
+ testHashcodeHelper((PKIX_PL_Object *)(goodObj), \
+ (PKIX_PL_Object *)(diffObj), \
+ PKIX_FALSE, \
+ plContext); \
+ if (expAscii) { \
+ subTest("PKIX_PL_" #type "_ToString"); \
+ testToStringHelper((PKIX_PL_Object *)(goodObj), \
+ (expAscii), \
+ plContext); \
+ } \
+ if (checkDuplicate) { \
+ subTest("PKIX_PL_" #type "_Duplicate"); \
+ testDuplicateHelper((PKIX_PL_Object *)goodObj, plContext); \
+ } \
+ } while (0)
/*
* PKIX_TEST_DECREF_BC is a convenience macro which should only be called
@@ -233,16 +223,14 @@ extern "C" {
*/
#define PKIX_TEST_ABORT_ON_NULL(obj) \
- do { \
- if (!obj){ \
- goto cleanup; \
- } \
- } while (0)
+ do { \
+ if (!obj) { \
+ goto cleanup; \
+ } \
+ } while (0)
#define PKIX_TEST_ARENAS_ARG(arena) \
- (arena? \
- (PORT_Strcmp(arena, "arenas") ? PKIX_FALSE : (j++, PKIX_TRUE)): \
- PKIX_FALSE)
+ (arena ? (PORT_Strcmp(arena, "arenas") ? PKIX_FALSE : (j++, PKIX_TRUE)) : PKIX_FALSE)
#define PKIX_TEST_ERROR_RECEIVED (pkixTestErrorMsg || pkixTestErrorResult)
@@ -262,38 +250,38 @@ _ErrorCheck(PKIX_Error *errorResult);
extern PKIX_Error *
_OutputError(PKIX_Error *errorResult);
-char* PKIX_String2ASCII(PKIX_PL_String *string, void *plContext);
+char *PKIX_String2ASCII(PKIX_PL_String *string, void *plContext);
-char* PKIX_Error2ASCII(PKIX_Error *error, void *plContext);
+char *PKIX_Error2ASCII(PKIX_Error *error, void *plContext);
-char* PKIX_Object2ASCII(PKIX_PL_Object *object);
+char *PKIX_Object2ASCII(PKIX_PL_Object *object);
char *PKIX_Cert2ASCII(PKIX_PL_Cert *cert);
void
testHashcodeHelper(
- PKIX_PL_Object *goodObject,
- PKIX_PL_Object *otherObject,
- PKIX_Boolean match,
- void *plContext);
+ PKIX_PL_Object *goodObject,
+ PKIX_PL_Object *otherObject,
+ PKIX_Boolean match,
+ void *plContext);
void
testToStringHelper(
- PKIX_PL_Object *goodObject,
- char *expected,
- void *plContext);
+ PKIX_PL_Object *goodObject,
+ char *expected,
+ void *plContext);
void
testEqualsHelper(
- PKIX_PL_Object *goodObject,
- PKIX_PL_Object *otherObject,
- PKIX_Boolean match,
- void *plContext);
+ PKIX_PL_Object *goodObject,
+ PKIX_PL_Object *otherObject,
+ PKIX_Boolean match,
+ void *plContext);
void
testDuplicateHelper(
- PKIX_PL_Object *object,
- void *plContext);
+ PKIX_PL_Object *object,
+ void *plContext);
void
testErrorUndo(char *msg);