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 trying to put a node after a leaf.
25 SJME_TEST_DECLARE(testTraversePutLeafToNode
)
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 /* Put value at high enough depth. */
37 memset(&value
, 0, sizeof(value
));
40 if (sjme_error_is(test
->error
= sjme_traverse_put(traverse
,
41 &value
, 3, 2, test_data
, 0)))
42 return sjme_unit_fail(test
, "Could not put in value?");
44 /* There should be a one facing node to a one facing leaf. */
45 sjme_unit_notEqualP(test
, NULL
, traverse
->root
->node
.one
,
46 "There is no one node?");
47 sjme_unit_notEqualP(test
,
48 (void*)SJME_TRAVERSE_LEAF_KEY
,
49 (void*)traverse
->root
->node
.one
->leaf
.key
,
50 "One facing is not a node?");
51 sjme_unit_equalP(test
,
52 (void*)SJME_TRAVERSE_LEAF_KEY
,
53 (void*)traverse
->root
->node
.one
->node
.one
->leaf
.key
,
54 "One+one facing is not a leaf?");
56 /* Put putting in a value higher up. */
57 memset(&value
, 0, sizeof(value
));
60 test
->error
= sjme_traverse_put(traverse
,
61 &value
, 1, 1, test_data
, 0);
62 sjme_unit_equalI(test
, test
->error
, SJME_ERROR_TREE_COLLISION
,
63 "Adding entry did not indicate collision?");
65 /* Should be untouched. */
66 sjme_unit_notEqualP(test
, NULL
, traverse
->root
->node
.one
,
67 "There is no one node?");
68 sjme_unit_notEqualP(test
,
69 (void*)SJME_TRAVERSE_LEAF_KEY
,
70 (void*)traverse
->root
->node
.one
->leaf
.key
,
71 "One facing is not a node?");
72 sjme_unit_equalP(test
,
73 (void*)SJME_TRAVERSE_LEAF_KEY
,
74 (void*)traverse
->root
->node
.one
->node
.one
->leaf
.key
,
75 "One+one facing is not a leaf?");
77 /* Destroy traverse. */
78 if (sjme_error_is(test
->error
= sjme_traverse_destroy(
79 SJME_AS_TRAVERSE(traverse
))))
80 return sjme_unit_fail(test
, "Could not destroy traverse?");
83 return SJME_TEST_RESULT_PASS
;