queue.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * OpenHMD - Free and Open Source API and drivers for immersive technology.
  3. * Copyright (C) 2016 Fredrik Hultin.
  4. * Distributed under the Boost 1.0 licence, see LICENSE for full text.
  5. */
  6. /* Unit Tests - Queue */
  7. #include "tests.h"
  8. #include "openhmdi.h"
  9. void test_ohmdq_push_pop()
  10. {
  11. ohmd_context* ctx = ohmd_ctx_create();
  12. ohmdq* q = ohmdq_create(ctx, sizeof(int), 10);
  13. TAssert(ohmdq_get_max(q) == 10);
  14. for(int i = 0; i < 10; i++){
  15. bool ret = ohmdq_push(q, &i);
  16. TAssert(ret);
  17. }
  18. TAssert(ohmdq_get_size(q) == 10);
  19. int val = 0;
  20. bool ret = ohmdq_push(q, &val);
  21. TAssert(!ret);
  22. for(int i = 0; i < 10; i++){
  23. int val = 0;
  24. bool ret = ohmdq_pop(q, &val);
  25. TAssert(ret);
  26. TAssert(val == i);
  27. }
  28. TAssert(ohmdq_get_size(q) == 0);
  29. for(int i = 0; i < 10; i++){
  30. bool ret = ohmdq_push(q, &i);
  31. TAssert(ret);
  32. }
  33. TAssert(ohmdq_get_size(q) == 10);
  34. val = 0;
  35. ret = ohmdq_push(q, &val);
  36. TAssert(!ret);
  37. for(int i = 0; i < 10; i++){
  38. int val = 0;
  39. bool ret = ohmdq_pop(q, &val);
  40. TAssert(ret);
  41. TAssert(val == i);
  42. }
  43. TAssert(ohmdq_get_size(q) == 0);
  44. ohmdq_destroy(q);
  45. ohmd_ctx_destroy(ctx);
  46. }