示例#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
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, "");
}
示例#3
0
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")), "");
}
示例#4
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, "");
}
示例#5
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);
}
示例#6
0
void wi_test_runtime_pool(void) {
	wi_pool_t			*pool, *pool2;
	_wi_runtimetest_t	*runtimetest, *runtimetest2;
	
	_wi_runtimetest_deallocs = 0;
	
	pool = wi_pool_init(wi_pool_alloc());
	runtimetest = wi_retain(wi_autorelease(_wi_runtimetest_init_with_value(_wi_runtimetest_alloc(), 42)));
	wi_release(pool);
	WI_TEST_ASSERT_EQUALS(wi_retain_count(runtimetest), 1U, "");
	wi_release(runtimetest);

	pool = wi_pool_init(wi_pool_alloc());
	runtimetest = wi_retain(wi_autorelease(_wi_runtimetest_init_with_value(_wi_runtimetest_alloc(), 42)));
	wi_pool_drain(pool);
	WI_TEST_ASSERT_EQUALS(wi_retain_count(runtimetest), 1U, "");
	wi_release(pool);
	wi_release(runtimetest);
	
	pool = wi_pool_init(wi_pool_alloc());
	runtimetest = wi_retain(wi_autorelease(_wi_runtimetest_init_with_value(_wi_runtimetest_alloc(), 42)));
	pool2 = wi_pool_init(wi_pool_alloc());
	runtimetest2 = wi_retain(wi_autorelease(_wi_runtimetest_init_with_value(_wi_runtimetest_alloc(), 42)));
	wi_release(pool2);
	WI_TEST_ASSERT_EQUALS(wi_retain_count(runtimetest2), 1U, "");
	wi_release(pool);
	WI_TEST_ASSERT_EQUALS(wi_retain_count(runtimetest), 1U, "");
	wi_release(runtimetest);
	wi_release(runtimetest2);
}
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);
}
void wi_test_indexset_creation(void) {
    wi_indexset_t    *indexset;
    
    indexset = wi_indexset();

    WI_TEST_ASSERT_NOT_NULL(indexset, "");
    WI_TEST_ASSERT_EQUALS(wi_indexset_count(indexset), 0U, "");
    WI_TEST_ASSERT_EQUALS(wi_indexset_first_index(indexset), 0U, "");
    WI_TEST_ASSERT_EQUALS(wi_indexset_last_index(indexset), 0U, "");
    
    indexset = wi_indexset_with_index(1);

    WI_TEST_ASSERT_NOT_NULL(indexset, "");
    WI_TEST_ASSERT_EQUALS(wi_indexset_count(indexset), 1U, "");
    WI_TEST_ASSERT_TRUE(wi_indexset_contains_index(indexset, 1), "");
    WI_TEST_ASSERT_EQUALS(wi_indexset_first_index(indexset), 1U, "");
    WI_TEST_ASSERT_EQUALS(wi_indexset_last_index(indexset), 1U, "");
    
    indexset = wi_indexset_with_indexes_in_range(wi_make_range(1, 3));
    
    WI_TEST_ASSERT_NOT_NULL(indexset, "");
    WI_TEST_ASSERT_EQUALS(wi_indexset_count(indexset), 3U, "");
    WI_TEST_ASSERT_TRUE(wi_indexset_contains_index(indexset, 1), "");
    WI_TEST_ASSERT_TRUE(wi_indexset_contains_index(indexset, 2), "");
    WI_TEST_ASSERT_TRUE(wi_indexset_contains_index(indexset, 3), "");
    WI_TEST_ASSERT_EQUALS(wi_indexset_first_index(indexset), 1U, "");
    WI_TEST_ASSERT_EQUALS(wi_indexset_last_index(indexset), 3U, "");
}
示例#9
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, "");
}
示例#10
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
}
示例#11
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);
}
示例#12
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"), "");
}
示例#13
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));
}
示例#14
0
void wi_test_set_instances(void) {
    wi_set_t    *set;
    wi_array_t  *array;
    
    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")), "");
    
    array = wi_set_all_data(set);
    
    WI_TEST_ASSERT_EQUALS(wi_array_count(array), 2U, "");
    WI_TEST_ASSERT_TRUE(wi_array_contains_data(array, WI_STR("foo")), "");
    WI_TEST_ASSERT_TRUE(wi_array_contains_data(array, WI_STR("bar")), "");
}
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
}
示例#16
0
void wi_test_indexset_indexes(void) {
    wi_indexset_t   *indexset;
    
    indexset = wi_indexset_with_indexes_in_range(wi_make_range(1, 3));
    
    WI_TEST_ASSERT_NOT_NULL(indexset, "");
    WI_TEST_ASSERT_EQUALS(wi_indexset_count(indexset), 3U, "");
    WI_TEST_ASSERT_TRUE(wi_indexset_contains_index(indexset, 1), "");
    WI_TEST_ASSERT_TRUE(wi_indexset_contains_index(indexset, 2), "");
    WI_TEST_ASSERT_TRUE(wi_indexset_contains_index(indexset, 3), "");
    WI_TEST_ASSERT_FALSE(wi_indexset_contains_index(indexset, 4), "");
    WI_TEST_ASSERT_TRUE(wi_indexset_contains_indexes(indexset, wi_indexset_with_index(1)), "");
    WI_TEST_ASSERT_FALSE(wi_indexset_contains_indexes(indexset, wi_indexset_with_index(4)), "");
    WI_TEST_ASSERT_TRUE(wi_indexset_contains_indexes_in_range(indexset, wi_make_range(2, 1)), "");
    WI_TEST_ASSERT_FALSE(wi_indexset_contains_indexes_in_range(indexset, wi_make_range(4, 1)), "");
    WI_TEST_ASSERT_EQUALS(wi_indexset_first_index(indexset), 1U, "");
    WI_TEST_ASSERT_EQUALS(wi_indexset_last_index(indexset), 3U, "");
}
示例#17
0
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, "");
}
示例#18
0
void wi_test_sha2_creation(void) {
#ifdef WI_SHA1
    wi_sha2_t   *sha2;
    
    sha2 = wi_sha2_with_bits(WI_SHA2_256);
    
    WI_TEST_ASSERT_NOT_NULL(sha2, "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_id(sha2), wi_sha2_runtime_id(), "");
#endif
}
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
}
示例#20
0
void wi_test_set_scalars(void) {
    wi_mutable_set_t    *set;
    wi_array_t          *array;
    
    set = wi_set_init_with_capacity_and_callbacks(wi_mutable_set_alloc(), 0, false, wi_set_null_callbacks);
    
    wi_mutable_set_add_data(set, "foo");
    wi_mutable_set_add_data(set, "bar");
    
    WI_TEST_ASSERT_NOT_NULL(set, "");
    WI_TEST_ASSERT_EQUALS(wi_set_count(set), 2U, "");
    WI_TEST_ASSERT_TRUE(wi_set_contains_data(set, "foo"), "");
    WI_TEST_ASSERT_TRUE(wi_set_contains_data(set, "bar"), "");
    
    array = wi_set_all_data(set);
    
    WI_TEST_ASSERT_EQUALS(wi_array_count(array), 2U, "");
    WI_TEST_ASSERT_TRUE(wi_array_contains_data(array, "foo"), "");
    WI_TEST_ASSERT_TRUE(wi_array_contains_data(array, "bar"), "");
}
void wi_test_string_encoding_runtime_functions(void) {
#ifdef WI_STRING_ENCODING
    wi_string_encoding_t    *encoding;

    encoding = wi_string_encoding_with_charset(WI_STR("ASCII"), 0);

    WI_TEST_ASSERT_EQUALS(wi_runtime_id(encoding), wi_string_encoding_runtime_id(), "");

    WI_TEST_ASSERT_NOT_EQUALS(wi_string_index_of_string(wi_description(encoding), WI_STR("ASCII"), 0), WI_NOT_FOUND, "");
#endif
}
void wi_test_readwrite_lock_runtime_functions(void) {
#ifdef WI_PTHREADS
    wi_readwrite_lock_t     *lock;
    
    lock = wi_autorelease(wi_readwrite_lock_init(wi_readwrite_lock_alloc()));
    
    WI_TEST_ASSERT_EQUALS(wi_runtime_id(lock), wi_readwrite_lock_runtime_id(), "");
    
    WI_TEST_ASSERT_NOT_EQUALS(wi_string_index_of_string(wi_description(lock), WI_STR("wi_readwrite_lock_t"), 0), WI_NOT_FOUND, "");
#endif
}
示例#23
0
void wi_test_dsa_accessors(void) {
#ifdef WI_DSA
    wi_dsa_t    *dsa;
    
    dsa = wi_autorelease(wi_dsa_init_with_bits(wi_dsa_alloc(), 512));
    
    WI_TEST_ASSERT_TRUE(wi_data_length(wi_dsa_public_key(dsa)) > 0, "");
    WI_TEST_ASSERT_TRUE(wi_data_length(wi_dsa_private_key(dsa)) > 0, "");
    WI_TEST_ASSERT_EQUALS(wi_dsa_bits(dsa), 384U, "");
#endif
}
示例#24
0
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, "");
}
示例#25
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"), "");
}
示例#26
0
void wi_test_timer(void) {
#ifdef WI_PTHREADS
    wi_timer_t		*timer;

    timer = wi_autorelease(wi_timer_init_with_function(wi_timer_alloc(), _wi_test_timer_function, 0.01, false));
    wi_timer_set_data(timer, &_wi_test_timer_hits);
    wi_timer_schedule(timer);

    wi_thread_sleep(0.1);

    WI_TEST_ASSERT_EQUALS(_wi_test_timer_hits, 5U, "");
#endif
}
示例#27
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, "");
}
示例#28
0
void wi_test_runtime_retain(void) {
	_wi_runtimetest_t		*runtimetest, *runtimetest2;
	
	_wi_runtimetest_deallocs = 0;

	runtimetest = _wi_runtimetest_init_with_value(_wi_runtimetest_alloc(), 42);
	
	WI_TEST_ASSERT_EQUALS(wi_retain_count(runtimetest), 1U, "");
	
	runtimetest2 = wi_retain(runtimetest);
	
	WI_TEST_ASSERT_EQUALS(wi_retain_count(runtimetest), 2U, "");
	WI_TEST_ASSERT_EQUALS(runtimetest, runtimetest2, "");
	
	wi_release(runtimetest);
	
	WI_TEST_ASSERT_EQUALS(wi_retain_count(runtimetest), 1U, "");
	
	wi_release(runtimetest);
	
	WI_TEST_ASSERT_EQUALS(_wi_runtimetest_deallocs, 1U, "");
}
示例#29
0
void wi_test_set(void) {
	wi_set_t		*set;
	
	set = wi_set_init(wi_set_alloc());
	
	WI_TEST_ASSERT_NOT_NULL(set, "");
	
	wi_set_add_data(set, WI_STR("foo"));
	
	WI_TEST_ASSERT_TRUE(wi_set_contains_data(set, WI_STR("foo")), "");
	WI_TEST_ASSERT_FALSE(wi_set_contains_data(set, WI_STR("bar")), "");
	WI_TEST_ASSERT_EQUALS(wi_set_count_for_data(set, WI_STR("foo")), 1U, "");
	
	wi_release(set);

	set = wi_set_init_with_capacity(wi_set_alloc(), 0, true);

	WI_TEST_ASSERT_NOT_NULL(set, "");
	
	wi_set_add_data(set, WI_STR("foo"));
	wi_set_add_data(set, WI_STR("foo"));

	WI_TEST_ASSERT_TRUE(wi_set_contains_data(set, WI_STR("foo")), "");
	WI_TEST_ASSERT_FALSE(wi_set_contains_data(set, WI_STR("bar")), "");
	WI_TEST_ASSERT_EQUALS(wi_set_count_for_data(set, WI_STR("foo")), 2U, "");

	wi_set_remove_data(set, WI_STR("foo"));

	WI_TEST_ASSERT_TRUE(wi_set_contains_data(set, WI_STR("foo")), "");
	WI_TEST_ASSERT_EQUALS(wi_set_count_for_data(set, WI_STR("foo")), 1U, "");
	
	wi_set_remove_data(set, WI_STR("foo"));
	
	WI_TEST_ASSERT_FALSE(wi_set_contains_data(set, WI_STR("foo")), "");
	WI_TEST_ASSERT_EQUALS(wi_set_count_for_data(set, WI_STR("foo")), 0U, "");
	
	wi_release(set);
}
示例#30
0
void wi_test_dsa_creation(void) {
#ifdef WI_DSA
    wi_dsa_t    *dsa;
    
    dsa = wi_autorelease(wi_dsa_init_with_bits(wi_dsa_alloc(), 512));
    
    WI_TEST_ASSERT_NOT_NULL(dsa, "");
    WI_TEST_ASSERT_EQUALS(wi_dsa_bits(dsa), 384U, "");
    
    dsa = wi_autorelease(wi_dsa_init_with_pem_file(wi_dsa_alloc(), WI_STR("/non/existing/file.pem")));
    
    WI_TEST_ASSERT_NULL(dsa, "");
    
    dsa = wi_autorelease(wi_dsa_init_with_pem_file(wi_dsa_alloc(), wi_string_by_appending_path_component(wi_test_fixture_path, WI_STR("wi-dsa-tests-1.pem"))));
    
    WI_TEST_ASSERT_NULL(dsa, "");
    
    dsa = wi_autorelease(wi_dsa_init_with_pem_file(wi_dsa_alloc(), wi_string_by_appending_path_component(wi_test_fixture_path, WI_STR("wi-dsa-tests-2.pem"))));
    
    WI_TEST_ASSERT_NOT_NULL(dsa, "");
    WI_TEST_ASSERT_EQUALS(wi_dsa_bits(dsa), 384U, "");
    
    dsa = wi_autorelease(wi_dsa_init_with_private_key(wi_dsa_alloc(), wi_data()));
    
    WI_TEST_ASSERT_NULL(dsa, "");
    
    dsa = wi_autorelease(wi_dsa_init_with_private_key(wi_dsa_alloc(), wi_data_with_base64_string(WI_STR("MIH3AgEAAkEA0c36Uaj1S/cKjYAokEUtWQHmFHLqd8mbnY9J9wyNS0mlXvklnko2NlflL1qg9p58uRjkGBtCinI0mxeEIxwckwIVAPpF85s7Iv1o7z4UUAs9KRamjULXAkBFchKBXr+D+lGgnBFtb//EBThgSD9t3WBxyKGvNLBDWGJu2+av/fR9uBxBm1cUUldzGvqBjr/lcBmTIUe4rmAcAkBBN2fEFvs6uuIX+/8EqM1T2yBmwt3KHMVuCD+opZga29WJPNZgNXIj8yNFGFIxJeTndvhcndNrlcztYx3e/GSCAhRDUGb+CUPkNuBbsSHbdYtEQ+/2Gg=="))));
    
    WI_TEST_ASSERT_NOT_NULL(dsa, "");
    WI_TEST_ASSERT_EQUALS(wi_dsa_bits(dsa), 384U, "");
    
    dsa = wi_autorelease(wi_dsa_init_with_public_key(wi_dsa_alloc(), wi_data()));
    
    WI_TEST_ASSERT_NULL(dsa, "");
#endif
}