#include <openssl/buffer.h>
#include "../ssl/packet_locl.h"
#include "testutil.h"
+#include "test_main_custom.h"
const static unsigned char simple1 = 0xff;
const static unsigned char simple2[] = { 0x01, 0xff };
const static unsigned char empty = 0x00;
const static unsigned char alloc[] = { 0x02, 0xfe, 0xff };
const static unsigned char submem[] = { 0x03, 0x02, 0xfe, 0xff };
+const static unsigned char fixed[] = { 0xff, 0xff, 0xff };
static BUF_MEM *buf;
WPACKET pkt;
int i;
size_t written;
+ unsigned char sbuf[3];
if (!WPACKET_init(&pkt, buf)
|| !WPACKET_put_bytes_u8(&pkt, 0xff)
return 0;
}
+ /* Test initialising from a fixed size buffer */
+ if (!WPACKET_init_static_len(&pkt, sbuf, sizeof(sbuf), 0)
+ /* Adding 3 bytes should succeed */
+ || !WPACKET_put_bytes_u24(&pkt, 0xffffff)
+ /* Adding 1 more byte should fail */
+ || WPACKET_put_bytes_u8(&pkt, 0xff)
+ /* Finishing the top level WPACKET should succeed */
+ || !WPACKET_finish(&pkt)
+ || !WPACKET_get_total_written(&pkt, &written)
+ || written != sizeof(fixed)
+ || memcmp(sbuf, fixed, sizeof(sbuf)) != 0
+ /* Initialise with 1 len byte */
+ || !WPACKET_init_static_len(&pkt, sbuf, sizeof(sbuf), 1)
+ /* Adding 2 bytes should succeed */
+ || !WPACKET_put_bytes_u16(&pkt, 0xfeff)
+ /* Adding 1 more byte should fail */
+ || WPACKET_put_bytes_u8(&pkt, 0xff)
+ || !WPACKET_finish(&pkt)
+ || !WPACKET_get_total_written(&pkt, &written)
+ || written != sizeof(alloc)
+ || memcmp(sbuf, alloc, written) != 0) {
+ testfail("test_WPACKET_init():5 failed\n", &pkt);
+ return 0;
+ }
+
return 1;
}
|| !WPACKET_set_max_size(&pkt, SIZE_MAX)
|| !WPACKET_finish(&pkt)) {
testfail("test_WPACKET_set_max_size():1 failed\n", &pkt);
- return 0;
+ return 0;
}
if (!WPACKET_init_len(&pkt, buf, 1)
return 1;
}
-int main(int argc, char *argv[])
+int test_main(int argc, char *argv[])
{
- BIO *err = NULL;
int testresult = 0;
- err = BIO_new_fp(stderr, BIO_NOCLOSE | BIO_FP_TEXT);
-
- CRYPTO_set_mem_debug(1);
- CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
-
buf = BUF_MEM_new();
if (buf != NULL) {
ADD_TEST(test_WPACKET_init);
BUF_MEM_free(buf);
}
-#ifndef OPENSSL_NO_CRYPTO_MDEBUG
- if (CRYPTO_mem_leaks(err) <= 0)
- testresult = 1;
-#endif
- BIO_free(err);
-
- if (!testresult)
- printf("PASS\n");
-
return testresult;
}
-