highlevel.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * OpenHMD - Free and Open Source API and drivers for immersive technology.
  3. * Copyright (C) 2013 Fredrik Hultin.
  4. * Copyright (C) 2013 Jakob Bornecrantz.
  5. * Distributed under the Boost 1.0 licence, see LICENSE for full text.
  6. */
  7. /* Unit Tests - High-level functions */
  8. #include "tests.h"
  9. #include "openhmd.h"
  10. void test_highlevel_open_close_device()
  11. {
  12. ohmd_context* ctx = ohmd_ctx_create();
  13. TAssert(ctx);
  14. // Probe for devices
  15. int num_devices = ohmd_ctx_probe(ctx);
  16. TAssert(num_devices > 0);
  17. // Open dummy device (num_devices - 1)
  18. ohmd_device* hmd = ohmd_list_open_device(ctx, num_devices - 1);
  19. TAssert(hmd);
  20. // Close the device
  21. int ret = ohmd_close_device(hmd);
  22. TAssert(ret == 0);
  23. ohmd_ctx_destroy(ctx);
  24. }
  25. void test_highlevel_open_close_many_devices()
  26. {
  27. ohmd_context* ctx = ohmd_ctx_create();
  28. TAssert(ctx);
  29. // Probe for devices
  30. int num_devices = ohmd_ctx_probe(ctx);
  31. TAssert(num_devices > 0);
  32. ohmd_device* hmds[16];
  33. for(int i = 0; i < 8; i++){
  34. // Open dummy device (num_devices - 1)
  35. hmds[i] = ohmd_list_open_device(ctx, num_devices - 1);
  36. TAssert(hmds[i]);
  37. }
  38. for(int i = 4; i < 8; i++){
  39. // Close the device
  40. int ret = ohmd_close_device(hmds[i]);
  41. TAssert(ret == 0);
  42. }
  43. for(int i = 4; i < 16; i++){
  44. // Open dummy device (num_devices - 1)
  45. hmds[i] = ohmd_list_open_device(ctx, num_devices - 1);
  46. TAssert(hmds[i]);
  47. }
  48. for(int i = 0; i < 16; i++){
  49. // Close the device
  50. int ret = ohmd_close_device(hmds[i]);
  51. TAssert(ret == 0);
  52. }
  53. ohmd_ctx_destroy(ctx);
  54. }