Пример #1
0
void wi_test_set_runtime_functions(void) {
    wi_set_t            *set1;
    wi_mutable_set_t    *set2;
    
    set1 = wi_set_with_data(WI_STR("foo"), WI_STR("bar"), NULL);
    set2 = wi_autorelease(wi_mutable_copy(set1));
    
    WI_TEST_ASSERT_EQUAL_INSTANCES(set1, set2, "");
    WI_TEST_ASSERT_EQUALS(wi_hash(set1), wi_hash(set2), "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_id(set1), wi_set_runtime_id(), "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_id(set2), wi_set_runtime_id(), "");
    WI_TEST_ASSERT_TRUE(wi_runtime_options(set1) & WI_RUNTIME_OPTION_IMMUTABLE, "");
    WI_TEST_ASSERT_TRUE(wi_runtime_options(set2) & WI_RUNTIME_OPTION_MUTABLE, "");
    
    wi_mutable_set_remove_data(set2, WI_STR("bar"));
    wi_mutable_set_add_data(set2, WI_STR("baz"));
    
    WI_TEST_ASSERT_NOT_EQUAL_INSTANCES(set1, set2, "");
    
    wi_mutable_set_remove_data(set2, WI_STR("baz"));
    
    WI_TEST_ASSERT_NOT_EQUAL_INSTANCES(set1, set2, "");

    set2 = wi_autorelease(wi_set_init_with_capacity_and_callbacks(wi_mutable_set_alloc(), 0, false, wi_set_null_callbacks));
    
    wi_mutable_set_add_data(set2, (void *) 1);
    wi_mutable_set_add_data(set2, (void *) 2);
    
    WI_TEST_ASSERT_NOT_EQUALS(wi_string_index_of_string(wi_description(set1), WI_STR("foo"), 0), WI_NOT_FOUND, "");
    WI_TEST_ASSERT_NOT_EQUALS(wi_string_index_of_string(wi_description(set2), WI_STR("0x1"), 0), WI_NOT_FOUND, "");
}
Пример #2
0
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, "");
}
Пример #3
0
void wi_test_set_enumeration(void) {
    wi_mutable_set_t    *set;
    wi_enumerator_t     *enumerator;
    wi_number_t         *number;
    wi_uinteger_t       i;
    
    set = wi_mutable_set();
    
    for(i = 1; i <= 1000; i++)
        wi_mutable_set_add_data(set, WI_INT32(i));
    
    enumerator = wi_set_data_enumerator(set);
    i = 0;
    
    while((number = wi_enumerator_next_data(enumerator))) {
        WI_TEST_ASSERT_TRUE(wi_number_int32(number) >= 1, "");
        WI_TEST_ASSERT_TRUE(wi_number_int32(number) <= 1000, "");
        
        i++;
    }
    
    WI_TEST_ASSERT_EQUALS(i, 1000, "");
    
    for(i = 1; i <= 1000; i++)
        wi_mutable_set_remove_data(set, WI_INT32(i));
}
Пример #4
0
void wd_user_unsubscribe_paths(wd_user_t *user) {
	wi_enumerator_t		*enumerator;
	wi_string_t			*path;
	
	wi_recursive_lock_lock(user->user_lock);

	enumerator = wi_array_data_enumerator(wi_set_all_data(user->subscribed_paths));
		
	while((path = wi_enumerator_next_data(enumerator))) {
		wi_retain(path);

		while(wi_set_contains_data(user->subscribed_paths, path)) {
			if(wd_files_fsevents)
				wi_fsevents_remove_path(wd_files_fsevents, path);

			wi_mutable_set_remove_data(user->subscribed_paths, path);
		}
			
		wi_release(path);
	}
	
	wi_mutable_dictionary_remove_all_data(user->subscribed_virtualpaths);
		
	wi_recursive_lock_unlock(user->user_lock);
}
Пример #5
0
void wd_user_unsubscribe_path(wd_user_t *user, wi_string_t *realpath) {
	wi_string_t		*metapath;
	
	wi_recursive_lock_lock(user->user_lock);
		
	wi_mutable_set_remove_data(user->subscribed_paths, realpath);

	if(wd_files_fsevents)
		wi_fsevents_remove_path(wd_files_fsevents, realpath);
		
	metapath = wi_string_by_appending_path_component(realpath, WI_STR(WD_FILES_META_PATH));
		
	wi_mutable_set_add_data(user->subscribed_paths, metapath);

	if(wd_files_fsevents)
		wi_fsevents_add_path(wd_files_fsevents, metapath);

	wi_mutable_dictionary_remove_data_for_key(user->subscribed_virtualpaths, realpath);
	
	wi_recursive_lock_unlock(user->user_lock);
}
Пример #6
0
wi_boolean_t wi_config_write_file(wi_config_t *config) {
	wi_enumerator_t		*enumerator;
	wi_file_t			*file, *tmpfile;
	wi_string_t			*string, *name, *value;
	wi_mutable_set_t	*keys;
	wi_boolean_t		write;
	
	file = wi_file_for_updating(config->path);
	
	if(!file) {
		wi_log_err(WI_STR("Could not open %@: %m"),
			config->path);
		
		return false;
	}
	
	tmpfile = wi_file_temporary_file();
	
	wi_lock_lock(config->lock);
	
	keys = wi_autorelease(wi_mutable_copy(config->changes));

	while((string = wi_file_read_line(file))) {
		if(wi_string_length(string) == 0) {
			wi_file_write_format(tmpfile, WI_STR("\n"));
		}
		else if(wi_string_has_prefix(string, WI_STR("#"))) {
			write = true;
			string = wi_string_substring_from_index(string, 1);
			
			if(_wi_config_parse_string(config, string, &name, &value)) {
				if(wi_set_contains_data(keys, name)) {
					if(_wi_config_write_setting_to_file(config, name, tmpfile)) {
						write = false;
						
						wi_mutable_set_remove_data(keys, name);
					}
				}
			}
			
			if(write)
				wi_file_write_format(tmpfile, WI_STR("#%@\n"), string);
		}
		else {
			write = true;
			
			if(_wi_config_parse_string(config, string, &name, &value)) {
				if(wi_set_contains_data(keys, name)) {
					if(_wi_config_write_setting_to_file(config, name, tmpfile)) {
						write = false;
						
						wi_mutable_set_remove_data(keys, name);
					}
				}
			}

			if(write)
				wi_file_write_format(tmpfile, WI_STR("%@\n"), string);
		}
	}
	
	enumerator = wi_set_data_enumerator(keys);
	
	while((name = wi_enumerator_next_data(enumerator)))
		_wi_config_write_setting_to_file(config, name, tmpfile);
	
	wi_mutable_set_remove_all_data(config->changes);

	wi_lock_unlock(config->lock);
	
	wi_file_truncate(file, 0);
	wi_file_seek(tmpfile, 0);
	
	while((string = wi_file_read_line(tmpfile)))
		wi_file_write_format(file, WI_STR("%@\n"), string);

	return true;
}