BufferTests.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include "tests/BufferTests.h"
  2. #include "tests/Test.h"
  3. #include "utils/Buffer.h"
  4. #include "utils/Utility.h"
  5. static constexpr int SIZE_TYPES =
  6. sizeof(int) + sizeof(long) + sizeof(float) + sizeof(double);
  7. static void testAdd(Test& test) {
  8. Buffer buffer(10);
  9. for(int i = 0; i < 100000; i++) {
  10. buffer.add(5);
  11. buffer.add(5L);
  12. buffer.add(5.0f);
  13. buffer.add(5.0);
  14. }
  15. test.checkEqual(SIZE_TYPES * 100000, buffer.getLength(),
  16. "add increments length");
  17. }
  18. static void testCopy(Test& test) {
  19. Buffer buffer(10);
  20. for(int i = 0; i < 10; i++) {
  21. buffer.add(5);
  22. buffer.add(5L);
  23. buffer.add(5.0f);
  24. buffer.add(5.0);
  25. }
  26. Buffer buffer2(buffer);
  27. Buffer buffer3(2);
  28. buffer3 = buffer;
  29. test.checkEqual(SIZE_TYPES * 10, buffer.getLength(), "copy");
  30. test.checkEqual(SIZE_TYPES * 10, buffer2.getLength(), "copy");
  31. test.checkEqual(SIZE_TYPES * 10, buffer3.getLength(), "copy");
  32. }
  33. static void testMoveConstruct(Test& test) {
  34. Buffer buffer(10);
  35. for(int i = 0; i < 10; i++) {
  36. buffer.add(5);
  37. buffer.add(5L);
  38. buffer.add(5.0f);
  39. buffer.add(5.0);
  40. }
  41. Buffer buffer2(Core::move(buffer));
  42. test.checkEqual(0, buffer.getLength(), "move");
  43. test.checkEqual(SIZE_TYPES * 10, buffer2.getLength(), "move");
  44. }
  45. static void testMove(Test& test) {
  46. Buffer buffer(10);
  47. for(int i = 0; i < 10; i++) {
  48. buffer.add(5);
  49. buffer.add(5L);
  50. buffer.add(5.0f);
  51. buffer.add(5.0);
  52. }
  53. Buffer buffer2(3);
  54. buffer2 = Core::move(buffer);
  55. test.checkEqual(0, buffer.getLength(), "move");
  56. test.checkEqual(SIZE_TYPES * 10, buffer2.getLength(), "move");
  57. }
  58. void BufferTests::test() {
  59. Test test("Buffer");
  60. testAdd(test);
  61. testCopy(test);
  62. testMoveConstruct(test);
  63. testMove(test);
  64. test.finalize();
  65. }