A library for talking to Multi-Tech's Cellular SocketModem Devices.
Dependents: M2X_dev axeda_wrapper_dev MTS_M2x_Example1 MTS_Cellular_Connect_Example ... more
tests/testMTSCircularBuffer.h
- Committer:
- jengbrecht
- Date:
- 2013-12-09
- Revision:
- 0:563b70517320
- Child:
- 60:ee9c7a700330
File content as of revision 0:563b70517320:
#ifndef TESTMTSCIRCULARBUFFER_H #define TESTMTSCIRCULARBUFFER_H #include "MTSCircularBuffer.h" #include "Vars.h" int capacity = 0; MTSCircularBuffer* buffer = new MTSCircularBuffer(5); void callback() { capacity = buffer->capacity(); } int testMTSCircularBuffer() { printf("Testing: MTSCircularBuffer\n"); int failed = 0; //Test getSize method if (buffer->getSize() != 5) { printf("Failed: getSize()\n"); failed++; } //Test clear function buffer->write("AT", 2); buffer->clear(); if (buffer->available() != 0) { printf("Failed: clear()\n"); failed++; } /* The next set of test all rely on an empty buffer!!! */ //Test isEmpty method - empty buffer if (buffer->isEmpty() != true) { printf("Failed: isEmpty() - empty\n"); failed++; } //Test isFull method - empty buffer if (buffer->isFull() == true) { printf("Failed: isFull() - empty\n"); failed++; } //Test capacity method - empty buffer if (buffer->capacity() != 5) { printf("Failed: capacity() - empty\n"); failed++; } //Test available method - empty buffer if (buffer->available() != 0) { printf("Failed: available() - empty\n"); failed++; } /* The next set of tests all rely on a full buffer */ //Test bulk write method int tmp = buffer->write("Test", 5); if (tmp != 0) { printf("Failed: bulk write()\n"); failed++; } //Test isEmpty method - full buffer if (buffer->isEmpty() == true) { printf("Failed: isEmpty() - full\n"); failed++; } //Test isFull method - full buffer if (buffer->isFull() == false) { printf("Failed: isFull() - full\n"); failed++; } //Test capacity method - full buffer if (buffer->capacity() != 0) { printf("Failed: capacity() - full\n"); failed++; } //Test available method - full buffer if (buffer->available() != 5) { printf("Failed: available() - full\n"); failed++; } //Test single overwrite method if (buffer->write('A') != -1) { printf("Failed: write() - overwrite\n"); failed++; } //Test bulk overwrite method if (buffer->write("Test", 5) != -1) { printf("Failed: bulk write() - overflow\n"); failed++; } //Test single read method if (buffer->read() != 'T' || buffer->capacity() != 1) { printf("Failed: single read()\n"); failed++; } //Test bulk read method char data[5]; if (buffer->read(data, 5) != 4 || data[0] != 'e' || data[1] != 's' || data[2] != 't' || data[3] != '\0') { printf("Failed: bulk read()\n"); failed++; } //Test wrap write/read methods tmp = buffer->write("AT", 2); if (tmp != 3 || buffer->read() != 'A' || buffer->read() != 'T') { printf("Failed: wrap write()/read()\n"); failed++; } buffer->clear(); /* The next set of test are focused all on the attach methods */ //Test attach with greater than below level buffer->attach(&callback, 3, Vars::GREATER); buffer->write("ABC", 3); if (capacity != 0) { printf("Failed: attach() - greater/below\n"); failed++; } //Test attach with greater than above level buffer->write('T'); if (capacity != 1) { printf("Failed: attach() - greater/above\n"); failed++; } buffer->clear(); capacity = 0; //Test attach with greater equal than below level buffer->attach(&callback, 3, Vars::GREATER_EQUAL); buffer->write("AB", 2); if (capacity != 0) { printf("Failed: attach() - greater equal/below\n"); failed++; } //Test attach with greater equal than above level buffer->write('T'); if (capacity != 2) { printf("Failed: attach() - greater equal/above\n"); failed++; } //Test attach with less than above level buffer->clear(); buffer->write("ABC", 3); capacity = 0; buffer->attach(&callback, 2, Vars::LESS); buffer->read(); if (capacity != 0) { printf("Failed: attach() - less_equal/above\n"); failed++; } //Test attach with less than below level buffer->read(); if (capacity != 4) { printf("Failed: attach() - less_equal/below%d\n", capacity); failed++; } //Test attach with less equal than above level buffer->clear(); buffer->write("Test", 4); capacity = 0; buffer->attach(&callback, 2, Vars::LESS_EQUAL); buffer->read(); if (capacity != 0) { printf("Failed: attach() - less equal/above\n"); failed++; } //Test attach with less equal than below level buffer->read(); if (capacity != 3) { printf("Failed: attach() - less equal/below%d\n", capacity); failed++; } //Test attach with less equal than above level buffer->clear(); buffer->write("Test", 4); capacity = 0; buffer->attach(&callback, 2, Vars::EQUAL); buffer->read(); if (capacity != 0) { printf("Failed: attach() - equal/above\n"); failed++; } //Test attach with less equal than below level buffer->read(); if (capacity != 3) { printf("Failed: attach() - equal/below%d\n", capacity); failed++; } return failed; } #endif /* TESTMTSCIRCULARBUFFER_H */