Exemplo n.º 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, "");
}
Exemplo n.º 2
0
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, "");
}
void wi_test_readwrite_lock_locking(void) {
#ifdef WI_PTHREADS
    wi_readwrite_lock_t     *lock;
    wi_boolean_t            result;
    
    lock = wi_autorelease(wi_readwrite_lock_init(wi_readwrite_lock_alloc()));
    
    wi_readwrite_lock_read_lock(lock);
    wi_readwrite_lock_unlock(lock);
    
    wi_readwrite_lock_write_lock(lock);
    wi_readwrite_lock_unlock(lock);
    
    result = wi_readwrite_lock_try_read_lock(lock);
    
    WI_TEST_ASSERT_TRUE(result, "");
    
    wi_readwrite_lock_unlock(lock);
    
    result = wi_readwrite_lock_try_write_lock(lock);
    
    WI_TEST_ASSERT_TRUE(result, "");
    
    wi_readwrite_lock_unlock(lock);
#endif
}
Exemplo n.º 4
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));
}
Exemplo n.º 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);
}
Exemplo n.º 6
0
void wi_test_ip(void) {
	WI_TEST_ASSERT_TRUE(wi_ip_matches_string(WI_STR("127.0.0.1"), WI_STR("127.0.0.1")), "");
	WI_TEST_ASSERT_TRUE(wi_ip_matches_string(WI_STR("127.0.0.1"), WI_STR("127.0.0.*")), "");
	WI_TEST_ASSERT_FALSE(wi_ip_matches_string(WI_STR("255.0.0.1"), WI_STR("127.0.0.*")), "");
	WI_TEST_ASSERT_TRUE(wi_ip_matches_string(WI_STR("127.0.0.1"), WI_STR("127.0.0.0/24")), "");
	WI_TEST_ASSERT_FALSE(wi_ip_matches_string(WI_STR("255.0.0.1"), WI_STR("127.0.0.0/24")), "");
	WI_TEST_ASSERT_TRUE(wi_ip_matches_string(WI_STR("::1"), WI_STR("0000:0000:0000:0000:0000:0000:0000:0001")), "");
}
Exemplo n.º 7
0
void wi_test_string_compare(void) {
	WI_TEST_ASSERT_TRUE(wi_is_equal(wi_string_with_cstring("hello world"), wi_string_with_cstring("hello world")), "");
	WI_TEST_ASSERT_FALSE(wi_is_equal(wi_string_with_cstring("hello world"), wi_string_with_cstring("hello another world")), "");
	WI_TEST_ASSERT_TRUE(wi_string_compare(wi_string_with_cstring("hello world"), wi_string_with_cstring("hello world")) == 0, "");
	WI_TEST_ASSERT_FALSE(wi_string_compare(wi_string_with_cstring("hello world"), wi_string_with_cstring("Hello world")) == 0, "");
	WI_TEST_ASSERT_FALSE(wi_string_compare(wi_string_with_cstring("hello world"), wi_string_with_cstring("hello another world")) == 0, "");
	WI_TEST_ASSERT_TRUE(wi_string_case_insensitive_compare(wi_string_with_cstring("hello world"), wi_string_with_cstring("Hello world")) == 0, "");
	WI_TEST_ASSERT_FALSE(wi_string_case_insensitive_compare(wi_string_with_cstring("hello world"), wi_string_with_cstring("Hello another world")) == 0, "");
}
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);
}
Exemplo n.º 9
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
}
Exemplo n.º 10
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")), "");
}
Exemplo n.º 11
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, "");
}
Exemplo n.º 12
0
void wi_test_host_addresses(void) {
    wi_host_t   *host;
    wi_array_t  *addresses;
    
    host = wi_host();
    addresses = wi_host_addresses(host);
    
    WI_TEST_ASSERT_TRUE(wi_array_count(addresses) > 0, "");
    WI_TEST_ASSERT_TRUE(wi_array_contains_data(addresses, wi_host_address(host)), "");
    
#ifndef HAVE_GETIFADDRS
    WI_TEST_ASSERT_TRUE(wi_array_contains_data(addresses, wi_address_wildcard_for_family(WI_ADDRESS_IPV4)), "");
    WI_TEST_ASSERT_TRUE(wi_array_contains_data(addresses, wi_address_wildcard_for_family(WI_ADDRESS_IPV6)), "");
#endif
    
    host = wi_host_with_string(WI_STR("aab119a592b9e23779b66649677b436d24b35aaa5ad5beadf4c2a945b70577e5.com"));

    WI_TEST_ASSERT_NULL(wi_host_addresses(host), "");
    WI_TEST_ASSERT_NULL(wi_host_address(host), "");
}
Exemplo n.º 13
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"), "");
}
Exemplo n.º 14
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, "");
}
Exemplo n.º 15
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")), "");
}
Exemplo n.º 16
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);
}
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
}
Exemplo n.º 18
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, "");
}
Exemplo n.º 19
0
void wi_test_number(void) {
	WI_TEST_ASSERT_TRUE(wi_number_bool(wi_number_with_bool(true)), "");
	WI_TEST_ASSERT_FALSE(wi_number_bool(wi_number_with_bool(false)), "");
	WI_TEST_ASSERT_EQUALS(wi_number_int32(wi_number_with_int32(2147483647)), 2147483647, "");
	WI_TEST_ASSERT_EQUALS((uint32_t) wi_number_int32(wi_number_with_int32(4294967295U)), 4294967295U, "");
	WI_TEST_ASSERT_EQUALS(wi_number_int64(wi_number_with_int64(9223372036854775807LL)), 9223372036854775807LL, "");
	WI_TEST_ASSERT_EQUALS((uint64_t) wi_number_int64(wi_number_with_int64(18446744073709551615ULL)), 18446744073709551615ULL, "");

#ifdef WI_32
	WI_TEST_ASSERT_EQUALS(wi_number_integer(wi_number_with_integer(2147483647)), 2147483647, "");
	WI_TEST_ASSERT_EQUALS((wi_uinteger_t) wi_number_integer(wi_number_with_integer(4294967295U)), 4294967295U, "");
#else
	WI_TEST_ASSERT_EQUALS(wi_number_integer(wi_number_with_integer(9223372036854775807LL)), 9223372036854775807LL, "");
	WI_TEST_ASSERT_EQUALS((wi_uinteger_t) wi_number_integer(wi_number_with_integer(18446744073709551615ULL)), 18446744073709551615ULL, "");
#endif
	
	WI_TEST_ASSERT_EQUALS_WITH_ACCURACY(wi_number_float(wi_number_with_float(3.40282346e38)), 3.40282346e38F, 0.0001, "");
	WI_TEST_ASSERT_EQUALS_WITH_ACCURACY(wi_number_double(wi_number_with_double(1.7976931348623155e308)), 1.7976931348623155e308, 0.0001, "");
}
Exemplo n.º 20
0
void wi_test_system(void) {
    wi_array_t  *backtrace;
    
    WI_TEST_ASSERT_TRUE(wi_user_id() >= 0, "");
    WI_TEST_ASSERT_TRUE(wi_string_length(wi_user_name()) > 0, "");
    WI_TEST_ASSERT_TRUE(wi_string_length(wi_user_home()) > 0, "");
    WI_TEST_ASSERT_TRUE(wi_group_id() >= 0, "");
    WI_TEST_ASSERT_TRUE(wi_string_length(wi_group_name()) > 0, "");

    WI_TEST_ASSERT_TRUE(wi_page_size() > 0, "");
    
    backtrace = wi_backtrace();
    
    if(backtrace) {
        WI_TEST_ASSERT_TRUE(wi_array_count(backtrace) > 0, "");
        WI_TEST_ASSERT_NOT_EQUALS(wi_string_index_of_string(wi_array_components_joined_by_string(backtrace, WI_STR("\n")),
                                                            WI_STR("test"), 0),
                                  WI_NOT_FOUND, "");
    }
    
    WI_TEST_ASSERT_TRUE(wi_string_length(wi_getenv(WI_STR("HOME"))) > 0, "");
}
Exemplo n.º 21
0
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, "");
}
Exemplo n.º 22
0
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, "");
}
Exemplo n.º 23
0
void wi_test_string_constant(void) {
	WI_TEST_ASSERT_EQUALS(WI_STR("hello world"), WI_STR("hello world"), "");
	WI_TEST_ASSERT_TRUE(WI_STR("hello world") != WI_STR("hello another world"), "");
}