summaryrefslogtreecommitdiff
path: root/test/urldbtest.c
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2017-03-08 22:22:54 +0000
committerVincent Sanders <vince@kyllikki.org>2017-03-08 22:22:54 +0000
commit5ebec852825072e50fb21363f23cf2fcd106425d (patch)
treebaf8023c06274d2ba2d8cb5c90f80c86582283fd /test/urldbtest.c
parent0da0dcc342f3c3078b73449c2ead95fee39ec4b8 (diff)
downloadnetsurf-5ebec852825072e50fb21363f23cf2fcd106425d.tar.gz
netsurf-5ebec852825072e50fb21363f23cf2fcd106425d.tar.bz2
actually check the generated database files against reference test data
Diffstat (limited to 'test/urldbtest.c')
-rw-r--r--test/urldbtest.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/test/urldbtest.c b/test/urldbtest.c
index 89cf27679..6b3f2acad 100644
--- a/test/urldbtest.c
+++ b/test/urldbtest.c
@@ -43,13 +43,67 @@
#include "desktop/gui_internal.h"
#include "desktop/cookie_manager.h"
+/**
+ * url database used as input to test sets
+ */
const char *test_urldb_path = "test/data/urldb";
+/**
+ * url database used as output reference
+ */
+const char *test_urldb_out_path = "test/data/urldb-out";
+
+/**
+ * cookie database used as input
+ */
const char *test_cookies_path = "test/data/cookies";
+/**
+ * cookie database used as output reference
+ */
+const char *test_cookies_out_path = "test/data/cookies-out";
const char *wikipedia_url = "http://www.wikipedia.org/";
struct netsurf_table *guit = NULL;
+/**
+ * compare two files contents
+ */
+static int cmp(const char *f1, const char *f2)
+{
+ int res = 0;
+ FILE *fp1;
+ FILE *fp2;
+ int ch1;
+ int ch2;
+
+ fp1 = fopen(f1, "r");
+ if (fp1 == NULL) {
+ return -1;
+ }
+ fp2 = fopen(f2, "r");
+ if (fp2 == NULL) {
+ fclose(fp1);
+ return -1;
+ }
+
+ while (res == 0) {
+ ch1 = fgetc(fp1);
+ ch2 = fgetc(fp2);
+
+ if (ch1 != ch2) {
+ res = 1;
+ }
+
+ if (ch1 == EOF) {
+ break;
+ }
+ }
+
+ fclose(fp1);
+ fclose(fp2);
+ return res;
+}
+
/*************** original test helpers ************/
bool cookie_manager_add(const struct cookie_data *data)
@@ -398,6 +452,9 @@ START_TEST(urldb_session_test)
res = urldb_save(outnam);
ck_assert_int_eq(res, NSERROR_OK);
+ /* check for the correct answer */
+ ck_assert_int_eq(cmp(outnam, test_urldb_out_path), 0);
+
/* remove test output */
unlink(outnam);
@@ -405,6 +462,9 @@ START_TEST(urldb_session_test)
outnam = tmpnam(NULL);
urldb_save_cookies(outnam);
+ /* check for the correct answer */
+ ck_assert_int_eq(cmp(outnam, test_cookies_out_path), 0);
+
/* remove test output */
unlink(outnam);