static wi_runtime_instance_t * _wi_plist_instance_for_node(xmlNodePtr node) { wi_string_t *name; name = wi_xml_node_name(node); if(wi_is_equal(name, WI_STR("dict"))) return wi_dictionary(); else if(wi_is_equal(name, WI_STR("array"))) return wi_array(); wi_error_set_libwired_error_with_format(WI_ERROR_PLIST_READFAILED, WI_STR("Content \"%@\" is not \"dict\" or \"array\""), name); return NULL; }
void wi_test_runtime_invalid(void) { WI_TEST_ASSERT_NULL(wi_runtime_class_with_name(WI_STR("foo")), ""); WI_TEST_ASSERT_NULL(wi_runtime_class_with_id(1337), ""); WI_TEST_ASSERT_EQUALS(wi_runtime_id_for_class(NULL), WI_RUNTIME_ID_NULL, ""); WI_TEST_ASSERT_NULL(wi_runtime_class("foo"), ""); WI_TEST_ASSERT_NULL(wi_runtime_class_name("foo"), ""); WI_TEST_ASSERT_EQUALS(wi_runtime_id("foo"), WI_RUNTIME_ID_NULL, ""); WI_TEST_ASSERT_NULL(wi_retain(NULL), ""); WI_TEST_ASSERT_EQUALS(wi_retain_count(NULL), 0U, ""); WI_TEST_ASSERT_NULL(wi_copy(NULL), ""); WI_TEST_ASSERT_NULL(wi_mutable_copy(NULL), ""); WI_TEST_ASSERT_TRUE(wi_is_equal(NULL, NULL), ""); WI_TEST_ASSERT_FALSE(wi_is_equal(NULL, "foo"), ""); WI_TEST_ASSERT_FALSE(wi_is_equal(wi_array(), wi_dictionary()), ""); WI_TEST_ASSERT_NULL(wi_description(NULL), ""); WI_TEST_ASSERT_EQUALS(wi_hash(NULL), 0U, ""); }
void wi_parse_wired_command(wi_string_t *buffer, wi_string_t **out_command, wi_array_t **out_arguments) { wi_string_t *string, *substring; wi_uinteger_t index; index = wi_string_index_of_string(buffer, WI_STR(_WI_WIRED_MESSAGE_SEPARATOR), WI_STRING_BACKWARDS); if(index != WI_NOT_FOUND) string = wi_string_by_deleting_characters_from_index(buffer, index); else string = wi_autorelease(wi_copy(buffer)); index = wi_string_index_of_string(string, WI_STR(" "), 0); if(index != WI_NOT_FOUND) { *out_command = wi_string_substring_to_index(string, index); substring = wi_string_substring_from_index(string, index + 1); *out_arguments = wi_string_components_separated_by_string(substring, WI_STR(_WI_WIRED_FIELD_SEPARATOR)); } else { *out_command = string; *out_arguments = wi_array(); } }
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, ""); }