void wi_test_dsa_creation(void) { #ifdef WI_DSA wi_dsa_t *dsa; dsa = wi_autorelease(wi_dsa_init_with_bits(wi_dsa_alloc(), 512)); WI_TEST_ASSERT_NOT_NULL(dsa, ""); WI_TEST_ASSERT_EQUALS(wi_dsa_bits(dsa), 384U, ""); dsa = wi_autorelease(wi_dsa_init_with_pem_file(wi_dsa_alloc(), WI_STR("/non/existing/file.pem"))); WI_TEST_ASSERT_NULL(dsa, ""); dsa = wi_autorelease(wi_dsa_init_with_pem_file(wi_dsa_alloc(), wi_string_by_appending_path_component(wi_test_fixture_path, WI_STR("wi-dsa-tests-1.pem")))); WI_TEST_ASSERT_NULL(dsa, ""); dsa = wi_autorelease(wi_dsa_init_with_pem_file(wi_dsa_alloc(), wi_string_by_appending_path_component(wi_test_fixture_path, WI_STR("wi-dsa-tests-2.pem")))); WI_TEST_ASSERT_NOT_NULL(dsa, ""); WI_TEST_ASSERT_EQUALS(wi_dsa_bits(dsa), 384U, ""); dsa = wi_autorelease(wi_dsa_init_with_private_key(wi_dsa_alloc(), wi_data())); WI_TEST_ASSERT_NULL(dsa, ""); dsa = wi_autorelease(wi_dsa_init_with_private_key(wi_dsa_alloc(), wi_data_with_base64_string(WI_STR("MIH3AgEAAkEA0c36Uaj1S/cKjYAokEUtWQHmFHLqd8mbnY9J9wyNS0mlXvklnko2NlflL1qg9p58uRjkGBtCinI0mxeEIxwckwIVAPpF85s7Iv1o7z4UUAs9KRamjULXAkBFchKBXr+D+lGgnBFtb//EBThgSD9t3WBxyKGvNLBDWGJu2+av/fR9uBxBm1cUUldzGvqBjr/lcBmTIUe4rmAcAkBBN2fEFvs6uuIX+/8EqM1T2yBmwt3KHMVuCD+opZga29WJPNZgNXIj8yNFGFIxJeTndvhcndNrlcztYx3e/GSCAhRDUGb+CUPkNuBbsSHbdYtEQ+/2Gg==")))); WI_TEST_ASSERT_NOT_NULL(dsa, ""); WI_TEST_ASSERT_EQUALS(wi_dsa_bits(dsa), 384U, ""); dsa = wi_autorelease(wi_dsa_init_with_public_key(wi_dsa_alloc(), wi_data())); WI_TEST_ASSERT_NULL(dsa, ""); #endif }
void wi_test_set_instances(void) { wi_set_t *set; wi_array_t *array; set = wi_set_with_data(WI_STR("foo"), WI_STR("bar"), NULL); WI_TEST_ASSERT_NOT_NULL(set, ""); WI_TEST_ASSERT_EQUALS(wi_set_count(set), 2U, ""); WI_TEST_ASSERT_TRUE(wi_set_contains_data(set, WI_STR("foo")), ""); WI_TEST_ASSERT_TRUE(wi_set_contains_data(set, WI_STR("bar")), ""); array = wi_set_all_data(set); WI_TEST_ASSERT_EQUALS(wi_array_count(array), 2U, ""); WI_TEST_ASSERT_TRUE(wi_array_contains_data(array, WI_STR("foo")), ""); WI_TEST_ASSERT_TRUE(wi_array_contains_data(array, WI_STR("bar")), ""); }
void wi_test_fsevents(void) { #ifdef WI_PTHREADS wi_string_t *directory; wi_test_fsevents_fsevents = wi_fsevents_init(wi_fsevents_alloc()); if(!wi_test_fsevents_fsevents) { if(wi_error_domain() != WI_ERROR_DOMAIN_LIBWIRED && wi_error_code() != WI_ERROR_FSEVENTS_NOTSUPP) WI_TEST_ASSERT_NOT_NULL(wi_test_fsevents_fsevents, "%m"); return; } directory = wi_fs_temporary_path_with_template(WI_STR("/tmp/libwired-fsevents.XXXXXXXX")); wi_fs_create_directory(directory, 0700); wi_fsevents_add_path(wi_test_fsevents_fsevents, directory); wi_fsevents_set_callback(wi_test_fsevents_fsevents, wi_test_fsevents_callback); wi_test_fsevents_lock = wi_condition_lock_init_with_condition(wi_condition_lock_alloc(), 0); if(!wi_thread_create_thread(wi_test_fsevents_thread, NULL)) WI_TEST_FAIL("%m"); wi_thread_sleep(0.1); wi_string_write_to_file(WI_STR("foo"), wi_string_by_appending_path_component(directory, WI_STR("file"))); wi_condition_lock_lock_when_condition(wi_test_fsevents_lock, 1, 0.0); if(!wi_test_fsevents_path) WI_TEST_FAIL("No fsevents callback received"); else WI_TEST_ASSERT_EQUAL_INSTANCES(wi_test_fsevents_path, directory, ""); wi_condition_lock_unlock(wi_test_fsevents_lock); wi_fs_delete_path(directory); wi_release(wi_test_fsevents_lock); wi_release(wi_test_fsevents_fsevents); wi_release(wi_test_fsevents_path); #endif }
void wi_test_indexset_indexes(void) { wi_indexset_t *indexset; indexset = wi_indexset_with_indexes_in_range(wi_make_range(1, 3)); WI_TEST_ASSERT_NOT_NULL(indexset, ""); WI_TEST_ASSERT_EQUALS(wi_indexset_count(indexset), 3U, ""); WI_TEST_ASSERT_TRUE(wi_indexset_contains_index(indexset, 1), ""); WI_TEST_ASSERT_TRUE(wi_indexset_contains_index(indexset, 2), ""); WI_TEST_ASSERT_TRUE(wi_indexset_contains_index(indexset, 3), ""); WI_TEST_ASSERT_FALSE(wi_indexset_contains_index(indexset, 4), ""); WI_TEST_ASSERT_TRUE(wi_indexset_contains_indexes(indexset, wi_indexset_with_index(1)), ""); WI_TEST_ASSERT_FALSE(wi_indexset_contains_indexes(indexset, wi_indexset_with_index(4)), ""); WI_TEST_ASSERT_TRUE(wi_indexset_contains_indexes_in_range(indexset, wi_make_range(2, 1)), ""); WI_TEST_ASSERT_FALSE(wi_indexset_contains_indexes_in_range(indexset, wi_make_range(4, 1)), ""); WI_TEST_ASSERT_EQUALS(wi_indexset_first_index(indexset), 1U, ""); WI_TEST_ASSERT_EQUALS(wi_indexset_last_index(indexset), 3U, ""); }
void wi_test_string_encoding_conversion(void) { #ifdef WI_STRING_ENCODING wi_string_t *string, *path; wi_data_t *data; wi_string_encoding_t *encoding; encoding = wi_string_encoding_with_charset(WI_STR("ISO-8859-1"), 0); string = wi_string_with_c_string("hello world", encoding); WI_TEST_ASSERT_EQUAL_INSTANCES(string, WI_STR("hello world"), ""); data = wi_data_with_base64_string(WI_STR("aGVsbG8gd29ybGQ=")); string = wi_string_with_data(data, encoding); WI_TEST_ASSERT_EQUAL_INSTANCES(string, WI_STR("hello world"), ""); string = wi_string_with_bytes(wi_data_bytes(data), wi_data_length(data), encoding); WI_TEST_ASSERT_EQUAL_INSTANCES(string, WI_STR("hello world"), ""); path = wi_string_by_appending_path_component(wi_test_fixture_path, WI_STR("wi-string-encoding-tests-1.txt")); string = wi_string_with_contents_of_file(path, encoding); WI_TEST_ASSERT_NOT_NULL(string, ""); WI_TEST_ASSERT_EQUALS(wi_string_character_at_index(string, 0), 'h', ""); WI_TEST_ASSERT_EQUALS(wi_string_length(string), 14, ""); data = wi_string_data(WI_STR("hello world"), encoding); WI_TEST_ASSERT_EQUAL_INSTANCES(data, wi_data_with_base64_string(WI_STR("aGVsbG8gd29ybGQ=")), ""); encoding = wi_string_encoding_with_charset(WI_STR("ASCII"), 0); string = wi_string_with_contents_of_file(path, encoding); WI_TEST_ASSERT_NULL(string, ""); encoding = wi_string_encoding_with_charset(WI_STR("hello world"), 0); string = wi_string_with_contents_of_file(path, encoding); WI_TEST_ASSERT_NULL(string, ""); #endif }
void wi_test_set_scalars(void) { wi_mutable_set_t *set; wi_array_t *array; set = wi_set_init_with_capacity_and_callbacks(wi_mutable_set_alloc(), 0, false, wi_set_null_callbacks); wi_mutable_set_add_data(set, "foo"); wi_mutable_set_add_data(set, "bar"); WI_TEST_ASSERT_NOT_NULL(set, ""); WI_TEST_ASSERT_EQUALS(wi_set_count(set), 2U, ""); WI_TEST_ASSERT_TRUE(wi_set_contains_data(set, "foo"), ""); WI_TEST_ASSERT_TRUE(wi_set_contains_data(set, "bar"), ""); array = wi_set_all_data(set); WI_TEST_ASSERT_EQUALS(wi_array_count(array), 2U, ""); WI_TEST_ASSERT_TRUE(wi_array_contains_data(array, "foo"), ""); WI_TEST_ASSERT_TRUE(wi_array_contains_data(array, "bar"), ""); }
void wi_test_plist(void) { #ifdef WI_PLIST wi_string_t *string1, *string2; wi_dictionary_t *dictionary1, *dictionary2; string1 = wi_autorelease(wi_string_init_with_contents_of_file(wi_string_alloc(), wi_string_by_appending_path_component(wi_test_fixture_path, WI_STR("wi-plist-tests-1.plist")))); dictionary1 = wi_plist_instance_for_string(string1); WI_TEST_ASSERT_NOT_NULL(dictionary1, "%m"); dictionary2 = wi_dictionary_with_data_and_keys( WI_STR("hello world"), WI_STR("string"), wi_number_with_bool(true), WI_STR("true"), wi_number_with_bool(false), WI_STR("false"), wi_number_with_integer(42), WI_STR("integer"), wi_number_with_double(3.14), WI_STR("real"), wi_date_with_rfc3339_string(WI_STR("2008-06-01T17:28:00Z")), WI_STR("date"), wi_data_with_base64(wi_string_base64(WI_STR("hello world"))), WI_STR("data"), wi_dictionary_with_data_and_keys(WI_STR("value1"), WI_STR("key1"), WI_STR("value2"), WI_STR("key2"), NULL), WI_STR("dict"), wi_array_with_data(WI_STR("value1"), WI_STR("value2"), NULL), WI_STR("array"), NULL); WI_TEST_ASSERT_EQUAL_INSTANCES(dictionary1, dictionary2, ""); string2 = wi_plist_string_for_instance(dictionary2); WI_TEST_ASSERT_EQUAL_INSTANCES(string1, string2, ""); #endif }
void wi_test_filesystem_successes(void) { wi_array_t *contents; wi_string_t *path, *otherpath; wi_file_stats_t file_stats; wi_filesystem_stats_t filesystem_stats; wi_boolean_t result, is_directory; path = wi_filesystem_temporary_path_with_template(WI_STR("/tmp/libwired-test-filesystem.XXXXXXX")); WI_TEST_ASSERT_NOT_NULL(path, ""); result = wi_filesystem_create_directory_at_path(path); WI_TEST_ASSERT_TRUE(result, ""); result = wi_filesystem_file_exists_at_path(path, &is_directory); WI_TEST_ASSERT_TRUE(result, ""); WI_TEST_ASSERT_TRUE(is_directory, ""); result = wi_filesystem_change_current_directory_to_path(path); WI_TEST_ASSERT_TRUE(result, ""); otherpath = wi_filesystem_current_directory_path(); WI_TEST_ASSERT_NOT_NULL(otherpath, ""); WI_TEST_ASSERT_EQUAL_INSTANCES(otherpath, wi_string_by_resolving_symbolic_links_in_path(path), ""); contents = wi_filesystem_directory_contents_at_path(path); WI_TEST_ASSERT_EQUAL_INSTANCES(contents, wi_array(), ""); result = wi_filesystem_create_directory_at_path(WI_STR("foobar")); WI_TEST_ASSERT_TRUE(result, ""); contents = wi_filesystem_directory_contents_at_path(path); WI_TEST_ASSERT_EQUAL_INSTANCES(contents, wi_array_with_data(WI_STR("foobar"), NULL), ""); result = wi_string_write_utf8_string_to_path(WI_STR("hello world"), WI_STR("foobar/foobar")); WI_TEST_ASSERT_TRUE(result, ""); result = wi_filesystem_get_file_stats_for_path(WI_STR("foobar/foobar"), &file_stats); WI_TEST_ASSERT_TRUE(result, ""); WI_TEST_ASSERT_TRUE(file_stats.filesystem_id > 0, ""); WI_TEST_ASSERT_TRUE(file_stats.file_id > 0, ""); WI_TEST_ASSERT_EQUALS(file_stats.file_type, WI_FILE_REGULAR, ""); WI_TEST_ASSERT_TRUE(file_stats.posix_permissions > 0, ""); WI_TEST_ASSERT_EQUALS(file_stats.reference_count, 1, ""); WI_TEST_ASSERT_EQUALS(file_stats.size, 11, ""); WI_TEST_ASSERT_NOT_NULL(file_stats.user, ""); WI_TEST_ASSERT_TRUE(wi_string_length(file_stats.user) > 0, ""); WI_TEST_ASSERT_NOT_NULL(file_stats.group, ""); WI_TEST_ASSERT_TRUE(wi_string_length(file_stats.group) > 0, ""); WI_TEST_ASSERT_NOT_NULL(file_stats.creation_date, ""); WI_TEST_ASSERT_TRUE(wi_date_time_interval(file_stats.creation_date) > 0, ""); WI_TEST_ASSERT_NOT_NULL(file_stats.modification_date, ""); WI_TEST_ASSERT_TRUE(wi_date_time_interval(file_stats.modification_date) > 0, ""); result = wi_filesystem_get_filesystem_stats_for_path(WI_STR("foobar/foobar"), &filesystem_stats); WI_TEST_ASSERT_TRUE(result, ""); WI_TEST_ASSERT_TRUE(filesystem_stats.size > 0, ""); WI_TEST_ASSERT_TRUE(filesystem_stats.free_size > 0, ""); WI_TEST_ASSERT_TRUE(filesystem_stats.free_size < filesystem_stats.size, ""); WI_TEST_ASSERT_TRUE(filesystem_stats.nodes > 0, ""); WI_TEST_ASSERT_TRUE(filesystem_stats.free_nodes > 0, ""); WI_TEST_ASSERT_TRUE(filesystem_stats.free_nodes < filesystem_stats.nodes, ""); result = wi_filesystem_create_symbolic_link_from_path(WI_STR("foobar"), WI_STR("foobar/foobaz")); WI_TEST_ASSERT_TRUE(result, ""); result = wi_filesystem_copy_path_with_callback(WI_STR("foobar"), WI_STR("foobaz"), _wi_test_filesystem_successes_copy_callback); WI_TEST_ASSERT_TRUE(result, ""); contents = wi_filesystem_directory_contents_at_path(path); WI_TEST_ASSERT_EQUAL_INSTANCES(wi_set_with_array(contents), wi_set_with_data(WI_STR("foobar"), WI_STR("foobaz"), NULL), ""); result = wi_filesystem_delete_path_with_callback(path, _wi_test_filesystem_successes_delete_callback); WI_TEST_ASSERT_TRUE(result, ""); }
static void _wi_test_filesystem_successes_delete_callback(wi_string_t *path) { WI_TEST_ASSERT_NOT_NULL(path, ""); }
static void _wi_test_filesystem_successes_copy_callback(wi_string_t *frompath, wi_string_t *topath) { WI_TEST_ASSERT_NOT_NULL(frompath, ""); WI_TEST_ASSERT_NOT_NULL(topath, ""); }