From 4456645b451300aff4a763e966746e247ec5ae39 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sat, 14 Feb 2009 11:12:22 +0000 Subject: Allow TESTTYPE=release to be specified to build the tests with the release CFLAGS. Add TARGET to the build paths. You should 'make distclean' before updating to this. Add BUILD_SHARED=yes support to the *nix build svn path=/trunk/hubbub/; revision=6478 --- test/Makefile | 17 +++++++++++++---- test/parser.c | 26 ++++++++++---------------- test/tokeniser.c | 31 +++++++++++-------------------- test/tree-buf.c | 4 +++- test/tree.c | 28 +++++++++++----------------- test/tree2.c | 2 +- 6 files changed, 49 insertions(+), 59 deletions(-) (limited to 'test') diff --git a/test/Makefile b/test/Makefile index caf397d..cb01a62 100644 --- a/test/Makefile +++ b/test/Makefile @@ -9,6 +9,7 @@ # TOP The location of the source tree root # RELEASEDIR The place to put release objects # DEBUGDIR The place to put debug objects +# TESTTYPE The type of test to build (release/debug) # # do_include Canned command sequence to include a child makefile # @@ -40,6 +41,14 @@ CFLAGS := $(CFLAGS) -I$(TOP)/src/ -I$(d) \ LDFLAGS := $(LDFLAGS) $(shell $(PKGCONFIG) $(PKGCONFIGFLAGS) --libs json) endif +ifeq ($(TESTTYPE),release) +TESTCFLAGS := $(RELEASECFLAGS) +TESTLIB := libhubbub.a +else +TESTCFLAGS := $(DEBUGCFLAGS) +TESTLIB := libhubbub-debug.a +endif + ifdef PROFILE CFLAGS := $(CFLAGS) -pg -fno-omit-frame-pointer LDFLAGS := $(LDFLAGS) -pg @@ -75,7 +84,7 @@ define dep_test DEP_$(d) += $(2) $(2): $(1) @$$(RM) $$(RMFLAGS) $(2) - @$$(CC) $$(DEBUGCFLAGS) -MM -MT '$(2) $(3)' -MF $(2) $(1) + @$$(CC) $$(TESTCFLAGS) -MM -MT '$(2) $(3)' -MF $(2) $(1) endef @@ -86,11 +95,11 @@ define compile_test ifeq ($(HOST),riscos) $(2): $(3) else -$(2): $(3) $(TOP)/$(COMPONENT)-debug.a +$(2): $(3) $(TOP)/$(TESTLIB) endif @$$(ECHO) $$(ECHOFLAGS) "==> $(1)" - @$$(CC) -c -g $$(DEBUGCFLAGS) -o $$@.o $(1) - @$$(LD) -g -o $$@ $$@.o -lhubbub-debug $$(LDFLAGS) -lgcov + @$$(CC) -c -g $$(TESTCFLAGS) -o $$@.o $(1) + @$$(LD) -g -o $$@ $$@.o $$(TOP)/$$(TESTLIB) $$(LDFLAGS) -lgcov @$$(RM) $$(RMFLAGS) $$@.o endef diff --git a/test/parser.c b/test/parser.c index 5531af1..7847a68 100644 --- a/test/parser.c +++ b/test/parser.c @@ -50,25 +50,19 @@ static int run_test(int argc, char **argv, unsigned int CHUNK_SIZE) origlen = len = ftell(fp); fseek(fp, 0, SEEK_SET); - while (len >= CHUNK_SIZE) { - fread(buf, 1, CHUNK_SIZE, fp); - + while (len > 0) { + ssize_t bytes_read = fread(buf, 1, CHUNK_SIZE, fp); + + if (bytes_read < 1) + break; + assert(hubbub_parser_parse_chunk(parser, - buf, CHUNK_SIZE) == HUBBUB_OK); - - len -= CHUNK_SIZE; - } - - if (len > 0) { - fread(buf, 1, len, fp); - - assert(hubbub_parser_parse_chunk(parser, - buf, len) == HUBBUB_OK); - - len = 0; + buf, bytes_read) == HUBBUB_OK); - assert(hubbub_parser_completed(parser) == HUBBUB_OK); + len -= bytes_read; } + + assert(len == 0); fclose(fp); diff --git a/test/tokeniser.c b/test/tokeniser.c index 0614e78..29a2a7e 100644 --- a/test/tokeniser.c +++ b/test/tokeniser.c @@ -59,31 +59,22 @@ int main(int argc, char **argv) origlen = len = ftell(fp); fseek(fp, 0, SEEK_SET); - while (len >= CHUNK_SIZE) { - fread(buf, 1, CHUNK_SIZE, fp); - - assert(parserutils_inputstream_append(stream, - buf, CHUNK_SIZE) == HUBBUB_OK); - - len -= CHUNK_SIZE; - - assert(hubbub_tokeniser_run(tok) == HUBBUB_OK); - } - - if (len > 0) { - fread(buf, 1, len, fp); - + while (len > 0) { + ssize_t bytes_read = fread(buf, 1, CHUNK_SIZE, fp); + + if (bytes_read < 1) + break; + assert(parserutils_inputstream_append(stream, - buf, len) == HUBBUB_OK); + buf, bytes_read) == HUBBUB_OK); - len = 0; - - assert(parserutils_inputstream_append(stream, NULL, 0) == - HUBBUB_OK); + len -= bytes_read; assert(hubbub_tokeniser_run(tok) == HUBBUB_OK); } - + + assert(len == 0); + fclose(fp); hubbub_tokeniser_destroy(tok); diff --git a/test/tree-buf.c b/test/tree-buf.c index e406a45..4280a69 100644 --- a/test/tree-buf.c +++ b/test/tree-buf.c @@ -241,9 +241,11 @@ int main(int argc, char **argv) parser = setup_parser(); for (uint32_t i = 0; i < n_chunks; i++) { + ssize_t bytes_read; assert(chunks[i] <= sizeof(buf)); - fread(buf, 1, chunks[i], fp); + bytes_read = fread(buf, 1, chunks[i], fp); + assert((size_t)(bytes_read) == chunks[i]); assert(hubbub_parser_parse_chunk(parser, (uint8_t *) buf, chunks[i]) == HUBBUB_OK); diff --git a/test/tree.c b/test/tree.c index 9a5bf8c..8a5a5b1 100644 --- a/test/tree.c +++ b/test/tree.c @@ -117,26 +117,20 @@ static int run_test(int argc, char **argv, unsigned int CHUNK_SIZE) origlen = len = ftell(fp); fseek(fp, 0, SEEK_SET); - while (len >= CHUNK_SIZE) { - fread(buf, 1, CHUNK_SIZE, fp); - - assert(hubbub_parser_parse_chunk(parser, - buf, CHUNK_SIZE) == HUBBUB_OK); - - len -= CHUNK_SIZE; - } - - if (len > 0) { - fread(buf, 1, len, fp); - + while (len > 0) { + ssize_t bytes_read = fread(buf, 1, CHUNK_SIZE, fp); + + if (bytes_read < 1) + break; + assert(hubbub_parser_parse_chunk(parser, - buf, len) == HUBBUB_OK); + buf, bytes_read) == HUBBUB_OK); - len = 0; - - assert(hubbub_parser_completed(parser) == HUBBUB_OK); + len -= bytes_read; } - + + assert(len == 0); + fclose(fp); charset = hubbub_parser_read_charset(parser, &cssource); diff --git a/test/tree2.c b/test/tree2.c index 8fba853..98826ca 100644 --- a/test/tree2.c +++ b/test/tree2.c @@ -217,7 +217,7 @@ int main(int argc, char **argv) bool reprocess = false; bool passed = true; - hubbub_parser *parser; + hubbub_parser *parser = NULL; enum reading_state state = EXPECT_DATA; buf_t expected = { NULL, 0, 0 }; -- cgit v1.2.3