Gitweb links:
...log
http://git.netsurf-browser.org/librosprite.git/shortlog/c8f5b9a37174f7184db1e3e57c0f588a59306c90
...commit
http://git.netsurf-browser.org/librosprite.git/commit/c8f5b9a37174f7184db1e3e57c0f588a59306c90
...tree
http://git.netsurf-browser.org/librosprite.git/tree/c8f5b9a37174f7184db1e3e57c0f588a59306c90
The branch, master has been updated
via c8f5b9a37174f7184db1e3e57c0f588a59306c90 (commit)
from 8f19e4ea8242a46db7c59ddad1edc5f6a9a5656b (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff
http://git.netsurf-browser.org/librosprite.git/commit/?id=c8f5b9a37174f7184db1e3e57c0f588a59306c90
commit c8f5b9a37174f7184db1e3e57c0f588a59306c90
Author: Vincent Sanders <[email protected]>
Commit: Vincent Sanders <[email protected]>
fix tests
diff --git a/.gitignore b/.gitignore
index dd07bff..015f2f7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
build-*
+*~
diff --git a/Makefile b/Makefile
index b82e633..d432327 100644
--- a/Makefile
+++ b/Makefile
@@ -13,6 +13,9 @@ PREFIX ?= /opt/netsurf
NSSHARED ?= $(PREFIX)/share/netsurf-buildsystem
include $(NSSHARED)/makefiles/Makefile.tools
+# Reevaluate when used, as BUILDDIR won't be defined yet
+TESTRUNNER = test/runtest.sh $(BUILDDIR) $(EXEEXT)
+
# Toolchain flags
WARNFLAGS := -Wall -Wextra -Wundef -Wpointer-arith -Wcast-align \
-Wwrite-strings -Wstrict-prototypes \
@@ -36,6 +39,9 @@ else
CFLAGS := $(CFLAGS) -Dinline="__inline__"
endif
+TESTCFLAGS := -g -O2
+TESTLDFLAGS := -lm -l$(COMPONENT) $(TESTLDFLAGS)
+
include $(NSBUILD)/Makefile.top
# Extra installation rules
diff --git a/test-data/32bpp-alpha-test b/test-data/32bpp-alpha-test
deleted file mode 100644
index 92ebd63..0000000
Binary files a/test-data/32bpp-alpha-test and /dev/null differ
diff --git a/test-data/primary-color-16bpp b/test-data/primary-color-16bpp
deleted file mode 100644
index fba7a08..0000000
Binary files a/test-data/primary-color-16bpp and /dev/null differ
diff --git a/test-data/small b/test-data/small
deleted file mode 100644
index 5552782..0000000
Binary files a/test-data/small and /dev/null differ
diff --git a/test/Makefile b/test/Makefile
new file mode 100644
index 0000000..1402632
--- /dev/null
+++ b/test/Makefile
@@ -0,0 +1,3 @@
+DIR_TEST_ITEMS := decode_rosprite:decode_rosprite.c
+
+include $(NSBUILD)/Makefile.subdir
diff --git a/test/decode_rosprite.c b/test/decode_rosprite.c
new file mode 100644
index 0000000..c038b1f
--- /dev/null
+++ b/test/decode_rosprite.c
@@ -0,0 +1,135 @@
+/*
+ * Copyright 2018 Vincent Sanders <[email protected]>
+ *
+ * This file is part of NetSurf's librosprite, http://www.netsurf-browser.org/
+ * Licenced under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ */
+
+#include <assert.h>
+#include <errno.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/stat.h>
+#include "../include/librosprite.h"
+
+
+static void write_ppm(FILE* fh, const char *srcname, struct rosprite* sprite)
+{
+ fprintf(fh, "P3\n");
+ fprintf(fh, "# %s\n", srcname);
+
+ fprintf(fh, "# name %s\n", sprite->name);
+ fprintf(fh, "# color_model %s\n",
+ sprite->mode.color_model == ROSPRITE_RGB ? "RGB" : "CMYK");
+ fprintf(fh, "# colorbpp %u\n", sprite->mode.colorbpp);
+ fprintf(fh, "# xdpi %u\n", sprite->mode.xdpi);
+ fprintf(fh, "# ydpi %u\n", sprite->mode.ydpi);
+ fprintf(fh, "# width %u px\n", sprite->width);
+ fprintf(fh, "# height %u px\n", sprite->height);
+
+ fprintf(fh, "# hasPalette %s\n", sprite->has_palette ? "YES" : "NO");
+ if (sprite->has_palette) {
+ fprintf(fh, "# paletteSize %u\n", sprite->palettesize);
+ }
+ fprintf(fh, "# hasMask %s\n", sprite->has_mask ? "YES" : "NO");
+ if (sprite->has_mask) {
+ fprintf(fh, "# mask_width %u\n", sprite->mode.mask_width);
+ }
+ if (sprite->has_mask) {
+ fprintf(fh, "# maskbpp %u\n", sprite->mode.maskbpp);
+ }
+
+ fprintf(fh, "%u %u 256\n", sprite->width, sprite->height);
+
+
+ for (uint32_t y = 0; y < sprite->height; y++) {
+ for (uint32_t x = 0; x < sprite->width; x++) {
+ uint32_t color; /* color is 0xrrggbbaa */
+
+ color = sprite->image[y*sprite->width + x];
+ fprintf(fh, "%u %u %u ",
+ (color & 0xff000000) >> 24,
+ (color & 0x00ff0000) >> 16,
+ (color & 0x0000ff00) >> 8);
+
+ }
+ fprintf(fh, "\n");
+ }
+
+}
+
+
+int main(int argc, char *argv[])
+{
+
+ int res = 0;
+ FILE *inf;
+ FILE *outf = stdout;
+ struct rosprite_file_context *ctx;
+ struct rosprite_area *sprite_area;
+ unsigned int sprite_number = 0;/* number of sprite in sprite area to
convert */
+
+ if (argc < 2) {
+ fprintf(stderr, "Usage: %s image.spr [out]\n", argv[0]);
+ return 1;
+ }
+
+ inf = fopen(argv[1], "rb");
+ if (inf == NULL) {
+ fprintf(stderr, "Unable to open %s for reading\n", argv[1]);
+ return 3;
+ }
+
+ if (argc > 2) {
+ outf = fopen(argv[2], "w+");
+ if (outf == NULL) {
+ fprintf(stderr,
+ "Unable to open %s for writing\n", argv[2]);
+ fclose(inf);
+ return 2;
+ }
+ }
+
+ if (rosprite_create_file_context(inf, &ctx) != ROSPRITE_OK) {
+ fprintf(stderr, "Unable to create file context\n");
+ res = 4;
+ goto cleanup;
+ }
+
+ /* load sprites into sprite area */
+ if (rosprite_load(rosprite_file_reader,
+ ctx,
+ &sprite_area) != ROSPRITE_OK) {
+ fprintf(stderr, "Error loading spritefile\n");
+ res = 5;
+ goto cleanup;
+ };
+
+ if (sprite_number >= sprite_area->sprite_count) {
+ fprintf(stderr,
+ "Sprite %d of %d is not present in sprite pool\n",
+ sprite_number, sprite_area->sprite_count);
+ res = 6;
+ goto cleanup;
+ }
+
+ /* write out sprite */
+ write_ppm(outf, argv[1], sprite_area->sprites[sprite_number]);
+
+ rosprite_destroy_file_context(ctx);
+ rosprite_destroy_sprite_area(sprite_area);
+
+cleanup:
+
+ fclose(inf);
+
+ if (argc > 2) {
+ fclose(outf);
+ }
+
+ return res;
+}
diff --git a/test/runtest.sh b/test/runtest.sh
new file mode 100755
index 0000000..c5535d9
--- /dev/null
+++ b/test/runtest.sh
@@ -0,0 +1,58 @@
+#!/bin/sh
+
+# run test images through librosprite and count results
+
+TEST_PATH=$1
+TEST_OUT=${TEST_PATH}/ppm
+TEST_LOG=${TEST_PATH}/test.log
+
+mkdir -p ${TEST_OUT}
+
+echo "RO Sprite tests" > ${TEST_LOG}
+
+# netsurf test sprites
+SPRTESTS="test/sprite/*.spr"
+
+
+rospritedecode()
+{
+ OUTF=$(basename ${1} .spr)
+ CMPF=$(dirname ${1})/${OUTF}.ppm
+ echo "Icon:${1}" >> ${TEST_LOG}
+ ${TEST_PATH}/test_decode_rosprite ${1} ${TEST_OUT}/${OUTF}.ppm 2>>
${TEST_LOG}
+ if [ -f "${CMPF}" ]; then
+ cmp ${CMPF} ${TEST_OUT}/${OUTF}.ppm >> ${TEST_LOG} 2>> ${TEST_LOG}
+ if [ "$?" -ne 0 ]; then
+ return 128
+ fi
+ fi
+}
+
+# sprite tests
+
+SPRTESTTOTC=0
+SPRTESTPASSC=0
+SPRTESTERRC=0
+
+# netsurf test sprites
+for SPR in $(ls ${SPRTESTS});do
+ SPRTESTTOTC=$((SPRTESTTOTC+1))
+ rospritedecode ${SPR}
+ ECODE=$?
+ if [ \( "${ECODE}" -gt 127 \) -o \( "${ECODE}" -eq 1 \) ];then
+ SPRTESTERRC=$((SPRTESTERRC+1))
+ else
+ SPRTESTPASSC=$((SPRTESTPASSC+1))
+ fi
+done
+
+echo "Test sprite decode"
+echo "Tests:${SPRTESTTOTC} Pass:${SPRTESTPASSC} Error:${SPRTESTERRC}"
+
+
+# exit code
+if [ "${SPRTESTERRC}" -gt 0 ]; then
+ exit 1
+fi
+
+exit 0
diff --git a/test/sprite/32bpp-alpha-test.spr b/test/sprite/32bpp-alpha-test.spr
new file mode 100644
index 0000000..92ebd63
Binary files /dev/null and b/test/sprite/32bpp-alpha-test.spr differ
diff --git a/test/sprite/primary-color-16bpp.spr
b/test/sprite/primary-color-16bpp.spr
new file mode 100644
index 0000000..fba7a08
Binary files /dev/null and b/test/sprite/primary-color-16bpp.spr differ
diff --git a/test/sprite/small.spr b/test/sprite/small.spr
new file mode 100644
index 0000000..5552782
Binary files /dev/null and b/test/sprite/small.spr differ
-----------------------------------------------------------------------
Summary of changes:
.gitignore | 1 +
Makefile | 6 +
test/Makefile | 3 +
test/decode_rosprite.c | 135 ++++++++++++++++++++
test/runtest.sh | 58 +++++++++
.../sprite/32bpp-alpha-test.spr | Bin 30356 -> 30356 bytes
.../sprite/primary-color-16bpp.spr | Bin 180144 -> 180144
bytes
test-data/small => test/sprite/small.spr | Bin 224 -> 224 bytes
8 files changed, 203 insertions(+)
create mode 100644 test/Makefile
create mode 100644 test/decode_rosprite.c
create mode 100755 test/runtest.sh
rename test-data/32bpp-alpha-test => test/sprite/32bpp-alpha-test.spr (100%)
rename test-data/primary-color-16bpp => test/sprite/primary-color-16bpp.spr
(100%)
rename test-data/small => test/sprite/small.spr (100%)
diff --git a/.gitignore b/.gitignore
index dd07bff..015f2f7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
build-*
+*~
diff --git a/Makefile b/Makefile
index b82e633..d432327 100644
--- a/Makefile
+++ b/Makefile
@@ -13,6 +13,9 @@ PREFIX ?= /opt/netsurf
NSSHARED ?= $(PREFIX)/share/netsurf-buildsystem
include $(NSSHARED)/makefiles/Makefile.tools
+# Reevaluate when used, as BUILDDIR won't be defined yet
+TESTRUNNER = test/runtest.sh $(BUILDDIR) $(EXEEXT)
+
# Toolchain flags
WARNFLAGS := -Wall -Wextra -Wundef -Wpointer-arith -Wcast-align \
-Wwrite-strings -Wstrict-prototypes \
@@ -36,6 +39,9 @@ else
CFLAGS := $(CFLAGS) -Dinline="__inline__"
endif
+TESTCFLAGS := -g -O2
+TESTLDFLAGS := -lm -l$(COMPONENT) $(TESTLDFLAGS)
+
include $(NSBUILD)/Makefile.top
# Extra installation rules
diff --git a/test/Makefile b/test/Makefile
new file mode 100644
index 0000000..1402632
--- /dev/null
+++ b/test/Makefile
@@ -0,0 +1,3 @@
+DIR_TEST_ITEMS := decode_rosprite:decode_rosprite.c
+
+include $(NSBUILD)/Makefile.subdir
diff --git a/test/decode_rosprite.c b/test/decode_rosprite.c
new file mode 100644
index 0000000..c038b1f
--- /dev/null
+++ b/test/decode_rosprite.c
@@ -0,0 +1,135 @@
+/*
+ * Copyright 2018 Vincent Sanders <[email protected]>
+ *
+ * This file is part of NetSurf's librosprite, http://www.netsurf-browser.org/
+ * Licenced under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ */
+
+#include <assert.h>
+#include <errno.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/stat.h>
+#include "../include/librosprite.h"
+
+
+static void write_ppm(FILE* fh, const char *srcname, struct rosprite* sprite)
+{
+ fprintf(fh, "P3\n");
+ fprintf(fh, "# %s\n", srcname);
+
+ fprintf(fh, "# name %s\n", sprite->name);
+ fprintf(fh, "# color_model %s\n",
+ sprite->mode.color_model == ROSPRITE_RGB ? "RGB" : "CMYK");
+ fprintf(fh, "# colorbpp %u\n", sprite->mode.colorbpp);
+ fprintf(fh, "# xdpi %u\n", sprite->mode.xdpi);
+ fprintf(fh, "# ydpi %u\n", sprite->mode.ydpi);
+ fprintf(fh, "# width %u px\n", sprite->width);
+ fprintf(fh, "# height %u px\n", sprite->height);
+
+ fprintf(fh, "# hasPalette %s\n", sprite->has_palette ? "YES" : "NO");
+ if (sprite->has_palette) {
+ fprintf(fh, "# paletteSize %u\n", sprite->palettesize);
+ }
+ fprintf(fh, "# hasMask %s\n", sprite->has_mask ? "YES" : "NO");
+ if (sprite->has_mask) {
+ fprintf(fh, "# mask_width %u\n", sprite->mode.mask_width);
+ }
+ if (sprite->has_mask) {
+ fprintf(fh, "# maskbpp %u\n", sprite->mode.maskbpp);
+ }
+
+ fprintf(fh, "%u %u 256\n", sprite->width, sprite->height);
+
+
+ for (uint32_t y = 0; y < sprite->height; y++) {
+ for (uint32_t x = 0; x < sprite->width; x++) {
+ uint32_t color; /* color is 0xrrggbbaa */
+
+ color = sprite->image[y*sprite->width + x];
+ fprintf(fh, "%u %u %u ",
+ (color & 0xff000000) >> 24,
+ (color & 0x00ff0000) >> 16,
+ (color & 0x0000ff00) >> 8);
+
+ }
+ fprintf(fh, "\n");
+ }
+
+}
+
+
+int main(int argc, char *argv[])
+{
+
+ int res = 0;
+ FILE *inf;
+ FILE *outf = stdout;
+ struct rosprite_file_context *ctx;
+ struct rosprite_area *sprite_area;
+ unsigned int sprite_number = 0;/* number of sprite in sprite area to
convert */
+
+ if (argc < 2) {
+ fprintf(stderr, "Usage: %s image.spr [out]\n", argv[0]);
+ return 1;
+ }
+
+ inf = fopen(argv[1], "rb");
+ if (inf == NULL) {
+ fprintf(stderr, "Unable to open %s for reading\n", argv[1]);
+ return 3;
+ }
+
+ if (argc > 2) {
+ outf = fopen(argv[2], "w+");
+ if (outf == NULL) {
+ fprintf(stderr,
+ "Unable to open %s for writing\n", argv[2]);
+ fclose(inf);
+ return 2;
+ }
+ }
+
+ if (rosprite_create_file_context(inf, &ctx) != ROSPRITE_OK) {
+ fprintf(stderr, "Unable to create file context\n");
+ res = 4;
+ goto cleanup;
+ }
+
+ /* load sprites into sprite area */
+ if (rosprite_load(rosprite_file_reader,
+ ctx,
+ &sprite_area) != ROSPRITE_OK) {
+ fprintf(stderr, "Error loading spritefile\n");
+ res = 5;
+ goto cleanup;
+ };
+
+ if (sprite_number >= sprite_area->sprite_count) {
+ fprintf(stderr,
+ "Sprite %d of %d is not present in sprite pool\n",
+ sprite_number, sprite_area->sprite_count);
+ res = 6;
+ goto cleanup;
+ }
+
+ /* write out sprite */
+ write_ppm(outf, argv[1], sprite_area->sprites[sprite_number]);
+
+ rosprite_destroy_file_context(ctx);
+ rosprite_destroy_sprite_area(sprite_area);
+
+cleanup:
+
+ fclose(inf);
+
+ if (argc > 2) {
+ fclose(outf);
+ }
+
+ return res;
+}
diff --git a/test/runtest.sh b/test/runtest.sh
new file mode 100755
index 0000000..c5535d9
--- /dev/null
+++ b/test/runtest.sh
@@ -0,0 +1,58 @@
+#!/bin/sh
+
+# run test images through librosprite and count results
+
+TEST_PATH=$1
+TEST_OUT=${TEST_PATH}/ppm
+TEST_LOG=${TEST_PATH}/test.log
+
+mkdir -p ${TEST_OUT}
+
+echo "RO Sprite tests" > ${TEST_LOG}
+
+# netsurf test sprites
+SPRTESTS="test/sprite/*.spr"
+
+
+rospritedecode()
+{
+ OUTF=$(basename ${1} .spr)
+ CMPF=$(dirname ${1})/${OUTF}.ppm
+ echo "Icon:${1}" >> ${TEST_LOG}
+ ${TEST_PATH}/test_decode_rosprite ${1} ${TEST_OUT}/${OUTF}.ppm 2>>
${TEST_LOG}
+ if [ -f "${CMPF}" ]; then
+ cmp ${CMPF} ${TEST_OUT}/${OUTF}.ppm >> ${TEST_LOG} 2>> ${TEST_LOG}
+ if [ "$?" -ne 0 ]; then
+ return 128
+ fi
+ fi
+}
+
+# sprite tests
+
+SPRTESTTOTC=0
+SPRTESTPASSC=0
+SPRTESTERRC=0
+
+# netsurf test sprites
+for SPR in $(ls ${SPRTESTS});do
+ SPRTESTTOTC=$((SPRTESTTOTC+1))
+ rospritedecode ${SPR}
+ ECODE=$?
+ if [ \( "${ECODE}" -gt 127 \) -o \( "${ECODE}" -eq 1 \) ];then
+ SPRTESTERRC=$((SPRTESTERRC+1))
+ else
+ SPRTESTPASSC=$((SPRTESTPASSC+1))
+ fi
+done
+
+echo "Test sprite decode"
+echo "Tests:${SPRTESTTOTC} Pass:${SPRTESTPASSC} Error:${SPRTESTERRC}"
+
+
+# exit code
+if [ "${SPRTESTERRC}" -gt 0 ]; then
+ exit 1
+fi
+
+exit 0
diff --git a/test-data/32bpp-alpha-test b/test/sprite/32bpp-alpha-test.spr
similarity index 100%
rename from test-data/32bpp-alpha-test
rename to test/sprite/32bpp-alpha-test.spr
diff --git a/test-data/primary-color-16bpp b/test/sprite/primary-color-16bpp.spr
similarity index 100%
rename from test-data/primary-color-16bpp
rename to test/sprite/primary-color-16bpp.spr
diff --git a/test-data/small b/test/sprite/small.spr
similarity index 100%
rename from test-data/small
rename to test/sprite/small.spr
--
NetSurf RISC OS Sprite decoder
_______________________________________________
netsurf-commits mailing list
[email protected]
http://listmaster.pepperfish.net/cgi-bin/mailman/listinfo/netsurf-commits-netsurf-browser.org