1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * libdatrie - Double-Array Trie Library
4 * Copyright (C) 2015 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_null_trie.c - Test for datrie iteration on empty trie
24 * Author: Theppitak Karoonboonyanan <theppitak@gmail.com>
27 #include <datrie/trie.h>
36 TrieState *trie_root_state;
37 TrieIterator *trie_it;
40 msg_step ("Preparing empty trie");
41 test_trie = en_trie_new ();
43 fprintf (stderr, "Fail to create test trie\n");
44 goto err_trie_not_created;
48 msg_step ("Iterating");
49 trie_root_state = trie_root (test_trie);
50 if (!trie_root_state) {
51 printf ("Failed to get trie root state\n");
52 goto err_trie_created;
54 trie_it = trie_iterator_new (trie_root_state);
56 printf ("Failed to get trie iterator\n");
57 goto err_trie_root_created;
61 while (trie_iterator_next (trie_it)) {
64 printf ("Got entry from empty trie, which is weird!\n");
66 key = trie_iterator_get_key (trie_it);
68 printf ("Got key from empty trie, which is weird! (key='%ls')\n",
76 printf ("Errors found in empty trie iteration.\n");
77 goto err_trie_it_created;
80 trie_iterator_free (trie_it);
81 trie_state_free (trie_root_state);
82 trie_free (test_trie);
86 trie_iterator_free (trie_it);
87 err_trie_root_created:
88 trie_state_free (trie_root_state);
90 trie_free (test_trie);