uncert.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (c) 2018-2020 SignalWire, Inc
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in all
  12. * copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. #include "swclt_test.h"
  23. static ks_cond_t *g_cond;
  24. static void __on_sess_state_event(swclt_sess_t *sess, void *cb_data)
  25. {
  26. REQUIRE(!strcmp((char *)cb_data, "bobo"));
  27. ks_cond_lock(g_cond);
  28. ks_cond_broadcast(g_cond);
  29. ks_cond_unlock(g_cond);
  30. }
  31. void test_uncert_exp(ks_pool_t *pool)
  32. {
  33. swclt_sess_t *sess;
  34. REQUIRE(!ks_cond_create(&g_cond, NULL));
  35. /* Load the config we expect session to load */
  36. REQUIRE(swclt_config_get_authentication(g_uncertified_config));
  37. REQUIRE(!swclt_sess_create(&sess, g_target_ident_str, g_uncertified_config));
  38. /* Register a monitor to get to know when session comes online successfully */
  39. REQUIRE(!swclt_sess_set_state_change_cb(sess, __on_sess_state_event, "bobo"));
  40. ks_cond_lock(g_cond);
  41. /* Now take the session onine */
  42. REQUIRE(!swclt_sess_connect(sess));
  43. int i = 5;
  44. while (i-- > 0 && !swclt_sess_connected(sess)) {
  45. ks_cond_timedwait(g_cond, 1000);
  46. }
  47. REQUIRE(swclt_sess_connected(sess));
  48. /* Now disconnect the session */
  49. REQUIRE(!swclt_sess_disconnect(sess));
  50. i = 5;
  51. while (i-- > 0 && swclt_sess_connected(sess)) {
  52. ks_cond_timedwait(g_cond, 1000);
  53. }
  54. REQUIRE(!swclt_sess_connected(sess));
  55. /* Go online again */
  56. REQUIRE(!swclt_sess_connect(sess));
  57. i = 5;
  58. while (i-- > 0 && !swclt_sess_connected(sess)) {
  59. ks_cond_timedwait(g_cond, 1000);
  60. }
  61. REQUIRE(swclt_sess_connected(sess));
  62. ks_cond_unlock(g_cond);
  63. swclt_sess_destroy(&sess);
  64. /* Ok we're done */
  65. ks_cond_destroy(&g_cond);
  66. }