Add test recipes for internal SM2 tests
[openssl.git] / test / packettest.c
index 7ee4a08fe04752d46fac64a01cce4df8cf12e33f..e58d8d8bcfaa473d16af1d604785bc2b6bf8da1b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved.
  *
  * Licensed under the OpenSSL license (the "License").  You may not use
  * this file except in compliance with the License.  You can obtain a copy
@@ -9,46 +9,45 @@
 
 #include "../ssl/packet_locl.h"
 #include "testutil.h"
-#include "test_main.h"
 
 #define BUF_LEN 255
 
 static unsigned char smbuf[BUF_LEN];
 
-static int test_PACKET_remaining()
+static int test_PACKET_remaining(void)
 {
     PACKET pkt;
 
-    if (!TEST_true(PACKET_buf_init(&pkt, smbuf, sizeof(smbuf))
+    if (!TEST_true(PACKET_buf_init(&pkt, smbuf, sizeof(smbuf)))
             || !TEST_size_t_eq(PACKET_remaining(&pkt), BUF_LEN)
             || !TEST_true(PACKET_forward(&pkt, BUF_LEN - 1))
             || !TEST_size_t_eq(PACKET_remaining(&pkt), 1)
             || !TEST_true(PACKET_forward(&pkt, 1))
-            || !TEST_size_t_eq(PACKET_remaining(&pkt), 0)))
+            || !TEST_size_t_eq(PACKET_remaining(&pkt), 0))
         return 0;
 
     return 1;
 }
 
-static int test_PACKET_end()
+static int test_PACKET_end(void)
 {
     PACKET pkt;
 
-    if (!TEST_true(PACKET_buf_init(&pkt, smbuf, sizeof(smbuf))
+    if (!TEST_true(PACKET_buf_init(&pkt, smbuf, sizeof(smbuf)))
             || !TEST_size_t_eq(PACKET_remaining(&pkt), BUF_LEN)
-            || !TEST_ptr_ne(PACKET_end(&pkt), smbuf + BUF_LEN)
+            || !TEST_ptr_eq(PACKET_end(&pkt), smbuf + BUF_LEN)
             || !TEST_true(PACKET_forward(&pkt, BUF_LEN - 1))
             || !TEST_ptr_eq(PACKET_end(&pkt), smbuf + BUF_LEN)
             || !TEST_true(PACKET_forward(&pkt, 1))
-            || !TEST_ptr_eq(PACKET_end(&pkt), smbuf + BUF_LEN)))
+            || !TEST_ptr_eq(PACKET_end(&pkt), smbuf + BUF_LEN))
         return 0;
 
     return 1;
 }
 
-static int test_PACKET_get_1()
+static int test_PACKET_get_1(void)
 {
-    unsigned int i;
+    unsigned int i = 0;
     PACKET pkt;
 
     if (!TEST_true(PACKET_buf_init(&pkt, smbuf, BUF_LEN))
@@ -63,9 +62,9 @@ static int test_PACKET_get_1()
     return 1;
 }
 
-static int test_PACKET_get_4()
+static int test_PACKET_get_4(void)
 {
-    unsigned long i;
+    unsigned long i = 0;
     PACKET pkt;
 
     if (!TEST_true(PACKET_buf_init(&pkt, smbuf, BUF_LEN))
@@ -80,9 +79,9 @@ static int test_PACKET_get_4()
     return 1;
 }
 
-static int test_PACKET_get_net_2()
+static int test_PACKET_get_net_2(void)
 {
-    unsigned int i;
+    unsigned int i = 0;
     PACKET pkt;
 
     if (!TEST_true(PACKET_buf_init(&pkt, smbuf, BUF_LEN))
@@ -97,9 +96,9 @@ static int test_PACKET_get_net_2()
     return 1;
 }
 
-static int test_PACKET_get_net_3()
+static int test_PACKET_get_net_3(void)
 {
-    unsigned long i;
+    unsigned long i = 0;
     PACKET pkt;
 
     if (!TEST_true(PACKET_buf_init(&pkt, smbuf, BUF_LEN))
@@ -114,9 +113,9 @@ static int test_PACKET_get_net_3()
     return 1;
 }
 
-static int test_PACKET_get_net_4()
+static int test_PACKET_get_net_4(void)
 {
-    unsigned long i;
+    unsigned long i = 0;
     PACKET pkt;
 
     if (!TEST_true(PACKET_buf_init(&pkt, smbuf, BUF_LEN))
@@ -131,10 +130,10 @@ static int test_PACKET_get_net_4()
     return 1;
 }
 
-static int test_PACKET_get_sub_packet()
+static int test_PACKET_get_sub_packet(void)
 {
     PACKET pkt, subpkt;
-    unsigned long i;
+    unsigned long i = 0;
 
     if (!TEST_true(PACKET_buf_init(&pkt, smbuf, BUF_LEN))
             || !TEST_true(PACKET_get_sub_packet(&pkt, &subpkt, 4))
@@ -152,9 +151,9 @@ static int test_PACKET_get_sub_packet()
     return 1;
 }
 
-static int test_PACKET_get_bytes()
+static int test_PACKET_get_bytes(void)
 {
-    const unsigned char *bytes;
+    const unsigned char *bytes = NULL;
     PACKET pkt;
 
     if (!TEST_true(PACKET_buf_init(&pkt, smbuf, BUF_LEN))
@@ -176,7 +175,7 @@ static int test_PACKET_get_bytes()
     return 1;
 }
 
-static int test_PACKET_copy_bytes()
+static int test_PACKET_copy_bytes(void)
 {
     unsigned char bytes[4];
     PACKET pkt;
@@ -200,7 +199,7 @@ static int test_PACKET_copy_bytes()
     return 1;
 }
 
-static int test_PACKET_copy_all()
+static int test_PACKET_copy_all(void)
 {
     unsigned char tmp[BUF_LEN];
     PACKET pkt;
@@ -217,7 +216,7 @@ static int test_PACKET_copy_all()
     return 1;
 }
 
-static int test_PACKET_memdup()
+static int test_PACKET_memdup(void)
 {
     unsigned char *data = NULL;
     size_t len;
@@ -239,7 +238,7 @@ end:
     return result;
 }
 
-static int test_PACKET_strndup()
+static int test_PACKET_strndup(void)
 {
     char buf1[10], buf2[10];
     char *data = NULL;
@@ -266,7 +265,7 @@ end:
     return result;
 }
 
-static int test_PACKET_contains_zero_byte()
+static int test_PACKET_contains_zero_byte(void)
 {
     char buf1[10], buf2[10];
     PACKET pkt;
@@ -284,9 +283,9 @@ static int test_PACKET_contains_zero_byte()
     return 1;
 }
 
-static int test_PACKET_forward()
+static int test_PACKET_forward(void)
 {
-    const unsigned char *byte;
+    const unsigned char *byte = NULL;
     PACKET pkt;
 
     if (!TEST_true(PACKET_buf_init(&pkt, smbuf, BUF_LEN))
@@ -301,7 +300,7 @@ static int test_PACKET_forward()
     return 1;
 }
 
-static int test_PACKET_buf_init()
+static int test_PACKET_buf_init(void)
 {
     unsigned char buf1[BUF_LEN];
     PACKET pkt;
@@ -317,7 +316,7 @@ static int test_PACKET_buf_init()
     return 1;
 }
 
-static int test_PACKET_null_init()
+static int test_PACKET_null_init(void)
 {
     PACKET pkt;
 
@@ -329,7 +328,7 @@ static int test_PACKET_null_init()
     return 1;
 }
 
-static int test_PACKET_equal()
+static int test_PACKET_equal(void)
 {
     PACKET pkt;
 
@@ -346,14 +345,14 @@ static int test_PACKET_equal()
     return 1;
 }
 
-static int test_PACKET_get_length_prefixed_1()
+static int test_PACKET_get_length_prefixed_1(void)
 {
     unsigned char buf1[BUF_LEN];
     const size_t len = 16;
     unsigned int i;
     PACKET pkt, short_pkt, subpkt = {0};
 
-    buf1[0] = len;
+    buf1[0] = (unsigned char)len;
     for (i = 1; i < BUF_LEN; i++)
         buf1[i] = (i * 2) & 0xff;
 
@@ -370,7 +369,7 @@ static int test_PACKET_get_length_prefixed_1()
     return 1;
 }
 
-static int test_PACKET_get_length_prefixed_2()
+static int test_PACKET_get_length_prefixed_2(void)
 {
     unsigned char buf1[1024];
     const size_t len = 516;  /* 0x0204 */
@@ -393,7 +392,7 @@ static int test_PACKET_get_length_prefixed_2()
     return 1;
 }
 
-static int test_PACKET_get_length_prefixed_3()
+static int test_PACKET_get_length_prefixed_3(void)
 {
     unsigned char buf1[1024];
     const size_t len = 516;  /* 0x000204 */
@@ -416,14 +415,14 @@ static int test_PACKET_get_length_prefixed_3()
     return 1;
 }
 
-static int test_PACKET_as_length_prefixed_1()
+static int test_PACKET_as_length_prefixed_1(void)
 {
     unsigned char buf1[BUF_LEN];
     const size_t len = 16;
     unsigned int i;
-    PACKET pkt, exact_pkt, subpkt;
+    PACKET pkt, exact_pkt, subpkt = {0};
 
-    buf1[0] = len;
+    buf1[0] = (unsigned char)len;
     for (i = 1; i < BUF_LEN; i++)
         buf1[i] = (i * 2) & 0xff;
 
@@ -431,20 +430,20 @@ static int test_PACKET_as_length_prefixed_1()
             || !TEST_true(PACKET_buf_init(&exact_pkt, buf1, len + 1))
             || !TEST_false(PACKET_as_length_prefixed_1(&pkt, &subpkt))
             || !TEST_size_t_eq(PACKET_remaining(&pkt), BUF_LEN)
-            || !TEST_true(PACKET_as_length_prefixed_1(&exact_pkt, &subpkt)
+            || !TEST_true(PACKET_as_length_prefixed_1(&exact_pkt, &subpkt))
             || !TEST_size_t_eq(PACKET_remaining(&exact_pkt), 0)
-            || !TEST_size_t_eq(PACKET_remaining(&subpkt), len)))
+            || !TEST_size_t_eq(PACKET_remaining(&subpkt), len))
         return 0;
 
     return 1;
 }
 
-static int test_PACKET_as_length_prefixed_2()
+static int test_PACKET_as_length_prefixed_2(void)
 {
     unsigned char buf[1024];
     const size_t len = 516;  /* 0x0204 */
     unsigned int i;
-    PACKET pkt, exact_pkt, subpkt;
+    PACKET pkt, exact_pkt, subpkt = {0};
 
     for (i = 1; i <= 1024; i++)
         buf[i-1] = (i * 2) & 0xff;
@@ -461,7 +460,7 @@ static int test_PACKET_as_length_prefixed_2()
     return 1;
 }
 
-void register_tests(void)
+int setup_tests(void)
 {
     unsigned int i;
 
@@ -491,4 +490,5 @@ void register_tests(void)
     ADD_TEST(test_PACKET_get_length_prefixed_3);
     ADD_TEST(test_PACKET_as_length_prefixed_1);
     ADD_TEST(test_PACKET_as_length_prefixed_2);
+    return 1;
 }