1 /* -*- Mode: C; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // -------------------------------------------------------------------------*/
17 #include "sjme/traverse.h"
18 #include "testTraverse.h"
21 * Tests clearing a traversal tree.
25 SJME_TEST_DECLARE(testTraverseClear
)
27 sjme_traverse_test_data traverse
;
32 if (sjme_error_is(test
->error
= sjme_traverse_new(test
->pool
,
33 &traverse
, MAX_ELEMENTS
, test_data
, 0)) || traverse
== NULL
)
34 return sjme_unit_fail(test
, "Could not create traverse?");
36 /* Store first value. */
37 memset(&value
, 0, sizeof(value
));
40 if (sjme_error_is(test
->error
= sjme_traverse_put(traverse
,
41 &value
, 0, 1, test_data
, 0)))
42 return sjme_unit_fail(test
, "Could not put in first value?");
44 /* Store second value. */
45 memset(&value
, 0, sizeof(value
));
48 if (sjme_error_is(test
->error
= sjme_traverse_put(traverse
,
49 &value
, 1, 1, test_data
, 0)))
50 return sjme_unit_fail(test
, "Could not put in second value?");
53 if (sjme_error_is(test
->error
= sjme_traverse_clear(
54 SJME_AS_TRAVERSE(traverse
))))
55 return sjme_unit_fail(test
, "Could not clear traversal tree?");
57 /* There should be no root node. */
58 sjme_unit_equalP(test
, NULL
, traverse
->root
,
59 "There was a root node on a cleared tree?");
61 /* There should be storage, however. */
62 sjme_unit_notEqualP(test
, NULL
, traverse
->storage
,
63 "Storage is missing?");
64 sjme_unit_equalP(test
, traverse
->start
, traverse
->next
,
65 "Next storage node not at start?");
67 /* Destroy traverse. */
68 if (sjme_error_is(test
->error
= sjme_traverse_destroy(
69 SJME_AS_TRAVERSE(traverse
))))
70 return sjme_unit_fail(test
, "Could not destroy traverse?");
73 return SJME_TEST_RESULT_PASS
;