BufferTests.cpp 650 B

12345678910111213141516171819202122232425262728
  1. #include "tests/BufferTests.h"
  2. #include "tests/Test.h"
  3. #include "utils/Buffer.h"
  4. static void testAdd(Test& test) {
  5. Buffer<10> bits;
  6. int a = 5;
  7. bits.add(a);
  8. test.checkEqual(static_cast<int> (sizeof (a)), bits.getLength(), "add increments length");
  9. }
  10. static void testOverflow(Test& test) {
  11. Buffer<10> bits;
  12. for(int i = 0; i < 1000000; i++) {
  13. bits.add(5);
  14. bits.add(5L);
  15. bits.add(5.0f);
  16. bits.add(5.0);
  17. }
  18. test.checkEqual(10, bits.getLength(), "add increments length");
  19. }
  20. void BufferTests::test() {
  21. Test test("Buffer");
  22. testAdd(test);
  23. testOverflow(test);
  24. test.finalize();
  25. }