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, ""); }
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, ""); }
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_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_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, ""); }
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, ""); }
static wi_hash_code_t _wi_uuid_hash(wi_runtime_instance_t *instance) { wi_uuid_t *uuid = instance; return wi_hash(_wi_uuid_string(uuid)); }
static wi_hash_code_t _wi_url_hash(wi_runtime_instance_t *instance) { wi_url_t *url = instance; return wi_hash(url->string); }
static wi_hash_code_t _wi_address_hash(wi_runtime_instance_t *instance) { wi_address_t *address = instance; return wi_hash(wi_address_string(address)); }