MiscTest.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /******************************************************************
  2. *
  3. * uEcho for C
  4. *
  5. * Copyright (C) Satoshi Konno 2015
  6. *
  7. * This is licensed under BSD-style license, see file COPYING.
  8. *
  9. ******************************************************************/
  10. #include <boost/test/unit_test.hpp>
  11. #include <uecho/misc.h>
  12. BOOST_AUTO_TEST_CASE(ObjCode2ClsCode)
  13. {
  14. BOOST_CHECK_EQUAL(uecho_objectcode2classcode(0x0EF001), 0x0EF0);
  15. BOOST_CHECK_EQUAL(uecho_objectcode2classcode(0x001102), 0x0011);
  16. BOOST_CHECK_EQUAL(uecho_objectcode2classcode(0x001102), 0x0011);
  17. }
  18. BOOST_AUTO_TEST_CASE(Byte2Integer)
  19. {
  20. byte int_bytes[4];
  21. for (int n = 0; n <= 0xFF; n++) {
  22. uecho_integer2byte(n, int_bytes, 1);
  23. BOOST_CHECK_EQUAL(n, uecho_byte2integer(int_bytes, 1));
  24. }
  25. for (int n = 0; n <= 0xFFFF; n += (0xFFFF / 0xFF)) {
  26. uecho_integer2byte(n, int_bytes, 2);
  27. BOOST_CHECK_EQUAL(n, uecho_byte2integer(int_bytes, 2));
  28. }
  29. for (int n = 0; n <= 0xFFFFFF; n += (0xFFFFFF / 0xFF)) {
  30. uecho_integer2byte(n, int_bytes, 3);
  31. BOOST_CHECK_EQUAL(n, uecho_byte2integer(int_bytes, 3));
  32. }
  33. for (int n = 0; n < 0xFFFFFFFF; n += (0xFFFFFFFF / 0xFF)) {
  34. uecho_integer2byte(n, int_bytes, 4);
  35. BOOST_CHECK_EQUAL(n, uecho_byte2integer(int_bytes, 4));
  36. }
  37. }
  38. BOOST_AUTO_TEST_CASE(ClassGroupCode)
  39. {
  40. for (int n = uEchoClassGroupDeviceMin; n <= uEchoClassGroupDeviceMax; n++) {
  41. BOOST_CHECK(uecho_isdeviceclassgroupcode(n));
  42. BOOST_CHECK(!uecho_isprofileclassgroupcode(n));
  43. }
  44. BOOST_CHECK(!uecho_isdeviceclassgroupcode(uEchoClassGroupProfile));
  45. BOOST_CHECK(uecho_isprofileclassgroupcode(uEchoClassGroupProfile));
  46. }