1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * libdatrie - Double-Array Trie Library
4 * Copyright (C) 2018 Theppitak Karoonboonyanan <theppitak@gmail.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 * test_byte_alpha.c - Test byte stream (full-range 0..255) alpha map
24 * Author: Theppitak Karoonboonyanan <theppitak@gmail.com>
25 * Based on test case in issue #6
26 * https://github.com/tlwg/libdatrie/issues/6
29 #include <datrie/trie.h>
42 msg_step ("Preparing alpha map");
43 alpha_map = alpha_map_new ();
45 printf ("Fail to allocate alpha map\n");
46 goto err_alpha_map_not_created;
48 if (alpha_map_add_range (alpha_map, 0x00, 0xff) != 0) {
49 printf ("Fail to add full alpha map range\n");
50 goto err_alpha_map_created;
53 msg_step ("Preparing trie");
54 test_trie = trie_new (alpha_map);
55 alpha_map_free (alpha_map);
57 printf ("Fail to create test trie\n");
58 goto err_alpha_map_created;
61 msg_step ("Storing key to test trie");
65 if (!trie_store (test_trie, key, TEST_DATA)) {
66 printf ("Fail to store key to test trie\n");
67 goto err_trie_created;
70 msg_step ("Retrieving data from test trie");
71 if (!trie_retrieve (test_trie, key, &data)) {
72 printf ("Fail to retrieve key from test trie\n");
73 goto err_trie_created;
75 if (TEST_DATA != data) {
76 printf ("Retrieved data = %d, not %d\n", data, TEST_DATA);
77 goto err_trie_created;
80 msg_step ("Freeing test trie");
81 trie_free (test_trie);
85 trie_free (test_trie);
86 err_alpha_map_created:
87 alpha_map_free (alpha_map);
88 err_alpha_map_not_created: