-
Notifications
You must be signed in to change notification settings - Fork 154
/
Copy pathguid.testc
80 lines (69 loc) · 2.35 KB
/
guid.testc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "cunit/cyrunit.h"
#include "imap/message_guid.h"
static void test_guid(void)
{
static const char TEXT[] = "lorem ipsum dolor sit amet, "
"consectetur adipisicing elit\n";
static const char SHA1[20] = {
0xd1,0xb0,0x52,0xa0,0x12,0xcb,0xec,0xd5,0x42,0x5b,
0x23,0xf3,0x61,0x42,0x6f,0x24,0xdb,0x56,0xd7,0x45
};
struct message_guid guid;
struct message_guid guid2;
int r;
message_guid_set_null(&guid);
r = message_guid_isnull(&guid);
CU_ASSERT_EQUAL(r, 1);
r = message_guid_isnull(&guid);
CU_ASSERT_EQUAL(r, 1);
message_guid_generate(&guid, TEXT, sizeof(TEXT)-1);
r = message_guid_isnull(&guid);
CU_ASSERT_EQUAL(r, 0);
r = message_guid_isnull(&guid);
CU_ASSERT_EQUAL(r, 0);
CU_ASSERT_EQUAL(memcmp(&guid.value, SHA1, sizeof(SHA1)), 0);
memset(&guid2, 0x45, sizeof(guid2));
r = message_guid_equal(&guid, &guid2);
CU_ASSERT_EQUAL(r, 0);
message_guid_copy(&guid2, &guid);
CU_ASSERT_EQUAL(memcmp(&guid2.value, SHA1, sizeof(SHA1)), 0);
r = message_guid_equal(&guid, &guid2);
CU_ASSERT_EQUAL(r, 1);
}
static void test_import(void)
{
static const char SHA1[20] = {
0xd1,0xb0,0x52,0xa0,0x12,0xcb,0xec,0xd5,0x42,0x5b,
0x23,0xf3,0x61,0x42,0x6f,0x24,0xdb,0x56,0xd7,0x45
};
struct message_guid guid;
char buf[MESSAGE_GUID_SIZE];
int r;
memset(&guid, 0x45, sizeof(guid));
message_guid_import(&guid, SHA1);
r = message_guid_isnull(&guid);
CU_ASSERT_EQUAL(r, 0);
CU_ASSERT_EQUAL(memcmp(&guid.value, SHA1, sizeof(SHA1)), 0);
memset(buf, 0x69, sizeof(buf));
message_guid_export(&guid, buf);
CU_ASSERT_EQUAL(memcmp(buf, SHA1, sizeof(SHA1)), 0);
}
static void test_encode(void)
{
static const char SHA1HEX[41] = "d1b052a012cbecd5425b23f361426f24db56d745";
static const unsigned char SHA1BIN[20] = {
0xd1,0xb0,0x52,0xa0,0x12,0xcb,0xec,0xd5,0x42,0x5b,
0x23,0xf3,0x61,0x42,0x6f,0x24,0xdb,0x56,0xd7,0x45
};
struct message_guid guid;
const char *s;
int r;
memset(&guid, 0x45, sizeof(guid));
message_guid_decode(&guid, SHA1HEX);
r = message_guid_isnull(&guid);
CU_ASSERT_EQUAL(r, 0);
CU_ASSERT_EQUAL(memcmp(&guid.value, SHA1BIN, sizeof(SHA1BIN)), 0);
s = message_guid_encode(&guid);
CU_ASSERT_STRING_EQUAL(s, SHA1HEX);
}
/* vim: set ft=c: */