message: Added tests for circular buffer
diff: @@ -15,9 +15,74 @@ limitations under the License.
  #include "circular_buffer.h"
  #include "gtest/gtest.h"
  +#include <cstdlib>
  // Just getting my feet wet with gtest
  +TEST(CircBuff, Counts) {
  + CircBuff<128> buff;
  +
  + // Note that a buffer with 128 bytes of storage can only actually
  + // hold 127 bytes. This is a side effect of how we represent a
  + // full buffer.
  + ASSERT_EQ(buff.FreeCt(), 127);
  + ASSERT_EQ(buff.FullCt(), 0);
  +
  + // Add/remove bytes from the buffer and check counts along the way.
  + // The full/free calculations change when the buffer wraps, so I
  + // want to make sure I do this enough times to catch any errors in
  + // that logic
  + for (int i = 0; i < 100; i++) {
  + int full = 0;
  + int free = 127;
  + for (int j = 0; j < 20; j++) {
  + bool ok = buff.Put(0);
  + ASSERT_EQ(ok, true);
  +
  + full++;
  + free--;
  + ASSERT_EQ(buff.FreeCt(), free);
  + ASSERT_EQ(buff.FullCt(), full);
  + }
  +
  + for (int j = 0; j < 20; j++) {
  + int ch = buff.Get();
  + ASSERT_EQ(ch, 0);
  +
  + full--;
  + free++;
  + ASSERT_EQ(buff.FreeCt(), free);
  + ASSERT_EQ(buff.FullCt(), full);
  + }
  + }
  +}
  +
  +// Make sure the data we add to the buffer is the same
  +// as the data we get out of it
  TEST(CircBuff, DataIO) {
  - ASSERT_EQ( 1, 2 ) << "In these uncertain times, I'm not sure of anything";
  + CircBuff<128> buff;
  +
  + uint8_t TestSet[200];
  + for (uint32_t i = 0; i < sizeof(TestSet); i++)
  + TestSet[i] = rand();
  +
  + // Add data to the buffer until failure
  + for (int i = 0; i < 128; i++) {
  + bool ok = buff.Put(TestSet[i]);
  + if (i < 127) {
  + ASSERT_EQ(ok, true);
  }
  + else {
  + ASSERT_EQ(ok, false);
  + break;
  + }
  + }
  +
  + for (int i = 0; i < 127; i++) {
  + int x = buff.Get();
  + ASSERT_EQ(x, TestSet[i]);
  + }
  +
  + // The buffer should be empty now
  + ASSERT_EQ(buff.Get(), -1);
  +}
  