test_00010_parameter_errors.c 5.82 KB
Newer Older
Yoni Fogel's avatar
Yoni Fogel committed
1 2 3 4 5 6 7 8 9 10 11 12
/* We are going to test whether create and close properly check their input. */

#include "test.h"

int main(int argc, const char *argv[]) {
    int r;
    toku_range_tree *tree = NULL;
    toku_range range;

    parse_args(argc, argv);

    /* Create tests */
13
    r = toku_rt_create(NULL,  int_cmp, TXNID_cmp,   FALSE, toku_malloc, toku_free, toku_realloc);
Yoni Fogel's avatar
Yoni Fogel committed
14 15
    CKERR2(r, EINVAL);

16
    r = toku_rt_create(&tree, NULL,    TXNID_cmp,   FALSE, toku_malloc, toku_free, toku_realloc);
Yoni Fogel's avatar
Yoni Fogel committed
17 18 19
    CKERR2(r, EINVAL);
    assert(tree == NULL);

20
    r = toku_rt_create(&tree, int_cmp, NULL,      FALSE, toku_malloc, toku_free, toku_realloc);
Yoni Fogel's avatar
Yoni Fogel committed
21 22
    CKERR2(r, EINVAL);

23
    r = toku_rt_create(&tree, int_cmp, TXNID_cmp,   FALSE, NULL, toku_free, toku_realloc);
Vincenzo Liberatore's avatar
Vincenzo Liberatore committed
24 25
    CKERR2(r, EINVAL);

26
    r = toku_rt_create(&tree, int_cmp, TXNID_cmp,   FALSE, toku_malloc, NULL, toku_realloc);
Vincenzo Liberatore's avatar
Vincenzo Liberatore committed
27 28
    CKERR2(r, EINVAL);

29
    r = toku_rt_create(&tree, int_cmp, TXNID_cmp,   FALSE, toku_malloc, toku_free, NULL);
Vincenzo Liberatore's avatar
Vincenzo Liberatore committed
30
    CKERR2(r, EINVAL);
Yoni Fogel's avatar
Yoni Fogel committed
31 32 33 34 35 36 37 38 39 40
    assert(tree == NULL);

    /* Close tests */
    r = toku_rt_close(NULL);
    CKERR2(r, EINVAL);

    /* Insert tests */
    r = toku_rt_insert(NULL, &range);
    CKERR2(r, EINVAL);
    
41
    r = toku_rt_create(&tree, int_cmp,   TXNID_cmp,   FALSE, toku_malloc, toku_free, toku_realloc);
Yoni Fogel's avatar
Yoni Fogel committed
42
    CKERR(r);
Yoni Fogel's avatar
Yoni Fogel committed
43 44 45 46 47 48 49 50 51 52 53
    assert(tree != NULL);

    r = toku_rt_insert(tree, NULL);                         CKERR2(r, EINVAL);
    r = toku_rt_close(tree);                                CKERR(r);
    
    tree = NULL;

    /* Delete tests */
    r = toku_rt_delete(NULL, &range);
    CKERR2(r, EINVAL);
    
54
    r = toku_rt_create(&tree, int_cmp,   TXNID_cmp,   FALSE, toku_malloc, toku_free, toku_realloc);
Yoni Fogel's avatar
Yoni Fogel committed
55
    CKERR(r);
Yoni Fogel's avatar
Yoni Fogel committed
56 57 58 59 60 61 62 63 64
    assert(tree != NULL);

    r = toku_rt_delete(tree, NULL);                         CKERR2(r, EINVAL);
    r = toku_rt_close(tree);                                CKERR(r);

    /* Find tests */
    toku_range* buf = (toku_range*)toku_malloc(2*sizeof(toku_range));
    unsigned bufsize = 2;
    unsigned found;
Yoni Fogel's avatar
Yoni Fogel committed
65

66
    toku_point stuff[3] = {{0},{1},{2}};
Yoni Fogel's avatar
Yoni Fogel committed
67 68 69
    range.ends.left  = (toku_point*)&stuff[0];
    range.ends.right = (toku_point*)&stuff[1];
    range.data       = 0;
Yoni Fogel's avatar
Yoni Fogel committed
70
    
71
    r = toku_rt_create(&tree, int_cmp,   TXNID_cmp,   FALSE, toku_malloc, toku_free, toku_realloc);
Yoni Fogel's avatar
Yoni Fogel committed
72
    CKERR(r);
Yoni Fogel's avatar
Yoni Fogel committed
73 74
    assert(tree != NULL);

Yoni Fogel's avatar
Yoni Fogel committed
75
    r = toku_rt_find(NULL, &range.ends, 2, &buf, &bufsize, &found);
Yoni Fogel's avatar
Yoni Fogel committed
76 77 78 79 80
    CKERR2(r, EINVAL);
    
    r = toku_rt_find(tree, NULL, 2, &buf, &bufsize, &found);
    CKERR2(r, EINVAL);
    
Yoni Fogel's avatar
Yoni Fogel committed
81
    r = toku_rt_find(tree, &range.ends, 2, NULL, &bufsize, &found);
Yoni Fogel's avatar
Yoni Fogel committed
82 83
    CKERR2(r, EINVAL);
    
Yoni Fogel's avatar
Yoni Fogel committed
84
    r = toku_rt_find(tree, &range.ends, 2, &buf, NULL, &found);
Yoni Fogel's avatar
Yoni Fogel committed
85 86
    CKERR2(r, EINVAL);
    
Yoni Fogel's avatar
Yoni Fogel committed
87 88
    unsigned oldbufsize = bufsize;
    bufsize = 0;
Yoni Fogel's avatar
Yoni Fogel committed
89
    r = toku_rt_find(tree, &range.ends, 2, &buf, &bufsize, &found);
Yoni Fogel's avatar
Yoni Fogel committed
90 91 92
    CKERR2(r, EINVAL);
    bufsize = oldbufsize;
    
Yoni Fogel's avatar
Yoni Fogel committed
93
    r = toku_rt_find(tree, &range.ends, 2, &buf, &bufsize, NULL);
Yoni Fogel's avatar
Yoni Fogel committed
94 95 96 97 98
    CKERR2(r, EINVAL);
    
    r = toku_rt_close(tree);                                CKERR(r);

    /* Predecessor tests */
99
    toku_point* foo = (toku_point*)&stuff[0];
Yoni Fogel's avatar
Yoni Fogel committed
100
    BOOL wasfound;
101
    r = toku_rt_create(&tree, int_cmp,   TXNID_cmp,   FALSE, toku_malloc, toku_free, toku_realloc);
Yoni Fogel's avatar
Yoni Fogel committed
102
    CKERR(r);
Yoni Fogel's avatar
Yoni Fogel committed
103 104
    assert(tree != NULL);

105
    r = toku_rt_predecessor(NULL, foo,  &range, &wasfound);
Yoni Fogel's avatar
Yoni Fogel committed
106 107 108 109 110
    CKERR2(r, EINVAL);

    r = toku_rt_predecessor(tree, NULL, &range, &wasfound);
    CKERR2(r, EINVAL);

111
    r = toku_rt_predecessor(tree, foo,  NULL, &wasfound);
Yoni Fogel's avatar
Yoni Fogel committed
112 113
    CKERR2(r, EINVAL);

114
    r = toku_rt_predecessor(tree, foo,  &range, NULL);
Yoni Fogel's avatar
Yoni Fogel committed
115 116 117 118
    CKERR2(r, EINVAL);

    r = toku_rt_close(tree);                                CKERR(r);

Yoni Fogel's avatar
Yoni Fogel committed
119
#ifndef TOKU_RT_NOOVERLAPS
120
    r = toku_rt_create(&tree, int_cmp,   TXNID_cmp,   TRUE, toku_malloc, toku_free, toku_realloc);
Yoni Fogel's avatar
Yoni Fogel committed
121
    CKERR(r);
Yoni Fogel's avatar
Yoni Fogel committed
122 123
    assert(tree != NULL);

124
    r = toku_rt_predecessor(tree, foo,  &range, &wasfound);
Yoni Fogel's avatar
Yoni Fogel committed
125 126 127
    CKERR2(r, EINVAL);

    r = toku_rt_close(tree);                                CKERR(r);
Yoni Fogel's avatar
Yoni Fogel committed
128 129 130
    
    tree = NULL;
#endif
Yoni Fogel's avatar
Yoni Fogel committed
131 132 133


    /* Successor tests */
134
    r = toku_rt_create(&tree, int_cmp,   TXNID_cmp,   FALSE, toku_malloc, toku_free, toku_realloc);
Yoni Fogel's avatar
Yoni Fogel committed
135
    CKERR(r);
Yoni Fogel's avatar
Yoni Fogel committed
136 137
    assert(tree != NULL);

138
    r = toku_rt_successor(NULL, foo,  &range, &wasfound);
Yoni Fogel's avatar
Yoni Fogel committed
139 140 141 142 143
    CKERR2(r, EINVAL);

    r = toku_rt_successor(tree, NULL, &range, &wasfound);
    CKERR2(r, EINVAL);

144
    r = toku_rt_successor(tree, foo,  NULL, &wasfound);
Yoni Fogel's avatar
Yoni Fogel committed
145 146
    CKERR2(r, EINVAL);

147
    r = toku_rt_successor(tree, foo,  &range, NULL);
Yoni Fogel's avatar
Yoni Fogel committed
148 149 150 151
    CKERR2(r, EINVAL);

    r = toku_rt_close(tree);                                CKERR(r);

Yoni Fogel's avatar
Yoni Fogel committed
152
#ifndef TOKU_RT_NOOVERLAPS
153
    r = toku_rt_create(&tree, int_cmp,   TXNID_cmp,   TRUE, toku_malloc, toku_free, toku_realloc);
Yoni Fogel's avatar
Yoni Fogel committed
154
    CKERR(r);
Yoni Fogel's avatar
Yoni Fogel committed
155 156
    assert(tree != NULL);

157
    r = toku_rt_successor(tree, foo,  &range, &wasfound);
Yoni Fogel's avatar
Yoni Fogel committed
158 159 160 161
    CKERR2(r, EINVAL);

    r = toku_rt_close(tree);                                CKERR(r);

Yoni Fogel's avatar
Yoni Fogel committed
162
    tree = NULL;
Yoni Fogel's avatar
Yoni Fogel committed
163
#endif
Vincenzo Liberatore's avatar
Vincenzo Liberatore committed
164 165 166 167 168 169

    /* Get allow overlap */
    BOOL allowed;
    r = toku_rt_get_allow_overlaps(NULL, &allowed);
    CKERR2(r, EINVAL);
    
170
    r = toku_rt_create(&tree, int_cmp,   TXNID_cmp,   FALSE, toku_malloc, toku_free, toku_realloc);
Vincenzo Liberatore's avatar
Vincenzo Liberatore committed
171 172 173 174 175 176 177 178 179
    CKERR(r);
    assert(tree != NULL);

    r = toku_rt_get_allow_overlaps(tree, NULL);
    CKERR2(r, EINVAL);

    r = toku_rt_close(tree);                                CKERR(r);
    tree = NULL;

180 181 182 183 184 185 186 187 188 189 190 191 192 193
    /* size tests */
    r = toku_rt_create(&tree, int_cmp,   TXNID_cmp,   FALSE, toku_malloc, toku_free, toku_realloc);
    CKERR(r);
    assert(tree != NULL);

    r = toku_rt_get_size(NULL, NULL); CKERR2(r, EINVAL);
    r = toku_rt_get_size(tree, NULL); CKERR2(r, EINVAL);
    u_int32_t tree_size;
    r = toku_rt_get_size(NULL, &tree_size); CKERR2(r, EINVAL);
    r = toku_rt_get_size(tree, &tree_size); CKERR(r);

    r = toku_rt_close(tree);                                CKERR(r);
    tree = NULL;    

Vincenzo Liberatore's avatar
Vincenzo Liberatore committed
194
    /* That's it: clean up and go home */
Yoni Fogel's avatar
Yoni Fogel committed
195 196
    toku_free(buf);
    buf = NULL;
Yoni Fogel's avatar
Yoni Fogel committed
197 198
    return 0;
}