static void symmetric_key_from_too_short_bin_fails() { struct cpn_symmetric_key bin; assert_success(cpn_symmetric_key_from_hex(&bin, SYMMETRIC_KEY)); assert_failure(cpn_symmetric_key_from_bin(&key, bin.data, sizeof(bin.data) - 1)); }
static void connect_refuses_with_invalid_version() { ConnectionInitiationMessage initialization = CONNECTION_INITIATION_MESSAGE__INIT; SessionConnectMessage connect = SESSION_CONNECT_MESSAGE__INIT; CapabilityMessage cap = CAPABILITY_MESSAGE__INIT; struct handle_session_args args = { &remote, &local_keys.pk, &service, &config, 0 }; struct cpn_thread t; initialization.type = CONNECTION_INITIATION_MESSAGE__TYPE__CONNECT; connect.version = -1; connect.capability = ∩ connect.service_type = (char *) service.plugin->type; connect.service_version = service.plugin->version; cpn_spawn(&t, handle_session, &args); assert_success(cpn_channel_write_protobuf(&local, &initialization.base)); assert_success(cpn_channel_write_protobuf(&local, &connect.base)); cpn_join(&t, NULL); assert_failure(args.result); }
TEST(find_command, IF(not_windows)) { opt_handlers_setup(); replace_string(&cfg.shell, "/bin/sh"); assert_success(chdir(TEST_DATA_PATH)); strcpy(lwin.curr_dir, test_data); assert_success(exec_commands("set findprg='find %s %a %u'", &lwin, CIT_COMMAND)); /* Nothing to repeat. */ assert_failure(exec_commands("find", &lwin, CIT_COMMAND)); assert_success(exec_commands("find a", &lwin, CIT_COMMAND)); assert_int_equal(3, lwin.list_rows); assert_success(exec_commands("find . -name aaa", &lwin, CIT_COMMAND)); assert_int_equal(1, lwin.list_rows); assert_success(exec_commands("find -name '*.vifm'", &lwin, CIT_COMMAND)); assert_int_equal(4, lwin.list_rows); view_teardown(&lwin); view_setup(&lwin); /* Repeat last search. */ strcpy(lwin.curr_dir, test_data); assert_success(exec_commands("find", &lwin, CIT_COMMAND)); assert_int_equal(4, lwin.list_rows); opt_handlers_teardown(); }
static void connect_refuses_without_session() { struct handle_session_args args = { &remote, &local_keys.pk, &service, &config, 0 }; struct cpn_thread t; struct cpn_cap cap; struct cpn_session *session = NULL; cap.chain_depth = 0; cpn_spawn(&t, handle_session, &args); assert_failure(cpn_client_start_session(&session, &local, 1, &cap, service.plugin)); cpn_join(&t, NULL); assert_failure(args.result); assert_null(session); cpn_session_free(session); }
static void terminating_nonexistent_does_nothing() { struct handle_termination_args args = { &remote, &local_keys.pk, 0 }; struct cpn_thread t; struct cpn_cap cap; cap.chain_depth = 0; cpn_spawn(&t, handle_termination, &args); assert_success(cpn_client_terminate_session(&local, 12345, &cap)); cpn_join(&t, NULL); assert_failure(args.result); }
static void request_refuses_with_invalid_version() { ConnectionInitiationMessage initialization = CONNECTION_INITIATION_MESSAGE__INIT; SessionRequestMessage request = SESSION_REQUEST_MESSAGE__INIT; struct await_request_args args = { &remote, &service, &local_keys.pk, NULL, 0, 0 }; struct cpn_thread t; initialization.type = CONNECTION_INITIATION_MESSAGE__TYPE__REQUEST; request.version = -1; cpn_spawn(&t, await_request, &args); assert_success(cpn_channel_write_protobuf(&local, &initialization.base)); assert_success(cpn_channel_write_protobuf(&local, &request.base)); cpn_join(&t, NULL); assert_failure(args.result); }
static void query_refuses_with_invalid_version() { ConnectionInitiationMessage initialization = CONNECTION_INITIATION_MESSAGE__INIT; ServiceQueryMessage query = SERVICE_QUERY_MESSAGE__INIT; struct await_query_args args = { &remote, &service, 0 }; struct cpn_thread t; initialization.type = CONNECTION_INITIATION_MESSAGE__TYPE__QUERY; query.version = -1; cpn_spawn(&t, await_query, &args); assert_success(cpn_channel_write_protobuf(&local, &initialization.base)); assert_success(cpn_channel_write_protobuf(&local, &query.base)); cpn_join(&t, NULL); assert_failure(args.result); }
static void termination_refuses_with_invalid_version() { ConnectionInitiationMessage initialization = CONNECTION_INITIATION_MESSAGE__INIT; SessionTerminationMessage term = SESSION_TERMINATION_MESSAGE__INIT; CapabilityMessage cap = CAPABILITY_MESSAGE__INIT; struct await_query_args args = { &remote, &service, 0 }; struct cpn_thread t; initialization.type = CONNECTION_INITIATION_MESSAGE__TYPE__TERMINATE; term.capability = ∩ term.version = -1; cpn_spawn(&t, handle_termination, &args); assert_success(cpn_channel_write_protobuf(&local, &initialization.base)); assert_success(cpn_channel_write_protobuf(&local, &term.base)); cpn_join(&t, NULL); assert_failure(args.result); }
static void termination_kills_session() { struct handle_termination_args args = { &remote, &local_keys.pk, 0 }; struct cpn_thread t; struct cpn_cap *cap; const struct cpn_session *session; uint32_t sessionid; assert_success(cpn_sessions_add(&session, 0, &remote_keys.pk)); sessionid = session->identifier; assert_success(cpn_cap_create_ref(&cap, session->cap, CPN_CAP_RIGHT_TERM, &local_keys.pk)); cpn_spawn(&t, handle_termination, &args); assert_success(cpn_client_terminate_session(&local, sessionid, cap)); cpn_cap_free(cap); cpn_join(&t, NULL); assert_success(args.result); assert_failure(cpn_sessions_find(NULL, sessionid)); }
TEST(grep_command, IF(not_windows)) { opt_handlers_setup(); replace_string(&cfg.shell, "/bin/sh"); assert_success(chdir(TEST_DATA_PATH "/scripts")); assert_non_null(get_cwd(lwin.curr_dir, sizeof(lwin.curr_dir))); assert_success(exec_commands("set grepprg='grep -n -H -r %i %a %s %u'", &lwin, CIT_COMMAND)); /* Nothing to repeat. */ assert_failure(exec_commands("grep", &lwin, CIT_COMMAND)); assert_success(exec_commands("grep command", &lwin, CIT_COMMAND)); assert_int_equal(2, lwin.list_rows); /* Repeat last grep. */ assert_success(exec_commands("grep!", &lwin, CIT_COMMAND)); assert_int_equal(1, lwin.list_rows); opt_handlers_teardown(); }
SETUP() { static int option_changed; optval_t def = { .str_val = "/tmp" }; init_options(&option_changed, NULL); def.str_val = "/tmp"; add_option("fusehome", "fh", "descr", OPT_STR, OPT_GLOBAL, 0, NULL, &fusehome_handler, def); def.int_val = 0; add_option("number", "nu", "descr", OPT_BOOL, OPT_GLOBAL, 0, NULL, &number_handler, def); add_option("numberwidth", "nuw", "descr", OPT_INT, OPT_GLOBAL, 0, NULL, &numberwidth_global, def); add_option("numberwidth", "nuw", "descr", OPT_INT, OPT_LOCAL, 0, NULL, &numberwidth_local, def); fuse_home = NULL; number_width_global = 0; number_width_local = 0; } TEARDOWN() { clear_options(); } static void fusehome_handler(OPT_OP op, optval_t val) { fuse_home = val.str_val; } static void number_handler(OPT_OP op, optval_t val) { number = val.bool_val; } static void numberwidth_global(OPT_OP op, optval_t val) { number_width_global = val.int_val; } static void numberwidth_local(OPT_OP op, optval_t val) { number_width_local = val.int_val; } TEST(set_global_option_without_prefix) { assert_success(let_variables("&fusehome = 'value'")); assert_string_equal("value", fuse_home); } TEST(set_global_option_with_global_prefix) { assert_success(let_variables("&g:fusehome = 'value'")); assert_string_equal("value", fuse_home); } TEST(set_global_option_with_local_prefix) { assert_failure(let_variables("&l:fusehome = 'value'")); assert_string_equal(NULL, fuse_home); } TEST(set_global_and_local_option_without_prefix) { assert_success(let_variables("&numberwidth = 2")); assert_int_equal(2, number_width_global); assert_int_equal(2, number_width_local); } TEST(set_global_and_local_option_with_global_prefix) { assert_success(let_variables("&g:numberwidth = 2")); assert_int_equal(2, number_width_global); assert_int_equal(0, number_width_local); } TEST(set_global_and_local_option_with_local_prefix) { assert_success(let_variables("&l:numberwidth = 2")); assert_int_equal(0, number_width_global); assert_int_equal(2, number_width_local); } TEST(appending_works_for_strings) { assert_success(let_variables("&fusehome = 'value'")); assert_string_equal("value", fuse_home); assert_success(let_variables("&fusehome .= 'more'")); assert_string_equal("valuemore", fuse_home); } TEST(incdec_does_not_work_for_strings) { assert_failure(let_variables("&fusehome += 3")); assert_failure(let_variables("&fusehome -= 3")); } TEST(incdec_works_for_numbers) { assert_success(let_variables("&numberwidth += 2")); assert_int_equal(2, number_width_local); assert_success(let_variables("&numberwidth += 4")); assert_int_equal(6, number_width_local); assert_success(let_variables("&numberwidth -= 5")); assert_int_equal(1, number_width_local); } TEST(appending_does_not_work_for_numbers) { assert_failure(let_variables("&numberwidth .= 2")); } TEST(appending_does_not_work_for_bools) { assert_failure(let_variables("&number .= 2")); } TEST(addition_does_not_work_for_bools) { assert_failure(let_variables("&number += 2")); } #if 0 /* For the future. */ TEST(set_of_a_boolean_option) { assert_failure(let_variables("&number = 'a'")); assert_success(let_variables("&number = '1'")); assert_true(number); assert_success(let_variables("&number = '0'")); assert_false(number); }
static void symmetric_key_hex_from_too_short_bin_fails() { assert_success(cpn_symmetric_key_from_hex(&key, SYMMETRIC_KEY)); assert_failure(cpn_symmetric_key_hex_from_bin(&key_hex, key.data, sizeof(key.data) - 1)); }
static void symmetric_key_from_too_long_hex_fails() { assert_failure(cpn_symmetric_key_from_hex(&key, SYMMETRIC_KEY "1")); }
static void symmetric_key_from_too_short_hex_fails() { assert_failure(cpn_symmetric_key_from_hex(&key, "abc1234")); }
TEST(Fail, _unexpected_assertion) { assert_failure (); }