123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- #include "swclt_test.h"
- static SWCLT_HSTATE g_last_state_change;
- static ks_cond_t *g_cond;
- static void __on_sess_hmon_event(swclt_sess_t sess, swclt_hstate_change_t *state_change_info, const char *cb_data)
- {
- REQUIRE(!strcmp(cb_data, "bobo"));
- ks_cond_lock(g_cond);
- g_last_state_change = state_change_info->new_state;
- ks_cond_broadcast(g_cond);
- ks_cond_unlock(g_cond);
- }
- typedef void(*swclt_hstate_change_cb_t)(swclt_handle_base_t *ctx, swclt_hstate_change_t *state_change_request);
- void test_session(ks_pool_t *pool)
- {
- swclt_sess_t sess;
- swclt_sess_ctx_t *sess_ctx;
- swclt_hmon_t hmon;
- REQUIRE(!ks_cond_create(&g_cond, NULL));
-
- REQUIRE(swclt_config_get_private_key_path(g_certified_config));
- REQUIRE(swclt_config_get_client_cert_path(g_certified_config));
- REQUIRE(swclt_config_get_cert_chain_path(g_certified_config));
- REQUIRE(!swclt_sess_create(&sess, g_target_ident_str, g_certified_config));
-
- REQUIRE(!swclt_hmon_register(&hmon, sess, __on_sess_hmon_event, "bobo"));
- {
- ks_handle_t next = 0;
- uint32_t count = 0;
- while (KS_STATUS_SUCCESS == ks_handle_enum_type(SWCLT_HTYPE_HMON, &next))
- count++;
- REQUIRE(count == 1);
- }
- ks_cond_lock(g_cond);
-
- REQUIRE(!swclt_sess_connect(sess));
- ks_cond_wait(g_cond);
-
- REQUIRE(g_last_state_change == SWCLT_HSTATE_ONLINE);
-
- REQUIRE(!swclt_sess_disconnect(sess));
-
- ks_cond_wait(g_cond);
- REQUIRE(g_last_state_change == SWCLT_HSTATE_OFFLINE);
-
- ks_handle_destroy(&hmon);
- ks_cond_unlock(g_cond);
-
- REQUIRE(!swclt_sess_connect(sess));
-
- while (swclt_hstate_check(sess, NULL))
- ks_sleep(1000);
-
- ks_cond_destroy(&g_cond);
- ks_handle_destroy(&sess);
- }
|