| 1 |
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
/* |
| 3 |
* libdatrie - Double-Array Trie Library |
| 4 |
* Copyright (C) 2015 Theppitak Karoonboonyanan <[email protected]> |
| 5 |
* |
| 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. |
| 10 |
* |
| 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. |
| 15 |
* |
| 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 |
| 19 |
*/ |
| 20 |
|
| 21 |
/* |
| 22 |
* test_null_trie.c - Test for datrie iteration on empty trie |
| 23 |
* Created: 2015-04-21 |
| 24 |
* Author: Theppitak Karoonboonyanan <[email protected]> |
| 25 |
*/ |
| 26 |
|
| 27 |
#include <datrie/trie.h> |
| 28 |
#include "utils.h" |
| 29 |
#include <stdio.h> |
| 30 |
#include <wchar.h> |
| 31 |
#include <stdlib.h> |
| 32 |
|
| 33 |
int |
| 34 |
main (void) |
| 35 |
{ |
| 36 |
Trie *test_trie; |
| 37 |
TrieState *trie_root_state; |
| 38 |
TrieIterator *trie_it; |
| 39 |
Bool is_failed; |
| 40 |
|
| 41 |
msg_step ("Preparing empty trie"); |
| 42 |
test_trie = en_trie_new (); |
| 43 |
if (!test_trie) { |
| 44 |
fprintf (stderr, "Fail to create test trie\n"); |
| 45 |
goto err_trie_not_created; |
| 46 |
} |
| 47 |
|
| 48 |
/* iterate & check */ |
| 49 |
msg_step ("Iterating"); |
| 50 |
trie_root_state = trie_root (test_trie); |
| 51 |
if (!trie_root_state) { |
| 52 |
printf ("Failed to get trie root state\n"); |
| 53 |
goto err_trie_created; |
| 54 |
} |
| 55 |
trie_it = trie_iterator_new (trie_root_state); |
| 56 |
if (!trie_it) { |
| 57 |
printf ("Failed to get trie iterator\n"); |
| 58 |
goto err_trie_root_created; |
| 59 |
} |
| 60 |
|
| 61 |
is_failed = FALSE; |
| 62 |
while (trie_iterator_next (trie_it)) { |
| 63 |
AlphaChar *key; |
| 64 |
|
| 65 |
printf ("Got entry from empty trie, which is weird!\n"); |
| 66 |
|
| 67 |
key = trie_iterator_get_key (trie_it); |
| 68 |
if (key) { |
| 69 |
printf ("Got key from empty trie, which is weird! (key='%ls')\n", |
| 70 |
(wchar_t *)key); |
| 71 |
is_failed = TRUE; |
| 72 |
free (key); |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
if (is_failed) { |
| 77 |
printf ("Errors found in empty trie iteration.\n"); |
| 78 |
goto err_trie_it_created; |
| 79 |
} |
| 80 |
|
| 81 |
trie_iterator_free (trie_it); |
| 82 |
trie_state_free (trie_root_state); |
| 83 |
trie_free (test_trie); |
| 84 |
return 0; |
| 85 |
|
| 86 |
err_trie_it_created: |
| 87 |
trie_iterator_free (trie_it); |
| 88 |
err_trie_root_created: |
| 89 |
trie_state_free (trie_root_state); |
| 90 |
err_trie_created: |
| 91 |
trie_free (test_trie); |
| 92 |
err_trie_not_created: |
| 93 |
return 1; |
| 94 |
} |
| 95 |
|
| 96 |
/* |
| 97 |
vi:ts=4:ai:expandtab |
| 98 |
*/ |