END_TEST START_TEST (test_cometd_new_publish_message) { cometd_conn_set_client_id(g_instance->conn, "testid"); const char* expected_channel = "/baz/bar"; JsonNode* node = cometd_json_str2node("{ \"hey\": \"now\" }"); JsonNode* message = cometd_new_publish_message(g_instance, expected_channel, node); JsonObject* obj = json_node_get_object(message); const gchar* actual_channel = json_object_get_string_member(obj, COMETD_MSG_CHANNEL_FIELD); ck_assert_str_eq(expected_channel, actual_channel); JsonObject* data = json_object_get_object_member(obj, COMETD_MSG_DATA_FIELD); const char* value = json_object_get_string_member(data, "hey"); ck_assert_str_eq("now", value); json_node_free(message); json_node_free(node); }
int cometd_publish(const cometd* h, const char* channel, JsonNode* message) { int code = COMETD_SUCCESS; JsonNode* node = cometd_new_publish_message(h, channel, message); if (node == NULL) goto failed_node; code = cometd_transport_send(h, node); json_node_free(node); failed_node: return code; }