TEST(symlinks_to_dirs_are_recognized_as_dirs, IF(not_windows)) { char test_dir[PATH_MAX]; assert_non_null(os_realpath(TEST_DATA_PATH "/existing-files", test_dir)); assert_success(chdir(SANDBOX_PATH)); /* symlink() is not available on Windows, but other code is fine. */ #ifndef _WIN32 assert_success(symlink(test_dir, "dir-link")); #endif (void)test_dir; assert_false(flist_custom_active(&lwin)); flist_custom_start(&lwin, "test"); flist_custom_add(&lwin, "./dir-link"); assert_true(flist_custom_finish(&lwin, 0) == 0); assert_int_equal(1, lwin.list_rows); assert_true(is_directory_entry(&lwin.dir_entry[0])); assert_success(remove("dir-link")); }
TEST(reload_does_not_remove_broken_symlinks, IF(not_windows)) { char test_file[PATH_MAX]; assert_non_null(os_realpath(TEST_DATA_PATH "/existing-files/a", test_file)); assert_success(chdir(SANDBOX_PATH)); /* symlink() is not available on Windows, but other code is fine. */ #ifndef _WIN32 assert_success(symlink("/wrong/path", "broken-link")); #endif assert_false(flist_custom_active(&lwin)); flist_custom_start(&lwin, "test"); flist_custom_add(&lwin, test_file); flist_custom_add(&lwin, "./broken-link"); assert_true(flist_custom_finish(&lwin, 0) == 0); assert_int_equal(2, lwin.list_rows); load_dir_list(&lwin, 1); assert_int_equal(2, lwin.list_rows); assert_success(remove("broken-link")); }
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); }
static void whitlisted_request_constructs_session() { ProtobufCMessage *parsed; const char *params[] = { "testdata" }; struct await_request_args args = { &remote, &service, &local_keys.pk, &local_keys.pk, 1, 0 }; struct cpn_session *added; struct cpn_thread t; struct cpn_cap *cap = NULL; uint32_t sessionid; cpn_spawn(&t, await_request, &args); assert_success(test_service->parse_fn(&parsed, ARRAY_SIZE(params), params)); assert_success(cpn_client_request_session(&sessionid, &cap, &local, parsed)); cpn_join(&t, NULL); assert_success(args.result); assert_success(cpn_sessions_remove(&added, sessionid)); assert_int_equal(sessionid, added->identifier); cpn_session_free(added); cpn_cap_free(cap); protobuf_c_message_free_unpacked(parsed, NULL); }
static void set_file_perms(const int perms[13]) { FILE *f; int origin_perms[13] = { 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0 }; int adv_perms[3] = { 0, 0, 0 }; assert_non_null(f = fopen(SANDBOX_PATH "/file", "w")); fclose(f); assert_success(chmod(SANDBOX_PATH "/file", 0777)); if(get_perms(SANDBOX_PATH "/file") != 0777) { assert_success(unlink(SANDBOX_PATH "/file")); return; } strcpy(lwin.curr_dir, SANDBOX_PATH); alloc_file_list(&lwin, "file"); set_perm_string(&lwin, perms, origin_perms, adv_perms); free_file_list(&lwin); assert_int_equal(perms_to_mode(perms), get_perms(SANDBOX_PATH "/file")); assert_success(unlink(SANDBOX_PATH "/file")); }
TEST(mediaprg, IF(not_windows)) { assert_success(exec_commands("set mediaprg=prg", &lwin, CIT_COMMAND)); assert_string_equal("prg", cfg.media_prg); assert_success(exec_commands("set mediaprg=", &lwin, CIT_COMMAND)); assert_string_equal("", cfg.media_prg); }
TEST(symlinks_are_not_resolved_in_tree_preview, IF(not_windows)) { int nlines; FILE *fp; char **lines; assert_success(os_mkdir(SANDBOX_PATH "/dir", 0777)); /* symlink() is not available on Windows, but the rest of the code is fine. */ #ifndef _WIN32 assert_success(symlink(".", SANDBOX_PATH "/dir/link")); #endif fp = qv_view_dir(SANDBOX_PATH "/dir"); lines = read_file_lines(fp, &nlines); assert_int_equal(4, nlines); assert_string_equal("dir/", lines[0]); assert_string_equal("`-- link/ -> .", lines[1]); assert_string_equal("", lines[2]); assert_string_equal("1 directory, 0 files", lines[3]); free_string_array(lines, nlines); fclose(fp); assert_success(unlink(SANDBOX_PATH "/dir/link")); assert_success(rmdir(SANDBOX_PATH "/dir")); }
END_TEST START_TEST (normal_init) { int rc; char *msg, *filename; varnam *handle; filename = get_unique_filename(); rc = varnam_init(filename, &handle, &msg); assert_success (rc); if (handle->internal->config_use_dead_consonants != 0) { ck_abort_msg ("varnam_init() should have turned off use dead consonant option"); } rc = varnam_config (handle, VARNAM_CONFIG_USE_DEAD_CONSONANTS, 0); assert_success (rc); if (handle->internal->config_use_dead_consonants != 0) { ck_abort_msg ("varnam_config() is not changing value of use_dead_consonant option"); } varnam_destroy (handle); free (filename); }
static void setup_data() { int rc; char* unique_filename = NULL; const char *filename = "../schemes/ml.vst"; if (!file_exist (filename)) { ck_abort_msg ("../schemes/ml.vst is not available"); } reinitialize_varnam_instance (filename); unique_filename = get_unique_filename (); rc = varnam_config (varnam_instance, VARNAM_CONFIG_ENABLE_SUGGESTIONS, unique_filename); assert_success (rc); rc = varnam_learn (varnam_instance, word1); assert_success (rc); rc = varnam_learn (varnam_instance, word2); assert_success (rc); rc = varnam_learn (varnam_instance, word3); assert_success (rc); free (unique_filename); }
static void discovery_with_services_succeeds() { struct await_discovery_args args; struct cpn_discovery_results results; struct cpn_thread t; args.channel = &remote; args.identity = &remote_keys.pk; args.name = "test"; args.nservices = 1; args.services = &service; assert_success(cpn_spawn(&t, await_discovery, &args)); assert_success(cpn_client_discovery_probe(&local, NULL)); assert_success(cpn_client_discovery_handle_announce(&results, &local)); assert_success(cpn_join(&t, NULL)); assert_success(args.result); assert_string_equal(results.name, args.name); assert_int_equal(results.version, CPN_PROTOCOL_VERSION); assert_memory_equal(&results.identity, &remote_keys.pk, sizeof(struct cpn_sign_pk)); assert_int_equal(results.nservices, args.nservices); assert_string_equal(results.services[0].category, service.plugin->category); assert_string_equal(results.services[0].name, service.name); assert_int_equal(results.services[0].port, service.port); cpn_discovery_results_clear(&results); }
void parse_ply(const std::string& filename, PLYParser* parser) { p_ply ply = ply_open(filename.c_str(), NULL, 0, NULL); assert_success(ply != NULL); assert_success(ply_read_header(ply)); const char* elem_name; const char* prop_name; long num_elements; p_ply_element element = ply_get_next_element(ply, NULL); while (element != NULL) { assert_success(ply_get_element_info(element, &elem_name, &num_elements)); p_ply_property property = ply_get_next_property(element, NULL); while (property != NULL) { assert_success(ply_get_property_info(property, &prop_name, NULL, NULL, NULL)); ply_set_read_cb(ply, elem_name, prop_name, ply_parser_call_back, parser, 0); parser->add_property(elem_name, prop_name, num_elements); property = ply_get_next_property(element, property); } element = ply_get_next_element(ply, element); } assert_success(ply_read(ply)); ply_close(ply); }
static void symmetric_key_from_bin_succeeds() { struct cpn_symmetric_key bin; assert_success(cpn_symmetric_key_from_hex(&bin, SYMMETRIC_KEY)); assert_success(cpn_symmetric_key_from_bin(&key, bin.data, sizeof(bin.data))); assert_memory_equal(&bin, &key, sizeof(bin)); }
SETUP_ONCE() { static const function_t function_a = { "a", "adescr", {1,1}, &dummy }; static const function_t function_b = { "b", "bdescr", {2,2}, &dummy }; static const function_t function_c = { "c", "cdescr", {0,0}, &dummy }; static const function_t function_d = { "d", "ddescr", {1,3}, &dummy }; assert_success(function_register(&function_a)); assert_success(function_register(&function_b)); assert_success(function_register(&function_c)); assert_success(function_register(&function_d)); }
void view_setup(FileView *view) { view->list_rows = 0; view->dir_entry = NULL; assert_success(filter_init(&view->local_filter.filter, 1)); assert_success(filter_init(&view->manual_filter, 1)); assert_success(filter_init(&view->auto_filter, 1)); view->sort[0] = SK_NONE; ui_view_sort_list_ensure_well_formed(view, view->sort); }
void view_setup(view_t *view) { char *error; view->list_rows = 0; view->dir_entry = NULL; assert_success(filter_init(&view->local_filter.filter, 1)); assert_non_null(view->manual_filter = matcher_alloc("", 0, 0, "", &error)); assert_success(filter_init(&view->auto_filter, 1)); view->sort[0] = SK_NONE; ui_view_sort_list_ensure_well_formed(view, view->sort); }
static void whitelisted_query_succeeds() { struct await_query_args args = { &remote, &service, 0 }; struct cpn_thread t; struct cpn_query_results results; cpn_spawn(&t, await_query, &args); assert_success(cpn_client_query_service(&results, &local)); cpn_join(&t, NULL); assert_success(args.result); cpn_query_results_free(&results); }
TEST(cloning_of_broken_symlink, IF(not_windows)) { /* symlink() is not available on Windows, but the rest of the code is fine. */ #ifndef _WIN32 assert_success(symlink("no-such-file", SANDBOX_PATH "/broken-link")); #endif flist_load_tree(&lwin, SANDBOX_PATH); /* Without specifying new name. */ lwin.dir_entry[0].marked = 1; (void)fops_clone(&lwin, NULL, 0, 0, 1); assert_success(unlink(SANDBOX_PATH "/broken-link(1)")); assert_success(unlink(SANDBOX_PATH "/broken-link")); }
SETUP() { saved_cwd = save_cwd(); assert_success(chdir(SANDBOX_PATH)); /* lwin */ strcpy(lwin.curr_dir, "."); view_setup(&lwin); lwin.list_rows = 1; lwin.list_pos = 0; lwin.dir_entry = dynarray_cextend(NULL, lwin.list_rows*sizeof(*lwin.dir_entry)); lwin.dir_entry[0].name = strdup("file"); lwin.dir_entry[0].origin = &lwin.curr_dir[0]; /* rwin */ strcpy(rwin.curr_dir, "."); view_setup(&rwin); rwin.filtered = 0; rwin.list_pos = 0; curr_view = &lwin; other_view = &rwin; }
SETUP() { conf_setup(); init_modes(); init_commands(); curr_view = &lwin; other_view = &rwin; view_setup(&lwin); curr_stats.load_stage = -1; curr_stats.save_msg = 0; saved_cwd = save_cwd(); assert_success(chdir(sandbox)); update_string(&cfg.shell, "/bin/sh"); update_string(&cfg.shell_cmd_flag, "-c"); stats_update_shell_type(cfg.shell); curr_stats.exec_env_type = EET_EMULATOR; update_string(&cfg.media_prg, "./script"); create_executable("script"); }
END_TEST START_TEST (initialize_using_lang_code) { int rc; char *errMsg = NULL; varnam *handle; strbuf *tmp; rc = varnam_init_from_id ("ml", &handle, &errMsg); if (errMsg != NULL) { printf ("init_from_lang failed: %s\n", errMsg); } assert_success (rc); tmp = strbuf_init (20); strbuf_addf (tmp, "%s/ml.vst", strbuf_to_s (varnam_get_symbols_dir())); ck_assert_str_eq (strbuf_to_s(tmp), varnam_get_scheme_file (handle)); strbuf_destroy (tmp); tmp = strbuf_init (10); strbuf_addf (tmp, "%s/.local/share/varnam/suggestions/ml.vst.learnings", getenv ("HOME")); ck_assert_str_eq (strbuf_to_s (tmp), varnam_get_suggestions_file (handle)); strbuf_destroy (tmp); varnam_destroy (handle); }
void create_empty_file(const char path[]) { FILE *const f = fopen(path, "w"); fclose(f); assert_success(access(path, F_OK)); }
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 mode_t get_perms(const char path[]) { struct stat st; assert_success(stat(path, &st)); return (st.st_mode & 0777); }
TEST(dquoted_completion_escaping, IF(dquotes_allowed_in_paths)) { assert_int_equal(0, chdir("../quotes-in-names")); prepare_for_line_completion(L"touch \"d-quote"); assert_success(line_completion(&stats)); assert_wstring_equal(L"touch \"d-quote-\\\"-in-name", stats.line); }
TEST(rename_to_broken_symlink_name, IF(not_windows)) { /* symlink() is not available on Windows, but the rest of the code is fine. */ #ifndef _WIN32 assert_success(symlink("no-such-file", SANDBOX_PATH "/broken-link")); #endif create_empty_file(SANDBOX_PATH "/a-file"); populate_dir_list(&lwin, 0); lwin.list_pos = 0; fops_init(&broken_link_name, NULL); fops_rename_current(&lwin, 0); assert_success(unlink(SANDBOX_PATH "/a-file")); assert_success(unlink(SANDBOX_PATH "/broken-link")); }
END_TEST START_TEST (basic_learning) { int rc; varray *words; const char *word_to_learn = "കഖ"; rc = varnam_learn (varnam_instance, word_to_learn); assert_success (rc); /* Here gha is a possibility. But since it is learned, it will be suggested back */ rc = varnam_transliterate (varnam_instance, "kagha", &words); assert_success (rc); ck_assert_int_eq (varray_length (words), 2); ensure_word_list_contains (words, word_to_learn); }
/* Windows has various limitations on characters used in file names. */ TEST(tilde_is_expanded_after_negation, IF(not_windows)) { char path[PATH_MAX]; snprintf(path, sizeof(path), "%s/~", sandbox); assert_success(exec_commands("let $a = 'x'", &lwin, CIT_COMMAND)); assert_success(os_mkdir(path, 0700)); assert_success(exec_commands("auto DirEnter !~ let $a = 1", &lwin, CIT_COMMAND)); assert_string_equal("x", env_get("a")); assert_true(change_directory(curr_view, path) >= 0); assert_string_equal("1", env_get("a")); assert_success(rmdir(path)); }
void view_setup(FileView *view) { view->list_rows = 0; view->filtered = 0; view->list_pos = 0; view->dir_entry = NULL; assert_success(filter_init(&view->local_filter.filter, 1)); assert_success(filter_init(&view->manual_filter, 1)); assert_success(filter_init(&view->auto_filter, 1)); strcpy(view->curr_dir, "/path"); update_string(&view->custom.orig_dir, NULL); view->sort[0] = SK_BY_NAME; memset(&view->sort[1], SK_NONE, sizeof(view->sort) - 1); }
END_TEST START_TEST (enable_suggestions) { int rc; char *msg, *filename; varnam *handle; filename = get_unique_filename(); rc = varnam_init(filename, &handle, &msg); assert_success (rc); rc = varnam_config (handle, VARNAM_CONFIG_ENABLE_SUGGESTIONS, "output/00-suggestions"); assert_success (rc); varnam_destroy (handle); free (filename); }
TEST(pattern_anding_and_orring, IF(has_mime_type_detection)) { char cmd[1024]; assoc_records_t ft; ft_init(&prog_exists); snprintf(cmd, sizeof(cmd), "filetype {two-lines}<text/plain>,<%s>{binary-data} app", get_mimetype(TEST_DATA_PATH "/read/binary-data")); assert_success(exec_commands(cmd, &lwin, CIT_COMMAND)); snprintf(cmd, sizeof(cmd), "fileviewer {two-lines}<text/plain>,<%s>{binary-data} viewer", get_mimetype(TEST_DATA_PATH "/read/binary-data")); assert_success(exec_commands(cmd, &lwin, CIT_COMMAND)); ft = ft_get_all_programs(TEST_DATA_PATH "/read/two-lines"); assert_int_equal(1, ft.count); if(ft.count == 1) { assert_string_equal("app", ft.list[0].command); } ft_assoc_records_free(&ft); ft = ft_get_all_programs(TEST_DATA_PATH "/read/binary-data"); assert_int_equal(1, ft.count); if(ft.count == 1) { assert_string_equal("app", ft.list[0].command); } ft_assoc_records_free(&ft); ft = ft_get_all_programs(TEST_DATA_PATH "/read/utf8-bom"); assert_int_equal(0, ft.count); ft_assoc_records_free(&ft); assert_string_equal("viewer", ft_get_viewer(TEST_DATA_PATH "/read/two-lines")); assert_string_equal("viewer", ft_get_viewer(TEST_DATA_PATH "/read/binary-data")); assert_string_equal(NULL, ft_get_viewer(TEST_DATA_PATH "/read/utf8-bom")); ft_reset(0); }