Example #1
0
void wi_test_string_paths(void) {
	WI_TEST_ASSERT_EQUAL_INSTANCES(
		wi_string_path_components(WI_STR("/usr/local/wired")),
		wi_autorelease(wi_array_init_with_data(wi_array_alloc(),
			WI_STR("/"), WI_STR("usr"), WI_STR("local"), WI_STR("wired"), NULL)),
		"");
	
	WI_TEST_ASSERT_EQUAL_INSTANCES(
		wi_string_by_normalizing_path(WI_STR("////usr/././local/../local/../local/wired///")),
		WI_STR("/usr/local/wired"),
		"");
	
	WI_TEST_ASSERT_EQUAL_INSTANCES(
		wi_string_by_appending_path_component(WI_STR("/usr/local/"), WI_STR("/wired")),
		WI_STR("/usr/local/wired"),
		"");
	
	WI_TEST_ASSERT_EQUAL_INSTANCES(wi_string_last_path_component(WI_STR("/usr/local/wired/")), WI_STR("wired"), "");
	WI_TEST_ASSERT_EQUAL_INSTANCES(wi_string_last_path_component(WI_STR("/")), WI_STR("/"), "");
	WI_TEST_ASSERT_EQUAL_INSTANCES(wi_string_last_path_component(WI_STR("/wired/")), WI_STR("wired"), "");
	WI_TEST_ASSERT_EQUAL_INSTANCES(wi_string_by_deleting_last_path_component(WI_STR("/usr/local/wired")), WI_STR("/usr/local"), "");
	WI_TEST_ASSERT_EQUAL_INSTANCES(wi_string_path_extension(WI_STR("wired.c")), WI_STR("c"), "");
	WI_TEST_ASSERT_EQUAL_INSTANCES(wi_string_path_extension(WI_STR("wired")), WI_STR(""), "");
	WI_TEST_ASSERT_EQUAL_INSTANCES(wi_string_by_deleting_path_extension(WI_STR("wired")), WI_STR("wired"), "");
}
Example #2
0
void wi_test_regexp_replacing_by_creating(void) {
    wi_regexp_t     *regexp;
    wi_string_t     *string;
    
    regexp = wi_regexp_with_pattern(WI_STR("l"), 0);
    string = wi_regexp_string_by_replacing_matches_in_string(regexp, WI_STR("hello world"), WI_STR(""));
    
    WI_TEST_ASSERT_EQUAL_INSTANCES(string, WI_STR("heo word"), "");
    
    regexp = wi_regexp_with_pattern(WI_STR("l"), 0);
    string = wi_regexp_string_by_replacing_matches_in_string(regexp, WI_STR("hello world"), WI_STR("x"));
    
    WI_TEST_ASSERT_EQUAL_INSTANCES(string, WI_STR("hexxo worxd"), "");
    
    regexp = wi_regexp_with_pattern(WI_STR("l"), 0);
    string = wi_regexp_string_by_replacing_matches_in_string(regexp, WI_STR("hello world"), WI_STR("xxx"));
    
    WI_TEST_ASSERT_EQUAL_INSTANCES(string, WI_STR("hexxxxxxo worxxxd"), "");
    
    regexp = wi_regexp_with_pattern(WI_STR("hello (world)"), 0);
    string = wi_regexp_string_by_replacing_matches_in_string(regexp, WI_STR("hello world"), WI_STR("hi $1"));
    
    WI_TEST_ASSERT_EQUAL_INSTANCES(string, WI_STR("hi world"), "");
    
    regexp = wi_regexp_with_pattern(WI_STR("hello (world)"), 0);
    string = wi_regexp_string_by_replacing_matches_in_string(regexp, WI_STR("hello world"), WI_STR("hi $0"));
    
    WI_TEST_ASSERT_EQUAL_INSTANCES(string, WI_STR("hi hello world"), "");
}
Example #3
0
void wi_test_crypto_rsa(void) {
	wi_rsa_t		*rsa;
	
	rsa = wi_autorelease(wi_rsa_init_with_private_key(wi_rsa_alloc(), wi_data_with_base64(WI_STR("MIIBOwIBAAJBANlpi/JRzsGFCHyHARWkjg6qLnNjvgo84Shha4aOKQlQVON6LjVUTKuTGodkp7yZK0W4gfoNF/5CNbXb1Qo4xcUCAwEAAQJAafHFAJBc8HCjcgtXu/Q0RXEosZIpSVPhZIwUmb0swhw9LULNarL244HT2WJ/pSSUu3uIx+sT6mpNL+OtunQJAQIhAPSgtPWiWbHE7Bf3F4GS87PuVD2uYj9nbHuGAqfkrTaLAiEA44Tzb52/2dKz56sOW/ga/4ydsQeIQAxVBmr3uHK9zu8CIQDzQviQp5CQUeYBcurCJHMKA79r0wTKTju3niz37lQ9PwIhANdjtv5UzhpNgalxY++nSw/gtCyy38capaekvo2seoqbAiBYCzlmjq02JpohH29ijG52ecfb88uS9eUufUVoOfTC/A=="))));

	WI_TEST_ASSERT_NOT_NULL(rsa, "");
	WI_TEST_ASSERT_EQUALS(wi_rsa_bits(rsa), 512U, "");

	WI_TEST_ASSERT_EQUAL_INSTANCES(
		wi_rsa_public_key(rsa),
		wi_data_with_base64(WI_STR("MEgCQQDZaYvyUc7BhQh8hwEVpI4Oqi5zY74KPOEoYWuGjikJUFTjei41VEyrkxqHZKe8mStFuIH6DRf+QjW129UKOMXFAgMBAAE=")),
		"");
	
	WI_TEST_ASSERT_EQUAL_INSTANCES(
		wi_rsa_decrypt(rsa, wi_rsa_encrypt(rsa, wi_string_data(WI_STR("hello world")))),
		wi_string_data(WI_STR("hello world")),
		"%m");
	
	WI_TEST_ASSERT_EQUAL_INSTANCES(
		wi_rsa_decrypt(rsa, wi_rsa_encrypt(rsa, wi_string_data(WI_STR("hello world")))),
		wi_string_data(WI_STR("hello world")),
		"%m");

	rsa = wi_autorelease(wi_rsa_init_with_bits(wi_rsa_alloc(), 512));

	WI_TEST_ASSERT_NOT_NULL(rsa, "");
	WI_TEST_ASSERT_EQUALS(wi_rsa_bits(rsa), 512U, "");
}
Example #4
0
static void _wi_test_crypto_cipher(wi_cipher_type_t type, wi_string_t *name, wi_uinteger_t bits, wi_data_t *key, wi_data_t *iv) {
	wi_cipher_t		*cipher;
	
	cipher = wi_autorelease(wi_cipher_init_with_key(wi_cipher_alloc(), type, key, iv));
	
	WI_TEST_ASSERT_NOT_NULL(cipher, "");
	WI_TEST_ASSERT_EQUAL_INSTANCES(wi_cipher_key(cipher), key, "");
	WI_TEST_ASSERT_EQUAL_INSTANCES(wi_cipher_iv(cipher), iv, "");
	WI_TEST_ASSERT_EQUALS(wi_cipher_type(cipher), type, "");
	WI_TEST_ASSERT_EQUALS(wi_cipher_bits(cipher), bits, "");
	WI_TEST_ASSERT_EQUAL_INSTANCES(wi_cipher_name(cipher), name, "");

	WI_TEST_ASSERT_EQUAL_INSTANCES(
		wi_cipher_decrypt(cipher, wi_cipher_encrypt(cipher, wi_string_data(WI_STR("hello world")))),
		wi_string_data(WI_STR("hello world")),
		"%m");

	WI_TEST_ASSERT_EQUAL_INSTANCES(
		wi_cipher_decrypt(cipher, wi_cipher_encrypt(cipher, wi_string_data(WI_STR("hello world")))),
		wi_string_data(WI_STR("hello world")),
		"%m");

	cipher = wi_autorelease(wi_cipher_init_with_random_key(wi_cipher_alloc(), type)); 					

	WI_TEST_ASSERT_NOT_NULL(cipher, "");
}
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);
}
Example #6
0
void wi_test_error(void) {
    wi_string_t     *string;
    wi_boolean_t    result;
    
    result = wi_filesystem_file_exists_at_path(WI_STR("/non/existing/path"), NULL);
    
    WI_TEST_ASSERT_FALSE(result, "");
    WI_TEST_ASSERT_EQUALS(wi_error_domain(), WI_ERROR_DOMAIN_ERRNO, "");
    WI_TEST_ASSERT_EQUALS(wi_error_code(), ENOENT, "");
    WI_TEST_ASSERT_EQUAL_INSTANCES(wi_error_string(), WI_STR("No such file or directory"), "");
    
    string = wi_string_with_format(WI_STR("%m"));

    WI_TEST_ASSERT_EQUAL_INSTANCES(string, WI_STR("No such file or directory"), "");
}
Example #7
0
void wi_test_string_format(void) {
	WI_TEST_ASSERT_EQUAL_INSTANCES(
		wi_string_with_format(WI_STR("'%d' '%u' '%p' '%.5f' '%@' '%@' '%#@' '%s' '%s' '%#s'"),
			-5, 5, 0xAC1DFEED, 3.1415926, WI_STR("hello world"), NULL, NULL, "hello world", NULL, NULL),
		WI_STR("'-5' '5' '0xac1dfeed' '3.14159' 'hello world' '(null)' '' 'hello world' '(null)' ''"),
		"");
}
Example #8
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, "");
}
Example #9
0
void wi_test_runtime_functions(void) {
	_wi_runtimetest_t			*runtimetest1, *runtimetest2;
	_wi_mutable_runtimetest_t	*runtimetest3;
	
	_wi_runtimetest_deallocs = 0;
	
	runtimetest1 = _wi_runtimetest_init_with_value(_wi_runtimetest_alloc(), 42);
	runtimetest2 = wi_copy(runtimetest1);
	
	WI_TEST_ASSERT_TRUE(runtimetest1 == runtimetest2, "");
	
	wi_release(runtimetest2);

	runtimetest3 = wi_mutable_copy(runtimetest1);
	
	WI_TEST_ASSERT_TRUE(runtimetest1 != runtimetest3, "");
	WI_TEST_ASSERT_EQUALS(runtimetest1->value, runtimetest3->value, "");
	WI_TEST_ASSERT_TRUE(wi_is_equal(runtimetest1, runtimetest3), "");
	
	runtimetest3->value++;
	
	WI_TEST_ASSERT_FALSE(wi_is_equal(runtimetest1, runtimetest3), "");
	
	wi_release(runtimetest3);
	
	WI_TEST_ASSERT_EQUALS(_wi_runtimetest_deallocs, 1U, "");
	WI_TEST_ASSERT_EQUAL_INSTANCES(wi_description(runtimetest1), WI_STR("value=42"), "");
	WI_TEST_ASSERT_EQUALS(wi_hash(runtimetest1), 42U, "");
	
	wi_release(runtimetest1);
}
void wi_test_string_encoding_creation(void) {
#ifdef WI_STRING_ENCODING
    wi_string_encoding_t    *encoding;
    
    encoding = wi_string_encoding_with_charset(WI_STR("ASCII"), 0);
    
    WI_TEST_ASSERT_NOT_NULL(encoding, "");
    WI_TEST_ASSERT_EQUAL_INSTANCES(wi_string_encoding_charset(encoding), WI_STR("ASCII"), "");
    WI_TEST_ASSERT_EQUALS(wi_string_encoding_options(encoding), 0, "");
    
    encoding = wi_string_encoding_with_charset(WI_STR("ASCII"), WI_STRING_ENCODING_IGNORE);
    
    WI_TEST_ASSERT_NOT_NULL(encoding, "");
    WI_TEST_ASSERT_EQUAL_INSTANCES(wi_string_encoding_charset(encoding), WI_STR("ASCII"), "");
    WI_TEST_ASSERT_EQUALS(wi_string_encoding_options(encoding), WI_STRING_ENCODING_IGNORE, "");
#endif
}
Example #11
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, "");
}
Example #12
0
void wi_test_regexp_matching(void) {
    wi_regexp_t         *regexp;
    wi_string_t         *string;
    wi_regexp_match_t   matches[8];
    wi_range_t          range;
    wi_uinteger_t       i, count;
    
    regexp = wi_regexp_with_pattern(WI_STR("l"), 0);
    
    WI_TEST_ASSERT_EQUALS(wi_regexp_number_of_capture_groups(regexp), 0U, "");
    WI_TEST_ASSERT_EQUALS(wi_regexp_number_of_matches_in_string(regexp, WI_STR("foobar")), 0U, "");
    WI_TEST_ASSERT_EQUALS(wi_regexp_number_of_matches_in_string(regexp, WI_STR("hello world")), 3U, "");
    
    count = wi_regexp_get_matches_in_string(regexp, WI_STR("foobar"), matches, 8);
    
    WI_TEST_ASSERT_EQUALS(count, 0U, "");
    
    for(i = 0; i < 8; i++) {
        WI_TEST_ASSERT_EQUALS(matches[i].range.location, WI_NOT_FOUND, "");
        WI_TEST_ASSERT_EQUALS(matches[i].range.length, 0U, "");
    }
    
    count = wi_regexp_get_matches_in_string(regexp, WI_STR("hello world"), matches, 8);
    
    WI_TEST_ASSERT_EQUALS(count, 3U, "");
    WI_TEST_ASSERT_EQUALS(matches[0].range.location, 2U, "");
    WI_TEST_ASSERT_EQUALS(matches[0].range.length, 1U, "");
    WI_TEST_ASSERT_EQUALS(matches[1].range.location, 3U, "");
    WI_TEST_ASSERT_EQUALS(matches[1].range.length, 1U, "");
    WI_TEST_ASSERT_EQUALS(matches[2].range.location, 9U, "");
    WI_TEST_ASSERT_EQUALS(matches[2].range.length, 1U, "");
    
    for(i = 3; i < 8; i++) {
        WI_TEST_ASSERT_EQUALS(matches[i].range.location, WI_NOT_FOUND, "");
        WI_TEST_ASSERT_EQUALS(matches[i].range.length, 0U, "");
    }
    
    range = wi_regexp_range_of_first_match_in_string(regexp, WI_STR("foobar"));

    WI_TEST_ASSERT_EQUALS(range.location, WI_NOT_FOUND, "");
    WI_TEST_ASSERT_EQUALS(range.length, 0U, "");
    
    range = wi_regexp_range_of_first_match_in_string(regexp, WI_STR("hello world"));
    
    WI_TEST_ASSERT_EQUALS(range.location, 2U, "");
    WI_TEST_ASSERT_EQUALS(range.length, 1U, "");
    
    string = wi_regexp_string_of_first_match_in_string(regexp, WI_STR("foobar"));
    
    WI_TEST_ASSERT_NULL(string, "");
    
    string = wi_regexp_string_of_first_match_in_string(regexp, WI_STR("hello world"));
    
    WI_TEST_ASSERT_EQUAL_INSTANCES(string, WI_STR("l"), "");
}
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
}
Example #14
0
void wi_test_regexp_replacing_by_mutating(void) {
    wi_regexp_t             *regexp;
    wi_mutable_string_t     *string;
    wi_uinteger_t           count;
    
    regexp = wi_regexp_with_pattern(WI_STR("l"), 0);
    string = wi_mutable_string_with_format(WI_STR("hello world"));
    count = wi_regexp_replace_matches_in_string(regexp, string, WI_STR(""));
    
    WI_TEST_ASSERT_EQUALS(count, 3U, "");
    WI_TEST_ASSERT_EQUAL_INSTANCES(string, WI_STR("heo word"), "");
    
    regexp = wi_regexp_with_pattern(WI_STR("l"), 0);
    string = wi_mutable_string_with_format(WI_STR("hello world"));
    count = wi_regexp_replace_matches_in_string(regexp, string, WI_STR("x"));

    WI_TEST_ASSERT_EQUALS(count, 3U, "");
    WI_TEST_ASSERT_EQUAL_INSTANCES(string, WI_STR("hexxo worxd"), "");
    
    regexp = wi_regexp_with_pattern(WI_STR("l"), 0);
    string = wi_mutable_string_with_format(WI_STR("hello world"));
    count = wi_regexp_replace_matches_in_string(regexp, string, WI_STR("xxx"));
    
    WI_TEST_ASSERT_EQUALS(count, 3U, "");
    WI_TEST_ASSERT_EQUAL_INSTANCES(string, WI_STR("hexxxxxxo worxxxd"), "");
    
    regexp = wi_regexp_with_pattern(WI_STR("hello (world)"), 0);
    string = wi_mutable_string_with_format(WI_STR("hello world"));
    count = wi_regexp_replace_matches_in_string(regexp, string, WI_STR("hi $1"));
    
    WI_TEST_ASSERT_EQUALS(count, 1U, "");
    WI_TEST_ASSERT_EQUAL_INSTANCES(string, WI_STR("hi world"), "");
    
    regexp = wi_regexp_with_pattern(WI_STR("hello (world)"), 0);
    string = wi_mutable_string_with_format(WI_STR("hello world"));
    count = wi_regexp_replace_matches_in_string(regexp, string, WI_STR("hi $0"));
    
    WI_TEST_ASSERT_EQUALS(count, 1U, "");
    WI_TEST_ASSERT_EQUAL_INSTANCES(string, WI_STR("hi hello world"), "");
}
Example #15
0
void wi_test_dsa_runtime_functions(void) {
#ifdef WI_DSA
    wi_dsa_t    *dsa1, *dsa2;
    
    dsa1 = wi_autorelease(wi_dsa_init_with_bits(wi_dsa_alloc(), 512));
    dsa2 = wi_autorelease(wi_copy(dsa1));
    
    WI_TEST_ASSERT_EQUAL_INSTANCES(wi_dsa_private_key(dsa1), wi_dsa_private_key(dsa2), "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_id(dsa1), wi_dsa_runtime_id(), "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_id(dsa2), wi_dsa_runtime_id(), "");
    WI_TEST_ASSERT_NOT_EQUALS(wi_string_index_of_string(wi_description(dsa1), WI_STR("384"), 0), WI_NOT_FOUND, "");
#endif
}
Example #16
0
void wi_test_regexp_creation(void) {
    wi_regexp_t     *regexp;
    
    regexp = wi_regexp_with_pattern(WI_STR("*"), 0);
    
    WI_TEST_ASSERT_NULL(regexp, "");
    
    regexp = wi_regexp_with_pattern(WI_STR("foobar"), WI_REGEXP_CASE_INSENSITIVE | WI_REGEXP_NEWLINE_SENSITIVE);
    
    WI_TEST_ASSERT_NOT_NULL(regexp, "");
    WI_TEST_ASSERT_EQUAL_INSTANCES(wi_regexp_pattern(regexp), WI_STR("foobar"), "");
    WI_TEST_ASSERT_EQUALS(wi_regexp_options(regexp), WI_REGEXP_CASE_INSENSITIVE | WI_REGEXP_NEWLINE_SENSITIVE, "");
}
Example #17
0
void wi_test_host_runtime_functions(void) {
    wi_host_t   *host1, *host2, *host3, *host4, *host5, *host6;
    
    host1 = wi_host();
    host2 = wi_autorelease(wi_copy(host1));
    host3 = wi_host_with_string(WI_STR("localhost"));
    host4 = wi_autorelease(wi_copy(host3));
    host5 = wi_host_with_string(WI_STR("aab119a592b9e23779b66649677b436d24b35aaa5ad5beadf4c2a945b70577e5.com"));
    host6 = wi_autorelease(wi_copy(host5));
    
    WI_TEST_ASSERT_EQUAL_INSTANCES(host1, host2, "");
    WI_TEST_ASSERT_EQUAL_INSTANCES(host3, host4, "");
    WI_TEST_ASSERT_EQUAL_INSTANCES(host5, host6, "");
    WI_TEST_ASSERT_NOT_EQUAL_INSTANCES(host1, host3, "");
    WI_TEST_ASSERT_NOT_EQUAL_INSTANCES(host2, host3, "");
    WI_TEST_ASSERT_NOT_EQUAL_INSTANCES(host1, host4, "");
    WI_TEST_ASSERT_NOT_EQUAL_INSTANCES(host2, host4, "");
    WI_TEST_ASSERT_NOT_EQUAL_INSTANCES(host1, host5, "");
    WI_TEST_ASSERT_NOT_EQUAL_INSTANCES(host2, host5, "");
    WI_TEST_ASSERT_NOT_EQUAL_INSTANCES(host1, host6, "");
    WI_TEST_ASSERT_NOT_EQUAL_INSTANCES(host2, host6, "");
    WI_TEST_ASSERT_EQUALS(wi_hash(host1), wi_hash(host2), "");
    WI_TEST_ASSERT_EQUALS(wi_hash(host3), wi_hash(host4), "");
    WI_TEST_ASSERT_EQUALS(wi_hash(host5), wi_hash(host6), "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_id(host1), wi_host_runtime_id(), "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_id(host2), wi_host_runtime_id(), "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_id(host3), wi_host_runtime_id(), "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_id(host4), wi_host_runtime_id(), "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_id(host5), wi_host_runtime_id(), "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_id(host6), wi_host_runtime_id(), "");
    
#ifdef HAVE_GETIFADDRS
    WI_TEST_ASSERT_NOT_EQUALS(wi_string_index_of_string(wi_description(host1), WI_STR("127.0.0.1"), 0), WI_NOT_FOUND, "");
#else
    WI_TEST_ASSERT_NOT_EQUALS(wi_string_index_of_string(wi_description(host1), WI_STR("0.0.0.0"), 0), WI_NOT_FOUND, "");
#endif

    WI_TEST_ASSERT_NOT_EQUALS(wi_string_index_of_string(wi_description(host3), WI_STR("127.0.0.1"), 0), WI_NOT_FOUND, "");
}
Example #18
0
void wi_test_regexp_runtime_functions(void) {
    wi_regexp_t   *regexp1, *regexp2;
    
    regexp1 = wi_regexp_with_pattern(WI_STR("foobar"), 0);
    regexp2 = wi_autorelease(wi_copy(regexp1));
    
    WI_TEST_ASSERT_EQUAL_INSTANCES(regexp1, regexp2, "");
    WI_TEST_ASSERT_EQUALS(wi_hash(regexp1), wi_hash(regexp2), "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_id(regexp1), wi_regexp_runtime_id(), "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_id(regexp2), wi_regexp_runtime_id(), "");
    
    WI_TEST_ASSERT_NOT_EQUALS(wi_string_index_of_string(wi_description(regexp1), wi_regexp_pattern(regexp1), 0), WI_NOT_FOUND, "");
}
Example #19
0
void wi_test_sha2_digest(void) {
#ifdef WI_SHA1
    wi_sha2_t       *sha2;
    wi_data_t       *data;
    unsigned char   buffer[WI_SHA2_MAX_LENGTH];
    
    data = wi_data();
    
    wi_sha2_digest(WI_SHA2_256, wi_data_bytes(data), wi_data_length(data), buffer);
    
    WI_TEST_ASSERT_EQUAL_INSTANCES(wi_data_with_bytes(buffer, WI_SHA2_256_LENGTH), wi_data_with_base64_string(WI_STR("47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=")), "");
    WI_TEST_ASSERT_EQUAL_INSTANCES(wi_sha2_digest_string(WI_SHA2_256, data), WI_STR("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"), "");
    
    sha2 = wi_sha2_with_bits(WI_SHA2_512);
    
    wi_sha2_close(sha2);
    wi_sha2_get_data(sha2, buffer);
    
    WI_TEST_ASSERT_EQUAL_INSTANCES(wi_data_with_bytes(buffer, WI_SHA2_512_LENGTH), wi_data_with_base64_string(WI_STR("z4PhNX7vuL3xVChQ1m2AB9Yg5AULVxXcg/SpIdNs6c5H0NE8XYXysP+DGNKHfuwvY7kxvUdBeoGlODJ6+SfaPg==")), "");
    WI_TEST_ASSERT_EQUAL_INSTANCES(wi_sha2_data(sha2), wi_data_with_base64_string(WI_STR("z4PhNX7vuL3xVChQ1m2AB9Yg5AULVxXcg/SpIdNs6c5H0NE8XYXysP+DGNKHfuwvY7kxvUdBeoGlODJ6+SfaPg==")), "");
#endif
}
Example #20
0
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
}
Example #21
0
void wi_test_runtime_info(void) {
	_wi_runtimetest_t		*runtimetest;
	
	WI_TEST_ASSERT_EQUALS(wi_runtime_class_with_name(WI_STR("_wi_runtimetest_t")), &_wi_runtimetest_runtime_class, "");
	WI_TEST_ASSERT_EQUALS(wi_runtime_class_with_id(_wi_runtimetest_runtime_id), &_wi_runtimetest_runtime_class, "");
	
	runtimetest = _wi_runtimetest_init_with_value(_wi_runtimetest_alloc(), 42);
	
	WI_TEST_ASSERT_EQUALS(wi_runtime_id(runtimetest), _wi_runtimetest_runtime_id, "");
	WI_TEST_ASSERT_EQUALS(wi_runtime_class(runtimetest), &_wi_runtimetest_runtime_class, "");
	WI_TEST_ASSERT_EQUAL_INSTANCES(wi_runtime_class_name(runtimetest), wi_string_with_cstring(_wi_runtimetest_runtime_class.name), "");
	
	wi_release(runtimetest);
}
Example #22
0
void wi_test_runtime_info(void) {
    _wi_runtimetest_t   *runtimetest;
    
    WI_TEST_ASSERT_EQUALS(wi_runtime_class_with_name(WI_STR("_wi_runtimetest_t")), &_wi_runtimetest_runtime_class, "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_class_with_id(_wi_runtimetest_runtime_id), &_wi_runtimetest_runtime_class, "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_id_for_class(&_wi_runtimetest_runtime_class), _wi_runtimetest_runtime_id, "");
    
    runtimetest = _wi_runtimetest_init_with_value(_wi_runtimetest_alloc(), 42);
    
    WI_TEST_ASSERT_EQUALS(wi_runtime_class(runtimetest), &_wi_runtimetest_runtime_class, "");
    WI_TEST_ASSERT_EQUAL_INSTANCES(wi_runtime_class_name(runtimetest), wi_string_with_utf8_string(_wi_runtimetest_runtime_class.name), "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_id(runtimetest), _wi_runtimetest_runtime_id, "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_options(runtimetest), WI_RUNTIME_OPTION_IMMUTABLE, "");
    
    wi_release(runtimetest);
}
Example #23
0
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_runtime_functions(void) {
    wi_indexset_t           *indexset1;
    wi_mutable_indexset_t   *indexset2;
    
    indexset1 = wi_indexset_with_indexes_in_range(wi_make_range(1, 3));
    indexset2 = wi_autorelease(wi_mutable_copy(indexset1));
    
    WI_TEST_ASSERT_EQUAL_INSTANCES(indexset1, indexset2, "");
    WI_TEST_ASSERT_EQUALS(wi_hash(indexset1), wi_hash(indexset2), "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_id(indexset1), wi_indexset_runtime_id(), "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_id(indexset2), wi_indexset_runtime_id(), "");
    WI_TEST_ASSERT_TRUE(wi_runtime_options(indexset1) & WI_RUNTIME_OPTION_IMMUTABLE, "");
    WI_TEST_ASSERT_TRUE(wi_runtime_options(indexset2) & WI_RUNTIME_OPTION_MUTABLE, "");
    
    wi_mutable_indexset_remove_index(indexset2, 1);
    wi_mutable_indexset_add_index(indexset2, 4);
    
    WI_TEST_ASSERT_NOT_EQUAL_INSTANCES(indexset1, indexset2, "");
    
    WI_TEST_ASSERT_NOT_EQUALS(wi_string_index_of_string(wi_description(indexset2), WI_STR("4"), 0), WI_NOT_FOUND, "");
}
void wi_test_filesystem_events(void) {
#if defined(WI_FILESYSTEM_EVENTS)
    wi_filesystem_events_t  *filesystem_events;
    wi_string_t             *path;
    wi_boolean_t            result;
    
    _wi_test_filesystem_events_lock = wi_autorelease(wi_condition_lock_init_with_condition(wi_condition_lock_alloc(), 0));
    _wi_test_filesystem_events_paths = wi_mutable_set();
    
    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, "");
    
    filesystem_events = wi_filesystem_events();
    
    WI_TEST_ASSERT_NOT_NULL(filesystem_events, "");
    
    result = wi_filesystem_events_add_path_with_callback(filesystem_events, path, _wi_test_filesystem_events_callback);
    
    WI_TEST_ASSERT_TRUE(result, "");
    
    result = wi_string_write_utf8_string_to_path(WI_STR("hello world"), wi_string_by_appending_path_component(path, WI_STR("foobar")));
    
    WI_TEST_ASSERT_TRUE(result, "");
    
    if(!wi_condition_lock_lock_when_condition(_wi_test_filesystem_events_lock, 1, 1.0))
        WI_TEST_FAIL("timed out waiting for filesystem events thread");
    
    WI_TEST_ASSERT_EQUAL_INSTANCES(_wi_test_filesystem_events_paths, wi_set_with_data(path, NULL), "");
    
    wi_condition_lock_unlock(_wi_test_filesystem_events_lock);
#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, "");
}
void wi_test_indexset_mutation(void) {
    wi_mutable_indexset_t     *indexset1, *indexset2;
    
    indexset1 = wi_mutable_indexset();
    
    WI_TEST_ASSERT_EQUALS(wi_indexset_count(indexset1), 0U, "");
    WI_TEST_ASSERT_FALSE(wi_indexset_contains_index(indexset1, 1), "");
    WI_TEST_ASSERT_FALSE(wi_indexset_contains_index(indexset1, 2), "");
    WI_TEST_ASSERT_FALSE(wi_indexset_contains_index(indexset1, 3), "");
    WI_TEST_ASSERT_EQUALS(wi_indexset_first_index(indexset1), 0U, "");
    WI_TEST_ASSERT_EQUALS(wi_indexset_last_index(indexset1), 0U, "");
    
    wi_mutable_indexset_add_index(indexset1, 1);
    wi_mutable_indexset_add_indexes(indexset1, wi_indexset_with_index(2));
    wi_mutable_indexset_add_indexes_in_range(indexset1, wi_make_range(3, 1));
    
    WI_TEST_ASSERT_EQUALS(wi_indexset_count(indexset1), 3U, "");
    WI_TEST_ASSERT_TRUE(wi_indexset_contains_index(indexset1, 1), "");
    WI_TEST_ASSERT_TRUE(wi_indexset_contains_index(indexset1, 2), "");
    WI_TEST_ASSERT_TRUE(wi_indexset_contains_index(indexset1, 3), "");
    WI_TEST_ASSERT_EQUALS(wi_indexset_first_index(indexset1), 1U, "");
    WI_TEST_ASSERT_EQUALS(wi_indexset_last_index(indexset1), 3U, "");
    
    wi_mutable_indexset_remove_index(indexset1, 1);
    wi_mutable_indexset_remove_indexes(indexset1, wi_indexset_with_index(2));
    wi_mutable_indexset_remove_indexes_in_range(indexset1, wi_make_range(3, 1));
    
    WI_TEST_ASSERT_EQUALS(wi_indexset_count(indexset1), 0U, "");
    WI_TEST_ASSERT_FALSE(wi_indexset_contains_index(indexset1, 1), "");
    WI_TEST_ASSERT_FALSE(wi_indexset_contains_index(indexset1, 2), "");
    WI_TEST_ASSERT_FALSE(wi_indexset_contains_index(indexset1, 3), "");
    WI_TEST_ASSERT_EQUALS(wi_indexset_first_index(indexset1), 0U, "");
    WI_TEST_ASSERT_EQUALS(wi_indexset_last_index(indexset1), 0U, "");

    wi_mutable_indexset_add_indexes_in_range(indexset1, wi_make_range(1, 3));
    
    indexset2 = wi_autorelease(wi_mutable_copy(indexset1));

    wi_mutable_indexset_add_index(indexset2, 5);
    wi_mutable_indexset_add_index(indexset2, 4);

    WI_TEST_ASSERT_EQUALS(wi_indexset_count(indexset2), 5U, "");
    WI_TEST_ASSERT_TRUE(wi_indexset_contains_index(indexset2, 1), "");
    WI_TEST_ASSERT_TRUE(wi_indexset_contains_index(indexset2, 2), "");
    WI_TEST_ASSERT_TRUE(wi_indexset_contains_index(indexset2, 3), "");
    WI_TEST_ASSERT_TRUE(wi_indexset_contains_index(indexset2, 4), "");
    WI_TEST_ASSERT_TRUE(wi_indexset_contains_index(indexset2, 5), "");
    WI_TEST_ASSERT_EQUALS(wi_indexset_first_index(indexset2), 1U, "");
    WI_TEST_ASSERT_EQUALS(wi_indexset_last_index(indexset2), 5U, "");
    
    wi_mutable_indexset_set_indexes(indexset1, indexset2);

    WI_TEST_ASSERT_EQUAL_INSTANCES(indexset1, indexset2, "");
    
    wi_mutable_indexset_remove_all_indexes(indexset1);
    
    WI_TEST_ASSERT_EQUALS(wi_indexset_count(indexset1), 0U, "");
    WI_TEST_ASSERT_FALSE(wi_indexset_contains_index(indexset1, 1), "");
    WI_TEST_ASSERT_FALSE(wi_indexset_contains_index(indexset1, 2), "");
    WI_TEST_ASSERT_FALSE(wi_indexset_contains_index(indexset1, 3), "");
    WI_TEST_ASSERT_EQUALS(wi_indexset_first_index(indexset1), 0U, "");
    WI_TEST_ASSERT_EQUALS(wi_indexset_last_index(indexset1), 0U, "");
}
Example #28
0
void wi_test_string_data_conversions(void) {
	WI_TEST_ASSERT_EQUAL_INSTANCES(wi_string_md5(WI_STR("hello world")), WI_STR("5eb63bbbe01eeed093cb22bb8f5acdc3"), "");
	WI_TEST_ASSERT_EQUAL_INSTANCES(wi_string_sha1(WI_STR("hello world")), WI_STR("2aae6c35c94fcfb415dbe95f408b9ce91ee846ed"), "");
	WI_TEST_ASSERT_EQUAL_INSTANCES(wi_string_base64(WI_STR("hello world")), WI_STR("aGVsbG8gd29ybGQ="), "");
	WI_TEST_ASSERT_EQUAL_INSTANCES(wi_string_with_base64(WI_STR("aGVsbG8gd29ybGQ=")), WI_STR("hello world"), "");
}
Example #29
0
void wi_test_string_case(void) {
	WI_TEST_ASSERT_EQUAL_INSTANCES(wi_string_lowercase_string(WI_STR("ABC")), WI_STR("abc"), "");
	WI_TEST_ASSERT_EQUAL_INSTANCES(wi_string_uppercase_string(WI_STR("abc")), WI_STR("ABC"), "");
}