test_packing.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * Copyright (C) 2009 Mamadou Diop.
  3. *
  4. * Contact: Mamadou Diop <diopmamadou(at)doubango.org>
  5. *
  6. * This file is part of Open Source Doubango Framework.
  7. *
  8. * DOUBANGO is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * DOUBANGO is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with DOUBANGO.
  20. *
  21. */
  22. #ifndef _TEST_SMSPACKING_H
  23. #define _TEST_SMSPACKING_H
  24. typedef struct test_message_7bit_s {
  25. const char* ascii;
  26. const char* _7bit;
  27. }
  28. test_message_7bit_t;
  29. test_message_7bit_t test_messages_7bit[] = {
  30. "a","\x61",
  31. "ab","\x61\x31",
  32. "abc","\x61\xF1\x18",
  33. "abcdefg","\x61\xF1\x98\x5C\x36\x9F\x01",
  34. "abcdefgh","\x61\xF1\x98\x5C\x36\x9F\xD1",
  35. "abcdefghi","\x61\xF1\x98\x5C\x36\x9F\xD1\x69",
  36. "abcdefgh12345678","\x61\xF1\x98\x5C\x36\x9F\xD1\x31\xD9\x8C\x56\xB3\xDD\x70",
  37. "abcdefgh123456789","\x61\xF1\x98\x5C\x36\x9F\xD1\x31\xD9\x8C\x56\xB3\xDD\x70\x39",
  38. "This is a test sms message","\x54\x74\x7A\x0E\x4A\xCF\x41\x61\x10\xBD\x3C\xA7\x83\xE6\xED\x39\xA8\x5D\x9E\xCF\xC3\xE7\x32",
  39. "salut","\xF3\x30\xBB\x4E\x07",
  40. "hellohello","\xE8\x32\x9B\xFD\x46\x97\xD9\xEC\x37",
  41. };
  42. void test_7bit()
  43. {
  44. tsk_size_t i;
  45. tsk_buffer_t* buffer;
  46. char* temp;
  47. /* To 7bit */
  48. for(i=0; i<sizeof(test_messages_7bit)/sizeof(test_message_7bit_t); i++) {
  49. if((buffer = tsms_pack_to_7bit(test_messages_7bit[i].ascii))) {
  50. /*if((temp = tohex(buffer->data, buffer->size))){
  51. if(!tsk_striequals(temp, test_messages_7bit[i]._7bit)){
  52. TSK_DEBUG_ERROR("tsms_pack_to_7bit(\"%s\") Failed.\n", test_messages_7bit[i].ascii);
  53. }
  54. TSK_FREE(temp);
  55. }*/
  56. if(!bin_equals(buffer->data, test_messages_7bit[i]._7bit, buffer->size)) {
  57. TSK_DEBUG_ERROR("tsms_pack_to_7bit(\"%s\") Failed.\n", test_messages_7bit[i].ascii);
  58. }
  59. TSK_OBJECT_SAFE_FREE(buffer);
  60. }
  61. }
  62. /* From 7bit */
  63. for(i=0; i<sizeof(test_messages_7bit)/sizeof(test_message_7bit_t); i++) {
  64. if((temp = tsms_pack_from_7bit(test_messages_7bit[i]._7bit, (tsk_size_t)tsk_strlen(test_messages_7bit[i]._7bit)))) {
  65. if(!tsk_striequals(temp, test_messages_7bit[i].ascii)) {
  66. TSK_DEBUG_ERROR("tsms_pack_from_7bit(\"%s\") Failed.\n", test_messages_7bit[i].ascii);
  67. }
  68. TSK_FREE(temp);
  69. }
  70. }
  71. }
  72. void test_8bit()
  73. {
  74. tsk_size_t i;
  75. tsk_buffer_t* buffer;
  76. char* temp;
  77. /* To 8bit */
  78. for(i=0; i<sizeof(test_messages_7bit)/sizeof(test_message_7bit_t); i++) {
  79. if((buffer = tsms_pack_to_8bit(test_messages_7bit[i].ascii))) {
  80. if(!tsk_strequals(buffer->data, test_messages_7bit[i].ascii)) {
  81. TSK_DEBUG_INFO("tsms_pack_to_8bit(%s) Failed", test_messages_7bit[i].ascii);
  82. }
  83. TSK_OBJECT_SAFE_FREE(buffer);
  84. }
  85. }
  86. /* From 8bit */
  87. for(i=0; i<sizeof(test_messages_7bit)/sizeof(test_message_7bit_t); i++) {
  88. if((temp = tsms_pack_from_8bit(test_messages_7bit[i].ascii, (tsk_size_t)tsk_strlen(test_messages_7bit[i].ascii)))) {
  89. if(!tsk_strequals(temp, test_messages_7bit[i].ascii)) {
  90. TSK_DEBUG_INFO("tsms_pack_from_8bit(%s) Failed", test_messages_7bit[i].ascii);
  91. }
  92. TSK_FREE(temp);
  93. }
  94. }
  95. }
  96. void test_ucs2()
  97. {
  98. tsk_size_t i;
  99. tsk_buffer_t* buffer;
  100. char* temp;
  101. /* To ucs2 */
  102. for(i=0; i<sizeof(test_messages_7bit)/sizeof(test_message_7bit_t); i++) {
  103. if((buffer = tsms_pack_to_ucs2(test_messages_7bit[i].ascii))) {
  104. if(!tsk_strequals(buffer->data, test_messages_7bit[i].ascii)) {
  105. TSK_DEBUG_INFO("tsms_pack_to_ucs2(%s) Failed", test_messages_7bit[i].ascii);
  106. }
  107. TSK_OBJECT_SAFE_FREE(buffer);
  108. }
  109. }
  110. /* From ucs2 */
  111. for(i=0; i<sizeof(test_messages_7bit)/sizeof(test_message_7bit_t); i++) {
  112. if((temp = tsms_pack_from_ucs2(test_messages_7bit[i].ascii, (tsk_size_t)tsk_strlen(test_messages_7bit[i].ascii)))) {
  113. if(!tsk_strequals(temp, test_messages_7bit[i].ascii)) {
  114. TSK_DEBUG_INFO("tsms_pack_from_ucs2(%s) Failed", test_messages_7bit[i].ascii);
  115. }
  116. TSK_FREE(temp);
  117. }
  118. }
  119. }
  120. void test_packing()
  121. {
  122. test_ucs2();
  123. test_8bit();
  124. test_7bit();
  125. }
  126. #endif /* _TEST_SMSPACKING_H */