dovecot-2.2: lib: Added unit tests for guid_128_*()
dovecot at dovecot.org
dovecot at dovecot.org
Wed Oct 22 02:41:39 UTC 2014
details: http://hg.dovecot.org/dovecot-2.2/rev/07c709075598
changeset: 17979:07c709075598
user: Timo Sirainen <tss at iki.fi>
date: Wed Oct 22 05:40:44 2014 +0300
description:
lib: Added unit tests for guid_128_*()
diffstat:
src/lib/Makefile.am | 1 +
src/lib/test-guid.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++
src/lib/test-lib.c | 1 +
src/lib/test-lib.h | 1 +
4 files changed, 84 insertions(+), 0 deletions(-)
diffs (118 lines):
diff -r 40cca8d452f5 -r 07c709075598 src/lib/Makefile.am
--- a/src/lib/Makefile.am Wed Oct 22 02:59:22 2014 +0300
+++ b/src/lib/Makefile.am Wed Oct 22 05:40:44 2014 +0300
@@ -282,6 +282,7 @@
test-buffer.c \
test-crc32.c \
test-data-stack.c \
+ test-guid.c \
test-hash.c \
test-hash-format.c \
test-hash-method.c \
diff -r 40cca8d452f5 -r 07c709075598 src/lib/test-guid.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib/test-guid.c Wed Oct 22 05:40:44 2014 +0300
@@ -0,0 +1,81 @@
+/* Copyright (c) 2014 Dovecot authors, see the included COPYING file */
+
+#include "test-lib.h"
+#include "guid.h"
+
+void test_guid(void)
+{
+ static const guid_128_t test_guid =
+ { 0x01, 0x23, 0x45, 0x67, 0x89,
+ 0xab, 0xcd, 0xef,
+ 0xAB, 0xCD, 0xEF,
+ 0x00, 0x00, 0x00, 0x00, 0x00 };
+ guid_128_t guid1, guid2, guid3, empty_guid;
+ const char *str;
+ char guidbuf[GUID_128_SIZE*2 + 2];
+ unsigned int i;
+
+ memset(empty_guid, 0, sizeof(empty_guid));
+
+ test_begin("guid_128_generate()");
+ guid_128_generate(guid1);
+ guid_128_generate(guid2);
+ test_assert(!guid_128_equals(guid1, guid2));
+ test_assert(guid_128_cmp(guid1, guid2) != 0);
+ test_end();
+
+ test_begin("guid_128_is_empty()");
+ test_assert(!guid_128_is_empty(guid1));
+ test_assert(!guid_128_is_empty(guid2));
+ test_assert(guid_128_is_empty(empty_guid));
+ test_end();
+
+ test_begin("guid_128_copy()");
+ guid_128_copy(guid3, guid1);
+ test_assert(guid_128_equals(guid3, guid1));
+ test_assert(!guid_128_equals(guid3, guid2));
+ guid_128_copy(guid3, guid2);
+ test_assert(!guid_128_equals(guid3, guid1));
+ test_assert(guid_128_equals(guid3, guid2));
+ test_end();
+
+ test_begin("guid_128_to_string()");
+ str = guid_128_to_string(guid1);
+ test_assert(guid_128_from_string(str, guid3) == 0);
+ test_assert(guid_128_equals(guid3, guid1));
+ test_end();
+
+ test_begin("guid_128_from_string()");
+ /* empty */
+ memset(guidbuf, '0', GUID_128_SIZE*2);
+ guidbuf[GUID_128_SIZE*2] = '\0';
+ guidbuf[GUID_128_SIZE*2+1] = '\0';
+ test_assert(guid_128_from_string(guidbuf, guid3) == 0);
+ test_assert(guid_128_is_empty(guid3));
+ /* too large */
+ guidbuf[GUID_128_SIZE*2] = '0';
+ test_assert(guid_128_from_string(guidbuf, guid3) < 0);
+ /* too small */
+ guidbuf[GUID_128_SIZE*2-1] = '\0';
+ test_assert(guid_128_from_string(guidbuf, guid3) < 0);
+ /* reset to normal */
+ guidbuf[GUID_128_SIZE*2-1] = '0';
+ guidbuf[GUID_128_SIZE*2] = '\0';
+ test_assert(guid_128_from_string(guidbuf, guid3) == 0);
+ /* upper + lowercase hex chars */
+ i_assert(GUID_128_SIZE*2 > 16 + 6);
+ for (i = 0; i < 10; i++)
+ guidbuf[i] = '0' + i;
+ for (i = 0; i < 6; i++)
+ guidbuf[10 + i] = 'a' + i;
+ for (i = 0; i < 6; i++)
+ guidbuf[16 + i] = 'A' + i;
+ test_assert(guid_128_from_string(guidbuf, guid3) == 0);
+ test_assert(guid_128_equals(guid3, test_guid));
+ /* non-hex chars */
+ guidbuf[0] = 'g';
+ test_assert(guid_128_from_string(guidbuf, guid3) < 0);
+ guidbuf[0] = ' ';
+ test_assert(guid_128_from_string(guidbuf, guid3) < 0);
+ test_end();
+}
diff -r 40cca8d452f5 -r 07c709075598 src/lib/test-lib.c
--- a/src/lib/test-lib.c Wed Oct 22 02:59:22 2014 +0300
+++ b/src/lib/test-lib.c Wed Oct 22 05:40:44 2014 +0300
@@ -13,6 +13,7 @@
test_buffer,
test_crc32,
test_data_stack,
+ test_guid,
test_hash,
test_hash_format,
test_hash_method,
diff -r 40cca8d452f5 -r 07c709075598 src/lib/test-lib.h
--- a/src/lib/test-lib.h Wed Oct 22 02:59:22 2014 +0300
+++ b/src/lib/test-lib.h Wed Oct 22 05:40:44 2014 +0300
@@ -13,6 +13,7 @@
void test_crc32(void);
void test_data_stack(void);
enum fatal_test_state fatal_data_stack(int);
+void test_guid(void);
void test_hash(void);
void test_hash_format(void);
void test_hash_method(void);
More information about the dovecot-cvs
mailing list