2 * collectd - src/tests/test_utils_avltree.c
3 * Copyright (C) 2013 Florian octo Forster
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 * Florian octo Forster <octo at collectd.org>
27 #include "tests/macros.h"
29 #include "utils_avltree.h"
31 static int compare_total_count = 0;
32 #define RESET_COUNTS() do { compare_total_count = 0; } while (0)
34 static int compare_callback (void const *v0, void const *v1)
39 compare_total_count++;
40 return (strcmp (v0, v1));
46 char key_orig[] = "foo";
47 char value_orig[] = "bar";
49 char *value_ret = NULL;
52 t = c_avl_create (compare_callback);
55 OK (c_avl_insert (t, key_orig, value_orig) == 0);
56 OK (c_avl_size (t) == 1);
58 /* Key already exists. */
59 OK (c_avl_insert (t, "foo", "qux") > 0);
61 OK (c_avl_get (t, "foo", (void *) &value_ret) == 0);
62 OK (value_ret == &value_orig[0]);
64 key_ret = value_ret = NULL;
65 OK (c_avl_remove (t, "foo", (void *) &key_ret, (void *) &value_ret) == 0);
66 OK (key_ret == &key_orig[0]);
67 OK (value_ret == &value_orig[0]);
68 OK (c_avl_size (t) == 0);
82 /* vim: set sw=2 sts=2 et : */