dovecot-2.0: Added missing test-hex-binary.c from earlier commit.
dovecot at dovecot.org
dovecot at dovecot.org
Thu Jul 16 01:32:05 EEST 2009
details: http://hg.dovecot.org/dovecot-2.0/rev/c4118cfa1085
changeset: 9637:c4118cfa1085
user: Timo Sirainen <tss at iki.fi>
date: Wed Jul 15 18:29:58 2009 -0400
description:
Added missing test-hex-binary.c from earlier commit.
diffstat:
1 file changed, 61 insertions(+)
src/lib/test-hex-binary.c | 61 +++++++++++++++++++++++++++++++++++++++++++++
diffs (65 lines):
diff -r 54f84f569ca0 -r c4118cfa1085 src/lib/test-hex-binary.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib/test-hex-binary.c Wed Jul 15 18:29:58 2009 -0400
@@ -0,0 +1,61 @@
+/* Copyright (c) 2009 Dovecot authors, see the included COPYING file */
+
+#include "test-lib.h"
+#include "buffer.h"
+#include "str.h"
+#include "hex-binary.h"
+
+static void test_binary_to_hex(void)
+{
+ static unsigned char input[] = { 0xff, 0x00, 0x01, 0xb3 };
+ static char *output_lcase = "ff0001b3";
+ static char *output_ucase = "FF0001B3";
+ string_t *str;
+
+ test_begin("binary to hex");
+ test_assert(strcmp(binary_to_hex(input, sizeof(input)), output_lcase) == 0);
+ test_end();
+
+ test_begin("binary to hex ucase");
+ test_assert(strcmp(binary_to_hex_ucase(input, sizeof(input)), output_ucase) == 0);
+ test_end();
+
+ test_begin("binary to hex ucase");
+ str = t_str_new(32);
+ str_append_c(str, '<');
+ binary_to_hex_append(str, input, sizeof(input));
+ str_append_c(str, '>');
+ test_assert(strcmp(str_c(str), t_strconcat("<", output_lcase, ">", NULL)) == 0);
+ test_end();
+}
+
+static void test_hex_to_binary(void)
+{
+ static const char *ok_input = "0001fEFf";
+ static unsigned char ok_output[] = { 0x00, 0x01, 0xfe, 0xff };
+ static const char *error_input[] = {
+ "00 01",
+ "0x01",
+ "0g"
+ };
+ buffer_t *buf = buffer_create_dynamic(pool_datastack_create(), 10);
+ unsigned int i;
+
+ test_begin("hex to binary");
+ test_assert(hex_to_binary("", buf) == 0);
+ test_assert(buf->used == 0);
+
+ test_assert(hex_to_binary(ok_input, buf) == 0);
+ test_assert(buf->used == N_ELEMENTS(ok_output));
+ test_assert(memcmp(buf->data, ok_output, buf->used) == 0);
+
+ for (i = 0; i < N_ELEMENTS(error_input); i++)
+ test_assert(hex_to_binary(error_input[i], buf) == -1);
+ test_end();
+}
+
+void test_hex_binary(void)
+{
+ test_binary_to_hex();
+ test_hex_to_binary();
+}
More information about the dovecot-cvs
mailing list