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 putting values into the iteration.
25 SJME_TEST_DECLARE(testTraversePut
)
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 /* There should be a root and zero facing leaf. */
45 sjme_unit_notEqualP(test
, NULL
, traverse
->root
,
46 "Root node missing?");
47 sjme_unit_notEqualP(test
,
48 (void*)SJME_TRAVERSE_LEAF_KEY
, (void*)traverse
->root
->leaf
.key
,
49 "Root node not a node?");
50 sjme_unit_notEqualP(test
, NULL
, traverse
->root
->node
.zero
,
51 "There is no zero node?");
52 sjme_unit_equalP(test
, NULL
, traverse
->root
->node
.one
,
53 "There is a one node?");
54 sjme_unit_equalP(test
,
55 (void*)SJME_TRAVERSE_LEAF_KEY
,
56 (void*)traverse
->root
->node
.zero
->leaf
.key
,
57 "Zero facing is not a leaf?");
58 sjme_unit_equalI(test
,
60 &traverse
->root
->node
.zero
->leaf
.value
[0],
64 /* Store second value. */
65 memset(&value
, 0, sizeof(value
));
68 if (sjme_error_is(test
->error
= sjme_traverse_put(traverse
,
69 &value
, 1, 1, test_data
, 0)))
70 return sjme_unit_fail(test
, "Could not put in second value?");
72 /* There should be a root and one facing leaf. */
73 sjme_unit_notEqualP(test
, NULL
, traverse
->root
,
74 "Root node missing?");
75 sjme_unit_notEqualP(test
,
76 (void*)SJME_TRAVERSE_LEAF_KEY
, (void*)traverse
->root
->leaf
.key
,
77 "Root node not a node?");
78 sjme_unit_notEqualP(test
, NULL
, traverse
->root
->node
.zero
,
79 "There is no zero node?");
80 sjme_unit_notEqualP(test
, NULL
, traverse
->root
->node
.one
,
81 "There is no one node?");
82 sjme_unit_equalP(test
,
83 (void*)SJME_TRAVERSE_LEAF_KEY
,
84 (void*)traverse
->root
->node
.one
->leaf
.key
,
85 "One facing is not a leaf?");
86 sjme_unit_equalI(test
,
88 &traverse
->root
->node
.one
->leaf
.value
[0],
92 /* Destroy traverse. */
93 if (sjme_error_is(test
->error
= sjme_traverse_destroy(
94 SJME_AS_TRAVERSE(traverse
))))
95 return sjme_unit_fail(test
, "Could not destroy traverse?");
98 return SJME_TEST_RESULT_PASS
;