123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- #include "../Tests.h"
- #include "core/Queue.h"
- #include "core/ToString.h"
- QUEUE(size_t, Size)
- QUEUE_SOURCE(size_t, Size)
- static void testReadAndWrite() {
- QueueSize r;
- initQueueSize(&r, 5);
- TEST_SIZE(0, r.length);
- pushQueueDataSize(&r, 4);
- TEST_SIZE(1, r.length);
- TEST_SIZE(4, *getQueueIndexSize(&r, 0));
- popQueueDataSize(&r);
- TEST_SIZE(0, r.length);
- destroyQueueSize(&r);
- }
- static void testOverflow() {
- QueueSize r;
- initQueueSize(&r, 3);
- pushQueueDataSize(&r, 1);
- pushQueueDataSize(&r, 2);
- pushQueueDataSize(&r, 3);
- pushQueueDataSize(&r, 4);
- pushQueueDataSize(&r, 5);
- TEST_SIZE(3, r.length);
- TEST_SIZE(1, *getQueueIndexSize(&r, 0));
- popQueueDataSize(&r);
- TEST_SIZE(2, r.length);
- TEST_SIZE(2, *getQueueIndexSize(&r, 0));
- popQueueDataSize(&r);
- TEST_SIZE(1, r.length);
- TEST_SIZE(3, *getQueueIndexSize(&r, 0));
- popQueueDataSize(&r);
- TEST_SIZE(0, r.length);
- destroyQueueSize(&r);
- }
- static void testRefill() {
- QueueSize r;
- initQueueSize(&r, 3);
- pushQueueDataSize(&r, 1);
- pushQueueDataSize(&r, 2);
- pushQueueDataSize(&r, 3);
- pushQueueDataSize(&r, 4);
- TEST_SIZE(3, r.length);
- TEST_SIZE(1, *getQueueIndexSize(&r, 0));
- popQueueDataSize(&r);
- TEST_SIZE(2, *getQueueIndexSize(&r, 0));
- popQueueDataSize(&r);
- TEST_SIZE(3, *getQueueIndexSize(&r, 0));
- popQueueDataSize(&r);
- TEST_SIZE(0, r.length);
- pushQueueDataSize(&r, 5);
- pushQueueDataSize(&r, 6);
- TEST_SIZE(2, r.length);
- TEST_SIZE(5, *getQueueIndexSize(&r, 0));
- popQueueDataSize(&r);
- TEST_SIZE(6, *getQueueIndexSize(&r, 0));
- popQueueDataSize(&r);
- TEST_SIZE(0, r.length);
- destroyQueueSize(&r);
- }
- static void testClear() {
- QueueSize r;
- initQueueSize(&r, 3);
- pushQueueDataSize(&r, 1);
- pushQueueDataSize(&r, 2);
- TEST_SIZE(2, r.length);
- clearQueueSize(&r);
- TEST_SIZE(0, r.length);
- destroyQueueSize(&r);
- }
- static void testOverall() {
- QueueSize r;
- initQueueSize(&r, 3);
- pushQueueDataSize(&r, 1);
- pushQueueDataSize(&r, 2);
- pushQueueDataSize(&r, 3);
- char buffer[128];
- toStringQueueSize(&r, buffer, sizeof(buffer), toStringSize);
- TEST_STRING("[1, 2, 3]", buffer);
- TEST_SIZE(3, r.length);
- popQueueDataSize(&r);
- toStringQueueSize(&r, buffer, sizeof(buffer), toStringSize);
- TEST_STRING("[2, 3]", buffer);
- TEST_SIZE(2, r.length);
- pushQueueDataSize(&r, 4);
- toStringQueueSize(&r, buffer, sizeof(buffer), toStringSize);
- TEST_STRING("[2, 3, 4]", buffer);
- TEST_SIZE(3, r.length);
- popQueueDataSize(&r);
- toStringQueueSize(&r, buffer, sizeof(buffer), toStringSize);
- TEST_STRING("[3, 4]", buffer);
- TEST_SIZE(2, r.length);
- pushQueueDataSize(&r, 5);
- toStringQueueSize(&r, buffer, sizeof(buffer), toStringSize);
- TEST_STRING("[3, 4, 5]", buffer);
- TEST_SIZE(3, r.length);
- popQueueDataSize(&r);
- toStringQueueSize(&r, buffer, sizeof(buffer), toStringSize);
- TEST_STRING("[4, 5]", buffer);
- TEST_SIZE(2, r.length);
- clearQueueSize(&r);
- toStringQueueSize(&r, buffer, sizeof(buffer), toStringSize);
- TEST_STRING("[]", buffer);
- TEST_SIZE(0, r.length);
- destroyQueueSize(&r);
- }
- void testQueue() {
- testReadAndWrite();
- testOverflow();
- testRefill();
- testClear();
- testOverall();
- }
|