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/pkix_pl/system/test_object.c | |
parent | 8189af23f9ee951b4f5ca31d4e79693bc34d4ae5 (diff) | |
download | nss-hg-efe5b290c741ac43f20cfef1d138360f79bdcdc1.tar.gz |
Bug 1254918 - clang-format NSS: cmd, r=kaie
Diffstat (limited to 'cmd/libpkix/pkix_pl/system/test_object.c')
-rw-r--r-- | cmd/libpkix/pkix_pl/system/test_object.c | 350 |
1 files changed, 171 insertions, 179 deletions
diff --git a/cmd/libpkix/pkix_pl/system/test_object.c b/cmd/libpkix/pkix_pl/system/test_object.c index d94477957..ebb691ba6 100644 --- a/cmd/libpkix/pkix_pl/system/test_object.c +++ b/cmd/libpkix/pkix_pl/system/test_object.c @@ -15,275 +15,267 @@ static void *plContext = NULL; static PKIX_Error * destructor( - /* ARGSUSED */ PKIX_PL_Object *object, - /* ARGSUSED */ void *plContext) + /* ARGSUSED */ PKIX_PL_Object *object, + /* ARGSUSED */ void *plContext) { - (void) printf("\tUser defined destructor called\n"); - return (NULL); + (void)printf("\tUser defined destructor called\n"); + return (NULL); } -static PKIX_Error* +static PKIX_Error * toStringCallback( - PKIX_PL_Object *obj, - PKIX_PL_String **pString, - /* ARGSUSED */ void* plContext) { - - PKIX_Error *errorResult; - PKIX_UInt32 type; - char *format = "(addr: %x, type: %d)"; - PKIX_PL_String *formatString = NULL; - - errorResult = PKIX_PL_String_Create( - PKIX_ESCASCII, - format, - PL_strlen(format), - &formatString, - plContext); - if (errorResult) testError("PKIX_PL_String_Create failed"); + PKIX_PL_Object *obj, + PKIX_PL_String **pString, + /* ARGSUSED */ void *plContext) +{ + + PKIX_Error *errorResult; + PKIX_UInt32 type; + char *format = "(addr: %x, type: %d)"; + PKIX_PL_String *formatString = NULL; - if (pString == plContext) - testError("Null String"); + errorResult = PKIX_PL_String_Create( + PKIX_ESCASCII, + format, + PL_strlen(format), + &formatString, + plContext); + if (errorResult) + testError("PKIX_PL_String_Create failed"); - type = (unsigned int)0; + if (pString == plContext) + testError("Null String"); - (void) PKIX_PL_Object_GetType(obj, &type, plContext); + type = (unsigned int)0; - errorResult = PKIX_PL_Sprintf(pString, plContext, - formatString, - (int)obj, type); - if (errorResult) testError("PKIX_PL_Sprintf failed"); + (void)PKIX_PL_Object_GetType(obj, &type, plContext); + errorResult = PKIX_PL_Sprintf(pString, plContext, + formatString, + (int)obj, type); + if (errorResult) + testError("PKIX_PL_Sprintf failed"); - errorResult = PKIX_PL_Object_DecRef((PKIX_PL_Object*)formatString, + errorResult = PKIX_PL_Object_DecRef((PKIX_PL_Object *)formatString, plContext); - if (errorResult) testError("PKIX_PL_Object_DecRef failed"); + if (errorResult) + testError("PKIX_PL_Object_DecRef failed"); - return (NULL); + return (NULL); } static PKIX_Error * comparator( - PKIX_PL_Object *first, - PKIX_PL_Object *second, - PKIX_Int32 *pValue, - /* ARGSUSED */ void *plContext) + PKIX_PL_Object *first, + PKIX_PL_Object *second, + PKIX_Int32 *pValue, + /* ARGSUSED */ void *plContext) { - if (*(char *)first > *(char *)second) - *pValue = 1; - else if (*(char *)first < *(char *)second) - *pValue = -1; - else - *pValue = 0; - return (NULL); + if (*(char *)first > *(char *)second) + *pValue = 1; + else if (*(char *)first < *(char *)second) + *pValue = -1; + else + *pValue = 0; + return (NULL); } - static PKIX_Error * hashcodeCallback( - PKIX_PL_Object *object, - PKIX_UInt32 *pValue, - /* ARGSUSED */ void *plContext) + PKIX_PL_Object *object, + PKIX_UInt32 *pValue, + /* ARGSUSED */ void *plContext) { - *pValue = 123456789; - return (NULL); + *pValue = 123456789; + return (NULL); } -static PKIX_Error* +static PKIX_Error * equalsCallback( - PKIX_PL_Object *first, - PKIX_PL_Object *second, - PKIX_Boolean *result, - void* plContext) { + PKIX_PL_Object *first, + PKIX_PL_Object *second, + PKIX_Boolean *result, + void *plContext) +{ - PKIX_UInt32 firstType = 0, secondType = 0; + PKIX_UInt32 firstType = 0, secondType = 0; - if ((first == plContext)||(second == plContext)) - testError("Null Object"); + if ((first == plContext) || (second == plContext)) + testError("Null Object"); - (void) PKIX_PL_Object_GetType(first, &firstType, plContext); + (void)PKIX_PL_Object_GetType(first, &firstType, plContext); - (void) PKIX_PL_Object_GetType(second, &secondType, plContext); + (void)PKIX_PL_Object_GetType(second, &secondType, plContext); - *result = (firstType == secondType)?PKIX_TRUE:PKIX_FALSE; + *result = (firstType == secondType) ? PKIX_TRUE : PKIX_FALSE; - return (NULL); + return (NULL); } static void createObjects( - PKIX_PL_Object **obj, - PKIX_PL_Object **obj2, - PKIX_PL_Object **obj3, - PKIX_PL_Object **obj4) + PKIX_PL_Object **obj, + PKIX_PL_Object **obj2, + PKIX_PL_Object **obj3, + PKIX_PL_Object **obj4) { - PKIX_TEST_STD_VARS(); + PKIX_TEST_STD_VARS(); #ifdef PKIX_USER_OBJECT_TYPE - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_RegisterType - (1000, /* type */ - "thousand", /* description */ - NULL, /* destructor */ - NULL, /* equals */ - (PKIX_PL_HashcodeCallback)hashcodeCallback, - NULL, /* toString */ - NULL, /* Comparator */ - NULL, - plContext)); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_Alloc - (1000, /* type */ - 12, /* size */ - obj, - plContext)); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_RegisterType - (2000, /* type */ - "two thousand" /* description */, - (PKIX_PL_DestructorCallback)destructor, - (PKIX_PL_EqualsCallback)equalsCallback, - NULL, /* hashcode */ - (PKIX_PL_ToStringCallback)toStringCallback, - (PKIX_PL_ComparatorCallback)comparator, - NULL, - plContext)); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_Alloc - (2000, /* type */ - 1, /* size */ - obj2, - plContext)); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_Alloc - (2000, /* type */ - 1, /* size */ - obj4, - plContext)); - - *obj3 = *obj; - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_IncRef(*obj3, plContext)); + PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_RegisterType(1000, /* type */ + "thousand", /* description */ + NULL, /* destructor */ + NULL, /* equals */ + (PKIX_PL_HashcodeCallback)hashcodeCallback, + NULL, /* toString */ + NULL, /* Comparator */ + NULL, + plContext)); + + PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_Alloc(1000, /* type */ + 12, /* size */ + obj, + plContext)); + + PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_RegisterType(2000, /* type */ + "two thousand" /* description */, + (PKIX_PL_DestructorCallback)destructor, + (PKIX_PL_EqualsCallback)equalsCallback, + NULL, /* hashcode */ + (PKIX_PL_ToStringCallback)toStringCallback, + (PKIX_PL_ComparatorCallback)comparator, + NULL, + plContext)); + + PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_Alloc(2000, /* type */ + 1, /* size */ + obj2, + plContext)); + + PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_Alloc(2000, /* type */ + 1, /* size */ + obj4, + plContext)); + + *obj3 = *obj; + PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_IncRef(*obj3, plContext)); cleanup: #endif /* PKIX_USER_OBJECT_TYPE */ - PKIX_TEST_RETURN(); + PKIX_TEST_RETURN(); } - static void testGetType( - PKIX_PL_Object *obj, - PKIX_PL_Object *obj2, - PKIX_PL_Object *obj3) + PKIX_PL_Object *obj, + PKIX_PL_Object *obj2, + PKIX_PL_Object *obj3) { - PKIX_UInt32 testType; + PKIX_UInt32 testType; - PKIX_TEST_STD_VARS(); + PKIX_TEST_STD_VARS(); - PKIX_TEST_EXPECT_NO_ERROR - (PKIX_PL_Object_GetType(obj, &testType, plContext)); + PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_GetType(obj, &testType, plContext)); - if (testType != 1000) - testError("Object 1 returned the wrong type"); + if (testType != 1000) + testError("Object 1 returned the wrong type"); - PKIX_TEST_EXPECT_NO_ERROR - (PKIX_PL_Object_GetType(obj2, &testType, plContext)); - if (testType != 2000) - testError("Object 2 returned the wrong type"); + PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_GetType(obj2, &testType, plContext)); + if (testType != 2000) + testError("Object 2 returned the wrong type"); - PKIX_TEST_EXPECT_NO_ERROR - (PKIX_PL_Object_GetType(obj3, &testType, plContext)); - if (testType != 1000) - testError("Object 3 returned the wrong type"); + PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_GetType(obj3, &testType, plContext)); + if (testType != 1000) + testError("Object 3 returned the wrong type"); cleanup: - PKIX_TEST_RETURN(); + PKIX_TEST_RETURN(); } static void testCompare( - PKIX_PL_Object *obj2, - PKIX_PL_Object *obj4) + PKIX_PL_Object *obj2, + PKIX_PL_Object *obj4) { - PKIX_Int32 cmpResult; - PKIX_TEST_STD_VARS(); - - *(char *)obj2 = 0x20; - *(char *)obj4 = 0x10; - PKIX_TEST_EXPECT_NO_ERROR - (PKIX_PL_Object_Compare(obj2, obj4, &cmpResult, plContext)); - if (cmpResult <= 0) testError("Invalid Result from Object Compare"); + PKIX_Int32 cmpResult; + PKIX_TEST_STD_VARS(); - PKIX_TEST_EXPECT_NO_ERROR - (PKIX_PL_Object_Compare(obj4, obj2, &cmpResult, plContext)); - if (cmpResult >= 0) testError("Invalid Result from Object Compare"); + *(char *)obj2 = 0x20; + *(char *)obj4 = 0x10; + PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_Compare(obj2, obj4, &cmpResult, plContext)); + if (cmpResult <= 0) + testError("Invalid Result from Object Compare"); - PKIX_TEST_EXPECT_NO_ERROR - (PKIX_PL_Object_Compare(obj4, obj4, &cmpResult, plContext)); + PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_Compare(obj4, obj2, &cmpResult, plContext)); + if (cmpResult >= 0) + testError("Invalid Result from Object Compare"); - *(char *)obj2 = 0x10; - if (cmpResult != 0) testError("Invalid Result from Object Compare"); + PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_Compare(obj4, obj4, &cmpResult, plContext)); + *(char *)obj2 = 0x10; + if (cmpResult != 0) + testError("Invalid Result from Object Compare"); cleanup: - PKIX_TEST_RETURN(); + PKIX_TEST_RETURN(); } - static void testDestroy( - PKIX_PL_Object *obj, - PKIX_PL_Object *obj2, - PKIX_PL_Object *obj3, - PKIX_PL_Object *obj4) + PKIX_PL_Object *obj, + PKIX_PL_Object *obj2, + PKIX_PL_Object *obj3, + PKIX_PL_Object *obj4) { - PKIX_TEST_STD_VARS(); + PKIX_TEST_STD_VARS(); - PKIX_TEST_DECREF_BC(obj); - PKIX_TEST_DECREF_BC(obj2); - PKIX_TEST_DECREF_BC(obj3); - PKIX_TEST_DECREF_BC(obj4); + PKIX_TEST_DECREF_BC(obj); + PKIX_TEST_DECREF_BC(obj2); + PKIX_TEST_DECREF_BC(obj3); + PKIX_TEST_DECREF_BC(obj4); cleanup: - PKIX_TEST_RETURN(); + PKIX_TEST_RETURN(); } -int test_object(int argc, char *argv[]) { +int +test_object(int argc, char *argv[]) +{ #ifdef PKIX_USER_OBJECT_TYPE - PKIX_PL_Object *obj, *obj2, *obj3, *obj4; - PKIX_UInt32 actualMinorVersion; - PKIX_UInt32 j = 0; - - PKIX_TEST_STD_VARS(); + PKIX_PL_Object *obj, *obj2, *obj3, *obj4; + PKIX_UInt32 actualMinorVersion; + PKIX_UInt32 j = 0; - startTests("Objects"); + PKIX_TEST_STD_VARS(); - PKIX_TEST_EXPECT_NO_ERROR( - PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext)); + startTests("Objects"); - subTest("PKIX_PL_Object_Create"); - createObjects(&obj, &obj2, &obj3, &obj4); + PKIX_TEST_EXPECT_NO_ERROR( + PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext)); - PKIX_TEST_EQ_HASH_TOSTR_DUP(obj, obj3, obj2, NULL, Object, PKIX_FALSE); + subTest("PKIX_PL_Object_Create"); + createObjects(&obj, &obj2, &obj3, &obj4); - subTest("PKIX_PL_Object_GetType"); - testGetType(obj, obj2, obj3); + PKIX_TEST_EQ_HASH_TOSTR_DUP(obj, obj3, obj2, NULL, Object, PKIX_FALSE); - subTest("PKIX_PL_Object_Compare"); - testCompare(obj2, obj4); + subTest("PKIX_PL_Object_GetType"); + testGetType(obj, obj2, obj3); - subTest("PKIX_PL_Object_Destroy"); - testDestroy(obj, obj2, obj3, obj4); + subTest("PKIX_PL_Object_Compare"); + testCompare(obj2, obj4); + subTest("PKIX_PL_Object_Destroy"); + testDestroy(obj, obj2, obj3, obj4); cleanup: - PKIX_Shutdown(plContext); + PKIX_Shutdown(plContext); - endTests("Objects"); + endTests("Objects"); #endif /* PKIX_USER_OBJECT_TYPE */ - return (0); - + return (0); } |