diff options
author | Franziskus Kiefer <franziskuskiefer@gmail.com> | 2016-04-21 21:50:20 +0200 |
---|---|---|
committer | Franziskus Kiefer <franziskuskiefer@gmail.com> | 2016-04-21 21:50:20 +0200 |
commit | efe5b290c741ac43f20cfef1d138360f79bdcdc1 (patch) | |
tree | d95945989095c453fcea223a7ec4a496efb7a396 /cmd/libpkix/testutil/testutil.h | |
parent | 8189af23f9ee951b4f5ca31d4e79693bc34d4ae5 (diff) | |
download | nss-hg-efe5b290c741ac43f20cfef1d138360f79bdcdc1.tar.gz |
Bug 1254918 - clang-format NSS: cmd, r=kaie
Diffstat (limited to 'cmd/libpkix/testutil/testutil.h')
-rw-r--r--[-rwxr-xr-x] | cmd/libpkix/testutil/testutil.h | 243 |
1 files changed, 116 insertions, 127 deletions
diff --git a/cmd/libpkix/testutil/testutil.h b/cmd/libpkix/testutil/testutil.h index 9ef6719c0..2cfe5b8a8 100755..100644 --- a/cmd/libpkix/testutil/testutil.h +++ b/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,15 @@ 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) +#define PKIX_TEST_ARENAS_ARG(arena) \ + (arena ? (PORT_Strcmp(arena, "arenas") ? PKIX_FALSE : (j++, PKIX_TRUE)) : \ + PKIX_FALSE) #define PKIX_TEST_ERROR_RECEIVED (pkixTestErrorMsg || pkixTestErrorResult) @@ -262,38 +251,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); |