Fix some typo and comments
[openssl.git] / test / asn1_encode_test.c
index 7d762ae3c25e1a38398d3407dbcea6c10208297a..3b8d4184be74e9adee0928ce3bf0e1acf09f7255 100644 (file)
@@ -41,6 +41,9 @@ static unsigned char t_one[] = {
 static unsigned char t_one_neg[] = {
     0xff
 };
+static unsigned char t_minus_256[] = {
+    0xff, 0x00
+};
 static unsigned char t_longundef[] = {
     0x7f, 0xff, 0xff, 0xff
 };
@@ -99,6 +102,7 @@ static TEST_CUSTOM_DATA test_custom_data[] = {
     CUSTOM_DATA(t_longundef),
     CUSTOM_DATA(t_one),
     CUSTOM_DATA(t_one_neg),
+    CUSTOM_DATA(t_minus_256),
     CUSTOM_DATA(t_9bytes_1),
     CUSTOM_DATA(t_8bytes_1),
     CUSTOM_DATA(t_8bytes_2),
@@ -200,6 +204,7 @@ static ASN1_LONG_DATA long_expected_32bit[] = {
     { 0, 0, 0 }, { 0xff, 1, 0x7fffffff }, /* t_longundef */
     CUSTOM_EXPECTED_SUCCESS(1, 1), /* t_one */
     CUSTOM_EXPECTED_SUCCESS(-1, -1), /* t_one_neg */
+    CUSTOM_EXPECTED_SUCCESS(-256, -256), /* t_minus_256 */
     CUSTOM_EXPECTED_FAILURE,     /* t_9bytes_1 */
     CUSTOM_EXPECTED_FAILURE,     /* t_8bytes_1 */
     CUSTOM_EXPECTED_FAILURE,     /* t_8bytes_2 */
@@ -235,6 +240,7 @@ static ASN1_LONG_DATA long_expected_64bit[] = {
     { 0, 0, 0 }, { 0xff, 1, 0x7fffffff }, /* t_longundef */
     CUSTOM_EXPECTED_SUCCESS(1, 1), /* t_one */
     CUSTOM_EXPECTED_SUCCESS(-1, -1), /* t_one_neg */
+    CUSTOM_EXPECTED_SUCCESS(-256, -256), /* t_minus_256 */
     CUSTOM_EXPECTED_FAILURE,     /* t_9bytes_1 */
     CUSTOM_EXPECTED_FAILURE,     /* t_8bytes_1 */
     CUSTOM_EXPECTED_SUCCESS(LONG_MAX, LONG_MAX), /* t_8bytes_2 */
@@ -287,6 +293,7 @@ static ASN1_INT32_DATA int32_expected[] = {
     CUSTOM_EXPECTED_SUCCESS(ASN1_LONG_UNDEF, ASN1_LONG_UNDEF), /* t_zero */
     CUSTOM_EXPECTED_SUCCESS(1, 1), /* t_one */
     CUSTOM_EXPECTED_SUCCESS(-1, -1), /* t_one_neg */
+    CUSTOM_EXPECTED_SUCCESS(-256, -256), /* t_minus_256 */
     CUSTOM_EXPECTED_FAILURE,     /* t_9bytes_1 */
     CUSTOM_EXPECTED_FAILURE,     /* t_8bytes_1 */
     CUSTOM_EXPECTED_FAILURE,     /* t_8bytes_2 */
@@ -334,6 +341,7 @@ static ASN1_UINT32_DATA uint32_expected[] = {
     CUSTOM_EXPECTED_SUCCESS(ASN1_LONG_UNDEF, ASN1_LONG_UNDEF), /* t_zero */
     CUSTOM_EXPECTED_SUCCESS(1, 1), /* t_one */
     CUSTOM_EXPECTED_FAILURE,     /* t_one_neg (illegal negative value) */
+    CUSTOM_EXPECTED_FAILURE,     /* t_minus_256 (illegal negative value) */
     CUSTOM_EXPECTED_FAILURE,     /* t_9bytes_1 */
     CUSTOM_EXPECTED_FAILURE,     /* t_8bytes_1 */
     CUSTOM_EXPECTED_FAILURE,     /* t_8bytes_2 */
@@ -381,6 +389,7 @@ static ASN1_INT64_DATA int64_expected[] = {
     CUSTOM_EXPECTED_SUCCESS(ASN1_LONG_UNDEF, ASN1_LONG_UNDEF), /* t_zero */
     CUSTOM_EXPECTED_SUCCESS(1, 1), /* t_one */
     CUSTOM_EXPECTED_SUCCESS(-1, -1), /* t_one_neg */
+    CUSTOM_EXPECTED_SUCCESS(-256, -256), /* t_minus_256 */
     CUSTOM_EXPECTED_FAILURE,     /* t_9bytes_1 */
     CUSTOM_EXPECTED_FAILURE,     /* t_8bytes_1 (too large positive) */
     CUSTOM_EXPECTED_SUCCESS(INT64_MAX, INT64_MAX), /* t_8bytes_2 */
@@ -429,6 +438,7 @@ static ASN1_UINT64_DATA uint64_expected[] = {
     CUSTOM_EXPECTED_SUCCESS(ASN1_LONG_UNDEF, ASN1_LONG_UNDEF), /* t_zero */
     CUSTOM_EXPECTED_SUCCESS(1, 1), /* t_one */
     CUSTOM_EXPECTED_FAILURE,     /* t_one_neg (illegal negative value) */
+    CUSTOM_EXPECTED_FAILURE,     /* t_minus_256 (illegal negative value) */
     CUSTOM_EXPECTED_FAILURE,     /* t_9bytes_1 */
     CUSTOM_EXPECTED_SUCCESS((uint64_t)INT64_MAX+1, (uint64_t)INT64_MAX+1),
                                  /* t_8bytes_1 */
@@ -662,7 +672,7 @@ static int do_decode_custom(const TEST_CUSTOM_DATA *custom_data,
 {
     unsigned char *encoding = NULL;
     /*
-     * We force the defaults to be explicitely encoded to make sure we test
+     * We force the defaults to be explicitly encoded to make sure we test
      * for defaults that shouldn't be present (i.e. we check for failure)
      */
     size_t encoding_length = make_custom_der(custom_data, &encoding, 1);
@@ -702,14 +712,12 @@ static int do_print_item(const TEST_PACKAGE *package)
     unsigned char buf[DATA_BUF_SIZE];
     const ASN1_ITEM *i = ASN1_ITEM_ptr(package->asn1_type);
     ASN1_VALUE *o = (ASN1_VALUE *)&buf;
-    BIO *bio = BIO_new_fp(stdout, 0);
     int ret;
 
     OPENSSL_assert(package->encode_expectations_elem_size <= DATA_BUF_SIZE);
 
     (void)RAND_bytes(buf, (int)package->encode_expectations_elem_size);
-    ret = ASN1_item_print(bio, o, 0, i, NULL);
-    BIO_free(bio);
+    ret = ASN1_item_print(bio_err, o, 0, i, NULL);
 
     return ret;
 }
@@ -735,18 +743,16 @@ static int test_intern(const TEST_PACKAGE *package)
                                                ->encode_expectations)[pos],
                                  &test_custom_data[i], package)) {
         case -1:
-            fprintf(stderr, "Failed custom encode round trip %u of %s\n",
-                    i, package->name);
-            ERR_print_errors_fp(stderr);
+            TEST_error("Failed custom encode round trip %u of %s",
+                       i, package->name);
+            TEST_openssl_errors();
             fail++;
-            ERR_clear_error();
             break;
         case 0:
-            fprintf(stderr, "Custom encode round trip %u of %s mismatch\n",
-                    i, package->name);
-            ERR_print_errors_fp(stderr);
+            TEST_error("Custom encode round trip %u of %s mismatch",
+                       i, package->name);
+            TEST_openssl_errors();
             fail++;
-            ERR_clear_error();
             break;
         case 1:
             break;
@@ -760,18 +766,16 @@ static int test_intern(const TEST_PACKAGE *package)
                                  package->encode_expectations_elem_size,
                                  package)) {
         case -1:
-            fprintf(stderr, "Failed custom decode round trip %u of %s\n",
-                    i, package->name);
-            ERR_print_errors_fp(stderr);
+            TEST_error("Failed custom decode round trip %u of %s",
+                       i, package->name);
+            TEST_openssl_errors();
             fail++;
-            ERR_clear_error();
             break;
         case 0:
-            fprintf(stderr, "Custom decode round trip %u of %s mismatch\n",
-                    i, package->name);
-            ERR_print_errors_fp(stderr);
+            TEST_error("Custom decode round trip %u of %s mismatch",
+                       i, package->name);
+            TEST_openssl_errors();
             fail++;
-            ERR_clear_error();
             break;
         case 1:
             break;
@@ -790,15 +794,14 @@ static int test_intern(const TEST_PACKAGE *package)
                            package->encdec_data_elem_size,
                            package)) {
         case -1:
-            fprintf(stderr, "Failed encode/decode round trip %u of %s\n",
-                    i, package->name);
-            ERR_print_errors_fp(stderr);
-            ERR_clear_error();
+            TEST_error("Failed encode/decode round trip %u of %s",
+                       i, package->name);
+            TEST_openssl_errors();
             fail++;
             break;
         case 0:
-            fprintf(stderr, "Encode/decode round trip %u of %s mismatch\n",
-                    i, package->name);
+            TEST_error("Encode/decode round trip %u of %s mismatch",
+                       i, package->name);
             fail++;
             break;
         case 1:
@@ -810,8 +813,8 @@ static int test_intern(const TEST_PACKAGE *package)
     }
 
     if (!do_print_item(package)) {
-        fprintf(stderr, "Printing of %s failed\n", package->name);
-        ERR_print_errors_fp(stderr);
+        TEST_error("Printing of %s failed", package->name);
+        TEST_openssl_errors();
         fail++;
     }
 
@@ -850,7 +853,7 @@ static int test_uint64(void)
     return test_intern(&uint64_test_package);
 }
 
-void register_tests(void)
+int setup_tests(void)
 {
 #if OPENSSL_API_COMPAT < 0x10200000L
     ADD_TEST(test_long_32bit);
@@ -860,4 +863,5 @@ void register_tests(void)
     ADD_TEST(test_uint32);
     ADD_TEST(test_int64);
     ADD_TEST(test_uint64);
+    return 1;
 }