summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2018-01-20 17:31:20 +0000
committerMichael Drake <tlsa@netsurf-browser.org>2018-01-20 17:31:20 +0000
commit0dd48e83fbc246a881609b4c18ce10001ba1cc1a (patch)
tree7494cc81744799ab88f1503ac5ff044be2fcf4a5 /test
parente220b0fc2ede1dcbbe7e6e62c256e2ec297f26a3 (diff)
downloadlibcss-0dd48e83fbc246a881609b4c18ce10001ba1cc1a.tar.gz
libcss-0dd48e83fbc246a881609b4c18ce10001ba1cc1a.tar.bz2
Add support for logging via libnslog.
Release builds minumum compiled level is warning. Debug builds minimum compiled level is debug.
Diffstat (limited to 'test')
-rw-r--r--test/csdetect.c26
-rw-r--r--test/css21.c26
-rw-r--r--test/lex-auto.c26
-rw-r--r--test/lex.c26
-rw-r--r--test/number.c26
-rw-r--r--test/parse-auto.c26
-rw-r--r--test/parse.c26
-rw-r--r--test/parse2-auto.c26
-rw-r--r--test/select.c26
9 files changed, 234 insertions, 0 deletions
diff --git a/test/csdetect.c b/test/csdetect.c
index b8c8e3f..bbe4307 100644
--- a/test/csdetect.c
+++ b/test/csdetect.c
@@ -22,6 +22,20 @@ typedef struct line_ctx {
bool inenc;
} line_ctx;
+static void test_logger(
+ void *_ctx, nslog_entry_context_t *ctx,
+ const char *fmt,
+ va_list args)
+{
+ UNUSED(_ctx);
+ fprintf(stderr, "%s: %s: %s:%i: ",
+ nslog_level_name(ctx->level),
+ ctx->category->description,
+ ctx->filename, ctx->lineno);
+ vfprintf(stderr, fmt, args);
+ fprintf(stderr, "\n");
+}
+
static bool handle_line(const char *data, size_t datalen, void *pw);
static void run_test(const uint8_t *data, size_t len, char *expected);
@@ -34,6 +48,16 @@ int main(int argc, char **argv)
return 1;
}
+ if (nslog_set_render_callback(test_logger, NULL) != NSLOG_NO_ERROR) {
+ printf("Unable to set log render callback\n");
+ return 1;
+ }
+
+ if (nslog_uncork() != NSLOG_NO_ERROR) {
+ printf("Failed to uncork log.\n");
+ return 1;
+ }
+
ctx.buflen = css__parse_filesize(argv[1]);
if (ctx.buflen == 0)
return 1;
@@ -61,6 +85,8 @@ int main(int argc, char **argv)
free(ctx.buf);
+ nslog_cleanup();
+
printf("PASS\n");
return 0;
diff --git a/test/css21.c b/test/css21.c
index a29fae1..f8d3891 100644
--- a/test/css21.c
+++ b/test/css21.c
@@ -25,6 +25,20 @@ static css_error resolve_url(void *pw,
return CSS_OK;
}
+static void test_logger(
+ void *_ctx, nslog_entry_context_t *ctx,
+ const char *fmt,
+ va_list args)
+{
+ UNUSED(_ctx);
+ fprintf(stderr, "%s: %s: %s:%i: ",
+ nslog_level_name(ctx->level),
+ ctx->category->description,
+ ctx->filename, ctx->lineno);
+ vfprintf(stderr, fmt, args);
+ fprintf(stderr, "\n");
+}
+
int main(int argc, char **argv)
{
css_stylesheet_params params;
@@ -41,6 +55,16 @@ int main(int argc, char **argv)
return 1;
}
+ if (nslog_set_render_callback(test_logger, NULL) != NSLOG_NO_ERROR) {
+ printf("Unable to set log render callback\n");
+ return 1;
+ }
+
+ if (nslog_uncork() != NSLOG_NO_ERROR) {
+ printf("Failed to uncork log.\n");
+ return 1;
+ }
+
params.params_version = CSS_STYLESHEET_PARAMS_VERSION_1;
params.level = CSS_LEVEL_21;
params.charset = "UTF-8";
@@ -153,6 +177,8 @@ int main(int argc, char **argv)
css_stylesheet_destroy(sheet);
}
+ nslog_cleanup();
+
printf("PASS\n");
return 0;
diff --git a/test/lex-auto.c b/test/lex-auto.c
index f4afec3..e7e7c83 100644
--- a/test/lex-auto.c
+++ b/test/lex-auto.c
@@ -42,6 +42,20 @@ static css_token_type string_to_type(const char *data, size_t len);
static void run_test(const uint8_t *data, size_t len,
exp_entry *exp, size_t explen);
+static void test_logger(
+ void *_ctx, nslog_entry_context_t *ctx,
+ const char *fmt,
+ va_list args)
+{
+ UNUSED(_ctx);
+ fprintf(stderr, "%s: %s: %s:%i: ",
+ nslog_level_name(ctx->level),
+ ctx->category->description,
+ ctx->filename, ctx->lineno);
+ vfprintf(stderr, fmt, args);
+ fprintf(stderr, "\n");
+}
+
int main(int argc, char **argv)
{
line_ctx ctx;
@@ -51,6 +65,16 @@ int main(int argc, char **argv)
return 1;
}
+ if (nslog_set_render_callback(test_logger, NULL) != NSLOG_NO_ERROR) {
+ printf("Unable to set log render callback\n");
+ return 1;
+ }
+
+ if (nslog_uncork() != NSLOG_NO_ERROR) {
+ printf("Failed to uncork log.\n");
+ return 1;
+ }
+
ctx.buflen = css__parse_filesize(argv[1]);
if (ctx.buflen == 0)
return 1;
@@ -79,6 +103,8 @@ int main(int argc, char **argv)
free(ctx.buf);
free(ctx.exp);
+ nslog_cleanup();
+
printf("PASS\n");
return 0;
diff --git a/test/lex.c b/test/lex.c
index cce8ded..92db574 100644
--- a/test/lex.c
+++ b/test/lex.c
@@ -110,6 +110,20 @@ static void printToken(const css_token *token)
#endif
}
+static void test_logger(
+ void *_ctx, nslog_entry_context_t *ctx,
+ const char *fmt,
+ va_list args)
+{
+ UNUSED(_ctx);
+ fprintf(stderr, "%s: %s: %s:%i: ",
+ nslog_level_name(ctx->level),
+ ctx->category->description,
+ ctx->filename, ctx->lineno);
+ vfprintf(stderr, fmt, args);
+ fprintf(stderr, "\n");
+}
+
int main(int argc, char **argv)
{
parserutils_inputstream *stream;
@@ -127,6 +141,16 @@ int main(int argc, char **argv)
return 1;
}
+ if (nslog_set_render_callback(test_logger, NULL) != NSLOG_NO_ERROR) {
+ printf("Unable to set log render callback\n");
+ return 1;
+ }
+
+ if (nslog_uncork() != NSLOG_NO_ERROR) {
+ printf("Failed to uncork log.\n");
+ return 1;
+ }
+
for (i = 0; i < ITERATIONS; i++) {
assert(parserutils_inputstream_create("UTF-8",
CSS_CHARSET_DICTATED,css__charset_extract,
@@ -190,6 +214,8 @@ int main(int argc, char **argv)
parserutils_inputstream_destroy(stream);
}
+ nslog_cleanup();
+
printf("PASS\n");
return 0;
diff --git a/test/number.c b/test/number.c
index d255f4c..e3c2c8f 100644
--- a/test/number.c
+++ b/test/number.c
@@ -25,6 +25,20 @@ static void run_test(const uint8_t *data, size_t len,
const char *exp, size_t explen);
static void print_css_fixed(char *buf, size_t len, css_fixed f);
+static void test_logger(
+ void *_ctx, nslog_entry_context_t *ctx,
+ const char *fmt,
+ va_list args)
+{
+ UNUSED(_ctx);
+ fprintf(stderr, "%s: %s: %s:%i: ",
+ nslog_level_name(ctx->level),
+ ctx->category->description,
+ ctx->filename, ctx->lineno);
+ vfprintf(stderr, fmt, args);
+ fprintf(stderr, "\n");
+}
+
int main(int argc, char **argv)
{
line_ctx ctx;
@@ -34,6 +48,16 @@ int main(int argc, char **argv)
return 1;
}
+ if (nslog_set_render_callback(test_logger, NULL) != NSLOG_NO_ERROR) {
+ printf("Unable to set log render callback\n");
+ return 1;
+ }
+
+ if (nslog_uncork() != NSLOG_NO_ERROR) {
+ printf("Failed to uncork log.\n");
+ return 1;
+ }
+
ctx.buflen = css__parse_filesize(argv[1]);
if (ctx.buflen == 0)
return 1;
@@ -59,6 +83,8 @@ int main(int argc, char **argv)
free(ctx.buf);
+ nslog_cleanup();
+
printf("PASS\n");
return 0;
diff --git a/test/parse-auto.c b/test/parse-auto.c
index 58ccf9a..a298864 100644
--- a/test/parse-auto.c
+++ b/test/parse-auto.c
@@ -99,6 +99,20 @@ static void destroy_expected(line_ctx *ctx)
}
}
+static void test_logger(
+ void *_ctx, nslog_entry_context_t *ctx,
+ const char *fmt,
+ va_list args)
+{
+ UNUSED(_ctx);
+ fprintf(stderr, "%s: %s: %s:%i: ",
+ nslog_level_name(ctx->level),
+ ctx->category->description,
+ ctx->filename, ctx->lineno);
+ vfprintf(stderr, fmt, args);
+ fprintf(stderr, "\n");
+}
+
int main(int argc, char **argv)
{
line_ctx ctx;
@@ -108,6 +122,16 @@ int main(int argc, char **argv)
return 1;
}
+ if (nslog_set_render_callback(test_logger, NULL) != NSLOG_NO_ERROR) {
+ printf("Unable to set log render callback\n");
+ return 1;
+ }
+
+ if (nslog_uncork() != NSLOG_NO_ERROR) {
+ printf("Failed to uncork log.\n");
+ return 1;
+ }
+
ctx.buflen = css__parse_filesize(argv[1]);
if (ctx.buflen == 0)
return 1;
@@ -143,6 +167,8 @@ int main(int argc, char **argv)
assert(fail_because_lwc_leaked == false);
+ nslog_cleanup();
+
printf("PASS\n");
return 0;
diff --git a/test/parse.c b/test/parse.c
index 0692fc7..c7017a9 100644
--- a/test/parse.c
+++ b/test/parse.c
@@ -66,6 +66,20 @@ static css_error event_handler(css_parser_event type,
return CSS_OK;
}
+static void test_logger(
+ void *_ctx, nslog_entry_context_t *ctx,
+ const char *fmt,
+ va_list args)
+{
+ UNUSED(_ctx);
+ fprintf(stderr, "%s: %s: %s:%i: ",
+ nslog_level_name(ctx->level),
+ ctx->category->description,
+ ctx->filename, ctx->lineno);
+ vfprintf(stderr, fmt, args);
+ fprintf(stderr, "\n");
+}
+
int main(int argc, char **argv)
{
css_parser_optparams params;
@@ -82,6 +96,16 @@ int main(int argc, char **argv)
return 1;
}
+ if (nslog_set_render_callback(test_logger, NULL) != NSLOG_NO_ERROR) {
+ printf("Unable to set log render callback\n");
+ return 1;
+ }
+
+ if (nslog_uncork() != NSLOG_NO_ERROR) {
+ printf("Failed to uncork log.\n");
+ return 1;
+ }
+
for (i = 0; i < ITERATIONS; i++) {
assert(css__parser_create("UTF-8", CSS_CHARSET_DICTATED,
&parser) == CSS_OK);
@@ -129,6 +153,8 @@ int main(int argc, char **argv)
}
+ nslog_cleanup();
+
printf("PASS\n");
return 0;
diff --git a/test/parse2-auto.c b/test/parse2-auto.c
index ee717c3..ea833f9 100644
--- a/test/parse2-auto.c
+++ b/test/parse2-auto.c
@@ -57,6 +57,20 @@ printing_lwc_iterator(lwc_string *str, void *pw)
fail_because_lwc_leaked = true;
}
+static void test_logger(
+ void *_ctx, nslog_entry_context_t *ctx,
+ const char *fmt,
+ va_list args)
+{
+ UNUSED(_ctx);
+ fprintf(stderr, "%s: %s: %s:%i: ",
+ nslog_level_name(ctx->level),
+ ctx->category->description,
+ ctx->filename, ctx->lineno);
+ vfprintf(stderr, fmt, args);
+ fprintf(stderr, "\n");
+}
+
int main(int argc, char **argv)
{
line_ctx ctx;
@@ -66,6 +80,16 @@ int main(int argc, char **argv)
return 1;
}
+ if (nslog_set_render_callback(test_logger, NULL) != NSLOG_NO_ERROR) {
+ printf("Unable to set log render callback\n");
+ return 1;
+ }
+
+ if (nslog_uncork() != NSLOG_NO_ERROR) {
+ printf("Failed to uncork log.\n");
+ return 1;
+ }
+
ctx.buflen = css__parse_filesize(argv[1]);
if (ctx.buflen == 0)
return 1;
@@ -99,6 +123,8 @@ int main(int argc, char **argv)
assert(fail_because_lwc_leaked == false);
+ nslog_cleanup();
+
printf("PASS\n");
return 0;
diff --git a/test/select.c b/test/select.c
index f21d937..923bf38 100644
--- a/test/select.c
+++ b/test/select.c
@@ -231,6 +231,20 @@ printing_lwc_iterator(lwc_string *str, void *pw)
fail_because_lwc_leaked = true;
}
+static void test_logger(
+ void *_ctx, nslog_entry_context_t *ctx,
+ const char *fmt,
+ va_list args)
+{
+ UNUSED(_ctx);
+ fprintf(stderr, "%s: %s: %s:%i: ",
+ nslog_level_name(ctx->level),
+ ctx->category->description,
+ ctx->filename, ctx->lineno);
+ vfprintf(stderr, fmt, args);
+ fprintf(stderr, "\n");
+}
+
int main(int argc, char **argv)
{
line_ctx ctx;
@@ -240,6 +254,16 @@ int main(int argc, char **argv)
return 1;
}
+ if (nslog_set_render_callback(test_logger, NULL) != NSLOG_NO_ERROR) {
+ printf("Unable to set log render callback\n");
+ return 1;
+ }
+
+ if (nslog_uncork() != NSLOG_NO_ERROR) {
+ printf("Failed to uncork log.\n");
+ return 1;
+ }
+
memset(&ctx, 0, sizeof(ctx));
@@ -261,6 +285,8 @@ int main(int argc, char **argv)
assert(fail_because_lwc_leaked == false);
+ nslog_cleanup();
+
printf("PASS\n");
return 0;
}