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>
43 msg_step ("Preparing alpha map");
44 alpha_map = alpha_map_new ();
46 printf ("Fail to allocate alpha map\n");
47 goto err_alpha_map_not_created;
49 if (alpha_map_add_range (alpha_map, 0x00, 0xff) != 0) {
50 printf ("Fail to add full alpha map range\n");
51 goto err_alpha_map_created;
54 msg_step ("Preparing trie");
55 test_trie = trie_new (alpha_map);
56 alpha_map_free (alpha_map);
58 printf ("Fail to create test trie\n");
59 goto err_alpha_map_created;
62 msg_step ("Storing key to test trie");
66 if (!trie_store (test_trie, key, TEST_DATA)) {
67 printf ("Fail to store key to test trie\n");
68 goto err_trie_created;
71 msg_step ("Retrieving data from test trie");
72 if (!trie_retrieve (test_trie, key, &data)) {
73 printf ("Fail to retrieve key from test trie\n");
74 goto err_trie_created;
76 if (TEST_DATA != data) {
77 printf ("Retrieved data = %d, not %d\n", data, TEST_DATA);
78 goto err_trie_created;
81 msg_step ("Freeing test trie");
82 trie_free (test_trie);
86 trie_free (test_trie);
87 err_alpha_map_created:
88 alpha_map_free (alpha_map);
89 err_alpha_map_not_created: