2
0

switch_hold.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #include <switch.h>
  2. #include <test/switch_test.h>
  3. int timeout_sec = 10;
  4. switch_interval_time_t delay_start_ms = 5000;
  5. FST_CORE_DB_BEGIN("./conf_test")
  6. {
  7. FST_SUITE_BEGIN(switch_hold)
  8. {
  9. FST_SETUP_BEGIN()
  10. {
  11. /* Give mod_sofia time to spinup profile threads */
  12. if (delay_start_ms) {
  13. switch_sleep(delay_start_ms * 1000);
  14. delay_start_ms = 0;
  15. }
  16. fst_requires_module("mod_sofia");
  17. fst_requires_module("mod_commands");
  18. }
  19. FST_SETUP_END()
  20. FST_TEARDOWN_BEGIN()
  21. {
  22. }
  23. FST_TEARDOWN_END()
  24. FST_TEST_BEGIN(hold_unhold_restriction)
  25. {
  26. switch_core_session_t *session = NULL;
  27. switch_status_t status;
  28. switch_call_cause_t cause;
  29. status = switch_ivr_originate(NULL, &session, &cause, "{ignore_early_media=true}sofia/gateway/test_gateway/+15553332900", timeout_sec, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, NULL);
  30. fst_requires(session);
  31. fst_check(status == SWITCH_STATUS_SUCCESS);
  32. if (session) {
  33. const char *uuid = switch_core_session_get_uuid(session);
  34. switch_channel_t *channel = NULL;
  35. channel = switch_core_session_get_channel(session);
  36. fst_requires(channel);
  37. if (uuid) {
  38. char *off_uuid = switch_mprintf("off %s", uuid);
  39. char *toggle_uuid = switch_mprintf("toggle %s", uuid);
  40. switch_stream_handle_t stream = { 0 };
  41. switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "firing the api.\n");
  42. SWITCH_STANDARD_STREAM(stream);
  43. switch_api_execute("uuid_hold", off_uuid, NULL, &stream);
  44. fst_check_string_equals(stream.data, "-ERR Operation failed\n");
  45. switch_safe_free(stream.data);
  46. switch_sleep(200000);
  47. SWITCH_STANDARD_STREAM(stream);
  48. switch_api_execute("uuid_hold", uuid, NULL, &stream);
  49. fst_check_string_equals(stream.data, "+OK Success\n");
  50. switch_safe_free(stream.data);
  51. switch_sleep(200000);
  52. SWITCH_STANDARD_STREAM(stream);
  53. switch_api_execute("uuid_hold", uuid, NULL, &stream);
  54. fst_check_string_equals(stream.data, "-ERR Operation failed\n");
  55. switch_safe_free(stream.data);
  56. switch_sleep(200000);
  57. SWITCH_STANDARD_STREAM(stream);
  58. switch_api_execute("uuid_hold", uuid, NULL, &stream);
  59. fst_check_string_equals(stream.data, "-ERR Operation failed\n");
  60. switch_safe_free(stream.data);
  61. switch_sleep(200000);
  62. SWITCH_STANDARD_STREAM(stream);
  63. switch_api_execute("uuid_hold", toggle_uuid, NULL, &stream);
  64. fst_check_string_equals(stream.data, "+OK Success\n");
  65. switch_safe_free(stream.data);
  66. switch_sleep(200000);
  67. SWITCH_STANDARD_STREAM(stream);
  68. switch_api_execute("uuid_hold", off_uuid, NULL, &stream);
  69. fst_check_string_equals(stream.data, "-ERR Operation failed\n");
  70. switch_safe_free(stream.data);
  71. switch_sleep(200000);
  72. SWITCH_STANDARD_STREAM(stream);
  73. switch_api_execute("uuid_hold", toggle_uuid, NULL, &stream);
  74. fst_check_string_equals(stream.data, "+OK Success\n");
  75. switch_safe_free(stream.data);
  76. switch_sleep(200000);
  77. SWITCH_STANDARD_STREAM(stream);
  78. switch_api_execute("uuid_hold", uuid, NULL, &stream);
  79. fst_check_string_equals(stream.data, "-ERR Operation failed\n");
  80. switch_safe_free(stream.data);
  81. switch_sleep(200000);
  82. switch_safe_free(off_uuid);
  83. switch_safe_free(toggle_uuid);
  84. }
  85. switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
  86. switch_core_session_rwunlock(session);
  87. }
  88. }
  89. FST_TEST_END()
  90. }
  91. FST_SUITE_END()
  92. }
  93. FST_CORE_END()