summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2012-07-07 15:13:39 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2012-07-07 15:13:39 +0100
commit6f6f365c502da0cefd468755f55848301f7518e7 (patch)
tree4afd9af130ff4ab8854633d99db04b11bf50bfff /test
parent2d8858577a5cfb5878464f4a1b94eb13231ee63a (diff)
downloadlibdom-6f6f365c502da0cefd468755f55848301f7518e7.tar.gz
libdom-6f6f365c502da0cefd468755f55848301f7518e7.tar.bz2
DOMTS: Add proper support for assertURIEquals
Diffstat (limited to 'test')
-rw-r--r--test/DOMTSHandler.pm7
-rw-r--r--test/testutils/domtsasserts.c152
-rw-r--r--test/testutils/domtsasserts.h7
-rw-r--r--test/testutils/utils.c9
-rw-r--r--test/testutils/utils.h2
5 files changed, 159 insertions, 18 deletions
diff --git a/test/DOMTSHandler.pm b/test/DOMTSHandler.pm
index e440f64..dd5a7a8 100644
--- a/test/DOMTSHandler.pm
+++ b/test/DOMTSHandler.pm
@@ -1116,7 +1116,7 @@ sub generate_assertion {
case "assertURIEquals" {
my $actual = $ats->{actual};
- my ($scheme, $path, $host, $file, $query, $fragment, $isAbsolute) = qw(NULL NULL NULL NULL NULL NULL NULL);
+ my ($scheme, $path, $host, $file, $name, $query, $fragment, $isAbsolute) = qw(NULL NULL NULL NULL NULL NULL NULL NULL);
if (exists $ats->{scheme}) {
$scheme = $ats->{scheme};
}
@@ -1129,6 +1129,9 @@ sub generate_assertion {
if (exists $ats->{file}) {
$file = $ats->{file};
}
+ if (exists $ats->{name}) {
+ $name = $ats->{name};
+ }
if (exists $ats->{query}) {
$query = $ats->{query};
}
@@ -1139,7 +1142,7 @@ sub generate_assertion {
$isAbsolute = $ats->{isAbsolute};
}
- print "is_uri_equals($scheme, $path, $host, $file, $query, $fragment, $isAbsolute, $actual)"
+ print "is_uri_equals($scheme, $path, $host, $file, $name, $query, $fragment, $isAbsolute, $actual)"
}
}
diff --git a/test/testutils/domtsasserts.c b/test/testutils/domtsasserts.c
index 92e8222..e5220e0 100644
--- a/test/testutils/domtsasserts.c
+++ b/test/testutils/domtsasserts.c
@@ -190,20 +190,148 @@ bool is_size_list(unsigned long size, list *list)
}
-bool is_uri_equals(char *scheme, char *path, char *host,
- char *file, char *query, char *fragment,
- bool isAbsolute, dom_string *actual)
+bool is_uri_equals(const char *scheme, const char *path, const char *host,
+ const char *file, const char *name, const char *query,
+ const char *fragment, const char *isAbsolute,
+ dom_string *actual)
{
- UNUSED(scheme);
- UNUSED(path);
- UNUSED(host);
- UNUSED(file);
- UNUSED(query);
- UNUSED(fragment);
- UNUSED(isAbsolute);
- UNUSED(actual);
+ const char *_ptr = actual != NULL ? dom_string_data(actual) : NULL;
+ const size_t slen = actual != NULL ? dom_string_byte_length(actual) : 0;
+ char *_sptr = actual != NULL ? domts_strndup(_ptr, slen) : NULL;
+ char *sptr = _sptr;
+ bool result = false;
+
+ /* Used farther down */
+ const char *firstColon = NULL;
+ const char *firstSlash = NULL;
+ char *actualPath = NULL;
+ char *actualScheme = NULL;
+ char *actualHost = NULL;
+ char *actualFile = NULL;
+ char *actualName = NULL;
+
+ assert(sptr != NULL);
+
+ /* Note, from here on down, this is essentially a semi-direct
+ * reimplementation of assertURIEquals in the Java DOMTS.
+ */
+
+ /* Attempt to check fragment */
+ {
+ char *fptr = strrchr(sptr, '#');
+ const char *cfptr = fptr + 1;
+ if (fptr != NULL) {
+ *fptr = '\0'; /* Remove fragment from sptr */
+ } else {
+ cfptr = "";
+ }
+ if (fragment != NULL) {
+ if (strcmp(fragment, cfptr) != 0)
+ goto out;
+ }
+ }
+ /* Attempt to check query string */
+ {
+ char *qptr = strrchr(sptr, '?');
+ const char *cqptr = qptr + 1;
+ if (qptr != NULL) {
+ *qptr = '\0'; /* Remove query from sptr */
+ } else {
+ cqptr = "";
+ }
+ if (query != NULL) {
+ if (strcmp(query, cqptr) != 0)
+ goto out;
+ }
+ }
+
+ /* Scheme and path */
+ firstColon = strchr(sptr, ':');
+ firstSlash = strchr(sptr, '/');
+ actualPath = strdup(sptr);
+ actualScheme = strdup("");
+ if (firstColon != NULL && firstColon < firstSlash) {
+ free(actualScheme);
+ free(actualPath);
+ actualScheme = domts_strndup(sptr, firstColon - sptr);
+ actualPath = strdup(firstColon + 1);
+ }
+ if (scheme != NULL) {
+ if (strcmp(scheme, actualScheme) != 0)
+ goto out;
+ }
+ if (path != NULL) {
+ if (strcmp(path, actualPath) != 0)
+ goto out;
+ }
+
+ /* host */
+ if (host != NULL) {
+ if (actualPath[0] == '/' &&
+ actualPath[1] == '/') {
+ const char *termslash = strchr(actualPath + 2, '/');
+ actualHost = domts_strndup(actualPath,
+ termslash - actualPath);
+ } else {
+ actualHost = strdup("");
+ }
+ if (strcmp(actualHost, host) != 0)
+ goto out;
+ }
+
+
+ /* file */
+ actualFile = strdup(actualPath);
+ if (file != NULL || name != NULL) {
+ const char *finalSlash = strrchr(actualPath, '/');
+ if (finalSlash != NULL) {
+ free(actualFile);
+ actualFile = strdup(finalSlash + 1);
+ }
+ if (file != NULL) {
+ if (strcmp(actualFile, file) != 0)
+ goto out;
+ }
+ }
+
+ /* name */
+ if (name != NULL) {
+ const char *finalPeriod = strrchr(actualFile, '.');
+ if (finalPeriod != NULL) {
+ actualName = domts_strndup(actualFile,
+ finalPeriod - actualFile);
+ } else {
+ actualName = strdup(actualFile);
+ }
+ if (strcmp(actualName, name) != 0)
+ goto out;
+ }
+
+ /* isAbsolute */
+ if (isAbsolute != NULL) {
+ bool startslash = *actualPath == '/';
+ bool isabsolute = strcasecmp(isAbsolute, "true") == 0;
+ isabsolute |= (strcasecmp(isAbsolute, "yes") == 0);
+ isabsolute |= (strcmp(isAbsolute, "1") == 0);
+ startslash |= (strncmp(actualPath, "file:/", 6) == 0);
+ if (isabsolute != startslash)
+ goto out;
+ }
- return false;
+ result = true;
+out:
+ if (actualPath != NULL)
+ free(actualPath);
+ if (actualScheme != NULL)
+ free(actualScheme);
+ if (actualHost != NULL)
+ free(actualHost);
+ if (actualFile != NULL)
+ free(actualFile);
+ if (actualName != NULL)
+ free(actualName);
+ free(_sptr);
+ return result;
}
diff --git a/test/testutils/domtsasserts.h b/test/testutils/domtsasserts.h
index c301d88..bc214e8 100644
--- a/test/testutils/domtsasserts.h
+++ b/test/testutils/domtsasserts.h
@@ -49,9 +49,10 @@ bool is_size_domnamednodemap(unsigned long size, dom_namednodemap *map);
bool is_size_domnodelist(unsigned long size, dom_nodelist *list);
bool is_size_list(unsigned long size, list *list);
-bool is_uri_equals(char *scheme, char *path, char *host,
- char *file, char *query, char *fragment,
- bool isAbsolute, dom_string *actual);
+bool is_uri_equals(const char *scheme, const char *path, const char *host,
+ const char *file, const char *name, const char *query,
+ const char *fragment, const char *isAbsolute,
+ dom_string *actual);
bool is_contenttype(const char *type);
diff --git a/test/testutils/utils.c b/test/testutils/utils.c
index 739933f..c876613 100644
--- a/test/testutils/utils.c
+++ b/test/testutils/utils.c
@@ -8,6 +8,7 @@
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include "utils.h"
@@ -31,4 +32,10 @@ void mymsg(uint32_t severity, void *ctx, const char *msg, ...)
fprintf(stderr, "\n");
}
-
+char *domts_strndup(const char *s, size_t len)
+{
+ size_t retlen = min(strlen(s), len);
+ char *ret = calloc(retlen + 1, 1);
+ memcpy(ret, s, retlen);
+ return ret;
+}
diff --git a/test/testutils/utils.h b/test/testutils/utils.h
index b57db36..560e909 100644
--- a/test/testutils/utils.h
+++ b/test/testutils/utils.h
@@ -31,5 +31,7 @@
void *myrealloc(void *ptr, size_t len, void *pw);
void mymsg(uint32_t severity, void *ctx, const char *msg, ...);
+char *domts_strndup(const char *s, size_t len);
+
#endif