void wi_test_set_creation(void) { wi_set_t *set; set = wi_set(); WI_TEST_ASSERT_NOT_NULL(set, ""); WI_TEST_ASSERT_EQUALS(wi_set_count(set), 0U, ""); 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")), ""); set = wi_autorelease(wi_set_init_with_data(wi_set_alloc(), 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")), ""); set = wi_autorelease(wi_set_init_with_array(wi_set_alloc(), wi_array_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")), ""); }
void wi_test_set_mutation(void) { wi_mutable_set_t *set1, *set2; set1 = wi_set_init_with_capacity_and_callbacks(wi_mutable_set_alloc(), 0, true, wi_set_null_callbacks); WI_TEST_ASSERT_EQUALS(wi_set_count(set1), 0U, ""); WI_TEST_ASSERT_EQUALS(wi_set_count_for_data(set1, WI_STR("foo")), 0U, ""); WI_TEST_ASSERT_EQUALS(wi_set_count_for_data(set1, WI_STR("bar")), 0U, ""); wi_mutable_set_add_data(set1, WI_STR("foo")); wi_mutable_set_add_data(set1, WI_STR("bar")); WI_TEST_ASSERT_EQUALS(wi_set_count(set1), 2U, ""); WI_TEST_ASSERT_EQUALS(wi_set_count_for_data(set1, WI_STR("foo")), 1U, ""); WI_TEST_ASSERT_EQUALS(wi_set_count_for_data(set1, WI_STR("bar")), 1U, ""); wi_mutable_set_add_data(set1, WI_STR("foo")); wi_mutable_set_add_data(set1, WI_STR("bar")); WI_TEST_ASSERT_EQUALS(wi_set_count(set1), 2U, ""); WI_TEST_ASSERT_EQUALS(wi_set_count_for_data(set1, WI_STR("foo")), 2U, ""); WI_TEST_ASSERT_EQUALS(wi_set_count_for_data(set1, WI_STR("bar")), 2U, ""); wi_mutable_set_remove_data(set1, WI_STR("foo")); wi_mutable_set_remove_data(set1, WI_STR("bar")); WI_TEST_ASSERT_EQUALS(wi_set_count(set1), 2U, ""); WI_TEST_ASSERT_EQUALS(wi_set_count_for_data(set1, WI_STR("foo")), 1U, ""); WI_TEST_ASSERT_EQUALS(wi_set_count_for_data(set1, WI_STR("bar")), 1U, ""); wi_mutable_set_remove_data(set1, WI_STR("foo")); wi_mutable_set_remove_data(set1, WI_STR("bar")); WI_TEST_ASSERT_EQUALS(wi_set_count(set1), 0U, ""); wi_mutable_set_add_data(set1, WI_STR("foo")); wi_mutable_set_add_data(set1, WI_STR("bar")); set2 = wi_mutable_copy(set1); wi_mutable_set_add_data(set2, WI_STR("baz")); wi_mutable_set_set_set(set1, set2); WI_TEST_ASSERT_EQUAL_INSTANCES(set1, set2, ""); wi_mutable_set_remove_all_data(set1); WI_TEST_ASSERT_EQUALS(wi_set_count(set1), 0U, ""); wi_mutable_set_add_data_from_array(set1, wi_array_with_data(WI_STR("foo"), WI_STR("bar"), NULL)); WI_TEST_ASSERT_EQUALS(wi_set_count(set1), 2U, ""); WI_TEST_ASSERT_EQUALS(wi_set_count_for_data(set1, WI_STR("foo")), 1U, ""); WI_TEST_ASSERT_EQUALS(wi_set_count_for_data(set1, WI_STR("bar")), 1U, ""); }
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, ""); }