diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2024-05-05 22:30:04 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2024-05-05 22:30:04 +0200 |
commit | 211cd11c2a310e336ecd8760d8f33fd04dc99590 (patch) | |
tree | 3e5be77b6ef0647339dcab2e292470229e3f3487 /tests/unit/plugins/relay/api | |
parent | 9ceea3697bf5f194d4a86e46dd9b04012dc0592c (diff) | |
download | weechat-211cd11c2a310e336ecd8760d8f33fd04dc99590.zip |
relay/api: add parameter "lines_free" in GET /api/buffers
This parameter is the number of lines to return for buffers with free content.
Its default value is `0` if "lines" is set to `0`, otherwise all buffer lines
are returned.
Diffstat (limited to 'tests/unit/plugins/relay/api')
-rw-r--r-- | tests/unit/plugins/relay/api/test-relay-api-msg.cpp | 51 |
1 files changed, 46 insertions, 5 deletions
diff --git a/tests/unit/plugins/relay/api/test-relay-api-msg.cpp b/tests/unit/plugins/relay/api/test-relay-api-msg.cpp index 239dd80f8..696bf1fc8 100644 --- a/tests/unit/plugins/relay/api/test-relay-api-msg.cpp +++ b/tests/unit/plugins/relay/api/test-relay-api-msg.cpp @@ -118,7 +118,8 @@ TEST(RelayApiMsg, SendEvent) TEST(RelayApiMsg, BufferToJson) { - cJSON *json, *json_obj, *json_local_vars, *json_keys, *json_key, *json_lines; + cJSON *json, *json_obj, *json_local_vars, *json_keys, *json_key; + cJSON *json_lines, *json_line; cJSON *json_nicklist_root, *json_nicks, *json_groups, *json_group; cJSON *json_group_nicks, *json_nick; struct t_gui_buffer *buffer; @@ -126,7 +127,7 @@ TEST(RelayApiMsg, BufferToJson) long long group_id; char *color; - json = relay_api_msg_buffer_to_json (NULL, 0, 0, RELAY_API_COLORS_ANSI); + json = relay_api_msg_buffer_to_json (NULL, 0L, 0L, 0, RELAY_API_COLORS_ANSI); CHECK(json); CHECK(cJSON_IsObject (json)); POINTERS_EQUAL(NULL, cJSON_GetObjectItem (json, "name")); @@ -136,7 +137,7 @@ TEST(RelayApiMsg, BufferToJson) gui_buffer_set (gui_buffers, "key_bind_meta-y,2", "/test2 arg"); /* buffer without lines and nicks */ - json = relay_api_msg_buffer_to_json (gui_buffers, 0, 0, RELAY_API_COLORS_ANSI); + json = relay_api_msg_buffer_to_json (gui_buffers, 0L, 0L, 0, RELAY_API_COLORS_ANSI); CHECK(json); CHECK(cJSON_IsObject (json)); WEE_CHECK_OBJ_NUM(gui_buffers->id, json, "id"); @@ -169,7 +170,7 @@ TEST(RelayApiMsg, BufferToJson) cJSON_Delete (json); /* buffer with 2 lines, without nicks */ - json = relay_api_msg_buffer_to_json (gui_buffers, 2, 0, RELAY_API_COLORS_ANSI); + json = relay_api_msg_buffer_to_json (gui_buffers, 2L, 0L, 0, RELAY_API_COLORS_ANSI); CHECK(json); CHECK(cJSON_IsObject (json)); json_lines = cJSON_GetObjectItem (json, "lines"); @@ -192,7 +193,7 @@ TEST(RelayApiMsg, BufferToJson) CHECK(gui_nicklist_add_nick (buffer, NULL, "root_nick_hidden", "cyan", "+", "yellow", 0)); /* buffer with no lines and 1 group / 4 nicks */ - json = relay_api_msg_buffer_to_json (buffer, 1, 1, RELAY_API_COLORS_ANSI); + json = relay_api_msg_buffer_to_json (buffer, 1L, 0L, 1, RELAY_API_COLORS_ANSI); CHECK(json); CHECK(cJSON_IsObject (json)); WEE_CHECK_OBJ_BOOL(1, json, "nicklist"); @@ -315,6 +316,46 @@ TEST(RelayApiMsg, BufferToJson) gui_buffer_set (gui_buffers, "key_unbind_meta-y", ""); gui_buffer_close (buffer); + + buffer = gui_buffer_new_user ("test", GUI_BUFFER_TYPE_FREE); + CHECK(buffer); + gui_chat_printf_y (buffer, 0, "test line 1"); + gui_chat_printf_y (buffer, 1, "test line 2"); + gui_chat_printf_y (buffer, 2, "test line 3"); + gui_chat_printf_y (buffer, 3, "test line 4"); + gui_chat_printf_y (buffer, 4, "test line 5"); + + json = relay_api_msg_buffer_to_json (buffer, 1L, 2L, 0, RELAY_API_COLORS_ANSI); + CHECK(json); + CHECK(cJSON_IsObject (json)); + json_lines = cJSON_GetObjectItem (json, "lines"); + CHECK(json_lines); + CHECK(cJSON_IsArray (json_lines)); + LONGS_EQUAL(2, cJSON_GetArraySize (json_lines)); + json_line = cJSON_GetArrayItem (json_lines, 0); + CHECK(json_line); + WEE_CHECK_OBJ_STR("test line 1", json_line, "message"); + json_line = cJSON_GetArrayItem (json_lines, 1); + CHECK(json_line); + WEE_CHECK_OBJ_STR("test line 2", json_line, "message"); + cJSON_Delete (json); + + json = relay_api_msg_buffer_to_json (buffer, 1L, -2L, 0, RELAY_API_COLORS_ANSI); + CHECK(json); + CHECK(cJSON_IsObject (json)); + json_lines = cJSON_GetObjectItem (json, "lines"); + CHECK(json_lines); + CHECK(cJSON_IsArray (json_lines)); + LONGS_EQUAL(2, cJSON_GetArraySize (json_lines)); + json_line = cJSON_GetArrayItem (json_lines, 0); + CHECK(json_line); + WEE_CHECK_OBJ_STR("test line 4", json_line, "message"); + json_line = cJSON_GetArrayItem (json_lines, 1); + CHECK(json_line); + WEE_CHECK_OBJ_STR("test line 5", json_line, "message"); + cJSON_Delete (json); + + gui_buffer_close (buffer); } /* |