summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/Makefile2
-rw-r--r--test/basictests.c538
-rw-r--r--test/memorytests.c246
-rw-r--r--test/testmain.c2
4 files changed, 205 insertions, 583 deletions
diff --git a/test/Makefile b/test/Makefile
index 9ce2c1c..2ba343a 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -1,3 +1,3 @@
-DIR_TEST_ITEMS := testrunner:testmain.c;basictests.c;memorytests.c
+DIR_TEST_ITEMS := testrunner:testmain.c;basictests.c
include build/makefiles/Makefile.subdir
diff --git a/test/basictests.c b/test/basictests.c
index cedb0c3..210b82c 100644
--- a/test/basictests.c
+++ b/test/basictests.c
@@ -12,6 +12,10 @@
#include "tests.h"
+#ifndef UNUSED
+#define UNUSED(x) (void)(x)
+#endif
+
static void *last_pw = NULL;
static void *
trivial_alloc_fn(void *p, size_t s, void *pw)
@@ -22,383 +26,225 @@ trivial_alloc_fn(void *p, size_t s, void *pw)
#ifndef NDEBUG
/* All the basic assert() tests */
-START_TEST (test_lwc_context_creation_bad_alloc_aborts)
-{
- lwc_context *ctx = NULL;
- lwc_error err;
-
- err = lwc_create_context(NULL, NULL, &ctx);
-}
-END_TEST
-
-START_TEST (test_lwc_context_destruction_aborts)
-{
- lwc_context_unref(NULL);
-}
-END_TEST
-
-START_TEST (test_lwc_context_ref_aborts)
-{
- lwc_context_ref(NULL);
-}
-END_TEST
-
-START_TEST (test_lwc_context_unref_aborts)
-{
- lwc_context_unref(NULL);
-}
-END_TEST
-
-START_TEST (test_lwc_context_intern_aborts1)
-{
- lwc_context_intern(NULL, NULL, 0, NULL);
-}
-END_TEST
-
-START_TEST (test_lwc_context_intern_aborts2)
+START_TEST (test_lwc_intern_string_aborts1)
{
- lwc_context *ctx;
-
- fail_unless(lwc_create_context(trivial_alloc_fn, NULL, &ctx) == lwc_error_ok,
- "Unable to create context");
-
- lwc_context_intern(ctx, NULL, 0, NULL);
+ lwc_intern_string(NULL, 0, NULL);
}
END_TEST
-START_TEST (test_lwc_context_intern_aborts3)
+START_TEST (test_lwc_intern_string_aborts2)
{
- lwc_context *ctx;
-
- fail_unless(lwc_create_context(trivial_alloc_fn, NULL, &ctx) == lwc_error_ok,
- "Unable to create context");
-
- lwc_context_intern(ctx, "A", 1, NULL);
+ lwc_intern_string("A", 1, NULL);
}
END_TEST
-START_TEST (test_lwc_context_intern_substring_aborts1)
+START_TEST (test_lwc_intern_substring_aborts1)
{
- lwc_context_intern_substring(NULL, NULL, 0, 0, NULL);
+ lwc_intern_substring(NULL, 0, 0, NULL);
}
END_TEST
-START_TEST (test_lwc_context_intern_substring_aborts2)
+START_TEST (test_lwc_intern_substring_aborts2)
{
- lwc_context *ctx;
- fail_unless(lwc_create_context(trivial_alloc_fn, NULL, &ctx) == lwc_error_ok,
- "Unable to create context");
-
- lwc_context_intern_substring(ctx, NULL, 0, 0, NULL);
-}
-END_TEST
-
-START_TEST (test_lwc_context_intern_substring_aborts3)
-{
- lwc_context *ctx;
lwc_string *str;
- fail_unless(lwc_create_context(trivial_alloc_fn, NULL, &ctx) == lwc_error_ok,
- "Unable to create context");
- fail_unless(lwc_context_intern(ctx, "Jam", 3, &str) == lwc_error_ok,
+ fail_unless(lwc_initialise(trivial_alloc_fn, NULL, 0) == lwc_error_ok,
+ "unable to initialise the library");
+ fail_unless(lwc_intern_string("Jam", 3, &str) == lwc_error_ok,
"unable to intern 'Jam'");
- lwc_context_intern_substring(ctx, str, 100, 1, NULL);
+ lwc_intern_substring(str, 88, 77, NULL);
}
END_TEST
-START_TEST (test_lwc_context_intern_substring_aborts4)
+START_TEST (test_lwc_string_ref_aborts)
{
- lwc_context *ctx;
- lwc_string *str;
- fail_unless(lwc_create_context(trivial_alloc_fn, NULL, &ctx) == lwc_error_ok,
- "Unable to create context");
- fail_unless(lwc_context_intern(ctx, "Jam", 3, &str) == lwc_error_ok,
- "unable to intern 'Jam'");
-
- lwc_context_intern_substring(ctx, str, 1, 10, NULL);
+ lwc_string_ref(NULL);
}
END_TEST
-START_TEST (test_lwc_context_intern_substring_aborts5)
+START_TEST (test_lwc_string_unref_aborts)
{
- lwc_context *ctx;
- lwc_string *str;
- fail_unless(lwc_create_context(trivial_alloc_fn, NULL, &ctx) == lwc_error_ok,
- "Unable to create context");
- fail_unless(lwc_context_intern(ctx, "Jam", 3, &str) == lwc_error_ok,
- "unable to intern 'Jam'");
-
- lwc_context_intern_substring(ctx, str, 1, 2, NULL);
+ lwc_string_unref(NULL);
}
END_TEST
-START_TEST (test_lwc_context_string_ref_aborts1)
+START_TEST (test_lwc_string_data_aborts)
{
- lwc_context_string_ref(NULL, NULL);
+ lwc_string_data(NULL);
}
END_TEST
-START_TEST (test_lwc_context_string_ref_aborts2)
+START_TEST (test_lwc_string_length_aborts)
{
- lwc_context *ctx;
- fail_unless(lwc_create_context(trivial_alloc_fn, NULL, &ctx) == lwc_error_ok,
- "Unable to create context");
- lwc_context_string_ref(ctx, NULL);
+ lwc_string_length(NULL);
}
END_TEST
-START_TEST (test_lwc_context_string_unref_aborts1)
+START_TEST (test_lwc_string_hash_value_aborts)
{
- lwc_context_string_unref(NULL, NULL);
+ lwc_string_hash_value(NULL);
}
END_TEST
-START_TEST (test_lwc_context_string_unref_aborts2)
-{
- lwc_context *ctx;
- fail_unless(lwc_create_context(trivial_alloc_fn, NULL, &ctx) == lwc_error_ok,
- "Unable to create context");
- lwc_context_string_unref(ctx, NULL);
-}
-END_TEST
+#endif
-START_TEST (test_lwc_string_data_aborts)
+START_TEST (test_lwc_double_initialise_fails)
{
- lwc_string_data(NULL);
+ fail_unless(lwc_initialise(trivial_alloc_fn, NULL, 0) == lwc_error_ok,
+ "Unable to initialise library");
+ fail_unless(lwc_initialise(trivial_alloc_fn, NULL, 0) == lwc_error_initialised,
+ "Able to initialise library a second time");
}
END_TEST
-START_TEST (test_lwc_string_length_aborts)
+static void *enomem_allocator(void *ptr, size_t n, void *pw)
{
- lwc_string_length(NULL);
+ int *pi = (int*)pw;
+ UNUSED(ptr);
+ UNUSED(n);
+
+ if (*pi > 0) {
+ *pi -= 1;
+ return realloc(ptr, n);
+ }
+
+ return NULL;
}
-END_TEST
-START_TEST (test_lwc_string_hash_value_aborts)
+START_TEST (test_lwc_initialise_fails_with_no_memory)
{
- lwc_string_hash_value(NULL);
+ int permitted = 0;
+ fail_unless(lwc_initialise(enomem_allocator, &permitted, 0) == lwc_error_oom,
+ "Able to initialise library with no memory available?!");
}
END_TEST
-START_TEST (test_lwc_context_size_aborts)
+START_TEST (test_lwc_initialise_fails_with_low_memory)
{
- lwc_context_size(NULL);
+ int permitted = 1;
+ fail_unless(lwc_initialise(enomem_allocator, &permitted, 0) == lwc_error_oom,
+ "Able to initialise library with no memory available?!");
}
END_TEST
-#endif
-
-START_TEST (test_lwc_context_creation_ok)
+START_TEST (test_lwc_intern_fails_with_no_memory)
{
- lwc_context *ctx = NULL;
- lwc_error err;
+ int permitted = 2; /* context and buckets */
+ lwc_string *str;
+
+ fail_unless(lwc_initialise(enomem_allocator, &permitted, 0) == lwc_error_ok,
+ "Unable to initialise library");
+ fail_unless(lwc_intern_string("Hello", 5, &str) == lwc_error_oom,
+ "Able to allocate string despite enomem.");
- err = lwc_create_context(trivial_alloc_fn, NULL, &ctx);
- fail_unless(ctx != NULL,
- "Unable to create context");
- fail_unless(err == lwc_error_ok,
- "Created context but returned !ok");
}
END_TEST
-START_TEST (test_lwc_context_destruction_ok)
+START_TEST (test_lwc_caseless_compare_fails_with_no_memory1)
{
- lwc_context *ctx = NULL;
+ int permitted = 3; /* ctx, buckets, 1 string */
+ lwc_string *str;
+ bool result = true;
- fail_unless(lwc_create_context(trivial_alloc_fn, NULL, &ctx) == lwc_error_ok,
- "Unable to create context");
+ fail_unless(lwc_initialise(enomem_allocator, &permitted, 0) == lwc_error_ok,
+ "Unable to initialise library");
+ fail_unless(lwc_intern_string("Hello", 5, &str) == lwc_error_ok,
+ "Unable to allocate string.");
+ fail_unless(lwc_string_caseless_isequal(str, str, &result) == lwc_error_oom,
+ "Able to caselessly compare despite no memory");
- lwc_context_unref(ctx);
}
END_TEST
-START_TEST (test_lwc_reffed_context_destruction_ok)
+START_TEST (test_lwc_caseless_compare_fails_with_no_memory2)
{
- lwc_context *ctx = NULL;
-
- fail_unless(lwc_create_context(trivial_alloc_fn, NULL, &ctx) == lwc_error_ok,
- "Unable to create context");
+ int permitted = 5; /* ctx, buckets, 3 strings */
+ lwc_string *str1, *str2;
+ bool result = true;
- lwc_context_ref(ctx); /* make the weak ref strong */
+ fail_unless(lwc_initialise(enomem_allocator, &permitted, 0) == lwc_error_ok,
+ "Unable to initialise library");
+ fail_unless(lwc_intern_string("Hello", 5, &str1) == lwc_error_ok,
+ "Unable to allocate string.");
+ fail_unless(lwc_intern_string("World", 5, &str2) == lwc_error_ok,
+ "Unable to allocate string.");
+ fail_unless(lwc_string_caseless_isequal(str1, str2, &result) == lwc_error_oom,
+ "Able to caselessly compare despite no memory");
- lwc_context_unref(ctx);
}
END_TEST
/**** The next set of tests need a fixture set ****/
-static lwc_context *shared_ctx;
-
static void
with_simple_context_setup(void)
{
- fail_unless(lwc_create_context(trivial_alloc_fn, NULL,
- &shared_ctx) == lwc_error_ok,
- "Unable to create context");
- lwc_context_ref(shared_ctx);
+ fail_unless(lwc_initialise(trivial_alloc_fn, NULL, 0) == lwc_error_ok,
+ "Unable to initialise library");
}
static void
with_simple_context_teardown(void)
{
- lwc_context_unref(shared_ctx);
+ /* Nothing to do to tear down */
}
-START_TEST (test_lwc_context_intern_ok)
+START_TEST (test_lwc_intern_string_ok)
{
lwc_string *str = NULL;
- fail_unless(lwc_context_intern(shared_ctx, "A", 1, &str) == lwc_error_ok,
+ fail_unless(lwc_intern_string("A", 1, &str) == lwc_error_ok,
"Unable to intern a simple string");
fail_unless(str != NULL,
"Returned OK but str was still NULL");
}
END_TEST
-START_TEST (test_lwc_context_intern_twice_ok)
+START_TEST (test_lwc_intern_string_twice_ok)
{
lwc_string *str1 = NULL, *str2 = NULL;
- fail_unless(lwc_context_intern(shared_ctx, "A", 1, &str1) == lwc_error_ok,
+ fail_unless(lwc_intern_string("A", 1, &str1) == lwc_error_ok,
"Unable to intern a simple string");
fail_unless(str1 != NULL,
"Returned OK but str was still NULL");
- fail_unless(lwc_context_intern(shared_ctx, "B", 1, &str2) == lwc_error_ok,
+ fail_unless(lwc_intern_string("B", 1, &str2) == lwc_error_ok,
"Unable to intern a simple string");
fail_unless(str2 != NULL,
"Returned OK but str was still NULL");
}
END_TEST
-START_TEST (test_lwc_context_intern_twice_same_ok)
+START_TEST (test_lwc_intern_string_twice_same_ok)
{
lwc_string *str1 = NULL, *str2 = NULL;
- fail_unless(lwc_context_intern(shared_ctx, "A", 1, &str1) == lwc_error_ok,
+ fail_unless(lwc_intern_string("A", 1, &str1) == lwc_error_ok,
"Unable to intern a simple string");
fail_unless(str1 != NULL,
"Returned OK but str was still NULL");
- fail_unless(lwc_context_intern(shared_ctx, "A", 1, &str2) == lwc_error_ok,
+ fail_unless(lwc_intern_string("A", 1, &str2) == lwc_error_ok,
"Unable to intern a simple string");
fail_unless(str2 != NULL,
"Returned OK but str was still NULL");
}
END_TEST
-START_TEST (test_lwc_context_size_non_zero)
-{
- fail_unless(lwc_context_size(shared_ctx) > 0,
- "Size of empty context is zero");
-}
-END_TEST
-
-START_TEST (test_lwc_context_size_updated_on_string_intern)
-{
- size_t empty_size = lwc_context_size(shared_ctx);
- lwc_string *str;
-
- fail_unless(empty_size > 0,
- "Size of empty context is zero");
-
- fail_unless(lwc_context_intern(shared_ctx, "one", 3, &str) == lwc_error_ok,
- "Unable to intern a simple string");
-
- fail_unless(lwc_context_size(shared_ctx) > empty_size,
- "Post-intern context size is same or smaller than empty size");
-}
-END_TEST
-
-START_TEST (test_lwc_context_size_updated_on_string_unref)
-{
- size_t empty_size = lwc_context_size(shared_ctx);
- lwc_string *str;
-
- fail_unless(empty_size > 0,
- "Size of empty context is zero");
-
- fail_unless(lwc_context_intern(shared_ctx, "one", 3, &str) == lwc_error_ok,
- "Unable to intern a simple string");
-
- fail_unless(lwc_context_size(shared_ctx) > empty_size,
- "Post-intern context size is same or smaller than empty size");
-
- lwc_context_string_unref(shared_ctx, str);
-
- fail_unless(lwc_context_size(shared_ctx) == empty_size,
- "Post-unref context size is not the same as empty size");
-}
-END_TEST
-
-START_TEST (test_lwc_context_size_updated_on_substring_intern)
-{
- size_t empty_size = lwc_context_size(shared_ctx);
- size_t post_intern_size = 0;
- lwc_string *str, *str2;
-
- fail_unless(empty_size > 0,
- "Size of empty context is zero");
-
- fail_unless(lwc_context_intern(shared_ctx, "one", 3, &str) == lwc_error_ok,
- "Unable to intern a simple string");
-
- post_intern_size = lwc_context_size(shared_ctx);
-
- fail_unless(post_intern_size > empty_size,
- "Post-intern context size is same or smaller than empty size");
-
- fail_unless(lwc_context_intern_substring(shared_ctx, str, 0, 1, &str2) == lwc_error_ok,
- "Failed to intern substring");
-
- fail_unless(lwc_context_size(shared_ctx) > post_intern_size,
- "Post-substring-intern context size is same or smaller than pre-substring-intern size");
-}
-END_TEST
-
-START_TEST (test_lwc_context_size_updated_on_substring_unref)
-{
- size_t empty_size = lwc_context_size(shared_ctx);
- size_t post_intern_size = 0;
- lwc_string *str, *str2;
-
- fail_unless(empty_size > 0,
- "Size of empty context is zero");
-
- fail_unless(lwc_context_intern(shared_ctx, "one", 3, &str) == lwc_error_ok,
- "Unable to intern a simple string");
-
- post_intern_size = lwc_context_size(shared_ctx);
-
- fail_unless(post_intern_size > empty_size,
- "Post-intern context size is same or smaller than empty size");
-
- fail_unless(lwc_context_intern_substring(shared_ctx, str, 0, 1, &str2) == lwc_error_ok,
- "Failed to intern substring");
-
- fail_unless(lwc_context_size(shared_ctx) > post_intern_size,
- "Post-substring-intern context size is same or smaller than pre-substring-intern size");
-
- lwc_context_string_unref(shared_ctx, str2);
-
- fail_unless(lwc_context_size(shared_ctx) == post_intern_size,
- "Post-substring-unref size is not the same as pre-substring-intern size");
-}
-END_TEST
-
/**** The next set of tests need a fixture set with some strings ****/
-static lwc_string *intern_one = NULL, *intern_two = NULL, *intern_three = NULL;
+static lwc_string *intern_one = NULL, *intern_two = NULL, *intern_three = NULL, *intern_YAY = NULL;
static void
with_filled_context_setup(void)
{
- fail_unless(lwc_create_context(trivial_alloc_fn, NULL,
- &shared_ctx) == lwc_error_ok,
- "Unable to create context");
- lwc_context_ref(shared_ctx);
+ fail_unless(lwc_initialise(trivial_alloc_fn, NULL, 2) == lwc_error_ok,
+ "Unable to initialise library");
- fail_unless(lwc_context_intern(shared_ctx, "one", 3, &intern_one) == lwc_error_ok,
- "Unable to intern 'one'");
- fail_unless(lwc_context_intern(shared_ctx, "two", 3, &intern_two) == lwc_error_ok,
- "Unable to intern 'one'");
- fail_unless(lwc_context_intern(shared_ctx, "three", 5, &intern_three) == lwc_error_ok,
+ fail_unless(lwc_intern_string("one", 3, &intern_one) == lwc_error_ok,
"Unable to intern 'one'");
+ fail_unless(lwc_intern_string("two", 3, &intern_two) == lwc_error_ok,
+ "Unable to intern 'two'");
+ fail_unless(lwc_intern_string("three", 5, &intern_three) == lwc_error_ok,
+ "Unable to intern 'three'");
+ fail_unless(lwc_intern_string("YAY", 3, &intern_YAY) == lwc_error_ok,
+ "Unable to intern 'YAY'");
fail_unless(intern_one != intern_two, "'one' == 'two'");
fail_unless(intern_one != intern_three, "'one' == 'three'");
@@ -408,14 +254,17 @@ with_filled_context_setup(void)
static void
with_filled_context_teardown(void)
{
- lwc_context_unref(shared_ctx);
+ lwc_string_unref(intern_one);
+ lwc_string_unref(intern_two);
+ lwc_string_unref(intern_three);
+ lwc_string_unref(intern_YAY);
}
START_TEST (test_lwc_interning_works)
{
lwc_string *new_one = NULL;
- fail_unless(lwc_context_intern(shared_ctx, "one", 3, &new_one) == lwc_error_ok,
+ fail_unless(lwc_intern_string("one", 3, &new_one) == lwc_error_ok,
"Unable to re-intern 'one'");
fail_unless(new_one == intern_one,
@@ -427,62 +276,113 @@ START_TEST (test_lwc_intern_substring)
{
lwc_string *new_hre = NULL, *sub_hre = NULL;
- fail_unless(lwc_context_intern(shared_ctx, "hre", 3,
- &new_hre) == lwc_error_ok,
+ fail_unless(lwc_intern_string("hre", 3, &new_hre) == lwc_error_ok,
"Unable to intern 'hre'");
- fail_unless(lwc_context_intern_substring(shared_ctx, intern_three,
- 1, 3, &sub_hre) == lwc_error_ok,
+ fail_unless(lwc_intern_substring(intern_three,
+ 1, 3, &sub_hre) == lwc_error_ok,
"Unable to re-intern 'hre' by substring");
fail_unless(new_hre == sub_hre,
"'hre' != 'hre' -- wow!");
}
END_TEST
-START_TEST (test_lwc_context_string_ref_ok)
+START_TEST (test_lwc_intern_substring_bad_offset)
{
- fail_unless(lwc_context_string_ref(shared_ctx, intern_one) == intern_one,
+ lwc_string *str;
+
+ fail_unless(lwc_intern_substring(intern_three, 100, 1, &str) == lwc_error_range,
+ "Able to intern substring starting out of range");
+}
+END_TEST
+
+START_TEST (test_lwc_intern_substring_bad_size)
+{
+ lwc_string *str;
+
+ fail_unless(lwc_intern_substring(intern_three, 1, 100, &str) == lwc_error_range,
+ "Able to intern substring ending out of range");
+}
+END_TEST
+
+START_TEST (test_lwc_string_ref_ok)
+{
+ fail_unless(lwc_string_ref(intern_one) == intern_one,
"Oddly, reffing a string didn't return it");
}
END_TEST
-START_TEST (test_lwc_context_string_unref_ok)
+START_TEST (test_lwc_string_unref_ok)
+{
+ lwc_string_unref(intern_one);
+}
+END_TEST
+
+START_TEST (test_lwc_string_ref_unref_ok)
{
- lwc_context_string_unref(shared_ctx, intern_one);
+ lwc_string_ref(intern_one);
+ lwc_string_unref(intern_one);
}
END_TEST
-START_TEST (test_lwc_context_string_isequal_ok)
+START_TEST (test_lwc_string_isequal_ok)
{
bool result = true;
- fail_unless((lwc_context_string_isequal(shared_ctx, intern_one,
- intern_two, &result)) == lwc_error_ok,
+ fail_unless((lwc_string_isequal(intern_one, intern_two, &result)) == lwc_error_ok,
"Failure comparing 'one' and 'two'");
fail_unless(result == false,
"'one' == 'two' ?!");
}
END_TEST
-START_TEST (test_lwc_context_string_caseless_isequal_ok)
+START_TEST (test_lwc_string_caseless_isequal_ok1)
{
bool result = true;
lwc_string *new_ONE;
- fail_unless(lwc_context_intern(shared_ctx, "ONE", 3, &new_ONE) == lwc_error_ok,
+ fail_unless(lwc_intern_string("ONE", 3, &new_ONE) == lwc_error_ok,
"Failure interning 'ONE'");
- fail_unless((lwc_context_string_isequal(shared_ctx, intern_one, new_ONE,
- &result)) == lwc_error_ok);
+ fail_unless((lwc_string_isequal(intern_one, new_ONE, &result)) == lwc_error_ok);
fail_unless(result == false,
"'one' == 'ONE' ?!");
- fail_unless((lwc_context_string_caseless_isequal(shared_ctx, intern_one,
- new_ONE, &result)) == lwc_error_ok,
- "Failure comparing 'one' and 'two'");
+ fail_unless((lwc_string_caseless_isequal(intern_one, new_ONE, &result)) == lwc_error_ok,
+ "Failure comparing 'one' and 'ONE' caselessly");
fail_unless(result == true,
"'one' !~= 'ONE' ?!");
}
END_TEST
+START_TEST (test_lwc_string_caseless_isequal_ok2)
+{
+ bool result = true;
+ lwc_string *new_yay;
+
+ fail_unless(lwc_intern_string("yay", 3, &new_yay) == lwc_error_ok,
+ "Failure interning 'yay'");
+
+ fail_unless((lwc_string_isequal(intern_YAY, new_yay, &result)) == lwc_error_ok);
+ fail_unless(result == false,
+ "'yay' == 'YAY' ?!");
+
+ fail_unless((lwc_string_caseless_isequal(intern_YAY, new_yay, &result)) == lwc_error_ok,
+ "Failure comparing 'yay' and 'YAY' caselessly");
+ fail_unless(result == true,
+ "'yay' !~= 'YAY' ?!");
+}
+END_TEST
+
+START_TEST (test_lwc_string_caseless_isequal_bad)
+{
+ bool result = true;
+
+ fail_unless(lwc_string_caseless_isequal(intern_YAY, intern_one, &result) == lwc_error_ok,
+ "Failure comparing 'YAY' and 'one' caselessly");
+ fail_unless(result == false,
+ "'YAY' ~= 'one' ?!");
+}
+END_TEST
+
START_TEST (test_lwc_extract_data_ok)
{
fail_unless(memcmp("one",
@@ -502,7 +402,7 @@ START_TEST (test_lwc_string_is_nul_terminated)
{
lwc_string *new_ONE;
- fail_unless(lwc_context_intern(shared_ctx, "ONE", 3, &new_ONE) == lwc_error_ok,
+ fail_unless(lwc_intern_string("ONE", 3, &new_ONE) == lwc_error_ok,
"Failure interning 'ONE'");
fail_unless(lwc_string_data(new_ONE)[lwc_string_length(new_ONE)] == '\0',
@@ -515,10 +415,10 @@ START_TEST (test_lwc_substring_is_nul_terminated)
lwc_string *new_ONE;
lwc_string *new_O;
- fail_unless(lwc_context_intern(shared_ctx, "ONE", 3, &new_ONE) == lwc_error_ok,
+ fail_unless(lwc_intern_string("ONE", 3, &new_ONE) == lwc_error_ok,
"Failure interning 'ONE'");
- fail_unless(lwc_context_intern_substring(shared_ctx, new_ONE, 0, 1, &new_O) == lwc_error_ok,
+ fail_unless(lwc_intern_substring(new_ONE, 0, 1, &new_O) == lwc_error_ok,
"Failure interning substring 'O'");
fail_unless(lwc_string_data(new_O)[lwc_string_length(new_O)] == '\0',
@@ -536,52 +436,22 @@ lwc_basic_suite(SRunner *sr)
#ifndef NDEBUG
tcase_add_test_raise_signal(tc_basic,
- test_lwc_context_creation_bad_alloc_aborts,
- SIGABRT);
- tcase_add_test_raise_signal(tc_basic,
- test_lwc_context_destruction_aborts,
+ test_lwc_intern_string_aborts1,
SIGABRT);
tcase_add_test_raise_signal(tc_basic,
- test_lwc_context_ref_aborts,
+ test_lwc_intern_string_aborts2,
SIGABRT);
tcase_add_test_raise_signal(tc_basic,
- test_lwc_context_unref_aborts,
+ test_lwc_intern_substring_aborts1,
SIGABRT);
tcase_add_test_raise_signal(tc_basic,
- test_lwc_context_intern_aborts1,
+ test_lwc_intern_substring_aborts2,
SIGABRT);
tcase_add_test_raise_signal(tc_basic,
- test_lwc_context_intern_aborts2,
+ test_lwc_string_ref_aborts,
SIGABRT);
tcase_add_test_raise_signal(tc_basic,
- test_lwc_context_intern_aborts3,
- SIGABRT);
- tcase_add_test_raise_signal(tc_basic,
- test_lwc_context_intern_substring_aborts1,
- SIGABRT);
- tcase_add_test_raise_signal(tc_basic,
- test_lwc_context_intern_substring_aborts2,
- SIGABRT);
- tcase_add_test_raise_signal(tc_basic,
- test_lwc_context_intern_substring_aborts3,
- SIGABRT);
- tcase_add_test_raise_signal(tc_basic,
- test_lwc_context_intern_substring_aborts4,
- SIGABRT);
- tcase_add_test_raise_signal(tc_basic,
- test_lwc_context_intern_substring_aborts5,
- SIGABRT);
- tcase_add_test_raise_signal(tc_basic,
- test_lwc_context_string_ref_aborts1,
- SIGABRT);
- tcase_add_test_raise_signal(tc_basic,
- test_lwc_context_string_ref_aborts2,
- SIGABRT);
- tcase_add_test_raise_signal(tc_basic,
- test_lwc_context_string_unref_aborts1,
- SIGABRT);
- tcase_add_test_raise_signal(tc_basic,
- test_lwc_context_string_unref_aborts2,
+ test_lwc_string_unref_aborts,
SIGABRT);
tcase_add_test_raise_signal(tc_basic,
test_lwc_string_data_aborts,
@@ -592,31 +462,24 @@ lwc_basic_suite(SRunner *sr)
tcase_add_test_raise_signal(tc_basic,
test_lwc_string_hash_value_aborts,
SIGABRT);
- tcase_add_test_raise_signal(tc_basic,
- test_lwc_context_size_aborts,
- SIGABRT);
#endif
- tcase_add_test(tc_basic, test_lwc_context_creation_ok);
- tcase_add_test(tc_basic, test_lwc_context_destruction_ok);
- tcase_add_test(tc_basic, test_lwc_reffed_context_destruction_ok);
+ tcase_add_test(tc_basic, test_lwc_double_initialise_fails);
+ tcase_add_test(tc_basic, test_lwc_initialise_fails_with_no_memory);
+ tcase_add_test(tc_basic, test_lwc_initialise_fails_with_low_memory);
+ tcase_add_test(tc_basic, test_lwc_intern_fails_with_no_memory);
+ tcase_add_test(tc_basic, test_lwc_caseless_compare_fails_with_no_memory1);
+ tcase_add_test(tc_basic, test_lwc_caseless_compare_fails_with_no_memory2);
+
suite_add_tcase(s, tc_basic);
tc_basic = tcase_create("Ops with a context");
tcase_add_checked_fixture(tc_basic, with_simple_context_setup,
with_simple_context_teardown);
- tcase_add_test(tc_basic, test_lwc_context_intern_ok);
- tcase_add_test(tc_basic, test_lwc_context_intern_twice_ok);
- tcase_add_test(tc_basic, test_lwc_context_intern_twice_same_ok);
- tcase_add_test(tc_basic, test_lwc_context_size_non_zero);
- tcase_add_test(tc_basic,
- test_lwc_context_size_updated_on_string_intern);
- tcase_add_test(tc_basic, test_lwc_context_size_updated_on_string_unref);
- tcase_add_test(tc_basic,
- test_lwc_context_size_updated_on_substring_intern);
- tcase_add_test(tc_basic,
- test_lwc_context_size_updated_on_substring_unref);
+ tcase_add_test(tc_basic, test_lwc_intern_string_ok);
+ tcase_add_test(tc_basic, test_lwc_intern_string_twice_ok);
+ tcase_add_test(tc_basic, test_lwc_intern_string_twice_same_ok);
suite_add_tcase(s, tc_basic);
tc_basic = tcase_create("Ops with a filled context");
@@ -625,14 +488,19 @@ lwc_basic_suite(SRunner *sr)
with_filled_context_teardown);
tcase_add_test(tc_basic, test_lwc_interning_works);
tcase_add_test(tc_basic, test_lwc_intern_substring);
- tcase_add_test(tc_basic, test_lwc_context_string_ref_ok);
- tcase_add_test(tc_basic, test_lwc_context_string_unref_ok);
- tcase_add_test(tc_basic, test_lwc_context_string_isequal_ok);
- tcase_add_test(tc_basic, test_lwc_context_string_caseless_isequal_ok);
+ tcase_add_test(tc_basic, test_lwc_string_ref_ok);
+ tcase_add_test(tc_basic, test_lwc_string_ref_unref_ok);
+ tcase_add_test(tc_basic, test_lwc_string_unref_ok);
+ tcase_add_test(tc_basic, test_lwc_string_isequal_ok);
+ tcase_add_test(tc_basic, test_lwc_string_caseless_isequal_ok1);
+ tcase_add_test(tc_basic, test_lwc_string_caseless_isequal_ok2);
+ tcase_add_test(tc_basic, test_lwc_string_caseless_isequal_bad);
tcase_add_test(tc_basic, test_lwc_extract_data_ok);
tcase_add_test(tc_basic, test_lwc_string_hash_value_ok);
tcase_add_test(tc_basic, test_lwc_string_is_nul_terminated);
tcase_add_test(tc_basic, test_lwc_substring_is_nul_terminated);
+ tcase_add_test(tc_basic, test_lwc_intern_substring_bad_size);
+ tcase_add_test(tc_basic, test_lwc_intern_substring_bad_offset);
suite_add_tcase(s, tc_basic);
srunner_add_suite(sr, s);
diff --git a/test/memorytests.c b/test/memorytests.c
deleted file mode 100644
index 7c55cce..0000000
--- a/test/memorytests.c
+++ /dev/null
@@ -1,246 +0,0 @@
-/* test/basictests.c
- *
- * Basic tests for the test suite for libwapcaplet
- *
- * Copyright 2009 The NetSurf Browser Project
- * Daniel Silverstone <dsilvers@netsurf-browser.org>
- */
-
-#include <check.h>
-#include <stdlib.h>
-
-#include "tests.h"
-
-/**** Simple tracking allocator ****/
-
-typedef enum {
- NONE, ALLOC, FREE
-} alloc_op;
-
-static unsigned long bytes = 0;
-static unsigned long allocs = 0;
-static void *last_pw = NULL;
-static alloc_op last_op = NONE;
-
-static void *
-tracking_allocator(void *ptr, size_t len, void *pw)
-{
- void *ret;
- last_pw = pw;
- if (ptr == NULL) {
- last_op = ALLOC;
- bytes += len;
- allocs++;
- ret = malloc(len + sizeof(size_t));
- *(size_t *)ret = len;
- return ((char *) ret) + sizeof(size_t);
- }
- last_op = FREE;
- allocs--;
- bytes -= *(((size_t *)ptr) - 1);
- free((((size_t *)ptr) - 1));
- return NULL;
-}
-
-static lwc_context *ctx = NULL;
-
-static void
-with_tracked_alloc_setup(void)
-{
- fail_unless(lwc_create_context(tracking_allocator, NULL, &ctx) == lwc_error_ok,
- "Unable to create context");
- fail_unless(allocs == 1,
- "Creating a context used more than one alloc?");
- fail_unless(lwc_context_ref(ctx) == ctx,
- "Reffing the context failed to return the context.");
-}
-
-static void
-with_tracked_alloc_teardown(void)
-{
- lwc_context_unref(ctx);
- fail_unless(allocs == 0,
- "Unreffing the context failed to free everything left.");
-}
-
-START_TEST (test_tracking_one_intern)
-{
- lwc_string *str;
- fail_unless(lwc_context_intern(ctx, "one", 3, &str) == lwc_error_ok,
- "Unable to intern 'one'");
- fail_unless(allocs == 2,
- "Interning a string into a fresh context didn't.");
-}
-END_TEST
-
-START_TEST (test_tracking_one_intern_twice)
-{
- lwc_string *str;
- fail_unless(lwc_context_intern(ctx, "one", 3, &str) == lwc_error_ok,
- "Unable to intern 'one'");
- fail_unless(allocs == 2,
- "Interning a string into a fresh context didn't.");
- fail_unless(lwc_context_intern(ctx, "one", 3, &str) == lwc_error_ok,
- "Unable to intern 'one' again");
- fail_unless(allocs == 2,
- "Interning a string again still did.");
-}
-END_TEST
-
-START_TEST (test_tracking_two_interns)
-{
- lwc_string *one, *ONE;
- fail_unless(lwc_context_intern(ctx, "one", 3, &one) == lwc_error_ok,
- "Unable to intern 'one'");
- fail_unless(allocs == 2,
- "Interning a string into a fresh context didn't.");
- fail_unless(lwc_context_intern(ctx, "ONE", 3, &ONE) == lwc_error_ok,
- "Unable to intern 'one' again");
- fail_unless(allocs == 3,
- "Interning a new string didn't.");
-}
-END_TEST
-
-START_TEST (test_tracking_two_interns_caseless1)
-{
- lwc_string *one, *ONE;
- bool comp = false;
- fail_unless(lwc_context_intern(ctx, "one", 3, &one) == lwc_error_ok,
- "Unable to intern 'one'");
- fail_unless(allocs == 2,
- "Interning a string into a fresh context didn't.");
- fail_unless(lwc_context_intern(ctx, "ONE", 3, &ONE) == lwc_error_ok,
- "Unable to intern 'ONE'");
- fail_unless(allocs == 3,
- "Interning a new string didn't.");
- fail_unless(lwc_context_string_caseless_isequal(ctx, one, ONE, &comp) == lwc_error_ok,
- "Unable to caseless compare");
- fail_unless(allocs == 3,
- "Caseless compare created worthless new values");
- fail_unless(comp == true,
- "Caseless compare failed to spot that 'one' and 'ONE' are the same");
-}
-END_TEST
-
-START_TEST (test_tracking_two_interns_caseless2)
-{
- lwc_string *one, *ONE;
- bool comp = false;
- fail_unless(lwc_context_intern(ctx, "oNe", 3, &one) == lwc_error_ok,
- "Unable to intern 'oNe'");
- fail_unless(allocs == 2,
- "Interning a string into a fresh context didn't.");
- fail_unless(lwc_context_intern(ctx, "ONE", 3, &ONE) == lwc_error_ok,
- "Unable to intern 'ONE'");
- fail_unless(allocs == 3,
- "Interning a new string didn't.");
- fail_unless(lwc_context_string_caseless_isequal(ctx, one, ONE, &comp) == lwc_error_ok,
- "Unable to caseless compare");
- fail_unless(allocs == 4,
- "Caseless compare didn't make one caseless 'one'");
- fail_unless(comp == true,
- "Caseless compare failed to spot that 'oNe' and 'ONE' are the same");
-}
-END_TEST
-
-START_TEST (test_tracking_caseless_unref1)
-{
- lwc_string *one, *ONE;
- bool comp = false;
- fail_unless(lwc_context_intern(ctx, "one", 3, &one) == lwc_error_ok,
- "Unable to intern 'one'");
- fail_unless(allocs == 2,
- "Interning a string into a fresh context didn't.");
- fail_unless(lwc_context_intern(ctx, "ONE", 3, &ONE) == lwc_error_ok,
- "Unable to intern 'ONE'");
- fail_unless(allocs == 3,
- "Interning a new string didn't.");
- fail_unless(lwc_context_string_caseless_isequal(ctx, one, ONE, &comp) == lwc_error_ok,
- "Unable to caseless compare");
- fail_unless(allocs == 3,
- "Caseless compare made pointless additional 'one'");
- fail_unless(comp == true,
- "Caseless compare failed to spot that 'oNe' and 'ONE' are the same");
-
- lwc_context_string_unref(ctx, ONE);
- fail_unless(allocs == 2, "Unreffing 'ONE' failed to free something");
-}
-END_TEST
-
-START_TEST (test_tracking_caseless_unref2)
-{
- lwc_string *one, *ONE;
- bool comp = false;
- fail_unless(lwc_context_intern(ctx, "one", 3, &one) == lwc_error_ok,
- "Unable to intern 'one'");
- fail_unless(allocs == 2,
- "Interning a string into a fresh context didn't.");
- fail_unless(lwc_context_intern(ctx, "ONE", 3, &ONE) == lwc_error_ok,
- "Unable to intern 'ONE'");
- fail_unless(allocs == 3,
- "Interning a new string didn't.");
- fail_unless(lwc_context_string_caseless_isequal(ctx, one, ONE, &comp) == lwc_error_ok,
- "Unable to caseless compare");
- fail_unless(allocs == 3,
- "Caseless compare made pointless additional 'one'");
- fail_unless(comp == true,
- "Caseless compare failed to spot that 'oNe' and 'ONE' are the same");
-
- lwc_context_string_unref(ctx, ONE);
- fail_unless(allocs == 2, "Unreffing 'ONE' failed to free something");
-
- lwc_context_string_unref(ctx, one);
- fail_unless(allocs == 1, "Unreffing 'one' failed to free something");
-}
-END_TEST
-
-START_TEST (test_tracking_caseless_unref3)
-{
- lwc_string *one, *ONE;
- bool comp = false;
- fail_unless(lwc_context_intern(ctx, "one", 3, &one) == lwc_error_ok,
- "Unable to intern 'one'");
- fail_unless(allocs == 2,
- "Interning a string into a fresh context didn't.");
- fail_unless(lwc_context_intern(ctx, "ONE", 3, &ONE) == lwc_error_ok,
- "Unable to intern 'ONE'");
- fail_unless(allocs == 3,
- "Interning a new string didn't.");
- fail_unless(lwc_context_string_caseless_isequal(ctx, one, ONE, &comp) == lwc_error_ok,
- "Unable to caseless compare");
- fail_unless(allocs == 3,
- "Caseless compare made pointless additional 'one'");
- fail_unless(comp == true,
- "Caseless compare failed to spot that 'oNe' and 'ONE' are the same");
-
- lwc_context_string_unref(ctx, one);
- fail_unless(allocs == 3, "Unreffing 'one' freed something");
-
- lwc_context_string_unref(ctx, ONE);
- fail_unless(allocs == 1, "Unreffing 'ONE' failed to free both things");
-}
-END_TEST
-
-/**** And the suites are set up here ****/
-
-void
-lwc_memory_suite(SRunner *sr)
-{
- Suite *s = suite_create("libwapcaplet: Memory allocation tests");
- TCase *tc_mem = tcase_create("memory");
-
- tcase_add_checked_fixture(tc_mem, with_tracked_alloc_setup,
- with_tracked_alloc_teardown);
-
- tcase_add_test(tc_mem, test_tracking_one_intern);
- tcase_add_test(tc_mem, test_tracking_one_intern_twice);
- tcase_add_test(tc_mem, test_tracking_two_interns);
- tcase_add_test(tc_mem, test_tracking_two_interns_caseless1);
- tcase_add_test(tc_mem, test_tracking_two_interns_caseless2);
- tcase_add_test(tc_mem, test_tracking_caseless_unref1);
- tcase_add_test(tc_mem, test_tracking_caseless_unref2);
- tcase_add_test(tc_mem, test_tracking_caseless_unref3);
-
- suite_add_tcase(s, tc_mem);
- srunner_add_suite(sr, s);
-}
diff --git a/test/testmain.c b/test/testmain.c
index 7c5aee9..95fd6d2 100644
--- a/test/testmain.c
+++ b/test/testmain.c
@@ -31,7 +31,7 @@ main(int argc, char **argv)
sr = srunner_create(suite_create("Test suite for libwapcaplet"));
lwc_basic_suite(sr);
- lwc_memory_suite(sr);
+// lwc_memory_suite(sr);
srunner_set_fork_status(sr, CK_FORK);
srunner_run_all(sr, CK_ENV);