diff options
Diffstat (limited to 'security/nss/cmd/libpkix/pkix_pl/system')
16 files changed, 0 insertions, 3183 deletions
diff --git a/security/nss/cmd/libpkix/pkix_pl/system/Makefile b/security/nss/cmd/libpkix/pkix_pl/system/Makefile deleted file mode 100755 index 09ca5f1c6..000000000 --- a/security/nss/cmd/libpkix/pkix_pl/system/Makefile +++ /dev/null @@ -1,47 +0,0 @@ -#! gmake -# -# 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/. - -####################################################################### -# (1) Include initial platform-independent assignments (MANDATORY). # -####################################################################### - -include manifest.mn - -####################################################################### -# (2) Include "global" configuration information. (OPTIONAL) # -####################################################################### - -include $(CORE_DEPTH)/coreconf/config.mk - -####################################################################### -# (3) Include "component" configuration information. (OPTIONAL) # -####################################################################### - -include $(PKIX_DEPTH)/config.mk - -####################################################################### -# (4) Include "local" platform-dependent assignments (OPTIONAL). # -####################################################################### - -include $(PLAT_DEPTH)/platlibs.mk - -####################################################################### -# (5) Execute "global" rules. (OPTIONAL) # -####################################################################### - -include $(CORE_DEPTH)/coreconf/rules.mk - -####################################################################### -# (6) Execute "component" rules. (OPTIONAL) # -####################################################################### - - - -####################################################################### -# (7) Execute "local" rules. (OPTIONAL). # -####################################################################### - -include $(PLAT_DEPTH)/platrules.mk diff --git a/security/nss/cmd/libpkix/pkix_pl/system/manifest.mn b/security/nss/cmd/libpkix/pkix_pl/system/manifest.mn deleted file mode 100755 index edbf0cda8..000000000 --- a/security/nss/cmd/libpkix/pkix_pl/system/manifest.mn +++ /dev/null @@ -1,38 +0,0 @@ -# -# 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/. - -PKIX_DEPTH = ../.. -PLAT_DEPTH = $(PKIX_DEPTH)/.. -CORE_DEPTH = $(PKIX_DEPTH)/../../.. - -# MODULE public and private header directories are implicitly REQUIRED. -MODULE = nss - -# test_rwlock.c is taken out, need to link to libpkix internals -# -# The test is using LIBPKIX PL call directly, which violates our -# code convention. -# -CSRCS = test_bigint.c \ - test_bytearray.c \ - test_hashtable.c \ - test_mem.c \ - test_mutex.c \ - test_mutex2.c \ - test_mutex3.c \ - test_monitorlock.c \ - test_object.c \ - test_oid.c \ - stress_test.c \ - test_string.c \ - test_string2.c \ - $(NULL) - - -LIBRARY_NAME=pkixtoolsys - -SOURCE_LIB_DIR=$(PKIX_DEPTH)/$(OBJDIR) - -NO_MD_RELEASE = 1 diff --git a/security/nss/cmd/libpkix/pkix_pl/system/stress_test.c b/security/nss/cmd/libpkix/pkix_pl/system/stress_test.c deleted file mode 100644 index a19f9d33e..000000000 --- a/security/nss/cmd/libpkix/pkix_pl/system/stress_test.c +++ /dev/null @@ -1,155 +0,0 @@ -/* 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/. */ -/* - * stress_test.c - * - * Creates and deletes many objects - * - */ - -#include "testutil.h" -#include "testutil_nss.h" - -static void *plContext = NULL; - -int stress_test(int argc, char *argv[]) { - - PKIX_UInt32 i, k, length, hashcode; - PKIX_UInt32 size = 17576; - char temp[4]; - PKIX_Boolean result; - PKIX_PL_String *strings[17576], *tempString; - PKIX_PL_String *utf16strings[17576]; - PKIX_PL_ByteArray *byteArrays[17576]; - void *dest; - PKIX_PL_HashTable *ht = NULL; - PKIX_UInt32 actualMinorVersion; - PKIX_UInt32 j = 0; - - PKIX_TEST_STD_VARS(); - - startTests("Stress Test"); - - PKIX_TEST_EXPECT_NO_ERROR( - PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext)); - - /* ---------------------------- */ - subTest("Create every three letter String"); - - for (i = 0; i < 26; i++) - for (j = 0; j < 26; j++) - for (k = 0; k < 26; k++) { - temp[0] = (char)('a'+i); - temp[1] = (char)('a'+j); - temp[2] = (char)('a'+k); - temp[3] = 0; - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_Create - (PKIX_ESCASCII, temp, 3, - &strings[26*(i*26+j)+k], plContext)); - } - - /* ---------------------------- */ - subTest("Create a bytearray from each string's UTF-16 encoding"); - for (i = 0; i < size; i++) { - PKIX_TEST_EXPECT_NO_ERROR - (PKIX_PL_String_GetEncoded - (strings[i], - PKIX_UTF16, - &dest, - &length, - plContext)); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_ByteArray_Create - (dest, length, &byteArrays[i], plContext)); - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Free(dest, plContext)); - } - - /* ---------------------------- */ - subTest("Create a copy string from each bytearray"); - for (i = 0; i < size; i++) { - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_Create - (PKIX_UTF16, *(void **)byteArrays[i], 6, - &utf16strings[i], plContext)); - } - - /* ---------------------------- */ - subTest("Compare each original string with the copy"); - for (i = 0; i < size; i++) { - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_Equals - ((PKIX_PL_Object*)strings[i], - (PKIX_PL_Object*)utf16strings[i], - &result, - plContext)); - if (result == 0) - testError("Strings do not match"); - } - - /* ---------------------------- */ - subTest("Put each string into a Hashtable"); - PKIX_TEST_EXPECT_NO_ERROR - (PKIX_PL_HashTable_Create(size/2, 0, &ht, plContext)); - - for (i = 0; i < size; i++) { - PKIX_TEST_EXPECT_NO_ERROR - (PKIX_PL_Object_Hashcode - ((PKIX_PL_Object*)strings[i], - &hashcode, - plContext)); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_HashTable_Add - (ht, - (void *)&hashcode, - (void*)strings[i], - plContext)); - } - - - /* ---------------------------- */ - subTest("Compare each copy string with the hashtable entries "); - for (i = 0; i < size; i++) { - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_Hashcode - ((PKIX_PL_Object*)utf16strings[i], - &hashcode, - plContext)); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_HashTable_Lookup - (ht, - (void *)&hashcode, - (PKIX_PL_Object**)&tempString, - plContext)); - - if (tempString == NULL) - testError("String not found in hashtable"); - else { - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_Equals - ((PKIX_PL_Object*)tempString, - (PKIX_PL_Object*)utf16strings[i], - &result, - plContext)); - if (result == 0) - testError("Strings do not match"); - PKIX_TEST_DECREF_BC(tempString); - } - } - -cleanup: - - /* ---------------------------- */ - subTest("Destroy All Objects"); - - PKIX_TEST_DECREF_AC(ht); - - for (i = 0; i < size; i++) { - PKIX_TEST_DECREF_AC(strings[i]); - PKIX_TEST_DECREF_AC(utf16strings[i]); - PKIX_TEST_DECREF_AC(byteArrays[i]); - } - - PKIX_Shutdown(plContext); - - PKIX_TEST_RETURN(); - - endTests("Stress Test"); - return (0); -} diff --git a/security/nss/cmd/libpkix/pkix_pl/system/test_bigint.c b/security/nss/cmd/libpkix/pkix_pl/system/test_bigint.c deleted file mode 100644 index a70f8d349..000000000 --- a/security/nss/cmd/libpkix/pkix_pl/system/test_bigint.c +++ /dev/null @@ -1,194 +0,0 @@ -/* 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/. */ -/* - * test_bigint.c - * - * Tests BigInt Types - * - */ - -#include "testutil.h" -#include "testutil_nss.h" - -static void *plContext = NULL; - -static void -createBigInt( - PKIX_PL_BigInt **bigInts, - char *bigIntAscii, - PKIX_Boolean errorHandling) -{ - PKIX_PL_String *bigIntString = NULL; - - PKIX_TEST_STD_VARS(); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_Create - (PKIX_ESCASCII, - bigIntAscii, - PL_strlen(bigIntAscii), - &bigIntString, - plContext)); - - if (errorHandling){ - PKIX_TEST_EXPECT_ERROR(PKIX_PL_BigInt_Create - (bigIntString, - bigInts, - plContext)); - } else { - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_BigInt_Create - (bigIntString, - bigInts, - plContext)); - } - -cleanup: - - PKIX_TEST_DECREF_AC(bigIntString); - - PKIX_TEST_RETURN(); -} - -static void -testToString( - PKIX_PL_BigInt *bigInt, - char *expAscii) -{ - PKIX_PL_String *bigIntString = NULL; - char *temp = NULL; - - PKIX_TEST_STD_VARS(); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_ToString - ((PKIX_PL_Object*)bigInt, - &bigIntString, plContext)); - - temp = PKIX_String2ASCII(bigIntString, plContext); - if (temp == plContext){ - testError("PKIX_String2Ascii failed"); - goto cleanup; - } - - if (PL_strcmp(temp, expAscii) != 0) { - (void) printf("\tBigInt ToString: %s %s\n", temp, expAscii); - testError("Output string does not match source"); - } - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Free(temp, plContext)); - -cleanup: - - PKIX_TEST_DECREF_AC(bigIntString); - - PKIX_TEST_RETURN(); -} - -static void -testCompare( - PKIX_PL_BigInt *firstBigInt, - PKIX_PL_BigInt *secondBigInt, - PKIX_Int32 *cmpResult) -{ - PKIX_TEST_STD_VARS(); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_Compare - ((PKIX_PL_Object*)firstBigInt, - (PKIX_PL_Object*)secondBigInt, - cmpResult, plContext)); -cleanup: - - PKIX_TEST_RETURN(); -} - -static void -testDestroy( - PKIX_PL_BigInt *bigInt) -{ - PKIX_TEST_STD_VARS(); - - PKIX_TEST_DECREF_BC(bigInt); - -cleanup: - - PKIX_TEST_RETURN(); -} - -int test_bigint(int argc, char *argv[]) { - - PKIX_UInt32 size = 4, badSize = 3, i = 0; - PKIX_PL_BigInt *testBigInt[4] = {NULL}; - PKIX_Int32 cmpResult; - PKIX_UInt32 actualMinorVersion; - PKIX_UInt32 j = 0; - - char *bigIntValue[4] = - { - "03", - "ff", - "1010101010101010101010101010101010101010", - "1010101010101010101010101010101010101010", - }; - - char *badValue[3] = {"00ff", "fff", "-ff"}; - - PKIX_TEST_STD_VARS(); - - startTests("BigInts"); - - PKIX_TEST_EXPECT_NO_ERROR( - PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext)); - - for (i = 0; i < badSize; i++) { - subTest("PKIX_PL_BigInt_Create <error_handling>"); - createBigInt(&testBigInt[i], badValue[i], PKIX_TRUE); - } - - for (i = 0; i < size; i++) { - subTest("PKIX_PL_BigInt_Create"); - createBigInt(&testBigInt[i], bigIntValue[i], PKIX_FALSE); - } - - PKIX_TEST_EQ_HASH_TOSTR_DUP - (testBigInt[2], - testBigInt[3], - testBigInt[1], - bigIntValue[2], - BigInt, - PKIX_TRUE); - - for (i = 0; i < size; i++) { - subTest("PKIX_PL_BigInt_ToString"); - testToString(testBigInt[i], bigIntValue[i]); - } - - subTest("PKIX_PL_BigInt_Compare <gt>"); - testCompare(testBigInt[2], testBigInt[1], &cmpResult); - if (cmpResult <= 0){ - testError("Invalid Result from String Compare"); - } - - subTest("PKIX_PL_BigInt_Compare <lt>"); - testCompare(testBigInt[1], testBigInt[2], &cmpResult); - if (cmpResult >= 0){ - testError("Invalid Result from String Compare"); - } - - subTest("PKIX_PL_BigInt_Compare <eq>"); - testCompare(testBigInt[2], testBigInt[3], &cmpResult); - if (cmpResult != 0){ - testError("Invalid Result from String Compare"); - } - - for (i = 0; i < size; i++) { - subTest("PKIX_PL_BigInt_Destroy"); - testDestroy(testBigInt[i]); - } - -cleanup: - - PKIX_Shutdown(plContext); - - endTests("BigInt"); - - return (0); -} diff --git a/security/nss/cmd/libpkix/pkix_pl/system/test_bytearray.c b/security/nss/cmd/libpkix/pkix_pl/system/test_bytearray.c deleted file mode 100644 index ba056681c..000000000 --- a/security/nss/cmd/libpkix/pkix_pl/system/test_bytearray.c +++ /dev/null @@ -1,241 +0,0 @@ -/* 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/. */ -/* - * test_bytearray.c - * - * Tests ByteArray types. - * - */ - -#include "testutil.h" -#include "testutil_nss.h" - -static void *plContext = NULL; - -static void -createByteArray( - PKIX_PL_ByteArray **byteArray, - char *bytes, - PKIX_UInt32 length) -{ - PKIX_TEST_STD_VARS(); - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_ByteArray_Create - ((void*)bytes, - length, - byteArray, - plContext)); -cleanup: - PKIX_TEST_RETURN(); -} - - -static void -testZeroLength(void) -{ - PKIX_PL_ByteArray *byteArray = NULL; - void *array = NULL; - PKIX_UInt32 length = 2; - - PKIX_TEST_STD_VARS(); - - createByteArray(&byteArray, NULL, 0); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_ByteArray_GetLength - (byteArray, &length, plContext)); - if (length != 0){ - testError("Length should be zero"); - } - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_ByteArray_GetPointer - (byteArray, &array, plContext)); - if (array){ - testError("Array should be NULL"); - } - - testToStringHelper((PKIX_PL_Object *)byteArray, "[]", plContext); - -cleanup: - - PKIX_TEST_DECREF_AC(byteArray); - - PKIX_TEST_RETURN(); -} - - -static void -testToString( - PKIX_PL_ByteArray *byteArray, - char *expAscii) -{ - PKIX_PL_String *string = NULL; - char *temp = NULL; - - PKIX_TEST_STD_VARS(); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_ToString - ((PKIX_PL_Object*)byteArray, - &string, plContext)); - - temp = PKIX_String2ASCII(string, plContext); - if (temp == NULL){ - testError("PKIX_String2Ascii failed"); - goto cleanup; - } - - if (PL_strcmp(temp, expAscii) != 0) { - (void) printf("\tByteArray ToString: %s %s\n", temp, expAscii); - testError("Output string does not match source"); - } - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Free(temp, plContext)); - -cleanup: - - PKIX_TEST_DECREF_AC(string); - - PKIX_TEST_RETURN(); -} - -static void -testGetLength( - PKIX_PL_ByteArray *byteArray, - PKIX_UInt32 expLength) -{ - PKIX_UInt32 arrayLength; - - PKIX_TEST_STD_VARS(); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_ByteArray_GetLength - (byteArray, &arrayLength, plContext)); - - if (arrayLength != expLength){ - (void) printf("\tByteArray GetLength: %d %d\n", - arrayLength, expLength); - testError("Incorrect Array Length returned"); - } - - -cleanup: - PKIX_TEST_RETURN(); -} - -static void -testGetPointer( - PKIX_PL_ByteArray *byteArray, - char *expBytes, - PKIX_UInt32 arrayLength) -{ - char *temp = NULL; - PKIX_UInt32 j; - - PKIX_TEST_STD_VARS(); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_ByteArray_GetPointer - (byteArray, (void **)&temp, plContext)); - - for (j = 0; j < arrayLength; j++) { - if (temp[j] != expBytes[j]){ - testError("Incorrect Byte Array Contents"); - } - } - -cleanup: - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Free(temp, plContext)); - PKIX_TEST_RETURN(); -} - -void -testDestroy( - PKIX_PL_ByteArray *byteArray) -{ - PKIX_TEST_STD_VARS(); - - PKIX_TEST_DECREF_BC(byteArray); - -cleanup: - - PKIX_TEST_RETURN(); -} - -int test_bytearray(int argc, char *argv[]) { - - PKIX_PL_ByteArray *testByteArray[4]; - - PKIX_UInt32 i, size = 4; - PKIX_UInt32 lengths[4] = {5, 6, 1, 5}; - char dArray0[5] = {1, 2, 3, 4, 5}; - unsigned char dArray1[6] = {127, 128, 129, 254, 255, 0}; - char dArray2[1] = {100}; - char dArray3[5] = {1, 2, 3, 4, 5}; - - char *expected[4] = { - "[001, 002, 003, 004, 005]", - "[127, 128, 129, 254, 255, 000]", - "[100]", - "[001, 002, 003, 004, 005]" - }; - - char *dummyArray[4]; - PKIX_UInt32 actualMinorVersion; - PKIX_UInt32 j = 0; - - PKIX_TEST_STD_VARS(); - - dummyArray[0] = dArray0; - dummyArray[1] = (char*)dArray1; - dummyArray[2] = dArray2; - dummyArray[3] = dArray3; - - startTests("ByteArrays"); - - PKIX_TEST_EXPECT_NO_ERROR( - PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext)); - - subTest ("PKIX_PL_ByteArray_Create <zero length>"); - testZeroLength(); - - for (i = 0; i < size; i++) { - subTest("PKIX_PL_ByteArray_Create"); - createByteArray(&testByteArray[i], dummyArray[i], lengths[i]); - } - - PKIX_TEST_EQ_HASH_TOSTR_DUP - (testByteArray[0], - testByteArray[3], - testByteArray[1], - "[001, 002, 003, 004, 005]", - ByteArray, - PKIX_TRUE); - - for (i = 0; i < size; i++) { - subTest("PKIX_PL_ByteArray_ToString"); - testToString(testByteArray[i], expected[i]); - } - - for (i = 0; i < size; i++) { - subTest("PKIX_PL_ByteArray_GetLength"); - testGetLength(testByteArray[i], lengths[i]); - } - - for (i = 0; i < size; i++) { - subTest("PKIX_PL_ByteArray_GetPointer"); - testGetPointer(testByteArray[i], dummyArray[i], lengths[i]); - } - - - for (i = 0; i < size; i++) { - subTest("PKIX_PL_ByteArray_Destroy"); - testDestroy(testByteArray[i]); - } - -cleanup: - - PKIX_Shutdown(plContext); - - endTests("ByteArray"); - - return (0); - -} diff --git a/security/nss/cmd/libpkix/pkix_pl/system/test_hashtable.c b/security/nss/cmd/libpkix/pkix_pl/system/test_hashtable.c deleted file mode 100644 index 9d774a678..000000000 --- a/security/nss/cmd/libpkix/pkix_pl/system/test_hashtable.c +++ /dev/null @@ -1,425 +0,0 @@ -/* 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/. */ -/* - * test_hashtable.c - * - * Tests Hashtables - * - */ - -#include "testutil.h" -#include "testutil_nss.h" - -static void *plContext = NULL; - -static void -createHashTables( - PKIX_PL_HashTable **ht, - PKIX_PL_HashTable **ht2, - PKIX_PL_HashTable **ht3, - PKIX_PL_HashTable **ht4) -{ - PKIX_TEST_STD_VARS(); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_HashTable_Create - (1, 0, ht, plContext)); - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_HashTable_Create - (5, 0, ht2, plContext)); - - /* at most two entries per bucket */ - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_HashTable_Create - (1, 2, ht4, plContext)); - - *ht3 = *ht; - PKIX_TEST_EXPECT_NO_ERROR - (PKIX_PL_Object_IncRef((PKIX_PL_Object*)*ht3, plContext)); - -cleanup: - PKIX_TEST_RETURN(); -} - -static void -testAdd( - PKIX_PL_HashTable *ht, - PKIX_PL_HashTable *ht2, - PKIX_PL_String **testString, - PKIX_PL_String **testString2, - PKIX_PL_String **testString3, - PKIX_PL_OID **testOID) -{ - char* dummyString = "test string 1"; - char* dummyString2 = "test string 2"; - char* dummyString3 = "test string 3"; - char* dummyOID = "2.11.22222.33333"; - - PKIX_TEST_STD_VARS(); - - /* Make some dummy objects */ - PKIX_TEST_EXPECT_NO_ERROR - (PKIX_PL_String_Create( - PKIX_ESCASCII, - dummyString, - PL_strlen(dummyString), - testString, - plContext)); - - PKIX_TEST_EXPECT_NO_ERROR - (PKIX_PL_String_Create( - PKIX_ESCASCII, - dummyString2, - PL_strlen(dummyString2), - testString2, - plContext)); - - PKIX_TEST_EXPECT_NO_ERROR - (PKIX_PL_String_Create( - PKIX_ESCASCII, - dummyString3, - PL_strlen(dummyString3), - testString3, - plContext)); - - PKIX_TEST_EXPECT_NO_ERROR - (PKIX_PL_OID_Create(dummyOID, testOID, plContext)); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_HashTable_Add - (ht, - (PKIX_PL_Object *)*testString, - (PKIX_PL_Object *)*testString2, - plContext)); - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_HashTable_Add - (ht2, - (PKIX_PL_Object *)*testString, - (PKIX_PL_Object *)*testString2, - plContext)); - - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_HashTable_Add - (ht, - (PKIX_PL_Object *)*testString2, - (PKIX_PL_Object *)*testString, - plContext)); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_HashTable_Add - (ht2, - (PKIX_PL_Object *)*testString2, - (PKIX_PL_Object *)*testString, - plContext)); - - - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_HashTable_Add - (ht, - (PKIX_PL_Object *)*testOID, - (PKIX_PL_Object *)*testOID, - plContext)); - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_HashTable_Add - (ht2, - (PKIX_PL_Object *)*testOID, - (PKIX_PL_Object *)*testOID, - plContext)); - -cleanup: - PKIX_TEST_RETURN(); -} - -static void -testAddFIFO( - PKIX_PL_HashTable *ht, - PKIX_PL_String **testString, - PKIX_PL_String **testString2, - PKIX_PL_String **testString3) -{ - PKIX_PL_String *targetString = NULL; - PKIX_Boolean cmpResult; - - PKIX_TEST_STD_VARS(); - - /* - * ht is created as one bucket, two entries per bucket. Since we add - * three items to the ht, we expect the first one to be deleted. - */ - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_HashTable_Add - (ht, - (PKIX_PL_Object *)*testString, - (PKIX_PL_Object *)*testString, - plContext)); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_HashTable_Add - (ht, - (PKIX_PL_Object *)*testString2, - (PKIX_PL_Object *)*testString2, - plContext)); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_HashTable_Add - (ht, - (PKIX_PL_Object *)*testString3, - (PKIX_PL_Object *)*testString3, - plContext)); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_HashTable_Lookup - (ht, - (PKIX_PL_Object *)*testString, - (PKIX_PL_Object**)&targetString, - plContext)); - if (targetString != NULL) { - testError("HashTable_Lookup retrieved a supposed deleted item"); - PKIX_TEST_DECREF_BC(targetString); - } - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_HashTable_Lookup - (ht, - (PKIX_PL_Object *)*testString3, - (PKIX_PL_Object**)&targetString, - plContext)); - - PKIX_TEST_EXPECT_NO_ERROR - (PKIX_PL_Object_Equals( - (PKIX_PL_Object *)targetString, - (PKIX_PL_Object *)*testString3, - &cmpResult, - plContext)); - if (cmpResult != PKIX_TRUE){ - testError("HashTable_Lookup failed"); - } - PKIX_TEST_DECREF_BC(targetString); - -cleanup: - PKIX_TEST_RETURN(); -} - -static void -testLookup( - PKIX_PL_HashTable *ht, - PKIX_PL_HashTable *ht2, - PKIX_PL_String *testString, - PKIX_PL_String *testString2, - PKIX_PL_String *testString3, - PKIX_PL_OID *testOID) -{ - PKIX_PL_String *targetString = NULL; - PKIX_PL_String *targetOID = NULL; - PKIX_Boolean cmpResult; - - PKIX_TEST_STD_VARS(); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_HashTable_Lookup - (ht, - (PKIX_PL_Object *)testString, - (PKIX_PL_Object**)&targetString, - plContext)); - - PKIX_TEST_EXPECT_NO_ERROR - (PKIX_PL_Object_Equals( - (PKIX_PL_Object *)targetString, - (PKIX_PL_Object *)testString2, - &cmpResult, - plContext)); - if (cmpResult != PKIX_TRUE){ - testError("HashTable_Lookup failed"); - } - PKIX_TEST_DECREF_BC(targetString); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_HashTable_Lookup - (ht2, - (PKIX_PL_Object *)testString, - (PKIX_PL_Object**)&targetString, - plContext)); - - PKIX_TEST_EXPECT_NO_ERROR - (PKIX_PL_Object_Equals( - (PKIX_PL_Object *)targetString, - (PKIX_PL_Object *)testString2, - &cmpResult, - plContext)); - if (cmpResult != PKIX_TRUE){ - testError("HashTable_Lookup failed"); - } - PKIX_TEST_DECREF_BC(targetString); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_HashTable_Lookup - (ht2, - (PKIX_PL_Object *)testString2, - (PKIX_PL_Object**)&targetString, - plContext)); - - PKIX_TEST_EXPECT_NO_ERROR - (PKIX_PL_Object_Equals( - (PKIX_PL_Object *)targetString, - (PKIX_PL_Object *)testString, - &cmpResult, - plContext)); - if (cmpResult != PKIX_TRUE){ - testError("HashTable_Lookup failed"); - } - PKIX_TEST_DECREF_BC(targetString); - - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_HashTable_Lookup - (ht, - (PKIX_PL_Object *)testOID, - (PKIX_PL_Object**)&targetOID, - plContext)); - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_ToString - ((PKIX_PL_Object*)targetOID, &targetString, plContext)); - - PKIX_TEST_EXPECT_NO_ERROR - (PKIX_PL_Object_Equals( - (PKIX_PL_Object *)targetOID, - (PKIX_PL_Object *)testOID, - &cmpResult, - plContext)); - if (cmpResult != PKIX_TRUE){ - testError("HashTable_Lookup failed"); - } - PKIX_TEST_DECREF_BC(targetString); - PKIX_TEST_DECREF_BC(targetOID); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_HashTable_Lookup - (ht2, - (PKIX_PL_Object *)testOID, - (PKIX_PL_Object**)&targetOID, - plContext)); - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_ToString - ((PKIX_PL_Object*)targetOID, &targetString, plContext)); - - PKIX_TEST_EXPECT_NO_ERROR - (PKIX_PL_Object_Equals( - (PKIX_PL_Object *)targetOID, - (PKIX_PL_Object *)testOID, - &cmpResult, - plContext)); - if (cmpResult != PKIX_TRUE){ - testError("HashTable_Lookup failed"); - } - PKIX_TEST_DECREF_BC(targetString); - PKIX_TEST_DECREF_BC(targetOID); - - (void) printf("Looking up item not in HashTable.\n"); - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_HashTable_Lookup - (ht, - (PKIX_PL_Object *)testString3, - (PKIX_PL_Object**)&targetString, - plContext)); - if (targetString == NULL) - (void) printf("\tCorrectly returned NULL.\n"); - else - testError("Hashtable did not return NULL value as expected"); - - -cleanup: - PKIX_TEST_RETURN(); -} - -static void -testRemove( - PKIX_PL_HashTable *ht, - PKIX_PL_HashTable *ht2, - PKIX_PL_String *testString, - PKIX_PL_String *testString2, - PKIX_PL_OID *testOID) -{ - - PKIX_TEST_STD_VARS(); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_HashTable_Remove - (ht, - (PKIX_PL_Object *)testString, - plContext)); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_HashTable_Remove - (ht, - (PKIX_PL_Object *)testOID, - plContext)); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_HashTable_Remove - (ht2, - (PKIX_PL_Object *)testString2, - plContext)); - - PKIX_TEST_EXPECT_ERROR(PKIX_PL_HashTable_Remove - (ht, - (PKIX_PL_Object *)testString, - plContext)); - -cleanup: - PKIX_TEST_RETURN(); -} - -static void -testDestroy( - PKIX_PL_HashTable *ht, - PKIX_PL_HashTable *ht2, - PKIX_PL_HashTable *ht3, - PKIX_PL_HashTable *ht4) -{ - PKIX_TEST_STD_VARS(); - - PKIX_TEST_DECREF_BC(ht); - PKIX_TEST_DECREF_BC(ht2); - PKIX_TEST_DECREF_BC(ht3); - PKIX_TEST_DECREF_BC(ht4); - -cleanup: - PKIX_TEST_RETURN(); -} - - - - -int test_hashtable(int argc, char *argv[]) { - - PKIX_PL_HashTable *ht, *ht2, *ht3, *ht4; - PKIX_PL_String *testString, *testString2, *testString3; - PKIX_PL_OID *testOID; - PKIX_UInt32 actualMinorVersion; - PKIX_UInt32 j = 0; - - PKIX_TEST_STD_VARS(); - - startTests("HashTables"); - - PKIX_TEST_EXPECT_NO_ERROR( - PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext)); - - subTest("PKIX_PL_HashTable_Create"); - createHashTables(&ht, &ht2, &ht3, &ht4); - - PKIX_TEST_EQ_HASH_TOSTR_DUP - (ht, - ht3, - ht2, - NULL, - HashTable, - PKIX_FALSE); - - subTest("PKIX_PL_HashTable_Add"); - testAdd(ht, ht2, &testString, &testString2, &testString3, &testOID); - - subTest("PKIX_PL_HashTable_ADD - with Bucket Size limit"); - testAddFIFO(ht4, &testString, &testString2, &testString3); - - subTest("PKIX_PL_HashTable_Lookup"); - testLookup(ht, ht2, testString, testString2, testString3, testOID); - - subTest("PKIX_PL_HashTable_Remove"); - testRemove(ht, ht2, testString, testString2, testOID); - - PKIX_TEST_DECREF_BC(testString); - PKIX_TEST_DECREF_BC(testString2); - PKIX_TEST_DECREF_BC(testString3); - PKIX_TEST_DECREF_BC(testOID); - - subTest("PKIX_PL_HashTable_Destroy"); - testDestroy(ht, ht2, ht3, ht4); - -cleanup: - - PKIX_Shutdown(plContext); - - endTests("BigInt"); - - return (0); - -} diff --git a/security/nss/cmd/libpkix/pkix_pl/system/test_mem.c b/security/nss/cmd/libpkix/pkix_pl/system/test_mem.c deleted file mode 100644 index 3df436761..000000000 --- a/security/nss/cmd/libpkix/pkix_pl/system/test_mem.c +++ /dev/null @@ -1,131 +0,0 @@ -/* 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/. */ -/* - * test_mem.c - * - * Tests Malloc, Realloc and Free - * - */ - -#include "testutil.h" -#include "testutil_nss.h" - -static void *plContext = NULL; - -static -void testMalloc(PKIX_UInt32 **array) -{ - PKIX_UInt32 i, arraySize = 10; - PKIX_TEST_STD_VARS(); - - /* Create an integer array of size 10 */ - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Malloc( - (PKIX_UInt32)(arraySize*sizeof (unsigned int)), - (void **) array, plContext)); - - /* Fill in some values */ - (void) printf ("Setting array[i] = i...\n"); - for (i = 0; i < arraySize; i++) { - (*array)[i] = i; - if ((*array)[i] != i) - testError("Array has incorrect contents"); - } - - /* Memory now reflects changes */ - (void) printf("\tArray: a[0] = %d, a[5] = %d, a[7] = %d.\n", - (*array[0]), (*array)[5], (*array)[7]); - -cleanup: - PKIX_TEST_RETURN(); -} - -static -void testRealloc(PKIX_UInt32 **array) -{ - PKIX_UInt32 i, arraySize = 20; - PKIX_TEST_STD_VARS(); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Realloc(*array, - (PKIX_UInt32)(arraySize*sizeof (unsigned int)), - (void **) array, plContext)); - - /* Fill in the new elements */ - (void) printf ("Setting new portion of array to a[i] = i...\n"); - for (i = arraySize/2; i < arraySize; i++) { - (*array)[i] = i; - if ((*array)[i] != i) - testError("Array has incorrect contents"); - } - - /* New elements should be reflected. The old should be the same */ - (void) printf("\tArray: a[0] = %d, a[15] = %d, a[17] = %d.\n", - (*array)[0], (*array)[15], (*array)[17]); - -cleanup: - PKIX_TEST_RETURN(); -} - -static -void testFree(PKIX_UInt32 *array) -{ - - PKIX_TEST_STD_VARS(); - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Free(array, plContext)); - -cleanup: - PKIX_TEST_RETURN(); -} - -int test_mem(int argc, char *argv[]) { - - unsigned int *array = NULL; - int arraySize = 10; - PKIX_UInt32 actualMinorVersion; - PKIX_UInt32 j = 0; - - PKIX_TEST_STD_VARS(); - - startTests("Memory Allocation"); - - PKIX_TEST_EXPECT_NO_ERROR( - PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext)); - - subTest("PKIX_PL_Malloc"); - testMalloc(&array); - - subTest("PKIX_PL_Realloc"); - testRealloc(&array); - - subTest("PKIX_PL_Free"); - testFree(array); - - /* --Negative Test Cases------------------- */ - /* Create an integer array of size 10 */ - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Malloc( - (PKIX_UInt32)(arraySize*sizeof (unsigned int)), - (void **) &array, plContext)); - - (void) printf("Attempting to reallocate 0 sized memory...\n"); - - PKIX_TEST_EXPECT_NO_ERROR - (PKIX_PL_Realloc(array, 0, (void **) &array, plContext)); - - (void) printf("Attempting to allocate to null pointer...\n"); - - PKIX_TEST_EXPECT_ERROR(PKIX_PL_Malloc(10, NULL, plContext)); - - (void) printf("Attempting to reallocate to null pointer...\n"); - - PKIX_TEST_EXPECT_ERROR(PKIX_PL_Realloc(NULL, 10, NULL, plContext)); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Free(array, plContext)); - -cleanup: - - PKIX_Shutdown(plContext); - - endTests("Memory Allocation"); - - return (0); -} diff --git a/security/nss/cmd/libpkix/pkix_pl/system/test_monitorlock.c b/security/nss/cmd/libpkix/pkix_pl/system/test_monitorlock.c deleted file mode 100644 index 513489747..000000000 --- a/security/nss/cmd/libpkix/pkix_pl/system/test_monitorlock.c +++ /dev/null @@ -1,111 +0,0 @@ -/* 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/. */ -/* - * test_monitorlock.c - * - * Tests basic MonitorLock object functionality. No multi-threading. - * - */ - -#include "testutil.h" -#include "testutil_nss.h" - -static void *plContext = NULL; - -static -void createMonitorLockes( - PKIX_PL_MonitorLock **monitorLock, - PKIX_PL_MonitorLock **monitorLock2, - PKIX_PL_MonitorLock **monitorLock3) -{ - PKIX_TEST_STD_VARS(); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_MonitorLock_Create - (monitorLock, plContext)); - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_MonitorLock_Create - (monitorLock2, plContext)); - - *monitorLock3 = *monitorLock; - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_IncRef - ((PKIX_PL_Object*)*monitorLock3, plContext)); - -cleanup: - PKIX_TEST_RETURN(); -} - -static -void testLock(PKIX_PL_MonitorLock *monitorLock) -{ - PKIX_TEST_STD_VARS(); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_MonitorLock_Enter - (monitorLock, plContext)); - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_MonitorLock_Enter - (monitorLock, plContext)); - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_MonitorLock_Exit - (monitorLock, plContext)); - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_MonitorLock_Exit - (monitorLock, plContext)); - -cleanup: - PKIX_TEST_RETURN(); -} - -static -void testDestroy( - PKIX_PL_MonitorLock *monitorLock, - PKIX_PL_MonitorLock *monitorLock2, - PKIX_PL_MonitorLock *monitorLock3) -{ - PKIX_TEST_STD_VARS(); - - PKIX_TEST_DECREF_BC(monitorLock); - PKIX_TEST_DECREF_BC(monitorLock2); - PKIX_TEST_DECREF_BC(monitorLock3); - -cleanup: - PKIX_TEST_RETURN(); -} - -int test_monitorlock(int argc, char *argv[]) { - - PKIX_PL_MonitorLock *monitorLock, *monitorLock2, *monitorLock3; - PKIX_UInt32 actualMinorVersion; - PKIX_UInt32 j = 0; - - PKIX_TEST_STD_VARS(); - - startTests("MonitorLocks"); - - PKIX_TEST_EXPECT_NO_ERROR( - PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext)); - - subTest("PKIX_PL_MonitorLock_Create"); - createMonitorLockes(&monitorLock, &monitorLock2, &monitorLock3); - - PKIX_TEST_EQ_HASH_TOSTR_DUP - (monitorLock, - monitorLock3, - monitorLock2, - NULL, - MonitorLock, - PKIX_FALSE); - - subTest("PKIX_PL_MonitorLock_Lock/Unlock"); - testLock(monitorLock); - - subTest("PKIX_PL_MonitorLock_Destroy"); - testDestroy(monitorLock, monitorLock2, monitorLock3); - -cleanup: - - PKIX_Shutdown(plContext); - - PKIX_TEST_RETURN(); - - endTests("MonitorLockes"); - - return (0); - -} diff --git a/security/nss/cmd/libpkix/pkix_pl/system/test_mutex.c b/security/nss/cmd/libpkix/pkix_pl/system/test_mutex.c deleted file mode 100644 index f40ad44ab..000000000 --- a/security/nss/cmd/libpkix/pkix_pl/system/test_mutex.c +++ /dev/null @@ -1,103 +0,0 @@ -/* 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/. */ -/* - * test_mutex.c - * - * Tests basic mutex object functionality. No multi-threading. - * - */ - -#include "testutil.h" -#include "testutil_nss.h" - -static void *plContext = NULL; - -static -void createMutexes( - PKIX_PL_Mutex **mutex, - PKIX_PL_Mutex **mutex2, - PKIX_PL_Mutex **mutex3) -{ - PKIX_TEST_STD_VARS(); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Mutex_Create(mutex, plContext)); - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Mutex_Create(mutex2, plContext)); - - *mutex3 = *mutex; - PKIX_TEST_EXPECT_NO_ERROR - (PKIX_PL_Object_IncRef((PKIX_PL_Object*)*mutex3, plContext)); - -cleanup: - PKIX_TEST_RETURN(); -} - -static -void testLock(PKIX_PL_Mutex *mutex) -{ - PKIX_TEST_STD_VARS(); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Mutex_Lock(mutex, plContext)); - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Mutex_Unlock(mutex, plContext)); - -cleanup: - PKIX_TEST_RETURN(); -} - -static -void testDestroy( - PKIX_PL_Mutex *mutex, - PKIX_PL_Mutex *mutex2, - PKIX_PL_Mutex *mutex3) -{ - PKIX_TEST_STD_VARS(); - - PKIX_TEST_DECREF_BC(mutex); - PKIX_TEST_DECREF_BC(mutex2); - PKIX_TEST_DECREF_BC(mutex3); - -cleanup: - PKIX_TEST_RETURN(); -} - -int test_mutex(int argc, char *argv[]) { - - PKIX_PL_Mutex *mutex, *mutex2, *mutex3; - PKIX_UInt32 actualMinorVersion; - PKIX_UInt32 j = 0; - - PKIX_TEST_STD_VARS(); - - startTests("Mutexes"); - - PKIX_TEST_EXPECT_NO_ERROR( - PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext)); - - subTest("PKIX_PL_Mutex_Create"); - createMutexes(&mutex, &mutex2, &mutex3); - - PKIX_TEST_EQ_HASH_TOSTR_DUP - (mutex, - mutex3, - mutex2, - NULL, - Mutex, - PKIX_FALSE); - - subTest("PKIX_PL_Mutex_Lock/Unlock"); - testLock(mutex); - - subTest("PKIX_PL_Mutex_Destroy"); - testDestroy(mutex, mutex2, mutex3); - -cleanup: - - PKIX_Shutdown(plContext); - - PKIX_TEST_RETURN(); - - endTests("Mutexes"); - - return (0); - -} diff --git a/security/nss/cmd/libpkix/pkix_pl/system/test_mutex2.c b/security/nss/cmd/libpkix/pkix_pl/system/test_mutex2.c deleted file mode 100644 index fc433840c..000000000 --- a/security/nss/cmd/libpkix/pkix_pl/system/test_mutex2.c +++ /dev/null @@ -1,160 +0,0 @@ -/* 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/. */ -/* - * test_mutex2.c - * - * Tests multi-threaded functionality of Mutex - * - */ - - -#include "testutil.h" -#include "testutil_nss.h" - -static int box1 = 0, box2 = 0, box3 = 0; -static PKIX_PL_Mutex *mutex; -static PRCondVar *cv; -static void *plContext = NULL; - -static void consumer(/* ARGSUSED */ void* arg) { - PRStatus status = PR_SUCCESS; - PKIX_Error *errorResult; - int i = 0; - for (i = 0; i < 5; i++) { - (void) PKIX_PL_Mutex_Lock(mutex, plContext); - while (((box1 == 0) || - (box2 == 0) || - (box3 == 0)) && - (status == PR_SUCCESS)) - status = PR_WaitCondVar(cv, PR_INTERVAL_NO_TIMEOUT); - - (void) printf("\tConsumer got Box1 = %d ", box1); - box1 = 0; - (void) printf("Box2 = %d ", box2); - box2 = 0; - (void) printf("Box3 = %d\n", box3); - box3 = 0; - - status = PR_NotifyAllCondVar(cv); - if (status == PR_FAILURE) - (void) printf - ("Consumer error while notifying condvar\n"); - errorResult = PKIX_PL_Mutex_Unlock(mutex, plContext); - if (errorResult) testError("PKIX_PL_Mutex_Unlock failed"); - } - (void) printf("Consumer exiting...\n"); -} - -static void producer(void* arg) { - PRStatus status = PR_SUCCESS; - int value = *(int*)arg; - int i = 0; - int *box; - PKIX_Error *errorResult; - if (value == 10) box = &box1; - else if (value == 20) box = &box2; - else if (value == 30) box = &box3; - - for (i = 0; i < 5; i++) { - (void) PKIX_PL_Mutex_Lock(mutex, plContext); - while ((*box != 0) && (status == PR_SUCCESS)) - status = PR_WaitCondVar(cv, PR_INTERVAL_NO_TIMEOUT); - - *box = i+1; - (void) printf - ("\tProducer %d put value: %d\n", value, *box); - - status = PR_NotifyAllCondVar(cv); - if (status == PR_FAILURE) - (void) printf - ("Producer %d error while notifying condvar\n", - value); - errorResult = PKIX_PL_Mutex_Unlock(mutex, plContext); - if (errorResult) testError("PKIX_PL_Mutex_Unlock failed"); - } -} - -int test_mutex2(int argc, char *argv[]) { - - PRThread *consThread, *prodThread, *prodThread2, *prodThread3; - int x = 10, y = 20, z = 30; - PKIX_UInt32 actualMinorVersion; - PKIX_UInt32 j = 0; - - PKIX_TEST_STD_VARS(); - - startTests("Mutex and Threads"); - - PKIX_TEST_EXPECT_NO_ERROR( - PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext)); - - (void) printf("Attempting to create new mutex...\n"); - subTest("Mutex Creation"); - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Mutex_Create(&mutex, plContext)); - - cv = PR_NewCondVar(*(PRLock **) mutex); - - subTest("Starting consumer thread"); - consThread = PR_CreateThread(PR_USER_THREAD, - consumer, - NULL, - PR_PRIORITY_NORMAL, - PR_LOCAL_THREAD, - PR_JOINABLE_THREAD, - 0); - - subTest("Starting producer thread 1"); - prodThread = PR_CreateThread(PR_USER_THREAD, - producer, - &x, - PR_PRIORITY_NORMAL, - PR_LOCAL_THREAD, - PR_JOINABLE_THREAD, - 0); - - subTest("Starting producer thread 2"); - prodThread2 = PR_CreateThread(PR_USER_THREAD, - producer, - &y, - PR_PRIORITY_NORMAL, - PR_LOCAL_THREAD, - PR_JOINABLE_THREAD, - 0); - - subTest("Starting producer thread 3"); - prodThread3 = PR_CreateThread(PR_USER_THREAD, - producer, - &z, - PR_PRIORITY_NORMAL, - PR_LOCAL_THREAD, - PR_JOINABLE_THREAD, - 0); - - - PR_JoinThread(consThread); - - (void) PR_DestroyCondVar(cv); - PKIX_TEST_DECREF_BC(mutex); - - /* - * Note: we should also be freeing each thread's stack, but we - * don't have access to the prodThread->stack variable (since - * it is not exported). As a result, we have 120 bytes of memory - * leakage. - */ - - PR_Free(prodThread); - PR_Free(prodThread2); - PR_Free(prodThread3); - -cleanup: - - PKIX_Shutdown(plContext); - - PKIX_TEST_RETURN(); - - endTests("Mutex and Threads"); - - return (0); -} diff --git a/security/nss/cmd/libpkix/pkix_pl/system/test_mutex3.c b/security/nss/cmd/libpkix/pkix_pl/system/test_mutex3.c deleted file mode 100644 index 2bcbd4aab..000000000 --- a/security/nss/cmd/libpkix/pkix_pl/system/test_mutex3.c +++ /dev/null @@ -1,94 +0,0 @@ -/* 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/. */ -/* - * test_mutex3.c - * - * Tests multi-threaded functionality of Mutex - * - */ - -#include "testutil.h" -#include "testutil_nss.h" - -static PKIX_PL_Mutex *mutex; -static void *plContext = NULL; - -static void t1(/* ARGSUSED */ void* arg) { - PKIX_Error *errorResult; - - (void) printf("t1 acquiring lock...\n"); - errorResult = PKIX_PL_Mutex_Lock(mutex, plContext); - if (errorResult) testError("PKIX_PL_Mutex_Lock failed"); - - (void) printf("t1 sleeplng for 3 seconds\n"); - PR_Sleep(PR_SecondsToInterval(3)); - (void) printf("t1 releasing lock...\n"); - - errorResult = PKIX_PL_Mutex_Unlock(mutex, plContext); - if (errorResult) testError("PKIX_PL_Mutex_Unlock failed"); - - (void) printf("t1 exiting...\n"); -} - -static void t2(/* ARGSUSED */ void* arg) { - PKIX_Error *errorResult; - - (void) printf("t2 acquiring lock...\n"); - errorResult = PKIX_PL_Mutex_Lock(mutex, plContext); - if (errorResult) testError("PKIX_PL_Mutex_Lock failed"); - - (void) printf("t2 releasing lock...\n"); - errorResult = PKIX_PL_Mutex_Unlock(mutex, plContext); - if (errorResult) testError("PKIX_PL_Mutex_Unlock failed"); - - (void) printf("t2 exiting...\n"); -} - -int test_mutex3(int argc, char *argv[]) { - PRThread *thread, *thread2; - PKIX_UInt32 actualMinorVersion; - PKIX_UInt32 j = 0; - - PKIX_TEST_STD_VARS(); - - startTests("Mutex and Threads"); - - PKIX_TEST_EXPECT_NO_ERROR( - PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext)); - - subTest("Mutex Creation"); - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Mutex_Create(&mutex, plContext)); - - subTest("Starting thread"); - thread = PR_CreateThread(PR_USER_THREAD, - t1, - NULL, - PR_PRIORITY_NORMAL, - PR_LOCAL_THREAD, - PR_JOINABLE_THREAD, - 0); - - thread2 = PR_CreateThread(PR_USER_THREAD, - t2, - NULL, - PR_PRIORITY_NORMAL, - PR_LOCAL_THREAD, - PR_JOINABLE_THREAD, - 0); - - PR_JoinThread(thread2); - PR_JoinThread(thread); - -cleanup: - - PKIX_TEST_DECREF_AC(mutex); - - PKIX_Shutdown(plContext); - - PKIX_TEST_RETURN(); - - endTests("Mutex and Threads"); - - return (0); -} diff --git a/security/nss/cmd/libpkix/pkix_pl/system/test_object.c b/security/nss/cmd/libpkix/pkix_pl/system/test_object.c deleted file mode 100644 index d94477957..000000000 --- a/security/nss/cmd/libpkix/pkix_pl/system/test_object.c +++ /dev/null @@ -1,289 +0,0 @@ -/* 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/. */ -/* - * test_object.c - * - * Test Object Allocation, toString, Equals, Destruction - * - */ - -#include "testutil.h" -#include "testutil_nss.h" - -static void *plContext = NULL; - -static PKIX_Error * -destructor( - /* ARGSUSED */ PKIX_PL_Object *object, - /* ARGSUSED */ void *plContext) -{ - (void) printf("\tUser defined destructor called\n"); - return (NULL); -} - -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"); - - if (pString == plContext) - testError("Null String"); - - type = (unsigned int)0; - - (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, - plContext); - if (errorResult) testError("PKIX_PL_Object_DecRef failed"); - - return (NULL); -} - -static PKIX_Error * -comparator( - 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); -} - - -static PKIX_Error * -hashcodeCallback( - PKIX_PL_Object *object, - PKIX_UInt32 *pValue, - /* ARGSUSED */ void *plContext) -{ - *pValue = 123456789; - return (NULL); -} - -static PKIX_Error* -equalsCallback( - PKIX_PL_Object *first, - PKIX_PL_Object *second, - PKIX_Boolean *result, - void* plContext) { - - PKIX_UInt32 firstType = 0, secondType = 0; - - if ((first == plContext)||(second == plContext)) - testError("Null Object"); - - (void) PKIX_PL_Object_GetType(first, &firstType, plContext); - - (void) PKIX_PL_Object_GetType(second, &secondType, plContext); - - *result = (firstType == secondType)?PKIX_TRUE:PKIX_FALSE; - - return (NULL); -} - -static void -createObjects( - PKIX_PL_Object **obj, - PKIX_PL_Object **obj2, - PKIX_PL_Object **obj3, - PKIX_PL_Object **obj4) -{ - 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)); - -cleanup: -#endif /* PKIX_USER_OBJECT_TYPE */ - PKIX_TEST_RETURN(); -} - - -static void -testGetType( - PKIX_PL_Object *obj, - PKIX_PL_Object *obj2, - PKIX_PL_Object *obj3) -{ - PKIX_UInt32 testType; - - PKIX_TEST_STD_VARS(); - - PKIX_TEST_EXPECT_NO_ERROR - (PKIX_PL_Object_GetType(obj, &testType, plContext)); - - 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(obj3, &testType, plContext)); - if (testType != 1000) - testError("Object 3 returned the wrong type"); - -cleanup: - - PKIX_TEST_RETURN(); -} - -static void -testCompare( - 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_TEST_EXPECT_NO_ERROR - (PKIX_PL_Object_Compare(obj4, obj2, &cmpResult, plContext)); - 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(); -} - - -static void -testDestroy( - PKIX_PL_Object *obj, - PKIX_PL_Object *obj2, - PKIX_PL_Object *obj3, - PKIX_PL_Object *obj4) -{ - PKIX_TEST_STD_VARS(); - - PKIX_TEST_DECREF_BC(obj); - PKIX_TEST_DECREF_BC(obj2); - PKIX_TEST_DECREF_BC(obj3); - PKIX_TEST_DECREF_BC(obj4); - -cleanup: - - PKIX_TEST_RETURN(); -} - -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(); - - startTests("Objects"); - - PKIX_TEST_EXPECT_NO_ERROR( - PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext)); - - subTest("PKIX_PL_Object_Create"); - createObjects(&obj, &obj2, &obj3, &obj4); - - PKIX_TEST_EQ_HASH_TOSTR_DUP(obj, obj3, obj2, NULL, Object, PKIX_FALSE); - - subTest("PKIX_PL_Object_GetType"); - testGetType(obj, obj2, obj3); - - subTest("PKIX_PL_Object_Compare"); - testCompare(obj2, obj4); - - subTest("PKIX_PL_Object_Destroy"); - testDestroy(obj, obj2, obj3, obj4); - - -cleanup: - - PKIX_Shutdown(plContext); - - endTests("Objects"); -#endif /* PKIX_USER_OBJECT_TYPE */ - return (0); - -} diff --git a/security/nss/cmd/libpkix/pkix_pl/system/test_oid.c b/security/nss/cmd/libpkix/pkix_pl/system/test_oid.c deleted file mode 100644 index 55d95f268..000000000 --- a/security/nss/cmd/libpkix/pkix_pl/system/test_oid.c +++ /dev/null @@ -1,213 +0,0 @@ -/* 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/. */ -/* - * test_oid.c - * - * Test OID Types - * - */ - -#include "testutil.h" -#include "testutil_nss.h" - -static void *plContext = NULL; - -static void -createOID( - PKIX_PL_OID **testOID, - char *oidAscii, - PKIX_Boolean errorHandling) -{ - PKIX_TEST_STD_VARS(); - - if (errorHandling){ - PKIX_TEST_EXPECT_ERROR - (PKIX_PL_OID_Create(oidAscii, testOID, plContext)); - } else { - PKIX_TEST_EXPECT_NO_ERROR - (PKIX_PL_OID_Create(oidAscii, testOID, plContext)); - } - - -cleanup: - - PKIX_TEST_RETURN(); -} - -static void -testToString( - PKIX_PL_OID *oid, - char *expAscii) -{ - PKIX_PL_String *oidString = NULL; - char *temp = NULL; - - PKIX_TEST_STD_VARS(); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_ToString - ((PKIX_PL_Object*)oid, - &oidString, plContext)); - - temp = PKIX_String2ASCII(oidString, plContext); - if (temp == NULL){ - testError("PKIX_String2Ascii failed"); - goto cleanup; - } - - if (PL_strcmp(temp, expAscii) != 0) { - (void) printf("\tOid ToString: %s %s\n", temp, expAscii); - testError("Output string does not match source"); - } - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Free(temp, plContext)); - -cleanup: - - PKIX_TEST_DECREF_AC(oidString); - - PKIX_TEST_RETURN(); -} - -static void -testCompare( - PKIX_PL_OID *oid0, - PKIX_PL_OID *oid1, - PKIX_PL_OID *oid2, - PKIX_PL_OID *oid3) -{ - PKIX_Int32 cmpResult; - PKIX_TEST_STD_VARS(); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_Compare((PKIX_PL_Object*)oid0, - (PKIX_PL_Object*)oid1, - &cmpResult, plContext)); - if (cmpResult <= 0) testError("Invalid Result from OID Compare"); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_Compare((PKIX_PL_Object*)oid1, - (PKIX_PL_Object*)oid0, - &cmpResult, plContext)); - if (cmpResult >= 0) testError("Invalid Result from OID Compare"); - - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_Compare((PKIX_PL_Object*)oid1, - (PKIX_PL_Object*)oid2, - &cmpResult, plContext)); - if (cmpResult >= 0) testError("Invalid Result from OID Compare"); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_Compare((PKIX_PL_Object*)oid2, - (PKIX_PL_Object*)oid1, - &cmpResult, plContext)); - if (cmpResult <= 0) testError("Invalid Result from OID Compare"); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_Compare((PKIX_PL_Object*)oid1, - (PKIX_PL_Object*)oid3, - &cmpResult, plContext)); - if (cmpResult != 0) testError("Invalid Result from OID Compare"); - -cleanup: - - PKIX_TEST_RETURN(); -} - -static void -testDestroy( - PKIX_PL_OID *oid) -{ - PKIX_TEST_STD_VARS(); - - PKIX_TEST_DECREF_BC(oid); - -cleanup: - - PKIX_TEST_RETURN(); -} - - -int test_oid(int argc, char *argv[]) { - - PKIX_PL_OID *testOID[6] = {NULL}; - PKIX_PL_OID *badTestOID = NULL; - PKIX_UInt32 i, size = 6; - PKIX_UInt32 actualMinorVersion; - PKIX_UInt32 j = 0; - - char* validOID[6] = { - "2.11.22222.33333", - "1.2.3.004.5.6.7", - "2.11.22222.33333", - "1.2.3.4.5.6.7", - "1.2.3", - "2.39.3" - }; - - char* expected[6] = { - "2.11.22222.33333", - "1.2.3.4.5.6.7", - "2.11.22222.33333", - "1.2.3.4.5.6.7", - "1.2.3", - "2.39.3" - }; - - char *badOID[11] = { - "1.2.4294967299", - "this. is. a. bad. oid", - "00a1000.002b", - "100.-5.10", - "1.2..3", - ".1.2.3", - "1.2.3.", - "00010.1.2.3", - "1.000041.2.3", - "000000000000000000000000000000000000000010.3.2", - "1" - }; - - PKIX_TEST_STD_VARS(); - - startTests("OIDs"); - - PKIX_TEST_EXPECT_NO_ERROR( - PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext)); - - for (i = 0; i < size; i++) { - subTest("PKIX_PL_OID_Create"); - createOID(&testOID[i], validOID[i], PKIX_FALSE); - } - - PKIX_TEST_EQ_HASH_TOSTR_DUP - (testOID[0], - testOID[2], - testOID[1], - NULL, - OID, - PKIX_FALSE); - - for (i = 0; i < size; i++) { - subTest("PKIX_PL_OID_ToString"); - testToString(testOID[i], expected[i]); - } - - subTest("PKIX_PL_OID_Compare"); - testCompare(testOID[0], testOID[1], testOID[2], testOID[3]); - - for (i = 0; i < size; i++) { - subTest("PKIX_PL_OID_Destroy"); - testDestroy(testOID[i]); - } - - for (i = 0; i < 11; i++) { - subTest("PKIX_PL_OID Error Handling"); - createOID(&badTestOID, badOID[i], PKIX_TRUE); - } - -cleanup: - - PKIX_Shutdown(plContext); - - endTests("OIDs"); - - return (0); - -} diff --git a/security/nss/cmd/libpkix/pkix_pl/system/test_rwlock.c b/security/nss/cmd/libpkix/pkix_pl/system/test_rwlock.c deleted file mode 100644 index fe62dd462..000000000 --- a/security/nss/cmd/libpkix/pkix_pl/system/test_rwlock.c +++ /dev/null @@ -1,194 +0,0 @@ -/* 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/. */ -/* - * test_rwlock.c - * - */ - -#include "testutil.h" -#include "testutil_nss.h" - -static PKIX_PL_RWLock *rwlock = NULL, *rwlock2 = NULL, *rwlock3 = NULL; -static PRThread *thread = NULL, *thread2 = NULL, *thread3 = NULL; -static void *plContext = NULL; - -static void reader(void) { - PKIX_Error *errorResult; - - errorResult = PKIX_PL_AcquireReaderLock(rwlock, NULL); - if (errorResult) testError("PKIX_PL_AcquireReaderLock failed"); - - (void) printf("\t[Thread #1 Read Lock #1.]\n"); - (void) printf("\t[Thread #1 Sleeplng for 1 seconds.]\n"); - PR_Sleep(PR_SecondsToInterval(1)); - PKIX_PL_ReleaseReaderLock(rwlock, NULL); - if (errorResult) testError("PKIX_PL_ReleaseReaderLock failed"); - (void) printf("\t[Thread #1 Read UNLock #1.]\n"); -} - - -static void writer(void) { - PKIX_Error *errorResult; - /* This thread should stick here until lock 1 is released */ - PKIX_PL_AcquireWriterLock(rwlock, NULL); - if (errorResult) testError("PKIX_PL_AcquireWriterLock failed"); - - (void) printf("\t[Thread #2 Write Lock #1.]\n"); - - PKIX_PL_AcquireWriterLock(rwlock2, NULL); - if (errorResult) testError("PKIX_PL_AcquireWriterLock failed"); - (void) printf("\t[Thread #2 Write Lock #2.]\n"); - - (void) printf("\t[Thread #2 Sleeplng for 1 seconds.]\n"); - PR_Sleep(PR_SecondsToInterval(1)); - - PKIX_PL_ReleaseWriterLock(rwlock2, NULL); - if (errorResult) testError("PKIX_PL_ReleaseWriterLock failed"); - (void) printf("\t[Thread #2 Write UNLock #2.]\n"); - - (void) printf("\t[Thread #2 Sleeplng for 1 seconds.]\n"); - PR_Sleep(PR_SecondsToInterval(1)); - - PKIX_PL_ReleaseWriterLock(rwlock, NULL); - if (errorResult) testError("PKIX_PL_ReleaseWriterLock failed"); - (void) printf("\t[Thread #2 Write UNLock #1.]\n"); - - PR_JoinThread(thread3); -} - -static void reader2(void) { - PKIX_Error *errorResult; - /* Reader 2 should yield here until the writer is done */ - - PKIX_PL_AcquireReaderLock(rwlock2, NULL); - if (errorResult) testError("PKIX_PL_AcquireReaderLock failed"); - - (void) printf("\t[Thread #3 Read Lock #2.]\n"); - - PKIX_PL_AcquireReaderLock(rwlock3, NULL); - if (errorResult) testError("PKIX_PL_AcquireReaderLock failed"); - (void) printf("\t[Thread #3 Read Lock #3.]\n"); - - (void) printf("\t[Thread #3 Sleeplng for 1 seconds.]\n"); - PR_Sleep(PR_SecondsToInterval(1)); - - PKIX_PL_ReleaseReaderLock(rwlock3, NULL); - if (errorResult) testError("PKIX_PL_ReleaseReaderLock failed"); - (void) printf("\t[Thread #3 Read UNLock #3.]\n"); - - (void) printf("\t[Thread #3 Sleeplng for 1 seconds.]\n"); - PR_Sleep(PR_SecondsToInterval(1)); - - PKIX_PL_ReleaseReaderLock(rwlock2, NULL); - if (errorResult) testError("PKIX_PL_ReleaseReaderLock failed"); - (void) printf("\t[Thread #3 Read UNLock #2.]\n"); -} - - - -int test_rwlock() { - PKIX_PL_String* outputString = NULL; - PKIX_UInt32 j = 0; - PKIX_Boolean bool; - PKIX_UInt32 actualMinorVersion; - - PKIX_TEST_STD_VARS(); - startTests("RWLocks"); - - PKIX_TEST_EXPECT_NO_ERROR( - PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext)); - - (void) printf("Attempting to create new rwlock...\n"); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_RWLock_Create(&rwlock, plContext)); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_RWLock_Create(&rwlock2, plContext)); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_RWLock_Create(&rwlock3, plContext)); - - /* Test toString functionality */ - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_ToString - ((PKIX_PL_Object*)rwlock, &outputString, plContext)); - - (void) printf("Testing RWLock toString: %s\n", - PKIX_String2ASCII(outputString)); - - PKIX_TEST_DECREF_BC(outputString); - - /* Call Equals on two different objects */ - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_Equals - ((PKIX_PL_Object*)rwlock, - (PKIX_PL_Object*)rwlock2, - &bool, - plContext)); - - (void) printf("Testing RWLock Equals: %d (should be 0)\n", bool); - - if (bool != 0) - testError("Error in RWLock_Equals"); - - /* Call Equals on two equal objects */ - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_Equals((PKIX_PL_Object*)rwlock, - (PKIX_PL_Object*)rwlock, &bool, plContext)); - - (void) printf("Testing RWLock Equals: %d (should be 1)\n", bool); - if (bool != 1) - testError("Error in RWLock_Equals"); - - subTest("Multi-Thread Read/Write Lock Testing"); - - PKIX_TEST_EXPECT_NO_ERROR - (PKIX_PL_AcquireReaderLock(rwlock, plContext)); - (void) printf("\t[Main Thread Read Lock #1.]\n"); - - thread = PR_CreateThread(PR_USER_THREAD, - reader, - NULL, - PR_PRIORITY_NORMAL, - PR_LOCAL_THREAD, - PR_JOINABLE_THREAD, - 0); - - thread2 = PR_CreateThread(PR_USER_THREAD, - writer, - NULL, - PR_PRIORITY_NORMAL, - PR_LOCAL_THREAD, - PR_JOINABLE_THREAD, - 0); - - thread3 = PR_CreateThread(PR_USER_THREAD, - reader2, - NULL, - PR_PRIORITY_NORMAL, - PR_LOCAL_THREAD, - PR_JOINABLE_THREAD, - 0); - - PR_JoinThread(thread); - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_ReleaseReaderLock - (rwlock, plContext)); - (void) printf("\t[Main Thread Read Unlock #1.]\n"); - - PR_JoinThread(thread2); - - - -cleanup: - - /* Test destructor */ - subTest("Testing destructor..."); - PKIX_TEST_DECREF_AC(rwlock); - PKIX_TEST_DECREF_AC(rwlock2); - PKIX_TEST_DECREF_AC(rwlock3); - - pkixTestTempResult = PKIX_Shutdown(plContext); - if (pkixTestTempResult) pkixTestErrorResult = pkixTestTempResult; - - PKIX_TEST_RETURN(); - - endTests("RWLocks"); - - return (0); -} diff --git a/security/nss/cmd/libpkix/pkix_pl/system/test_string.c b/security/nss/cmd/libpkix/pkix_pl/system/test_string.c deleted file mode 100644 index de80ed0f7..000000000 --- a/security/nss/cmd/libpkix/pkix_pl/system/test_string.c +++ /dev/null @@ -1,446 +0,0 @@ -/* 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/. */ -/* - * test_string.c - * - * Tests Strings. - * - */ - -#include "testutil.h" -#include "testutil_nss.h" - -static void *plContext = NULL; - -static void -createString( - PKIX_PL_String **testString, - PKIX_UInt32 format, - char *stringAscii, - PKIX_UInt32 length) -{ - PKIX_TEST_STD_VARS(); - - PKIX_TEST_EXPECT_NO_ERROR - (PKIX_PL_String_Create - (format, stringAscii, length, testString, plContext)); - -cleanup: - - PKIX_TEST_RETURN(); -} - -static void -createStringOther( - PKIX_PL_String **testEscAscii, - PKIX_PL_String **testUtf16, - PKIX_PL_String **ampString, - PKIX_PL_String **testDebugAscii, - PKIX_PL_String **testNullString, - PKIX_UInt32 *utf16data) -{ - char *nullText = "Hi� there!"; - - char *escAsciiString = - "¡𐀀࿿􀀁"; - - char *debugAsciiString = - "string with
newlines and	tabs"; - - char * utfAmp = "\x00&"; - - PKIX_TEST_STD_VARS(); - - createString(testEscAscii, - PKIX_ESCASCII, - escAsciiString, - PL_strlen(escAsciiString)); - - createString(testUtf16, PKIX_UTF16, (char *)utf16data, 12); - - createString(ampString, PKIX_UTF16, utfAmp, 2); - - createString(testDebugAscii, - PKIX_ESCASCII_DEBUG, - debugAsciiString, - PL_strlen(debugAsciiString)); - - createString(testNullString, - PKIX_ESCASCII_DEBUG, - nullText, - PL_strlen(nullText)); - - goto cleanup; - -cleanup: - - PKIX_TEST_RETURN(); -} - -static void -testGetEncoded( - PKIX_PL_String *testEscAscii, - PKIX_PL_String *testString0, - PKIX_PL_String *testDebugAscii, - PKIX_PL_String *testNullString, - PKIX_UInt32 *utf16data) -{ - char *temp = NULL; - void *dest = NULL; - void *dest2 = NULL; - char *plainText = "string with\nnewlines and\ttabs"; - PKIX_UInt32 length, length2, i; - - PKIX_TEST_STD_VARS(); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_GetEncoded(testEscAscii, - PKIX_UTF16, - &dest, - &length, - plContext)); - for (i = 0; i < length; i++) { - if (((char*)dest)[i] != ((char*)utf16data)[i]) { - testError("UTF-16 Data Differs from Source"); - printf("%d-th char is different -%c-%c-\n", i, - ((char*)dest)[i], ((char*)utf16data)[i]); - } - } - - length = 0; - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Free(dest, plContext)); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_GetEncoded(testNullString, - PKIX_UTF16, - &dest, - &length, - plContext)); - - length = 0; - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Free(dest, plContext)); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_GetEncoded(testString0, - PKIX_ESCASCII_DEBUG, - &dest, - &length, - plContext)); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_GetEncoded(testDebugAscii, - PKIX_ESCASCII_DEBUG, - &dest2, - &length2, - plContext)); - - for (i = 0; (i < length) && (i < length2); i++) - if (((char*)dest)[i] != ((char*)dest2)[i]) { - testError("Equivalent strings are unequal"); - break; - } - - length = 0; - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Free(dest, plContext)); - length2 = 0; - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Free(dest2, plContext)); - - temp = PKIX_String2ASCII(testDebugAscii, plContext); - if (temp){ - if (PL_strcmp(plainText, temp) != 0) - testError("Debugged ASCII does not match " - "equivalent EscAscii"); - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Free(temp, plContext)); - } - -cleanup: - - PKIX_TEST_RETURN(); -} - -static void -testSprintf(void) -{ - PKIX_Int32 x = 0xCAFE; - PKIX_Int32 y = -12345; - PKIX_PL_String *testString = NULL; - PKIX_PL_String *formatString = NULL; - PKIX_PL_String *sprintfString = NULL; - char *plainText = "Testing Sprintf"; - char *format = "%s %x %u %d"; - char *convertedFormat = "%s %lx %lu %ld"; - char *temp = NULL; - char *temp2 = NULL; - - PKIX_TEST_STD_VARS(); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_Create( - PKIX_ESCASCII, - plainText, - PL_strlen(plainText), - &testString, - plContext)); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_Create( - PKIX_ESCASCII, - format, - 11, - &formatString, - plContext)); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Sprintf(&sprintfString, - plContext, - formatString, - testString, x, y, y)); - PKIX_TEST_DECREF_BC(testString); - - temp = PR_smprintf(convertedFormat, plainText, x, y, y); - temp2 = PKIX_String2ASCII(sprintfString, plContext); - - if (PL_strcmp(temp, temp2) != 0) - testError("Sprintf produced incorrect output"); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Free(temp, plContext)); - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Free(temp2, plContext)); - - - PKIX_TEST_DECREF_BC(sprintfString); - - - PKIX_TEST_DECREF_BC(formatString); - - -cleanup: - - PKIX_TEST_RETURN(); -} - -static void -testErrorHandling(void) -{ - char *debugAsciiString = - "string with
newlines and	tabs"; - - PKIX_PL_String *testString = NULL; - - PKIX_TEST_STD_VARS(); - - PKIX_TEST_EXPECT_ERROR(PKIX_PL_String_Create( - PKIX_ESCASCII, - NULL, - 50, - &testString, - plContext)); - - PKIX_TEST_EXPECT_ERROR(PKIX_PL_String_Create(PKIX_ESCASCII, - "blah", 4, NULL, plContext)); - - PKIX_TEST_EXPECT_ERROR(PKIX_PL_Sprintf(&testString, plContext, NULL)); - - PKIX_TEST_EXPECT_ERROR - (PKIX_PL_GetString(0, NULL, &testString, plContext)); - - PKIX_TEST_EXPECT_ERROR(PKIX_PL_GetString(0, "blah", 0, plContext)); - - /* ---------------------------- */ - subTest("Unicode Error Handling"); - - /* &#x must be followed by 4 hexadecimal digits */ - PKIX_TEST_EXPECT_ERROR(PKIX_PL_String_Create( - PKIX_ESCASCII, - "k;", - 7, - &testString, - plContext)); - - /* &#x must be followed by 4 hexadecimal digits */ - PKIX_TEST_EXPECT_ERROR(PKIX_PL_String_Create( - PKIX_ESCASCII, - "abc�", - 8, - &testString, - plContext)); - - /* &#x must be between 00010000-0010FFFF */ - PKIX_TEST_EXPECT_ERROR(PKIX_PL_String_Create( - PKIX_ESCASCII, - "�", - 11, - &testString, - plContext)); - - /* &#x must be followed by 8 hexadecimal digits */ - PKIX_TEST_EXPECT_ERROR(PKIX_PL_String_Create( - PKIX_ESCASCII, - "က", - 10, - &testString, - plContext)); - - /* &#x must be followed by 8 hexadecimal digits */ - PKIX_TEST_EXPECT_ERROR(PKIX_PL_String_Create( - PKIX_ESCASCII, - "m00;", - 10, - &testString, - plContext)); - - /* Byte values D800-DFFF are reserved */ - PKIX_TEST_EXPECT_ERROR(PKIX_PL_String_Create( - PKIX_ESCASCII, - "�", - 7, - &testString, - plContext)); - - /* Can't use &#x for regular characters */ - PKIX_TEST_EXPECT_ERROR(PKIX_PL_String_Create( - PKIX_ESCASCII, - "2", - 7, - &testString, - plContext)); - - /* Can't use non-printable characters */ - PKIX_TEST_EXPECT_ERROR(PKIX_PL_String_Create( - PKIX_ESCASCII, - "\xA1", - 1, - &testString, - plContext)); - - /* Only legal \\ characters are \\, u and U */ - PKIX_TEST_EXPECT_ERROR(PKIX_PL_String_Create( - PKIX_ESCASCII, - "&blah", - 5, - &testString, - plContext)); - - - - /* Surrogate pairs must be legal */ - PKIX_TEST_EXPECT_ERROR(PKIX_PL_String_Create( - PKIX_UTF16, - "\xd8\x00\x0\x66", - 4, - &testString, - plContext)); - - /* Debugged EscASCII should not be accepted as EscASCII */ - PKIX_TEST_EXPECT_ERROR(PKIX_PL_String_Create( - PKIX_ESCASCII, - debugAsciiString, - PL_strlen(debugAsciiString), - &testString, - plContext)); -cleanup: - - PKIX_TEST_RETURN(); -} - -static void -testDestroy( - PKIX_PL_String *string) -{ - PKIX_TEST_STD_VARS(); - - PKIX_TEST_DECREF_BC(string); - -cleanup: - - PKIX_TEST_RETURN(); -} - - -int test_string(int argc, char *argv[]) { - - PKIX_PL_String *testString[6] = {NULL}; - PKIX_PL_String *testNullString = NULL; - PKIX_PL_String *testDebugAscii = NULL; - PKIX_PL_String *testEscAscii = NULL; - PKIX_PL_String *testUtf16 = NULL; - PKIX_PL_String *ampString = NULL; - unsigned char utf16Data[] = {0x00, 0xA1, 0xD8, 0x00, - 0xDC, 0x00, 0x0F, 0xFF, - 0xDB, 0xC0, 0xDC, 0x01}; - PKIX_UInt32 i, size = 6; - - char *plainText[6] = { - "string with\nnewlines and\ttabs", - "Not an escaped char: &#x0012;", - "Encode & with &amp; in ASCII", - "¡", - "&", - "string with\nnewlines and\ttabs" - }; - - PKIX_UInt32 actualMinorVersion; - PKIX_UInt32 j = 0; - - PKIX_TEST_STD_VARS(); - - startTests("Strings"); - - PKIX_TEST_EXPECT_NO_ERROR( - PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext)); - - subTest("PKIX_PL_String_Create <ascii format>"); - for (i = 0; i < size; i++) { - testString[i] = NULL; - createString - (&testString[i], - PKIX_ESCASCII, - plainText[i], - PL_strlen(plainText[i])); - } - - subTest("PKIX_PL_String_Create <other formats>"); - createStringOther - (&testEscAscii, - &testUtf16, - &String, - &testDebugAscii, - &testNullString, - (PKIX_UInt32 *)utf16Data); - - PKIX_TEST_EQ_HASH_TOSTR_DUP - (testString[0], - testString[5], - testString[1], - plainText[0], - String, - PKIX_TRUE); - - subTest("PKIX_PL_String_GetEncoded"); - testGetEncoded - (testEscAscii, - testString[0], - testDebugAscii, - testNullString, - (PKIX_UInt32 *)utf16Data); - - subTest("PKIX_PL_Sprintf"); - testSprintf(); - - subTest("PKIX_PL_String_Create <error_handling>"); - testErrorHandling(); - - subTest("PKIX_PL_String_Destroy"); - for (i = 0; i < size; i++) { - testDestroy(testString[i]); - } - testDestroy(testEscAscii); - testDestroy(testUtf16); - testDestroy(ampString); - testDestroy(testDebugAscii); - testDestroy(testNullString); - -cleanup: - - PKIX_Shutdown(plContext); - - PKIX_TEST_RETURN(); - - endTests("String"); - - return (0); - -} diff --git a/security/nss/cmd/libpkix/pkix_pl/system/test_string2.c b/security/nss/cmd/libpkix/pkix_pl/system/test_string2.c deleted file mode 100644 index 8424c4874..000000000 --- a/security/nss/cmd/libpkix/pkix_pl/system/test_string2.c +++ /dev/null @@ -1,342 +0,0 @@ -/* 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/. */ -/* - * test_string2.c - * - * Tests International Strings - * - */ - -#include "testutil.h" -#include "testutil_nss.h" - -static void *plContext = NULL; - -static void -createString( - PKIX_PL_String **vivaEspanaString, - PKIX_PL_String **straussString, - PKIX_PL_String **gorbachevString, - PKIX_PL_String **testUTF16String, - PKIX_PL_String **chineseString, - PKIX_PL_String **jeanRenoString) -{ - /* this is meant to fail - it highlights bug 0002 */ - unsigned char utf16String[4] = { 0xF8, 0x60, - 0xFC, 0x60}; - - unsigned char chinese[16] = { 0xe7, 0xab, 0xa0, - 0xe5, 0xad, 0x90, - 0xe6, 0x80, 0xa1, - 0x20, - 0xe4, 0xb8, 0xad, - 0xe5, 0x9b, 0xbd - }; - - char* jeanReno = "Jean R\303\251no is an actor."; - char* gorbachev = /* This is the name "Gorbachev" in cyrllic */ - "\xd0\x93\xd0\xbe\xd1\x80\xd0\xb1\xd0\xb0\xd1\x87\xd1\x91\xd0\xb2"; - - char *vivaEspana = - "¡Viva España!"; - - char *strauss = - "Strauß was born in Österreich"; - - PKIX_TEST_STD_VARS(); - - /* ---------------------------- */ - subTest("String Creation"); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_Create( - PKIX_ESCASCII, - vivaEspana, - PL_strlen(vivaEspana), - vivaEspanaString, - plContext)); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_Create( - PKIX_ESCASCII, - strauss, - PL_strlen(strauss), - straussString, - plContext)); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_Create( - PKIX_UTF8, - gorbachev, - PL_strlen(gorbachev), - gorbachevString, - plContext)); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_Create( - PKIX_UTF16, - utf16String, - 4, - testUTF16String, - plContext)); - - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_Create( - PKIX_UTF8, - chinese, - 16, - chineseString, - plContext)); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_Create( - PKIX_UTF8, - jeanReno, - PL_strlen(jeanReno), - jeanRenoString, - plContext)); - -cleanup: - - PKIX_TEST_RETURN(); -} - -static void -testGetEncoded(PKIX_PL_String *string, PKIX_UInt32 format) -{ - void *dest = NULL; - PKIX_UInt32 length; - - PKIX_TEST_STD_VARS(); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_GetEncoded - (string, - format, - &dest, - &length, - plContext)); - - if (dest){ - (void) printf("\tResult: %s\n", (char *)dest); - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Free(dest, plContext)); - } - -cleanup: - PKIX_TEST_RETURN(); -} - - -static void -testHTMLOutput( - PKIX_PL_String *vivaEspanaString, - PKIX_PL_String *straussString, - PKIX_PL_String *gorbachevString, - PKIX_PL_String *testUTF16String, - PKIX_PL_String *chineseString, - PKIX_PL_String *jeanRenoString) -{ - void *dest = NULL; - PKIX_UInt32 length; - - FILE *htmlFile = NULL; - - PKIX_TEST_STD_VARS(); - - /* Opening a file for output */ - htmlFile = fopen("utf8.html", "w"); - - if (htmlFile != plContext) { - (void) fprintf(htmlFile, "<html><head>\n"); - (void) fprintf(htmlFile, "<meta http-equiv=\"Content-Type\""); - (void) fprintf(htmlFile, - "content = \"text/html; charset = UTF-8\">\n"); - (void) fprintf(htmlFile, "</head><body>\n"); - (void) fprintf(htmlFile, "<font size =\"+2\">\n"); - } else - (void) printf("Could not open HTML file\n"); - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_GetEncoded(testUTF16String, - PKIX_UTF8, - &dest, - &length, - plContext)); - if (htmlFile != plContext) { - (void) printf("%d bytes written to HTML file\n", - fwrite(dest, length, 1, htmlFile)); - (void) fprintf(htmlFile, "<BR>\n"); - } - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Free(dest, plContext)); - dest = NULL; - length = 0; - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_GetEncoded(chineseString, - PKIX_UTF8, - &dest, - &length, - plContext)); - if (htmlFile != plContext) { - (void) printf("%d bytes written to HTML file\n", - fwrite(dest, length, 1, htmlFile)); - (void) fprintf(htmlFile, "<BR>\n"); - } - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Free(dest, plContext)); - dest = NULL; - length = 0; - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_GetEncoded(jeanRenoString, - PKIX_UTF8, - &dest, - &length, - plContext)); - if (htmlFile != plContext) { - (void) printf("%d bytes written to HTML file\n", - fwrite(dest, length, 1, htmlFile)); - (void) fprintf(htmlFile, "<BR>\n"); - } - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Free(dest, plContext)); - dest = NULL; - length = 0; - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_GetEncoded(vivaEspanaString, - PKIX_UTF8, - &dest, - &length, - plContext)); - if (htmlFile != plContext) { - (void) printf("%d bytes written to HTML file\n", - fwrite(dest, length, 1, htmlFile)); - (void) fprintf(htmlFile, "<BR>\n"); - } - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Free(dest, plContext)); - dest = NULL; - length = 0; - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_GetEncoded(straussString, - PKIX_UTF8, - &dest, - &length, - plContext)); - if (htmlFile != plContext) { - (void) printf("%d bytes written to HTML file\n", - fwrite(dest, length, 1, htmlFile)); - (void) fprintf(htmlFile, "<BR>\n"); - } - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Free(dest, plContext)); - dest = NULL; - length = 0; - - - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_GetEncoded(straussString, - PKIX_UTF8, - &dest, - &length, - plContext)); - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Free(dest, plContext)); - dest = NULL; - length = 0; - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_GetEncoded(gorbachevString, - PKIX_UTF8, - &dest, - &length, - plContext)); - if (htmlFile != plContext) { - (void) printf("%d bytes written to HTML file\n", - fwrite(dest, length, 1, htmlFile)); - (void) fprintf(htmlFile, "<BR>\n"); - } - - PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Free(dest, plContext)); - dest = NULL; - length = 0; - - if (htmlFile != plContext) { - (void) fprintf(htmlFile, "</font>\n"); - (void) fprintf(htmlFile, "</body></html>\n"); - (void) fclose(htmlFile); - } - -cleanup: - - PKIX_TEST_RETURN(); -} - -static void -testDestroy( - PKIX_PL_String *string) -{ - PKIX_TEST_STD_VARS(); - - PKIX_TEST_DECREF_BC(string); - -cleanup: - - PKIX_TEST_RETURN(); -} - -int test_string2(int argc, char *argv[]) { - - PKIX_PL_String *vivaEspanaString, *straussString, *testUTF16String; - PKIX_PL_String *chineseString, *jeanRenoString, *gorbachevString; - PKIX_UInt32 actualMinorVersion; - PKIX_UInt32 j = 0; - - PKIX_TEST_STD_VARS(); - - startTests("Unicode Strings"); - - PKIX_TEST_EXPECT_NO_ERROR( - PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext)); - - subTest("PKIX_PL_String_Create"); - createString(&vivaEspanaString, - &straussString, - &gorbachevString, - &testUTF16String, - &chineseString, - &jeanRenoString); - - subTest("Converting UTF-16 to EscASCII"); - testGetEncoded(testUTF16String, PKIX_ESCASCII); - - subTest("Converting UTF-8 to EscASCII"); - testGetEncoded(chineseString, PKIX_ESCASCII); - - subTest("Converting UTF-8 to EscASCII"); - testGetEncoded(jeanRenoString, PKIX_ESCASCII); - - subTest("Converting EscASCII to UTF-16"); - testGetEncoded(vivaEspanaString, PKIX_UTF16); - - subTest("Converting UTF-8 to UTF-16"); - testGetEncoded(chineseString, PKIX_UTF16); - - subTest("Creating HTML Output File \'utf8.html\'"); - testHTMLOutput(vivaEspanaString, - straussString, - gorbachevString, - testUTF16String, - chineseString, - jeanRenoString); - - subTest("Unicode Destructors"); - testDestroy(testUTF16String); - testDestroy(chineseString); - testDestroy(jeanRenoString); - testDestroy(vivaEspanaString); - testDestroy(straussString); - testDestroy(gorbachevString); - -cleanup: - - PKIX_Shutdown(plContext); - - PKIX_TEST_RETURN(); - - endTests("Unicode Strings"); - - return (0); - -} |