switch_utils.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
  3. * Copyright (C) 2005-2018, Anthony Minessale II <anthm@freeswitch.org>
  4. *
  5. * Version: MPL 1.1
  6. *
  7. * The contents of this file are subject to the Mozilla Public License Version
  8. * 1.1 (the "License"); you may not use this file except in compliance with
  9. * the License. You may obtain a copy of the License at
  10. * http://www.mozilla.org/MPL/
  11. *
  12. * Software distributed under the License is distributed on an "AS IS" basis,
  13. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  14. * for the specific language governing rights and limitations under the
  15. * License.
  16. *
  17. * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
  18. *
  19. * The Initial Developer of the Original Code is
  20. * Anthony Minessale II <anthm@freeswitch.org>
  21. * Portions created by the Initial Developer are Copyright (C)
  22. * the Initial Developer. All Rights Reserved.
  23. *
  24. * Contributor(s):
  25. * Seven Du <seven@signalwire.com>
  26. * Windy Wang <xiaofengcanyuexp@163.com>
  27. *
  28. * switch_utils.c -- tests switch_utils
  29. *
  30. */
  31. #include <stdio.h>
  32. #include <switch.h>
  33. #include <test/switch_test.h>
  34. FST_MINCORE_BEGIN("./conf")
  35. FST_SUITE_BEGIN(switch_hash)
  36. FST_SETUP_BEGIN()
  37. {
  38. }
  39. FST_SETUP_END()
  40. FST_TEARDOWN_BEGIN()
  41. {
  42. }
  43. FST_TEARDOWN_END()
  44. FST_TEST_BEGIN(benchmark)
  45. {
  46. char encoded[1024];
  47. char *s = "ABCD";
  48. switch_url_encode(s, encoded, sizeof(encoded));
  49. switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "encoded: [%s]\n", encoded);
  50. fst_check_string_equals(encoded, "ABCD");
  51. s = "&bryän#!杜金房";
  52. switch_url_encode(s, encoded, sizeof(encoded));
  53. switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "encoded: [%s]\n", encoded);
  54. fst_check_string_equals(encoded, "%26bry%C3%A4n%23!%E6%9D%9C%E9%87%91%E6%88%BF");
  55. }
  56. FST_TEST_END()
  57. FST_TEST_BEGIN(b64)
  58. {
  59. char *str = "ABC";
  60. unsigned char b64_str[6];
  61. char decoded_str[4];
  62. switch_status_t status = switch_b64_encode((unsigned char *)str, strlen(str), b64_str, sizeof(b64_str));
  63. switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "b64_str: %s\n", b64_str);
  64. fst_check(status == SWITCH_STATUS_SUCCESS);
  65. fst_check_string_equals((const char *)b64_str, "QUJD");
  66. switch_size_t size = switch_b64_decode((const char *)b64_str, decoded_str, sizeof(decoded_str));
  67. switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "decoded_str: %s\n", decoded_str);
  68. fst_check_string_equals(decoded_str, str);
  69. fst_check(size == 4);
  70. }
  71. FST_TEST_END()
  72. FST_SUITE_END()
  73. FST_MINCORE_END()
  74. /* For Emacs:
  75. * Local Variables:
  76. * mode:c
  77. * indent-tabs-mode:t
  78. * tab-width:4
  79. * c-basic-offset:4
  80. * End:
  81. * For VIM:
  82. * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
  83. */