void wi_test_directory_enumerator(void) {
    wi_directory_enumerator_t           *enumerator;
    wi_mutable_array_t                  *contents;
    wi_string_t                         *path, *subpath;
    wi_boolean_t                        result;
    wi_directory_enumerator_status_t    status;
    
    path = wi_filesystem_temporary_path_with_template(WI_STR("/tmp/libwired-test-directory-enumerator.XXXXXXX"));
    path = wi_string_by_resolving_symbolic_links_in_path(path);
    result = wi_filesystem_create_directory_at_path(path);
    
    WI_TEST_ASSERT_TRUE(result, "");
    
    enumerator = wi_filesystem_directory_enumerator_at_path(path);
    
    WI_TEST_ASSERT_NOT_NULL(enumerator, "");
    
    contents = wi_mutable_array();
    
    while((status = wi_directory_enumerator_get_next_path(enumerator, &subpath)) == WI_DIRECTORY_ENUMERATOR_PATH)
        wi_mutable_array_add_data(contents, subpath);
    
    WI_TEST_ASSERT_EQUALS(status, WI_DIRECTORY_ENUMERATOR_EOF, "");
    WI_TEST_ASSERT_EQUALS(wi_array_count(contents), 0U, "");
    
    result = wi_filesystem_change_current_directory_to_path(path);
    
    WI_TEST_ASSERT_TRUE(result, "");

    result = wi_filesystem_create_directory_at_path(WI_STR("foo"));
    
    WI_TEST_ASSERT_TRUE(result, "");
    
    result = wi_filesystem_create_directory_at_path(WI_STR("foo/bar"));
    
    WI_TEST_ASSERT_TRUE(result, "");
    
    result = wi_filesystem_create_directory_at_path(WI_STR("foo/bar/baz"));
    
    WI_TEST_ASSERT_TRUE(result, "");
    
    enumerator = wi_filesystem_directory_enumerator_at_path(path);
    
    WI_TEST_ASSERT_NOT_NULL(enumerator, "");
    
    while((status = wi_directory_enumerator_get_next_path(enumerator, &subpath)) == WI_DIRECTORY_ENUMERATOR_PATH)
        wi_mutable_array_add_data(contents, subpath);
    
    WI_TEST_ASSERT_EQUALS(status, WI_DIRECTORY_ENUMERATOR_EOF, "");
    WI_TEST_ASSERT_EQUALS(wi_array_count(contents), 3U, "");
    WI_TEST_ASSERT_EQUAL_INSTANCES(wi_array_data_at_index(contents, 0), wi_string_by_appending_path_component(path, WI_STR("foo")), "");
    WI_TEST_ASSERT_EQUAL_INSTANCES(wi_array_data_at_index(contents, 1), wi_string_by_appending_path_component(path, WI_STR("foo/bar")), "");
    WI_TEST_ASSERT_EQUAL_INSTANCES(wi_array_data_at_index(contents, 2), wi_string_by_appending_path_component(path, WI_STR("foo/bar/baz")), "");
    
    wi_filesystem_delete_path(path);
}
예제 #2
0
static void wr_command_mv(wi_array_t *arguments) {
    
    wi_p7_message_t     *message;
    wi_string_t         *path, *new_path;
    
    path        = wi_array_data_at_index(arguments, 0);
    new_path    = wi_array_data_at_index(arguments, 1);
    
    message     = wi_p7_message_with_name(WI_STR("wired.file.move"), wr_p7_spec);
    wi_p7_message_set_string_for_name(message, path, WI_STR("wired.file.path"));
    wi_p7_message_set_string_for_name(message, new_path, WI_STR("wired.file.new_path"));
    wr_commands_send_message(message, WI_STR("mv"));
}
예제 #3
0
void wi_array_add_data_from_array(wi_array_t *array, wi_array_t *otherarray) {
	wi_uinteger_t	i, count;
	
	count = wi_array_count(otherarray);
	
	for(i = 0; i < count; i++)
		wi_array_add_data(array, wi_array_data_at_index(otherarray, i));
}
예제 #4
0
static void wr_command_unsubscribe(wi_array_t *arguments) {
    wi_p7_message_t     *message;
    wi_string_t         *path;
    
    message = wi_p7_message_with_name(WI_STR("wired.file.unsubscribe_directory"), wr_p7_spec);
    path    = wi_array_data_at_index(arguments, 0);
    
    wi_p7_message_set_string_for_name(message, path, WI_STR("wired.file.path"));
    wr_commands_send_message(message, WI_STR("unsubscribe"));
}
예제 #5
0
static void wr_command_ls(wi_array_t *arguments) {
    wi_p7_message_t     *message;
    wi_string_t         *path;
            
    message = wi_p7_message_with_name(WI_STR("wired.file.list_directory"), wr_p7_spec);
    path    = (wi_array_count(arguments) > 0) ? wi_array_data_at_index(arguments, 0) : WI_STR("/");
    
    wi_p7_message_set_string_for_name(message, path, WI_STR("wired.file.path"));
    wr_commands_send_message(message, WI_STR("ls"));
}
예제 #6
0
파일: wi-list.c 프로젝트: ProfDrLuigi/zanka
wi_list_t * wi_list_init_with_array(wi_list_t *list, wi_array_t *array) {
	uint32_t		i, count;
	
	list = wi_list_init(list);
	count = wi_array_count(array);
	
	for(i = 0; i < count; i++)
		wi_list_append_data(list, wi_array_data_at_index(array, i));
	
	return list;
}
예제 #7
0
void * wi_enumerator_array_reverse_data_enumerator(wi_runtime_instance_t *instance, wi_enumerator_context_t *context) {
	wi_array_t		*array = instance;
	void			*data;
	
	if(context->index == array->data_count)
		return NULL;
	
	data = wi_array_data_at_index(array, array->data_count - context->index - 1);
	
	context->index++;
	
	return data;
}
예제 #8
0
void * wi_enumerator_array_reverse_data_enumerator(wi_runtime_instance_t *instance, void *context) {
	wi_array_t		*array = instance;
	wi_uinteger_t	*index = context;
	void			*data;
	
	if(*index == array->data_count)
		return NULL;
	
	data = wi_array_data_at_index(array, array->data_count - *index - 1);
	
	(*index)++;
	
	return data;
}
예제 #9
0
void * wi_enumerator_array_data_enumerator(wi_runtime_instance_t *instance, void *context) {
	wi_array_t		*array = instance;
	uint32_t		*index = context;
	void			*data;
	
	if(*index == array->data_count)
		return NULL;
	
	data = wi_array_data_at_index(array, *index);
	
	(*index)++;
	
	return data;
}