END_TEST

START_TEST (test_cometd_new_subscribe_message)
{
    cometd_conn_set_client_id(g_instance->conn, "testid");
    const char* expected_channel = "/foo/bar/baz";

    JsonNode* msg = cometd_new_subscribe_message(g_instance,
                    expected_channel);
    JsonObject* obj = json_node_get_object(msg);

    const gchar* actual_channel = json_object_get_string_member(obj,
                                  COMETD_MSG_SUBSCRIPTION_FIELD);

    ck_assert_str_eq(expected_channel, actual_channel);

    json_node_free(msg);
}
Beispiel #2
0
cometd_subscription*
cometd_subscribe(const cometd* h,
                 char* channel,
                 cometd_callback handler)
{
  int code = COMETD_SUCCESS;
  cometd_subscription* s = NULL;

  if (cometd_is_meta_channel(channel) == FALSE)
  {
    JsonNode* node = cometd_new_subscribe_message(h, channel);
    if (node != NULL)
    {
      code = cometd_transport_send(h, node);
      json_node_free(node);
    }
  }

  if (code == COMETD_SUCCESS)
    s = cometd_add_listener(h, channel, handler);

  return s;
}