switch_hold.c 3.1 KB

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