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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
/* Copyright (c) 2021 Dovecot authors, see the included COPYING file */
#include "test-lib.h"
#include "str.h"
#include "seq-set-builder.h"
static void test_seq_set_builder_add(void)
{
struct seqset_builder *seq_set_builder;
test_begin("seq set builder add");
string_t *test_str = t_str_new(128);
str_append(test_str, "UID COPY ");
seq_set_builder = seqset_builder_init(test_str);
seqset_builder_add(seq_set_builder, 1);
seqset_builder_add(seq_set_builder, 3);
seqset_builder_add(seq_set_builder, 6);
seqset_builder_add(seq_set_builder, 7);
seqset_builder_add(seq_set_builder, 8);
seqset_builder_add(seq_set_builder, 9);
seqset_builder_add(seq_set_builder, 10);
seqset_builder_add(seq_set_builder, 12);
seqset_builder_deinit(&seq_set_builder);
test_assert_strcmp(str_c(test_str), "UID COPY 1,3,6:10,12");
str_truncate(test_str, 0);
seq_set_builder = seqset_builder_init(test_str);
seqset_builder_add(seq_set_builder, 99999);
seqset_builder_add(seq_set_builder, 100000);
seqset_builder_add(seq_set_builder, 5);
seqset_builder_add(seq_set_builder, 7);
seqset_builder_add(seq_set_builder, 9);
seqset_builder_add(seq_set_builder, 10);
seqset_builder_add(seq_set_builder, 120);
seqset_builder_add(seq_set_builder, 121);
seqset_builder_add(seq_set_builder, 122);
seqset_builder_add(seq_set_builder, 125);
seqset_builder_deinit(&seq_set_builder);
test_assert_strcmp(str_c(test_str), "99999:100000,5,7,9:10,120:122,125");
str_truncate(test_str, 0);
str_append(test_str, "UID COPY ");
seq_set_builder = seqset_builder_init(test_str);
seqset_builder_add(seq_set_builder, 287409);
seqset_builder_add(seq_set_builder, 287410);
seqset_builder_deinit(&seq_set_builder);
test_assert_strcmp(str_c(test_str), "UID COPY 287409:287410");
str_truncate(test_str, 0);
str_append(test_str, "UID COPY 287409,");
seq_set_builder = seqset_builder_init(test_str);
seqset_builder_add(seq_set_builder, 287410);
seqset_builder_add(seq_set_builder, 287411);
test_assert_strcmp(str_c(test_str), "UID COPY 287409,287410:287411,");
seqset_builder_deinit(&seq_set_builder);
test_assert_strcmp(str_c(test_str), "UID COPY 287409,287410:287411");
str_truncate(test_str, 0);
seq_set_builder = seqset_builder_init(test_str);
seqset_builder_add(seq_set_builder, 4294967289);
seqset_builder_add(seq_set_builder, 4294967291);
seqset_builder_add(seq_set_builder, 4294967293);
seqset_builder_add(seq_set_builder, 4294967294);
seqset_builder_add(seq_set_builder, 4294967295);
test_assert_strcmp(str_c(test_str), "4294967289,4294967291,4294967293:4294967295,");
seqset_builder_deinit(&seq_set_builder);
test_assert_strcmp(str_c(test_str), "4294967289,4294967291,4294967293:4294967295");
str_truncate(test_str, 0);
str_append(test_str, ";j;,");
seq_set_builder = seqset_builder_init(test_str);
test_assert_strcmp(str_c(test_str), ";j;,");
seqset_builder_deinit(&seq_set_builder);
test_assert_strcmp(str_c(test_str), ";j;,");
test_end();
}
static void test_seq_set_builder_try_add(void)
{
struct seqset_builder *seq_set_builder;
test_begin("seq set builder try add");
string_t *test_str = t_str_new(128);
str_append(test_str, "UID MOVE ");
seq_set_builder = seqset_builder_init(test_str);
test_assert(seqset_builder_try_add(seq_set_builder, 20, 1));
test_assert(seqset_builder_try_add(seq_set_builder, 20, 3));
test_assert(seqset_builder_try_add(seq_set_builder, 20, 5));
test_assert(seqset_builder_try_add(seq_set_builder, 20, 7));
test_assert(seqset_builder_try_add(seq_set_builder, 20, 9));
test_assert(19 == str_len(test_str));
test_assert_strcmp(str_c(test_str), "UID MOVE 1,3,5,7,9,");
test_assert(!seqset_builder_try_add(seq_set_builder, 20, 11));
test_assert(str_len(test_str) <= 20);
test_assert_strcmp(str_c(test_str), "UID MOVE 1,3,5,7,9,");
test_assert(seqset_builder_try_add(seq_set_builder, 21, 2));
test_assert(str_len(test_str) <= 21);
test_assert_strcmp(str_c(test_str), "UID MOVE 1,3,5,7,9,2,");
test_assert(!seqset_builder_try_add(seq_set_builder, 20, 15));
test_assert(seqset_builder_try_add(seq_set_builder, 24, 13));
test_assert(!seqset_builder_try_add(seq_set_builder, 24, 17));
test_assert(str_len(test_str) <= 24);
test_assert_strcmp(str_c(test_str), "UID MOVE 1,3,5,7,9,2,13,");
seqset_builder_deinit(&seq_set_builder);
str_truncate(test_str, 0);
seq_set_builder = seqset_builder_init(test_str);
test_assert(seqset_builder_try_add(seq_set_builder, 32, 4294967289));
test_assert(seqset_builder_try_add(seq_set_builder, 32, 4294967291));
test_assert(seqset_builder_try_add(seq_set_builder, 32, 4294967292));
test_assert(!seqset_builder_try_add(seq_set_builder, 32, 4294967293));
test_assert(seqset_builder_try_add(seq_set_builder, 50, 4294967293));
test_assert(seqset_builder_try_add(seq_set_builder, 50, 4294967295));
test_assert_strcmp(str_c(test_str), "4294967289,4294967291:4294967293,4294967295,");
seqset_builder_deinit(&seq_set_builder);
test_assert_strcmp(str_c(test_str), "4294967289,4294967291:4294967293,4294967295");
test_end();
}
void test_seq_set_builder(void)
{
test_seq_set_builder_add();
test_seq_set_builder_try_add();
}
|