merge: sync upstream profanity-im/profanity
All checks were successful
CI Code / Check spelling (push) Successful in 18s
CI Code / Check coding style (push) Successful in 34s
CI Code / Code Coverage (push) Successful in 2m36s
CI Code / Linux (debian) (push) Successful in 4m41s
CI Code / Linux (ubuntu) (push) Successful in 4m52s
CI Code / Linux (arch) (push) Successful in 5m40s

Sync with upstream profanity-im/profanity.

Major upstream changes incorporated:

Memory management
  - Replace malloc+memset with g_new0 throughout codebase
  - Adopt auto_gchar / auto_gcharv / auto_gerror / auto_jid cleanup macros
  - Replace free() with g_free() for GAlloc'd memory

Editor rewrite
  - Remove pthread-based async editor; use GChildWatch callback API
  - New launch_editor(initial_content, callback, user_data) interface
  - Proper signal handling (SIGINT, SIGTSTP, SIGPIPE reset in child)
  - ui_suspend()/ui_resume() integration for TTY management

OMEMO improvements
  - Dual backend support: libsignal-protocol-c and libomemo-c
  - Proper pre-key removal after use (XEP-0384 compliance)
  - Automatic pre-key regeneration when store drops below threshold
  - New functions: omemo_is_device_active(), omemo_is_jid_trusted()
  - omemo_get_jid_untrusted_fingerprints() for better error messages
  - Fingerprint notifications on new device identity discovery
  - Deterministic pre-key ID generation tracking max_pre_key_id
  - omemo_trust_changed() UI updates on trust state changes

JID validation
  - RFC 6122-compliant validation in jid_is_valid()
  - Character-level checks (RFC 6122 forbidden chars: & ' / : < > @)
  - Length limits: 1023 per component, 3071 total
  - New jid_is_valid_user_jid() for user vs. service JID distinction

Database
  - Schema migration v3: UNIQUE constraint on archive_id for deduplication
  - Triggers for corrected message tracking (replaces_db_id / replaced_by_db_id)
  - db_history_result_t return type, _truncate_datetime_suffix()

UI / console
  - win_warn_needed() / win_warn_sent() warning deduplication hash table
  - PAD_MIN_HEIGHT dynamic pad sizing with PAD_THRESHOLD auto-cleanup
  - Spellcheck integration in input field with Unicode word detection
  - cons_spellcheck_setting() for /settings ui output
  - /[command]? shortcut for command help

Account config
  - Account name sanitization for GKeyFile special chars ([ ] = # \n \r)
  - Replace popen() with g_spawn_sync() for eval_password
  - TLS policy: add "direct" option alongside legacy

Connection
  - Port validation with g_assert (0–65535)
  - SHA-256 certificate fingerprint support (XMPP_CERT_PUBKEY_FINGERPRINT_SHA256)
  - "direct" TLS policy alias for legacy SSL

Common utilities
  - str_xml_sanitize() for XML 1.0 illegal character removal
  - string_matches_one_of() with formatted error messages
  - valid_tls_policy_option() helper
  - prof_date_time_format_iso8601() utility
  - Improved strip_arg_quotes() with backslash unescaping
  - prof_occurrences() uses g_slist_prepend + reverse for performance

PGP / OX
  - Proper GPGME resource cleanup with goto-cleanup pattern
  - g_string_free(xmppuri) leak fix in _ox_key_lookup

CSV export
  - Use GString + g_file_set_contents instead of raw write() syscalls

Tests
  - Restructured into subdirectories: command/, config/, xmpp/, ui/, omemo/, otr/, pgp/
  - New test_cmd_ac.c for autocompleter unit tests
  - Updated stubs for new UI suspend/resume functions

License headers
  - Migrate to SPDX-3.0 identifiers (GPL-3.0-or-later WITH OpenSSL-exception)

────────────────────────────────────────────────────
cproof-specific preservations:

  - XEP-0308 LMC: replace_id ?: id logic in message/stanza/omemo
  - Force encryption: cmd_force_encryption, test_forced_encryption
  - CWE-134: format string protection (cons_show("%s", ...))
  - y_start_pos-based paging in window.c
  - db_history_result_t return type, _truncate_datetime_suffix()

Merge-time fixes:

  - common.c: format-security (-Werror) — cons_show(errmsg) → cons_show("%s", errmsg)
  - database.c: null-deref guard — !msg->timestamp → msg && !msg->timestamp
  - console.c: implicit size_t → int cast — (int)(maxlen + 1)
  - tlscerts.c: %d for size_t — %zu

Build system:
  - Kept autotools (Makefile.am, configure.ac); upstream uses Meson
  - Restored deleted files: bootstrap.sh, autogen.sh, ax_valgrind_check.m4, configure-debug
  - Updated Makefile.am test paths for subdirectory structure
  - Added test_cmd_ac, test_forced_encryption to test sources

Functional tests:
  - Use cproof version; upstream requires stbbr_for_xmlns from updated stabber
  - Not yet available in devs/stabber fork

Closes #64

Merge author: jabber.developer2
Commits authors:
 Michael Vetter <jubalh@iodoru.org>
& Steffen Jaeckel <s@jaeckel.eu>
This commit is contained in:
2026-05-26 17:48:14 +00:00
parent 3b673150b4
commit 72f4f186da
303 changed files with 10658 additions and 9857 deletions

View File

@@ -215,7 +215,7 @@ sleep_ms(int ms)
* Read available data from fd into output_buffer with timeout.
* Returns number of bytes read, 0 on timeout, -1 on error.
*/
static int
static ssize_t
_read_output(int timeout_ms)
{
fd_set readfds;
@@ -232,17 +232,19 @@ _read_output(int timeout_ms)
return ret;
}
size_t space = OUTPUT_BUF_SIZE - output_len - 1;
if (space <= 0) {
/* Check size before subtracting so OUTPUT_BUF_SIZE - output_len - 1
* never goes negative / underflows. Reserves one byte for the
* trailing NUL. */
if (output_len >= OUTPUT_BUF_SIZE - 1) {
/* Buffer full, shift content */
memmove(output_buffer, output_buffer + OUTPUT_BUF_SIZE / 2, OUTPUT_BUF_SIZE / 2);
output_len = OUTPUT_BUF_SIZE / 2;
space = OUTPUT_BUF_SIZE - output_len - 1;
}
size_t space = OUTPUT_BUF_SIZE - output_len - 1;
ssize_t n = read(fd, output_buffer + output_len, space);
if (n > 0) {
output_len += n;
output_len += (size_t)n;
output_buffer[output_len] = '\0';
}
return n;

View File

@@ -0,0 +1,90 @@
/*
* test_i18n.c
*
* Copyright (C) 2026 Michael Vetter <jubalh@iodoru.org>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include <glib.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stabber.h>
#include "proftest.h"
void
i18n_msg_nickname(void** state)
{
// Connect with a roster containing a UTF-8 nickname: Σωκράτης (Socrates)
prof_connect_with_roster(
"<item jid='socrates@localhost' subscription='both' name='Σωκράτης'/>"
"<item jid='buddy2@localhost' subscription='both' name='Buddy2'/>");
// Test that we can /msg the UTF-8 nickname successfully.
// This verifies that the UI and command parsing handle UTF-8.
prof_input("/msg Σωκράτης Hello");
// Check if we switched to the socrates window
assert_true(prof_output_regex("socrates@localhost"));
}
void
i18n_win_nickname(void** state)
{
prof_connect_with_roster(
"<item jid='socrates@localhost' subscription='both' name='Σωκράτης'/>");
// Open a chat with Socrates
prof_input("/msg Σωκράτης");
assert_true(prof_output_regex("socrates@localhost"));
// Switch back to console
prof_input("/win 1");
assert_true(prof_output_regex("Console"));
// Switch to Socrates window using name
prof_input("/win Σωκράτης");
assert_true(prof_output_regex("socrates@localhost"));
}
void
i18n_autocomplete_tab_utf8(void** state)
{
prof_connect_with_roster(
"<item jid='socrates@localhost' subscription='both' name='Σωκράτης'/>");
prof_send_raw("/msg Σω");
// TAB for completion
prof_send_raw("\t");
prof_input(" Hello");
// If autocompletion worked, we should be in the Socrates window
assert_true(prof_output_regex("socrates@localhost"));
// And stabber should have received the message
assert_true(stbbr_received(
"<message to='socrates@localhost' id='*' type='chat'>"
"<body>Hello</body>"
"</message>"));
}
void
i18n_autocomplete_tab_latin(void** state)
{
prof_connect_with_roster(
"<item jid='plato@localhost' subscription='both' name='Plato'/>");
prof_send_raw("/msg Pl");
prof_send_raw("\t");
prof_input(" Hello");
assert_true(prof_output_regex("plato@localhost"));
assert_true(stbbr_received(
"<message to='plato@localhost' id='*' type='chat'>"
"<body>Hello</body>"
"</message>"));
}

View File

@@ -0,0 +1,11 @@
/*
* test_i18n.h
*
* Copyright (C) 2026 Michael Vetter <jubalh@iodoru.org>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
void i18n_msg_nickname(void** state);
void i18n_win_nickname(void** state);
void i18n_autocomplete_tab_utf8(void** state);
void i18n_autocomplete_tab_latin(void** state);

View File

@@ -33,7 +33,7 @@ send_receipt_request(void **state)
// Register disco#info response for capabilities query (receipts support)
stbbr_for_query("http://jabber.org/protocol/disco#info",
"<iq from='buddy1@localhost/laptop' to='stabber@localhost' id='*' type='result'>"
"<query xmlns='http://jabber.org/protocol/disco#info' node='http://profanity-im.github.io#hAkb1xZdJV9BQpgGNw8zG5Xsals='>"
"<query xmlns='http://jabber.org/protocol/disco#info' node='http://profanity-im.github.io#JNkIRQChhYM8+Co3IypmMtMJnOE='>"
"<identity category='client' name='Profanity 0.5.0' type='console'/>"
"<feature var='urn:xmpp:receipts'/>"
"</query>"
@@ -44,7 +44,7 @@ send_receipt_request(void **state)
"<presence to='stabber@localhost' from='buddy1@localhost/laptop'>"
"<priority>15</priority>"
"<status>My status</status>"
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://profanity-im.github.io' ver='hAkb1xZdJV9BQpgGNw8zG5Xsals='/>"
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://profanity-im.github.io' ver='JNkIRQChhYM8+Co3IypmMtMJnOE='/>"
"</presence>"
);

View File

@@ -3,21 +3,7 @@
*
* Copyright (C) 2012 - 2019 James Booth <boothj5@gmail.com>
*
* This file is part of Profanity.
*
* Profanity is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Profanity is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Profanity. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later WITH OpenSSL-exception
*/
#include <glib.h>

View File

@@ -0,0 +1,105 @@
#include <stdlib.h>
#include <glib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "prof_cmocka.h"
#include "command/cmd_ac.h"
static void
_create_test_file(const char* path)
{
FILE* f = fopen(path, "w");
if (f) {
fprintf(f, "test");
fclose(f);
}
}
void
cmd_ac_complete_filepath__no_segfault_when_empty(void** state)
{
char* result = cmd_ac_complete_filepath("/sendfile ", "/sendfile", FALSE);
free(result);
}
void
cmd_ac_complete_filepath__finds_files_in_current_dir(void** state)
{
mkdir("test_dir", 0755);
_create_test_file("test_dir/file1.txt");
_create_test_file("test_dir/file2.txt");
char* result = cmd_ac_complete_filepath("/sendfile test_dir/file", "/sendfile", FALSE);
assert_non_null(result);
assert_string_equal(result, "/sendfile test_dir/file1.txt");
free(result);
remove("test_dir/file1.txt");
remove("test_dir/file2.txt");
rmdir("test_dir");
}
void
cmd_ac_complete_filepath__finds_files_with_dot_slash(void** state)
{
mkdir("test_dir", 0755);
_create_test_file("test_dir/file1.txt");
char* result = cmd_ac_complete_filepath("/sendfile ./test_dir/file", "/sendfile", FALSE);
assert_non_null(result);
assert_string_equal(result, "/sendfile ./test_dir/file1.txt");
free(result);
remove("test_dir/file1.txt");
rmdir("test_dir");
}
void
cmd_ac_complete_filepath__cycles_through_files(void** state)
{
mkdir("test_dir", 0755);
_create_test_file("test_dir/file1.txt");
_create_test_file("test_dir/file2.txt");
_create_test_file("test_dir/file3.txt");
// TAB forward: file1 -> file2 -> file3
char* res1 = cmd_ac_complete_filepath("/sendfile test_dir/file", "/sendfile", FALSE);
assert_non_null(res1);
assert_string_equal(res1, "/sendfile test_dir/file1.txt");
char* res2 = cmd_ac_complete_filepath(res1, "/sendfile", FALSE);
assert_non_null(res2);
assert_string_equal(res2, "/sendfile test_dir/file2.txt");
char* res3 = cmd_ac_complete_filepath(res2, "/sendfile", FALSE);
assert_non_null(res3);
assert_string_equal(res3, "/sendfile test_dir/file3.txt");
// TAB wraps around: file3 -> file1
char* res4 = cmd_ac_complete_filepath(res3, "/sendfile", FALSE);
assert_non_null(res4);
assert_string_equal(res4, "/sendfile test_dir/file1.txt");
// SHIFT-TAB goes backward: file1 -> file3, then file3 -> file2
char* res5 = cmd_ac_complete_filepath(res4, "/sendfile", TRUE);
assert_non_null(res5);
assert_string_equal(res5, "/sendfile test_dir/file3.txt");
char* res6 = cmd_ac_complete_filepath(res5, "/sendfile", TRUE);
assert_non_null(res6);
assert_string_equal(res6, "/sendfile test_dir/file2.txt");
free(res1);
free(res2);
free(res3);
free(res4);
free(res5);
free(res6);
remove("test_dir/file1.txt");
remove("test_dir/file2.txt");
remove("test_dir/file3.txt");
rmdir("test_dir");
}

View File

@@ -0,0 +1,9 @@
#ifndef TESTS_TEST_CMD_AC_H
#define TESTS_TEST_CMD_AC_H
void cmd_ac_complete_filepath__no_segfault_when_empty(void** state);
void cmd_ac_complete_filepath__finds_files_in_current_dir(void** state);
void cmd_ac_complete_filepath__finds_files_with_dot_slash(void** state);
void cmd_ac_complete_filepath__cycles_through_files(void** state);
#endif

View File

@@ -15,7 +15,7 @@
#define CMD_ACCOUNT "/account"
void
cmd_account_shows_usage_when_not_connected_and_no_args(void** state)
cmd_account__shows__usage_when_not_connected_and_no_args(void** state)
{
gchar* args[] = { NULL };
@@ -28,7 +28,7 @@ cmd_account_shows_usage_when_not_connected_and_no_args(void** state)
}
void
cmd_account_shows_account_when_connected_and_no_args(void** state)
cmd_account__shows__account_when_connected_and_no_args(void** state)
{
ProfAccount* account = account_new(g_strdup("jabber_org"), g_strdup("me@jabber.org"), NULL, NULL,
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0);
@@ -46,14 +46,14 @@ cmd_account_shows_account_when_connected_and_no_args(void** state)
}
void
cmd_account_list_shows_accounts(void** state)
cmd_account_list__shows__accounts(void** state)
{
gchar* args[] = { "list", NULL };
gchar** accounts = malloc(sizeof(gchar*) * 4);
accounts[0] = strdup("account1");
accounts[1] = strdup("account2");
accounts[2] = strdup("account3");
gchar** accounts = g_new0(gchar*, 4);
accounts[0] = g_strdup("account1");
accounts[1] = g_strdup("account2");
accounts[2] = g_strdup("account3");
accounts[3] = NULL;
will_return(accounts_get_list, accounts);
@@ -65,7 +65,7 @@ cmd_account_list_shows_accounts(void** state)
}
void
cmd_account_show_shows_usage_when_no_arg(void** state)
cmd_account_show__shows__usage_when_no_arg(void** state)
{
gchar* args[] = { "show", NULL };
@@ -76,7 +76,7 @@ cmd_account_show_shows_usage_when_no_arg(void** state)
}
void
cmd_account_show_shows_message_when_account_does_not_exist(void** state)
cmd_account_show__shows__message_when_account_does_not_exist(void** state)
{
gchar* args[] = { "show", "account_name", NULL };
@@ -91,7 +91,7 @@ cmd_account_show_shows_message_when_account_does_not_exist(void** state)
}
void
cmd_account_show_shows_account_when_exists(void** state)
cmd_account_show__shows__account_when_exists(void** state)
{
gchar* args[] = { "show", "account_name", NULL };
ProfAccount* account = account_new(g_strdup("jabber_org"), g_strdup("me@jabber.org"), NULL, NULL,
@@ -107,7 +107,7 @@ cmd_account_show_shows_account_when_exists(void** state)
}
void
cmd_account_add_shows_usage_when_no_arg(void** state)
cmd_account_add__shows__usage_when_no_arg(void** state)
{
gchar* args[] = { "add", NULL };
@@ -118,7 +118,7 @@ cmd_account_add_shows_usage_when_no_arg(void** state)
}
void
cmd_account_add_adds_account(void** state)
cmd_account_add__updates__adds_account(void** state)
{
gchar* args[] = { "add", "new_account", NULL };
@@ -133,7 +133,7 @@ cmd_account_add_adds_account(void** state)
}
void
cmd_account_enable_shows_usage_when_no_arg(void** state)
cmd_account_enable__shows__usage_when_no_arg(void** state)
{
gchar* args[] = { "enable", NULL };
@@ -144,7 +144,7 @@ cmd_account_enable_shows_usage_when_no_arg(void** state)
}
void
cmd_account_enable_enables_account(void** state)
cmd_account_enable__updates__enables_account(void** state)
{
gchar* args[] = { "enable", "account_name", NULL };
@@ -159,7 +159,7 @@ cmd_account_enable_enables_account(void** state)
}
void
cmd_account_enable_shows_message_when_account_doesnt_exist(void** state)
cmd_account_enable__shows__message_when_account_doesnt_exist(void** state)
{
gchar* args[] = { "enable", "account_name", NULL };
@@ -174,7 +174,7 @@ cmd_account_enable_shows_message_when_account_doesnt_exist(void** state)
}
void
cmd_account_disable_shows_usage_when_no_arg(void** state)
cmd_account_disable__shows__usage_when_no_arg(void** state)
{
gchar* args[] = { "disable", NULL };
@@ -185,7 +185,7 @@ cmd_account_disable_shows_usage_when_no_arg(void** state)
}
void
cmd_account_disable_disables_account(void** state)
cmd_account_disable__updates__disables_account(void** state)
{
gchar* args[] = { "disable", "account_name", NULL };
@@ -200,7 +200,7 @@ cmd_account_disable_disables_account(void** state)
}
void
cmd_account_disable_shows_message_when_account_doesnt_exist(void** state)
cmd_account_disable__shows__message_when_account_doesnt_exist(void** state)
{
gchar* args[] = { "disable", "account_name", NULL };
@@ -215,7 +215,7 @@ cmd_account_disable_shows_message_when_account_doesnt_exist(void** state)
}
void
cmd_account_rename_shows_usage_when_no_args(void** state)
cmd_account_rename__shows__usage_when_no_args(void** state)
{
gchar* args[] = { "rename", NULL };
@@ -226,7 +226,7 @@ cmd_account_rename_shows_usage_when_no_args(void** state)
}
void
cmd_account_rename_shows_usage_when_one_arg(void** state)
cmd_account_rename__shows__usage_when_one_arg(void** state)
{
gchar* args[] = { "rename", "original_name", NULL };
@@ -237,7 +237,7 @@ cmd_account_rename_shows_usage_when_one_arg(void** state)
}
void
cmd_account_rename_renames_account(void** state)
cmd_account_rename__updates__renames_account(void** state)
{
gchar* args[] = { "rename", "original_name", "new_name", NULL };
@@ -253,7 +253,7 @@ cmd_account_rename_renames_account(void** state)
}
void
cmd_account_rename_shows_message_when_not_renamed(void** state)
cmd_account_rename__shows__message_when_not_renamed(void** state)
{
gchar* args[] = { "rename", "original_name", "new_name", NULL };
@@ -269,7 +269,7 @@ cmd_account_rename_shows_message_when_not_renamed(void** state)
}
void
cmd_account_set_shows_usage_when_no_args(void** state)
cmd_account_set__shows__usage_when_no_args(void** state)
{
gchar* args[] = { "set", NULL };
@@ -280,7 +280,7 @@ cmd_account_set_shows_usage_when_no_args(void** state)
}
void
cmd_account_set_shows_usage_when_one_arg(void** state)
cmd_account_set__shows__usage_when_one_arg(void** state)
{
gchar* args[] = { "set", "a_account", NULL };
@@ -291,7 +291,7 @@ cmd_account_set_shows_usage_when_one_arg(void** state)
}
void
cmd_account_set_shows_usage_when_two_args(void** state)
cmd_account_set__shows__usage_when_two_args(void** state)
{
gchar* args[] = { "set", "a_account", "a_property", NULL };
@@ -302,7 +302,7 @@ cmd_account_set_shows_usage_when_two_args(void** state)
}
void
cmd_account_set_shows_message_when_account_doesnt_exist(void** state)
cmd_account_set__shows__message_when_account_doesnt_exist(void** state)
{
gchar* args[] = { "set", "a_account", "a_property", "a_value", NULL };
@@ -317,7 +317,7 @@ cmd_account_set_shows_message_when_account_doesnt_exist(void** state)
}
void
cmd_account_set_jid_shows_message_for_malformed_jid(void** state)
cmd_account_set__shows__message_for_malformed_jid(void** state)
{
gchar* args[] = { "set", "a_account", "jid", "@malformed", NULL };
@@ -331,7 +331,7 @@ cmd_account_set_jid_shows_message_for_malformed_jid(void** state)
}
void
cmd_account_set_jid_sets_barejid(void** state)
cmd_account_set__updates__jid_sets_barejid(void** state)
{
gchar* args[] = { "set", "a_account", "jid", "a_local@a_domain", NULL };
@@ -349,7 +349,7 @@ cmd_account_set_jid_sets_barejid(void** state)
}
void
cmd_account_set_jid_sets_resource(void** state)
cmd_account_set__updates__jid_sets_resource(void** state)
{
gchar* args[] = { "set", "a_account", "jid", "a_local@a_domain/a_resource", NULL };
@@ -372,7 +372,7 @@ cmd_account_set_jid_sets_resource(void** state)
}
void
cmd_account_set_server_sets_server(void** state)
cmd_account_set__updates__server_sets_server(void** state)
{
gchar* args[] = { "set", "a_account", "server", "a_server", NULL };
@@ -390,7 +390,7 @@ cmd_account_set_server_sets_server(void** state)
}
void
cmd_account_set_resource_sets_resource(void** state)
cmd_account_set__updates__resource_sets_resource(void** state)
{
gchar* args[] = { "set", "a_account", "resource", "a_resource", NULL };
@@ -410,7 +410,7 @@ cmd_account_set_resource_sets_resource(void** state)
}
void
cmd_account_set_resource_sets_resource_with_online_message(void** state)
cmd_account_set__shows__resource_sets_resource_with_online_message(void** state)
{
gchar* args[] = { "set", "a_account", "resource", "a_resource", NULL };
@@ -430,7 +430,7 @@ cmd_account_set_resource_sets_resource_with_online_message(void** state)
}
void
cmd_account_set_password_sets_password(void** state)
cmd_account_set__updates__password_sets_password(void** state)
{
gchar* args[] = { "set", "a_account", "password", "a_password", NULL };
ProfAccount* account = account_new(g_strdup("a_account"), NULL, NULL, NULL,
@@ -453,7 +453,7 @@ cmd_account_set_password_sets_password(void** state)
}
void
cmd_account_set_eval_password_sets_eval_password(void** state)
cmd_account_set__updates__eval_password_sets_eval_password(void** state)
{
gchar* args[] = { "set", "a_account", "eval_password", "a_password", NULL };
ProfAccount* account = account_new(g_strdup("a_account"), NULL, NULL, NULL,
@@ -476,7 +476,7 @@ cmd_account_set_eval_password_sets_eval_password(void** state)
}
void
cmd_account_set_password_when_eval_password_set(void** state)
cmd_account_set__shows__password_when_eval_password_set(void** state)
{
gchar* args[] = { "set", "a_account", "password", "a_password", NULL };
ProfAccount* account = account_new(g_strdup("a_account"), NULL, NULL, g_strdup("a_password"),
@@ -495,7 +495,7 @@ cmd_account_set_password_when_eval_password_set(void** state)
}
void
cmd_account_set_eval_password_when_password_set(void** state)
cmd_account_set__shows__eval_password_when_password_set(void** state)
{
gchar* args[] = { "set", "a_account", "eval_password", "a_password", NULL };
ProfAccount* account = account_new(g_strdup("a_account"), NULL, g_strdup("a_password"), NULL,
@@ -514,7 +514,7 @@ cmd_account_set_eval_password_when_password_set(void** state)
}
void
cmd_account_set_muc_sets_muc(void** state)
cmd_account_set__updates__muc_sets_muc(void** state)
{
gchar* args[] = { "set", "a_account", "muc", "a_muc", NULL };
@@ -532,7 +532,7 @@ cmd_account_set_muc_sets_muc(void** state)
}
void
cmd_account_set_nick_sets_nick(void** state)
cmd_account_set__updates__nick_sets_nick(void** state)
{
gchar* args[] = { "set", "a_account", "nick", "a_nick", NULL };
@@ -550,7 +550,7 @@ cmd_account_set_nick_sets_nick(void** state)
}
void
cmd_account_show_message_for_missing_otr_policy(void** state)
cmd_account_set__shows__message_for_missing_otr_policy(void** state)
{
gchar* args[] = { "set", "a_account", "otr", NULL };
@@ -561,7 +561,7 @@ cmd_account_show_message_for_missing_otr_policy(void** state)
}
void
cmd_account_show_message_for_invalid_otr_policy(void** state)
cmd_account_set__shows__message_for_invalid_otr_policy(void** state)
{
gchar* args[] = { "set", "a_account", "otr", "bad_otr_policy", NULL };
@@ -576,7 +576,7 @@ cmd_account_show_message_for_invalid_otr_policy(void** state)
}
void
cmd_account_set_otr_sets_otr(void** state)
cmd_account_set__updates__otr_sets_otr(void** state)
{
gchar* args[] = { "set", "a_account", "otr", "opportunistic", NULL };
@@ -594,7 +594,7 @@ cmd_account_set_otr_sets_otr(void** state)
}
void
cmd_account_set_status_shows_message_when_invalid_status(void** state)
cmd_account_set__shows__message_when_invalid_status(void** state)
{
gchar* args[] = { "set", "a_account", "status", "bad_status", NULL };
@@ -609,7 +609,7 @@ cmd_account_set_status_shows_message_when_invalid_status(void** state)
}
void
cmd_account_set_status_sets_status_when_valid(void** state)
cmd_account_set__updates__status_sets_status_when_valid(void** state)
{
gchar* args[] = { "set", "a_account", "status", "away", NULL };
@@ -627,7 +627,7 @@ cmd_account_set_status_sets_status_when_valid(void** state)
}
void
cmd_account_set_status_sets_status_when_last(void** state)
cmd_account_set__updates__status_sets_status_when_last(void** state)
{
gchar* args[] = { "set", "a_account", "status", "last", NULL };
@@ -645,7 +645,7 @@ cmd_account_set_status_sets_status_when_last(void** state)
}
void
cmd_account_set_invalid_presence_string_priority_shows_message(void** state)
cmd_account_set__shows__invalid_presence_string_priority_message(void** state)
{
gchar* args[] = { "set", "a_account", "blah", "10", NULL };
@@ -660,7 +660,7 @@ cmd_account_set_invalid_presence_string_priority_shows_message(void** state)
}
void
cmd_account_set_last_priority_shows_message(void** state)
cmd_account_set__shows__last_priority_message(void** state)
{
gchar* args[] = { "set", "a_account", "last", "10", NULL };
@@ -675,7 +675,7 @@ cmd_account_set_last_priority_shows_message(void** state)
}
void
cmd_account_set_online_priority_sets_preference(void** state)
cmd_account_set__updates__online_priority_sets_preference(void** state)
{
gchar* args[] = { "set", "a_account", "online", "10", NULL };
@@ -695,7 +695,7 @@ cmd_account_set_online_priority_sets_preference(void** state)
}
void
cmd_account_set_chat_priority_sets_preference(void** state)
cmd_account_set__updates__chat_priority_sets_preference(void** state)
{
gchar* args[] = { "set", "a_account", "chat", "10", NULL };
@@ -715,7 +715,7 @@ cmd_account_set_chat_priority_sets_preference(void** state)
}
void
cmd_account_set_away_priority_sets_preference(void** state)
cmd_account_set__updates__away_priority_sets_preference(void** state)
{
gchar* args[] = { "set", "a_account", "away", "10", NULL };
@@ -735,7 +735,7 @@ cmd_account_set_away_priority_sets_preference(void** state)
}
void
cmd_account_set_xa_priority_sets_preference(void** state)
cmd_account_set__updates__xa_priority_sets_preference(void** state)
{
gchar* args[] = { "set", "a_account", "xa", "10", NULL };
@@ -755,7 +755,7 @@ cmd_account_set_xa_priority_sets_preference(void** state)
}
void
cmd_account_set_dnd_priority_sets_preference(void** state)
cmd_account_set__updates__dnd_priority_sets_preference(void** state)
{
gchar* args[] = { "set", "a_account", "dnd", "10", NULL };
@@ -775,7 +775,7 @@ cmd_account_set_dnd_priority_sets_preference(void** state)
}
void
cmd_account_set_priority_too_low_shows_message(void** state)
cmd_account_set__shows__priority_too_low_message(void** state)
{
gchar* args[] = { "set", "a_account", "online", "-150", NULL };
@@ -789,7 +789,7 @@ cmd_account_set_priority_too_low_shows_message(void** state)
}
void
cmd_account_set_priority_too_high_shows_message(void** state)
cmd_account_set__shows__priority_too_high_message(void** state)
{
gchar* args[] = { "set", "a_account", "online", "150", NULL };
@@ -803,7 +803,7 @@ cmd_account_set_priority_too_high_shows_message(void** state)
}
void
cmd_account_set_priority_when_not_number_shows_message(void** state)
cmd_account_set__shows__priority_when_not_number_message(void** state)
{
gchar* args[] = { "set", "a_account", "online", "abc", NULL };
@@ -817,7 +817,7 @@ cmd_account_set_priority_when_not_number_shows_message(void** state)
}
void
cmd_account_set_priority_when_empty_shows_message(void** state)
cmd_account_set__shows__priority_when_empty_message(void** state)
{
gchar* args[] = { "set", "a_account", "online", "", NULL };
@@ -831,7 +831,7 @@ cmd_account_set_priority_when_empty_shows_message(void** state)
}
void
cmd_account_set_priority_updates_presence_when_account_connected_with_presence(void** state)
cmd_account_set__updates__priority_updates_presence_when_connected(void** state)
{
gchar* args[] = { "set", "a_account", "online", "10", NULL };
@@ -868,7 +868,7 @@ cmd_account_set_priority_updates_presence_when_account_connected_with_presence(v
}
void
cmd_account_clear_shows_usage_when_no_args(void** state)
cmd_account_clear__shows__usage_when_no_args(void** state)
{
gchar* args[] = { "clear", NULL };
@@ -879,7 +879,7 @@ cmd_account_clear_shows_usage_when_no_args(void** state)
}
void
cmd_account_clear_shows_usage_when_one_arg(void** state)
cmd_account_clear__shows__usage_when_one_arg(void** state)
{
gchar* args[] = { "clear", "a_account", NULL };
@@ -890,7 +890,7 @@ cmd_account_clear_shows_usage_when_one_arg(void** state)
}
void
cmd_account_clear_shows_message_when_account_doesnt_exist(void** state)
cmd_account_clear__shows__message_when_account_doesnt_exist(void** state)
{
gchar* args[] = { "clear", "a_account", "a_property", NULL };
@@ -905,7 +905,7 @@ cmd_account_clear_shows_message_when_account_doesnt_exist(void** state)
}
void
cmd_account_clear_shows_message_when_invalid_property(void** state)
cmd_account_clear__shows__message_when_invalid_property(void** state)
{
gchar* args[] = { "clear", "a_account", "badproperty", NULL };

View File

@@ -0,0 +1,61 @@
#ifndef TESTS_TEST_CMD_ACCOUNT_H
#define TESTS_TEST_CMD_ACCOUNT_H
void cmd_account__shows__usage_when_not_connected_and_no_args(void** state);
void cmd_account__shows__account_when_connected_and_no_args(void** state);
void cmd_account_list__shows__accounts(void** state);
void cmd_account_show__shows__usage_when_no_arg(void** state);
void cmd_account_show__shows__message_when_account_does_not_exist(void** state);
void cmd_account_show__shows__account_when_exists(void** state);
void cmd_account_add__shows__usage_when_no_arg(void** state);
void cmd_account_add__updates__adds_account(void** state);
void cmd_account_enable__shows__usage_when_no_arg(void** state);
void cmd_account_enable__updates__enables_account(void** state);
void cmd_account_enable__shows__message_when_account_doesnt_exist(void** state);
void cmd_account_disable__shows__usage_when_no_arg(void** state);
void cmd_account_disable__updates__disables_account(void** state);
void cmd_account_disable__shows__message_when_account_doesnt_exist(void** state);
void cmd_account_rename__shows__usage_when_no_args(void** state);
void cmd_account_rename__shows__usage_when_one_arg(void** state);
void cmd_account_rename__updates__renames_account(void** state);
void cmd_account_rename__shows__message_when_not_renamed(void** state);
void cmd_account_set__shows__usage_when_no_args(void** state);
void cmd_account_set__shows__usage_when_one_arg(void** state);
void cmd_account_set__shows__usage_when_two_args(void** state);
void cmd_account_set__shows__message_when_account_doesnt_exist(void** state);
void cmd_account_set__shows__message_for_malformed_jid(void** state);
void cmd_account_set__updates__jid_sets_barejid(void** state);
void cmd_account_set__updates__jid_sets_resource(void** state);
void cmd_account_set__updates__server_sets_server(void** state);
void cmd_account_set__updates__resource_sets_resource(void** state);
void cmd_account_set__shows__resource_sets_resource_with_online_message(void** state);
void cmd_account_set__updates__password_sets_password(void** state);
void cmd_account_set__updates__eval_password_sets_eval_password(void** state);
void cmd_account_set__shows__password_when_eval_password_set(void** state);
void cmd_account_set__shows__eval_password_when_password_set(void** state);
void cmd_account_set__updates__muc_sets_muc(void** state);
void cmd_account_set__updates__nick_sets_nick(void** state);
void cmd_account_set__shows__message_for_missing_otr_policy(void** state);
void cmd_account_set__shows__message_for_invalid_otr_policy(void** state);
void cmd_account_set__updates__otr_sets_otr(void** state);
void cmd_account_set__shows__message_when_invalid_status(void** state);
void cmd_account_set__updates__status_sets_status_when_valid(void** state);
void cmd_account_set__updates__status_sets_status_when_last(void** state);
void cmd_account_set__shows__invalid_presence_string_priority_message(void** state);
void cmd_account_set__shows__last_priority_message(void** state);
void cmd_account_set__updates__online_priority_sets_preference(void** state);
void cmd_account_set__updates__chat_priority_sets_preference(void** state);
void cmd_account_set__updates__away_priority_sets_preference(void** state);
void cmd_account_set__updates__xa_priority_sets_preference(void** state);
void cmd_account_set__updates__dnd_priority_sets_preference(void** state);
void cmd_account_set__shows__priority_too_low_message(void** state);
void cmd_account_set__shows__priority_too_high_message(void** state);
void cmd_account_set__shows__priority_when_not_number_message(void** state);
void cmd_account_set__shows__priority_when_empty_message(void** state);
void cmd_account_set__updates__priority_updates_presence_when_connected(void** state);
void cmd_account_clear__shows__usage_when_no_args(void** state);
void cmd_account_clear__shows__usage_when_one_arg(void** state);
void cmd_account_clear__shows__message_when_account_doesnt_exist(void** state);
void cmd_account_clear__shows__message_when_invalid_property(void** state);
#endif

View File

@@ -17,7 +17,7 @@
#define CMD_ALIAS "/alias"
void
cmd_alias_add_shows_usage_when_no_args(void** state)
cmd_alias__shows__usage_when_add_no_args(void** state)
{
gchar* args[] = { "add", NULL };
@@ -28,7 +28,7 @@ cmd_alias_add_shows_usage_when_no_args(void** state)
}
void
cmd_alias_add_shows_usage_when_no_value(void** state)
cmd_alias__shows__usage_when_add_no_value(void** state)
{
gchar* args[] = { "add", "alias", NULL };
@@ -39,7 +39,7 @@ cmd_alias_add_shows_usage_when_no_value(void** state)
}
void
cmd_alias_remove_shows_usage_when_no_args(void** state)
cmd_alias__shows__usage_when_remove_no_args(void** state)
{
gchar* args[] = { "remove", NULL };
@@ -50,7 +50,7 @@ cmd_alias_remove_shows_usage_when_no_args(void** state)
}
void
cmd_alias_show_usage_when_invalid_subcmd(void** state)
cmd_alias__shows__usage_when_invalid_subcmd(void** state)
{
gchar* args[] = { "blah", NULL };
@@ -61,7 +61,7 @@ cmd_alias_show_usage_when_invalid_subcmd(void** state)
}
void
cmd_alias_add_adds_alias(void** state)
cmd_alias__updates__adds_alias(void** state)
{
gchar* args[] = { "add", "hc", "/help commands", NULL };
@@ -73,11 +73,11 @@ cmd_alias_add_adds_alias(void** state)
gchar* returned_val = prefs_get_alias("hc");
assert_string_equal("/help commands", returned_val);
free(returned_val);
g_free(returned_val);
}
void
cmd_alias_add_shows_message_when_exists(void** state)
cmd_alias__shows__message_when_add_exists(void** state)
{
gchar* args[] = { "add", "hc", "/help commands", NULL };
@@ -91,7 +91,7 @@ cmd_alias_add_shows_message_when_exists(void** state)
}
void
cmd_alias_remove_removes_alias(void** state)
cmd_alias__updates__removes_alias(void** state)
{
gchar* args[] = { "remove", "hn", NULL };
@@ -105,11 +105,11 @@ cmd_alias_remove_removes_alias(void** state)
gchar* returned_val = prefs_get_alias("hn");
assert_null(returned_val);
free(returned_val);
g_free(returned_val);
}
void
cmd_alias_remove_shows_message_when_no_alias(void** state)
cmd_alias__shows__message_when_remove_no_alias(void** state)
{
gchar* args[] = { "remove", "hn", NULL };
@@ -120,7 +120,7 @@ cmd_alias_remove_shows_message_when_no_alias(void** state)
}
void
cmd_alias_list_shows_all_aliases(void** state)
cmd_alias__shows__all_aliases(void** state)
{
gchar* args[] = { "list", NULL };

View File

@@ -0,0 +1,14 @@
#ifndef TESTS_TEST_CMD_ALIAS_H
#define TESTS_TEST_CMD_ALIAS_H
void cmd_alias__shows__usage_when_add_no_args(void** state);
void cmd_alias__shows__usage_when_add_no_value(void** state);
void cmd_alias__shows__usage_when_remove_no_args(void** state);
void cmd_alias__shows__usage_when_invalid_subcmd(void** state);
void cmd_alias__updates__adds_alias(void** state);
void cmd_alias__shows__message_when_add_exists(void** state);
void cmd_alias__updates__removes_alias(void** state);
void cmd_alias__shows__message_when_remove_no_alias(void** state);
void cmd_alias__shows__all_aliases(void** state);
#endif

View File

@@ -32,25 +32,25 @@ test_with_connection_status(jabber_conn_status_t status)
}
void
cmd_bookmark_shows_message_when_disconnected(void** state)
cmd_bookmark__shows__message_when_disconnected(void** state)
{
test_with_connection_status(JABBER_DISCONNECTED);
}
void
cmd_bookmark_shows_message_when_disconnecting(void** state)
cmd_bookmark__shows__message_when_disconnecting(void** state)
{
test_with_connection_status(JABBER_DISCONNECTING);
}
void
cmd_bookmark_shows_message_when_connecting(void** state)
cmd_bookmark__shows__message_when_connecting(void** state)
{
test_with_connection_status(JABBER_CONNECTING);
}
void
cmd_bookmark_shows_usage_when_no_args(void** state)
cmd_bookmark__shows__usage_when_no_args(void** state)
{
gchar* args[] = { NULL };
ProfWin window;
@@ -90,30 +90,30 @@ _cmp_bookmark(Bookmark* bm1, Bookmark* bm2)
}
void
cmd_bookmark_list_shows_bookmarks(void** state)
cmd_bookmark_list__shows__bookmarks(void** state)
{
gchar* args[] = { "list", NULL };
GList* bookmarks = NULL;
ProfWin window;
window.type = WIN_CONSOLE;
Bookmark* bm1 = malloc(sizeof(Bookmark));
Bookmark* bm1 = g_new0(Bookmark, 1);
bm1->barejid = strdup("room1@conf.org");
bm1->nick = strdup("bob");
bm1->autojoin = FALSE;
Bookmark* bm2 = malloc(sizeof(Bookmark));
Bookmark* bm2 = g_new0(Bookmark, 1);
bm2->barejid = strdup("room2@conf.org");
bm2->nick = strdup("steve");
bm2->autojoin = TRUE;
Bookmark* bm3 = malloc(sizeof(Bookmark));
Bookmark* bm3 = g_new0(Bookmark, 1);
bm3->barejid = strdup("room3@conf.org");
bm3->nick = strdup("dave");
bm3->autojoin = TRUE;
Bookmark* bm4 = malloc(sizeof(Bookmark));
Bookmark* bm4 = g_new0(Bookmark, 1);
bm4->barejid = strdup("room4@conf.org");
bm4->nick = strdup("james");
bm4->autojoin = FALSE;
Bookmark* bm5 = malloc(sizeof(Bookmark));
Bookmark* bm5 = g_new0(Bookmark, 1);
bm5->barejid = strdup("room5@conf.org");
bm5->nick = strdup("mike");
bm5->autojoin = FALSE;
@@ -152,7 +152,7 @@ cmd_bookmark_list_shows_bookmarks(void** state)
}
void
cmd_bookmark_add_shows_message_when_invalid_jid(void** state)
cmd_bookmark_add__shows__message_when_invalid_jid(void** state)
{
char* jid = "room";
gchar* args[] = { "add", jid, NULL };
@@ -169,7 +169,7 @@ cmd_bookmark_add_shows_message_when_invalid_jid(void** state)
}
void
cmd_bookmark_add_adds_bookmark_with_jid(void** state)
cmd_bookmark_add__updates__bookmark_with_jid(void** state)
{
char* jid = "room@conf.server";
gchar* args[] = { "add", jid, NULL };
@@ -191,7 +191,7 @@ cmd_bookmark_add_adds_bookmark_with_jid(void** state)
}
void
cmd_bookmark_uses_roomjid_in_room(void** state)
cmd_bookmark__tests__uses_roomjid_in_room(void** state)
{
gchar* args[] = { NULL };
ProfMucWin muc_win;
@@ -214,7 +214,7 @@ cmd_bookmark_uses_roomjid_in_room(void** state)
}
void
cmd_bookmark_add_uses_roomjid_in_room(void** state)
cmd_bookmark_add__tests__uses_roomjid_in_room(void** state)
{
gchar* args[] = { "add", NULL };
ProfMucWin muc_win;
@@ -237,7 +237,7 @@ cmd_bookmark_add_uses_roomjid_in_room(void** state)
}
void
cmd_bookmark_add_uses_supplied_jid_in_room(void** state)
cmd_bookmark_add__tests__uses_supplied_jid_in_room(void** state)
{
char* jid = "room1@conf.server";
gchar* args[] = { "add", jid, NULL };
@@ -261,7 +261,7 @@ cmd_bookmark_add_uses_supplied_jid_in_room(void** state)
}
void
cmd_bookmark_add_adds_bookmark_with_jid_nick(void** state)
cmd_bookmark_add__updates__bookmark_with_jid_nick(void** state)
{
char* jid = "room@conf.server";
char* nick = "bob";
@@ -284,7 +284,7 @@ cmd_bookmark_add_adds_bookmark_with_jid_nick(void** state)
}
void
cmd_bookmark_add_adds_bookmark_with_jid_autojoin(void** state)
cmd_bookmark_add__updates__bookmark_with_jid_autojoin(void** state)
{
char* jid = "room@conf.server";
gchar* args[] = { "add", jid, "autojoin", "on", NULL };
@@ -306,7 +306,7 @@ cmd_bookmark_add_adds_bookmark_with_jid_autojoin(void** state)
}
void
cmd_bookmark_add_adds_bookmark_with_jid_nick_autojoin(void** state)
cmd_bookmark_add__updates__bookmark_with_jid_nick_autojoin(void** state)
{
char* jid = "room@conf.server";
char* nick = "bob";
@@ -329,7 +329,7 @@ cmd_bookmark_add_adds_bookmark_with_jid_nick_autojoin(void** state)
}
void
cmd_bookmark_remove_removes_bookmark(void** state)
cmd_bookmark_remove__updates__removes_bookmark(void** state)
{
char* jid = "room@conf.server";
gchar* args[] = { "remove", jid, NULL };
@@ -348,7 +348,7 @@ cmd_bookmark_remove_removes_bookmark(void** state)
}
void
cmd_bookmark_remove_shows_message_when_no_bookmark(void** state)
cmd_bookmark_remove__shows__message_when_no_bookmark(void** state)
{
char* jid = "room@conf.server";
gchar* args[] = { "remove", jid, NULL };
@@ -367,7 +367,7 @@ cmd_bookmark_remove_shows_message_when_no_bookmark(void** state)
}
void
cmd_bookmark_remove_uses_roomjid_in_room(void** state)
cmd_bookmark_remove__tests__uses_roomjid_in_room(void** state)
{
gchar* args[] = { "remove", NULL };
ProfMucWin muc_win;
@@ -387,7 +387,7 @@ cmd_bookmark_remove_uses_roomjid_in_room(void** state)
}
void
cmd_bookmark_remove_uses_supplied_jid_in_room(void** state)
cmd_bookmark_remove__tests__uses_supplied_jid_in_room(void** state)
{
char* jid = "room1@conf.server";
gchar* args[] = { "remove", jid, NULL };

View File

@@ -0,0 +1,23 @@
#ifndef TESTS_TEST_CMD_BOOKMARK_H
#define TESTS_TEST_CMD_BOOKMARK_H
void cmd_bookmark__shows__message_when_disconnected(void** state);
void cmd_bookmark__shows__message_when_disconnecting(void** state);
void cmd_bookmark__shows__message_when_connecting(void** state);
void cmd_bookmark__shows__message_when_undefined(void** state);
void cmd_bookmark__shows__usage_when_no_args(void** state);
void cmd_bookmark_list__shows__bookmarks(void** state);
void cmd_bookmark_add__shows__message_when_invalid_jid(void** state);
void cmd_bookmark_add__updates__bookmark_with_jid(void** state);
void cmd_bookmark__tests__uses_roomjid_in_room(void** state);
void cmd_bookmark_add__tests__uses_roomjid_in_room(void** state);
void cmd_bookmark_add__tests__uses_supplied_jid_in_room(void** state);
void cmd_bookmark_remove__tests__uses_roomjid_in_room(void** state);
void cmd_bookmark_remove__tests__uses_supplied_jid_in_room(void** state);
void cmd_bookmark_add__updates__bookmark_with_jid_nick(void** state);
void cmd_bookmark_add__updates__bookmark_with_jid_autojoin(void** state);
void cmd_bookmark_add__updates__bookmark_with_jid_nick_autojoin(void** state);
void cmd_bookmark_remove__updates__removes_bookmark(void** state);
void cmd_bookmark_remove__shows__message_when_no_bookmark(void** state);
#endif

View File

@@ -25,25 +25,25 @@ test_with_connection_status(jabber_conn_status_t status)
}
void
cmd_connect_shows_message_when_disconnecting(void** state)
cmd_connect__shows__message_when_disconnecting(void** state)
{
test_with_connection_status(JABBER_DISCONNECTING);
}
void
cmd_connect_shows_message_when_connecting(void** state)
cmd_connect__shows__message_when_connecting(void** state)
{
test_with_connection_status(JABBER_CONNECTING);
}
void
cmd_connect_shows_message_when_connected(void** state)
cmd_connect__shows__message_when_connected(void** state)
{
test_with_connection_status(JABBER_CONNECTED);
}
void
cmd_connect_when_no_account(void** state)
cmd_connect__tests__no_account(void** state)
{
gchar* args[] = { "user@server.org", NULL };
@@ -52,7 +52,7 @@ cmd_connect_when_no_account(void** state)
expect_string(accounts_get_account, name, "user@server.org");
will_return(accounts_get_account, NULL);
will_return(ui_ask_password, strdup("password"));
will_return(ui_ask_password, g_strdup("password"));
expect_cons_show("Connecting as user@server.org");
@@ -67,7 +67,7 @@ cmd_connect_when_no_account(void** state)
}
void
cmd_connect_fail_message(void** state)
cmd_connect__shows__fail_message(void** state)
{
gchar* args[] = { "user@server.org", NULL };
@@ -76,7 +76,7 @@ cmd_connect_fail_message(void** state)
expect_any(accounts_get_account, name);
will_return(accounts_get_account, NULL);
will_return(ui_ask_password, strdup("password"));
will_return(ui_ask_password, g_strdup("password"));
expect_cons_show("Connecting as user@server.org");
@@ -93,7 +93,7 @@ cmd_connect_fail_message(void** state)
}
void
cmd_connect_lowercases_argument_with_no_account(void** state)
cmd_connect__tests__lowercases_argument_with_no_account(void** state)
{
gchar* args[] = { "USER@server.ORG", NULL };
@@ -102,7 +102,7 @@ cmd_connect_lowercases_argument_with_no_account(void** state)
expect_string(accounts_get_account, name, "USER@server.ORG");
will_return(accounts_get_account, NULL);
will_return(ui_ask_password, strdup("password"));
will_return(ui_ask_password, g_strdup("password"));
expect_cons_show("Connecting as user@server.org");
@@ -117,7 +117,7 @@ cmd_connect_lowercases_argument_with_no_account(void** state)
}
void
cmd_connect_lowercases_argument_with_account(void** state)
cmd_connect__tests__lowercases_argument_with_account(void** state)
{
gchar* args[] = { "Jabber_org", NULL };
ProfAccount* account = account_new(g_strdup("Jabber_org"), g_strdup("me@jabber.org"), g_strdup("password"), NULL,
@@ -130,7 +130,7 @@ cmd_connect_lowercases_argument_with_account(void** state)
expect_cons_show("Connecting with account Jabber_org as me@jabber.org");
expect_memory(session_connect_with_account, account, account, sizeof(account));
expect_memory(session_connect_with_account, account, account, sizeof(ProfAccount));
will_return(session_connect_with_account, JABBER_CONNECTING);
gboolean result = cmd_connect(NULL, CMD_CONNECT, args);
@@ -138,7 +138,7 @@ cmd_connect_lowercases_argument_with_account(void** state)
}
void
cmd_connect_asks_password_when_not_in_account(void** state)
cmd_connect__tests__asks_password_when_not_in_account(void** state)
{
gchar* args[] = { "jabber_org", NULL };
ProfAccount* account = account_new(g_strdup("jabber_org"), g_strdup("me@jabber.org"), NULL, NULL,
@@ -149,7 +149,7 @@ cmd_connect_asks_password_when_not_in_account(void** state)
expect_any(accounts_get_account, name);
will_return(accounts_get_account, account);
will_return(ui_ask_password, strdup("password"));
will_return(ui_ask_password, g_strdup("password"));
expect_cons_show("Connecting with account jabber_org as me@jabber.org");
@@ -161,7 +161,7 @@ cmd_connect_asks_password_when_not_in_account(void** state)
}
void
cmd_connect_shows_usage_when_no_server_value(void** state)
cmd_connect__shows__usage_when_no_server_value(void** state)
{
gchar* args[] = { "user@server.org", "server", NULL };
@@ -175,7 +175,7 @@ cmd_connect_shows_usage_when_no_server_value(void** state)
}
void
cmd_connect_shows_usage_when_server_no_port_value(void** state)
cmd_connect__shows__usage_when_server_no_port_value(void** state)
{
gchar* args[] = { "user@server.org", "server", "aserver", "port", NULL };
@@ -189,7 +189,7 @@ cmd_connect_shows_usage_when_server_no_port_value(void** state)
}
void
cmd_connect_shows_usage_when_no_port_value(void** state)
cmd_connect__shows__usage_when_no_port_value(void** state)
{
gchar* args[] = { "user@server.org", "port", NULL };
@@ -203,7 +203,7 @@ cmd_connect_shows_usage_when_no_port_value(void** state)
}
void
cmd_connect_shows_usage_when_port_no_server_value(void** state)
cmd_connect__shows__usage_when_port_no_server_value(void** state)
{
gchar* args[] = { "user@server.org", "port", "5678", "server", NULL };
@@ -217,7 +217,7 @@ cmd_connect_shows_usage_when_port_no_server_value(void** state)
}
void
cmd_connect_shows_message_when_port_0(void** state)
cmd_connect__shows__message_when_port_0(void** state)
{
gchar* args[] = { "user@server.org", "port", "0", NULL };
@@ -231,7 +231,7 @@ cmd_connect_shows_message_when_port_0(void** state)
}
void
cmd_connect_shows_message_when_port_minus1(void** state)
cmd_connect__shows__message_when_port_minus1(void** state)
{
gchar* args[] = { "user@server.org", "port", "-1", NULL };
@@ -245,7 +245,7 @@ cmd_connect_shows_message_when_port_minus1(void** state)
}
void
cmd_connect_shows_message_when_port_65536(void** state)
cmd_connect__shows__message_when_port_65536(void** state)
{
gchar* args[] = { "user@server.org", "port", "65536", NULL };
@@ -259,7 +259,7 @@ cmd_connect_shows_message_when_port_65536(void** state)
}
void
cmd_connect_shows_message_when_port_contains_chars(void** state)
cmd_connect__shows__message_when_port_contains_chars(void** state)
{
gchar* args[] = { "user@server.org", "port", "52f66", NULL };
@@ -273,7 +273,7 @@ cmd_connect_shows_message_when_port_contains_chars(void** state)
}
void
cmd_connect_shows_usage_when_server_provided_twice(void** state)
cmd_connect__shows__usage_when_server_provided_twice(void** state)
{
gchar* args[] = { "user@server.org", "server", "server1", "server", "server2", NULL };
@@ -287,7 +287,7 @@ cmd_connect_shows_usage_when_server_provided_twice(void** state)
}
void
cmd_connect_shows_usage_when_port_provided_twice(void** state)
cmd_connect__shows__usage_when_port_provided_twice(void** state)
{
gchar* args[] = { "user@server.org", "port", "1111", "port", "1111", NULL };
@@ -301,7 +301,7 @@ cmd_connect_shows_usage_when_port_provided_twice(void** state)
}
void
cmd_connect_shows_usage_when_invalid_first_property(void** state)
cmd_connect__shows__usage_when_invalid_first_property(void** state)
{
gchar* args[] = { "user@server.org", "wrong", "server", NULL };
@@ -315,7 +315,7 @@ cmd_connect_shows_usage_when_invalid_first_property(void** state)
}
void
cmd_connect_shows_usage_when_invalid_second_property(void** state)
cmd_connect__shows__usage_when_invalid_second_property(void** state)
{
gchar* args[] = { "user@server.org", "server", "aserver", "wrong", "1234", NULL };
@@ -329,7 +329,7 @@ cmd_connect_shows_usage_when_invalid_second_property(void** state)
}
void
cmd_connect_with_server_when_provided(void** state)
cmd_connect__tests__with_server_when_provided(void** state)
{
gchar* args[] = { "user@server.org", "server", "aserver", NULL };
@@ -338,7 +338,7 @@ cmd_connect_with_server_when_provided(void** state)
expect_string(accounts_get_account, name, "user@server.org");
will_return(accounts_get_account, NULL);
will_return(ui_ask_password, strdup("password"));
will_return(ui_ask_password, g_strdup("password"));
expect_cons_show("Connecting as user@server.org");
@@ -353,7 +353,7 @@ cmd_connect_with_server_when_provided(void** state)
}
void
cmd_connect_with_port_when_provided(void** state)
cmd_connect__tests__with_port_when_provided(void** state)
{
gchar* args[] = { "user@server.org", "port", "5432", NULL };
@@ -362,7 +362,7 @@ cmd_connect_with_port_when_provided(void** state)
expect_string(accounts_get_account, name, "user@server.org");
will_return(accounts_get_account, NULL);
will_return(ui_ask_password, strdup("password"));
will_return(ui_ask_password, g_strdup("password"));
expect_cons_show("Connecting as user@server.org");
@@ -377,7 +377,7 @@ cmd_connect_with_port_when_provided(void** state)
}
void
cmd_connect_with_server_and_port_when_provided(void** state)
cmd_connect__tests__with_server_and_port_when_provided(void** state)
{
gchar* args[] = { "user@server.org", "port", "5432", "server", "aserver", NULL };
@@ -386,7 +386,7 @@ cmd_connect_with_server_and_port_when_provided(void** state)
expect_string(accounts_get_account, name, "user@server.org");
will_return(accounts_get_account, NULL);
will_return(ui_ask_password, strdup("password"));
will_return(ui_ask_password, g_strdup("password"));
expect_cons_show("Connecting as user@server.org");
@@ -401,7 +401,7 @@ cmd_connect_with_server_and_port_when_provided(void** state)
}
void
cmd_connect_shows_message_when_connecting_with_account(void** state)
cmd_connect__shows__message_when_connecting_with_account(void** state)
{
gchar* args[] = { "jabber_org", NULL };
ProfAccount* account = account_new(g_strdup("jabber_org"), g_strdup("user@jabber.org"), g_strdup("password"), NULL,
@@ -422,7 +422,7 @@ cmd_connect_shows_message_when_connecting_with_account(void** state)
}
void
cmd_connect_connects_with_account(void** state)
cmd_connect__tests__connects_with_account(void** state)
{
gchar* args[] = { "jabber_org", NULL };
ProfAccount* account = account_new(g_strdup("jabber_org"), g_strdup("me@jabber.org"), g_strdup("password"), NULL,
@@ -435,7 +435,7 @@ cmd_connect_connects_with_account(void** state)
expect_cons_show("Connecting with account jabber_org as me@jabber.org");
expect_memory(session_connect_with_account, account, account, sizeof(account));
expect_memory(session_connect_with_account, account, account, sizeof(ProfAccount));
will_return(session_connect_with_account, JABBER_CONNECTING);
gboolean result = cmd_connect(NULL, CMD_CONNECT, args);

View File

@@ -0,0 +1,32 @@
#ifndef TESTS_TEST_CMD_CONNECT_H
#define TESTS_TEST_CMD_CONNECT_H
void cmd_connect__shows__message_when_disconnecting(void** state);
void cmd_connect__shows__message_when_connecting(void** state);
void cmd_connect__shows__message_when_connected(void** state);
void cmd_connect__shows__message_when_undefined(void** state);
void cmd_connect__tests__no_account(void** state);
void cmd_connect__tests__with_altdomain_when_provided(void** state);
void cmd_connect__shows__fail_message(void** state);
void cmd_connect__tests__lowercases_argument_with_no_account(void** state);
void cmd_connect__tests__lowercases_argument_with_account(void** state);
void cmd_connect__tests__asks_password_when_not_in_account(void** state);
void cmd_connect__shows__message_when_connecting_with_account(void** state);
void cmd_connect__tests__connects_with_account(void** state);
void cmd_connect__shows__usage_when_no_server_value(void** state);
void cmd_connect__shows__usage_when_server_no_port_value(void** state);
void cmd_connect__shows__usage_when_no_port_value(void** state);
void cmd_connect__shows__usage_when_port_no_server_value(void** state);
void cmd_connect__shows__message_when_port_0(void** state);
void cmd_connect__shows__message_when_port_minus1(void** state);
void cmd_connect__shows__message_when_port_65536(void** state);
void cmd_connect__shows__message_when_port_contains_chars(void** state);
void cmd_connect__tests__with_server_when_provided(void** state);
void cmd_connect__tests__with_port_when_provided(void** state);
void cmd_connect__tests__with_server_and_port_when_provided(void** state);
void cmd_connect__shows__usage_when_server_provided_twice(void** state);
void cmd_connect__shows__usage_when_port_provided_twice(void** state);
void cmd_connect__shows__usage_when_invalid_first_property(void** state);
void cmd_connect__shows__usage_when_invalid_second_property(void** state);
#endif

View File

@@ -12,7 +12,7 @@
#define CMD_DISCONNECT "/disconnect"
void
clears_chat_sessions(void** state)
cmd_disconnect__updates__clears_chat_sessions(void** state)
{
chat_sessions_init();
roster_create();

View File

@@ -0,0 +1,6 @@
#ifndef TESTS_TEST_CMD_DISCONNECT_H
#define TESTS_TEST_CMD_DISCONNECT_H
void cmd_disconnect__updates__clears_chat_sessions(void** state);
#endif

View File

@@ -27,25 +27,25 @@ test_with_connection_status(jabber_conn_status_t status)
}
void
cmd_join_shows_message_when_disconnecting(void** state)
cmd_join__shows__message_when_disconnecting(void** state)
{
test_with_connection_status(JABBER_DISCONNECTING);
}
void
cmd_join_shows_message_when_connecting(void** state)
cmd_join__shows__message_when_connecting(void** state)
{
test_with_connection_status(JABBER_CONNECTING);
}
void
cmd_join_shows_message_when_disconnected(void** state)
cmd_join__shows__message_when_disconnected(void** state)
{
test_with_connection_status(JABBER_DISCONNECTED);
}
void
cmd_join_shows_error_message_when_invalid_room_jid(void** state)
cmd_join__shows__error_message_when_invalid_room_jid(void** state)
{
gchar* args[] = { "//@@/", NULL };
@@ -59,7 +59,7 @@ cmd_join_shows_error_message_when_invalid_room_jid(void** state)
}
void
cmd_join_uses_account_mucservice_when_no_service_specified(void** state)
cmd_join__tests__uses_account_mucservice_when_no_service_specified(void** state)
{
gchar* account_name = g_strdup("an_account");
char* room = "room";
@@ -85,7 +85,7 @@ cmd_join_uses_account_mucservice_when_no_service_specified(void** state)
}
void
cmd_join_uses_supplied_nick(void** state)
cmd_join__tests__uses_supplied_nick(void** state)
{
gchar* account_name = g_strdup("an_account");
char* room = "room@conf.server.org";
@@ -109,7 +109,7 @@ cmd_join_uses_supplied_nick(void** state)
}
void
cmd_join_uses_account_nick_when_not_supplied(void** state)
cmd_join__tests__uses_account_nick_when_not_supplied(void** state)
{
gchar* account_name = g_strdup("an_account");
char* room = "room2@conf.server.org";
@@ -133,7 +133,7 @@ cmd_join_uses_account_nick_when_not_supplied(void** state)
}
void
cmd_join_uses_password_when_supplied(void** state)
cmd_join__tests__uses_password_when_supplied(void** state)
{
gchar* account_name = g_strdup("an_account");
char* room = "room";

View File

@@ -0,0 +1,14 @@
#ifndef TESTS_TEST_CMD_JOIN_H
#define TESTS_TEST_CMD_JOIN_H
void cmd_join__shows__message_when_disconnecting(void** state);
void cmd_join__shows__message_when_connecting(void** state);
void cmd_join__shows__message_when_disconnected(void** state);
void cmd_join__shows__message_when_undefined(void** state);
void cmd_join__shows__error_message_when_invalid_room_jid(void** state);
void cmd_join__tests__uses_account_mucservice_when_no_service_specified(void** state);
void cmd_join__tests__uses_supplied_nick(void** state);
void cmd_join__tests__uses_account_nick_when_not_supplied(void** state);
void cmd_join__tests__uses_password_when_supplied(void** state);
#endif

View File

@@ -24,7 +24,7 @@
#ifdef HAVE_LIBOTR
void
cmd_otr_log_shows_usage_when_no_args(void** state)
cmd_otr_log__shows__usage_when_no_args(void** state)
{
gchar* args[] = { "log", NULL };
@@ -35,7 +35,7 @@ cmd_otr_log_shows_usage_when_no_args(void** state)
}
void
cmd_otr_log_shows_usage_when_invalid_subcommand(void** state)
cmd_otr_log__shows__usage_when_invalid_subcommand(void** state)
{
gchar* args[] = { "log", "wrong", NULL };
@@ -46,7 +46,7 @@ cmd_otr_log_shows_usage_when_invalid_subcommand(void** state)
}
void
cmd_otr_log_on_enables_logging(void** state)
cmd_otr_log__updates__enables_logging(void** state)
{
gchar* args[] = { "log", "on", NULL };
prefs_set_string(PREF_OTR_LOG, "off");
@@ -62,7 +62,7 @@ cmd_otr_log_on_enables_logging(void** state)
}
void
cmd_otr_log_on_shows_warning_when_chlog_disabled(void** state)
cmd_otr_log__shows__warning_when_chlog_disabled(void** state)
{
gchar* args[] = { "log", "on", NULL };
prefs_set_string(PREF_OTR_LOG, "off");
@@ -76,7 +76,7 @@ cmd_otr_log_on_shows_warning_when_chlog_disabled(void** state)
}
void
cmd_otr_log_off_disables_logging(void** state)
cmd_otr_log__updates__disables_logging(void** state)
{
gchar* args[] = { "log", "off", NULL };
prefs_set_string(PREF_OTR_LOG, "on");
@@ -92,7 +92,7 @@ cmd_otr_log_off_disables_logging(void** state)
}
void
cmd_otr_redact_redacts_logging(void** state)
cmd_otr_log__updates__redacts_logging(void** state)
{
gchar* args[] = { "log", "redact", NULL };
prefs_set_string(PREF_OTR_LOG, "on");
@@ -108,7 +108,7 @@ cmd_otr_redact_redacts_logging(void** state)
}
void
cmd_otr_log_redact_shows_warning_when_chlog_disabled(void** state)
cmd_otr_log__shows__redact_warning_when_chlog_disabled(void** state)
{
gchar* args[] = { "log", "redact", NULL };
prefs_set_string(PREF_OTR_LOG, "off");
@@ -122,7 +122,7 @@ cmd_otr_log_redact_shows_warning_when_chlog_disabled(void** state)
}
void
cmd_otr_libver_shows_libotr_version(void** state)
cmd_otr_libver__shows__libotr_version(void** state)
{
gchar* args[] = { "libver", NULL };
char* version = "9.9.9";
@@ -140,7 +140,7 @@ cmd_otr_libver_shows_libotr_version(void** state)
}
void
cmd_otr_gen_shows_message_when_not_connected(void** state)
cmd_otr_gen__shows__message_when_not_connected(void** state)
{
gchar* args[] = { "gen", NULL };
@@ -167,25 +167,25 @@ test_with_command_and_connection_status(char* command, void* cmd_func, jabber_co
}
void
cmd_otr_gen_shows_message_when_disconnected(void** state)
cmd_otr_gen__shows__message_when_disconnected(void** state)
{
test_with_command_and_connection_status("gen", cmd_otr_gen, JABBER_DISCONNECTED);
}
void
cmd_otr_gen_shows_message_when_connecting(void** state)
cmd_otr_gen__shows__message_when_connecting(void** state)
{
test_with_command_and_connection_status("gen", cmd_otr_gen, JABBER_CONNECTING);
}
void
cmd_otr_gen_shows_message_when_disconnecting(void** state)
cmd_otr_gen__shows__message_when_disconnecting(void** state)
{
test_with_command_and_connection_status("gen", cmd_otr_gen, JABBER_DISCONNECTING);
}
void
cmd_otr_gen_generates_key_for_connected_account(void** state)
cmd_otr_gen__tests__generates_key_for_connected_account(void** state)
{
gchar* args[] = { "gen", NULL };
gchar* account_name = g_strdup("myaccount");
@@ -206,25 +206,25 @@ cmd_otr_gen_generates_key_for_connected_account(void** state)
}
void
cmd_otr_myfp_shows_message_when_disconnected(void** state)
cmd_otr_myfp__shows__message_when_disconnected(void** state)
{
test_with_command_and_connection_status("myfp", cmd_otr_myfp, JABBER_DISCONNECTED);
}
void
cmd_otr_myfp_shows_message_when_connecting(void** state)
cmd_otr_myfp__shows__message_when_connecting(void** state)
{
test_with_command_and_connection_status("myfp", cmd_otr_myfp, JABBER_CONNECTING);
}
void
cmd_otr_myfp_shows_message_when_disconnecting(void** state)
cmd_otr_myfp__shows__message_when_disconnecting(void** state)
{
test_with_command_and_connection_status("myfp", cmd_otr_myfp, JABBER_DISCONNECTING);
}
void
cmd_otr_myfp_shows_message_when_no_key(void** state)
cmd_otr_myfp__shows__message_when_no_key(void** state)
{
gchar* args[] = { "myfp", NULL };
@@ -238,7 +238,7 @@ cmd_otr_myfp_shows_message_when_no_key(void** state)
}
void
cmd_otr_myfp_shows_my_fingerprint(void** state)
cmd_otr_myfp__shows__my_fingerprint(void** state)
{
char* fingerprint = "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD EEEEEEEE";
gchar* args[] = { "myfp", NULL };
@@ -247,7 +247,7 @@ cmd_otr_myfp_shows_my_fingerprint(void** state)
will_return(connection_get_status, JABBER_CONNECTED);
will_return(otr_key_loaded, TRUE);
will_return(otr_get_my_fingerprint, strdup(fingerprint));
will_return(otr_get_my_fingerprint, g_strdup(fingerprint));
expect_win_println(message->str);
@@ -277,25 +277,25 @@ test_cmd_otr_theirfp_from_wintype(win_type_t wintype)
}
void
cmd_otr_theirfp_shows_message_when_in_console(void** state)
cmd_otr_theirfp__shows__message_when_in_console(void** state)
{
test_cmd_otr_theirfp_from_wintype(WIN_CONSOLE);
}
void
cmd_otr_theirfp_shows_message_when_in_muc(void** state)
cmd_otr_theirfp__shows__message_when_in_muc(void** state)
{
test_cmd_otr_theirfp_from_wintype(WIN_MUC);
}
void
cmd_otr_theirfp_shows_message_when_in_private(void** state)
cmd_otr_theirfp__shows__message_when_in_private(void** state)
{
test_cmd_otr_theirfp_from_wintype(WIN_PRIVATE);
}
void
cmd_otr_theirfp_shows_message_when_non_otr_chat_window(void** state)
cmd_otr_theirfp__shows__message_when_non_otr_chat_window(void** state)
{
gchar* args[] = { "theirfp", NULL };
@@ -320,7 +320,7 @@ cmd_otr_theirfp_shows_message_when_non_otr_chat_window(void** state)
}
void
cmd_otr_theirfp_shows_fingerprint(void** state)
cmd_otr_theirfp__shows__fingerprint(void** state)
{
char* recipient = "someone@chat.com";
char* fingerprint = "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD EEEEEEEE";
@@ -344,7 +344,7 @@ cmd_otr_theirfp_shows_fingerprint(void** state)
will_return(connection_get_status, JABBER_CONNECTED);
expect_string(otr_get_their_fingerprint, recipient, recipient);
will_return(otr_get_their_fingerprint, strdup(fingerprint));
will_return(otr_get_their_fingerprint, g_strdup(fingerprint));
expect_win_println(message->str);
@@ -373,25 +373,25 @@ test_cmd_otr_start_from_wintype(win_type_t wintype)
}
void
cmd_otr_start_shows_message_when_in_console(void** state)
cmd_otr_start__shows__message_when_in_console(void** state)
{
test_cmd_otr_start_from_wintype(WIN_CONSOLE);
}
void
cmd_otr_start_shows_message_when_in_muc(void** state)
cmd_otr_start__shows__message_when_in_muc(void** state)
{
test_cmd_otr_start_from_wintype(WIN_MUC);
}
void
cmd_otr_start_shows_message_when_in_private(void** state)
cmd_otr_start__shows__message_when_in_private(void** state)
{
test_cmd_otr_start_from_wintype(WIN_PRIVATE);
}
void
cmd_otr_start_shows_message_when_already_started(void** state)
cmd_otr_start__shows__message_when_already_started(void** state)
{
char* recipient = "someone@server.org";
gchar* args[] = { "start", NULL };
@@ -417,7 +417,7 @@ cmd_otr_start_shows_message_when_already_started(void** state)
}
void
cmd_otr_start_shows_message_when_no_key(void** state)
cmd_otr_start__shows__message_when_no_key(void** state)
{
char* recipient = "someone@server.org";
gchar* args[] = { "start", NULL };
@@ -444,7 +444,7 @@ cmd_otr_start_shows_message_when_no_key(void** state)
}
void
cmd_otr_start_sends_otr_query_message_to_current_recipeint(void** state)
cmd_otr_start__tests__sends_otr_query_message_to_current_recipeint(void** state)
{
char* recipient = "buddy@chat.com";
char* query_message = "?OTR?";
@@ -475,7 +475,7 @@ cmd_otr_start_sends_otr_query_message_to_current_recipeint(void** state)
#else
void
cmd_otr_shows_message_when_otr_unsupported(void** state)
cmd_otr__shows__message_when_otr_unsupported(void** state)
{
gchar* args[] = { "gen", NULL };

View File

@@ -0,0 +1,42 @@
#ifndef TESTS_TEST_CMD_OTR_H
#define TESTS_TEST_CMD_OTR_H
#include "config.h"
#ifdef HAVE_LIBOTR
void cmd_otr_log__shows__usage_when_no_args(void** state);
void cmd_otr_log__shows__usage_when_invalid_subcommand(void** state);
void cmd_otr_log__updates__enables_logging(void** state);
void cmd_otr_log__updates__disables_logging(void** state);
void cmd_otr_log__updates__redacts_logging(void** state);
void cmd_otr_log__shows__warning_when_chlog_disabled(void** state);
void cmd_otr_log__shows__redact_warning_when_chlog_disabled(void** state);
void cmd_otr_libver__shows__libotr_version(void** state);
void cmd_otr_gen__shows__message_when_not_connected(void** state);
void cmd_otr_gen__tests__generates_key_for_connected_account(void** state);
void cmd_otr_gen__shows__message_when_disconnected(void** state);
void cmd_otr_gen__shows__message_when_undefined(void** state);
void cmd_otr_gen__shows__message_when_connecting(void** state);
void cmd_otr_gen__shows__message_when_disconnecting(void** state);
void cmd_otr_myfp__shows__message_when_disconnected(void** state);
void cmd_otr_myfp__shows__message_when_undefined(void** state);
void cmd_otr_myfp__shows__message_when_connecting(void** state);
void cmd_otr_myfp__shows__message_when_disconnecting(void** state);
void cmd_otr_myfp__shows__message_when_no_key(void** state);
void cmd_otr_myfp__shows__my_fingerprint(void** state);
void cmd_otr_theirfp__shows__message_when_in_console(void** state);
void cmd_otr_theirfp__shows__message_when_in_muc(void** state);
void cmd_otr_theirfp__shows__message_when_in_private(void** state);
void cmd_otr_theirfp__shows__message_when_non_otr_chat_window(void** state);
void cmd_otr_theirfp__shows__fingerprint(void** state);
void cmd_otr_start__shows__message_when_in_console(void** state);
void cmd_otr_start__shows__message_when_in_muc(void** state);
void cmd_otr_start__shows__message_when_in_private(void** state);
void cmd_otr_start__shows__message_when_already_started(void** state);
void cmd_otr_start__shows__message_when_no_key(void** state);
void cmd_otr_start__tests__sends_otr_query_message_to_current_recipeint(void** state);
#else
void cmd_otr__shows__message_when_otr_unsupported(void** state);
#endif
#endif

View File

@@ -0,0 +1,116 @@
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "config.h"
#include "command/cmd_funcs.h"
#include "xmpp/xmpp.h"
#include "ui/stub_ui.h"
#define CMD_PGP "/pgp"
#ifdef HAVE_LIBGPGME
void
cmd_pgp__shows__usage_when_no_args(void** state)
{
gchar* args[] = { NULL };
expect_string(cons_bad_cmd_usage, cmd, CMD_PGP);
gboolean result = cmd_pgp(NULL, CMD_PGP, args);
assert_true(result);
}
void
cmd_pgp_start__shows__message_when_connection(jabber_conn_status_t conn_status)
{
gchar* args[] = { "start", NULL };
ProfWin window;
window.type = WIN_CHAT;
will_return(connection_get_status, conn_status);
expect_cons_show("You must be connected to start PGP encryption.");
gboolean result = cmd_pgp(&window, CMD_PGP, args);
assert_true(result);
}
void
cmd_pgp_start__shows__message_when_disconnected(void** state)
{
cmd_pgp_start__shows__message_when_connection(JABBER_DISCONNECTED);
}
void
cmd_pgp_start__shows__message_when_disconnecting(void** state)
{
cmd_pgp_start__shows__message_when_connection(JABBER_DISCONNECTING);
}
void
cmd_pgp_start__shows__message_when_connecting(void** state)
{
cmd_pgp_start__shows__message_when_connection(JABBER_CONNECTING);
}
void
cmd_pgp_start__shows__message_when_no_arg_in_wintype(win_type_t wintype)
{
gchar* args[] = { "start", NULL };
ProfWin window;
window.type = wintype;
will_return(connection_get_status, JABBER_CONNECTED);
expect_cons_show("You must set recipient in an argument or be in a regular chat window to start PGP encryption.");
gboolean result = cmd_pgp(&window, CMD_PGP, args);
assert_true(result);
}
void
cmd_pgp_start__shows__message_when_no_arg_in_console(void** state)
{
cmd_pgp_start__shows__message_when_no_arg_in_wintype(WIN_CONSOLE);
}
void
cmd_pgp_start__shows__message_when_no_arg_in_muc(void** state)
{
cmd_pgp_start__shows__message_when_no_arg_in_wintype(WIN_MUC);
}
void
cmd_pgp_start__shows__message_when_no_arg_in_conf(void** state)
{
cmd_pgp_start__shows__message_when_no_arg_in_wintype(WIN_CONFIG);
}
void
cmd_pgp_start__shows__message_when_no_arg_in_private(void** state)
{
cmd_pgp_start__shows__message_when_no_arg_in_wintype(WIN_PRIVATE);
}
void
cmd_pgp_start__shows__message_when_no_arg_in_xmlconsole(void** state)
{
cmd_pgp_start__shows__message_when_no_arg_in_wintype(WIN_XML);
}
#else
void
cmd_pgp__shows__message_when_pgp_unsupported(void** state)
{
gchar* args[] = { "gen", NULL };
expect_cons_show("This version of Profanity has not been built with PGP support enabled");
gboolean result = cmd_pgp(NULL, CMD_PGP, args);
assert_true(result);
}
#endif

View File

@@ -0,0 +1,21 @@
#ifndef TESTS_TEST_CMD_PGP_H
#define TESTS_TEST_CMD_PGP_H
#include "config.h"
#ifdef HAVE_LIBGPGME
void cmd_pgp__shows__usage_when_no_args(void** state);
void cmd_pgp_start__shows__message_when_disconnected(void** state);
void cmd_pgp_start__shows__message_when_disconnecting(void** state);
void cmd_pgp_start__shows__message_when_connecting(void** state);
void cmd_pgp_start__shows__message_when_undefined(void** state);
void cmd_pgp_start__shows__message_when_no_arg_in_console(void** state);
void cmd_pgp_start__shows__message_when_no_arg_in_muc(void** state);
void cmd_pgp_start__shows__message_when_no_arg_in_conf(void** state);
void cmd_pgp_start__shows__message_when_no_arg_in_private(void** state);
void cmd_pgp_start__shows__message_when_no_arg_in_xmlconsole(void** state);
#else
void cmd_pgp__shows__message_when_pgp_unsupported(void** state);
#endif
#endif

View File

@@ -13,7 +13,7 @@
#define CMD_PRESENCE "/presence"
void
cmd_presence_shows_usage_when_bad_subcmd(void** state)
cmd_presence__shows__usage_when_bad_subcmd(void** state)
{
gchar* args[] = { "badcmd", NULL };
@@ -24,7 +24,7 @@ cmd_presence_shows_usage_when_bad_subcmd(void** state)
}
void
cmd_presence_shows_usage_when_bad_console_setting(void** state)
cmd_presence__shows__usage_when_bad_console_setting(void** state)
{
gchar* args[] = { "console", "badsetting", NULL };
@@ -35,7 +35,7 @@ cmd_presence_shows_usage_when_bad_console_setting(void** state)
}
void
cmd_presence_shows_usage_when_bad_chat_setting(void** state)
cmd_presence__shows__usage_when_bad_chat_setting(void** state)
{
gchar* args[] = { "chat", "badsetting", NULL };
@@ -46,7 +46,7 @@ cmd_presence_shows_usage_when_bad_chat_setting(void** state)
}
void
cmd_presence_shows_usage_when_bad_muc_setting(void** state)
cmd_presence__shows__usage_when_bad_muc_setting(void** state)
{
gchar* args[] = { "muc", "badsetting", NULL };
@@ -57,7 +57,7 @@ cmd_presence_shows_usage_when_bad_muc_setting(void** state)
}
void
cmd_presence_console_sets_all(void** state)
cmd_presence__updates__console_all(void** state)
{
gchar* args[] = { "console", "all", NULL };
@@ -72,7 +72,7 @@ cmd_presence_console_sets_all(void** state)
}
void
cmd_presence_console_sets_online(void** state)
cmd_presence__updates__console_online(void** state)
{
gchar* args[] = { "console", "online", NULL };
@@ -87,7 +87,7 @@ cmd_presence_console_sets_online(void** state)
}
void
cmd_presence_console_sets_none(void** state)
cmd_presence__updates__console_none(void** state)
{
gchar* args[] = { "console", "none", NULL };
@@ -102,7 +102,7 @@ cmd_presence_console_sets_none(void** state)
}
void
cmd_presence_chat_sets_all(void** state)
cmd_presence__updates__chat_all(void** state)
{
gchar* args[] = { "chat", "all", NULL };
@@ -117,7 +117,7 @@ cmd_presence_chat_sets_all(void** state)
}
void
cmd_presence_chat_sets_online(void** state)
cmd_presence__updates__chat_online(void** state)
{
gchar* args[] = { "chat", "online", NULL };
@@ -132,7 +132,7 @@ cmd_presence_chat_sets_online(void** state)
}
void
cmd_presence_chat_sets_none(void** state)
cmd_presence__updates__chat_none(void** state)
{
gchar* args[] = { "chat", "none", NULL };
@@ -147,7 +147,7 @@ cmd_presence_chat_sets_none(void** state)
}
void
cmd_presence_room_sets_all(void** state)
cmd_presence__updates__room_all(void** state)
{
gchar* args[] = { "room", "all", NULL };
@@ -162,7 +162,7 @@ cmd_presence_room_sets_all(void** state)
}
void
cmd_presence_room_sets_online(void** state)
cmd_presence__updates__room_online(void** state)
{
gchar* args[] = { "room", "online", NULL };
@@ -177,7 +177,7 @@ cmd_presence_room_sets_online(void** state)
}
void
cmd_presence_room_sets_none(void** state)
cmd_presence__updates__room_none(void** state)
{
gchar* args[] = { "room", "none", NULL };

View File

@@ -0,0 +1,18 @@
#ifndef TESTS_TEST_CMD_PRESENCE_H
#define TESTS_TEST_CMD_PRESENCE_H
void cmd_presence__shows__usage_when_bad_subcmd(void** state);
void cmd_presence__shows__usage_when_bad_console_setting(void** state);
void cmd_presence__shows__usage_when_bad_chat_setting(void** state);
void cmd_presence__shows__usage_when_bad_muc_setting(void** state);
void cmd_presence__updates__console_all(void** state);
void cmd_presence__updates__console_online(void** state);
void cmd_presence__updates__console_none(void** state);
void cmd_presence__updates__chat_all(void** state);
void cmd_presence__updates__chat_online(void** state);
void cmd_presence__updates__chat_none(void** state);
void cmd_presence__updates__room_all(void** state);
void cmd_presence__updates__room_online(void** state);
void cmd_presence__updates__room_none(void** state);
#endif

View File

@@ -25,25 +25,25 @@ test_with_connection_status(jabber_conn_status_t status)
}
void
cmd_rooms_shows_message_when_disconnected(void** state)
cmd_rooms__shows__message_when_disconnected(void** state)
{
test_with_connection_status(JABBER_DISCONNECTED);
}
void
cmd_rooms_shows_message_when_disconnecting(void** state)
cmd_rooms__shows__message_when_disconnecting(void** state)
{
test_with_connection_status(JABBER_DISCONNECTING);
}
void
cmd_rooms_shows_message_when_connecting(void** state)
cmd_rooms__shows__message_when_connecting(void** state)
{
test_with_connection_status(JABBER_CONNECTING);
}
void
cmd_rooms_uses_account_default_when_no_arg(void** state)
cmd_rooms__tests__account_default_when_no_arg(void** state)
{
gchar* args[] = { NULL };
@@ -66,7 +66,7 @@ cmd_rooms_uses_account_default_when_no_arg(void** state)
}
void
cmd_rooms_service_arg_used_when_passed(void** state)
cmd_rooms__tests__service_arg_used_when_passed(void** state)
{
gchar* args[] = { "service", "conf_server_arg", NULL };
@@ -83,7 +83,7 @@ cmd_rooms_service_arg_used_when_passed(void** state)
}
void
cmd_rooms_filter_arg_used_when_passed(void** state)
cmd_rooms__tests__filter_arg_used_when_passed(void** state)
{
gchar* args[] = { "filter", "text", NULL };

View File

@@ -0,0 +1,12 @@
#ifndef TESTS_TEST_CMD_ROOMS_H
#define TESTS_TEST_CMD_ROOMS_H
void cmd_rooms__shows__message_when_disconnected(void** state);
void cmd_rooms__shows__message_when_disconnecting(void** state);
void cmd_rooms__shows__message_when_connecting(void** state);
void cmd_rooms__shows__message_when_undefined(void** state);
void cmd_rooms__tests__account_default_when_no_arg(void** state);
void cmd_rooms__tests__service_arg_used_when_passed(void** state);
void cmd_rooms__tests__filter_arg_used_when_passed(void** state);
#endif

View File

@@ -26,25 +26,25 @@ test_with_connection_status(jabber_conn_status_t status)
}
void
cmd_roster_shows_message_when_disconnecting(void** state)
cmd_roster__shows__message_when_disconnecting(void** state)
{
test_with_connection_status(JABBER_DISCONNECTING);
}
void
cmd_roster_shows_message_when_connecting(void** state)
cmd_roster__shows__message_when_connecting(void** state)
{
test_with_connection_status(JABBER_CONNECTING);
}
void
cmd_roster_shows_message_when_disconnected(void** state)
cmd_roster__shows__message_when_disconnected(void** state)
{
test_with_connection_status(JABBER_DISCONNECTED);
}
void
cmd_roster_shows_roster_when_no_args(void** state)
cmd_roster__shows__roster_when_no_args(void** state)
{
gchar* args[] = { NULL };
@@ -64,7 +64,7 @@ cmd_roster_shows_roster_when_no_args(void** state)
}
void
cmd_roster_add_shows_message_when_no_jid(void** state)
cmd_roster__shows__message_when_add_no_jid(void** state)
{
gchar* args[] = { "add", NULL };
@@ -77,7 +77,7 @@ cmd_roster_add_shows_message_when_no_jid(void** state)
}
void
cmd_roster_add_sends_roster_add_request(void** state)
cmd_roster__tests__add_sends_roster_add_request(void** state)
{
char* jid = "bob@server.org";
char* nick = "bob";
@@ -93,7 +93,7 @@ cmd_roster_add_sends_roster_add_request(void** state)
}
void
cmd_roster_remove_shows_message_when_no_jid(void** state)
cmd_roster__shows__message_when_remove_no_jid(void** state)
{
gchar* args[] = { "remove", NULL };
@@ -106,7 +106,7 @@ cmd_roster_remove_shows_message_when_no_jid(void** state)
}
void
cmd_roster_remove_sends_roster_remove_request(void** state)
cmd_roster__tests__remove_sends_roster_remove_request(void** state)
{
char* jid = "bob@server.org";
gchar* args[] = { "remove", jid, NULL };
@@ -124,13 +124,14 @@ cmd_roster_remove_sends_roster_remove_request(void** state)
}
void
cmd_roster_remove_nickname_sends_roster_remove_request(void** state)
cmd_roster__tests__remove_nickname_sends_roster_remove_request(void** state)
{
char* jid = "bob@server.org";
gchar* args[] = { "remove", "bob", NULL };
char* nick = "bob";
gchar* args[] = { "remove", nick, NULL };
roster_create();
roster_add("bob@server.org", "bob", NULL, "both", FALSE);
roster_add(jid, nick, NULL, "both", FALSE);
will_return(connection_get_status, JABBER_CONNECTED);
@@ -142,7 +143,7 @@ cmd_roster_remove_nickname_sends_roster_remove_request(void** state)
}
void
cmd_roster_nick_shows_message_when_no_jid(void** state)
cmd_roster__shows__message_when_nick_no_jid(void** state)
{
gchar* args[] = { "nick", NULL };
@@ -155,7 +156,7 @@ cmd_roster_nick_shows_message_when_no_jid(void** state)
}
void
cmd_roster_nick_shows_message_when_no_nick(void** state)
cmd_roster__shows__message_when_nick_no_nick(void** state)
{
gchar* args[] = { "nick", "bob@server.org", NULL };
@@ -168,7 +169,7 @@ cmd_roster_nick_shows_message_when_no_nick(void** state)
}
void
cmd_roster_nick_shows_message_when_no_contact_exists(void** state)
cmd_roster__shows__message_when_nick_no_contact_exists(void** state)
{
gchar* args[] = { "nick", "bob@server.org", "bobster", NULL };
@@ -185,7 +186,7 @@ cmd_roster_nick_shows_message_when_no_contact_exists(void** state)
}
void
cmd_roster_nick_sends_name_change_request(void** state)
cmd_roster__tests__nick_sends_name_change_request(void** state)
{
char* jid = "bob@server.org";
char* nick = "bobster";
@@ -193,7 +194,7 @@ cmd_roster_nick_sends_name_change_request(void** state)
roster_create();
GSList* groups = NULL;
groups = g_slist_append(groups, strdup("group1"));
groups = g_slist_append(groups, g_strdup("group1"));
roster_add(jid, "bob", groups, "both", FALSE);
will_return(connection_get_status, JABBER_CONNECTED);
@@ -214,7 +215,7 @@ cmd_roster_nick_sends_name_change_request(void** state)
}
void
cmd_roster_clearnick_shows_message_when_no_jid(void** state)
cmd_roster__shows__message_when_clearnick_no_jid(void** state)
{
gchar* args[] = { "clearnick", NULL };
@@ -227,7 +228,7 @@ cmd_roster_clearnick_shows_message_when_no_jid(void** state)
}
void
cmd_roster_clearnick_shows_message_when_no_contact_exists(void** state)
cmd_roster__shows__message_when_clearnick_no_contact_exists(void** state)
{
gchar* args[] = { "clearnick", "bob@server.org", NULL };
@@ -244,14 +245,14 @@ cmd_roster_clearnick_shows_message_when_no_contact_exists(void** state)
}
void
cmd_roster_clearnick_sends_name_change_request_with_empty_nick(void** state)
cmd_roster__tests__clearnick_sends_name_change_request_with_empty_nick(void** state)
{
char* jid = "bob@server.org";
gchar* args[] = { "clearnick", jid, NULL };
roster_create();
GSList* groups = NULL;
groups = g_slist_append(groups, strdup("group1"));
groups = g_slist_append(groups, g_strdup("group1"));
roster_add(jid, "bob", groups, "both", FALSE);
will_return(connection_get_status, JABBER_CONNECTED);

View File

@@ -0,0 +1,21 @@
#ifndef TESTS_TEST_CMD_ROSTER_H
#define TESTS_TEST_CMD_ROSTER_H
void cmd_roster__shows__message_when_disconnecting(void** state);
void cmd_roster__shows__message_when_connecting(void** state);
void cmd_roster__shows__message_when_disconnected(void** state);
void cmd_roster__shows__roster_when_no_args(void** state);
void cmd_roster__shows__message_when_add_no_jid(void** state);
void cmd_roster__tests__add_sends_roster_add_request(void** state);
void cmd_roster__shows__message_when_remove_no_jid(void** state);
void cmd_roster__tests__remove_sends_roster_remove_request(void** state);
void cmd_roster__tests__remove_nickname_sends_roster_remove_request(void** state);
void cmd_roster__shows__message_when_nick_no_jid(void** state);
void cmd_roster__shows__message_when_nick_no_nick(void** state);
void cmd_roster__shows__message_when_nick_no_contact_exists(void** state);
void cmd_roster__tests__nick_sends_name_change_request(void** state);
void cmd_roster__shows__message_when_clearnick_no_jid(void** state);
void cmd_roster__shows__message_when_clearnick_no_contact_exists(void** state);
void cmd_roster__tests__clearnick_sends_name_change_request_with_empty_nick(void** state);
#endif

View File

@@ -13,7 +13,7 @@
#define CMD_SUB "/sub"
void
cmd_sub_shows_message_when_not_connected(void** state)
cmd_sub__shows__message_when_not_connected(void** state)
{
gchar* args[] = { NULL };
@@ -26,7 +26,7 @@ cmd_sub_shows_message_when_not_connected(void** state)
}
void
cmd_sub_shows_usage_when_no_arg(void** state)
cmd_sub__shows__usage_when_no_arg(void** state)
{
gchar* args[] = { NULL };

View File

@@ -0,0 +1,7 @@
#ifndef TESTS_TEST_CMD_SUB_H
#define TESTS_TEST_CMD_SUB_H
void cmd_sub__shows__message_when_not_connected(void** state);
void cmd_sub__shows__usage_when_no_arg(void** state);
#endif

View File

@@ -4,33 +4,7 @@
*
* Copyright (C) 2022 Steffen Jaeckel <jaeckel-floss@eyet-services.de>
*
* This file is part of Profanity.
*
* Profanity is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Profanity is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Profanity. If not, see <https://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give permission to
* link the code of portions of this program with the OpenSSL library under
* certain conditions as described in each individual source file, and
* distribute linked combinations including the two.
*
* You must obey the GNU General Public License in all respects for all of the
* code used other than OpenSSL. If you modify file(s) with this exception, you
* may extend this exception to your version of the file(s), but you are not
* obligated to do so. If you do not wish to do so, delete this exception
* statement from your version. If you delete this exception statement from all
* source files in the program, then also delete it here.
*
* SPDX-License-Identifier: GPL-3.0-or-later WITH OpenSSL-exception
*/
#include <fcntl.h>

View File

@@ -6,7 +6,7 @@
#include "config/preferences.h"
void
statuses_console_defaults_to_all(void** state)
prefs_get_string__returns__all_for_console_default(void** state)
{
gchar* setting = prefs_get_string(PREF_STATUSES_CONSOLE);
@@ -16,7 +16,7 @@ statuses_console_defaults_to_all(void** state)
}
void
statuses_chat_defaults_to_all(void** state)
prefs_get_string__returns__none_for_chat_default(void** state)
{
gchar* setting = prefs_get_string(PREF_STATUSES_CHAT);
@@ -26,7 +26,7 @@ statuses_chat_defaults_to_all(void** state)
}
void
statuses_muc_defaults_to_all(void** state)
prefs_get_string__returns__none_for_muc_default(void** state)
{
gchar* setting = prefs_get_string(PREF_STATUSES_MUC);

View File

@@ -0,0 +1,8 @@
#ifndef TESTS_TEST_PREFERENCES_H
#define TESTS_TEST_PREFERENCES_H
void prefs_get_string__returns__all_for_console_default(void** state);
void prefs_get_string__returns__none_for_chat_default(void** state);
void prefs_get_string__returns__none_for_muc_default(void** state);
#endif

View File

@@ -1,23 +1,9 @@
/*
* stub_database.c
*
* Copyright (C) 2020 - 2025 Michael Vetter <jubalh@iodoru.org>
*
* This file is part of Profanity.
*
* Profanity is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Profanity is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Profanity. If not, see <http://www.gnu.org/licenses/>.
* Copyright (C) 2020 - 2026 Michael Vetter <jubalh@iodoru.org>
*
* SPDX-License-Identifier: GPL-3.0-or-later WITH OpenSSL-exception
*/
#include <glib.h>

View File

@@ -15,7 +15,7 @@
#include "ui/window_list.h"
void
console_shows_online_presence_when_set_online(void** state)
sv_ev_contact_online__shows__presence_in_console_when_set_online(void** state)
{
prefs_set_string(PREF_STATUSES_CONSOLE, "online");
plugins_init();
@@ -35,7 +35,7 @@ console_shows_online_presence_when_set_online(void** state)
}
void
console_shows_online_presence_when_set_all(void** state)
sv_ev_contact_online__shows__presence_in_console_when_set_all(void** state)
{
prefs_set_string(PREF_STATUSES_CONSOLE, "all");
plugins_init();
@@ -55,7 +55,7 @@ console_shows_online_presence_when_set_all(void** state)
}
void
console_shows_dnd_presence_when_set_all(void** state)
sv_ev_contact_online__shows__dnd_presence_in_console_when_set_all(void** state)
{
prefs_set_string(PREF_STATUSES_CONSOLE, "all");
plugins_init();
@@ -75,7 +75,7 @@ console_shows_dnd_presence_when_set_all(void** state)
}
void
handle_offline_removes_chat_session(void** state)
sv_ev_contact_offline__updates__removes_chat_session(void** state)
{
plugins_init();
roster_create();
@@ -87,7 +87,7 @@ handle_offline_removes_chat_session(void** state)
Resource* resourcep = resource_new(resource, RESOURCE_ONLINE, NULL, 10);
roster_update_presence(barejid, resourcep, NULL);
chat_session_recipient_active(barejid, resource, FALSE);
ProfConsoleWin* console = calloc(1, sizeof(ProfConsoleWin));
ProfConsoleWin* console = g_new0(ProfConsoleWin, 1);
will_return(win_create_console, &console->window);
wins_init();
sv_ev_contact_offline(barejid, resource, NULL);
@@ -100,7 +100,7 @@ handle_offline_removes_chat_session(void** state)
}
void
lost_connection_clears_chat_sessions(void** state)
sv_ev_lost_connection__updates__clears_chat_sessions(void** state)
{
roster_create();
roster_process_pending_presence();

View File

@@ -0,0 +1,10 @@
#ifndef TESTS_TEST_SERVER_EVENTS_H
#define TESTS_TEST_SERVER_EVENTS_H
void sv_ev_contact_online__shows__presence_in_console_when_set_online(void** state);
void sv_ev_contact_online__shows__presence_in_console_when_set_all(void** state);
void sv_ev_contact_online__shows__dnd_presence_in_console_when_set_all(void** state);
void sv_ev_contact_offline__updates__removes_chat_session(void** state);
void sv_ev_lost_connection__updates__clears_chat_sessions(void** state);
#endif

View File

@@ -1,3 +1,11 @@
/*
* helpers.h
*
* Copyright (C) 2015 James Booth <boothj5@gmail.com>
* Copyright (C) 2020 - 2026 Michael Vetter <jubalh@iodoru.org>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include "glib.h"
int load_preferences(void** state);

View File

@@ -3,21 +3,7 @@
*
* Copyright (C) 2012 - 2019 James Booth <boothj5@gmail.com>
*
* This file is part of Profanity.
*
* Profanity is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Profanity is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Profanity. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later WITH OpenSSL-exception
*/
#include <glib.h>
@@ -60,10 +46,10 @@ log_msg(log_level_t level, const char* const area, const char* const msg)
{
}
const char*
const gchar*
get_log_file_location(void)
{
return mock_ptr_type(char*);
return mock_ptr_type(gchar*);
}
int

View File

@@ -9,7 +9,7 @@ omemo_init(void)
}
char*
omemo_fingerprint_autocomplete(const char* const search_str, gboolean previous)
omemo_fingerprint_autocomplete(const char* const search_str, gboolean previous, void* context)
{
return NULL;
}
@@ -42,12 +42,30 @@ omemo_is_trusted_identity(const char* const jid, const char* const fingerprint)
return TRUE;
}
gboolean
omemo_is_jid_trusted(const char* const jid)
{
return TRUE;
}
GList*
omemo_get_jid_untrusted_fingerprints(const char* const jid)
{
return NULL;
}
GList*
omemo_known_device_identities(const char* const jid)
{
return NULL;
}
gboolean
omemo_is_device_active(const char* const jid, const char* const fingerprint)
{
return TRUE;
}
gboolean
omemo_loaded(void)
{
@@ -64,7 +82,7 @@ omemo_on_disconnect(void)
}
char*
omemo_on_message_send(ProfWin* win, const char* const message, gboolean request_receipt, gboolean muc)
omemo_on_message_send(ProfWin* win, const char* const message, gboolean request_receipt, gboolean muc, const char* const replace_id)
{
return NULL;
}
@@ -111,6 +129,23 @@ omemo_encrypt_file(FILE* in, FILE* out, off_t file_size, int* gcry_res)
};
void omemo_free(void* a) {};
char*
omemo_on_message_recv(const char* const from, uint32_t sid,
const unsigned char* const iv, size_t iv_len,
GList* keys, const unsigned char* const payload,
size_t payload_len, gboolean muc, gboolean* trusted, omemo_error_t* error)
{
*error = OMEMO_ERR_NONE;
return NULL;
}
char*
omemo_receive_message(xmpp_stanza_t* const stanza, gboolean* trusted, omemo_error_t* error)
{
*error = OMEMO_ERR_NONE;
return NULL;
}
uint32_t
omemo_device_id()
{

View File

@@ -1,3 +1,11 @@
/*
* stub_otr.c
*
* Copyright (C) 2015 - 2016 James Booth <boothj5@gmail.com>
* Copyright (C) 2020 - 2026 Michael Vetter <jubalh@iodoru.org>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include <libotr/proto.h>
#include <libotr/message.h>
#include <glib.h>

View File

@@ -1,3 +1,11 @@
/*
* stub_gpg.c
*
* Copyright (C) 2015 - 2017 James Booth <boothj5@gmail.com>
* Copyright (C) 2020 - 2026 Michael Vetter <jubalh@iodoru.org>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include <glib.h>
#include "pgp/gpg.h"
@@ -26,35 +34,35 @@ p_gpg_libver(void)
}
void
p_gpg_verify(const char* const barejid, const char* const sign)
p_gpg_verify(const gchar* const barejid, const gchar* const sign)
{
}
char*
p_gpg_sign(const char* const str, const char* const fp)
gchar*
p_gpg_sign(const gchar* const str, const gchar* const fp)
{
return NULL;
}
gboolean
p_gpg_valid_key(const char* const keyid, char** err_str)
p_gpg_valid_key(const gchar* const keyid, gchar** err_str)
{
return FALSE;
}
gboolean
p_gpg_available(const char* const barejid)
p_gpg_available(const gchar* const barejid)
{
return FALSE;
}
char*
p_gpg_decrypt(const char* const cipher)
gchar*
p_gpg_decrypt(const gchar* const cipher)
{
return NULL;
}
void
p_gpg_on_connect(const char* const barejid)
p_gpg_on_connect(const gchar* const barejid)
{
}
void
@@ -63,13 +71,13 @@ p_gpg_on_disconnect(void)
}
gboolean
p_gpg_addkey(const char* const jid, const char* const keyid)
p_gpg_addkey(const gchar* const jid, const gchar* const keyid)
{
return TRUE;
}
void
p_gpg_free_decrypted(char* decrypted)
p_gpg_free_decrypted(gchar* decrypted)
{
}
@@ -83,32 +91,32 @@ p_gpg_autocomplete_key_reset(void)
{
}
char*
p_gpg_autocomplete_key(const char* const search_str, gboolean previous, void* context)
gchar*
p_gpg_autocomplete_key(const gchar* const search_str, gboolean previous, void* context)
{
return NULL;
}
char*
p_gpg_format_fp_str(char* fp)
gchar*
p_gpg_format_fp_str(gchar* fp)
{
return NULL;
}
char*
p_gpg_get_pubkey(const char* const keyid)
gchar*
p_gpg_get_pubkey(const gchar* const keyid)
{
return NULL;
}
gboolean
p_gpg_is_public_key_format(const char* buffer)
p_gpg_is_public_key_format(const gchar* buffer)
{
return TRUE;
}
ProfPGPKey*
p_gpg_import_pubkey(const char* buffer)
p_gpg_import_pubkey(const gchar* buffer)
{
return NULL;
}

View File

@@ -7,7 +7,7 @@
#include "plugins/plugins.h"
void
returns_no_commands(void** state)
plugins_get_command_names__returns__no_commands(void** state)
{
plugins_init();
GList* commands = plugins_get_command_names();
@@ -16,19 +16,19 @@ returns_no_commands(void** state)
}
void
returns_commands(void** state)
plugins_get_command_names__returns__commands_when_added(void** state)
{
plugins_init();
PluginCommand* command1 = calloc(1, sizeof(PluginCommand));
command1->command_name = strdup("command1");
PluginCommand* command1 = g_new0(PluginCommand, 1);
command1->command_name = g_strdup("command1");
callbacks_add_command("plugin1", command1);
PluginCommand* command2 = calloc(1, sizeof(PluginCommand));
command2->command_name = strdup("command2");
PluginCommand* command2 = g_new0(PluginCommand, 1);
command2->command_name = g_strdup("command2");
callbacks_add_command("plugin1", command2);
PluginCommand* command3 = calloc(1, sizeof(PluginCommand));
command3->command_name = strdup("command3");
PluginCommand* command3 = g_new0(PluginCommand, 1);
command3->command_name = g_strdup("command3");
callbacks_add_command("plugin2", command3);
GList* names = plugins_get_command_names();

View File

@@ -0,0 +1,7 @@
#ifndef TESTS_TEST_CALLBACKS_H
#define TESTS_TEST_CALLBACKS_H
void plugins_get_command_names__returns__no_commands(void** state);
void plugins_get_command_names__returns__commands_when_added(void** state);
#endif

View File

@@ -4,7 +4,7 @@
#include "plugins/disco.h"
void
returns_empty_list_when_none(void** state)
disco_get_features__returns__empty_list_when_none(void** state)
{
disco_close();
GList* features = disco_get_features();
@@ -16,7 +16,7 @@ returns_empty_list_when_none(void** state)
}
void
returns_added_feature(void** state)
disco_add_feature__updates__added_feature(void** state)
{
disco_close();
disco_add_feature("my_plugin", "some:feature:example");
@@ -31,7 +31,7 @@ returns_added_feature(void** state)
}
void
resets_features_on_close(void** state)
disco_close__updates__resets_features(void** state)
{
disco_close();
disco_add_feature("my_plugin", "some:feature:example");
@@ -49,7 +49,7 @@ resets_features_on_close(void** state)
}
void
returns_all_added_features(void** state)
disco_get_features__returns__all_added_features(void** state)
{
disco_close();
disco_add_feature("first_plugin", "first:feature");
@@ -72,7 +72,7 @@ returns_all_added_features(void** state)
}
void
does_not_add_duplicate_feature(void** state)
disco_add_feature__updates__not_duplicate_feature(void** state)
{
disco_close();
disco_add_feature("my_plugin", "my:feature");
@@ -86,7 +86,7 @@ does_not_add_duplicate_feature(void** state)
}
void
removes_plugin_features(void** state)
disco_remove_features__updates__removes_plugin_features(void** state)
{
disco_close();
disco_add_feature("plugin1", "plugin1:feature1");
@@ -107,7 +107,7 @@ removes_plugin_features(void** state)
}
void
does_not_remove_feature_when_more_than_one_reference(void** state)
disco_remove_features__updates__not_remove_when_more_than_one_reference(void** state)
{
disco_close();
disco_add_feature("plugin1", "feature1");

View File

@@ -0,0 +1,12 @@
#ifndef TESTS_TEST_PLUGINS_DISCO_H
#define TESTS_TEST_PLUGINS_DISCO_H
void disco_get_features__returns__empty_list_when_none(void** state);
void disco_add_feature__updates__added_feature(void** state);
void disco_close__updates__resets_features(void** state);
void disco_get_features__returns__all_added_features(void** state);
void disco_add_feature__updates__not_duplicate_feature(void** state);
void disco_remove_features__updates__removes_plugin_features(void** state);
void disco_remove_features__updates__not_remove_when_more_than_one_reference(void** state);
#endif

View File

@@ -1,16 +0,0 @@
void clear_empty(void** state);
void reset_after_create(void** state);
void find_after_create(void** state);
void get_after_create_returns_null(void** state);
void add_one_and_complete(void** state);
void add_two_and_complete_returns_first(void** state);
void add_two_and_complete_returns_second(void** state);
void add_two_adds_two(void** state);
void add_two_same_adds_one(void** state);
void add_two_same_updates(void** state);
void complete_accented_with_accented(void** state);
void complete_accented_with_base(void** state);
void complete_both_with_accented(void** state);
void complete_both_with_base(void** state);
void complete_ignores_case(void** state);
void complete_previous(void** state);

View File

@@ -1,2 +0,0 @@
void returns_no_commands(void** state);
void returns_commands(void** state);

View File

@@ -1,4 +0,0 @@
void returns_false_when_chat_session_does_not_exist(void** state);
void creates_chat_session_on_recipient_activity(void** state);
void replaces_chat_session_on_recipient_activity_with_different_resource(void** state);
void removes_chat_session(void** state);

View File

@@ -1,56 +0,0 @@
void cmd_account_shows_usage_when_not_connected_and_no_args(void** state);
void cmd_account_shows_account_when_connected_and_no_args(void** state);
void cmd_account_list_shows_accounts(void** state);
void cmd_account_show_shows_usage_when_no_arg(void** state);
void cmd_account_show_shows_message_when_account_does_not_exist(void** state);
void cmd_account_show_shows_account_when_exists(void** state);
void cmd_account_add_shows_usage_when_no_arg(void** state);
void cmd_account_add_adds_account(void** state);
void cmd_account_enable_shows_usage_when_no_arg(void** state);
void cmd_account_enable_enables_account(void** state);
void cmd_account_enable_shows_message_when_account_doesnt_exist(void** state);
void cmd_account_disable_shows_usage_when_no_arg(void** state);
void cmd_account_disable_disables_account(void** state);
void cmd_account_disable_shows_message_when_account_doesnt_exist(void** state);
void cmd_account_rename_shows_usage_when_no_args(void** state);
void cmd_account_rename_shows_usage_when_one_arg(void** state);
void cmd_account_rename_renames_account(void** state);
void cmd_account_rename_shows_message_when_not_renamed(void** state);
void cmd_account_set_shows_usage_when_no_args(void** state);
void cmd_account_set_shows_usage_when_one_arg(void** state);
void cmd_account_set_shows_usage_when_two_args(void** state);
void cmd_account_set_shows_message_when_account_doesnt_exist(void** state);
void cmd_account_set_jid_shows_message_for_malformed_jid(void** state);
void cmd_account_set_jid_sets_barejid(void** state);
void cmd_account_set_jid_sets_resource(void** state);
void cmd_account_set_server_sets_server(void** state);
void cmd_account_set_resource_sets_resource(void** state);
void cmd_account_set_resource_sets_resource_with_online_message(void** state);
void cmd_account_set_password_sets_password(void** state);
void cmd_account_set_eval_password_sets_eval_password(void** state);
void cmd_account_set_password_when_eval_password_set(void** state);
void cmd_account_set_eval_password_when_password_set(void** state);
void cmd_account_set_muc_sets_muc(void** state);
void cmd_account_set_nick_sets_nick(void** state);
void cmd_account_show_message_for_missing_otr_policy(void** state);
void cmd_account_show_message_for_invalid_otr_policy(void** state);
void cmd_account_set_otr_sets_otr(void** state);
void cmd_account_set_status_shows_message_when_invalid_status(void** state);
void cmd_account_set_status_sets_status_when_valid(void** state);
void cmd_account_set_status_sets_status_when_last(void** state);
void cmd_account_set_invalid_presence_string_priority_shows_message(void** state);
void cmd_account_set_last_priority_shows_message(void** state);
void cmd_account_set_online_priority_sets_preference(void** state);
void cmd_account_set_chat_priority_sets_preference(void** state);
void cmd_account_set_away_priority_sets_preference(void** state);
void cmd_account_set_xa_priority_sets_preference(void** state);
void cmd_account_set_dnd_priority_sets_preference(void** state);
void cmd_account_set_priority_too_low_shows_message(void** state);
void cmd_account_set_priority_too_high_shows_message(void** state);
void cmd_account_set_priority_when_not_number_shows_message(void** state);
void cmd_account_set_priority_when_empty_shows_message(void** state);
void cmd_account_set_priority_updates_presence_when_account_connected_with_presence(void** state);
void cmd_account_clear_shows_usage_when_no_args(void** state);
void cmd_account_clear_shows_usage_when_one_arg(void** state);
void cmd_account_clear_shows_message_when_account_doesnt_exist(void** state);
void cmd_account_clear_shows_message_when_invalid_property(void** state);

View File

@@ -1,9 +0,0 @@
void cmd_alias_add_shows_usage_when_no_args(void** state);
void cmd_alias_add_shows_usage_when_no_value(void** state);
void cmd_alias_remove_shows_usage_when_no_args(void** state);
void cmd_alias_show_usage_when_invalid_subcmd(void** state);
void cmd_alias_add_adds_alias(void** state);
void cmd_alias_add_shows_message_when_exists(void** state);
void cmd_alias_remove_removes_alias(void** state);
void cmd_alias_remove_shows_message_when_no_alias(void** state);
void cmd_alias_list_shows_all_aliases(void** state);

View File

@@ -1,18 +0,0 @@
void cmd_bookmark_shows_message_when_disconnected(void** state);
void cmd_bookmark_shows_message_when_disconnecting(void** state);
void cmd_bookmark_shows_message_when_connecting(void** state);
void cmd_bookmark_shows_message_when_undefined(void** state);
void cmd_bookmark_shows_usage_when_no_args(void** state);
void cmd_bookmark_list_shows_bookmarks(void** state);
void cmd_bookmark_add_shows_message_when_invalid_jid(void** state);
void cmd_bookmark_add_adds_bookmark_with_jid(void** state);
void cmd_bookmark_uses_roomjid_in_room(void** state);
void cmd_bookmark_add_uses_roomjid_in_room(void** state);
void cmd_bookmark_add_uses_supplied_jid_in_room(void** state);
void cmd_bookmark_remove_uses_roomjid_in_room(void** state);
void cmd_bookmark_remove_uses_supplied_jid_in_room(void** state);
void cmd_bookmark_add_adds_bookmark_with_jid_nick(void** state);
void cmd_bookmark_add_adds_bookmark_with_jid_autojoin(void** state);
void cmd_bookmark_add_adds_bookmark_with_jid_nick_autojoin(void** state);
void cmd_bookmark_remove_removes_bookmark(void** state);
void cmd_bookmark_remove_shows_message_when_no_bookmark(void** state);

View File

@@ -1,27 +0,0 @@
void cmd_connect_shows_message_when_disconnecting(void** state);
void cmd_connect_shows_message_when_connecting(void** state);
void cmd_connect_shows_message_when_connected(void** state);
void cmd_connect_shows_message_when_undefined(void** state);
void cmd_connect_when_no_account(void** state);
void cmd_connect_with_altdomain_when_provided(void** state);
void cmd_connect_fail_message(void** state);
void cmd_connect_lowercases_argument_with_no_account(void** state);
void cmd_connect_lowercases_argument_with_account(void** state);
void cmd_connect_asks_password_when_not_in_account(void** state);
void cmd_connect_shows_message_when_connecting_with_account(void** state);
void cmd_connect_connects_with_account(void** state);
void cmd_connect_shows_usage_when_no_server_value(void** state);
void cmd_connect_shows_usage_when_server_no_port_value(void** state);
void cmd_connect_shows_usage_when_no_port_value(void** state);
void cmd_connect_shows_usage_when_port_no_server_value(void** state);
void cmd_connect_shows_message_when_port_0(void** state);
void cmd_connect_shows_message_when_port_minus1(void** state);
void cmd_connect_shows_message_when_port_65536(void** state);
void cmd_connect_shows_message_when_port_contains_chars(void** state);
void cmd_connect_with_server_when_provided(void** state);
void cmd_connect_with_port_when_provided(void** state);
void cmd_connect_with_server_and_port_when_provided(void** state);
void cmd_connect_shows_usage_when_server_provided_twice(void** state);
void cmd_connect_shows_usage_when_port_provided_twice(void** state);
void cmd_connect_shows_usage_when_invalid_first_property(void** state);
void cmd_connect_shows_usage_when_invalid_second_property(void** state);

View File

@@ -1 +0,0 @@
void clears_chat_sessions(void** state);

View File

@@ -1,9 +0,0 @@
void cmd_join_shows_message_when_disconnecting(void** state);
void cmd_join_shows_message_when_connecting(void** state);
void cmd_join_shows_message_when_disconnected(void** state);
void cmd_join_shows_message_when_undefined(void** state);
void cmd_join_shows_error_message_when_invalid_room_jid(void** state);
void cmd_join_uses_account_mucservice_when_no_service_specified(void** state);
void cmd_join_uses_supplied_nick(void** state);
void cmd_join_uses_account_nick_when_not_supplied(void** state);
void cmd_join_uses_password_when_supplied(void** state);

View File

@@ -1,37 +0,0 @@
#include "config.h"
#ifdef HAVE_LIBOTR
void cmd_otr_log_shows_usage_when_no_args(void** state);
void cmd_otr_log_shows_usage_when_invalid_subcommand(void** state);
void cmd_otr_log_on_enables_logging(void** state);
void cmd_otr_log_off_disables_logging(void** state);
void cmd_otr_redact_redacts_logging(void** state);
void cmd_otr_log_on_shows_warning_when_chlog_disabled(void** state);
void cmd_otr_log_redact_shows_warning_when_chlog_disabled(void** state);
void cmd_otr_libver_shows_libotr_version(void** state);
void cmd_otr_gen_shows_message_when_not_connected(void** state);
void cmd_otr_gen_generates_key_for_connected_account(void** state);
void cmd_otr_gen_shows_message_when_disconnected(void** state);
void cmd_otr_gen_shows_message_when_undefined(void** state);
void cmd_otr_gen_shows_message_when_connecting(void** state);
void cmd_otr_gen_shows_message_when_disconnecting(void** state);
void cmd_otr_myfp_shows_message_when_disconnected(void** state);
void cmd_otr_myfp_shows_message_when_undefined(void** state);
void cmd_otr_myfp_shows_message_when_connecting(void** state);
void cmd_otr_myfp_shows_message_when_disconnecting(void** state);
void cmd_otr_myfp_shows_message_when_no_key(void** state);
void cmd_otr_myfp_shows_my_fingerprint(void** state);
void cmd_otr_theirfp_shows_message_when_in_console(void** state);
void cmd_otr_theirfp_shows_message_when_in_muc(void** state);
void cmd_otr_theirfp_shows_message_when_in_private(void** state);
void cmd_otr_theirfp_shows_message_when_non_otr_chat_window(void** state);
void cmd_otr_theirfp_shows_fingerprint(void** state);
void cmd_otr_start_shows_message_when_in_console(void** state);
void cmd_otr_start_shows_message_when_in_muc(void** state);
void cmd_otr_start_shows_message_when_in_private(void** state);
void cmd_otr_start_shows_message_when_already_started(void** state);
void cmd_otr_start_shows_message_when_no_key(void** state);
void cmd_otr_start_sends_otr_query_message_to_current_recipeint(void** state);
#else
void cmd_otr_shows_message_when_otr_unsupported(void** state);
#endif

View File

@@ -1,16 +0,0 @@
#include "config.h"
#ifdef HAVE_LIBGPGME
void cmd_pgp_shows_usage_when_no_args(void** state);
void cmd_pgp_start_shows_message_when_disconnected(void** state);
void cmd_pgp_start_shows_message_when_disconnecting(void** state);
void cmd_pgp_start_shows_message_when_connecting(void** state);
void cmd_pgp_start_shows_message_when_undefined(void** state);
void cmd_pgp_start_shows_message_when_no_arg_in_console(void** state);
void cmd_pgp_start_shows_message_when_no_arg_in_muc(void** state);
void cmd_pgp_start_shows_message_when_no_arg_in_conf(void** state);
void cmd_pgp_start_shows_message_when_no_arg_in_private(void** state);
void cmd_pgp_start_shows_message_when_no_arg_in_xmlconsole(void** state);
#else
void cmd_pgp_shows_message_when_pgp_unsupported(void** state);
#endif

View File

@@ -1,13 +0,0 @@
void cmd_presence_shows_usage_when_bad_subcmd(void** state);
void cmd_presence_shows_usage_when_bad_console_setting(void** state);
void cmd_presence_shows_usage_when_bad_chat_setting(void** state);
void cmd_presence_shows_usage_when_bad_muc_setting(void** state);
void cmd_presence_console_sets_all(void** state);
void cmd_presence_console_sets_online(void** state);
void cmd_presence_console_sets_none(void** state);
void cmd_presence_chat_sets_all(void** state);
void cmd_presence_chat_sets_online(void** state);
void cmd_presence_chat_sets_none(void** state);
void cmd_presence_room_sets_all(void** state);
void cmd_presence_room_sets_online(void** state);
void cmd_presence_room_sets_none(void** state);

View File

@@ -1,7 +0,0 @@
void cmd_rooms_shows_message_when_disconnected(void** state);
void cmd_rooms_shows_message_when_disconnecting(void** state);
void cmd_rooms_shows_message_when_connecting(void** state);
void cmd_rooms_shows_message_when_undefined(void** state);
void cmd_rooms_uses_account_default_when_no_arg(void** state);
void cmd_rooms_service_arg_used_when_passed(void** state);
void cmd_rooms_filter_arg_used_when_passed(void** state);

View File

@@ -1,17 +0,0 @@
void cmd_roster_shows_message_when_disconnecting(void** state);
void cmd_roster_shows_message_when_connecting(void** state);
void cmd_roster_shows_message_when_disconnected(void** state);
void cmd_roster_shows_message_when_undefined(void** state);
void cmd_roster_shows_roster_when_no_args(void** state);
void cmd_roster_add_shows_message_when_no_jid(void** state);
void cmd_roster_add_sends_roster_add_request(void** state);
void cmd_roster_remove_shows_message_when_no_jid(void** state);
void cmd_roster_remove_sends_roster_remove_request(void** state);
void cmd_roster_remove_nickname_sends_roster_remove_request(void** state);
void cmd_roster_nick_shows_message_when_no_jid(void** state);
void cmd_roster_nick_shows_message_when_no_nick(void** state);
void cmd_roster_nick_shows_message_when_no_contact_exists(void** state);
void cmd_roster_nick_sends_name_change_request(void** state);
void cmd_roster_clearnick_shows_message_when_no_jid(void** state);
void cmd_roster_clearnick_shows_message_when_no_contact_exists(void** state);
void cmd_roster_clearnick_sends_name_change_request_with_empty_nick(void** state);

View File

@@ -1,10 +1,21 @@
/*
* test_common.c
*
* Copyright (C) 2015 - 2017 James Booth <boothj5@gmail.com>
* Copyright (C) 2015 - 2026 Michael Vetter <jubalh@iodoru.org>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include "xmpp/resource.h"
#include "common.h"
#include "prof_cmocka.h"
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include "tests/unittests/ui/stub_ui.h" // Include for mocking cons_show
void
replace_one_substr(void** state)
str_replace__returns__one_substr(void** state)
{
char* string = "it is a string";
char* sub = "is";
@@ -18,7 +29,7 @@ replace_one_substr(void** state)
}
void
replace_one_substr_beginning(void** state)
str_replace__returns__one_substr_beginning(void** state)
{
char* string = "it is a string";
char* sub = "it";
@@ -32,7 +43,7 @@ replace_one_substr_beginning(void** state)
}
void
replace_one_substr_end(void** state)
str_replace__returns__one_substr_end(void** state)
{
char* string = "it is a string";
char* sub = "string";
@@ -46,7 +57,7 @@ replace_one_substr_end(void** state)
}
void
replace_two_substr(void** state)
str_replace__returns__two_substr(void** state)
{
char* string = "it is a is string";
char* sub = "is";
@@ -60,7 +71,7 @@ replace_two_substr(void** state)
}
void
replace_char(void** state)
str_replace__returns__char(void** state)
{
char* string = "some & a thing & something else";
char* sub = "&";
@@ -74,7 +85,7 @@ replace_char(void** state)
}
void
replace_when_none(void** state)
str_replace__returns__original_when_none(void** state)
{
char* string = "its another string";
char* sub = "haha";
@@ -88,7 +99,7 @@ replace_when_none(void** state)
}
void
replace_when_match(void** state)
str_replace__returns__replaced_when_match(void** state)
{
char* string = "hello";
char* sub = "hello";
@@ -102,7 +113,7 @@ replace_when_match(void** state)
}
void
replace_when_string_empty(void** state)
str_replace__returns__empty_when_string_empty(void** state)
{
char* string = "";
char* sub = "hello";
@@ -116,7 +127,7 @@ replace_when_string_empty(void** state)
}
void
replace_when_string_null(void** state)
str_replace__returns__null_when_string_null(void** state)
{
char* string = NULL;
char* sub = "hello";
@@ -128,7 +139,7 @@ replace_when_string_null(void** state)
}
void
replace_when_sub_empty(void** state)
str_replace__returns__original_when_sub_empty(void** state)
{
char* string = "hello";
char* sub = "";
@@ -142,7 +153,7 @@ replace_when_sub_empty(void** state)
}
void
replace_when_sub_null(void** state)
str_replace__returns__original_when_sub_null(void** state)
{
char* string = "hello";
char* sub = NULL;
@@ -156,7 +167,7 @@ replace_when_sub_null(void** state)
}
void
replace_when_new_empty(void** state)
str_replace__returns__empty_when_new_empty(void** state)
{
char* string = "hello";
char* sub = "hello";
@@ -170,7 +181,7 @@ replace_when_new_empty(void** state)
}
void
replace_when_new_null(void** state)
str_replace__returns__original_when_new_null(void** state)
{
char* string = "hello";
char* sub = "hello";
@@ -184,55 +195,55 @@ replace_when_new_null(void** state)
}
void
test_online_is_valid_resource_presence_string(void** state)
valid_resource_presence_string__is__true_for_online(void** state)
{
assert_true(valid_resource_presence_string("online"));
}
void
test_chat_is_valid_resource_presence_string(void** state)
valid_resource_presence_string__is__true_for_chat(void** state)
{
assert_true(valid_resource_presence_string("chat"));
}
void
test_away_is_valid_resource_presence_string(void** state)
valid_resource_presence_string__is__true_for_away(void** state)
{
assert_true(valid_resource_presence_string("away"));
}
void
test_xa_is_valid_resource_presence_string(void** state)
valid_resource_presence_string__is__true_for_xa(void** state)
{
assert_true(valid_resource_presence_string("xa"));
}
void
test_dnd_is_valid_resource_presence_string(void** state)
valid_resource_presence_string__is__true_for_dnd(void** state)
{
assert_true(valid_resource_presence_string("dnd"));
}
void
test_available_is_not_valid_resource_presence_string(void** state)
valid_resource_presence_string__is__false_for_available(void** state)
{
assert_false(valid_resource_presence_string("available"));
}
void
test_unavailable_is_not_valid_resource_presence_string(void** state)
valid_resource_presence_string__is__false_for_unavailable(void** state)
{
assert_false(valid_resource_presence_string("unavailable"));
}
void
test_blah_is_not_valid_resource_presence_string(void** state)
valid_resource_presence_string__is__false_for_blah(void** state)
{
assert_false(valid_resource_presence_string("blah"));
}
void
utf8_display_len_null_str(void** state)
utf8_display_len__returns__0_for_null(void** state)
{
int result = utf8_display_len(NULL);
@@ -240,7 +251,7 @@ utf8_display_len_null_str(void** state)
}
void
utf8_display_len_1_non_wide(void** state)
utf8_display_len__returns__1_for_non_wide(void** state)
{
int result = utf8_display_len("1");
@@ -248,7 +259,7 @@ utf8_display_len_1_non_wide(void** state)
}
void
utf8_display_len_1_wide(void** state)
utf8_display_len__returns__2_for_wide(void** state)
{
int result = utf8_display_len("");
@@ -256,7 +267,7 @@ utf8_display_len_1_wide(void** state)
}
void
utf8_display_len_non_wide(void** state)
utf8_display_len__returns__correct_for_non_wide(void** state)
{
int result = utf8_display_len("123456789abcdef");
@@ -264,7 +275,7 @@ utf8_display_len_non_wide(void** state)
}
void
utf8_display_len_wide(void** state)
utf8_display_len__returns__correct_for_wide(void** state)
{
int result = utf8_display_len("12三四56");
@@ -272,7 +283,7 @@ utf8_display_len_wide(void** state)
}
void
utf8_display_len_all_wide(void** state)
utf8_display_len__returns__correct_for_all_wide(void** state)
{
int result = utf8_display_len("ひらがな");
@@ -280,7 +291,7 @@ utf8_display_len_all_wide(void** state)
}
void
strip_quotes_does_nothing_when_no_quoted(void** state)
strip_arg_quotes__returns__original_when_no_quotes(void** state)
{
char* input = "/cmd test string";
@@ -292,7 +303,7 @@ strip_quotes_does_nothing_when_no_quoted(void** state)
}
void
strip_quotes_strips_first(void** state)
strip_arg_quotes__returns__stripped_first(void** state)
{
char* input = "/cmd \"test string";
@@ -304,7 +315,7 @@ strip_quotes_strips_first(void** state)
}
void
strip_quotes_strips_last(void** state)
strip_arg_quotes__returns__stripped_last(void** state)
{
char* input = "/cmd test string\"";
@@ -316,7 +327,7 @@ strip_quotes_strips_last(void** state)
}
void
strip_quotes_strips_both(void** state)
strip_arg_quotes__returns__stripped_both(void** state)
{
char* input = "/cmd \"test string\"";
@@ -327,6 +338,317 @@ strip_quotes_strips_both(void** state)
free(result);
}
void
strip_arg_quotes__unescapes(void** state)
{
char* input = "\"Thor \\\"The Thunderer\\\" Odinson\"";
char* result = strip_arg_quotes(input);
assert_string_equal("Thor \"The Thunderer\" Odinson", result);
free(result);
}
void
valid_tls_policy_option__is__correct_for_various_inputs(void** state)
{
// Valid inputs
assert_true(valid_tls_policy_option("force"));
assert_true(valid_tls_policy_option("allow"));
assert_true(valid_tls_policy_option("trust"));
assert_true(valid_tls_policy_option("disable"));
assert_true(valid_tls_policy_option("legacy"));
assert_true(valid_tls_policy_option("direct"));
// Invalid inputs
// Not an option
expect_any_cons_show(); // For "Invalid TLS policy: 'profanity'"
expect_any_cons_show(); // For "TLS policy must be one of: 'force', 'allow', 'trust', 'disable', 'legacy', or 'direct'."
assert_false(valid_tls_policy_option("profanity"));
// Empty
expect_any_cons_show(); // For "Invalid TLS policy: ''"
expect_any_cons_show(); // For "TLS policy must be one of: 'force', 'allow', 'trust', 'disable', 'legacy', or 'direct'."
assert_false(valid_tls_policy_option(""));
// NULL
assert_true(valid_tls_policy_option(NULL));
}
void
get_expanded_path__returns__expanded(void** state)
{
gchar* expanded_path;
// `file://` prefix
expanded_path = get_expanded_path("file:///tmp/test.txt");
assert_string_equal("/tmp/test.txt", expanded_path);
g_free(expanded_path);
// `~/"` prefix
setenv("HOME", "/home/test", 1);
expanded_path = get_expanded_path("~/folder/file.txt");
assert_string_equal("/home/test/folder/file.txt", expanded_path);
g_free(expanded_path);
unsetenv("HOME");
// regular path
expanded_path = get_expanded_path("/home/test/file.pdf");
assert_string_equal("/home/test/file.pdf", expanded_path);
g_free(expanded_path);
// empty path
expanded_path = get_expanded_path("");
assert_string_equal("", expanded_path);
g_free(expanded_path);
}
void
strtoi_range__returns__true_for_valid_input(void** state)
{
int value;
gchar* err_msg = NULL;
gboolean result;
result = strtoi_range("10", &value, 0, 20, &err_msg);
assert_true(result);
assert_int_equal(10, value);
assert_null(err_msg);
result = strtoi_range("0", &value, 0, 20, &err_msg);
assert_true(result);
assert_int_equal(0, value);
assert_null(err_msg);
result = strtoi_range("20", &value, 0, 20, &err_msg);
assert_true(result);
assert_int_equal(20, value);
assert_null(err_msg);
result = strtoi_range("-5", &value, -10, 0, &err_msg);
assert_true(result);
assert_int_equal(-5, value);
assert_null(err_msg);
}
void
strtoi_range__returns__false_for_out_of_range(void** state)
{
int value;
gchar* err_msg = NULL;
gboolean result;
// too low, negative
result = strtoi_range("-11", &value, -10, 0, &err_msg);
assert_false(result);
assert_string_equal("Value -11 out of range. Must be in -10..0.", err_msg);
g_free(err_msg);
err_msg = NULL;
// too low
result = strtoi_range("-1", &value, 0, 10, &err_msg);
assert_false(result);
assert_string_equal("Value -1 out of range. Must be in 0..10.", err_msg);
g_free(err_msg);
err_msg = NULL;
// too high
result = strtoi_range("11", &value, 0, 10, &err_msg);
assert_false(result);
assert_string_equal("Value 11 out of range. Must be in 0..10.", err_msg);
g_free(err_msg);
err_msg = NULL;
}
void
strtoi_range__returns__false_for_invalid_input(void** state)
{
int value;
gchar* err_msg = NULL;
gboolean result;
// not a number
result = strtoi_range("profanity", &value, 0, 10, &err_msg);
assert_false(result);
assert_string_equal("Could not convert \"profanity\" to a number.", err_msg);
g_free(err_msg);
err_msg = NULL;
// not a number, start with digits
result = strtoi_range("23kk", &value, 0, 10, &err_msg);
assert_false(result);
assert_string_equal("Could not convert \"23kk\" to a number.", err_msg);
g_free(err_msg);
err_msg = NULL;
}
void
strtoi_range__returns__false_for_null_empty_input(void** state)
{
int value;
gchar* err_msg = NULL;
gboolean result;
// NULL input string
result = strtoi_range(NULL, &value, 0, 10, &err_msg);
assert_false(result);
assert_string_equal("'str' input pointer can not be NULL", err_msg);
g_free(err_msg);
err_msg = NULL;
// Empty input string
result = strtoi_range("", &value, 0, 10, &err_msg);
assert_false(result);
assert_string_equal("Could not convert \"\" to a number.", err_msg);
g_free(err_msg);
err_msg = NULL;
}
void
strtoi_range__returns__correct_values_when_err_msg_null(void** state)
{
int value;
gboolean result;
// valid conversion, err_msg is NULL
result = strtoi_range("5", &value, 0, 10, NULL);
assert_true(result);
assert_int_equal(5, value);
// invalid conversion, err_msg is NULL
result = strtoi_range("profanity", &value, 0, 10, NULL);
assert_false(result);
}
void
strtoi_range__returns__false_for_integer_overflow_underflow(void** state)
{
int value;
gchar* err_msg = NULL;
gboolean result;
char buf[64];
// INT_MAX + 1 overflows
snprintf(buf, sizeof(buf), "%lld", (long long)INT_MAX + 1);
result = strtoi_range(buf, &value, INT_MIN, INT_MAX, &err_msg);
assert_false(result);
g_free(err_msg);
err_msg = NULL;
// INT_MIN - 1 underflows
snprintf(buf, sizeof(buf), "%lld", (long long)INT_MIN - 1);
result = strtoi_range(buf, &value, INT_MIN, INT_MAX, &err_msg);
assert_false(result);
g_free(err_msg);
err_msg = NULL;
// Extreme overflow, larger than `long`
result = strtoi_range("9999999999999999999999999999999999", &value, INT_MIN, INT_MAX, &err_msg);
assert_false(result);
g_free(err_msg);
err_msg = NULL;
}
void
strtoi_range__returns_consistent_with_strtol_parsing(void** state)
{
int value;
gchar* err_msg = NULL;
gboolean result;
// Hexadecimal: "0x10" -> 16
result = strtoi_range("0x10", &value, 0, 100, &err_msg);
assert_true(result);
assert_int_equal(16, value);
g_free(err_msg);
err_msg = NULL;
// Octal: "010" -> 8
result = strtoi_range("010", &value, 0, 100, &err_msg);
assert_true(result);
assert_int_equal(8, value);
g_free(err_msg);
err_msg = NULL;
// Floating point "0.8" should fail: '.' is not a valid integer char
result = strtoi_range("0.8", &value, -10, 10, &err_msg);
assert_false(result);
g_free(err_msg);
err_msg = NULL;
}
void
string_to_verbosity__returns__correct_values(void** state)
{
int verbosity;
gchar* err_msg = NULL;
gboolean result;
// Valid input string (0)
result = string_to_verbosity("0", &verbosity, &err_msg);
assert_true(result);
assert_int_equal(0, verbosity);
assert_null(err_msg);
g_free(err_msg);
err_msg = NULL; // Clear for next test
// Valid input string (1)
result = string_to_verbosity("1", &verbosity, &err_msg);
assert_true(result);
assert_int_equal(1, verbosity);
assert_null(err_msg);
g_free(err_msg);
err_msg = NULL;
// Valid input string (3)
result = string_to_verbosity("3", &verbosity, &err_msg);
assert_true(result);
assert_int_equal(3, verbosity);
assert_null(err_msg);
g_free(err_msg);
err_msg = NULL;
// Invalid input string (not a number)
result = string_to_verbosity("profanity", &verbosity, &err_msg);
assert_false(result);
assert_string_equal("Could not convert \"profanity\" to a number.", err_msg);
g_free(err_msg);
err_msg = NULL;
// Valid input string, out of range (too low)
result = string_to_verbosity("-1", &verbosity, &err_msg);
assert_false(result);
assert_string_equal("Value -1 out of range. Must be in 0..3.", err_msg);
g_free(err_msg);
err_msg = NULL;
// Valid input string, out of range (too high)
result = string_to_verbosity("4", &verbosity, &err_msg);
assert_false(result);
assert_string_equal("Value 4 out of range. Must be in 0..3.", err_msg);
g_free(err_msg);
err_msg = NULL;
// NULL input string
result = string_to_verbosity(NULL, &verbosity, &err_msg);
assert_false(result);
assert_string_equal("'str' input pointer can not be NULL", err_msg);
g_free(err_msg);
err_msg = NULL;
// Empty input string
result = string_to_verbosity("", &verbosity, &err_msg);
assert_false(result);
assert_string_equal("Could not convert \"\" to a number.", err_msg);
g_free(err_msg);
err_msg = NULL;
// err_msg is NULL
result = string_to_verbosity("abc", &verbosity, NULL);
assert_false(result);
}
typedef struct
{
char* template;
@@ -336,7 +658,7 @@ typedef struct
} format_call_external_argv_t;
void
format_call_external_argv_td(void** state)
format_call_external_argv__tests__table_driven(void** state)
{
enum table { num_tests = 4 };
@@ -393,7 +715,7 @@ typedef struct
} unique_filename_from_url_t;
void
unique_filename_from_url_td(void** state)
unique_filename_from_url__tests__table_driven(void** state)
{
enum table { num_tests = 15 };
@@ -500,8 +822,8 @@ unique_filename_from_url_td(void** state)
assert_string_equal(got_filename, exp_filename);
free(got_filename);
free(exp_filename);
g_free(got_filename);
g_free(exp_filename);
}
}
@@ -531,7 +853,7 @@ _lists_equal(GSList* a, GSList* b)
}
void
prof_occurrences_of_large_message_tests(void** state)
prof_occurrences__tests__large_message(void** state)
{
GSList* actual = NULL;
GSList* expected = NULL;
@@ -553,7 +875,7 @@ prof_occurrences_of_large_message_tests(void** state)
}
void
prof_partial_occurrences_tests(void** state)
prof_occurrences__tests__partial(void** state)
{
GSList* actual = NULL;
GSList* expected = NULL;
@@ -645,7 +967,132 @@ prof_partial_occurrences_tests(void** state)
}
void
prof_whole_occurrences_tests(void** state)
get_mentions__tests__various(void** state)
{
GSList* actual = NULL;
GSList* expected = NULL;
// Basic match, case sensitive
expected = g_slist_append(expected, GINT_TO_POINTER(6));
actual = get_mentions(FALSE, TRUE, "hello boothj5", "boothj5");
assert_true(_lists_equal(actual, expected));
g_slist_free(actual);
actual = NULL;
g_slist_free(expected);
expected = NULL;
// Case insensitive match
expected = g_slist_append(expected, GINT_TO_POINTER(6));
actual = get_mentions(FALSE, FALSE, "hello BOOTHJ5", "boothj5");
assert_true(_lists_equal(actual, expected));
g_slist_free(actual);
actual = NULL;
g_slist_free(expected);
expected = NULL;
// Whole word match
expected = g_slist_append(expected, GINT_TO_POINTER(0));
actual = get_mentions(TRUE, TRUE, "boothj5 hello", "boothj5");
assert_true(_lists_equal(actual, expected));
g_slist_free(actual);
actual = NULL;
g_slist_free(expected);
expected = NULL;
// Whole word no match (partial)
actual = get_mentions(TRUE, TRUE, "boothj5hello", "boothj5");
assert_true(_lists_equal(actual, expected)); // expected is NULL
g_slist_free(actual);
actual = NULL;
// Multiple matches
expected = g_slist_append(expected, GINT_TO_POINTER(0));
expected = g_slist_append(expected, GINT_TO_POINTER(14));
actual = get_mentions(FALSE, TRUE, "boothj5 hello boothj5", "boothj5");
assert_true(_lists_equal(actual, expected));
g_slist_free(actual);
actual = NULL;
g_slist_free(expected);
expected = NULL;
// Nick with punctuation (whole word)
expected = g_slist_append(expected, GINT_TO_POINTER(0));
actual = get_mentions(TRUE, TRUE, "boothj5: hi", "boothj5");
assert_true(_lists_equal(actual, expected));
g_slist_free(actual);
actual = NULL;
g_slist_free(expected);
expected = NULL;
// Nick surrounded by punctuation
expected = g_slist_append(expected, GINT_TO_POINTER(1));
actual = get_mentions(TRUE, TRUE, "(boothj5)", "boothj5");
assert_true(_lists_equal(actual, expected));
g_slist_free(actual);
actual = NULL;
g_slist_free(expected);
expected = NULL;
// Empty message
actual = get_mentions(FALSE, TRUE, "", "boothj5");
assert_true(_lists_equal(actual, expected)); // expected is NULL
g_slist_free(actual);
actual = NULL;
// Empty nick
actual = get_mentions(FALSE, TRUE, "hello", "");
assert_true(_lists_equal(actual, expected)); // expected is NULL
g_slist_free(actual);
actual = NULL;
// UTF-8 characters
expected = g_slist_append(expected, GINT_TO_POINTER(0));
actual = get_mentions(TRUE, TRUE, "我能 hello", "我能");
assert_true(_lists_equal(actual, expected));
g_slist_free(actual);
actual = NULL;
g_slist_free(expected);
expected = NULL;
}
void
release_is_new__tests__various(void** state)
{
// Higher major version
assert_true(release_is_new("0.16.0", "1.0.0"));
// Higher minor version
assert_true(release_is_new("0.16.0", "0.17.0"));
// Higher patch version
assert_true(release_is_new("0.16.0", "0.16.1"));
// Same version
assert_false(release_is_new("0.16.0", "0.16.0"));
// Lower major version
assert_false(release_is_new("0.16.0", "0.15.9"));
// Lower minor version
assert_false(release_is_new("0.16.0", "0.15.0"));
// Lower patch version
assert_false(release_is_new("0.16.1", "0.16.0"));
// Higher version but with different current versions
assert_true(release_is_new("1.2.3", "1.2.4"));
assert_true(release_is_new("1.2.3", "1.3.0"));
assert_true(release_is_new("1.2.3", "2.0.0"));
// Malformed version strings
assert_false(release_is_new("0.16.0", "0.16")); // Missing patch in found
assert_false(release_is_new("0.16", "0.16.0")); // Missing patch in curr
assert_false(release_is_new("0.16.0", "0.16.0.1")); // Extra part
assert_false(release_is_new("0.16.0", "abc.def.ghi"));
assert_false(release_is_new("0.16.0", ""));
assert_false(release_is_new(NULL, "1.0.0"));
assert_false(release_is_new("1.0.0", NULL));
}
void
prof_occurrences__tests__whole(void** state)
{
GSList* actual = NULL;
GSList* expected = NULL;
@@ -846,3 +1293,94 @@ prof_whole_occurrences_tests(void** state)
g_slist_free(expected);
expected = NULL;
}
void
string_matches_one_of__tests__edge_cases(void** state)
{
// is is NULL, is_can_be_null is TRUE -> should return TRUE
assert_true(string_matches_one_of(NULL, NULL, TRUE, "option1", "option2", NULL));
// is is NULL, is_can_be_null is FALSE -> should return FALSE
assert_false(string_matches_one_of(NULL, NULL, FALSE, "option1", "option2", NULL));
// is matches one of the options
assert_true(string_matches_one_of("Test", "option1", FALSE, "option1", "option2", NULL));
assert_true(string_matches_one_of("Test", "option2", FALSE, "option1", "option2", NULL));
// is does not match any of the options
expect_any_cons_show(); // For "Invalid Test: 'option3'"
expect_any_cons_show(); // For "Test must be one of: 'option1', or 'option2'."
assert_false(string_matches_one_of("Test", "option3", FALSE, "option1", "option2", NULL));
// what is NULL (no error message printed)
assert_false(string_matches_one_of(NULL, "option3", FALSE, "option1", "option2", NULL));
// Empty options list (first is NULL)
expect_any_cons_show(); // For "Invalid Test: 'option1'"
expect_any_cons_show(); // For "Test must be one of: ." (empty options list error message)
assert_false(string_matches_one_of("Test", "option1", FALSE, NULL, NULL));
assert_false(string_matches_one_of(NULL, NULL, FALSE, NULL, NULL));
assert_true(string_matches_one_of(NULL, NULL, TRUE, NULL, NULL));
// Single option, matches
assert_true(string_matches_one_of("Test", "single", FALSE, "single", NULL));
// Single option, no match
expect_any_cons_show(); // For "Invalid Test: 'nomatch'"
expect_any_cons_show(); // For "Test must be one of: 'single'."
assert_false(string_matches_one_of("Test", "nomatch", FALSE, "single", NULL));
// Multiple options, first matches
assert_true(string_matches_one_of("Test", "first", FALSE, "first", "second", "third", NULL));
// Multiple options, middle matches
assert_true(string_matches_one_of("Test", "second", FALSE, "first", "second", "third", NULL));
// Multiple options, last matches
assert_true(string_matches_one_of("Test", "third", FALSE, "first", "second", "third", NULL));
// Multiple options, no match
expect_any_cons_show(); // For "Invalid Test: 'none'"
expect_any_cons_show(); // For "Test must be one of: 'first', 'second', or 'third'."
assert_false(string_matches_one_of("Test", "none", FALSE, "first", "second", "third", NULL));
// is is an empty string, options are not
expect_any_cons_show(); // For "Invalid Test: ''"
expect_any_cons_show(); // For "Test must be one of: 'option1', or 'option2'."
assert_false(string_matches_one_of("Test", "", FALSE, "option1", "option2", NULL));
// is is an empty string, one of the options is an empty string
assert_true(string_matches_one_of("Test", "", FALSE, "option1", "", "option2", NULL));
}
void
str_xml_sanitize__strips_illegal_characters(void** state)
{
// Test NULL input
assert_null(str_xml_sanitize(NULL));
// Test empty string
gchar* res1 = str_xml_sanitize("");
assert_string_equal("", res1);
g_free(res1);
// Test string with no illegal characters
gchar* res2 = str_xml_sanitize("Hello World! \t\n\r");
assert_string_equal("Hello World! \t\n\r", res2);
g_free(res2);
// Test string with illegal characters (0x16 is ^V, 0x01 is ^A)
gchar* res3 = str_xml_sanitize("Hello\x16World\x01!");
assert_string_equal("HelloWorld!", res3);
g_free(res3);
// Test string with mixed legal and illegal control characters
gchar* res4 = str_xml_sanitize("\x09Legal\x0BIllegal\x0ALegal\x1FIllegal\x0DLegal");
assert_string_equal("\tLegalIllegal\nLegalIllegal\rLegal", res4);
g_free(res4);
// Test UTF-8 characters
gchar* res5 = str_xml_sanitize("UTF-8: üñîçøðé \x16 and more");
assert_string_equal("UTF-8: üñîçøðé and more", res5);
g_free(res5);
}

View File

@@ -1,36 +1,68 @@
void replace_one_substr(void** state);
void replace_one_substr_beginning(void** state);
void replace_one_substr_end(void** state);
void replace_two_substr(void** state);
void replace_char(void** state);
void replace_when_none(void** state);
void replace_when_match(void** state);
void replace_when_string_empty(void** state);
void replace_when_string_null(void** state);
void replace_when_sub_empty(void** state);
void replace_when_sub_null(void** state);
void replace_when_new_empty(void** state);
void replace_when_new_null(void** state);
void test_online_is_valid_resource_presence_string(void** state);
void test_chat_is_valid_resource_presence_string(void** state);
void test_away_is_valid_resource_presence_string(void** state);
void test_xa_is_valid_resource_presence_string(void** state);
void test_dnd_is_valid_resource_presence_string(void** state);
void test_available_is_not_valid_resource_presence_string(void** state);
void test_unavailable_is_not_valid_resource_presence_string(void** state);
void test_blah_is_not_valid_resource_presence_string(void** state);
void utf8_display_len_null_str(void** state);
void utf8_display_len_1_non_wide(void** state);
void utf8_display_len_1_wide(void** state);
void utf8_display_len_non_wide(void** state);
void utf8_display_len_wide(void** state);
void utf8_display_len_all_wide(void** state);
void strip_quotes_does_nothing_when_no_quoted(void** state);
void strip_quotes_strips_first(void** state);
void strip_quotes_strips_last(void** state);
void strip_quotes_strips_both(void** state);
void prof_partial_occurrences_tests(void** state);
void prof_whole_occurrences_tests(void** state);
void prof_occurrences_of_large_message_tests(void** state);
void unique_filename_from_url_td(void** state);
void format_call_external_argv_td(void** state);
/*
* test_common.h
*
* Copyright (C) 2015 - 2016 James Booth <boothj5@gmail.com>
* Copyright (C) 2018 - 2026 Michael Vetter <jubalh@iodoru.org>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#ifndef TESTS_TEST_COMMON_H
#define TESTS_TEST_COMMON_H
void str_replace__returns__one_substr(void** state);
void str_replace__returns__one_substr_beginning(void** state);
void str_replace__returns__one_substr_end(void** state);
void str_replace__returns__two_substr(void** state);
void str_replace__returns__char(void** state);
void str_replace__returns__original_when_none(void** state);
void str_replace__returns__replaced_when_match(void** state);
void str_replace__returns__empty_when_string_empty(void** state);
void str_replace__returns__null_when_string_null(void** state);
void str_replace__returns__original_when_sub_empty(void** state);
void str_replace__returns__original_when_sub_null(void** state);
void str_replace__returns__empty_when_new_empty(void** state);
void str_replace__returns__original_when_new_null(void** state);
void valid_resource_presence_string__is__true_for_online(void** state);
void valid_resource_presence_string__is__true_for_chat(void** state);
void valid_resource_presence_string__is__true_for_away(void** state);
void valid_resource_presence_string__is__true_for_xa(void** state);
void valid_resource_presence_string__is__true_for_dnd(void** state);
void valid_resource_presence_string__is__false_for_available(void** state);
void valid_resource_presence_string__is__false_for_unavailable(void** state);
void valid_resource_presence_string__is__false_for_blah(void** state);
void utf8_display_len__returns__0_for_null(void** state);
void utf8_display_len__returns__1_for_non_wide(void** state);
void utf8_display_len__returns__2_for_wide(void** state);
void utf8_display_len__returns__correct_for_non_wide(void** state);
void utf8_display_len__returns__correct_for_wide(void** state);
void utf8_display_len__returns__correct_for_all_wide(void** state);
void strip_arg_quotes__returns__original_when_no_quotes(void** state);
void strip_arg_quotes__returns__stripped_first(void** state);
void strip_arg_quotes__returns__stripped_last(void** state);
void strip_arg_quotes__returns__stripped_both(void** state);
void strip_arg_quotes__unescapes(void** state);
void prof_occurrences__tests__partial(void** state);
void prof_occurrences__tests__whole(void** state);
void prof_occurrences__tests__large_message(void** state);
void unique_filename_from_url__tests__table_driven(void** state);
void format_call_external_argv__tests__table_driven(void** state);
void get_expanded_path__returns__expanded(void** state);
void string_to_verbosity__returns__correct_values(void** state);
void strtoi_range__returns__true_for_valid_input(void** state);
void strtoi_range__returns__false_for_out_of_range(void** state);
void strtoi_range__returns__false_for_invalid_input(void** state);
void strtoi_range__returns__false_for_null_empty_input(void** state);
void strtoi_range__returns__correct_values_when_err_msg_null(void** state);
void strtoi_range__returns__false_for_integer_overflow_underflow(void** state);
void strtoi_range__returns_consistent_with_strtol_parsing(void** state);
void string_matches_one_of__tests__edge_cases(void** state);
void valid_tls_policy_option__is__correct_for_various_inputs(void** state);
void get_mentions__tests__various(void** state);
void release_is_new__tests__various(void** state);
void str_xml_sanitize__strips_illegal_characters(void** state);
#endif

View File

@@ -1,24 +0,0 @@
void contact_in_group(void** state);
void contact_not_in_group(void** state);
void contact_name_when_name_exists(void** state);
void contact_jid_when_name_not_exists(void** state);
void contact_string_when_name_exists(void** state);
void contact_string_when_name_not_exists(void** state);
void contact_string_when_default_resource(void** state);
void contact_presence_offline(void** state);
void contact_presence_uses_highest_priority(void** state);
void contact_presence_chat_when_same_prioroty(void** state);
void contact_presence_online_when_same_prioroty(void** state);
void contact_presence_away_when_same_prioroty(void** state);
void contact_presence_xa_when_same_prioroty(void** state);
void contact_presence_dnd(void** state);
void contact_subscribed_when_to(void** state);
void contact_subscribed_when_both(void** state);
void contact_not_subscribed_when_from(void** state);
void contact_not_subscribed_when_no_subscription_value(void** state);
void contact_not_available(void** state);
void contact_not_available_when_highest_priority_away(void** state);
void contact_not_available_when_highest_priority_xa(void** state);
void contact_not_available_when_highest_priority_dnd(void** state);
void contact_available_when_highest_priority_online(void** state);
void contact_available_when_highest_priority_chat(void** state);

View File

@@ -1,21 +0,0 @@
void get_form_type_field_returns_null_no_fields(void** state);
void get_form_type_field_returns_null_when_not_present(void** state);
void get_form_type_field_returns_value_when_present(void** state);
void get_field_type_returns_unknown_when_no_fields(void** state);
void get_field_type_returns_correct_type(void** state);
void set_value_adds_when_none(void** state);
void set_value_updates_when_one(void** state);
void add_unique_value_adds_when_none(void** state);
void add_unique_value_does_nothing_when_exists(void** state);
void add_unique_value_adds_when_doesnt_exist(void** state);
void add_value_adds_when_none(void** state);
void add_value_adds_when_some(void** state);
void add_value_adds_when_exists(void** state);
void remove_value_does_nothing_when_none(void** state);
void remove_value_does_nothing_when_doesnt_exist(void** state);
void remove_value_removes_when_one(void** state);
void remove_value_removes_when_many(void** state);
void remove_text_multi_value_does_nothing_when_none(void** state);
void remove_text_multi_value_does_nothing_when_doesnt_exist(void** state);
void remove_text_multi_value_removes_when_one(void** state);
void remove_text_multi_value_removes_when_many(void** state);

View File

@@ -1,236 +0,0 @@
#include "prof_cmocka.h"
#include <stdlib.h>
#include "xmpp/jid.h"
void
create_jid_from_null_returns_null(void** state)
{
Jid* result = jid_create(NULL);
assert_null(result);
}
void
create_jid_from_empty_string_returns_null(void** state)
{
Jid* result = jid_create("");
assert_null(result);
}
void
create_jid_from_full_returns_full(void** state)
{
Jid* result = jid_create("myuser@mydomain/laptop");
assert_string_equal("myuser@mydomain/laptop", result->fulljid);
jid_destroy(result);
}
void
create_jid_from_full_returns_bare(void** state)
{
Jid* result = jid_create("myuser@mydomain/laptop");
assert_string_equal("myuser@mydomain", result->barejid);
jid_destroy(result);
}
void
create_jid_from_full_returns_resourcepart(void** state)
{
Jid* result = jid_create("myuser@mydomain/laptop");
assert_string_equal("laptop", result->resourcepart);
jid_destroy(result);
}
void
create_jid_from_full_returns_localpart(void** state)
{
Jid* result = jid_create("myuser@mydomain/laptop");
assert_string_equal("myuser", result->localpart);
jid_destroy(result);
}
void
create_jid_from_full_returns_domainpart(void** state)
{
Jid* result = jid_create("myuser@mydomain/laptop");
assert_string_equal("mydomain", result->domainpart);
jid_destroy(result);
}
void
create_jid_from_full_nolocal_returns_full(void** state)
{
Jid* result = jid_create("mydomain/laptop");
assert_string_equal("mydomain/laptop", result->fulljid);
jid_destroy(result);
}
void
create_jid_from_full_nolocal_returns_bare(void** state)
{
Jid* result = jid_create("mydomain/laptop");
assert_string_equal("mydomain", result->barejid);
jid_destroy(result);
}
void
create_jid_from_full_nolocal_returns_resourcepart(void** state)
{
Jid* result = jid_create("mydomain/laptop");
assert_string_equal("laptop", result->resourcepart);
jid_destroy(result);
}
void
create_jid_from_full_nolocal_returns_domainpart(void** state)
{
Jid* result = jid_create("mydomain/laptop");
assert_string_equal("mydomain", result->domainpart);
jid_destroy(result);
}
void
create_jid_from_full_nolocal_returns_null_localpart(void** state)
{
Jid* result = jid_create("mydomain/laptop");
assert_null(result->localpart);
jid_destroy(result);
}
void
create_jid_from_bare_returns_null_full(void** state)
{
Jid* result = jid_create("myuser@mydomain");
assert_null(result->fulljid);
jid_destroy(result);
}
void
create_jid_from_bare_returns_null_resource(void** state)
{
Jid* result = jid_create("myuser@mydomain");
assert_null(result->resourcepart);
jid_destroy(result);
}
void
create_jid_from_bare_returns_bare(void** state)
{
Jid* result = jid_create("myuser@mydomain");
assert_string_equal("myuser@mydomain", result->barejid);
jid_destroy(result);
}
void
create_jid_from_bare_returns_localpart(void** state)
{
Jid* result = jid_create("myuser@mydomain");
assert_string_equal("myuser", result->localpart);
jid_destroy(result);
}
void
create_jid_from_bare_returns_domainpart(void** state)
{
Jid* result = jid_create("myuser@mydomain");
assert_string_equal("mydomain", result->domainpart);
jid_destroy(result);
}
void
create_room_jid_returns_room(void** state)
{
Jid* result = jid_create_from_bare_and_resource("room@conference.domain.org", "myname");
assert_string_equal("room@conference.domain.org", result->barejid);
jid_destroy(result);
}
void
create_room_jid_returns_nick(void** state)
{
Jid* result = jid_create_from_bare_and_resource("room@conference.domain.org", "myname");
assert_string_equal("myname", result->resourcepart);
jid_destroy(result);
}
void
create_with_slash_in_resource(void** state)
{
Jid* result = jid_create("room@conference.domain.org/my/nick");
assert_string_equal("room", result->localpart);
assert_string_equal("conference.domain.org", result->domainpart);
assert_string_equal("my/nick", result->resourcepart);
assert_string_equal("room@conference.domain.org", result->barejid);
assert_string_equal("room@conference.domain.org/my/nick", result->fulljid);
jid_destroy(result);
}
void
create_with_at_in_resource(void** state)
{
Jid* result = jid_create("room@conference.domain.org/my@nick");
assert_string_equal("room", result->localpart);
assert_string_equal("conference.domain.org", result->domainpart);
assert_string_equal("my@nick", result->resourcepart);
assert_string_equal("room@conference.domain.org", result->barejid);
assert_string_equal("room@conference.domain.org/my@nick", result->fulljid);
jid_destroy(result);
}
void
create_with_at_and_slash_in_resource(void** state)
{
Jid* result = jid_create("room@conference.domain.org/my@nick/something");
assert_string_equal("room", result->localpart);
assert_string_equal("conference.domain.org", result->domainpart);
assert_string_equal("my@nick/something", result->resourcepart);
assert_string_equal("room@conference.domain.org", result->barejid);
assert_string_equal("room@conference.domain.org/my@nick/something", result->fulljid);
jid_destroy(result);
}
void
create_full_with_trailing_slash(void** state)
{
Jid* result = jid_create("room@conference.domain.org/nick/");
assert_string_equal("room", result->localpart);
assert_string_equal("conference.domain.org", result->domainpart);
assert_string_equal("nick/", result->resourcepart);
assert_string_equal("room@conference.domain.org", result->barejid);
assert_string_equal("room@conference.domain.org/nick/", result->fulljid);
jid_destroy(result);
}
void
returns_fulljid_when_exists(void** state)
{
Jid* jid = jid_create("localpart@domainpart/resourcepart");
const char* result = jid_fulljid_or_barejid(jid);
assert_string_equal("localpart@domainpart/resourcepart", result);
jid_destroy(jid);
}
void
returns_barejid_when_fulljid_not_exists(void** state)
{
Jid* jid = jid_create("localpart@domainpart");
const char* result = jid_fulljid_or_barejid(jid);
assert_string_equal("localpart@domainpart", result);
jid_destroy(jid);
}

View File

@@ -1,25 +0,0 @@
void create_jid_from_null_returns_null(void** state);
void create_jid_from_empty_string_returns_null(void** state);
void create_jid_from_full_returns_full(void** state);
void create_jid_from_full_returns_bare(void** state);
void create_jid_from_full_returns_resourcepart(void** state);
void create_jid_from_full_returns_localpart(void** state);
void create_jid_from_full_returns_domainpart(void** state);
void create_jid_from_full_nolocal_returns_full(void** state);
void create_jid_from_full_nolocal_returns_bare(void** state);
void create_jid_from_full_nolocal_returns_resourcepart(void** state);
void create_jid_from_full_nolocal_returns_domainpart(void** state);
void create_jid_from_full_nolocal_returns_null_localpart(void** state);
void create_jid_from_bare_returns_null_full(void** state);
void create_jid_from_bare_returns_null_resource(void** state);
void create_jid_from_bare_returns_bare(void** state);
void create_jid_from_bare_returns_localpart(void** state);
void create_jid_from_bare_returns_domainpart(void** state);
void create_room_jid_returns_room(void** state);
void create_room_jid_returns_nick(void** state);
void create_with_slash_in_resource(void** state);
void create_with_at_in_resource(void** state);
void create_with_at_and_slash_in_resource(void** state);
void create_full_with_trailing_slash(void** state);
void returns_fulljid_when_exists(void** state);
void returns_barejid_when_fulljid_not_exists(void** state);

View File

@@ -1,47 +0,0 @@
void append_to_empty(void **state);
void append_wide_to_empty(void **state);
void append_to_single(void **state);
void append_wide_to_single_non_wide(void **state);
void append_non_wide_to_single_wide(void **state);
void append_wide_to_single_wide(void **state);
void append_non_wide_when_overrun(void **state);
void insert_non_wide_to_non_wide(void **state);
void insert_single_non_wide_when_pad_scrolled(void **state);
void insert_many_non_wide_when_pad_scrolled(void **state);
void insert_single_non_wide_last_column(void **state);
void insert_many_non_wide_last_column(void **state);
void ctrl_left_when_no_input(void **state);
void ctrl_left_when_at_start(void **state);
void ctrl_left_when_in_first_word(void **state);
void ctrl_left_when_in_first_space(void **state);
void ctrl_left_when_at_start_of_second_word(void **state);
void ctrl_left_when_in_second_word(void **state);
void ctrl_left_when_at_end_of_second_word(void **state);
void ctrl_left_when_in_second_space(void **state);
void ctrl_left_when_at_start_of_third_word(void **state);
void ctrl_left_when_in_third_word(void **state);
void ctrl_left_when_at_end_of_third_word(void **state);
void ctrl_left_when_in_third_space(void **state);
void ctrl_left_when_at_end(void **state);
void ctrl_left_when_in_only_whitespace(void **state);
void ctrl_left_when_start_whitespace_start_of_word(void **state);
void ctrl_left_when_start_whitespace_middle_of_word(void **state);
void ctrl_left_in_whitespace_between_words(void **state);
void ctrl_left_in_whitespace_between_words_start_of_word(void **state);
void ctrl_left_in_whitespace_between_words_middle_of_word(void **state);
void ctrl_left_when_word_overrun_to_left(void **state);
void ctrl_right_when_no_input(void **state);
void ctrl_right_when_at_end(void **state);
void ctrl_right_one_word_at_start(void **state);
void ctrl_right_one_word_in_middle(void **state);
void ctrl_right_one_word_at_end(void **state);
void ctrl_right_two_words_from_middle_first(void **state);
void ctrl_right_two_words_from_end_first(void **state);
void ctrl_right_two_words_from_space(void **state);
void ctrl_right_two_words_from_start_second(void **state);
void ctrl_right_one_word_leading_whitespace(void **state);
void ctrl_right_two_words_in_whitespace(void **state);
void ctrl_right_trailing_whitespace_from_middle(void **state);

View File

@@ -1,9 +0,0 @@
int muc_before_test(void** state);
int muc_after_test(void** state);
void test_muc_invites_add(void** state);
void test_muc_remove_invite(void** state);
void test_muc_invites_count_0(void** state);
void test_muc_invites_count_5(void** state);
void test_muc_room_is_not_active(void** state);
void test_muc_active(void** state);

View File

@@ -1,50 +0,0 @@
void parse_null_returns_null(void** state);
void parse_empty_returns_null(void** state);
void parse_space_returns_null(void** state);
void parse_cmd_no_args_returns_null(void** state);
void parse_cmd_with_space_returns_null(void** state);
void parse_cmd_with_too_few_returns_null(void** state);
void parse_cmd_with_too_many_returns_null(void** state);
void parse_cmd_one_arg(void** state);
void parse_cmd_two_args(void** state);
void parse_cmd_three_args(void** state);
void parse_cmd_three_args_with_spaces(void** state);
void parse_cmd_with_freetext(void** state);
void parse_cmd_one_arg_with_freetext(void** state);
void parse_cmd_two_args_with_freetext(void** state);
void parse_cmd_min_zero(void** state);
void parse_cmd_min_zero_with_freetext(void** state);
void parse_cmd_with_quoted(void** state);
void parse_cmd_with_quoted_and_space(void** state);
void parse_cmd_with_quoted_and_many_spaces(void** state);
void parse_cmd_with_many_quoted_and_many_spaces(void** state);
void parse_cmd_freetext_with_quoted(void** state);
void parse_cmd_freetext_with_quoted_and_space(void** state);
void parse_cmd_freetext_with_quoted_and_many_spaces(void** state);
void parse_cmd_freetext_with_many_quoted_and_many_spaces(void** state);
void parse_cmd_with_quoted_freetext(void** state);
void parse_cmd_with_third_arg_quoted_0_min_3_max(void** state);
void parse_cmd_with_second_arg_quoted_0_min_3_max(void** state);
void parse_cmd_with_second_and_third_arg_quoted_0_min_3_max(void** state);
void count_one_token(void** state);
void count_one_token_quoted_no_whitespace(void** state);
void count_one_token_quoted_with_whitespace(void** state);
void count_two_tokens(void** state);
void count_two_tokens_first_quoted(void** state);
void count_two_tokens_second_quoted(void** state);
void count_two_tokens_both_quoted(void** state);
void get_first_of_one(void** state);
void get_first_of_two(void** state);
void get_first_two_of_three(void** state);
void get_first_two_of_three_first_quoted(void** state);
void get_first_two_of_three_second_quoted(void** state);
void get_first_two_of_three_first_and_second_quoted(void** state);
void parse_options_when_none_returns_empty_hasmap(void** state);
void parse_options_when_opt1_no_val_sets_error(void** state);
void parse_options_when_one_returns_map(void** state);
void parse_options_when_opt2_no_val_sets_error(void** state);
void parse_options_when_two_returns_map(void** state);
void parse_options_when_opt3_no_val_sets_error(void** state);
void parse_options_when_three_returns_map(void** state);
void parse_options_when_unknown_opt_sets_error(void** state);
void parse_options_with_duplicated_option_sets_error(void** state);

View File

@@ -1,7 +0,0 @@
void returns_empty_list_when_none(void** state);
void returns_added_feature(void** state);
void resets_features_on_close(void** state);
void returns_all_added_features(void** state);
void does_not_add_duplicate_feature(void** state);
void removes_plugin_features(void** state);
void does_not_remove_feature_when_more_than_one_reference(void** state);

View File

@@ -1,3 +0,0 @@
void statuses_console_defaults_to_all(void** state);
void statuses_chat_defaults_to_all(void** state);
void statuses_muc_defaults_to_all(void** state);

View File

@@ -1,35 +0,0 @@
void empty_list_when_none_added(void** state);
void contains_one_element(void** state);
void first_element_correct(void** state);
void contains_two_elements(void** state);
void first_and_second_elements_correct(void** state);
void contains_three_elements(void** state);
void first_three_elements_correct(void** state);
void add_twice_at_beginning_adds_once(void** state);
void add_twice_in_middle_adds_once(void** state);
void add_twice_at_end_adds_once(void** state);
void find_first_exists(void** state);
void find_second_exists(void** state);
void find_third_exists(void** state);
void find_returns_null(void** state);
void find_on_empty_returns_null(void** state);
void find_twice_returns_second_when_two_match(void** state);
void find_five_times_finds_fifth(void** state);
void find_twice_returns_first_when_two_match_and_reset(void** state);
void add_contact_with_no_group(void** state);
void add_contact_with_group(void** state);
void add_contact_with_two_groups(void** state);
void add_contact_with_three_groups(void** state);
void add_contact_with_three_groups_update_adding_two(void** state);
void add_contact_with_three_groups_update_removing_one(void** state);
void add_contact_with_three_groups_update_removing_two(void** state);
void add_contact_with_three_groups_update_removing_three(void** state);
void add_contact_with_three_groups_update_two_new(void** state);
void add_remove_contact_groups(void** state);
void add_contacts_with_different_groups(void** state);
void add_contacts_with_same_groups(void** state);
void add_contacts_with_overlapping_groups(void** state);
void remove_contact_with_remaining_in_group(void** state);
void get_contact_display_name(void** state);
void get_contact_display_name_is_barejid_if_name_is_empty(void** state);
void get_contact_display_name_is_passed_barejid_if_contact_does_not_exist(void** state);

View File

@@ -1,14 +0,0 @@
void console_doesnt_show_online_presence_when_set_none(void** state);
void console_shows_online_presence_when_set_online(void** state);
void console_shows_online_presence_when_set_all(void** state);
void console_doesnt_show_dnd_presence_when_set_none(void** state);
void console_doesnt_show_dnd_presence_when_set_online(void** state);
void console_shows_dnd_presence_when_set_all(void** state);
void handle_message_error_when_no_recipient(void** state);
void handle_message_error_when_recipient_cancel(void** state);
void handle_message_error_when_recipient_cancel_disables_chat_session(void** state);
void handle_message_error_when_recipient_and_no_type(void** state);
void handle_presence_error_when_no_recipient(void** state);
void handle_presence_error_when_from_recipient(void** state);
void handle_offline_removes_chat_session(void** state);
void lost_connection_clears_chat_sessions(void** state);

View File

@@ -1,3 +1,11 @@
/*
* stub_http_upload.c
*
* Copyright (C) 2017 James Booth <boothj5@gmail.com>
* Copyright (C) 2020 - 2026 Michael Vetter <jubalh@iodoru.org>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#ifndef TOOLS_HTTP_UPLOAD_H
#define TOOLS_HTTP_UPLOAD_H

View File

@@ -0,0 +1,375 @@
#include <glib.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include "xmpp/contact.h"
#include "tools/autocomplete.h"
void
autocomplete_complete__returns__null_when_empty(void** state)
{
Autocomplete ac = autocomplete_new();
char* result = autocomplete_complete(ac, "test", TRUE, FALSE);
assert_null(result);
autocomplete_free(ac);
free(result);
}
void
autocomplete_reset__updates__after_create(void** state)
{
Autocomplete ac = autocomplete_new();
autocomplete_reset(ac);
autocomplete_free(ac);
}
void
autocomplete_complete__returns__null_after_create(void** state)
{
Autocomplete ac = autocomplete_new();
char* result = autocomplete_complete(ac, "hello", TRUE, FALSE);
assert_null(result);
autocomplete_free(ac);
free(result);
}
void
autocomplete_create_list__returns__null_after_create(void** state)
{
Autocomplete ac = autocomplete_new();
GList* result = autocomplete_create_list(ac);
assert_null(result);
autocomplete_free(ac);
g_list_free_full(result, free);
}
void
autocomplete_add__updates__one_and_complete(void** state)
{
Autocomplete ac = autocomplete_new();
autocomplete_add(ac, "Hello");
char* result = autocomplete_complete(ac, "Hel", TRUE, FALSE);
assert_string_equal("Hello", result);
autocomplete_free(ac);
free(result);
}
void
autocomplete_complete__returns__first_of_two(void** state)
{
Autocomplete ac = autocomplete_new();
autocomplete_add(ac, "Hello");
autocomplete_add(ac, "Help");
char* result = autocomplete_complete(ac, "Hel", TRUE, FALSE);
assert_string_equal("Hello", result);
autocomplete_free(ac);
free(result);
}
void
autocomplete_complete__returns__second_of_two(void** state)
{
Autocomplete ac = autocomplete_new();
autocomplete_add(ac, "Hello");
autocomplete_add(ac, "Help");
char* result1 = autocomplete_complete(ac, "Hel", TRUE, FALSE);
char* result2 = autocomplete_complete(ac, result1, TRUE, FALSE);
assert_string_equal("Help", result2);
autocomplete_free(ac);
free(result1);
free(result2);
}
void
autocomplete_add__updates__two_elements(void** state)
{
Autocomplete ac = autocomplete_new();
autocomplete_add(ac, "Hello");
autocomplete_add(ac, "Help");
GList* result = autocomplete_create_list(ac);
assert_int_equal(2, g_list_length(result));
autocomplete_free(ac);
g_list_free_full(result, free);
}
void
autocomplete_add__updates__only_once_for_same_value(void** state)
{
Autocomplete ac = autocomplete_new();
autocomplete_add(ac, "Hello");
autocomplete_add(ac, "Hello");
GList* result = autocomplete_create_list(ac);
assert_int_equal(1, g_list_length(result));
autocomplete_free(ac);
g_list_free_full(result, free);
}
void
autocomplete_add__updates__existing_value(void** state)
{
Autocomplete ac = autocomplete_new();
autocomplete_add(ac, "Hello");
autocomplete_add(ac, "Hello");
GList* result = autocomplete_create_list(ac);
GList* first = g_list_nth(result, 0);
char* str = first->data;
assert_string_equal("Hello", str);
autocomplete_free(ac);
g_list_free_full(result, free);
}
void
autocomplete_complete__returns__accented_with_accented(void** state)
{
Autocomplete ac = autocomplete_new();
autocomplete_add(ac, "èâîô");
char* result = autocomplete_complete(ac, "èâ", TRUE, FALSE);
assert_string_equal("èâîô", result);
autocomplete_free(ac);
free(result);
}
void
autocomplete_complete__returns__accented_with_base(void** state)
{
Autocomplete ac = autocomplete_new();
autocomplete_add(ac, "èâîô");
char* result = autocomplete_complete(ac, "ea", TRUE, FALSE);
assert_string_equal("èâîô", result);
autocomplete_free(ac);
free(result);
}
void
autocomplete_complete__returns__both_with_accented(void** state)
{
Autocomplete ac = autocomplete_new();
autocomplete_add(ac, "eaooooo");
autocomplete_add(ac, "èâîô");
char* result1 = autocomplete_complete(ac, "èâ", TRUE, FALSE);
char* result2 = autocomplete_complete(ac, result1, TRUE, FALSE);
assert_string_equal("èâîô", result2);
autocomplete_free(ac);
free(result1);
free(result2);
}
void
autocomplete_complete__returns__both_with_base(void** state)
{
Autocomplete ac = autocomplete_new();
autocomplete_add(ac, "eaooooo");
autocomplete_add(ac, "èâîô");
char* result1 = autocomplete_complete(ac, "ea", TRUE, FALSE);
char* result2 = autocomplete_complete(ac, result1, TRUE, FALSE);
assert_string_equal("èâîô", result2);
autocomplete_free(ac);
free(result1);
free(result2);
}
void
autocomplete_complete__is__case_insensitive(void** state)
{
Autocomplete ac = autocomplete_new();
autocomplete_add(ac, "MyBuddy");
char* result = autocomplete_complete(ac, "myb", TRUE, FALSE);
assert_string_equal("MyBuddy", result);
autocomplete_free(ac);
free(result);
}
void
autocomplete_complete__returns__previous(void** state)
{
Autocomplete ac = autocomplete_new();
autocomplete_add(ac, "MyBuddy1");
autocomplete_add(ac, "MyBuddy2");
autocomplete_add(ac, "MyBuddy3");
char* result1 = autocomplete_complete(ac, "myb", TRUE, FALSE);
char* result2 = autocomplete_complete(ac, result1, TRUE, FALSE);
char* result3 = autocomplete_complete(ac, result2, TRUE, FALSE);
char* result4 = autocomplete_complete(ac, result3, TRUE, TRUE);
assert_string_equal("MyBuddy2", result4);
autocomplete_free(ac);
free(result1);
free(result2);
free(result3);
free(result4);
}
void
autocomplete_complete__returns__greek_false_match(void** state)
{
Autocomplete ac = autocomplete_new();
// Σωκράτης (Socrates) and Πλάτων (Plato)
autocomplete_add(ac, "Σωκράτης");
autocomplete_add(ac, "Πλάτων");
char* result = autocomplete_complete(ac, "Π", TRUE, FALSE);
assert_string_equal("Πλάτων", result);
autocomplete_free(ac);
free(result);
}
void
autocomplete_complete__returns__greek(void** state)
{
Autocomplete ac = autocomplete_new();
autocomplete_add(ac, "Αριστοτέλης");
char* result = autocomplete_complete(ac, "Αριστ", TRUE, FALSE);
assert_non_null(result);
assert_string_equal("Αριστοτέλης", result);
autocomplete_free(ac);
free(result);
}
void
autocomplete_complete__returns__greek_case_insensitive(void** state)
{
Autocomplete ac = autocomplete_new();
autocomplete_add(ac, "Σωκράτης");
// Case insensitive search for Socrates
// σω is the lowercase of Σω
char* result = autocomplete_complete(ac, "σω", TRUE, FALSE);
assert_non_null(result);
assert_string_equal("Σωκράτης", result);
autocomplete_free(ac);
free(result);
}
void
autocomplete_complete__returns__russian(void** state)
{
Autocomplete ac = autocomplete_new();
autocomplete_add(ac, "Достоевский");
autocomplete_add(ac, "Толстой");
autocomplete_add(ac, "Пушкин");
char* result = autocomplete_complete(ac, "дост", TRUE, FALSE);
assert_non_null(result);
assert_string_equal("Достоевский", result);
autocomplete_free(ac);
free(result);
}
void
autocomplete_complete__returns__chinese(void** state)
{
Autocomplete ac = autocomplete_new();
autocomplete_add(ac, "孙子");
autocomplete_add(ac, "诸葛亮");
char* result = autocomplete_complete(ac, "", TRUE, FALSE);
assert_non_null(result);
assert_string_equal("孙子", result);
autocomplete_free(ac);
free(result);
}
void
autocomplete_complete__returns__transliterated(void** state)
{
Autocomplete ac = autocomplete_new();
autocomplete_add(ac, "München");
// Match 'ü' with 'u'
char* result = autocomplete_complete(ac, "mun", TRUE, FALSE);
assert_non_null(result);
assert_string_equal("München", result);
autocomplete_free(ac);
free(result);
}
void
autocomplete_complete__returns__regular_ascii(void** state)
{
Autocomplete ac = autocomplete_new();
autocomplete_add(ac, "London");
char* result = autocomplete_complete(ac, "lon", TRUE, FALSE);
assert_non_null(result);
assert_string_equal("London", result);
autocomplete_free(ac);
free(result);
}
void
autocomplete_complete__handles__escaped_spaces(void** state)
{
Autocomplete ac = autocomplete_new();
autocomplete_add(ac, "Thor Odinson");
char* result = autocomplete_complete(ac, "Thor\\ ", TRUE, FALSE);
assert_string_equal("\"Thor Odinson\"", result);
autocomplete_free(ac);
free(result);
}
void
autocomplete_complete__handles__escaped_quotes(void** state)
{
Autocomplete ac = autocomplete_new();
autocomplete_add(ac, "Thor \"The Thunderer\" Odinson");
char* result = autocomplete_complete(ac, "Thor \\\"", TRUE, FALSE);
assert_string_equal("\"Thor \\\"The Thunderer\\\" Odinson\"", result);
autocomplete_free(ac);
free(result);
}

View File

@@ -0,0 +1,30 @@
#ifndef TESTS_TEST_AUTOCOMPLETE_H
#define TESTS_TEST_AUTOCOMPLETE_H
void autocomplete_complete__returns__null_when_empty(void** state);
void autocomplete_reset__updates__after_create(void** state);
void autocomplete_complete__returns__null_after_create(void** state);
void autocomplete_complete__handles__escaped_spaces(void** state);
void autocomplete_complete__handles__escaped_quotes(void** state);
void autocomplete_create_list__returns__null_after_create(void** state);
void autocomplete_add__updates__one_and_complete(void** state);
void autocomplete_complete__returns__first_of_two(void** state);
void autocomplete_complete__returns__second_of_two(void** state);
void autocomplete_add__updates__two_elements(void** state);
void autocomplete_add__updates__only_once_for_same_value(void** state);
void autocomplete_add__updates__existing_value(void** state);
void autocomplete_complete__returns__accented_with_accented(void** state);
void autocomplete_complete__returns__accented_with_base(void** state);
void autocomplete_complete__returns__both_with_accented(void** state);
void autocomplete_complete__returns__both_with_base(void** state);
void autocomplete_complete__is__case_insensitive(void** state);
void autocomplete_complete__returns__previous(void** state);
void autocomplete_complete__returns__greek(void** state);
void autocomplete_complete__returns__greek_false_match(void** state);
void autocomplete_complete__returns__greek_case_insensitive(void** state);
void autocomplete_complete__returns__russian(void** state);
void autocomplete_complete__returns__chinese(void** state);
void autocomplete_complete__returns__transliterated(void** state);
void autocomplete_complete__returns__regular_ascii(void** state);
#endif

View File

@@ -4,7 +4,7 @@
#include "tools/parser.h"
void
parse_null_returns_null(void** state)
parse_args__returns__null_from_null(void** state)
{
char* inp = NULL;
gboolean result = TRUE;
@@ -16,7 +16,7 @@ parse_null_returns_null(void** state)
}
void
parse_empty_returns_null(void** state)
parse_args__returns__null_from_empty(void** state)
{
char* inp = "";
gboolean result = TRUE;
@@ -28,7 +28,7 @@ parse_empty_returns_null(void** state)
}
void
parse_space_returns_null(void** state)
parse_args__returns__null_from_space(void** state)
{
char* inp = " ";
gboolean result = TRUE;
@@ -40,7 +40,7 @@ parse_space_returns_null(void** state)
}
void
parse_cmd_no_args_returns_null(void** state)
parse_args__returns__null_when_no_args(void** state)
{
char* inp = "/cmd";
gboolean result = TRUE;
@@ -52,7 +52,7 @@ parse_cmd_no_args_returns_null(void** state)
}
void
parse_cmd_with_space_returns_null(void** state)
parse_args__returns__null_from_cmd_with_space(void** state)
{
char* inp = "/cmd ";
gboolean result = TRUE;
@@ -64,7 +64,7 @@ parse_cmd_with_space_returns_null(void** state)
}
void
parse_cmd_with_too_few_returns_null(void** state)
parse_args__returns__null_when_too_few(void** state)
{
char* inp = "/cmd arg1";
gboolean result = TRUE;
@@ -76,7 +76,7 @@ parse_cmd_with_too_few_returns_null(void** state)
}
void
parse_cmd_with_too_many_returns_null(void** state)
parse_args__returns__null_when_too_many(void** state)
{
char* inp = "/cmd arg1 arg2 arg3 arg4";
gboolean result = TRUE;
@@ -88,7 +88,7 @@ parse_cmd_with_too_many_returns_null(void** state)
}
void
parse_cmd_one_arg(void** state)
parse_args__returns__one_arg(void** state)
{
char* inp = "/cmd arg1";
gboolean result = FALSE;
@@ -101,7 +101,7 @@ parse_cmd_one_arg(void** state)
}
void
parse_cmd_two_args(void** state)
parse_args__returns__two_args(void** state)
{
char* inp = "/cmd arg1 arg2";
gboolean result = FALSE;
@@ -115,7 +115,7 @@ parse_cmd_two_args(void** state)
}
void
parse_cmd_three_args(void** state)
parse_args__returns__three_args(void** state)
{
char* inp = "/cmd arg1 arg2 arg3";
gboolean result = FALSE;
@@ -130,7 +130,7 @@ parse_cmd_three_args(void** state)
}
void
parse_cmd_three_args_with_spaces(void** state)
parse_args__returns__three_args_with_spaces(void** state)
{
char* inp = " /cmd arg1 arg2 arg3 ";
gboolean result = FALSE;
@@ -145,7 +145,7 @@ parse_cmd_three_args_with_spaces(void** state)
}
void
parse_cmd_with_freetext(void** state)
parse_args_with_freetext__returns__freetext(void** state)
{
char* inp = "/cmd this is some free text";
gboolean result = FALSE;
@@ -158,7 +158,7 @@ parse_cmd_with_freetext(void** state)
}
void
parse_cmd_one_arg_with_freetext(void** state)
parse_args_with_freetext__returns__one_arg_with_freetext(void** state)
{
char* inp = "/cmd arg1 this is some free text";
gboolean result = FALSE;
@@ -172,7 +172,7 @@ parse_cmd_one_arg_with_freetext(void** state)
}
void
parse_cmd_two_args_with_freetext(void** state)
parse_args_with_freetext__returns__two_args_with_freetext(void** state)
{
char* inp = "/cmd arg1 arg2 this is some free text";
gboolean result = FALSE;
@@ -187,7 +187,7 @@ parse_cmd_two_args_with_freetext(void** state)
}
void
parse_cmd_min_zero(void** state)
parse_args__returns__zero_args_when_min_zero(void** state)
{
char* inp = "/cmd";
gboolean result = FALSE;
@@ -200,7 +200,7 @@ parse_cmd_min_zero(void** state)
}
void
parse_cmd_min_zero_with_freetext(void** state)
parse_args_with_freetext__returns__zero_args_when_min_zero(void** state)
{
char* inp = "/cmd";
gboolean result = FALSE;
@@ -213,7 +213,7 @@ parse_cmd_min_zero_with_freetext(void** state)
}
void
parse_cmd_with_quoted(void** state)
parse_args__returns__quoted_args(void** state)
{
char* inp = "/cmd \"arg1\" arg2";
gboolean result = FALSE;
@@ -227,7 +227,7 @@ parse_cmd_with_quoted(void** state)
}
void
parse_cmd_with_quoted_and_space(void** state)
parse_args__returns__quoted_args_with_space(void** state)
{
char* inp = "/cmd \"the arg1\" arg2";
gboolean result = FALSE;
@@ -241,7 +241,7 @@ parse_cmd_with_quoted_and_space(void** state)
}
void
parse_cmd_with_quoted_and_many_spaces(void** state)
parse_args__returns__quoted_args_with_many_spaces(void** state)
{
char* inp = "/cmd \"the arg1 is here\" arg2";
gboolean result = FALSE;
@@ -255,7 +255,7 @@ parse_cmd_with_quoted_and_many_spaces(void** state)
}
void
parse_cmd_with_many_quoted_and_many_spaces(void** state)
parse_args__returns__many_quoted_args_with_many_spaces(void** state)
{
char* inp = "/cmd \"the arg1 is here\" \"and arg2 is right here\"";
gboolean result = FALSE;
@@ -269,7 +269,7 @@ parse_cmd_with_many_quoted_and_many_spaces(void** state)
}
void
parse_cmd_freetext_with_quoted(void** state)
parse_args_with_freetext__returns__quoted_args(void** state)
{
char* inp = "/cmd \"arg1\" arg2 hello there what's up";
gboolean result = FALSE;
@@ -284,7 +284,7 @@ parse_cmd_freetext_with_quoted(void** state)
}
void
parse_cmd_freetext_with_quoted_and_space(void** state)
parse_args_with_freetext__returns__quoted_args_with_space(void** state)
{
char* inp = "/cmd \"the arg1\" arg2 another bit of freetext";
gboolean result = FALSE;
@@ -299,7 +299,7 @@ parse_cmd_freetext_with_quoted_and_space(void** state)
}
void
parse_cmd_freetext_with_quoted_and_many_spaces(void** state)
parse_args_with_freetext__returns__quoted_args_with_many_spaces(void** state)
{
char* inp = "/cmd \"the arg1 is here\" arg2 some more freetext";
gboolean result = FALSE;
@@ -314,7 +314,7 @@ parse_cmd_freetext_with_quoted_and_many_spaces(void** state)
}
void
parse_cmd_freetext_with_many_quoted_and_many_spaces(void** state)
parse_args_with_freetext__returns__many_quoted_args_with_many_spaces(void** state)
{
char* inp = "/cmd \"the arg1 is here\" \"and arg2 is right here\" and heres the free text";
gboolean result = FALSE;
@@ -329,7 +329,7 @@ parse_cmd_freetext_with_many_quoted_and_many_spaces(void** state)
}
void
parse_cmd_with_quoted_freetext(void** state)
parse_args_with_freetext__returns__quoted_freetext(void** state)
{
char* inp = "/cmd arg1 here is \"some\" quoted freetext";
gboolean result = FALSE;
@@ -343,7 +343,21 @@ parse_cmd_with_quoted_freetext(void** state)
}
void
parse_cmd_with_third_arg_quoted_0_min_3_max(void** state)
parse_args_with_freetext__returns__quoted_start_of_freetext(void** state)
{
char* inp = "/cmd arg1 \"arg2 with space\" more text";
gboolean result = FALSE;
gchar** args = parse_args_with_freetext(inp, 1, 2, &result);
assert_true(result);
assert_int_equal(2, g_strv_length(args));
assert_string_equal("arg1", args[0]);
assert_string_equal("\"arg2 with space\" more text", args[1]);
g_strfreev(args);
}
void
parse_args_with_freetext__returns__third_arg_quoted(void** state)
{
char* inp = "/group add friends \"The User\"";
gboolean result = FALSE;
@@ -359,7 +373,7 @@ parse_cmd_with_third_arg_quoted_0_min_3_max(void** state)
}
void
parse_cmd_with_second_arg_quoted_0_min_3_max(void** state)
parse_args_with_freetext__returns__second_arg_quoted(void** state)
{
char* inp = "/group add \"The Group\" friend";
gboolean result = FALSE;
@@ -375,7 +389,7 @@ parse_cmd_with_second_arg_quoted_0_min_3_max(void** state)
}
void
parse_cmd_with_second_and_third_arg_quoted_0_min_3_max(void** state)
parse_args_with_freetext__returns__second_and_third_arg_quoted(void** state)
{
char* inp = "/group add \"The Group\" \"The User\"";
gboolean result = FALSE;
@@ -391,7 +405,49 @@ parse_cmd_with_second_and_third_arg_quoted_0_min_3_max(void** state)
}
void
count_one_token(void** state)
parse_args__returns__escaped_quotes(void** state)
{
char* inp = "/cmd \"Thor \\\"The Thunderer\\\" Odinson\" arg2";
gboolean result = FALSE;
gchar** args = parse_args(inp, 2, 2, &result);
assert_true(result);
assert_int_equal(2, g_strv_length(args));
assert_string_equal("Thor \"The Thunderer\" Odinson", args[0]);
assert_string_equal("arg2", args[1]);
g_strfreev(args);
}
void
parse_args__returns__escaped_spaces(void** state)
{
char* inp = "/cmd Thor\\ The\\ Thunderer\\ Odinson arg2";
gboolean result = FALSE;
gchar** args = parse_args(inp, 2, 2, &result);
assert_true(result);
assert_int_equal(2, g_strv_length(args));
assert_string_equal("Thor The Thunderer Odinson", args[0]);
assert_string_equal("arg2", args[1]);
g_strfreev(args);
}
void
parse_args__returns__escaped_backslash(void** state)
{
char* inp = "/cmd \"Thor \\\\ Odinson\" arg2";
gboolean result = FALSE;
gchar** args = parse_args(inp, 2, 2, &result);
assert_true(result);
assert_int_equal(2, g_strv_length(args));
assert_string_equal("Thor \\ Odinson", args[0]);
assert_string_equal("arg2", args[1]);
g_strfreev(args);
}
void
count_tokens__returns__one_token(void** state)
{
char* inp = "one";
int result = count_tokens(inp);
@@ -400,7 +456,7 @@ count_one_token(void** state)
}
void
count_one_token_quoted_no_whitespace(void** state)
count_tokens__returns__one_token_quoted_no_whitespace(void** state)
{
char* inp = "\"one\"";
int result = count_tokens(inp);
@@ -409,7 +465,7 @@ count_one_token_quoted_no_whitespace(void** state)
}
void
count_one_token_quoted_with_whitespace(void** state)
count_tokens__returns__one_token_quoted_with_whitespace(void** state)
{
char* inp = "\"one two\"";
int result = count_tokens(inp);
@@ -418,7 +474,7 @@ count_one_token_quoted_with_whitespace(void** state)
}
void
count_two_tokens(void** state)
count_tokens__returns__two_tokens(void** state)
{
char* inp = "one two";
int result = count_tokens(inp);
@@ -427,7 +483,7 @@ count_two_tokens(void** state)
}
void
count_two_tokens_first_quoted(void** state)
count_tokens__returns__two_tokens_first_quoted(void** state)
{
char* inp = "\"one and\" two";
int result = count_tokens(inp);
@@ -436,7 +492,7 @@ count_two_tokens_first_quoted(void** state)
}
void
count_two_tokens_second_quoted(void** state)
count_tokens__returns__two_tokens_second_quoted(void** state)
{
char* inp = "one \"two and\"";
int result = count_tokens(inp);
@@ -445,7 +501,7 @@ count_two_tokens_second_quoted(void** state)
}
void
count_two_tokens_both_quoted(void** state)
count_tokens__returns__two_tokens_both_quoted(void** state)
{
char* inp = "\"one and then\" \"two and\"";
int result = count_tokens(inp);
@@ -454,67 +510,105 @@ count_two_tokens_both_quoted(void** state)
}
void
get_first_of_one(void** state)
count_tokens__handles__escapes(void** state)
{
char* inp = "one\\ two \"three \\\" four\"";
int result = count_tokens(inp);
assert_int_equal(2, result);
}
void
count_tokens__handles__multiple_spaces(void** state)
{
char* inp = "one two";
int result = count_tokens(inp);
assert_int_equal(2, result);
}
void
get_start__returns__first_of_one(void** state)
{
char* inp = "one";
char* result = get_start(inp, 2);
assert_string_equal("one", result);
free(result);
g_free(result);
}
void
get_first_of_two(void** state)
get_start__returns__first_of_two(void** state)
{
char* inp = "one two";
char* result = get_start(inp, 2);
assert_string_equal("one ", result);
free(result);
g_free(result);
}
void
get_first_two_of_three(void** state)
get_start__returns__first_two_of_three(void** state)
{
char* inp = "one two three";
char* result = get_start(inp, 3);
assert_string_equal("one two ", result);
free(result);
g_free(result);
}
void
get_first_two_of_three_first_quoted(void** state)
get_start__returns__first_two_of_three_first_quoted(void** state)
{
char* inp = "\"one\" two three";
char* result = get_start(inp, 3);
assert_string_equal("\"one\" two ", result);
free(result);
g_free(result);
}
void
get_first_two_of_three_second_quoted(void** state)
get_start__returns__first_two_of_three_second_quoted(void** state)
{
char* inp = "one \"two\" three";
char* result = get_start(inp, 3);
assert_string_equal("one \"two\" ", result);
free(result);
g_free(result);
}
void
get_first_two_of_three_first_and_second_quoted(void** state)
get_start__returns__first_two_of_three_first_and_second_quoted(void** state)
{
char* inp = "\"one\" \"two\" three";
char* result = get_start(inp, 3);
assert_string_equal("\"one\" \"two\" ", result);
free(result);
g_free(result);
}
void
parse_options_when_none_returns_empty_hasmap(void** state)
get_start__handles__escapes(void** state)
{
char* inp = "one\\ two three";
char* result = get_start(inp, 2);
assert_string_equal("one\\ two ", result);
g_free(result);
}
void
get_start__handles__multiple_spaces(void** state)
{
char* inp = "one two";
char* result = get_start(inp, 2);
assert_string_equal("one ", result);
g_free(result);
}
void
parse_options__returns__empty_hashmap_when_none(void** state)
{
gchar* args[] = { "cmd1", "cmd2", NULL };
gchar* keys[] = { "opt1", NULL };
@@ -531,7 +625,7 @@ parse_options_when_none_returns_empty_hasmap(void** state)
}
void
parse_options_when_opt1_no_val_sets_error(void** state)
parse_options__returns__error_when_opt1_no_val(void** state)
{
gchar* args[] = { "cmd1", "cmd2", "opt1", NULL };
gchar* keys[] = { "opt1", NULL };
@@ -547,7 +641,7 @@ parse_options_when_opt1_no_val_sets_error(void** state)
}
void
parse_options_when_one_returns_map(void** state)
parse_options__returns__map_when_one(void** state)
{
gchar* args[] = { "cmd1", "cmd2", "opt1", "val1", NULL };
gchar* keys[] = { "opt1", NULL };
@@ -565,7 +659,7 @@ parse_options_when_one_returns_map(void** state)
}
void
parse_options_when_opt2_no_val_sets_error(void** state)
parse_options__returns__error_when_opt2_no_val(void** state)
{
gchar* args[] = { "cmd1", "cmd2", "opt1", "val1", "opt2", NULL };
gchar* keys[] = { "opt1", "opt2", NULL };
@@ -581,7 +675,7 @@ parse_options_when_opt2_no_val_sets_error(void** state)
}
void
parse_options_when_two_returns_map(void** state)
parse_options__returns__map_when_two(void** state)
{
gchar* args[] = { "cmd1", "cmd2", "opt1", "val1", "opt2", "val2", NULL };
gchar* keys[] = { "opt1", "opt2", NULL };
@@ -601,7 +695,7 @@ parse_options_when_two_returns_map(void** state)
}
void
parse_options_when_opt3_no_val_sets_error(void** state)
parse_options__returns__error_when_opt3_no_val(void** state)
{
gchar* args[] = { "cmd1", "cmd2", "opt1", "val1", "opt2", "val2", "opt3", NULL };
gchar* keys[] = { "opt1", "opt2", "opt3", NULL };
@@ -617,7 +711,7 @@ parse_options_when_opt3_no_val_sets_error(void** state)
}
void
parse_options_when_three_returns_map(void** state)
parse_options__returns__map_when_three(void** state)
{
gchar* args[] = { "cmd1", "cmd2", "opt1", "val1", "opt2", "val2", "opt3", "val3", NULL };
gchar* keys[] = { "opt1", "opt2", "opt3", NULL };
@@ -639,7 +733,7 @@ parse_options_when_three_returns_map(void** state)
}
void
parse_options_when_unknown_opt_sets_error(void** state)
parse_options__returns__error_when_unknown_opt(void** state)
{
gchar* args[] = { "cmd1", "cmd2", "opt1", "val1", "oops", "val2", "opt3", "val3", NULL };
gchar* keys[] = { "opt1", "opt2", "opt3", NULL };
@@ -655,7 +749,7 @@ parse_options_when_unknown_opt_sets_error(void** state)
}
void
parse_options_with_duplicated_option_sets_error(void** state)
parse_options__returns__error_when_duplicated_option(void** state)
{
gchar* args[] = { "cmd1", "cmd2", "opt1", "val1", "opt2", "val2", "opt1", "val3", NULL };
gchar* keys[] = { "opt1", "opt2", "opt3", NULL };

View File

@@ -0,0 +1,62 @@
#ifndef TESTS_TEST_PARSER_H
#define TESTS_TEST_PARSER_H
void parse_args__returns__null_from_null(void** state);
void parse_args__returns__null_from_empty(void** state);
void parse_args__returns__null_from_space(void** state);
void parse_args__returns__null_when_no_args(void** state);
void parse_args__returns__null_from_cmd_with_space(void** state);
void parse_args__returns__null_when_too_few(void** state);
void parse_args__returns__null_when_too_many(void** state);
void parse_args__returns__one_arg(void** state);
void parse_args__returns__two_args(void** state);
void parse_args__returns__three_args(void** state);
void parse_args__returns__three_args_with_spaces(void** state);
void parse_args_with_freetext__returns__freetext(void** state);
void parse_args_with_freetext__returns__one_arg_with_freetext(void** state);
void parse_args_with_freetext__returns__two_args_with_freetext(void** state);
void parse_args__returns__zero_args_when_min_zero(void** state);
void parse_args_with_freetext__returns__zero_args_when_min_zero(void** state);
void parse_args__returns__quoted_args(void** state);
void parse_args__returns__quoted_args_with_space(void** state);
void parse_args__returns__quoted_args_with_many_spaces(void** state);
void parse_args__returns__many_quoted_args_with_many_spaces(void** state);
void parse_args_with_freetext__returns__quoted_args(void** state);
void parse_args_with_freetext__returns__quoted_args_with_space(void** state);
void parse_args_with_freetext__returns__quoted_args_with_many_spaces(void** state);
void parse_args_with_freetext__returns__many_quoted_args_with_many_spaces(void** state);
void parse_args_with_freetext__returns__quoted_freetext(void** state);
void parse_args_with_freetext__returns__third_arg_quoted(void** state);
void parse_args_with_freetext__returns__second_arg_quoted(void** state);
void parse_args_with_freetext__returns__second_and_third_arg_quoted(void** state);
void parse_args__returns__escaped_quotes(void** state);
void parse_args__returns__escaped_spaces(void** state);
void parse_args__returns__escaped_backslash(void** state);
void count_tokens__returns__one_token(void** state);
void count_tokens__returns__one_token_quoted_no_whitespace(void** state);
void count_tokens__returns__one_token_quoted_with_whitespace(void** state);
void count_tokens__returns__two_tokens(void** state);
void count_tokens__returns__two_tokens_first_quoted(void** state);
void count_tokens__returns__two_tokens_second_quoted(void** state);
void count_tokens__returns__two_tokens_both_quoted(void** state);
void count_tokens__handles__escapes(void** state);
void count_tokens__handles__multiple_spaces(void** state);
void get_start__returns__first_of_one(void** state);
void get_start__returns__first_of_two(void** state);
void get_start__returns__first_two_of_three(void** state);
void get_start__returns__first_two_of_three_first_quoted(void** state);
void get_start__returns__first_two_of_three_second_quoted(void** state);
void get_start__returns__first_two_of_three_first_and_second_quoted(void** state);
void get_start__handles__escapes(void** state);
void get_start__handles__multiple_spaces(void** state);
void parse_options__returns__empty_hashmap_when_none(void** state);
void parse_options__returns__error_when_opt1_no_val(void** state);
void parse_options__returns__map_when_one(void** state);
void parse_options__returns__error_when_opt2_no_val(void** state);
void parse_options__returns__map_when_two(void** state);
void parse_options__returns__error_when_opt3_no_val(void** state);
void parse_options__returns__map_when_three(void** state);
void parse_options__returns__error_when_unknown_opt(void** state);
void parse_options__returns__error_when_duplicated_option(void** state);
#endif

View File

@@ -1,3 +1,11 @@
/*
* stub_ui.c
*
* Copyright (C) 2015 - 2018 James Booth <boothj5@gmail.com>
* Copyright (C) 2019 - 2026 Michael Vetter <jubalh@iodoru.org>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include "config.h"
#include <glib.h>
@@ -54,6 +62,14 @@ ui_init(void)
{
}
void
ui_suspend(void)
{
}
void
ui_resume(void)
{
}
void
ui_load_colours(void)
{
}
@@ -1005,6 +1021,10 @@ cons_splash_setting(void)
{
}
void
cons_spellcheck_setting(void)
{
}
void
cons_vercheck_setting(void)
{
}
@@ -1320,6 +1340,22 @@ win_refresh_with_subwin(ProfWin* window)
{
}
gboolean
win_warn_needed(ProfWin* window, const char* const type, const char* const jid)
{
return TRUE;
}
void
win_warn_sent(ProfWin* window, const char* const type, const char* const jid)
{
}
void
win_clear_warned_jids(ProfWin* window)
{
}
void
win_println(ProfWin* window, theme_item_t theme, const char* ch, const char* const message, ...)
{
@@ -1433,3 +1469,9 @@ cons_has_alerts(void)
{
return FALSE;
}
gboolean
ui_is_suspended(void)
{
return FALSE;
}

View File

@@ -1,3 +1,11 @@
/*
* stub_ui.h
*
* Copyright (C) 2015 - 2016 James Booth <boothj5@gmail.com>
* Copyright (C) 2015 - 2026 Michael Vetter <jubalh@iodoru.org>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
void expect_cons_show(char* expected);
void expect_any_cons_show(void);
void expect_cons_show_error(char* expected);

View File

@@ -12,7 +12,8 @@ static char line[INP_WIN_MAX];
// append
void append_to_empty(void **state)
void
key_printable__updates__append_to_empty(void** state)
{
setlocale(LC_ALL, "");
line[0] = '\0';
@@ -28,7 +29,8 @@ void append_to_empty(void **state)
assert_int_equal(pad_start, 0);
}
void append_wide_to_empty(void **state)
void
key_printable__updates__append_wide_to_empty(void** state)
{
setlocale(LC_ALL, "");
line[0] = '\0';
@@ -44,7 +46,8 @@ void append_wide_to_empty(void **state)
assert_int_equal(pad_start, 0);
}
void append_to_single(void **state)
void
key_printable__updates__append_to_single(void** state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "a", 1);
@@ -61,8 +64,8 @@ void append_to_single(void **state)
assert_int_equal(pad_start, 0);
}
void append_wide_to_single_non_wide(void **state)
void
key_printable__updates__append_wide_to_single_non_wide(void** state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "a", 1);
@@ -79,7 +82,8 @@ void append_wide_to_single_non_wide(void **state)
assert_int_equal(pad_start, 0);
}
void append_non_wide_to_single_wide(void **state)
void
key_printable__updates__append_non_wide_to_single_wide(void** state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "", 1);
@@ -96,7 +100,8 @@ void append_non_wide_to_single_wide(void **state)
assert_int_equal(pad_start, 0);
}
void append_wide_to_single_wide(void **state)
void
key_printable__updates__append_wide_to_single_wide(void** state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "", 1);
@@ -113,7 +118,8 @@ void append_wide_to_single_wide(void **state)
assert_int_equal(pad_start, 0);
}
void append_non_wide_when_overrun(void **state)
void
key_printable__updates__append_non_wide_when_overrun(void** state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "0123456789四1234567", 18);
@@ -132,7 +138,8 @@ void append_non_wide_when_overrun(void **state)
assert_int_equal(pad_start, 3);
}
void insert_non_wide_to_non_wide(void **state)
void
key_printable__updates__insert_non_wide_to_non_wide(void** state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "abcd", 4);
@@ -149,7 +156,8 @@ void insert_non_wide_to_non_wide(void **state)
assert_int_equal(pad_start, 0);
}
void insert_single_non_wide_when_pad_scrolled(void **state)
void
key_printable__updates__insert_single_non_wide_when_pad_scrolled(void** state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "AAAAAAAAAAAAAAA", 15);
@@ -166,7 +174,8 @@ void insert_single_non_wide_when_pad_scrolled(void **state)
assert_int_equal(pad_start, 2);
}
void insert_many_non_wide_when_pad_scrolled(void **state)
void
key_printable__updates__insert_many_non_wide_when_pad_scrolled(void** state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "AAAAAAAAAAAAAAA", 15);
@@ -185,7 +194,8 @@ void insert_many_non_wide_when_pad_scrolled(void **state)
assert_int_equal(pad_start, 2);
}
void insert_single_non_wide_last_column(void **state)
void
key_printable__updates__insert_single_non_wide_last_column(void** state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "abcdefghijklmno", 15);
@@ -202,7 +212,8 @@ void insert_single_non_wide_last_column(void **state)
assert_int_equal(pad_start, 3);
}
void insert_many_non_wide_last_column(void **state)
void
key_printable__updates__insert_many_non_wide_last_column(void** state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "abcdefghijklmno", 15);
@@ -220,7 +231,8 @@ void insert_many_non_wide_last_column(void **state)
assert_int_equal(pad_start, 4);
}
void ctrl_left_when_no_input(void **state)
void
key_ctrl_left__updates__when_no_input(void** state)
{
setlocale(LC_ALL, "");
line[0] = '\0';
@@ -235,7 +247,8 @@ void ctrl_left_when_no_input(void **state)
assert_int_equal(pad_start, 0);
}
void ctrl_left_when_at_start(void **state)
void
key_ctrl_left__updates__when_at_start(void** state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "abcd efghij klmn opqr", 21);
@@ -251,7 +264,8 @@ void ctrl_left_when_at_start(void **state)
assert_int_equal(pad_start, 0);
}
void ctrl_left_when_in_first_word(void **state)
void
key_ctrl_left__updates__when_in_first_word(void** state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "abcd efghij klmn opqr", 21);
@@ -267,7 +281,8 @@ void ctrl_left_when_in_first_word(void **state)
assert_int_equal(pad_start, 0);
}
void ctrl_left_when_in_first_space(void **state)
void
key_ctrl_left__updates__when_in_first_space(void** state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "abcd efghij klmn opqr", 21);
@@ -283,7 +298,8 @@ void ctrl_left_when_in_first_space(void **state)
assert_int_equal(pad_start, 0);
}
void ctrl_left_when_at_start_of_second_word(void **state)
void
key_ctrl_left__updates__at_start_of_second_word(void** state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "abcd efghij klmn opqr", 21);
@@ -299,7 +315,8 @@ void ctrl_left_when_at_start_of_second_word(void **state)
assert_int_equal(pad_start, 0);
}
void ctrl_left_when_in_second_word(void **state)
void
key_ctrl_left__updates__when_in_second_word(void** state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "abcd efghij klmn opqr", 21);
@@ -315,7 +332,8 @@ void ctrl_left_when_in_second_word(void **state)
assert_int_equal(pad_start, 0);
}
void ctrl_left_when_at_end_of_second_word(void **state)
void
key_ctrl_left__updates__at_end_of_second_word(void** state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "abcd efghij klmn opqr", 21);
@@ -331,7 +349,8 @@ void ctrl_left_when_at_end_of_second_word(void **state)
assert_int_equal(pad_start, 0);
}
void ctrl_left_when_in_second_space(void **state)
void
key_ctrl_left__updates__when_in_second_space(void** state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "abcd efghij klmn opqr", 21);
@@ -347,7 +366,8 @@ void ctrl_left_when_in_second_space(void **state)
assert_int_equal(pad_start, 0);
}
void ctrl_left_when_at_start_of_third_word(void **state)
void
key_ctrl_left__updates__at_start_of_third_word(void** state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "abcd efghij klmn opqr", 21);
@@ -363,7 +383,8 @@ void ctrl_left_when_at_start_of_third_word(void **state)
assert_int_equal(pad_start, 0);
}
void ctrl_left_when_in_third_word(void **state)
void
key_ctrl_left__updates__when_in_third_word(void** state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "abcd efghij klmn opqr", 21);
@@ -379,7 +400,8 @@ void ctrl_left_when_in_third_word(void **state)
assert_int_equal(pad_start, 0);
}
void ctrl_left_when_at_end_of_third_word(void **state)
void
key_ctrl_left__updates__at_end_of_third_word(void** state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "abcd efghij klmn opqr", 21);
@@ -395,7 +417,8 @@ void ctrl_left_when_at_end_of_third_word(void **state)
assert_int_equal(pad_start, 0);
}
void ctrl_left_when_in_third_space(void **state)
void
key_ctrl_left__updates__when_in_third_space(void** state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "abcd efghij klmn opqr", 21);
@@ -411,7 +434,8 @@ void ctrl_left_when_in_third_space(void **state)
assert_int_equal(pad_start, 0);
}
void ctrl_left_when_at_end(void **state)
void
key_ctrl_left__updates__when_at_end(void** state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "abcd efghij klmn opqr", 21);
@@ -427,7 +451,8 @@ void ctrl_left_when_at_end(void **state)
assert_int_equal(pad_start, 0);
}
void ctrl_left_when_in_only_whitespace(void **state)
void
key_ctrl_left__updates__when_in_only_whitespace(void** state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, " ", 7);
@@ -443,7 +468,8 @@ void ctrl_left_when_in_only_whitespace(void **state)
assert_int_equal(pad_start, 0);
}
void ctrl_left_when_start_whitespace_start_of_word(void **state)
void
key_ctrl_left__updates__when_start_whitespace_start_of_word(void** state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, " hello", 9);
@@ -459,7 +485,8 @@ void ctrl_left_when_start_whitespace_start_of_word(void **state)
assert_int_equal(pad_start, 0);
}
void ctrl_left_when_start_whitespace_middle_of_word(void **state)
void
key_ctrl_left__updates__when_start_whitespace_middle_of_word(void** state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, " hello", 9);
@@ -475,7 +502,8 @@ void ctrl_left_when_start_whitespace_middle_of_word(void **state)
assert_int_equal(pad_start, 0);
}
void ctrl_left_in_whitespace_between_words(void **state)
void
key_ctrl_left__updates__in_whitespace_between_words(void** state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "hey hello", 12);
@@ -491,7 +519,8 @@ void ctrl_left_in_whitespace_between_words(void **state)
assert_int_equal(pad_start, 0);
}
void ctrl_left_in_whitespace_between_words_start_of_word(void **state)
void
key_ctrl_left__updates__in_whitespace_between_words_start_of_word(void** state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "hey hello", 12);
@@ -507,7 +536,8 @@ void ctrl_left_in_whitespace_between_words_start_of_word(void **state)
assert_int_equal(pad_start, 0);
}
void ctrl_left_in_whitespace_between_words_middle_of_word(void **state)
void
key_ctrl_left__updates__in_whitespace_between_words_middle_of_word(void** state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "hey hello", 12);
@@ -523,7 +553,8 @@ void ctrl_left_in_whitespace_between_words_middle_of_word(void **state)
assert_int_equal(pad_start, 0);
}
void ctrl_left_when_word_overrun_to_left(void **state)
void
key_ctrl_left__updates__when_word_overrun_to_left(void** state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "someword anotherword", 20);
@@ -539,7 +570,8 @@ void ctrl_left_when_word_overrun_to_left(void **state)
assert_int_equal(pad_start, 9);
}
void ctrl_right_when_no_input(void **state)
void
key_ctrl_right__updates__when_no_input(void** state)
{
setlocale(LC_ALL, "");
line[0] = '\0';
@@ -554,7 +586,8 @@ void ctrl_right_when_no_input(void **state)
assert_int_equal(pad_start, 0);
}
void ctrl_right_when_at_end(void **state)
void
key_ctrl_right__updates__when_at_end(void** state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "someword anotherword", 20);
@@ -570,7 +603,8 @@ void ctrl_right_when_at_end(void **state)
assert_int_equal(pad_start, 0);
}
void ctrl_right_one_word_at_start(void **state)
void
key_ctrl_right__updates__one_word_at_start(void** state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "someword", 8);
@@ -586,7 +620,8 @@ void ctrl_right_one_word_at_start(void **state)
assert_int_equal(pad_start, 0);
}
void ctrl_right_one_word_in_middle(void **state)
void
key_ctrl_right__updates__one_word_in_middle(void** state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "someword", 8);
@@ -602,7 +637,8 @@ void ctrl_right_one_word_in_middle(void **state)
assert_int_equal(pad_start, 0);
}
void ctrl_right_one_word_at_end(void **state)
void
key_ctrl_right__updates__one_word_at_end(void** state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "someword", 8);
@@ -618,7 +654,8 @@ void ctrl_right_one_word_at_end(void **state)
assert_int_equal(pad_start, 0);
}
void ctrl_right_two_words_from_middle_first(void **state)
void
key_ctrl_right__updates__two_words_from_middle_first(void** state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "someword anotherword", 20);
@@ -634,7 +671,8 @@ void ctrl_right_two_words_from_middle_first(void **state)
assert_int_equal(pad_start, 0);
}
void ctrl_right_two_words_from_end_first(void **state)
void
key_ctrl_right__updates__two_words_from_end_first(void** state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "someword anotherword", 20);
@@ -650,7 +688,8 @@ void ctrl_right_two_words_from_end_first(void **state)
assert_int_equal(pad_start, 0);
}
void ctrl_right_two_words_from_space(void **state)
void
key_ctrl_right__updates__two_words_from_space(void** state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "someword anotherword", 20);
@@ -666,7 +705,8 @@ void ctrl_right_two_words_from_space(void **state)
assert_int_equal(pad_start, 0);
}
void ctrl_right_two_words_from_start_second(void **state)
void
key_ctrl_right__updates__two_words_from_start_second(void** state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "someword anotherword", 20);
@@ -682,7 +722,8 @@ void ctrl_right_two_words_from_start_second(void **state)
assert_int_equal(pad_start, 0);
}
void ctrl_right_one_word_leading_whitespace(void **state)
void
key_ctrl_right__updates__one_word_leading_whitespace(void** state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, " someword", 15);
@@ -698,7 +739,8 @@ void ctrl_right_one_word_leading_whitespace(void **state)
assert_int_equal(pad_start, 0);
}
void ctrl_right_two_words_in_whitespace(void **state)
void
key_ctrl_right__updates__two_words_in_whitespace(void** state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, " someword adfasdf", 30);
@@ -714,7 +756,8 @@ void ctrl_right_two_words_in_whitespace(void **state)
assert_int_equal(pad_start, 0);
}
void ctrl_right_trailing_whitespace_from_middle(void **state)
void
key_ctrl_right__updates__trailing_whitespace_from_middle(void** state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "someword ", 16);

View File

@@ -0,0 +1,52 @@
#ifndef TESTS_TEST_KEYHANDLERS_H
#define TESTS_TEST_KEYHANDLERS_H
void key_printable__updates__append_to_empty(void** state);
void key_printable__updates__append_wide_to_empty(void** state);
void key_printable__updates__append_to_single(void** state);
void key_printable__updates__append_wide_to_single_non_wide(void** state);
void key_printable__updates__append_non_wide_to_single_wide(void** state);
void key_printable__updates__append_wide_to_single_wide(void** state);
void key_printable__updates__append_non_wide_when_overrun(void** state);
void key_printable__updates__insert_non_wide_to_non_wide(void** state);
void key_printable__updates__insert_single_non_wide_when_pad_scrolled(void** state);
void key_printable__updates__insert_many_non_wide_when_pad_scrolled(void** state);
void key_printable__updates__insert_single_non_wide_last_column(void** state);
void key_printable__updates__insert_many_non_wide_last_column(void** state);
void key_ctrl_left__updates__when_no_input(void** state);
void key_ctrl_left__updates__when_at_start(void** state);
void key_ctrl_left__updates__when_in_first_word(void** state);
void key_ctrl_left__updates__when_in_first_space(void** state);
void key_ctrl_left__updates__at_start_of_second_word(void** state);
void key_ctrl_left__updates__when_in_second_word(void** state);
void key_ctrl_left__updates__at_end_of_second_word(void** state);
void key_ctrl_left__updates__when_in_second_space(void** state);
void key_ctrl_left__updates__at_start_of_third_word(void** state);
void key_ctrl_left__updates__when_in_third_word(void** state);
void key_ctrl_left__updates__at_end_of_third_word(void** state);
void key_ctrl_left__updates__when_in_third_space(void** state);
void key_ctrl_left__updates__when_at_end(void** state);
void key_ctrl_left__updates__when_in_only_whitespace(void** state);
void key_ctrl_left__updates__when_start_whitespace_start_of_word(void** state);
void key_ctrl_left__updates__when_start_whitespace_middle_of_word(void** state);
void key_ctrl_left__updates__in_whitespace_between_words(void** state);
void key_ctrl_left__updates__in_whitespace_between_words_start_of_word(void** state);
void key_ctrl_left__updates__in_whitespace_between_words_middle_of_word(void** state);
void key_ctrl_left__updates__when_word_overrun_to_left(void** state);
void key_ctrl_right__updates__when_no_input(void** state);
void key_ctrl_right__updates__when_at_end(void** state);
void key_ctrl_right__updates__one_word_at_start(void** state);
void key_ctrl_right__updates__one_word_in_middle(void** state);
void key_ctrl_right__updates__one_word_at_end(void** state);
void key_ctrl_right__updates__two_words_from_middle_first(void** state);
void key_ctrl_right__updates__two_words_from_end_first(void** state);
void key_ctrl_right__updates__two_words_from_space(void** state);
void key_ctrl_right__updates__two_words_from_start_second(void** state);
void key_ctrl_right__updates__one_word_leading_whitespace(void** state);
void key_ctrl_right__updates__two_words_in_whitespace(void** state);
void key_ctrl_right__updates__trailing_whitespace_from_middle(void** state);
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,3 +1,11 @@
/*
* stub_xmpp.c
*
* Copyright (C) 2015 - 2018 James Booth <boothj5@gmail.com>
* Copyright (C) 2019 - 2026 Michael Vetter <jubalh@iodoru.org>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include "prof_cmocka.h"
#include "xmpp/xmpp.h"
@@ -162,11 +170,6 @@ connection_get_profanity_identifier(void)
return "profident";
}
void
connection_debug_print_features()
{
}
jabber_conn_status_t
connection_register(const char* const altdomain, int port, const char* const tls_policy,
const char* const username, const char* const password)
@@ -613,3 +616,9 @@ void
blocked_ac_reset(void)
{
}
GList*
connection_get_available_resources(void)
{
return NULL;
}

View File

@@ -5,14 +5,14 @@
#include "xmpp/chat_session.h"
void
returns_false_when_chat_session_does_not_exist(void** state)
chat_session_get__returns__null_when_no_session(void** state)
{
ChatSession* session = chat_session_get("somejid@server.org");
assert_null(session);
}
void
creates_chat_session_on_recipient_activity(void** state)
chat_session_recipient_active__updates__new_session(void** state)
{
char* barejid = "myjid@server.org";
char* resource = "tablet";
@@ -25,7 +25,7 @@ creates_chat_session_on_recipient_activity(void** state)
}
void
replaces_chat_session_on_recipient_activity_with_different_resource(void** state)
chat_session_recipient_active__updates__replace_resource(void** state)
{
char* barejid = "myjid@server.org";
char* resource1 = "tablet";
@@ -39,7 +39,7 @@ replaces_chat_session_on_recipient_activity_with_different_resource(void** state
}
void
removes_chat_session(void** state)
chat_session_remove__updates__session_removed(void** state)
{
char* barejid = "myjid@server.org";
char* resource1 = "laptop";

View File

@@ -0,0 +1,9 @@
#ifndef TESTS_TEST_CHAT_SESSION_H
#define TESTS_TEST_CHAT_SESSION_H
void chat_session_get__returns__null_when_no_session(void** state);
void chat_session_recipient_active__updates__new_session(void** state);
void chat_session_recipient_active__updates__replace_resource(void** state);
void chat_session_remove__updates__session_removed(void** state);
#endif

View File

@@ -6,10 +6,10 @@
#include "xmpp/contact.h"
void
contact_in_group(void** state)
p_contact_in_group__is__true_when_in_group(void** state)
{
GSList* groups = NULL;
groups = g_slist_append(groups, strdup("somegroup"));
groups = g_slist_append(groups, g_strdup("somegroup"));
PContact contact = p_contact_new("bob@server.com", "bob", groups, "both",
"is offline", FALSE);
@@ -22,10 +22,10 @@ contact_in_group(void** state)
}
void
contact_not_in_group(void** state)
p_contact_in_group__is__false_when_not_in_group(void** state)
{
GSList* groups = NULL;
groups = g_slist_append(groups, strdup("somegroup"));
groups = g_slist_append(groups, g_strdup("somegroup"));
PContact contact = p_contact_new("bob@server.com", "bob", groups, "both",
"is offline", FALSE);
@@ -38,7 +38,7 @@ contact_not_in_group(void** state)
}
void
contact_name_when_name_exists(void** state)
p_contact_name_or_jid__returns__name_when_exists(void** state)
{
PContact contact = p_contact_new("bob@server.com", "bob", NULL, "both",
"is offline", FALSE);
@@ -51,7 +51,7 @@ contact_name_when_name_exists(void** state)
}
void
contact_jid_when_name_not_exists(void** state)
p_contact_name_or_jid__returns__jid_when_name_not_exists(void** state)
{
PContact contact = p_contact_new("bob@server.com", NULL, NULL, "both",
"is offline", FALSE);
@@ -64,7 +64,7 @@ contact_jid_when_name_not_exists(void** state)
}
void
contact_string_when_name_exists(void** state)
p_contact_create_display_string__returns__name_and_resource_when_name_exists(void** state)
{
PContact contact = p_contact_new("bob@server.com", "bob", NULL, "both",
"is offline", FALSE);
@@ -74,11 +74,11 @@ contact_string_when_name_exists(void** state)
assert_string_equal("bob (laptop)", str);
p_contact_free(contact);
free(str);
g_free(str);
}
void
contact_string_when_name_not_exists(void** state)
p_contact_create_display_string__returns__jid_and_resource_when_name_not_exists(void** state)
{
PContact contact = p_contact_new("bob@server.com", NULL, NULL, "both",
"is offline", FALSE);
@@ -88,11 +88,11 @@ contact_string_when_name_not_exists(void** state)
assert_string_equal("bob@server.com (laptop)", str);
p_contact_free(contact);
free(str);
g_free(str);
}
void
contact_string_when_default_resource(void** state)
p_contact_create_display_string__returns__name_when_default_resource(void** state)
{
PContact contact = p_contact_new("bob@server.com", "bob", NULL, "both",
"is offline", FALSE);
@@ -102,11 +102,11 @@ contact_string_when_default_resource(void** state)
assert_string_equal("bob", str);
p_contact_free(contact);
free(str);
g_free(str);
}
void
contact_presence_offline(void** state)
p_contact_presence__returns__offline_when_no_resources(void** state)
{
PContact contact = p_contact_new("bob@server.com", "bob", NULL, "both",
"is offline", FALSE);
@@ -119,7 +119,7 @@ contact_presence_offline(void** state)
}
void
contact_presence_uses_highest_priority(void** state)
p_contact_presence__returns__highest_priority_presence(void** state)
{
PContact contact = p_contact_new("bob@server.com", "bob", NULL, "both",
"is offline", FALSE);
@@ -143,7 +143,7 @@ contact_presence_uses_highest_priority(void** state)
}
void
contact_presence_chat_when_same_prioroty(void** state)
p_contact_presence__returns__chat_when_same_priority(void** state)
{
PContact contact = p_contact_new("bob@server.com", "bob", NULL, "both",
"is offline", FALSE);
@@ -167,7 +167,7 @@ contact_presence_chat_when_same_prioroty(void** state)
}
void
contact_presence_online_when_same_prioroty(void** state)
p_contact_presence__returns__online_when_same_priority(void** state)
{
PContact contact = p_contact_new("bob@server.com", "bob", NULL, "both",
"is offline", FALSE);
@@ -189,7 +189,7 @@ contact_presence_online_when_same_prioroty(void** state)
}
void
contact_presence_away_when_same_prioroty(void** state)
p_contact_presence__returns__away_when_same_priority(void** state)
{
PContact contact = p_contact_new("bob@server.com", "bob", NULL, "both",
"is offline", FALSE);
@@ -209,7 +209,7 @@ contact_presence_away_when_same_prioroty(void** state)
}
void
contact_presence_xa_when_same_prioroty(void** state)
p_contact_presence__returns__xa_when_same_priority(void** state)
{
PContact contact = p_contact_new("bob@server.com", "bob", NULL, "both",
"is offline", FALSE);
@@ -227,7 +227,7 @@ contact_presence_xa_when_same_prioroty(void** state)
}
void
contact_presence_dnd(void** state)
p_contact_presence__returns__dnd(void** state)
{
PContact contact = p_contact_new("bob@server.com", "bob", NULL, "both",
"is offline", FALSE);
@@ -243,7 +243,7 @@ contact_presence_dnd(void** state)
}
void
contact_subscribed_when_to(void** state)
p_contact_subscribed__is__true_when_to(void** state)
{
PContact contact = p_contact_new("bob@server.com", "bob", NULL, "to",
"is offline", FALSE);
@@ -256,7 +256,7 @@ contact_subscribed_when_to(void** state)
}
void
contact_subscribed_when_both(void** state)
p_contact_subscribed__is__true_when_both(void** state)
{
PContact contact = p_contact_new("bob@server.com", "bob", NULL, "both",
"is offline", FALSE);
@@ -269,7 +269,7 @@ contact_subscribed_when_both(void** state)
}
void
contact_not_subscribed_when_from(void** state)
p_contact_subscribed__is__false_when_from(void** state)
{
PContact contact = p_contact_new("bob@server.com", "bob", NULL, "from",
"is offline", FALSE);
@@ -282,7 +282,7 @@ contact_not_subscribed_when_from(void** state)
}
void
contact_not_subscribed_when_no_subscription_value(void** state)
p_contact_subscribed__is__false_when_no_subscription_value(void** state)
{
PContact contact = p_contact_new("bob@server.com", "bob", NULL, NULL,
"is offline", FALSE);
@@ -295,7 +295,7 @@ contact_not_subscribed_when_no_subscription_value(void** state)
}
void
contact_not_available(void** state)
p_contact_is_available__is__false_when_offline(void** state)
{
PContact contact = p_contact_new("bob@server.com", "bob", NULL, NULL,
"is offline", FALSE);
@@ -308,7 +308,7 @@ contact_not_available(void** state)
}
void
contact_not_available_when_highest_priority_away(void** state)
p_contact_is_available__is__false_when_highest_priority_away(void** state)
{
PContact contact = p_contact_new("bob@server.com", "bob", NULL, NULL,
"is offline", FALSE);
@@ -332,7 +332,7 @@ contact_not_available_when_highest_priority_away(void** state)
}
void
contact_not_available_when_highest_priority_xa(void** state)
p_contact_is_available__is__false_when_highest_priority_xa(void** state)
{
PContact contact = p_contact_new("bob@server.com", "bob", NULL, NULL,
"is offline", FALSE);
@@ -356,7 +356,7 @@ contact_not_available_when_highest_priority_xa(void** state)
}
void
contact_not_available_when_highest_priority_dnd(void** state)
p_contact_is_available__is__false_when_highest_priority_dnd(void** state)
{
PContact contact = p_contact_new("bob@server.com", "bob", NULL, NULL,
"is offline", FALSE);
@@ -380,7 +380,7 @@ contact_not_available_when_highest_priority_dnd(void** state)
}
void
contact_available_when_highest_priority_online(void** state)
p_contact_is_available__is__true_when_highest_priority_online(void** state)
{
PContact contact = p_contact_new("bob@server.com", "bob", NULL, NULL,
"is offline", FALSE);
@@ -404,7 +404,7 @@ contact_available_when_highest_priority_online(void** state)
}
void
contact_available_when_highest_priority_chat(void** state)
p_contact_is_available__is__true_when_highest_priority_chat(void** state)
{
PContact contact = p_contact_new("bob@server.com", "bob", NULL, NULL,
"is offline", FALSE);

View File

@@ -0,0 +1,29 @@
#ifndef TESTS_TEST_CONTACT_H
#define TESTS_TEST_CONTACT_H
void p_contact_in_group__is__true_when_in_group(void** state);
void p_contact_in_group__is__false_when_not_in_group(void** state);
void p_contact_name_or_jid__returns__name_when_exists(void** state);
void p_contact_name_or_jid__returns__jid_when_name_not_exists(void** state);
void p_contact_create_display_string__returns__name_and_resource_when_name_exists(void** state);
void p_contact_create_display_string__returns__jid_and_resource_when_name_not_exists(void** state);
void p_contact_create_display_string__returns__name_when_default_resource(void** state);
void p_contact_presence__returns__offline_when_no_resources(void** state);
void p_contact_presence__returns__highest_priority_presence(void** state);
void p_contact_presence__returns__chat_when_same_priority(void** state);
void p_contact_presence__returns__online_when_same_priority(void** state);
void p_contact_presence__returns__away_when_same_priority(void** state);
void p_contact_presence__returns__xa_when_same_priority(void** state);
void p_contact_presence__returns__dnd(void** state);
void p_contact_subscribed__is__true_when_to(void** state);
void p_contact_subscribed__is__true_when_both(void** state);
void p_contact_subscribed__is__false_when_from(void** state);
void p_contact_subscribed__is__false_when_no_subscription_value(void** state);
void p_contact_is_available__is__false_when_offline(void** state);
void p_contact_is_available__is__false_when_highest_priority_away(void** state);
void p_contact_is_available__is__false_when_highest_priority_xa(void** state);
void p_contact_is_available__is__false_when_highest_priority_dnd(void** state);
void p_contact_is_available__is__true_when_highest_priority_online(void** state);
void p_contact_is_available__is__true_when_highest_priority_chat(void** state);
#endif

View File

@@ -13,13 +13,13 @@ connection_get_ctx(void)
static DataForm*
_new_form(void)
{
DataForm* form = malloc(sizeof(DataForm));
DataForm* form = g_new0(DataForm, 1);
form->type = NULL;
form->title = NULL;
form->instructions = NULL;
form->fields = NULL;
form->var_to_tag = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
form->tag_to_var = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
form->var_to_tag = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
form->tag_to_var = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
form->tag_ac = NULL;
return form;
@@ -28,7 +28,7 @@ _new_form(void)
static FormField*
_new_field(void)
{
FormField* field = malloc(sizeof(FormField));
FormField* field = g_new0(FormField, 1);
field->label = NULL;
field->type = NULL;
field->description = NULL;
@@ -42,7 +42,7 @@ _new_field(void)
}
void
get_form_type_field_returns_null_no_fields(void** state)
form_get_form_type_field__returns__null_no_fields(void** state)
{
DataForm* form = _new_form();
@@ -54,12 +54,12 @@ get_form_type_field_returns_null_no_fields(void** state)
}
void
get_form_type_field_returns_null_when_not_present(void** state)
form_get_form_type_field__returns__null_when_not_present(void** state)
{
DataForm* form = _new_form();
FormField* field = _new_field();
field->var = strdup("var1");
field->values = g_slist_append(field->values, strdup("value1"));
field->var = g_strdup("var1");
field->values = g_slist_append(field->values, g_strdup("value1"));
form->fields = g_slist_append(form->fields, field);
char* result = form_get_form_type_field(form);
@@ -70,23 +70,23 @@ get_form_type_field_returns_null_when_not_present(void** state)
}
void
get_form_type_field_returns_value_when_present(void** state)
form_get_form_type_field__returns__value_when_present(void** state)
{
DataForm* form = _new_form();
FormField* field1 = _new_field();
field1->var = strdup("var1");
field1->values = g_slist_append(field1->values, strdup("value1"));
field1->var = g_strdup("var1");
field1->values = g_slist_append(field1->values, g_strdup("value1"));
form->fields = g_slist_append(form->fields, field1);
FormField* field2 = _new_field();
field2->var = strdup("FORM_TYPE");
field2->values = g_slist_append(field2->values, strdup("value2"));
field2->var = g_strdup("FORM_TYPE");
field2->values = g_slist_append(field2->values, g_strdup("value2"));
form->fields = g_slist_append(form->fields, field2);
FormField* field3 = _new_field();
field3->var = strdup("var3");
field3->values = g_slist_append(field3->values, strdup("value3"));
field3->var = g_strdup("var3");
field3->values = g_slist_append(field3->values, g_strdup("value3"));
form->fields = g_slist_append(form->fields, field3);
char* result = form_get_form_type_field(form);
@@ -97,7 +97,7 @@ get_form_type_field_returns_value_when_present(void** state)
}
void
get_field_type_returns_unknown_when_no_fields(void** state)
form_get_field_type__returns__unknown_when_no_fields(void** state)
{
DataForm* form = _new_form();
@@ -109,22 +109,22 @@ get_field_type_returns_unknown_when_no_fields(void** state)
}
void
get_field_type_returns_correct_type(void** state)
form_get_field_type__returns__correct_type(void** state)
{
DataForm* form = _new_form();
g_hash_table_insert(form->tag_to_var, strdup("tag1"), strdup("var1"));
g_hash_table_insert(form->tag_to_var, strdup("tag2"), strdup("var2"));
g_hash_table_insert(form->tag_to_var, g_strdup("tag1"), g_strdup("var1"));
g_hash_table_insert(form->tag_to_var, g_strdup("tag2"), g_strdup("var2"));
FormField* field1 = _new_field();
field1->var = strdup("var1");
field1->var = g_strdup("var1");
field1->type_t = FIELD_TEXT_SINGLE;
field1->values = g_slist_append(field1->values, strdup("value1"));
field1->values = g_slist_append(field1->values, g_strdup("value1"));
form->fields = g_slist_append(form->fields, field1);
FormField* field2 = _new_field();
field2->var = strdup("var2");
field2->var = g_strdup("var2");
field2->type_t = FIELD_TEXT_MULTI;
field2->values = g_slist_append(field2->values, strdup("value2"));
field2->values = g_slist_append(field2->values, g_strdup("value2"));
form->fields = g_slist_append(form->fields, field2);
form_field_type_t result = form_get_field_type(form, "tag2");
@@ -135,20 +135,20 @@ get_field_type_returns_correct_type(void** state)
}
void
set_value_adds_when_none(void** state)
form_set_value__updates__adds_when_none(void** state)
{
DataForm* form = _new_form();
g_hash_table_insert(form->tag_to_var, strdup("tag1"), strdup("var1"));
g_hash_table_insert(form->tag_to_var, strdup("tag2"), strdup("var2"));
g_hash_table_insert(form->tag_to_var, g_strdup("tag1"), g_strdup("var1"));
g_hash_table_insert(form->tag_to_var, g_strdup("tag2"), g_strdup("var2"));
FormField* field1 = _new_field();
field1->var = strdup("var1");
field1->var = g_strdup("var1");
field1->type_t = FIELD_TEXT_SINGLE;
field1->values = g_slist_append(field1->values, strdup("value1"));
field1->values = g_slist_append(field1->values, g_strdup("value1"));
form->fields = g_slist_append(form->fields, field1);
FormField* field2 = _new_field();
field2->var = strdup("var2");
field2->var = g_strdup("var2");
field2->type_t = FIELD_LIST_SINGLE;
form->fields = g_slist_append(form->fields, field2);
@@ -174,21 +174,21 @@ set_value_adds_when_none(void** state)
}
void
set_value_updates_when_one(void** state)
form_set_value__updates__updates_when_one(void** state)
{
DataForm* form = _new_form();
g_hash_table_insert(form->tag_to_var, strdup("tag1"), strdup("var1"));
g_hash_table_insert(form->tag_to_var, strdup("tag2"), strdup("var2"));
g_hash_table_insert(form->tag_to_var, g_strdup("tag1"), g_strdup("var1"));
g_hash_table_insert(form->tag_to_var, g_strdup("tag2"), g_strdup("var2"));
FormField* field1 = _new_field();
field1->var = strdup("var1");
field1->var = g_strdup("var1");
field1->type_t = FIELD_TEXT_SINGLE;
form->fields = g_slist_append(form->fields, field1);
FormField* field2 = _new_field();
field2->var = strdup("var2");
field2->var = g_strdup("var2");
field2->type_t = FIELD_LIST_SINGLE;
field2->values = g_slist_append(field2->values, strdup("value2"));
field2->values = g_slist_append(field2->values, g_strdup("value2"));
form->fields = g_slist_append(form->fields, field2);
form_set_value(form, "tag2", "a new value");
@@ -213,21 +213,21 @@ set_value_updates_when_one(void** state)
}
void
add_unique_value_adds_when_none(void** state)
form_add_unique_value__updates__adds_when_none(void** state)
{
DataForm* form = _new_form();
g_hash_table_insert(form->tag_to_var, strdup("tag1"), strdup("var1"));
g_hash_table_insert(form->tag_to_var, strdup("tag2"), strdup("var2"));
g_hash_table_insert(form->tag_to_var, g_strdup("tag1"), g_strdup("var1"));
g_hash_table_insert(form->tag_to_var, g_strdup("tag2"), g_strdup("var2"));
FormField* field1 = _new_field();
field1->var = strdup("var1");
field1->var = g_strdup("var1");
field1->type_t = FIELD_JID_MULTI;
form->fields = g_slist_append(form->fields, field1);
FormField* field2 = _new_field();
field2->var = strdup("var2");
field2->var = g_strdup("var2");
field2->type_t = FIELD_LIST_SINGLE;
field2->values = g_slist_append(field2->values, strdup("value2"));
field2->values = g_slist_append(field2->values, g_strdup("value2"));
form->fields = g_slist_append(form->fields, field2);
gboolean ret = form_add_unique_value(form, "tag1", "me@server.com");
@@ -253,22 +253,22 @@ add_unique_value_adds_when_none(void** state)
}
void
add_unique_value_does_nothing_when_exists(void** state)
form_add_unique_value__updates__does_nothing_when_exists(void** state)
{
DataForm* form = _new_form();
g_hash_table_insert(form->tag_to_var, strdup("tag1"), strdup("var1"));
g_hash_table_insert(form->tag_to_var, strdup("tag2"), strdup("var2"));
g_hash_table_insert(form->tag_to_var, g_strdup("tag1"), g_strdup("var1"));
g_hash_table_insert(form->tag_to_var, g_strdup("tag2"), g_strdup("var2"));
FormField* field1 = _new_field();
field1->var = strdup("var1");
field1->var = g_strdup("var1");
field1->type_t = FIELD_JID_MULTI;
field1->values = g_slist_append(field1->values, strdup("me@server.com"));
field1->values = g_slist_append(field1->values, g_strdup("me@server.com"));
form->fields = g_slist_append(form->fields, field1);
FormField* field2 = _new_field();
field2->var = strdup("var2");
field2->var = g_strdup("var2");
field2->type_t = FIELD_LIST_SINGLE;
field2->values = g_slist_append(field2->values, strdup("value2"));
field2->values = g_slist_append(field2->values, g_strdup("value2"));
form->fields = g_slist_append(form->fields, field2);
gboolean ret = form_add_unique_value(form, "tag1", "me@server.com");
@@ -294,24 +294,24 @@ add_unique_value_does_nothing_when_exists(void** state)
}
void
add_unique_value_adds_when_doesnt_exist(void** state)
form_add_unique_value__updates__adds_when_doesnt_exist(void** state)
{
DataForm* form = _new_form();
g_hash_table_insert(form->tag_to_var, strdup("tag1"), strdup("var1"));
g_hash_table_insert(form->tag_to_var, strdup("tag2"), strdup("var2"));
g_hash_table_insert(form->tag_to_var, g_strdup("tag1"), g_strdup("var1"));
g_hash_table_insert(form->tag_to_var, g_strdup("tag2"), g_strdup("var2"));
FormField* field1 = _new_field();
field1->var = strdup("var1");
field1->var = g_strdup("var1");
field1->type_t = FIELD_JID_MULTI;
field1->values = g_slist_append(field1->values, strdup("dolan@server.com"));
field1->values = g_slist_append(field1->values, strdup("kieran@server.com"));
field1->values = g_slist_append(field1->values, strdup("chi@server.com"));
field1->values = g_slist_append(field1->values, g_strdup("dolan@server.com"));
field1->values = g_slist_append(field1->values, g_strdup("kieran@server.com"));
field1->values = g_slist_append(field1->values, g_strdup("chi@server.com"));
form->fields = g_slist_append(form->fields, field1);
FormField* field2 = _new_field();
field2->var = strdup("var2");
field2->var = g_strdup("var2");
field2->type_t = FIELD_LIST_SINGLE;
field2->values = g_slist_append(field2->values, strdup("value2"));
field2->values = g_slist_append(field2->values, g_strdup("value2"));
form->fields = g_slist_append(form->fields, field2);
gboolean ret = form_add_unique_value(form, "tag1", "me@server.com");
@@ -343,13 +343,13 @@ add_unique_value_adds_when_doesnt_exist(void** state)
}
void
add_value_adds_when_none(void** state)
form_add_value__updates__adds_when_none(void** state)
{
DataForm* form = _new_form();
g_hash_table_insert(form->tag_to_var, strdup("tag1"), strdup("var1"));
g_hash_table_insert(form->tag_to_var, g_strdup("tag1"), g_strdup("var1"));
FormField* field1 = _new_field();
field1->var = strdup("var1");
field1->var = g_strdup("var1");
field1->type_t = FIELD_LIST_MULTI;
form->fields = g_slist_append(form->fields, field1);
@@ -375,17 +375,17 @@ add_value_adds_when_none(void** state)
}
void
add_value_adds_when_some(void** state)
form_add_value__updates__adds_when_some(void** state)
{
DataForm* form = _new_form();
g_hash_table_insert(form->tag_to_var, strdup("tag1"), strdup("var1"));
g_hash_table_insert(form->tag_to_var, g_strdup("tag1"), g_strdup("var1"));
FormField* field1 = _new_field();
field1->var = strdup("var1");
field1->var = g_strdup("var1");
field1->type_t = FIELD_LIST_MULTI;
field1->values = g_slist_append(field1->values, strdup("some text"));
field1->values = g_slist_append(field1->values, strdup("some more text"));
field1->values = g_slist_append(field1->values, strdup("yet some more text"));
field1->values = g_slist_append(field1->values, g_strdup("some text"));
field1->values = g_slist_append(field1->values, g_strdup("some more text"));
field1->values = g_slist_append(field1->values, g_strdup("yet some more text"));
form->fields = g_slist_append(form->fields, field1);
form_add_value(form, "tag1", "new value");
@@ -416,18 +416,18 @@ add_value_adds_when_some(void** state)
}
void
add_value_adds_when_exists(void** state)
form_add_value__updates__adds_when_exists(void** state)
{
DataForm* form = _new_form();
g_hash_table_insert(form->tag_to_var, strdup("tag1"), strdup("var1"));
g_hash_table_insert(form->tag_to_var, g_strdup("tag1"), g_strdup("var1"));
FormField* field1 = _new_field();
field1->var = strdup("var1");
field1->var = g_strdup("var1");
field1->type_t = FIELD_LIST_MULTI;
field1->values = g_slist_append(field1->values, strdup("some text"));
field1->values = g_slist_append(field1->values, strdup("some more text"));
field1->values = g_slist_append(field1->values, strdup("yet some more text"));
field1->values = g_slist_append(field1->values, strdup("new value"));
field1->values = g_slist_append(field1->values, g_strdup("some text"));
field1->values = g_slist_append(field1->values, g_strdup("some more text"));
field1->values = g_slist_append(field1->values, g_strdup("yet some more text"));
field1->values = g_slist_append(field1->values, g_strdup("new value"));
form->fields = g_slist_append(form->fields, field1);
form_add_value(form, "tag1", "new value");
@@ -458,13 +458,13 @@ add_value_adds_when_exists(void** state)
}
void
remove_value_does_nothing_when_none(void** state)
form_remove_value__updates__does_nothing_when_none(void** state)
{
DataForm* form = _new_form();
g_hash_table_insert(form->tag_to_var, strdup("tag1"), strdup("var1"));
g_hash_table_insert(form->tag_to_var, g_strdup("tag1"), g_strdup("var1"));
FormField* field1 = _new_field();
field1->var = strdup("var1");
field1->var = g_strdup("var1");
field1->type_t = FIELD_LIST_MULTI;
form->fields = g_slist_append(form->fields, field1);
@@ -487,18 +487,18 @@ remove_value_does_nothing_when_none(void** state)
}
void
remove_value_does_nothing_when_doesnt_exist(void** state)
form_remove_value__updates__does_nothing_when_doesnt_exist(void** state)
{
DataForm* form = _new_form();
g_hash_table_insert(form->tag_to_var, strdup("tag1"), strdup("var1"));
g_hash_table_insert(form->tag_to_var, g_strdup("tag1"), g_strdup("var1"));
FormField* field1 = _new_field();
field1->var = strdup("var1");
field1->var = g_strdup("var1");
field1->type_t = FIELD_LIST_MULTI;
field1->values = g_slist_append(field1->values, strdup("value1"));
field1->values = g_slist_append(field1->values, strdup("value2"));
field1->values = g_slist_append(field1->values, strdup("value3"));
field1->values = g_slist_append(field1->values, strdup("value4"));
field1->values = g_slist_append(field1->values, g_strdup("value1"));
field1->values = g_slist_append(field1->values, g_strdup("value2"));
field1->values = g_slist_append(field1->values, g_strdup("value3"));
field1->values = g_slist_append(field1->values, g_strdup("value4"));
form->fields = g_slist_append(form->fields, field1);
gboolean res = form_remove_value(form, "tag1", "value5");
@@ -529,15 +529,15 @@ remove_value_does_nothing_when_doesnt_exist(void** state)
}
void
remove_value_removes_when_one(void** state)
form_remove_value__updates__removes_when_one(void** state)
{
DataForm* form = _new_form();
g_hash_table_insert(form->tag_to_var, strdup("tag1"), strdup("var1"));
g_hash_table_insert(form->tag_to_var, g_strdup("tag1"), g_strdup("var1"));
FormField* field1 = _new_field();
field1->var = strdup("var1");
field1->var = g_strdup("var1");
field1->type_t = FIELD_LIST_MULTI;
field1->values = g_slist_append(field1->values, strdup("value4"));
field1->values = g_slist_append(field1->values, g_strdup("value4"));
form->fields = g_slist_append(form->fields, field1);
gboolean res = form_remove_value(form, "tag1", "value4");
@@ -559,18 +559,18 @@ remove_value_removes_when_one(void** state)
}
void
remove_value_removes_when_many(void** state)
form_remove_value__updates__removes_when_many(void** state)
{
DataForm* form = _new_form();
g_hash_table_insert(form->tag_to_var, strdup("tag1"), strdup("var1"));
g_hash_table_insert(form->tag_to_var, g_strdup("tag1"), g_strdup("var1"));
FormField* field1 = _new_field();
field1->var = strdup("var1");
field1->var = g_strdup("var1");
field1->type_t = FIELD_LIST_MULTI;
field1->values = g_slist_append(field1->values, strdup("value1"));
field1->values = g_slist_append(field1->values, strdup("value2"));
field1->values = g_slist_append(field1->values, strdup("value3"));
field1->values = g_slist_append(field1->values, strdup("value4"));
field1->values = g_slist_append(field1->values, g_strdup("value1"));
field1->values = g_slist_append(field1->values, g_strdup("value2"));
field1->values = g_slist_append(field1->values, g_strdup("value3"));
field1->values = g_slist_append(field1->values, g_strdup("value4"));
form->fields = g_slist_append(form->fields, field1);
gboolean res = form_remove_value(form, "tag1", "value2");
@@ -601,13 +601,13 @@ remove_value_removes_when_many(void** state)
}
void
remove_text_multi_value_does_nothing_when_none(void** state)
form_remove_text_multi_value__updates__does_nothing_when_none(void** state)
{
DataForm* form = _new_form();
g_hash_table_insert(form->tag_to_var, strdup("tag1"), strdup("var1"));
g_hash_table_insert(form->tag_to_var, g_strdup("tag1"), g_strdup("var1"));
FormField* field1 = _new_field();
field1->var = strdup("var1");
field1->var = g_strdup("var1");
field1->type_t = FIELD_LIST_MULTI;
form->fields = g_slist_append(form->fields, field1);
@@ -630,18 +630,18 @@ remove_text_multi_value_does_nothing_when_none(void** state)
}
void
remove_text_multi_value_does_nothing_when_doesnt_exist(void** state)
form_remove_text_multi_value__updates__does_nothing_when_doesnt_exist(void** state)
{
DataForm* form = _new_form();
g_hash_table_insert(form->tag_to_var, strdup("tag1"), strdup("var1"));
g_hash_table_insert(form->tag_to_var, g_strdup("tag1"), g_strdup("var1"));
FormField* field1 = _new_field();
field1->var = strdup("var1");
field1->var = g_strdup("var1");
field1->type_t = FIELD_LIST_MULTI;
field1->values = g_slist_append(field1->values, strdup("value1"));
field1->values = g_slist_append(field1->values, strdup("value2"));
field1->values = g_slist_append(field1->values, strdup("value3"));
field1->values = g_slist_append(field1->values, strdup("value4"));
field1->values = g_slist_append(field1->values, g_strdup("value1"));
field1->values = g_slist_append(field1->values, g_strdup("value2"));
field1->values = g_slist_append(field1->values, g_strdup("value3"));
field1->values = g_slist_append(field1->values, g_strdup("value4"));
form->fields = g_slist_append(form->fields, field1);
gboolean res = form_remove_text_multi_value(form, "tag1", 5);
@@ -672,15 +672,15 @@ remove_text_multi_value_does_nothing_when_doesnt_exist(void** state)
}
void
remove_text_multi_value_removes_when_one(void** state)
form_remove_text_multi_value__updates__removes_when_one(void** state)
{
DataForm* form = _new_form();
g_hash_table_insert(form->tag_to_var, strdup("tag1"), strdup("var1"));
g_hash_table_insert(form->tag_to_var, g_strdup("tag1"), g_strdup("var1"));
FormField* field1 = _new_field();
field1->var = strdup("var1");
field1->var = g_strdup("var1");
field1->type_t = FIELD_LIST_MULTI;
field1->values = g_slist_append(field1->values, strdup("value4"));
field1->values = g_slist_append(field1->values, g_strdup("value4"));
form->fields = g_slist_append(form->fields, field1);
gboolean res = form_remove_text_multi_value(form, "tag1", 1);
@@ -702,18 +702,18 @@ remove_text_multi_value_removes_when_one(void** state)
}
void
remove_text_multi_value_removes_when_many(void** state)
form_remove_text_multi_value__updates__removes_when_many(void** state)
{
DataForm* form = _new_form();
g_hash_table_insert(form->tag_to_var, strdup("tag1"), strdup("var1"));
g_hash_table_insert(form->tag_to_var, g_strdup("tag1"), g_strdup("var1"));
FormField* field1 = _new_field();
field1->var = strdup("var1");
field1->var = g_strdup("var1");
field1->type_t = FIELD_LIST_MULTI;
field1->values = g_slist_append(field1->values, strdup("value1"));
field1->values = g_slist_append(field1->values, strdup("value2"));
field1->values = g_slist_append(field1->values, strdup("value3"));
field1->values = g_slist_append(field1->values, strdup("value4"));
field1->values = g_slist_append(field1->values, g_strdup("value1"));
field1->values = g_slist_append(field1->values, g_strdup("value2"));
field1->values = g_slist_append(field1->values, g_strdup("value3"));
field1->values = g_slist_append(field1->values, g_strdup("value4"));
form->fields = g_slist_append(form->fields, field1);
gboolean res = form_remove_text_multi_value(form, "tag1", 2);

View File

@@ -0,0 +1,26 @@
#ifndef TESTS_TEST_FORM_H
#define TESTS_TEST_FORM_H
void form_get_form_type_field__returns__null_no_fields(void** state);
void form_get_form_type_field__returns__null_when_not_present(void** state);
void form_get_form_type_field__returns__value_when_present(void** state);
void form_get_field_type__returns__unknown_when_no_fields(void** state);
void form_get_field_type__returns__correct_type(void** state);
void form_set_value__updates__adds_when_none(void** state);
void form_set_value__updates__updates_when_one(void** state);
void form_add_unique_value__updates__adds_when_none(void** state);
void form_add_unique_value__updates__does_nothing_when_exists(void** state);
void form_add_unique_value__updates__adds_when_doesnt_exist(void** state);
void form_add_value__updates__adds_when_none(void** state);
void form_add_value__updates__adds_when_some(void** state);
void form_add_value__updates__adds_when_exists(void** state);
void form_remove_value__updates__does_nothing_when_none(void** state);
void form_remove_value__updates__does_nothing_when_doesnt_exist(void** state);
void form_remove_value__updates__removes_when_one(void** state);
void form_remove_value__updates__removes_when_many(void** state);
void form_remove_text_multi_value__updates__does_nothing_when_none(void** state);
void form_remove_text_multi_value__updates__does_nothing_when_doesnt_exist(void** state);
void form_remove_text_multi_value__updates__removes_when_one(void** state);
void form_remove_text_multi_value__updates__removes_when_many(void** state);
#endif

View File

@@ -0,0 +1,372 @@
#include "prof_cmocka.h"
#include <stdlib.h>
#include "xmpp/jid.h"
void
jid_create__returns__null_from_null(void** state)
{
Jid* result = jid_create(NULL);
assert_null(result);
}
void
jid_create__returns__null_from_empty_string(void** state)
{
Jid* result = jid_create("");
assert_null(result);
}
void
jid_create__returns__full_from_full(void** state)
{
Jid* result = jid_create("myuser@mydomain/laptop");
assert_string_equal("myuser@mydomain/laptop", result->fulljid);
jid_destroy(result);
}
void
jid_create__returns__bare_from_full(void** state)
{
Jid* result = jid_create("myuser@mydomain/laptop");
assert_string_equal("myuser@mydomain", result->barejid);
jid_destroy(result);
}
void
jid_create__returns__resourcepart_from_full(void** state)
{
Jid* result = jid_create("myuser@mydomain/laptop");
assert_string_equal("laptop", result->resourcepart);
jid_destroy(result);
}
void
jid_create__returns__localpart_from_full(void** state)
{
Jid* result = jid_create("myuser@mydomain/laptop");
assert_string_equal("myuser", result->localpart);
jid_destroy(result);
}
void
jid_create__returns__domainpart_from_full(void** state)
{
Jid* result = jid_create("myuser@mydomain/laptop");
assert_string_equal("mydomain", result->domainpart);
jid_destroy(result);
}
void
jid_create__returns__full_from_full_nolocal(void** state)
{
Jid* result = jid_create("mydomain/laptop");
assert_string_equal("mydomain/laptop", result->fulljid);
jid_destroy(result);
}
void
jid_create__returns__bare_from_full_nolocal(void** state)
{
Jid* result = jid_create("mydomain/laptop");
assert_string_equal("mydomain", result->barejid);
jid_destroy(result);
}
void
jid_create__returns__resourcepart_from_full_nolocal(void** state)
{
Jid* result = jid_create("mydomain/laptop");
assert_string_equal("laptop", result->resourcepart);
jid_destroy(result);
}
void
jid_create__returns__domainpart_from_full_nolocal(void** state)
{
Jid* result = jid_create("mydomain/laptop");
assert_string_equal("mydomain", result->domainpart);
jid_destroy(result);
}
void
jid_create__returns__null_localpart_from_full_nolocal(void** state)
{
Jid* result = jid_create("mydomain/laptop");
assert_null(result->localpart);
jid_destroy(result);
}
void
jid_create__returns__null_full_from_bare(void** state)
{
Jid* result = jid_create("myuser@mydomain");
assert_null(result->fulljid);
jid_destroy(result);
}
void
jid_create__returns__null_resource_from_bare(void** state)
{
Jid* result = jid_create("myuser@mydomain");
assert_null(result->resourcepart);
jid_destroy(result);
}
void
jid_create__returns__bare_from_bare(void** state)
{
Jid* result = jid_create("myuser@mydomain");
assert_string_equal("myuser@mydomain", result->barejid);
jid_destroy(result);
}
void
jid_create__returns__localpart_from_bare(void** state)
{
Jid* result = jid_create("myuser@mydomain");
assert_string_equal("myuser", result->localpart);
jid_destroy(result);
}
void
jid_create__returns__domainpart_from_bare(void** state)
{
Jid* result = jid_create("myuser@mydomain");
assert_string_equal("mydomain", result->domainpart);
jid_destroy(result);
}
void
jid_create_from_bare_and_resource__returns__room(void** state)
{
Jid* result = jid_create_from_bare_and_resource("room@conference.domain.org", "myname");
assert_string_equal("room@conference.domain.org", result->barejid);
jid_destroy(result);
}
void
jid_create_from_bare_and_resource__returns__nick(void** state)
{
Jid* result = jid_create_from_bare_and_resource("room@conference.domain.org", "myname");
assert_string_equal("myname", result->resourcepart);
jid_destroy(result);
}
void
jid_create__returns__correct_parts_with_slash_in_resource(void** state)
{
Jid* result = jid_create("room@conference.domain.org/my/nick");
assert_string_equal("room", result->localpart);
assert_string_equal("conference.domain.org", result->domainpart);
assert_string_equal("my/nick", result->resourcepart);
assert_string_equal("room@conference.domain.org", result->barejid);
assert_string_equal("room@conference.domain.org/my/nick", result->fulljid);
jid_destroy(result);
}
void
jid_create__returns__correct_parts_with_at_in_resource(void** state)
{
Jid* result = jid_create("room@conference.domain.org/my@nick");
assert_string_equal("room", result->localpart);
assert_string_equal("conference.domain.org", result->domainpart);
assert_string_equal("my@nick", result->resourcepart);
assert_string_equal("room@conference.domain.org", result->barejid);
assert_string_equal("room@conference.domain.org/my@nick", result->fulljid);
jid_destroy(result);
}
void
jid_create__returns__correct_parts_with_at_and_slash_in_resource(void** state)
{
Jid* result = jid_create("room@conference.domain.org/my@nick/something");
assert_string_equal("room", result->localpart);
assert_string_equal("conference.domain.org", result->domainpart);
assert_string_equal("my@nick/something", result->resourcepart);
assert_string_equal("room@conference.domain.org", result->barejid);
assert_string_equal("room@conference.domain.org/my@nick/something", result->fulljid);
jid_destroy(result);
}
void
jid_create__returns__correct_parts_with_trailing_slash(void** state)
{
Jid* result = jid_create("room@conference.domain.org/nick/");
assert_string_equal("room", result->localpart);
assert_string_equal("conference.domain.org", result->domainpart);
assert_string_equal("nick/", result->resourcepart);
assert_string_equal("room@conference.domain.org", result->barejid);
assert_string_equal("room@conference.domain.org/nick/", result->fulljid);
jid_destroy(result);
}
void
jid_fulljid_or_barejid__returns__fulljid_when_exists(void** state)
{
Jid* jid = jid_create("localpart@domainpart/resourcepart");
const gchar* result = jid_fulljid_or_barejid(jid);
assert_string_equal("localpart@domainpart/resourcepart", result);
jid_destroy(jid);
}
void
jid_fulljid_or_barejid__returns__barejid_when_fulljid_not_exists(void** state)
{
Jid* jid = jid_create("localpart@domainpart");
const gchar* result = jid_fulljid_or_barejid(jid);
assert_string_equal("localpart@domainpart", result);
jid_destroy(jid);
}
void
jid_create__returns__bare_from_trailing_slash(void** state)
{
Jid* result = jid_create("myuser@mydomain/");
assert_non_null(result);
assert_string_equal("myuser@mydomain", result->barejid);
assert_null(result->resourcepart);
jid_destroy(result);
}
void
jid_create__returns__null_from_invalid_localpart_chars(void** state)
{
// Space
Jid* result = jid_create("user name@domain.com");
assert_null(result);
// Double quote
result = jid_create("user\"name@domain.com");
assert_null(result);
// Ampersand
result = jid_create("user&name@domain.com");
assert_null(result);
// Single quote
result = jid_create("user'name@domain.com");
assert_null(result);
// Colon
result = jid_create("user:name@domain.com");
assert_null(result);
// Less than
result = jid_create("user<name@domain.com");
assert_null(result);
// Greater than
result = jid_create("user>name@domain.com");
assert_null(result);
}
void
jid_create__returns__null_from_empty_parts(void** state)
{
// Empty local
Jid* result = jid_create("@domain.com");
assert_null(result);
// Empty domain (trailing @)
result = jid_create("user@");
assert_null(result);
// Empty domain in full jid
result = jid_create("user@/resource");
assert_null(result);
}
void
jid_create__returns__null_from_multiple_at_in_bare(void** state)
{
Jid* result = jid_create("user@domain@other.com");
assert_null(result);
}
void
jid_create__returns__correct_parts_with_at_in_resource_only(void** state)
{
// domain.com/user@host (no localpart)
Jid* result = jid_create("domain.com/user@host");
assert_non_null(result);
assert_null(result->localpart);
assert_string_equal("domain.com", result->domainpart);
assert_string_equal("user@host", result->resourcepart);
jid_destroy(result);
}
void
jid_is_valid_user_jid__is__true_for_valid_user_jid(void** state)
{
assert_true(jid_is_valid_user_jid("myuser@mydomain/laptop"));
assert_true(jid_is_valid_user_jid("myuser@mydomain"));
}
void
jid_is_valid_user_jid__is__true_for_at_in_resource(void** state)
{
// RFC 6122 section 2.4: '@' is allowed in the resourcepart.
assert_true(jid_is_valid_user_jid("myuser@mydomain/user@laptop"));
assert_true(jid_is_valid_user_jid("room@conference.example.org/user@host.example.org"));
}
void
jid_is_valid_user_jid__is__false_for_domain_jid(void** state)
{
assert_false(jid_is_valid_user_jid("mydomain/laptop"));
assert_false(jid_is_valid_user_jid("mydomain"));
}
void
jid_is_valid_user_jid__is__false_for_invalid_jid(void** state)
{
assert_false(jid_is_valid_user_jid("@mydomain"));
assert_false(jid_is_valid_user_jid("/laptop"));
assert_false(jid_is_valid_user_jid(NULL));
assert_false(jid_is_valid_user_jid(""));
}
void
jid_is_valid__is__true_for_valid_jid(void** state)
{
assert_true(jid_is_valid("myuser@mydomain/laptop"));
assert_true(jid_is_valid("myuser@mydomain"));
assert_true(jid_is_valid("mydomain/laptop"));
assert_true(jid_is_valid("mydomain"));
}
void
jid_is_valid__is__false_for_invalid_jid(void** state)
{
assert_false(jid_is_valid("@mydomain"));
assert_false(jid_is_valid("/laptop"));
}
void
jid_is_valid__is__false_for_null(void** state)
{
assert_false(jid_is_valid(NULL));
}
void
jid_is_valid__is__false_for_empty_string(void** state)
{
assert_false(jid_is_valid(""));
}

View File

@@ -0,0 +1,43 @@
#ifndef TESTS_TEST_JID_H
#define TESTS_TEST_JID_H
void jid_create__returns__null_from_null(void** state);
void jid_create__returns__null_from_empty_string(void** state);
void jid_create__returns__full_from_full(void** state);
void jid_create__returns__bare_from_full(void** state);
void jid_create__returns__resourcepart_from_full(void** state);
void jid_create__returns__localpart_from_full(void** state);
void jid_create__returns__domainpart_from_full(void** state);
void jid_create__returns__full_from_full_nolocal(void** state);
void jid_create__returns__bare_from_full_nolocal(void** state);
void jid_create__returns__resourcepart_from_full_nolocal(void** state);
void jid_create__returns__domainpart_from_full_nolocal(void** state);
void jid_create__returns__null_localpart_from_full_nolocal(void** state);
void jid_create__returns__null_full_from_bare(void** state);
void jid_create__returns__null_resource_from_bare(void** state);
void jid_create__returns__bare_from_bare(void** state);
void jid_create__returns__localpart_from_bare(void** state);
void jid_create__returns__domainpart_from_bare(void** state);
void jid_create_from_bare_and_resource__returns__room(void** state);
void jid_create_from_bare_and_resource__returns__nick(void** state);
void jid_create__returns__correct_parts_with_slash_in_resource(void** state);
void jid_create__returns__correct_parts_with_at_in_resource(void** state);
void jid_create__returns__correct_parts_with_at_and_slash_in_resource(void** state);
void jid_create__returns__correct_parts_with_trailing_slash(void** state);
void jid_fulljid_or_barejid__returns__fulljid_when_exists(void** state);
void jid_fulljid_or_barejid__returns__barejid_when_fulljid_not_exists(void** state);
void jid_create__returns__bare_from_trailing_slash(void** state);
void jid_create__returns__null_from_invalid_localpart_chars(void** state);
void jid_create__returns__null_from_empty_parts(void** state);
void jid_create__returns__null_from_multiple_at_in_bare(void** state);
void jid_create__returns__correct_parts_with_at_in_resource_only(void** state);
void jid_is_valid_user_jid__is__true_for_valid_user_jid(void** state);
void jid_is_valid_user_jid__is__true_for_at_in_resource(void** state);
void jid_is_valid_user_jid__is__false_for_domain_jid(void** state);
void jid_is_valid_user_jid__is__false_for_invalid_jid(void** state);
void jid_is_valid__is__true_for_valid_jid(void** state);
void jid_is_valid__is__false_for_invalid_jid(void** state);
void jid_is_valid__is__false_for_null(void** state);
void jid_is_valid__is__false_for_empty_string(void** state);
#endif

View File

@@ -20,7 +20,7 @@ muc_after_test(void** state)
}
void
test_muc_invites_add(void** state)
muc_invites_add__updates__invites_list(void** state)
{
char* room = "room@conf.server";
muc_invites_add(room, NULL);
@@ -31,7 +31,7 @@ test_muc_invites_add(void** state)
}
void
test_muc_remove_invite(void** state)
muc_invites_remove__updates__invites_list(void** state)
{
char* room = "room@conf.server";
muc_invites_add(room, NULL);
@@ -43,7 +43,7 @@ test_muc_remove_invite(void** state)
}
void
test_muc_invites_count_0(void** state)
muc_invites_count__returns__0_when_no_invites(void** state)
{
int invite_count = muc_invites_count();
@@ -51,7 +51,7 @@ test_muc_invites_count_0(void** state)
}
void
test_muc_invites_count_5(void** state)
muc_invites_count__returns__5_when_five_invites_added(void** state)
{
muc_invites_add("room1@conf.server", NULL);
muc_invites_add("room2@conf.server", NULL);
@@ -65,7 +65,7 @@ test_muc_invites_count_5(void** state)
}
void
test_muc_room_is_not_active(void** state)
muc_active__is__false_when_not_joined(void** state)
{
char* room = "room@server.org";
@@ -75,7 +75,7 @@ test_muc_room_is_not_active(void** state)
}
void
test_muc_active(void** state)
muc_active__is__true_when_joined(void** state)
{
char* room = "room@server.org";
char* nick = "bob";

View File

@@ -0,0 +1,14 @@
#ifndef TESTS_TEST_MUC_H
#define TESTS_TEST_MUC_H
int muc_before_test(void** state);
int muc_after_test(void** state);
void muc_invites_add__updates__invites_list(void** state);
void muc_invites_remove__updates__invites_list(void** state);
void muc_invites_count__returns__0_when_no_invites(void** state);
void muc_invites_count__returns__5_when_five_invites_added(void** state);
void muc_active__is__false_when_not_joined(void** state);
void muc_active__is__true_when_joined(void** state);
#endif

View File

@@ -7,7 +7,7 @@
#include "xmpp/roster_list.h"
void
empty_list_when_none_added(void** state)
roster_get_contacts__returns__empty_list_when_none_added(void** state)
{
roster_create();
GSList* list = roster_get_contacts(ROSTER_ORD_NAME);
@@ -18,7 +18,7 @@ empty_list_when_none_added(void** state)
}
void
contains_one_element(void** state)
roster_get_contacts__returns__one_element(void** state)
{
roster_create();
roster_add("James", NULL, NULL, NULL, FALSE);
@@ -30,7 +30,7 @@ contains_one_element(void** state)
}
void
first_element_correct(void** state)
roster_get_contacts__returns__correct_first_element(void** state)
{
roster_create();
roster_add("James", NULL, NULL, NULL, FALSE);
@@ -44,7 +44,7 @@ first_element_correct(void** state)
}
void
contains_two_elements(void** state)
roster_get_contacts__returns__two_elements(void** state)
{
roster_create();
roster_add("James", NULL, NULL, NULL, FALSE);
@@ -58,7 +58,7 @@ contains_two_elements(void** state)
}
void
first_and_second_elements_correct(void** state)
roster_get_contacts__returns__correct_first_and_second_elements(void** state)
{
roster_create();
roster_add("James", NULL, NULL, NULL, FALSE);
@@ -76,7 +76,7 @@ first_and_second_elements_correct(void** state)
}
void
contains_three_elements(void** state)
roster_get_contacts__returns__three_elements(void** state)
{
roster_create();
roster_add("James", NULL, NULL, NULL, FALSE);
@@ -91,7 +91,7 @@ contains_three_elements(void** state)
}
void
first_three_elements_correct(void** state)
roster_get_contacts__returns__correct_first_three_elements(void** state)
{
roster_create();
roster_add("Bob", NULL, NULL, NULL, FALSE);
@@ -111,7 +111,7 @@ first_three_elements_correct(void** state)
}
void
add_twice_at_beginning_adds_once(void** state)
roster_add__updates__adds_once_when_called_twice_at_beginning(void** state)
{
roster_create();
roster_add("James", NULL, NULL, NULL, FALSE);
@@ -133,7 +133,7 @@ add_twice_at_beginning_adds_once(void** state)
}
void
add_twice_in_middle_adds_once(void** state)
roster_add__updates__adds_once_when_called_twice_in_middle(void** state)
{
roster_create();
roster_add("James", NULL, NULL, NULL, FALSE);
@@ -155,7 +155,7 @@ add_twice_in_middle_adds_once(void** state)
}
void
add_twice_at_end_adds_once(void** state)
roster_add__updates__adds_once_when_called_twice_at_end(void** state)
{
roster_create();
roster_add("James", NULL, NULL, NULL, FALSE);
@@ -177,24 +177,24 @@ add_twice_at_end_adds_once(void** state)
}
void
find_first_exists(void** state)
roster_contact_autocomplete__returns__first_exists(void** state)
{
roster_create();
roster_add("James", NULL, NULL, NULL, FALSE);
roster_add("Dave", NULL, NULL, NULL, FALSE);
roster_add("Bob", NULL, NULL, NULL, FALSE);
char* search = strdup("B");
char* search = g_strdup("B");
char* result = roster_contact_autocomplete(search, FALSE, NULL);
assert_string_equal("Bob", result);
free(result);
free(search);
g_free(result);
g_free(search);
roster_destroy();
}
void
find_second_exists(void** state)
roster_contact_autocomplete__returns__second_exists(void** state)
{
roster_create();
roster_add("James", NULL, NULL, NULL, FALSE);
@@ -203,12 +203,12 @@ find_second_exists(void** state)
char* result = roster_contact_autocomplete("Dav", FALSE, NULL);
assert_string_equal("Dave", result);
free(result);
g_free(result);
roster_destroy();
}
void
find_third_exists(void** state)
roster_contact_autocomplete__returns__third_exists(void** state)
{
roster_create();
roster_add("James", NULL, NULL, NULL, FALSE);
@@ -217,12 +217,12 @@ find_third_exists(void** state)
char* result = roster_contact_autocomplete("Ja", FALSE, NULL);
assert_string_equal("James", result);
free(result);
g_free(result);
roster_destroy();
}
void
find_returns_null(void** state)
roster_contact_autocomplete__returns__null_when_no_match(void** state)
{
roster_create();
roster_add("James", NULL, NULL, NULL, FALSE);
@@ -235,7 +235,7 @@ find_returns_null(void** state)
}
void
find_on_empty_returns_null(void** state)
roster_contact_autocomplete__returns__null_on_empty_roster(void** state)
{
roster_create();
char* result = roster_contact_autocomplete("James", FALSE, NULL);
@@ -244,7 +244,7 @@ find_on_empty_returns_null(void** state)
}
void
find_twice_returns_second_when_two_match(void** state)
roster_contact_autocomplete__returns__second_when_two_match(void** state)
{
roster_create();
roster_add("James", NULL, NULL, NULL, FALSE);
@@ -254,13 +254,13 @@ find_twice_returns_second_when_two_match(void** state)
char* result1 = roster_contact_autocomplete("Jam", FALSE, NULL);
char* result2 = roster_contact_autocomplete(result1, FALSE, NULL);
assert_string_equal("Jamie", result2);
free(result1);
free(result2);
g_free(result1);
g_free(result2);
roster_destroy();
}
void
find_five_times_finds_fifth(void** state)
roster_contact_autocomplete__returns__fifth_when_multiple_match(void** state)
{
roster_create();
roster_add("Jama", NULL, NULL, NULL, FALSE);
@@ -280,16 +280,16 @@ find_five_times_finds_fifth(void** state)
char* result4 = roster_contact_autocomplete(result3, FALSE, NULL);
char* result5 = roster_contact_autocomplete(result4, FALSE, NULL);
assert_string_equal("Jamo", result5);
free(result1);
free(result2);
free(result3);
free(result4);
free(result5);
g_free(result1);
g_free(result2);
g_free(result3);
g_free(result4);
g_free(result5);
roster_destroy();
}
void
find_twice_returns_first_when_two_match_and_reset(void** state)
roster_contact_autocomplete__returns__first_when_two_match_and_reset(void** state)
{
roster_create();
roster_add("James", NULL, NULL, NULL, FALSE);
@@ -300,13 +300,35 @@ find_twice_returns_first_when_two_match_and_reset(void** state)
roster_reset_search_attempts();
char* result2 = roster_contact_autocomplete(result1, FALSE, NULL);
assert_string_equal("James", result2);
free(result1);
free(result2);
g_free(result1);
g_free(result2);
roster_destroy();
}
void
add_contact_with_no_group(void** state)
roster_contact_autocomplete__returns__utf8(void** state)
{
roster_create();
roster_add("Σωκράτης", NULL, NULL, NULL, FALSE);
roster_add("Πλάτων", NULL, NULL, NULL, FALSE);
// Byte-wise (strcmp): Πλάτων (CE A0...) < Σωκράτης (CE A3...)
char* result = roster_contact_autocomplete("Π", FALSE, NULL);
assert_string_equal("Πλάτων", result);
g_free(result);
roster_reset_search_attempts();
result = roster_contact_autocomplete("σω", FALSE, NULL);
assert_string_equal("Σωκράτης", result);
g_free(result);
roster_destroy();
}
void
roster_get_groups__returns__empty_for_no_group(void** state)
{
roster_create();
roster_add("person@server.org", NULL, NULL, NULL, FALSE);
@@ -314,17 +336,17 @@ add_contact_with_no_group(void** state)
GList* groups_res = roster_get_groups();
assert_int_equal(g_list_length(groups_res), 0);
g_list_free_full(groups_res, free);
g_list_free_full(groups_res, g_free);
roster_destroy();
}
void
add_contact_with_group(void** state)
roster_get_groups__returns__one_group(void** state)
{
roster_create();
GSList* groups = NULL;
groups = g_slist_append(groups, strdup("friends"));
groups = g_slist_append(groups, g_strdup("friends"));
roster_add("person@server.org", NULL, groups, NULL, FALSE);
GList* groups_res = roster_get_groups();
@@ -334,18 +356,18 @@ add_contact_with_group(void** state)
assert_true(found != NULL);
assert_string_equal(found->data, "friends");
g_list_free_full(groups_res, free);
g_list_free_full(groups_res, g_free);
roster_destroy();
}
void
add_contact_with_two_groups(void** state)
roster_get_groups__returns__two_groups(void** state)
{
roster_create();
GSList* groups = NULL;
groups = g_slist_append(groups, strdup("friends"));
groups = g_slist_append(groups, strdup("work"));
groups = g_slist_append(groups, g_strdup("friends"));
groups = g_slist_append(groups, g_strdup("work"));
roster_add("person@server.org", NULL, groups, NULL, FALSE);
GList* groups_res = roster_get_groups();
@@ -358,19 +380,19 @@ add_contact_with_two_groups(void** state)
assert_true(found != NULL);
assert_string_equal(found->data, "work");
g_list_free_full(groups_res, free);
g_list_free_full(groups_res, g_free);
roster_destroy();
}
void
add_contact_with_three_groups(void** state)
roster_get_groups__returns__three_groups(void** state)
{
roster_create();
GSList* groups = NULL;
groups = g_slist_append(groups, strdup("friends"));
groups = g_slist_append(groups, strdup("work"));
groups = g_slist_append(groups, strdup("stuff"));
groups = g_slist_append(groups, g_strdup("friends"));
groups = g_slist_append(groups, g_strdup("work"));
groups = g_slist_append(groups, g_strdup("stuff"));
roster_add("person@server.org", NULL, groups, NULL, FALSE);
GList* groups_res = roster_get_groups();
@@ -386,27 +408,27 @@ add_contact_with_three_groups(void** state)
assert_true(found != NULL);
assert_string_equal(found->data, "stuff");
g_list_free_full(groups_res, free);
g_list_free_full(groups_res, g_free);
roster_destroy();
}
void
add_contact_with_three_groups_update_adding_two(void** state)
roster_update__updates__adding_two_groups(void** state)
{
roster_create();
GSList* groups1 = NULL;
groups1 = g_slist_append(groups1, strdup("friends"));
groups1 = g_slist_append(groups1, strdup("work"));
groups1 = g_slist_append(groups1, strdup("stuff"));
groups1 = g_slist_append(groups1, g_strdup("friends"));
groups1 = g_slist_append(groups1, g_strdup("work"));
groups1 = g_slist_append(groups1, g_strdup("stuff"));
roster_add("person@server.org", NULL, groups1, NULL, FALSE);
GSList* groups2 = NULL;
groups2 = g_slist_append(groups2, strdup("friends"));
groups2 = g_slist_append(groups2, strdup("work"));
groups2 = g_slist_append(groups2, strdup("stuff"));
groups2 = g_slist_append(groups2, strdup("things"));
groups2 = g_slist_append(groups2, strdup("people"));
groups2 = g_slist_append(groups2, g_strdup("friends"));
groups2 = g_slist_append(groups2, g_strdup("work"));
groups2 = g_slist_append(groups2, g_strdup("stuff"));
groups2 = g_slist_append(groups2, g_strdup("things"));
groups2 = g_slist_append(groups2, g_strdup("people"));
roster_update("person@server.org", NULL, groups2, NULL, FALSE);
GList* groups_res = roster_get_groups();
@@ -428,24 +450,24 @@ add_contact_with_three_groups_update_adding_two(void** state)
assert_true(found != NULL);
assert_string_equal(found->data, "people");
g_list_free_full(groups_res, free);
g_list_free_full(groups_res, g_free);
roster_destroy();
}
void
add_contact_with_three_groups_update_removing_one(void** state)
roster_update__updates__removing_one_group(void** state)
{
roster_create();
GSList* groups1 = NULL;
groups1 = g_slist_append(groups1, strdup("friends"));
groups1 = g_slist_append(groups1, strdup("work"));
groups1 = g_slist_append(groups1, strdup("stuff"));
groups1 = g_slist_append(groups1, g_strdup("friends"));
groups1 = g_slist_append(groups1, g_strdup("work"));
groups1 = g_slist_append(groups1, g_strdup("stuff"));
roster_add("person@server.org", NULL, groups1, NULL, FALSE);
GSList* groups2 = NULL;
groups2 = g_slist_append(groups2, strdup("friends"));
groups2 = g_slist_append(groups2, strdup("stuff"));
groups2 = g_slist_append(groups2, g_strdup("friends"));
groups2 = g_slist_append(groups2, g_strdup("stuff"));
roster_update("person@server.org", NULL, groups2, NULL, FALSE);
GList* groups_res = roster_get_groups();
@@ -458,23 +480,23 @@ add_contact_with_three_groups_update_removing_one(void** state)
assert_true(found != NULL);
assert_string_equal(found->data, "stuff");
g_list_free_full(groups_res, free);
g_list_free_full(groups_res, g_free);
roster_destroy();
}
void
add_contact_with_three_groups_update_removing_two(void** state)
roster_update__updates__removing_two_groups(void** state)
{
roster_create();
GSList* groups1 = NULL;
groups1 = g_slist_append(groups1, strdup("friends"));
groups1 = g_slist_append(groups1, strdup("work"));
groups1 = g_slist_append(groups1, strdup("stuff"));
groups1 = g_slist_append(groups1, g_strdup("friends"));
groups1 = g_slist_append(groups1, g_strdup("work"));
groups1 = g_slist_append(groups1, g_strdup("stuff"));
roster_add("person@server.org", NULL, groups1, NULL, FALSE);
GSList* groups2 = NULL;
groups2 = g_slist_append(groups2, strdup("stuff"));
groups2 = g_slist_append(groups2, g_strdup("stuff"));
roster_update("person@server.org", NULL, groups2, NULL, FALSE);
GList* groups_res = roster_get_groups();
@@ -484,19 +506,19 @@ add_contact_with_three_groups_update_removing_two(void** state)
assert_true(found != NULL);
assert_string_equal(found->data, "stuff");
g_list_free_full(groups_res, free);
g_list_free_full(groups_res, g_free);
roster_destroy();
}
void
add_contact_with_three_groups_update_removing_three(void** state)
roster_update__updates__removing_three_groups(void** state)
{
roster_create();
GSList* groups1 = NULL;
groups1 = g_slist_append(groups1, strdup("friends"));
groups1 = g_slist_append(groups1, strdup("work"));
groups1 = g_slist_append(groups1, strdup("stuff"));
groups1 = g_slist_append(groups1, g_strdup("friends"));
groups1 = g_slist_append(groups1, g_strdup("work"));
groups1 = g_slist_append(groups1, g_strdup("stuff"));
roster_add("person@server.org", NULL, groups1, NULL, FALSE);
roster_update("person@server.org", NULL, NULL, NULL, FALSE);
@@ -504,24 +526,24 @@ add_contact_with_three_groups_update_removing_three(void** state)
GList* groups_res = roster_get_groups();
assert_int_equal(g_list_length(groups_res), 0);
g_list_free_full(groups_res, free);
g_list_free_full(groups_res, g_free);
roster_destroy();
}
void
add_contact_with_three_groups_update_two_new(void** state)
roster_update__updates__two_new_groups(void** state)
{
roster_create();
GSList* groups1 = NULL;
groups1 = g_slist_append(groups1, strdup("friends"));
groups1 = g_slist_append(groups1, strdup("work"));
groups1 = g_slist_append(groups1, strdup("stuff"));
groups1 = g_slist_append(groups1, g_strdup("friends"));
groups1 = g_slist_append(groups1, g_strdup("work"));
groups1 = g_slist_append(groups1, g_strdup("stuff"));
roster_add("person@server.org", NULL, groups1, NULL, FALSE);
GSList* groups2 = NULL;
groups2 = g_slist_append(groups2, strdup("newfriends"));
groups2 = g_slist_append(groups2, strdup("somepeople"));
groups2 = g_slist_append(groups2, g_strdup("newfriends"));
groups2 = g_slist_append(groups2, g_strdup("somepeople"));
roster_update("person@server.org", NULL, groups2, NULL, FALSE);
GList* groups_res = roster_get_groups();
@@ -532,19 +554,19 @@ add_contact_with_three_groups_update_two_new(void** state)
found = g_list_find_custom(groups_res, "somepeople", (GCompareFunc)g_strcmp0);
assert_true(found != NULL);
g_list_free_full(groups_res, free);
g_list_free_full(groups_res, g_free);
roster_destroy();
}
void
add_remove_contact_groups(void** state)
roster_remove__updates__contact_groups(void** state)
{
roster_create();
GSList* groups1 = NULL;
groups1 = g_slist_append(groups1, strdup("friends"));
groups1 = g_slist_append(groups1, strdup("work"));
groups1 = g_slist_append(groups1, strdup("stuff"));
groups1 = g_slist_append(groups1, g_strdup("friends"));
groups1 = g_slist_append(groups1, g_strdup("work"));
groups1 = g_slist_append(groups1, g_strdup("stuff"));
roster_add("person@server.org", NULL, groups1, NULL, FALSE);
roster_remove("person@server.org", "person@server.org");
@@ -552,24 +574,24 @@ add_remove_contact_groups(void** state)
GList* groups_res = roster_get_groups();
assert_int_equal(g_list_length(groups_res), 0);
g_list_free_full(groups_res, free);
g_list_free_full(groups_res, g_free);
roster_destroy();
}
void
add_contacts_with_different_groups(void** state)
roster_add__updates__different_groups(void** state)
{
roster_create();
GSList* groups1 = NULL;
groups1 = g_slist_append(groups1, strdup("friends"));
groups1 = g_slist_append(groups1, strdup("work"));
groups1 = g_slist_append(groups1, strdup("stuff"));
groups1 = g_slist_append(groups1, g_strdup("friends"));
groups1 = g_slist_append(groups1, g_strdup("work"));
groups1 = g_slist_append(groups1, g_strdup("stuff"));
roster_add("person@server.org", NULL, groups1, NULL, FALSE);
GSList* groups2 = NULL;
groups2 = g_slist_append(groups2, strdup("newfriends"));
groups2 = g_slist_append(groups2, strdup("somepeople"));
groups2 = g_slist_append(groups2, g_strdup("newfriends"));
groups2 = g_slist_append(groups2, g_strdup("somepeople"));
roster_add("bob@server.org", NULL, groups2, NULL, FALSE);
GList* groups_res = roster_get_groups();
@@ -586,25 +608,25 @@ add_contacts_with_different_groups(void** state)
found = g_list_find_custom(groups_res, "somepeople", (GCompareFunc)g_strcmp0);
assert_true(found != NULL);
g_list_free_full(groups_res, free);
g_list_free_full(groups_res, g_free);
roster_destroy();
}
void
add_contacts_with_same_groups(void** state)
roster_add__updates__same_groups(void** state)
{
roster_create();
GSList* groups1 = NULL;
groups1 = g_slist_append(groups1, strdup("friends"));
groups1 = g_slist_append(groups1, strdup("work"));
groups1 = g_slist_append(groups1, strdup("stuff"));
groups1 = g_slist_append(groups1, g_strdup("friends"));
groups1 = g_slist_append(groups1, g_strdup("work"));
groups1 = g_slist_append(groups1, g_strdup("stuff"));
roster_add("person@server.org", NULL, groups1, NULL, FALSE);
GSList* groups2 = NULL;
groups2 = g_slist_append(groups2, strdup("friends"));
groups2 = g_slist_append(groups2, strdup("work"));
groups2 = g_slist_append(groups2, strdup("stuff"));
groups2 = g_slist_append(groups2, g_strdup("friends"));
groups2 = g_slist_append(groups2, g_strdup("work"));
groups2 = g_slist_append(groups2, g_strdup("stuff"));
roster_add("bob@server.org", NULL, groups2, NULL, FALSE);
GList* groups_res = roster_get_groups();
@@ -617,25 +639,25 @@ add_contacts_with_same_groups(void** state)
found = g_list_find_custom(groups_res, "stuff", (GCompareFunc)g_strcmp0);
assert_true(found != NULL);
g_list_free_full(groups_res, free);
g_list_free_full(groups_res, g_free);
roster_destroy();
}
void
add_contacts_with_overlapping_groups(void** state)
roster_add__updates__overlapping_groups(void** state)
{
roster_create();
GSList* groups1 = NULL;
groups1 = g_slist_append(groups1, strdup("friends"));
groups1 = g_slist_append(groups1, strdup("work"));
groups1 = g_slist_append(groups1, strdup("stuff"));
groups1 = g_slist_append(groups1, g_strdup("friends"));
groups1 = g_slist_append(groups1, g_strdup("work"));
groups1 = g_slist_append(groups1, g_strdup("stuff"));
roster_add("person@server.org", NULL, groups1, NULL, FALSE);
GSList* groups2 = NULL;
groups2 = g_slist_append(groups2, strdup("friends"));
groups2 = g_slist_append(groups2, strdup("work"));
groups2 = g_slist_append(groups2, strdup("different"));
groups2 = g_slist_append(groups2, g_strdup("friends"));
groups2 = g_slist_append(groups2, g_strdup("work"));
groups2 = g_slist_append(groups2, g_strdup("different"));
roster_add("bob@server.org", NULL, groups2, NULL, FALSE);
GList* groups_res = roster_get_groups();
@@ -650,25 +672,25 @@ add_contacts_with_overlapping_groups(void** state)
found = g_list_find_custom(groups_res, "different", (GCompareFunc)g_strcmp0);
assert_true(found != NULL);
g_list_free_full(groups_res, free);
g_list_free_full(groups_res, g_free);
roster_destroy();
}
void
remove_contact_with_remaining_in_group(void** state)
roster_remove__updates__remaining_in_group(void** state)
{
roster_create();
GSList* groups1 = NULL;
groups1 = g_slist_append(groups1, strdup("friends"));
groups1 = g_slist_append(groups1, strdup("work"));
groups1 = g_slist_append(groups1, strdup("stuff"));
groups1 = g_slist_append(groups1, g_strdup("friends"));
groups1 = g_slist_append(groups1, g_strdup("work"));
groups1 = g_slist_append(groups1, g_strdup("stuff"));
roster_add("person@server.org", NULL, groups1, NULL, FALSE);
GSList* groups2 = NULL;
groups2 = g_slist_append(groups2, strdup("friends"));
groups2 = g_slist_append(groups2, strdup("work"));
groups2 = g_slist_append(groups2, strdup("different"));
groups2 = g_slist_append(groups2, g_strdup("friends"));
groups2 = g_slist_append(groups2, g_strdup("work"));
groups2 = g_slist_append(groups2, g_strdup("different"));
roster_add("bob@server.org", NULL, groups2, NULL, FALSE);
roster_remove("bob@server.org", "bob@server.org");
@@ -683,12 +705,12 @@ remove_contact_with_remaining_in_group(void** state)
found = g_list_find_custom(groups_res, "stuff", (GCompareFunc)g_strcmp0);
assert_true(found != NULL);
g_list_free_full(groups_res, free);
g_list_free_full(groups_res, g_free);
roster_destroy();
}
void
get_contact_display_name(void** state)
roster_get_display_name__returns__nickname_when_exists(void** state)
{
roster_create();
roster_add("person@server.org", "nickname", NULL, NULL, FALSE);
@@ -699,7 +721,7 @@ get_contact_display_name(void** state)
}
void
get_contact_display_name_is_barejid_if_name_is_empty(void** state)
roster_get_display_name__returns__barejid_when_nickname_empty(void** state)
{
roster_create();
roster_add("person@server.org", NULL, NULL, NULL, FALSE);
@@ -710,7 +732,7 @@ get_contact_display_name_is_barejid_if_name_is_empty(void** state)
}
void
get_contact_display_name_is_passed_barejid_if_contact_does_not_exist(void** state)
roster_get_display_name__returns__barejid_when_not_exists(void** state)
{
roster_create();

View File

@@ -0,0 +1,41 @@
#ifndef TESTS_TEST_ROSTER_LIST_H
#define TESTS_TEST_ROSTER_LIST_H
void roster_get_contacts__returns__empty_list_when_none_added(void** state);
void roster_get_contacts__returns__one_element(void** state);
void roster_get_contacts__returns__correct_first_element(void** state);
void roster_get_contacts__returns__two_elements(void** state);
void roster_get_contacts__returns__correct_first_and_second_elements(void** state);
void roster_get_contacts__returns__three_elements(void** state);
void roster_get_contacts__returns__correct_first_three_elements(void** state);
void roster_add__updates__adds_once_when_called_twice_at_beginning(void** state);
void roster_add__updates__adds_once_when_called_twice_in_middle(void** state);
void roster_add__updates__adds_once_when_called_twice_at_end(void** state);
void roster_contact_autocomplete__returns__first_exists(void** state);
void roster_contact_autocomplete__returns__second_exists(void** state);
void roster_contact_autocomplete__returns__third_exists(void** state);
void roster_contact_autocomplete__returns__null_when_no_match(void** state);
void roster_contact_autocomplete__returns__null_on_empty_roster(void** state);
void roster_contact_autocomplete__returns__second_when_two_match(void** state);
void roster_contact_autocomplete__returns__fifth_when_multiple_match(void** state);
void roster_contact_autocomplete__returns__first_when_two_match_and_reset(void** state);
void roster_contact_autocomplete__returns__utf8(void** state);
void roster_get_groups__returns__empty_for_no_group(void** state);
void roster_get_groups__returns__one_group(void** state);
void roster_get_groups__returns__two_groups(void** state);
void roster_get_groups__returns__three_groups(void** state);
void roster_update__updates__adding_two_groups(void** state);
void roster_update__updates__removing_one_group(void** state);
void roster_update__updates__removing_two_groups(void** state);
void roster_update__updates__removing_three_groups(void** state);
void roster_update__updates__two_new_groups(void** state);
void roster_remove__updates__contact_groups(void** state);
void roster_add__updates__different_groups(void** state);
void roster_add__updates__same_groups(void** state);
void roster_add__updates__overlapping_groups(void** state);
void roster_remove__updates__remaining_in_group(void** state);
void roster_get_display_name__returns__nickname_when_exists(void** state);
void roster_get_display_name__returns__barejid_when_nickname_empty(void** state);
void roster_get_display_name__returns__barejid_when_not_exists(void** state);
#endif