summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@netsurf-browser.org>2009-02-14 18:24:45 (GMT)
committer Daniel Silverstone <dsilvers@netsurf-browser.org>2009-02-14 18:24:45 (GMT)
commit50bdb0bb5577944a150dfae5cd6a6a47cbf30b1c (patch)
treec9cecf2a43c19e4d053b52302166ae34b3860638
parente091800dd4e21e7bd612aebdacae8f2029acdc1e (diff)
downloadlibwapcaplet-50bdb0bb5577944a150dfae5cd6a6a47cbf30b1c.tar.gz
libwapcaplet-50bdb0bb5577944a150dfae5cd6a6a47cbf30b1c.tar.bz2
Add simple accessors for data and length
svn path=/trunk/libwapcaplet/; revision=6509
-rw-r--r--include/libwapcaplet/libwapcaplet.h16
-rw-r--r--src/libwapcaplet.c18
-rw-r--r--test/basictests.c29
3 files changed, 63 insertions, 0 deletions
diff --git a/include/libwapcaplet/libwapcaplet.h b/include/libwapcaplet/libwapcaplet.h
index ded5d58..c3b99ea 100644
--- a/include/libwapcaplet/libwapcaplet.h
+++ b/include/libwapcaplet/libwapcaplet.h
@@ -110,5 +110,21 @@ extern lwc_error lwc_context_string_caseless_isequal(lwc_context *ctx,
lwc_string *str1,
lwc_string *str2,
bool *ret);
+/**
+ * Retrieve the data pointer for an interned string.
+ *
+ * @note The data we point at belongs to the string and will
+ * die with the string. Keep a ref if you need it.
+ */
+extern const char *lwc_string_data(lwc_string *str);
+
+/**
+ * Retrieve the data length for an interned string.
+ *
+ * @note The data we point at belongs to the string and will
+ * die with the string. Keep a ref if you need it.
+ */
+extern size_t lwc_string_length(lwc_string *str);
+
#endif /* libwapcaplet_h_ */
diff --git a/src/libwapcaplet.c b/src/libwapcaplet.c
index 9f408ed..c125390 100644
--- a/src/libwapcaplet.c
+++ b/src/libwapcaplet.c
@@ -314,3 +314,21 @@ lwc_context_string_caseless_isequal(lwc_context *ctx,
*ret = (str1->insensitive == str2->insensitive);
return lwc_error_ok;
}
+
+/**** Simple accessors ****/
+
+const char *
+lwc_string_data(lwc_string *str)
+{
+ assert(str);
+
+ return CSTR_OF(str);
+}
+
+size_t
+lwc_string_length(lwc_string *str)
+{
+ assert(str);
+
+ return str->len;
+}
diff --git a/test/basictests.c b/test/basictests.c
index ee7c2cb..07c54a3 100644
--- a/test/basictests.c
+++ b/test/basictests.c
@@ -8,6 +8,7 @@
#include <check.h>
#include <stdlib.h>
+#include <string.h>
#include "tests.h"
@@ -161,6 +162,18 @@ START_TEST (test_lwc_context_string_unref_aborts2)
}
END_TEST
+START_TEST (test_lwc_string_data_aborts)
+{
+ lwc_string_data(NULL);
+}
+END_TEST
+
+START_TEST (test_lwc_string_length_aborts)
+{
+ lwc_string_length(NULL);
+}
+END_TEST
+
#endif
START_TEST (test_lwc_context_creation_ok)
@@ -359,6 +372,15 @@ START_TEST (test_lwc_context_string_caseless_isequal_ok)
}
END_TEST
+START_TEST (test_lwc_extract_data_ok)
+{
+ fail_unless(memcmp("one",
+ lwc_string_data(intern_one),
+ lwc_string_length(intern_one)) == 0,
+ "Extracting data ptr etc failed");
+}
+END_TEST
+
/**** And the suites are set up here ****/
void
@@ -416,6 +438,12 @@ lwc_basic_suite(SRunner *sr)
tcase_add_test_raise_signal(tc_basic,
test_lwc_context_string_unref_aborts2,
SIGABRT);
+ tcase_add_test_raise_signal(tc_basic,
+ test_lwc_string_data_aborts,
+ SIGABRT);
+ tcase_add_test_raise_signal(tc_basic,
+ test_lwc_string_length_aborts,
+ SIGABRT);
#endif
tcase_add_test(tc_basic, test_lwc_context_creation_ok);
@@ -442,6 +470,7 @@ lwc_basic_suite(SRunner *sr)
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_extract_data_ok);
suite_add_tcase(s, tc_basic);
srunner_add_suite(sr, s);