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/circleBuffer.h"
19 #define TEST_BUF_SIZE 32
24 * Tests using a circle buffer as a stack.
28 SJME_TEST_DECLARE(testCircleBufferStack
)
30 sjme_circleBuffer
* buffer
;
31 sjme_circleBuffer_seekEnd seek
;
32 sjme_jint whichSeek
, val
;
35 for (whichSeek
= 0; whichSeek
< 2; whichSeek
++)
37 /* Which seek are we doing? */
38 seek
= (whichSeek
== 0 ? SJME_CIRCLE_BUFFER_TAIL
:
39 SJME_CIRCLE_BUFFER_HEAD
);
41 /* Setup new buffer. */
43 if (sjme_error_is(test
->error
= sjme_circleBuffer_new(
46 SJME_CIRCLE_BUFFER_QUEUE
, TEST_BUF_SIZE
)) ||
48 return sjme_unit_fail(test
, "Could not make buffer.");
50 /* Push values onto the given end. */
51 for (val
= 0; val
< TEST_COUNT
; val
++)
53 /* Push single value. */
55 if (sjme_error_is(test
->error
= sjme_circleBuffer_push(buffer
,
57 return sjme_unit_fail(test
, "Could not push %d?", val
);
60 /* All should have been pushed. */
61 sjme_unit_equalI(test
, TEST_COUNT
, buffer
->ready
,
62 "Buffer ready did not have everything?");
65 for (val
= TEST_COUNT
- 1; val
>= 0; val
--)
67 /* Push single value. */
69 if (sjme_error_is(test
->error
= sjme_circleBuffer_pop(buffer
,
71 return sjme_unit_fail(test
, "Could not pop %d?", val
);
73 /* Must be the same value. */
74 sjme_unit_equalI(test
, byteVal
, val
,
75 "Value popped did not match?");
78 /* All should have been popped. */
79 sjme_unit_equalI(test
, 0, buffer
->ready
,
80 "Not everything was removed from the buffer?");
82 /* Destroy the buffer. */
83 if (sjme_error_is(test
->error
= sjme_circleBuffer_destroy(buffer
)))
84 return sjme_unit_fail(test
, "Could not destroy buffer?");
88 return SJME_TEST_RESULT_PASS
;