test.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #include <stdio.h>
  2. #include "../emitlib.h"
  3. #define TEST_START printf("\n=== %s ===\n", __FUNCTION__)
  4. void testByteBuffer()
  5. {
  6. BYTE_BUFFER buffer;
  7. char bytes[] = {0xcd, 0xef, 0x12};
  8. TEST_START;
  9. buffer = createByteBuffer();
  10. pushByte(&buffer, 0xab);
  11. pushBytes(&buffer, bytes, 3);
  12. pushWord(&buffer, 0x3456);
  13. printf("Should: AB CD EF 12 34 56\nGet: ");
  14. printfByteBuffer(buffer);
  15. destroyByteBuffer(buffer);
  16. }
  17. void testPrintBits()
  18. {
  19. BYTE_BUFFER buffer;
  20. char bytes[] = {0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0};
  21. TEST_START;
  22. buffer = createByteBuffer();
  23. pushBytes(&buffer, bytes, 8);
  24. printfBitBuffer(buffer);
  25. destroyByteBuffer(buffer);
  26. }
  27. /*void testBitBuffer()
  28. {
  29. BIT_BUFFER buffer;
  30. TEST_START;
  31. buffer = createBitBuffer();
  32. bitPushBit(&buffer, 1);
  33. bitPushBit(&buffer, 1);
  34. bitPushBit(&buffer, 1);
  35. bitPushBit(&buffer, 1);
  36. bitPushBit(&buffer, 0);
  37. bitPushBit(&buffer, 0);
  38. bitPushBit(&buffer, 0);
  39. bitPushBit(&buffer, 0);
  40. printf("Should: 11110000\nGet: ");
  41. printfBitBuffer(buffer);
  42. printf("\n");
  43. destroyBitBuffer(buffer);
  44. }*/
  45. void testEncode()
  46. {
  47. unsigned char srcByte = 0x28;
  48. unsigned short int encWord;
  49. TEST_START;
  50. encWord = encodeByte(srcByte);
  51. printf("Input: %02X\nShould: 0x5995\nGet: %04X\n", srcByte, encWord);
  52. }
  53. void testDecode()
  54. {
  55. unsigned short int srcWord = 0x5995;
  56. unsigned char decByte;
  57. TEST_START;
  58. decByte = decodeByte(srcWord);
  59. printf("Input: %04X\nShould: 0x28\nGet: %02X\n", srcWord, decByte);
  60. }
  61. void testHomeEasyEncode()
  62. {
  63. BYTE_BUFFER source;
  64. BYTE_BUFFER encoded;
  65. unsigned char bytes[] = {0x28, 0x28, 0x01};
  66. TEST_START;
  67. source = createByteBuffer();
  68. pushBytes(&source, bytes, 3);
  69. printf("Input: ");
  70. printfByteBuffer(source);
  71. printf("Should: 59 95 59 95 55 56\nGet: ");
  72. encoded = homeEasyEncode(&source);
  73. printfByteBuffer(encoded);
  74. destroyByteBuffer(source);
  75. destroyByteBuffer(encoded);
  76. }
  77. void testHomeEasyDecode()
  78. {
  79. BYTE_BUFFER source;
  80. BYTE_BUFFER decoded;
  81. unsigned char bytes[] = {0x59, 0x95, 0x59, 0x95, 0x55, 0x56};
  82. TEST_START;
  83. source = createByteBuffer();
  84. pushBytes(&source, bytes, 6);
  85. printf("Input: ");
  86. printfByteBuffer(source);
  87. printf("Should: 28 28 01\nGet: ");
  88. decoded = homeEasyDecode(&source);
  89. printfByteBuffer(decoded);
  90. destroyByteBuffer(source);
  91. destroyByteBuffer(decoded);
  92. }
  93. void testHomeEasyCommand(char section, unsigned char num, unsigned char onOff)
  94. {
  95. BYTE_BUFFER command;
  96. BYTE_BUFFER encoded;
  97. unsigned char id[] = {0x28, 0x28, 0x01, 0x80};
  98. TEST_START;
  99. command = createHomeEasyCommand(id, section, num, onOff);
  100. printfByteBuffer(command);
  101. encoded = homeEasyEncode(&command);
  102. printfByteBuffer(encoded);
  103. destroyByteBuffer(command);
  104. destroyByteBuffer(encoded);
  105. }
  106. int main()
  107. {
  108. printf("Test\n");
  109. testByteBuffer();
  110. //testBitBuffer();
  111. testPrintBits();
  112. testEncode();
  113. testDecode();
  114. testHomeEasyEncode();
  115. testHomeEasyDecode();
  116. testHomeEasyCommand('D', 4, ON);
  117. return 0;
  118. }