Gfxprim
Threads by month
- ----- 2026 -----
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
November 2012
- 2 participants
- 28 discussions
[repo.or.cz] gfxprim.git branch master updated: a960a02a7e253fcdd2ec0cfa64f7d2f513719961
by metan 04 Nov '12
by metan 04 Nov '12
04 Nov '12
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via a960a02a7e253fcdd2ec0cfa64f7d2f513719961 (commit)
via 581ccfd2c21886816a54a99edf7e43a443506e5e (commit)
from 9f7de83d6395614ad22b2492340900a09f930db8 (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 -----------------------------------------------------------------
http://repo.or.cz/w/gfxprim.git/commit/a960a02a7e253fcdd2ec0cfa64f7d2f51371…
commit a960a02a7e253fcdd2ec0cfa64f7d2f513719961
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Nov 4 01:14:52 2012 +0100
loaders: Add PSP signature matching.
diff --git a/include/loaders/GP_PSP.h b/include/loaders/GP_PSP.h
index 4827a98..a44ae9b 100644
--- a/include/loaders/GP_PSP.h
+++ b/include/loaders/GP_PSP.h
@@ -58,4 +58,9 @@ GP_Context *GP_ReadPSP(FILE *f, GP_ProgressCallback *callback);
*/
GP_Context *GP_LoadPSP(const char *src_path, GP_ProgressCallback *callback);
+/*
+ * Match PSP signature.
+ */
+int GP_MatchPSP(const void *buf);
+
#endif /* LOADERS_GP_PSP_H */
diff --git a/libs/loaders/GP_Loader.c b/libs/loaders/GP_Loader.c
index 057322c..ab374c4 100644
--- a/libs/loaders/GP_Loader.c
+++ b/libs/loaders/GP_Loader.c
@@ -39,7 +39,7 @@
static GP_Loader psp_image = {
.Load = GP_LoadPSP,
.Save = NULL,
- .Match = NULL,
+ .Match = GP_MatchPSP,
.fmt_name = "Paint Shop Pro Image",
.next = NULL,
.extensions = {"psp", "pspimage", NULL},
diff --git a/libs/loaders/GP_PSP.c b/libs/loaders/GP_PSP.c
index 7ab8835..d77ee29 100644
--- a/libs/loaders/GP_PSP.c
+++ b/libs/loaders/GP_PSP.c
@@ -61,6 +61,11 @@ struct psp_version {
uint16_t minor;
};
+int GP_MatchPSP(const void *buf)
+{
+ return !memcmp(buf, PSP_SIGNATURE, PSP_SIGNATURE_LEN);
+}
+
int GP_OpenPSP(const char *src_path, FILE **f)
{
int err;
http://repo.or.cz/w/gfxprim.git/commit/581ccfd2c21886816a54a99edf7e43a44350…
commit 581ccfd2c21886816a54a99edf7e43a443506e5e
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Nov 4 00:56:48 2012 +0100
loaders: Add initial support for loader registration.
diff --git a/include/loaders/GP_Loaders.h b/include/loaders/GP_Loaders.h
index 5292608..d523494 100644
--- a/include/loaders/GP_Loaders.h
+++ b/include/loaders/GP_Loaders.h
@@ -49,33 +49,6 @@
#include "GP_MetaData.h"
-/*
- * Tries to load image accordingly to the file extension.
- *
- * If operation fails NULL is returned and errno is filled.
- */
-GP_Context *GP_LoadImage(const char *src_path, GP_ProgressCallback *callback);
-
-/*
- * Loads image Meta Data (if possible).
- */
-int GP_LoadMetaData(const char *src_path, GP_MetaData *data);
-
-/*
- * Simple saving function, the image format is matched by file extension.
- *
- * Retruns zero on succes.
- *
- * On failure non-zero is returned.
- *
- * When file type wasn't recognized by extension or if support for requested
- * image format wasn't compiled in non-zero is returned and errno is set to
- * ENOSYS.
- *
- * The resulting errno may also be set to any possible error from fopen(3), open(3),
- * write(3), fwrite(3), seek(3), etc..
- */
-int GP_SaveImage(const GP_Context *src, const char *dst_path,
- GP_ProgressCallback *callback);
+#include "GP_Loader.h"
#endif /* LOADERS_GP_LOADERS_H */
diff --git a/libs/loaders/GP_Loaders.c b/libs/loaders/GP_Loader.c
similarity index 70%
rename from libs/loaders/GP_Loaders.c
rename to libs/loaders/GP_Loader.c
index cef1821..057322c 100644
--- a/libs/loaders/GP_Loaders.c
+++ b/libs/loaders/GP_Loader.c
@@ -34,6 +34,122 @@
#include "GP_Loaders.h"
+#include "GP_Loader.h"
+
+static GP_Loader psp_image = {
+ .Load = GP_LoadPSP,
+ .Save = NULL,
+ .Match = NULL,
+ .fmt_name = "Paint Shop Pro Image",
+ .next = NULL,
+ .extensions = {"psp", "pspimage", NULL},
+};
+
+static GP_Loader *loaders = &psp_image;
+static GP_Loader *loaders_last = &psp_image;
+
+void GP_LoaderRegister(GP_Loader *self)
+{
+ GP_DEBUG(1, "Registering loader for '%s'", self->fmt_name);
+
+ self->next = NULL;
+ loaders_last->next = self;
+}
+
+void GP_LoaderUnregister(GP_Loader *self)
+{
+ struct GP_Loader *i;
+
+ if (self == NULL)
+ return;
+
+ GP_DEBUG(1, "Unregistering loader for '%s'", self->fmt_name);
+
+ for (i = loaders; i != NULL; i = i->next) {
+ if (i->next == self)
+ break;
+ }
+
+ if (i == NULL) {
+ GP_WARN("Loader '%s' (%p) wasn't registered",
+ self->fmt_name, self);
+ return;
+ }
+
+ i->next = self->next;
+}
+
+static struct GP_Loader *loader_by_extension(const char *ext)
+{
+ struct GP_Loader *i;
+ int j;
+
+ for (i = loaders; i != NULL; i = i->next) {
+ for (j = 0; i->extensions[j] != NULL; j++) {
+ if (!strcasecmp(ext, i->extensions[j])) {
+ GP_DEBUG(1, "Found loader '%s'", i->fmt_name);
+ return i;
+ }
+ }
+ }
+
+ return NULL;
+}
+
+static struct GP_Loader *loader_by_filename(const char *path)
+{
+ size_t len = strlen(path);
+ const char *ext;
+ int i;
+
+ for (i = len - 1; i >= 0; i--)
+ if (path[i] == '.')
+ break;
+
+ ext = path + i + 1;
+
+ GP_DEBUG(1, "Loading file by filename extension '%s'", ext);
+
+ return loader_by_extension(ext);
+}
+
+static struct GP_Loader *loader_by_signature(const char *path)
+{
+ uint8_t buf[32];
+ FILE *f;
+ int err;
+
+ GP_DEBUG(1, "Trying to match file signature");
+
+ f = fopen(path, "rb");
+
+ if (f == NULL) {
+ err = errno;
+ GP_DEBUG(1, "Failed to open file '%s'", path);
+ errno = err;
+ return NULL;
+ }
+
+ if (fread(buf, sizeof(buf), 1, f) < 1) {
+ GP_DEBUG(1, "Failed to read start of the file '%s'", path);
+ errno = EIO;
+ return NULL;
+ }
+
+ fclose(f);
+
+ struct GP_Loader *i;
+
+ for (i = loaders; i != NULL; i = i->next) {
+ if (i->Match && i->Match(buf)) {
+ GP_DEBUG(1, "Found loader '%s'", i->fmt_name);
+ return i;
+ }
+ }
+
+ return NULL;
+}
+
enum GP_ImageFmt {
GP_FMT_UNKNOWN,
GP_FMT_PNG,
@@ -178,6 +294,18 @@ GP_Context *GP_LoadImage(const char *src_path, GP_ProgressCallback *callback)
break;
}
+ struct GP_Loader *l;
+
+ l = loader_by_filename(src_path);
+
+ if (l != NULL)
+ return l->Load(src_path, callback);
+
+ l = loader_by_signature(src_path);
+
+ if (l != NULL)
+ return l->Load(src_path, callback);
+
//TODO file signature based check
errno = ENOSYS;
return NULL;
-----------------------------------------------------------------------
Summary of changes:
include/loaders/GP_Loaders.h | 29 +------
include/loaders/GP_PSP.h | 5 +
libs/loaders/{GP_Loaders.c => GP_Loader.c} | 128 ++++++++++++++++++++++++++++
libs/loaders/GP_PSP.c | 5 +
4 files changed, 139 insertions(+), 28 deletions(-)
rename libs/loaders/{GP_Loaders.c => GP_Loader.c} (70%)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: 9f7de83d6395614ad22b2492340900a09f930db8
by metan 03 Nov '12
by metan 03 Nov '12
03 Nov '12
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via 9f7de83d6395614ad22b2492340900a09f930db8 (commit)
via 36dac7fab1a5a700d756545b06b95c5352dd1615 (commit)
from 1a4cfc00663ccc76f058a87cc00c031ec57dd982 (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 -----------------------------------------------------------------
http://repo.or.cz/w/gfxprim.git/commit/9f7de83d6395614ad22b2492340900a09f93…
commit 9f7de83d6395614ad22b2492340900a09f930db8
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sat Nov 3 23:19:55 2012 +0100
tests: Add forgotten filters target to Makefile.
diff --git a/tests/Makefile b/tests/Makefile
index 6181430..7a0ad0d 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -1,10 +1,11 @@
TOPDIR=..
include $(TOPDIR)/pre.mk
-SUBDIRS=core SDL drivers framework loaders gfx
+SUBDIRS=core SDL drivers framework loaders gfx filters
loaders: framework
gfx: framework
core: framework
+filters: framework
include $(TOPDIR)/post.mk
http://repo.or.cz/w/gfxprim.git/commit/36dac7fab1a5a700d756545b06b95c5352dd…
commit 36dac7fab1a5a700d756545b06b95c5352dd1615
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sat Nov 3 23:18:26 2012 +0100
loaders: Add PSP Image loader.
The loader could extract composite image
from Paint Shop Pro Image format.
diff --git a/include/loaders/GP_Loaders.h b/include/loaders/GP_Loaders.h
index ab0f4ef..5292608 100644
--- a/include/loaders/GP_Loaders.h
+++ b/include/loaders/GP_Loaders.h
@@ -43,6 +43,7 @@
#include "GP_PNG.h"
#include "GP_JPG.h"
#include "GP_GIF.h"
+#include "GP_PSP.h"
#include "GP_TmpFile.h"
diff --git a/include/loaders/GP_Loaders.h b/include/loaders/GP_PSP.h
similarity index 55%
copy from include/loaders/GP_Loaders.h
copy to include/loaders/GP_PSP.h
index ab0f4ef..4827a98 100644
--- a/include/loaders/GP_Loaders.h
+++ b/include/loaders/GP_PSP.h
@@ -16,65 +16,46 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301 USA *
* *
- * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
- * <jiri.bluebear.dluhos(a)gmail.com> *
- * *
* Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
/*
-
- Core include file for loaders API.
+
+ Experimental Paint Shop Pro image loader.
*/
-#ifndef LOADERS_GP_LOADERS_H
-#define LOADERS_GP_LOADERS_H
+#ifndef LOADERS_GP_PSP_H
+#define LOADERS_GP_PSP_H
-#include "core/GP_Context.h"
#include "core/GP_ProgressCallback.h"
-
-#include "GP_PBM.h"
-#include "GP_PGM.h"
-#include "GP_PPM.h"
-
-#include "GP_BMP.h"
-#include "GP_PNG.h"
-#include "GP_JPG.h"
-#include "GP_GIF.h"
-
-#include "GP_TmpFile.h"
-
-#include "GP_MetaData.h"
+#include "core/GP_Context.h"
/*
- * Tries to load image accordingly to the file extension.
+ * The possible errno values:
*
- * If operation fails NULL is returned and errno is filled.
+ * - EIO for read/write failure
+ * - ENOSYS for not implemented bitmap format
+ * - ENOMEM from malloc()
+ * - EILSEQ for wrong image signature/data
+ * - ECANCELED when call was aborted from callback
*/
-GP_Context *GP_LoadImage(const char *src_path, GP_ProgressCallback *callback);
/*
- * Loads image Meta Data (if possible).
+ * Opens up the PSP image and checks signature.
+ * Returns zero on success.
*/
-int GP_LoadMetaData(const char *src_path, GP_MetaData *data);
+int GP_OpenPSP(const char *src_path, FILE **f);
/*
- * Simple saving function, the image format is matched by file extension.
- *
- * Retruns zero on succes.
- *
- * On failure non-zero is returned.
- *
- * When file type wasn't recognized by extension or if support for requested
- * image format wasn't compiled in non-zero is returned and errno is set to
- * ENOSYS.
- *
- * The resulting errno may also be set to any possible error from fopen(3), open(3),
- * write(3), fwrite(3), seek(3), etc..
+ * Reads image from PSP format.
+ */
+GP_Context *GP_ReadPSP(FILE *f, GP_ProgressCallback *callback);
+
+/*
+ * Does both GP_OpenPSP and GP_ReadPSP at once.
*/
-int GP_SaveImage(const GP_Context *src, const char *dst_path,
- GP_ProgressCallback *callback);
+GP_Context *GP_LoadPSP(const char *src_path, GP_ProgressCallback *callback);
-#endif /* LOADERS_GP_LOADERS_H */
+#endif /* LOADERS_GP_PSP_H */
diff --git a/libs/loaders/GP_Loaders.c b/libs/loaders/GP_Loaders.c
index b142e93..cef1821 100644
--- a/libs/loaders/GP_Loaders.c
+++ b/libs/loaders/GP_Loaders.c
@@ -40,6 +40,7 @@ enum GP_ImageFmt {
GP_FMT_JPG,
GP_FMT_BMP,
GP_FMT_GIF,
+ GP_FMT_PSP,
GP_FMT_PBM,
GP_FMT_PGM,
GP_FMT_PPM,
@@ -103,7 +104,7 @@ enum GP_ImageFmt filename_to_fmt(const char *path)
break;
}
break;
- /* BMP */
+ /* BMP, PSP */
case 'P':
case 'p':
switch (path[len - 2]) {
@@ -113,6 +114,12 @@ enum GP_ImageFmt filename_to_fmt(const char *path)
path[len - 3] == 'b')
return GP_FMT_BMP;
break;
+ case 'S':
+ case 's':
+ if (path[len - 3] == 'P' ||
+ path[len - 3] == 'p')
+ return GP_FMT_PSP;
+ break;
}
break;
/* GIF */
@@ -157,6 +164,8 @@ GP_Context *GP_LoadImage(const char *src_path, GP_ProgressCallback *callback)
return GP_LoadPNG(src_path, callback);
case GP_FMT_GIF:
return GP_LoadGIF(src_path, callback);
+ case GP_FMT_PSP:
+ return GP_LoadPSP(src_path, callback);
case GP_FMT_BMP:
return GP_LoadBMP(src_path, callback);
case GP_FMT_PBM:
@@ -165,7 +174,6 @@ GP_Context *GP_LoadImage(const char *src_path, GP_ProgressCallback *callback)
return GP_LoadPGM(src_path, callback);
case GP_FMT_PPM:
return GP_LoadPPM(src_path, callback);
-
case GP_FMT_UNKNOWN:
break;
}
diff --git a/libs/loaders/GP_PSP.c b/libs/loaders/GP_PSP.c
new file mode 100644
index 0000000..7ab8835
--- /dev/null
+++ b/libs/loaders/GP_PSP.c
@@ -0,0 +1,522 @@
+/*****************************************************************************
+ * This file is part of gfxprim library. *
+ * *
+ * Gfxprim is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU Lesser General Public *
+ * License as published by the Free Software Foundation; either *
+ * version 2.1 of the License, or (at your option) any later version. *
+ * *
+ * Gfxprim is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with gfxprim; if not, write to the Free Software *
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
+ * Boston, MA 02110-1301 USA *
+ * *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+/*
+
+ Paint Shop Pro Image loader.
+
+ Written using documentation available freely on the internet.
+
+ */
+
+#include <stdint.h>
+#include <inttypes.h>
+
+#include <ctype.h>
+#include <errno.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "core/GP_Debug.h"
+#include "core/GP_Pixel.h"
+#include "core/GP_GetPutPixel.h"
+#include "GP_JPG.h"
+#include "GP_PSP.h"
+
+#define BUF_TO_8(buf, off) + (buf[off] + (buf[off+1]<<8) + (buf[off+2]<<16) + (buf[off+3]<<24) + + ((uint64_t)buf[off+4]<<32) + ((uint64_t)buf[off+5]<<40) + + ((uint64_t)buf[off+6]<<48) + ((uint64_t)buf[off+7]<<56))
+
+#define BUF_TO_4(buf, off) + (buf[off] + (buf[off+1]<<8) + (buf[off+2]<<16) + (buf[off+3]<<24))
+
+#define BUF_TO_2(buf, off) + (buf[off] + (buf[off+1]<<8))
+
+#define PSP_SIGNATURE "Paint Shop Pro Image Filenx1a00000000"
+#define PSP_SIGNATURE_LEN 32
+
+struct psp_version {
+ uint16_t major;
+ uint16_t minor;
+};
+
+int GP_OpenPSP(const char *src_path, FILE **f)
+{
+ int err;
+
+ *f = fopen(src_path, "rb");
+
+ if (*f == NULL) {
+ err = errno;
+ GP_DEBUG(1, "Failed to open '%s' : %s",
+ src_path, strerror(errno));
+ goto err2;
+ }
+
+ char buf[36];
+
+ if (fread(buf, sizeof(buf), 1, *f) < 1) {
+ GP_DEBUG(1, "Failed to read file header");
+ err = EIO;
+ goto err1;
+ }
+
+ if (memcmp(buf, PSP_SIGNATURE, PSP_SIGNATURE_LEN)) {
+ GP_DEBUG(1, "Invalid signature, not a PSP image?");
+ err = EINVAL;
+ goto err1;
+ }
+
+ struct psp_version version;
+
+ version.major = BUF_TO_2(buf, 32);
+ version.minor = BUF_TO_2(buf, 34);
+
+ GP_DEBUG(1, "Have PSP image version %u.%u",
+ version.major, version.minor);
+
+ return 0;
+err1:
+ fclose(*f);
+err2:
+ errno = err;
+ return 1;
+}
+
+enum psp_block_id {
+ PSP_IMAGE_BLOCK,
+ PSP_CREATOR_BLOCK,
+ PSP_COLOR_BLOCK,
+ PSP_LAYER_START_BLOCK,
+ PSP_LAYER_BLOCK,
+ PSP_CHANNEL_BLOCK,
+ PSP_SELECTION_BLOCK,
+ PSP_ALPHA_BANK_BLOCK,
+ PSP_ALPHA_CHANNEL_BLOCK,
+ PSP_COMPOSITE_IMAGE_BLOCK,
+ PSP_EXTENDED_DATA_BLOCK,
+ PSP_TUBE_BLOCK,
+ PSP_ADJUSTMENT_EXTENSION_BLOCK,
+ PSP_VECTOR_EXTENSION_BLOCK,
+ PSP_SHAPE_BLOCK,
+ PSP_PAINTSTYLE_BLOCK,
+ PSP_COMPOSITE_IMAGE_BANK_BLOCK,
+ PSP_COMPOSITE_ATTRIBUTES_BLOCK,
+ PSP_JPEG_BLOCK,
+};
+
+static const char *psp_block_id_name(enum psp_block_id id)
+{
+ switch (id) {
+ case PSP_IMAGE_BLOCK:
+ return "Image";
+ case PSP_CREATOR_BLOCK:
+ return "Creator";
+ case PSP_COLOR_BLOCK:
+ return "Color";
+ case PSP_LAYER_START_BLOCK:
+ return "Layer Start";
+ case PSP_LAYER_BLOCK:
+ return "Layer";
+ case PSP_CHANNEL_BLOCK:
+ return "Channel";
+ case PSP_SELECTION_BLOCK:
+ return "Selection";
+ case PSP_ALPHA_BANK_BLOCK:
+ return "Alpha Bank";
+ case PSP_ALPHA_CHANNEL_BLOCK:
+ return "Alpha Channel";
+ case PSP_COMPOSITE_IMAGE_BLOCK:
+ return "Composite image";
+ case PSP_EXTENDED_DATA_BLOCK:
+ return "Extended Data";
+ case PSP_TUBE_BLOCK:
+ return "Tube";
+ case PSP_ADJUSTMENT_EXTENSION_BLOCK:
+ return "Adjustment Extension";
+ case PSP_VECTOR_EXTENSION_BLOCK:
+ return "Vector Extension";
+ case PSP_SHAPE_BLOCK:
+ return "Shape";
+ case PSP_PAINTSTYLE_BLOCK:
+ return "Paintstyle";
+ case PSP_COMPOSITE_IMAGE_BANK_BLOCK:
+ return "Composite Image Bank";
+ case PSP_COMPOSITE_ATTRIBUTES_BLOCK:
+ return "Composite Attributes";
+ case PSP_JPEG_BLOCK:
+ return "JPEG";
+ default:
+ return "Unknown";
+ }
+}
+
+enum psp_comp_type {
+ PSP_COMP_NONE,
+ PSP_COMP_RLE,
+ PSP_COMP_LZ77,
+ PSP_COMP_JPEG,
+};
+
+static const char *psp_comp_type_name(enum psp_comp_type type)
+{
+ switch (type) {
+ case PSP_COMP_NONE:
+ return "None";
+ case PSP_COMP_RLE:
+ return "RLE";
+ case PSP_COMP_LZ77:
+ return "LZ77";
+ case PSP_COMP_JPEG:
+ return "JPEG";
+ default:
+ return "Unknown";
+ }
+}
+
+struct psp_img_attrs {
+ int32_t w;
+ int32_t h;
+ /* resolution */
+ double res;
+ uint8_t res_metric;
+ /* compression, enum psp_comp_type */
+ uint16_t comp_type;
+ /* bit depth must be 1, 4, 8 or 24 */
+ uint16_t bit_depth;
+ /* plane count, must be 1 */
+ uint16_t plane_count;
+ /* color count = 2 ^ bit_depth */
+ uint16_t color_count;
+ /* grayscale flag, 0 -> not grayscale, 1 -> grayscale */
+ uint8_t grayscale_flag;
+ /* sum of the sizes of all layer color bitmaps */
+ uint32_t total_img_size;
+ /* active layer at the time of saving */
+ uint32_t active_layer;
+ uint16_t layer_count;
+
+ /* internal loader flags */
+ int is_loaded:1;
+ uint8_t subblock;
+ void *priv;
+ GP_Context *img;
+};
+
+static int psp_read_general_img_attr_chunk(FILE *f,
+ struct psp_img_attrs *attrs)
+{
+ uint8_t buf[38];
+
+ if (attrs->is_loaded) {
+ GP_WARN("Found Second Image Block");
+ return EINVAL;
+ }
+
+ //TODO SHIFT!!!
+ if (fread(buf, 4, 1, f) < 1) {
+ GP_DEBUG(1, "Failed to read Image block header");
+ return EIO;
+ }
+
+ if (fread(buf, sizeof(buf), 1, f) < 1) {
+ GP_DEBUG(1, "Failed to read Image chunk data");
+ return EIO;
+ }
+
+ attrs->w = BUF_TO_4(buf, 0);
+ attrs->h = BUF_TO_4(buf, 4);
+ attrs->res = BUF_TO_8(buf, 8);
+ attrs->res_metric = buf[16];
+ attrs->comp_type = BUF_TO_2(buf, 17);
+ attrs->bit_depth = BUF_TO_2(buf, 19);
+ attrs->plane_count = BUF_TO_2(buf, 21);
+ attrs->color_count = BUF_TO_2(buf, 23);
+ attrs->grayscale_flag = buf[25];
+ attrs->total_img_size = BUF_TO_4(buf, 26);
+ attrs->active_layer = BUF_TO_4(buf, 32);
+ attrs->layer_count = BUF_TO_2(buf, 36);
+
+ GP_DEBUG(3, "Image w=%u h=%u, compress=%s, bit_depth=%u, grayscale=%u",
+ attrs->w, attrs->h, psp_comp_type_name(attrs->comp_type),
+ attrs->bit_depth, attrs->grayscale_flag);
+
+ GP_DEBUG(3, "Image colors=%u, layer_count=%u, active_layer=%u",
+ attrs->color_count, attrs->layer_count, attrs->active_layer);
+
+ attrs->is_loaded = 1;
+
+ return 0;
+}
+
+static int psp_next_block(FILE *f, struct psp_img_attrs *attrs,
+ GP_ProgressCallback *callback);
+
+static int psp_read_layer_start_block(FILE *f, struct psp_img_attrs *attrs,
+ GP_ProgressCallback *callback)
+{
+ int i;
+
+ /* we are allready in subblock -> error */
+ if (attrs->subblock) {
+ GP_WARN("Layer Start block inside of Subblock");
+ return EINVAL;
+ }
+
+ attrs->subblock++;
+
+ for (i = 0; i < attrs->layer_count; i++)
+ psp_next_block(f, attrs, callback);
+
+ attrs->subblock--;
+
+ return 0;
+}
+
+static int psp_read_composite_image_block(FILE *f, struct psp_img_attrs *attrs,
+ GP_ProgressCallback *callback)
+{
+ uint8_t buf[8];
+ uint32_t chunk_size;
+ uint32_t i, composite_image_count;
+
+ /* we are allready in subblock -> error */
+ if (attrs->subblock) {
+ GP_WARN("Composite Image Bank block inside of a Subblock");
+ return EINVAL;
+ }
+
+ if (fread(buf, sizeof(buf), 1, f) < 1) {
+ GP_DEBUG(1, "Failed to read Composite Image Bank Info Chunk");
+ return EIO;
+ }
+
+ chunk_size = BUF_TO_4(buf, 0);
+ composite_image_count = BUF_TO_4(buf, 4);
+
+ //TODO: utilize chunk_size
+
+ GP_DEBUG(3, "Composite image count=%u", composite_image_count);
+
+ attrs->subblock++;
+
+ for (i = 0; i < composite_image_count; i++)
+ psp_next_block(f, attrs, callback);
+
+ attrs->subblock--;
+
+ return 0;
+}
+
+enum psp_comp_img_type {
+ PSP_IMAGE_COMPOSITE,
+ PSP_IMAGE_THUMBNAIL,
+};
+
+static const char *psp_comp_img_type_name(enum psp_comp_img_type type)
+{
+ switch (type) {
+ case PSP_IMAGE_COMPOSITE:
+ return "Composite";
+ case PSP_IMAGE_THUMBNAIL:
+ return "Thumbnail";
+ default:
+ return "Unknown";
+ }
+}
+
+struct psp_comp_img_attr_info {
+ uint32_t w;
+ uint32_t h;
+ uint16_t bit_depth;
+ uint16_t comp_type;
+ uint16_t plane_count;
+ uint32_t color_count;
+ uint16_t comp_img_type;
+};
+
+static int psp_read_composite_attributes_block(FILE *f, struct psp_img_attrs *attrs,
+ GP_ProgressCallback *callback)
+{
+ uint8_t buf[24];
+ struct psp_comp_img_attr_info info;
+ uint32_t chunk_size;
+
+ if (fread(buf, sizeof(buf), 1, f) < 1) {
+ GP_DEBUG(1, "Failed to read Composite Image Bank Info Chunk");
+ return EIO;
+ }
+
+ chunk_size = BUF_TO_4(buf, 0);
+
+ info.w = BUF_TO_4(buf, 4);
+ info.h = BUF_TO_4(buf, 8);
+ info.bit_depth = BUF_TO_2(buf, 12);
+ info.comp_type = BUF_TO_2(buf, 14);
+ info.plane_count = BUF_TO_2(buf, 16);
+ info.color_count = BUF_TO_4(buf, 18);
+ info.comp_img_type = BUF_TO_2(buf, 22);
+
+ GP_DEBUG(4, "Composite Image w=%u h=%u, bit_depth=%u, comp_type=%s, "
+ "comp_img_type=%s",
+ info.w, info.h, info.bit_depth, psp_comp_type_name(info.comp_type),
+ psp_comp_img_type_name(info.comp_img_type));
+
+ attrs->priv = &info;
+ attrs->subblock++;
+
+ if (info.comp_img_type == PSP_IMAGE_COMPOSITE)
+ psp_next_block(f, attrs, callback);
+
+ attrs->subblock--;
+ attrs->priv = NULL;
+
+ return 0;
+}
+
+static int psp_read_jpeg(FILE *f, struct psp_img_attrs *attrs,
+ GP_ProgressCallback *callback)
+{
+ uint8_t buf[14];
+ uint32_t chunk_size;
+ int err;
+
+ if (fread(buf, sizeof(buf), 1, f) < 1) {
+ GP_DEBUG(1, "Failed to read JPEG Information Chunk");
+ return EIO;
+ }
+
+ chunk_size = BUF_TO_4(buf, 0);
+
+ //TODO: utilize chunk_size
+
+ GP_DEBUG(5, "JPEG Chunk");
+
+ attrs->img = GP_ReadJPG(f, callback);
+
+ if (attrs->img == NULL) {
+ err = errno;
+ GP_WARN("Failed to load JPEG Data Chunk %s", strerror(err));
+ return err;
+ }
+
+ return 0;
+}
+
+#define GEN_IMG_HEADER_ID "~BK"
+#define GEN_IMG_HEADER_ID_LEN 4
+
+static int psp_next_block(FILE *f, struct psp_img_attrs *attrs,
+ GP_ProgressCallback *callback)
+{
+ uint8_t buf[10];
+ uint16_t block_id;
+ uint32_t block_size;
+ long offset;
+ int err = 0;
+
+ if (fread(buf, sizeof(buf), 1, f) < 1) {
+ GP_DEBUG(1, "Failed to read block header");
+ return EIO;
+ }
+
+ if (memcmp(buf, GEN_IMG_HEADER_ID, GEN_IMG_HEADER_ID_LEN)) {
+ GP_DEBUG(1, "Invalid block header identifier");
+ return EINVAL;
+ }
+
+ block_id = BUF_TO_2(buf, 4);
+ block_size = BUF_TO_4(buf, 6);
+
+ GP_DEBUG(2 + attrs->subblock, "%s Block size %u",
+ psp_block_id_name(block_id), block_size);
+
+ offset = ftell(f) + block_size;
+
+ switch (block_id) {
+ case PSP_IMAGE_BLOCK:
+ err = psp_read_general_img_attr_chunk(f, attrs);
+ break;
+ case PSP_LAYER_START_BLOCK:
+ err = psp_read_layer_start_block(f, attrs, callback);
+ break;
+ case PSP_COMPOSITE_IMAGE_BANK_BLOCK:
+ err = psp_read_composite_image_block(f, attrs, callback);
+ break;
+ case PSP_COMPOSITE_ATTRIBUTES_BLOCK:
+ err = psp_read_composite_attributes_block(f, attrs, callback);
+ break;
+ case PSP_JPEG_BLOCK:
+ err = psp_read_jpeg(f, attrs, callback);
+ break;
+ }
+
+ if (err)
+ return err;
+
+ if (fseek(f, offset, SEEK_SET) == -1) {
+ err = errno;
+ GP_DEBUG(1, "Failed to seek to next block");
+ return errno;
+ }
+
+ return 0;
+}
+
+GP_Context *GP_ReadPSP(FILE *f, GP_ProgressCallback *callback)
+{
+ int err = 0;
+ struct psp_img_attrs attrs = {.is_loaded = 0, .subblock = 0,
+ .priv = NULL, .img = NULL};
+
+ while (!err) {
+ err = psp_next_block(f, &attrs, callback);
+
+ if (err)
+ goto err1;
+
+ if (attrs.img != NULL) {
+ fclose(f);
+ return attrs.img;
+ }
+ }
+
+ fclose(f);
+ errno = ENOSYS;
+ return NULL;
+err1:
+ fclose(f);
+ errno = err;
+ return NULL;
+}
+
+GP_Context *GP_LoadPSP(const char *src_path, GP_ProgressCallback *callback)
+{
+ FILE *f;
+
+ if (GP_OpenPSP(src_path, &f))
+ return NULL;
+
+ return GP_ReadPSP(f, callback);
+}
-----------------------------------------------------------------------
Summary of changes:
include/loaders/GP_Loaders.h | 1 +
include/loaders/{GP_GIF.h => GP_PSP.h} | 20 +-
libs/loaders/GP_Loaders.c | 12 +-
libs/loaders/GP_PSP.c | 522 ++++++++++++++++++++++++++++++++
tests/Makefile | 3 +-
5 files changed, 545 insertions(+), 13 deletions(-)
copy include/loaders/{GP_GIF.h => GP_PSP.h} (82%)
create mode 100644 libs/loaders/GP_PSP.c
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: 1a4cfc00663ccc76f058a87cc00c031ec57dd982
by metan 02 Nov '12
by metan 02 Nov '12
02 Nov '12
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via 1a4cfc00663ccc76f058a87cc00c031ec57dd982 (commit)
from f7e6f933c737b7904e59d85438747f27785a89ac (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 -----------------------------------------------------------------
http://repo.or.cz/w/gfxprim.git/commit/1a4cfc00663ccc76f058a87cc00c031ec57d…
commit 1a4cfc00663ccc76f058a87cc00c031ec57dd982
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Nov 2 16:33:03 2012 +0100
tests: framework: Make output silent by default.
- shuffle some code to cleanup the sources
- add verbose switch and set it off by default
- add global runtest script to execute all testsuites
diff --git a/tests/framework/Makefile b/tests/framework/Makefile
index f3e22a1..a688952 100644
--- a/tests/framework/Makefile
+++ b/tests/framework/Makefile
@@ -17,7 +17,7 @@ ALL+=libtst_preload.so libtst.a
libtst_preload.so: tst_preload.o tst_alloc_barriers.o tst_preload_FILE.o
gcc -Wl,-soname -Wl,tst_preload.so --shared -ldl -fPIC $^ -o $@
-libtst.a: tst_test.o tst_job.o tst_msg.o tst_log.o tst_main.o tst_timespec.o
+libtst.a: tst_suite.o tst_job.o tst_msg.o tst_log.o tst_main.o tst_timespec.o
ar rcs $@ $^
CLEAN+=libtst_preload.so libtst.a log.html log.json
diff --git a/tests/framework/tst_job.c b/tests/framework/tst_job.c
index ce39d41..e60736b 100644
--- a/tests/framework/tst_job.c
+++ b/tests/framework/tst_job.c
@@ -33,7 +33,6 @@
#include <stdarg.h>
#include <math.h>
-#include "tst_preload.h"
#include "tst_test.h"
#include "tst_job.h"
#include "tst_timespec.h"
@@ -48,100 +47,6 @@ static int in_child(void)
return my_job != NULL;
}
-static void start_test(struct tst_job *job)
-{
- (void)job;
-// fprintf(stderr, "Starting test e[1;37m%se[0mn", job->test->name);
-}
-
-void tst_diff_timespec(int *sec, int *nsec, struct timespec *start,
- struct timespec *stop)
-{
- if (stop->tv_nsec < start->tv_nsec) {
- *sec = stop->tv_sec - start->tv_sec - 1;
- *nsec = stop->tv_nsec + 1000000000 - start->tv_nsec;
- } else {
- *sec = stop->tv_sec - start->tv_sec;
- *nsec = stop->tv_nsec - start->tv_nsec;
- }
-}
-
-#define NAME_PADD 35
-
-static void stop_test(struct tst_job *job)
-{
- const char *name = job->test->name;
- int sec, nsec;
- const char *result = "";
-
- tst_diff_timespec(&sec, &nsec, &job->start_time, &job->stop_time);
-
- switch (job->result) {
- case TST_SUCCESS:
- result = "[ e[1;32mSUCCESSe[0m ]";
- break;
- case TST_SKIPPED:
- result = "[ e[1;30mSKIPPEDe[0m ]";
- break;
- case TST_UNTESTED:
- result = "[ e[1;34mUNTESTEDe[0m ]";
- break;
- case TST_INTERR:
- result = "[ e[1;31mINTERNAL ERRORe[0m ]";
- break;
- case TST_SIGSEGV:
- result = "[ e[1;31mSEGFAULTe[0m ]";
- break;
- case TST_TIMEOUT:
- result = "[ e[1;35mTIMEOUTe[0m ]";
- break;
- case TST_ABORTED:
- result = "[ e[1;31mABORTEDe[0m ]";
- break;
- case TST_FPE:
- result = "[ e[1;31mFP EXCEPTIONe[0m ]";
- break;
- case TST_MEMLEAK:
- result = "[ e[1;33mMEMLEAKe[0m ]";
- break;
- case TST_FAILED:
- result = "[ e[1;31mFAILUREe[0m ]";
- break;
- case TST_MAX:
- break;
- }
-
- fprintf(stderr, "e[1;37m%se[0m", name);
-
- int i;
-
- for (i = strlen(name); i < NAME_PADD; i++)
- fprintf(stderr, " ");
-
- fprintf(stderr, " finished (Time %3i.%03is) %sn",
- sec, nsec/1000000, result);
-
- if (job->bench_iter) {
- for (i = 0; i < NAME_PADD; i++)
- fprintf(stderr, " ");
-
- fprintf(stderr, " bench CPU time %i.%06is +/- %i.%06isn",
- (int)job->bench_mean.tv_sec,
- (int)job->bench_mean.tv_nsec/1000,
- (int)job->bench_var.tv_sec,
- (int)job->bench_var.tv_nsec/1000);
- }
-
- if (job->result == TST_MEMLEAK)
- tst_malloc_print(&job->malloc_stats);
-
- /* Now print test message store */
- tst_msg_print(&job->store);
-
- fprintf(stderr, "------------------------------------------------------"
- "------------------------- n");
-}
-
/*
* Removes recursively temporary directory.
*/
@@ -438,9 +343,6 @@ void tst_job_run(struct tst_job *job)
/* Prepare the test message store */
tst_msg_init(&job->store);
- /* marks test as started */
- start_test(job);
-
/* copy benchmark interation */
job->bench_iter = job->test->bench_iter;
@@ -667,8 +569,6 @@ void tst_job_collect(struct tst_job *job)
/* Write down stop time */
clock_gettime(CLOCK_MONOTONIC, &job->stop_time);
-
- stop_test(job);
}
void tst_job_wait(struct tst_job *job)
diff --git a/tests/framework/tst_job.h b/tests/framework/tst_job.h
index 76984e5..171c0f0 100644
--- a/tests/framework/tst_job.h
+++ b/tests/framework/tst_job.h
@@ -90,7 +90,4 @@ void tst_job_run(struct tst_job *job);
*/
void tst_job_wait(struct tst_job *job);
-void tst_diff_timespec(int *sec, int *nsec, struct timespec *start,
- struct timespec *stop);
-
#endif /* TST_JOB_H */
diff --git a/tests/framework/tst_log.c b/tests/framework/tst_log.c
index a70f8c0..9daec17 100644
--- a/tests/framework/tst_log.c
+++ b/tests/framework/tst_log.c
@@ -27,6 +27,7 @@
#include "tst_job.h"
#include "tst_msg.h"
#include "tst_preload.h"
+#include "tst_timespec.h"
#include "tst_log.h"
static const char *ret_to_bg_color(enum tst_ret ret)
@@ -249,7 +250,7 @@ static int append_html(struct tst_job *job, FILE *f)
static int hack_counter = 0;
const char *bgcol;
- tst_diff_timespec(&sec, &nsec, &job->start_time, &job->stop_time);
+ timespec_diff(&sec, &nsec, &job->start_time, &job->stop_time);
if (hack_counter)
bgcol = "#ccccee";
@@ -375,7 +376,7 @@ static int append_json(struct tst_job *job, FILE *f)
/* Time statistics */
int sec, nsec;
- tst_diff_timespec(&sec, &nsec, &job->start_time, &job->stop_time);
+ timespec_diff(&sec, &nsec, &job->start_time, &job->stop_time);
fprintf(f, "ttt"CPU Time": %i.%09i,n",
(int)job->cpu_time.tv_sec, (int)job->cpu_time.tv_nsec);
diff --git a/tests/framework/tst_main.c b/tests/framework/tst_main.c
index 28020a0..d1c6474 100644
--- a/tests/framework/tst_main.c
+++ b/tests/framework/tst_main.c
@@ -28,12 +28,16 @@
extern const struct tst_suite tst_suite;
+/* defined in tst_suite.c */
+extern int tst_suite_verbose;
+
void print_help(void)
{
fprintf(stderr, "Test suite '%s' Usage:nn", tst_suite.suite_name);
fprintf(stderr, "-h prints this helpn");
fprintf(stderr, "-l list all testsn");
fprintf(stderr, "-t name runs single test by namen");
+ fprintf(stderr, "-v turns on verbose moden");
fprintf(stderr, "without any option, all tests are executedn");
}
@@ -41,7 +45,7 @@ int main(int argc, char *argv[])
{
int opt;
- while ((opt = getopt(argc, argv, "hlt:")) != -1) {
+ while ((opt = getopt(argc, argv, "hlt:v")) != -1) {
switch (opt) {
case 'l':
tst_list_suite(&tst_suite);
@@ -55,6 +59,9 @@ int main(int argc, char *argv[])
print_help();
return 0;
break;
+ case 'v':
+ tst_suite_verbose = 1;
+ break;
default:
print_help();
return 1;
diff --git a/tests/framework/tst_msg.c b/tests/framework/tst_msg.c
index 852fb81..8deafd1 100644
--- a/tests/framework/tst_msg.c
+++ b/tests/framework/tst_msg.c
@@ -85,7 +85,7 @@ static char type_to_char(enum tst_report_type type)
}
}
-void tst_msg_print(struct tst_msg_store *self)
+void tst_msg_print(const struct tst_msg_store *self)
{
struct tst_msg *msg;
diff --git a/tests/framework/tst_msg.h b/tests/framework/tst_msg.h
index a6a290a..f144851 100644
--- a/tests/framework/tst_msg.h
+++ b/tests/framework/tst_msg.h
@@ -62,6 +62,6 @@ int tst_msg_append(struct tst_msg_store *self, int type, const char *msg);
/*
* Prints messages in the store.
*/
-void tst_msg_print(struct tst_msg_store *self);
+void tst_msg_print(const struct tst_msg_store *self);
#endif /* TST_MSG_H */
diff --git a/tests/framework/tst_preload.c b/tests/framework/tst_preload.c
index 7241926..aec364f 100644
--- a/tests/framework/tst_preload.c
+++ b/tests/framework/tst_preload.c
@@ -146,7 +146,7 @@ void free(void *ptr)
real_free(ptr);
}
-void tst_malloc_print(struct malloc_stats *stats)
+void tst_malloc_print(const struct malloc_stats *stats)
{
fprintf(stderr, "Total size %zu chunks %u, lost size %zu chunks %un",
stats->total_size, stats->total_chunks,
diff --git a/tests/framework/tst_preload.h b/tests/framework/tst_preload.h
index d103e8c..0c44d3d 100644
--- a/tests/framework/tst_preload.h
+++ b/tests/framework/tst_preload.h
@@ -65,6 +65,6 @@ void tst_malloc_check_report(struct malloc_stats *stats);
/*
* Prints malloc statistics.
*/
-void tst_malloc_print(struct malloc_stats *stats);
+void tst_malloc_print(const struct malloc_stats *stats);
#endif /* TST_PRELOAD_H */
diff --git a/tests/framework/tst_suite.c b/tests/framework/tst_suite.c
new file mode 100644
index 0000000..1c0440b
--- /dev/null
+++ b/tests/framework/tst_suite.c
@@ -0,0 +1,195 @@
+/*****************************************************************************
+ * This file is part of gfxprim library. *
+ * *
+ * Gfxprim is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU Lesser General Public *
+ * License as published by the Free Software Foundation; either *
+ * version 2.1 of the License, or (at your option) any later version. *
+ * *
+ * Gfxprim is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with gfxprim; if not, write to the Free Software *
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
+ * Boston, MA 02110-1301 USA *
+ * *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <stdarg.h>
+
+#include "tst_log.h"
+#include "tst_job.h"
+#include "tst_test.h"
+#include "tst_preload.h"
+#include "tst_timespec.h"
+
+#define NAME_PADD 35
+
+int tst_suite_verbose = 0;
+
+static void test_job_report(const struct tst_job *job)
+{
+ const char *name = job->test->name;
+ int sec, nsec;
+ const char *result = "";
+
+ if ((job->result == TST_SUCCESS || job->result == TST_SKIPPED)
+ && !tst_suite_verbose)
+ return;
+
+ timespec_diff(&sec, &nsec, &job->start_time, &job->stop_time);
+
+ switch (job->result) {
+ case TST_SUCCESS:
+ result = "[ e[1;32mSUCCESSe[0m ]";
+ break;
+ case TST_SKIPPED:
+ result = "[ e[1;30mSKIPPEDe[0m ]";
+ break;
+ case TST_UNTESTED:
+ result = "[ e[1;34mUNTESTEDe[0m ]";
+ break;
+ case TST_INTERR:
+ result = "[ e[1;31mINTERNAL ERRORe[0m ]";
+ break;
+ case TST_SIGSEGV:
+ result = "[ e[1;31mSEGFAULTe[0m ]";
+ break;
+ case TST_TIMEOUT:
+ result = "[ e[1;35mTIMEOUTe[0m ]";
+ break;
+ case TST_ABORTED:
+ result = "[ e[1;31mABORTEDe[0m ]";
+ break;
+ case TST_FPE:
+ result = "[ e[1;31mFP EXCEPTIONe[0m ]";
+ break;
+ case TST_MEMLEAK:
+ result = "[ e[1;33mMEMLEAKe[0m ]";
+ break;
+ case TST_FAILED:
+ result = "[ e[1;31mFAILUREe[0m ]";
+ break;
+ case TST_MAX:
+ break;
+ }
+
+ fprintf(stderr, "e[1;37m%se[0m", name);
+
+ int i;
+
+ for (i = strlen(name); i < NAME_PADD; i++)
+ fprintf(stderr, " ");
+
+ fprintf(stderr, " finished (Time %3i.%03is) %sn",
+ sec, nsec/1000000, result);
+
+ if (job->bench_iter) {
+ for (i = 0; i < NAME_PADD; i++)
+ fprintf(stderr, " ");
+
+ fprintf(stderr, " bench CPU time %i.%06is +/- %i.%06isn",
+ (int)job->bench_mean.tv_sec,
+ (int)job->bench_mean.tv_nsec/1000,
+ (int)job->bench_var.tv_sec,
+ (int)job->bench_var.tv_nsec/1000);
+ }
+
+ if (job->result == TST_MEMLEAK)
+ tst_malloc_print(&job->malloc_stats);
+
+ /* Now print test message store */
+ tst_msg_print(&job->store);
+
+ fprintf(stderr, "------------------------------------------------------"
+ "------------------------- n");
+}
+
+static int run_test(const struct tst_test *test, FILE *html, FILE *json)
+{
+ struct tst_job job;
+
+ job.test = test;
+
+ /*
+ * Flush the file before forking, otherwise
+ * there would be a copy of its buffers in both
+ * child and parent and the lines in the resulting
+ * file would be repeated several times.
+ */
+ fflush(html);
+ fflush(json);
+
+ tst_job_run(&job);
+ tst_job_wait(&job);
+
+ /* report result into stdout */
+ test_job_report(&job);
+
+ tst_log_append(&job, html, TST_LOG_HTML);
+ tst_log_append(&job, json, TST_LOG_JSON);
+
+ /* Free the test message store */
+ tst_msg_clear(&job.store);
+
+ return job.result;
+}
+
+void tst_run_suite(const struct tst_suite *suite, const char *tst_name)
+{
+ unsigned int i;
+ unsigned int counters[TST_MAX] = {};
+ unsigned int counter = 0;
+ int ret;
+
+ fprintf(stderr, "Running e[1;37m%se[0mnn", suite->suite_name);
+
+ //TODO:
+ FILE *html = tst_log_open(suite, "log.html", TST_LOG_HTML);
+ FILE *json = tst_log_open(suite, "log.json", TST_LOG_JSON);
+
+ for (i = 0; suite->tests[i].name != NULL; i++) {
+ if (tst_name == NULL || !strcmp(tst_name, suite->tests[i].name)) {
+ ret = run_test(&suite->tests[i], html, json);
+ counters[ret]++;
+
+ if (ret != TST_SKIPPED)
+ counter++;
+ }
+ }
+
+ tst_log_close(html, TST_LOG_HTML);
+ tst_log_close(json, TST_LOG_JSON);
+
+ float percents;
+
+ if (counter == 0)
+ percents = 100;
+ else
+ percents = 100.00 * counters[0] / counter;
+
+ fprintf(stderr, "nSummary: succedded %u out of "
+ "%u %.2f%% (skipped %u)n",
+ counters[0], counter, percents,
+ counters[TST_SKIPPED]);
+}
+
+void tst_list_suite(const struct tst_suite *suite)
+{
+ int i;
+
+ fprintf(stderr, "Testsuite: e[1;37m%se[0mnn", suite->suite_name);
+
+ for (i = 0; suite->tests[i].name != NULL; i++)
+ fprintf(stderr, "Test: e[1;37m%se[0mn", suite->tests[i].name);
+}
diff --git a/tests/framework/tst_test.c b/tests/framework/tst_test.c
deleted file mode 100644
index 62666da..0000000
--- a/tests/framework/tst_test.c
+++ /dev/null
@@ -1,108 +0,0 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-#include <stdarg.h>
-
-#include "tst_log.h"
-#include "tst_job.h"
-#include "tst_test.h"
-
-static int run_test(const struct tst_test *test, FILE *html, FILE *json)
-{
- struct tst_job job;
-
- job.test = test;
-
- /*
- * Flush the file before forking, otherwise
- * there would be a copy of its buffers in both
- * child and parent and the lines in the resulting
- * file would be repeated several times.
- */
- fflush(html);
- fflush(json);
-
- tst_job_run(&job);
- tst_job_wait(&job);
-
- tst_log_append(&job, html, TST_LOG_HTML);
- tst_log_append(&job, json, TST_LOG_JSON);
-
- /* Free the test message store */
- tst_msg_clear(&job.store);
-
- return job.result;
-}
-
-void tst_run_suite(const struct tst_suite *suite, const char *tst_name)
-{
- unsigned int i;
- unsigned int counters[TST_MAX] = {};
- unsigned int counter = 0;
- int ret;
-
- fprintf(stderr, "Running e[1;37m%se[0mnn", suite->suite_name);
-
- //TODO:
- FILE *html = tst_log_open(suite, "log.html", TST_LOG_HTML);
- FILE *json = tst_log_open(suite, "log.json", TST_LOG_JSON);
-
- for (i = 0; suite->tests[i].name != NULL; i++) {
- if (tst_name == NULL || !strcmp(tst_name, suite->tests[i].name)) {
- ret = run_test(&suite->tests[i], html, json);
- counters[ret]++;
-
- if (ret != TST_SKIPPED)
- counter++;
- }
- }
-
- tst_log_close(html, TST_LOG_HTML);
- tst_log_close(json, TST_LOG_JSON);
-
- float percents;
-
- if (counter == 0)
- percents = 100;
- else
- percents = 100.00 * counters[0] / counter;
-
- fprintf(stderr, "nSummary: succedded %u out of "
- "%u %.2f%% (skipped %u)n",
- counters[0], counter, percents,
- counters[TST_SKIPPED]);
-}
-
-void tst_list_suite(const struct tst_suite *suite)
-{
- int i;
-
- fprintf(stderr, "Testsuite: e[1;37m%se[0mnn", suite->suite_name);
-
- for (i = 0; suite->tests[i].name != NULL; i++)
- fprintf(stderr, "Test: e[1;37m%se[0mn", suite->tests[i].name);
-}
diff --git a/tests/framework/tst_test.h b/tests/framework/tst_test.h
index 186d497..937f1cf 100644
--- a/tests/framework/tst_test.h
+++ b/tests/framework/tst_test.h
@@ -75,6 +75,7 @@ struct tst_test {
struct tst_suite {
const char *suite_name;
+ int verbose:1;
struct tst_test tests[];
};
diff --git a/tests/framework/tst_timespec.c b/tests/framework/tst_timespec.c
index d388502..233095c 100644
--- a/tests/framework/tst_timespec.c
+++ b/tests/framework/tst_timespec.c
@@ -24,6 +24,19 @@
#define NSEC_IN_SEC 1000000000
+void timespec_diff(int *sec, int *nsec,
+ const struct timespec *start,
+ const struct timespec *stop)
+{
+ if (stop->tv_nsec < start->tv_nsec) {
+ *sec = stop->tv_sec - start->tv_sec - 1;
+ *nsec = stop->tv_nsec + 1000000000 - start->tv_nsec;
+ } else {
+ *sec = stop->tv_sec - start->tv_sec;
+ *nsec = stop->tv_nsec - start->tv_nsec;
+ }
+}
+
double timespec_to_double(const struct timespec *t)
{
double res;
diff --git a/tests/framework/tst_timespec.h b/tests/framework/tst_timespec.h
index 25d010c..27ab5cb 100644
--- a/tests/framework/tst_timespec.h
+++ b/tests/framework/tst_timespec.h
@@ -31,6 +31,10 @@
#include <time.h>
+void timespec_diff(int *sec, int *nsec,
+ const struct timespec *start,
+ const struct timespec *stop);
+
double timespec_to_double(const struct timespec *t);
void double_to_timespec(const double time, struct timespec *res);
diff --git a/tests/runtests.sh b/tests/runtests.sh
new file mode 100755
index 0000000..f15668b
--- /dev/null
+++ b/tests/runtests.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+DIRS="core loaders gfx"
+
+for i in $DIRS; do
+ cd $i
+ ./runtest.sh $@
+ cd ..
+done
-----------------------------------------------------------------------
Summary of changes:
tests/framework/Makefile | 2 +-
tests/framework/tst_job.c | 100 --------------------
tests/framework/tst_job.h | 3 -
tests/framework/tst_log.c | 5 +-
tests/framework/tst_main.c | 9 ++-
tests/framework/tst_msg.c | 2 +-
tests/framework/tst_msg.h | 2 +-
tests/framework/tst_preload.c | 2 +-
tests/framework/tst_preload.h | 2 +-
tests/framework/tst_suite.c | 195 ++++++++++++++++++++++++++++++++++++++++
tests/framework/tst_test.c | 108 ----------------------
tests/framework/tst_test.h | 1 +
tests/framework/tst_timespec.c | 13 +++
tests/framework/tst_timespec.h | 4 +
tests/runtests.sh | 9 ++
15 files changed, 238 insertions(+), 219 deletions(-)
create mode 100644 tests/framework/tst_suite.c
delete mode 100644 tests/framework/tst_test.c
create mode 100755 tests/runtests.sh
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: f7e6f933c737b7904e59d85438747f27785a89ac
by metan 02 Nov '12
by metan 02 Nov '12
02 Nov '12
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via f7e6f933c737b7904e59d85438747f27785a89ac (commit)
via 6bb7181dfe0c836adde74679982b8e66584d4c29 (commit)
from 019030bda9e79cde4165d8a9f9ca78be39a5ea28 (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 -----------------------------------------------------------------
http://repo.or.cz/w/gfxprim.git/commit/f7e6f933c737b7904e59d85438747f27785a…
commit f7e6f933c737b7904e59d85438747f27785a89ac
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Nov 2 16:01:18 2012 +0100
tests: Fixup messages API and return values.
diff --git a/tests/core/Context.c b/tests/core/Context.c
index ec83876..4e05306 100644
--- a/tests/core/Context.c
+++ b/tests/core/Context.c
@@ -40,50 +40,50 @@ static int Context_Alloc_Free(void)
c = GP_ContextAlloc(100, 200, GP_PIXEL_RGB888);
if (c == NULL) {
- tst_report(0, "GP_ContextAlloc() failed");
+ tst_msg("GP_ContextAlloc() failed");
return TST_FAILED;
}
/* Assert context properties */
if (c->bpp != 24) {
- tst_report(0, "Context->bpp != 24 (== %i)", c->bpp);
+ tst_msg("Context->bpp != 24 (== %i)", c->bpp);
return TST_FAILED;
}
if (c->bytes_per_row != 3 * c->w) {
- tst_report(0, "Context->bytes_per_row != %i (== %i)",
- 3 * c->w, c->bytes_per_row);
+ tst_msg("Context->bytes_per_row != %i (== %i)",
+ 3 * c->w, c->bytes_per_row);
return TST_FAILED;
}
if (c->w != 100) {
- tst_report(0, "Context->w != 100 (== %i)", c->w);
+ tst_msg("Context->w != 100 (== %i)", c->w);
return TST_FAILED;
}
if (c->h != 200) {
- tst_report(0, "Context->h != 200 (== %i)", c->h);
+ tst_msg("Context->h != 200 (== %i)", c->h);
return TST_FAILED;
}
if (c->offset != 0) {
- tst_report(0, "Context->offset != 0");
+ tst_msg("Context->offset != 0");
return TST_FAILED;
}
if (c->pixel_type != GP_PIXEL_RGB888) {
- tst_report(0, "Context->pixel_type != GP_PIXEL_RGB888");
+ tst_msg("Context->pixel_type != GP_PIXEL_RGB888");
return TST_FAILED;
}
if (c->gamma != NULL) {
- tst_report(0, "Context->gamma != NULL");
+ tst_msg("Context->gamma != NULL");
return TST_FAILED;
}
if (c->axes_swap != 0 || c->x_swap != 0 || c->y_swap != 0) {
- tst_report(0, "Wrong default orientation %i %i %i",
- c->axes_swap, c->x_swap, c->y_swap);
+ tst_msg("Wrong default orientation %i %i %i",
+ c->axes_swap, c->x_swap, c->y_swap);
return TST_FAILED;
}
@@ -101,7 +101,6 @@ const struct tst_suite tst_suite = {
.tests = {
{.name = "Context Alloc Free", .tst_fn = Context_Alloc_Free,
.flags = TST_CHECK_MALLOC},
-
{.name = NULL},
}
};
diff --git a/tests/core/GetPutPixel.gen.c.t b/tests/core/GetPutPixel.gen.c.t
index 5f1354a..05ffbdd 100644
--- a/tests/core/GetPutPixel.gen.c.t
+++ b/tests/core/GetPutPixel.gen.c.t
@@ -50,7 +50,7 @@ static int check_filled(GP_Context *c)
for (x = 0; x < (GP_Coord)c->w; x++)
for (y = 0; y < (GP_Coord)c->h; y++)
if (p != GP_GetPixel(c, x, y)) {
- tst_report(0, "Pixels different %i %i", x, y);
+ tst_msg("Pixels different %i %i", x, y);
return 1;
}
@@ -61,7 +61,7 @@ static int try_pattern(GP_Context *c, GP_Pixel p)
{
fill_context(c, p);
- tst_report(0, "Filling pattern 0x%x", p);
+ tst_msg("Filling pattern 0x%x", p);
if (check_filled(c))
return 1;
@@ -79,7 +79,7 @@ static int GetPutPixel_{{ pt.name }}(void)
c = GP_ContextAlloc(100, 100, GP_PIXEL_{{ pt.name }});
if (c == NULL) {
- tst_report(0, "GP_ContextAlloc() failed");
+ tst_msg("GP_ContextAlloc() failed");
return TST_UNTESTED;
}
@@ -114,7 +114,7 @@ static int GetPutPixel_Clipping_{{ pt.name }}(void)
c = GP_ContextAlloc(100, 100, GP_PIXEL_{{ pt.name }});
if (c == NULL) {
- tst_report(0, "GP_ContextAlloc() failed");
+ tst_msg("GP_ContextAlloc() failed");
return TST_UNTESTED;
}
@@ -133,8 +133,8 @@ static int GetPutPixel_Clipping_{{ pt.name }}(void)
/* Must return 0 */
if (GP_GetPixel(c, x, y) != 0) {
- tst_report(0, "GP_GetPixel returned non-zero "
- "at %i %i", x, y);
+ tst_msg("GP_GetPixel returned non-zero "
+ "at %i %i", x, y);
err++;
}
}
diff --git a/tests/core/WritePixel_testsuite.gen.c.t b/tests/core/WritePixel_testsuite.gen.c.t
index a554e9b..365c247 100644
--- a/tests/core/WritePixel_testsuite.gen.c.t
+++ b/tests/core/WritePixel_testsuite.gen.c.t
@@ -58,7 +58,7 @@ static void dump_buffer(const char *name, char *buf, unsigned int buf_len)
unsigned int i; if (buf1_len != buf2_len) { - tst_report(0, "Invalid buffers"); + tst_msg("Invalid buffers"); return TST_FAILED; } @@ -67,7 +67,7 @@ static void dump_buffer(const char *name, char *buf, unsigned int buf_len)
printf("%sn", id); dump_buffer("wrote", buf1, buf1_len); dump_buffer("gen", buf2, buf2_len); - tst_report(0, "Buffers are different"); + tst_msg("Buffers are different"); return TST_FAILED; } diff --git a/tests/filters/LinearConvolution.c b/tests/filters/LinearConvolution.c
index 78d1bd4..0264ddd 100644
--- a/tests/filters/LinearConvolution.c
+++ b/tests/filters/LinearConvolution.c
@@ -37,8 +37,8 @@ static int load_resources(const char *path1, const char *path2,
*c2 = GP_LoadImage(path2, NULL);
if (*c1 == NULL || *c2 == NULL) {
- tst_report(0, "Failed to load resource");
- return TST_INTERR;
+ tst_err("Failed to load resource");
+ return TST_UNTESTED;
}
return TST_SUCCESS;
diff --git a/tests/framework/test.c b/tests/framework/test.c
index ccef65d..8111855 100644
--- a/tests/framework/test.c
+++ b/tests/framework/test.c
@@ -32,8 +32,8 @@
int success_fn(void)
{
- tst_report(0, "This test does nothing");
- tst_report(0, "But successfully");
+ tst_msg("This test does nothing");
+ tst_msg("But successfully");
return TST_SUCCESS;
}
@@ -57,7 +57,7 @@ int stack_overflow_fn(void)
int timeout_fn(void)
{
- tst_report(0, "Sleeping for ten seconds");
+ tst_msg("Sleeping for ten seconds");
sleep(10);
return TST_SUCCESS;
}
@@ -68,7 +68,7 @@ int temp_dir_fn(void)
/* log current working directory */
res = getcwd(buf, sizeof(buf));
- tst_report(0, "CWD is '%s'", res);
+ tst_msg("CWD is '%s'", res);
return TST_SUCCESS;
}
@@ -86,7 +86,7 @@ int malloc_leak_fn(void)
free(q);
free(r);
- tst_report(0, "Leaking 1 chunks 4 bytes total");
+ tst_msg("Leaking 1 chunks 4 bytes total");
return TST_SUCCESS;
}
@@ -129,11 +129,11 @@ int barrier_allocation(void)
for (i = 0; i < 31; i++)
buf[i] = 0;
- tst_report(0, "About to use address after the buffer with barrier");
+ tst_msg("About to use address after the buffer with barrier");
buf[31] = 0;
- tst_report(0, "This is not printed at all");
+ tst_msg("This is not printed at all");
return TST_SUCCESS;
}
@@ -154,31 +154,31 @@ int fail_FILE(void)
f = fopen("test_fail_fclose", "w");
if (f == NULL) {
- tst_report(0, "Failed to open 'test_fail_fclose' for writing: %s",
+ tst_msg("Failed to open 'test_fail_fclose' for writing: %s",
strerror(errno));
fail = 1;
}
- tst_report(0, "Correctly opened 'test_fail_fclose'");
+ tst_msg("Correctly opened 'test_fail_fclose'");
int ret = fclose(f);
if (ret == 0 || errno != ENOSPC) {
- tst_report(0, "Failed to fail to close 'test_fail_fclose'");
+ tst_msg("Failed to fail to close 'test_fail_fclose'");
fail = 1;
}
- tst_report(0, "Correctly failed to close 'test_fail_fclose'");
+ tst_msg("Correctly failed to close 'test_fail_fclose'");
f = fopen("test_fail_fopen", "w");
if (f != NULL && errno != EPERM) {
- tst_report(0, "Failed to fail to open 'test_fail_fopen'");
+ tst_msg("Failed to fail to open 'test_fail_fopen'");
fclose(f);
fail = 1;
}
- tst_report(0, "Correctly failed to open 'test_fail_fopen'");
+ tst_msg("Correctly failed to open 'test_fail_fopen'");
if (fail)
return TST_FAILED;
@@ -186,6 +186,19 @@ int fail_FILE(void)
return TST_SUCCESS;
}
+static int messages_test_fn(void)
+{
+ /* stdout and stderr capture test */
+ printf("This is stdoutn");
+ fprintf(stderr, "This is stderrn");
+
+ tst_msg("This is message");
+ tst_warn("This is a warning");
+ tst_err("This is an error");
+
+ return TST_SUCCESS;
+}
+
/*
* This status is returned when the could not be started
* because of unsufficient configuration
@@ -208,7 +221,7 @@ static int untested_fn(void)
static int res_fn(void)
{
if (access("test.c", R_OK) == 0)
- tst_report(0, "File correctly copied");
+ tst_msg("File correctly copied");
return TST_SUCCESS;
}
@@ -254,6 +267,7 @@ const struct tst_suite tst_suite = {
{.name = "Resource", .tst_fn = res_fn, .flags = TST_TMPDIR,
.res_path = "test.c"},
{.name = "FP exception", .tst_fn = fpe_fn},
+ {.name = "Messages test", .tst_fn = messages_test_fn},
{.name = "Benchmark test", .tst_fn = benchmark_fn, .bench_iter = 10},
{.name = NULL},
}
diff --git a/tests/framework/tst_job.c b/tests/framework/tst_job.c
index 889cc45..ce39d41 100644
--- a/tests/framework/tst_job.c
+++ b/tests/framework/tst_job.c
@@ -312,6 +312,23 @@ int tst_report(int level, const char *fmt, ...)
return ret;
}
+int tst_msg(const char *fmt, ...)
+{
+ va_list va;
+ int ret;
+
+ va_start(va, fmt);
+
+ if (in_child())
+ return tst_vreport(TST_MSG, fmt, va);
+
+ fprintf(stderr, "MSG: ");
+ ret = vfprintf(stderr, fmt, va);
+ va_end(va);
+
+ return ret;
+}
+
int tst_warn(const char *fmt, ...)
{
va_list va;
@@ -320,8 +337,26 @@ int tst_warn(const char *fmt, ...)
va_start(va, fmt);
if (in_child())
- return tst_vreport(-1, fmt, va);
+ return tst_vreport(TST_WARN, fmt, va);
+
+ fprintf(stderr, "WARN: ");
+ ret = vfprintf(stderr, fmt, va);
+ va_end(va);
+
+ return ret;
+}
+
+int tst_err(const char *fmt, ...)
+{
+ va_list va;
+ int ret;
+
+ va_start(va, fmt);
+
+ if (in_child())
+ return tst_vreport(TST_ERR, fmt, va);
+ fprintf(stderr, "ERR: ");
ret = vfprintf(stderr, fmt, va);
va_end(va);
diff --git a/tests/framework/tst_msg.c b/tests/framework/tst_msg.c
index 2d46338..852fb81 100644
--- a/tests/framework/tst_msg.c
+++ b/tests/framework/tst_msg.c
@@ -71,10 +71,24 @@ int tst_msg_append(struct tst_msg_store *self, int type, const char *msg_text)
return 0;
}
+static char type_to_char(enum tst_report_type type)
+{
+ switch (type) {
+ case TST_MSG:
+ return 'M';
+ case TST_WARN:
+ return 'W';
+ case TST_ERR:
+ return 'E';
+ default:
+ return '?';
+ }
+}
+
void tst_msg_print(struct tst_msg_store *self)
{
struct tst_msg *msg;
for (msg = self->first; msg != NULL; msg = msg->next)
- fprintf(stderr, "%i: %sn", msg->type, msg->msg);
+ fprintf(stderr, "%c: %sn", type_to_char(msg->type), msg->msg);
}
diff --git a/tests/framework/tst_test.h b/tests/framework/tst_test.h
index c6ef4fe..186d497 100644
--- a/tests/framework/tst_test.h
+++ b/tests/framework/tst_test.h
@@ -27,7 +27,7 @@ enum tst_ret {
TST_SUCCESS, /* Test succedded */
TST_SKIPPED, /* Test skipped due to not enough memory, ENOSYS ... */
TST_UNTESTED, /* Test not finished because of failure */
- TST_INTERR, /* Test framework error */
+ TST_INTERR, /* Test framework error, do not use */
TST_SIGSEGV, /* Test ended with SIGSEGV */
TST_TIMEOUT, /* Test hasn't finished in time */
TST_ABORTED, /* The abort() was called (possible double free) */
@@ -91,10 +91,29 @@ void tst_list_suite(const struct tst_suite *suite);
/*
* Printf-like reporting function.
*/
+enum tst_report_type {
+ TST_MSG,
+ TST_WARN,
+ TST_ERR,
+};
+
+/* general report function - do not use */
int tst_report(int level, const char *fmt, ...)
__attribute__ ((format (printf, 2, 3)));
+/* informative message */
+int tst_msg(const char *fmt, ...)
+ __attribute__ ((format (printf, 1, 2)));
+
+/*
+ * Warning and Error are used in test framework to distinguish the type of test
+ * internal problem. You shouldn't use this one unless the test exited with
+ * TST_UNTESTED.
+ */
int tst_warn(const char *fmt, ...)
__attribute__ ((format (printf, 1, 2)));
+int tst_err(const char *fmt, ...)
+ __attribute__ ((format (printf, 1, 2)));
+
#endif /* TST_TEST_H */
diff --git a/tests/gfx/Circle.c b/tests/gfx/Circle.c
index d159632..34637bc 100644
--- a/tests/gfx/Circle.c
+++ b/tests/gfx/Circle.c
@@ -110,7 +110,7 @@ static int test_circle(const char *pattern, GP_Size w, GP_Size h,
c = GP_ContextAlloc(w, h, GP_PIXEL_G8);
if (c == NULL) {
- tst_report(0, "Failed to allocate context");
+ tst_err("Failed to allocate context");
return TST_UNTESTED;
}
@@ -122,7 +122,7 @@ static int test_circle(const char *pattern, GP_Size w, GP_Size h,
err = compare_buffers(pattern, c);
if (err) {
- tst_report(0, "Patterns are different");
+ tst_msg("Patterns are different");
return TST_FAILED;
}
diff --git a/tests/gfx/CircleSeg.c b/tests/gfx/CircleSeg.c
index 69767ec..dfb099b 100644
--- a/tests/gfx/CircleSeg.c
+++ b/tests/gfx/CircleSeg.c
@@ -166,7 +166,7 @@ static int test_circle(const char *pattern, GP_Size w, GP_Size h,
c = GP_ContextAlloc(w, h, GP_PIXEL_G8);
if (c == NULL) {
- tst_report(0, "Failed to allocate context");
+ tst_err("Failed to allocate context");
return TST_UNTESTED;
}
@@ -178,7 +178,7 @@ static int test_circle(const char *pattern, GP_Size w, GP_Size h,
err = compare_buffers(pattern, c);
if (err) {
- tst_report(0, "Patterns are different");
+ tst_msg("Patterns are different");
return TST_FAILED;
}
diff --git a/tests/gfx/Line.c b/tests/gfx/Line.c
index 5821b25..4c15718 100644
--- a/tests/gfx/Line.c
+++ b/tests/gfx/Line.c
@@ -73,6 +73,20 @@ static const char line_0_0_10_10_11x11[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
};
+static const char line_0_0_11_5_11x11[] = {
+ 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+};
+
static int test_line(const char *pattern, GP_Size w, GP_Size h,
GP_Coord x0, GP_Coord y0, GP_Coord x1, GP_Coord y1)
{
@@ -82,7 +96,7 @@ static int test_line(const char *pattern, GP_Size w, GP_Size h,
c = GP_ContextAlloc(w, h, GP_PIXEL_G8);
if (c == NULL) {
- tst_report(0, "Failed to allocate context");
+ tst_err("Failed to allocate context");
return TST_UNTESTED;
}
@@ -94,7 +108,7 @@ static int test_line(const char *pattern, GP_Size w, GP_Size h,
err = compare_buffers(pattern, c);
if (err) {
- tst_report(0, "Patterns are different");
+ tst_msg("Patterns are different");
return TST_FAILED;
}
@@ -121,12 +135,18 @@ static int test_line__1__1_11_11(void)
return test_line(line_0_0_10_10_11x11, 11, 11, -1, -1, 11, 11);
}
+static int test_line_0_0_11_5(void)
+{
+ return test_line(line_0_0_11_5_11x11, 11, 11, 0, 0, 11, 5);
+}
+
const struct tst_suite tst_suite = {
.suite_name = "GFX Line Testsuite",
.tests = {
{.name = "Line 5x5 - 5x5", .tst_fn = test_line_5_5_5_5},
{.name = "Line 1x5 - 9x5", .tst_fn = test_line_1_5_9_5},
{.name = "Line 0x0 - 10x10", .tst_fn = test_line_0_0_10_10},
+ {.name = "Line 0x0 - 11x5", .tst_fn = test_line_0_0_11_5},
{.name = "Line -1x-1 - 11x11", .tst_fn = test_line__1__1_11_11},
{.name = NULL}
}
diff --git a/tests/gfx/gfx_benchmark.c b/tests/gfx/gfx_benchmark.c
index 0ec61c6..c4cff7a 100644
--- a/tests/gfx/gfx_benchmark.c
+++ b/tests/gfx/gfx_benchmark.c
@@ -30,8 +30,8 @@ static int bench_line(GP_PixelType type)
GP_Context *img = GP_ContextAlloc(800, 600, type);
if (img == NULL) {
- tst_report(0, "Malloc failed");
- return TST_INTERR;
+ tst_err("Malloc failed");
+ return TST_UNTESTED;
}
unsigned int i;
@@ -74,8 +74,8 @@ static int bench_circle(GP_PixelType type)
GP_Context *img = GP_ContextAlloc(800, 600, type);
if (img == NULL) {
- tst_report(0, "Malloc failed");
- return TST_INTERR;
+ tst_err("Malloc failed");
+ return TST_UNTESTED;
}
unsigned int i;
diff --git a/tests/loaders/loaders_suite.c b/tests/loaders/loaders_suite.c
index c87c6f9..3d9fed4 100644
--- a/tests/loaders/loaders_suite.c
+++ b/tests/loaders/loaders_suite.c
@@ -64,8 +64,8 @@ static int save_img(enum fmt fmt, const GP_Context *img, const char *name)
case JPG:
return GP_SaveJPG(img, buf, NULL);
default:
- tst_report(0, "WARNING: trying to save %s", strfmt(fmt));
- exit(TST_INTERR);
+ tst_err("Trying to save %s image", strfmt(fmt));
+ exit(TST_UNTESTED);
}
}
@@ -85,8 +85,8 @@ static GP_Context *load(enum fmt fmt, const char *name)
case BMP:
return GP_LoadBMP(buf, NULL);
default:
- tst_report(0, "WARNING: trying to load %s", strfmt(fmt));
- exit(TST_INTERR);
+ tst_err("Trying to load %s image", strfmt(fmt));
+ exit(TST_UNTESTED);
}
}
@@ -97,19 +97,19 @@ static int save_load(enum fmt fmt, GP_Size w, GP_Size h)
img = GP_ContextAlloc(w, h, GP_PIXEL_RGB888);
if (img == NULL) {
- tst_report(0, "GP_ContextAlloc failed");
- return TST_INTERR;
+ tst_warn("GP_ContextAlloc failed");
+ return TST_UNTESTED;
}
int ret = save_img(fmt, img, "test");
if (ret) {
if (errno == ENOSYS) {
- tst_report(0, "Save %s: ENOSYS", strfmt(fmt));
+ tst_msg("Save %s: ENOSYS", strfmt(fmt));
return TST_SKIPPED;
}
- tst_report(0, "Failed to save %s: %s",
+ tst_msg("Failed to save %s: %s",
strfmt(fmt), strerror(errno));
return TST_FAILED;
}
@@ -117,7 +117,7 @@ static int save_load(enum fmt fmt, GP_Size w, GP_Size h)
res = load(fmt, "test");
if (res == NULL) {
- tst_report(0, "Failed to load %s: %s",
+ tst_msg("Failed to load %s: %s",
strfmt(fmt), strerror(errno));
return TST_FAILED;
}
@@ -155,18 +155,17 @@ static int load_enoent(enum fmt fmt)
img = load(fmt, "nonexistent");
if (img != NULL) {
- tst_report(0, "Test succedded unexpectedly");
+ tst_msg("Test succedded unexpectedly");
return TST_FAILED;
}
if (errno == ENOSYS) {
- tst_report(0, "Load %s: ENOSYS", strfmt(fmt));
+ tst_msg("Load %s: ENOSYS", strfmt(fmt));
return TST_SKIPPED;
}
if (errno != ENOENT) {
- tst_report(0, "Expected errno = ENOENT, have %s",
- strerror(errno));
+ tst_msg("Expected errno = ENOENT, have %s", strerror(errno));
return TST_FAILED;
}
@@ -203,31 +202,31 @@ static int load_eacces(enum fmt fmt)
FILE *f = fopen(buf, "w");
if (f == NULL) {
- tst_report(0, "Failed to create file 'test'");
- return TST_INTERR;
+ tst_err("Failed to create file 'test': %s", strerror(errno));
+ return TST_UNTESTED;
}
fclose(f);
if (chmod(buf, 200)) {
- tst_report(0, "chmod failed: %s", strerror(errno));
- return TST_INTERR;
+ tst_err("chmod failed: %s", strerror(errno));
+ return TST_UNTESTED;
}
img = load(fmt, "test");
if (img != NULL) {
- tst_report(0, "Test succedded unexpectedly");
+ tst_msg("Test succedded unexpectedly");
return TST_FAILED;
}
if (errno == ENOSYS) {
- tst_report(0, "Load %s: ENOSYS", strfmt(fmt));
+ tst_msg("Load %s: ENOSYS", strfmt(fmt));
return TST_SKIPPED;
}
if (errno != EACCES) {
- tst_report(0, "Expected errno = EACCES, have %s",
+ tst_msg("Expected errno = EACCES, have %s",
strerror(errno));
return TST_FAILED;
}
@@ -265,8 +264,8 @@ static int load_eio(enum fmt fmt)
FILE *f = fopen(buf, "w");
if (f == NULL) {
- tst_report(0, "Failed to create file 'test'");
- return TST_INTERR;
+ tst_err("Failed to create file 'test': %s", strerror(errno));
+ return TST_UNTESTED;
}
fclose(f);
@@ -274,17 +273,17 @@ static int load_eio(enum fmt fmt)
img = load(fmt, "test");
if (img != NULL) {
- tst_report(0, "Test succedded unexpectedly");
+ tst_msg("Test succedded unexpectedly");
return TST_FAILED;
}
if (errno == ENOSYS) {
- tst_report(0, "Load %s: ENOSYS", strfmt(fmt));
+ tst_msg("Load %s: ENOSYS", strfmt(fmt));
return TST_SKIPPED;
}
if (errno != EIO) {
- tst_report(0, "Expected errno = EIO, have %s",
+ tst_msg("Expected errno = EIO, have %s",
strerror(errno));
return TST_FAILED;
}
@@ -330,17 +329,17 @@ static int test_PNG_Save_abort(void)
GP_ProgressCallback callback = {.callback = abort_callback};
if (GP_SavePNG(img, "test.png", &callback) == 0) {
- tst_report(0, "Failed to save PNG saving");
+ tst_msg("Failed to save PNG saving");
return TST_FAILED;
}
if (errno == ENOSYS) {
- tst_report(0, "Load PNG: ENOSYS");
+ tst_msg("Load PNG: ENOSYS");
return TST_SKIPPED;
}
if (errno != ECANCELED) {
- tst_report(0, "Expected errno = ECANCELED, have %s",
+ tst_msg("Expected errno = ECANCELED, have %s",
strerror(errno));
return TST_FAILED;
}
@@ -359,11 +358,11 @@ static int test_PNG_Load_abort(void)
if (GP_SavePNG(img, "test.png", NULL)) {
if (errno == ENOSYS) {
- tst_report(0, "Save PNG: ENOSYS");
+ tst_msg("Save PNG: ENOSYS");
return TST_SKIPPED;
}
- tst_report(0, "Failed to save PNG: %s", strerror(errno));
+ tst_msg("Failed to save PNG: %s", strerror(errno));
return TST_FAILED;
}
@@ -376,12 +375,12 @@ static int test_PNG_Load_abort(void)
int saved_errno = errno;
if (img != NULL) {
- tst_report(0, "Failed to abort PNG loading");
+ tst_msg("Failed to abort PNG loading");
return TST_FAILED;
}
if (saved_errno != ECANCELED) {
- tst_report(0, "Expected errno = ECANCELED, have %s",
+ tst_msg("Expected errno = ECANCELED, have %s",
strerror(saved_errno));
return TST_FAILED;
}
@@ -458,25 +457,25 @@ static int test_Load(void)
int saved_errno = errno;
if (ret != NULL) {
- tst_report(0, "GP_LoadImage('%s') succeeded "
- "unexpectedly", file_testcases[i].filename);
+ tst_msg("GP_LoadImage('%s') succeeded unexpectedly",
+ file_testcases[i].filename);
fail++;
continue;
}
if (file_testcases[i].expected_errno != ENOSYS && errno == ENOSYS) {
- tst_report(0, "Load Image '%s': ENOSYS",
- file_testcases[i].filename);
+ tst_msg("Load Image '%s': ENOSYS",
+ file_testcases[i].filename);
continue;
}
if (file_testcases[i].expected_errno != errno) {
- tst_report(0, "Expected errno %i (%s) got %i (%s) on '%s'",
- file_testcases[i].expected_errno,
- strerror(file_testcases[i].expected_errno),
- saved_errno,
- strerror(saved_errno),
- file_testcases[i].filename);
+ tst_msg("Expected errno %i (%s) got %i (%s) on '%s'",
+ file_testcases[i].expected_errno,
+ strerror(file_testcases[i].expected_errno),
+ saved_errno,
+ strerror(saved_errno),
+ file_testcases[i].filename);
fail++;
continue;
}
@@ -502,10 +501,10 @@ static int test_load_BMP(const char *path)
if (img == NULL) {
switch (errno) {
case ENOSYS:
- tst_report(0, "Not Implemented");
+ tst_msg("Not Implemented");
return TST_SKIPPED;
default:
- tst_report(0, "Got %s", strerror(errno));
+ tst_msg("Got %s", strerror(errno));
return TST_FAILED;
}
}
@@ -570,10 +569,10 @@ static int test_load_PNG(const char *path)
if (img == NULL) {
switch (errno) {
case ENOSYS:
- tst_report(0, "Not Implemented");
+ tst_msg("Not Implemented");
return TST_SKIPPED;
default:
- tst_report(0, "Got %s", strerror(errno));
+ tst_msg("Got %s", strerror(errno));
return TST_FAILED;
}
}
@@ -605,10 +604,10 @@ static int test_load_JPEG(const char *path)
if (img == NULL) {
switch (errno) {
case ENOSYS:
- tst_report(0, "Not Implemented");
+ tst_msg("Not Implemented");
return TST_SKIPPED;
default:
- tst_report(0, "Got %s", strerror(errno));
+ tst_msg("Got %s", strerror(errno));
return TST_FAILED;
}
}
http://repo.or.cz/w/gfxprim.git/commit/6bb7181dfe0c836adde74679982b8e66584d…
commit 6bb7181dfe0c836adde74679982b8e66584d4c29
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Nov 2 15:30:34 2012 +0100
tests: framework: Propagate tst_warn() from child.
This has been broken for quite some time.
diff --git a/tests/framework/tst_job.c b/tests/framework/tst_job.c
index d208b66..889cc45 100644
--- a/tests/framework/tst_job.c
+++ b/tests/framework/tst_job.c
@@ -43,6 +43,11 @@
*/
static struct tst_job *my_job = NULL;
+static int in_child(void)
+{
+ return my_job != NULL;
+}
+
static void start_test(struct tst_job *job)
{
(void)job;
@@ -271,15 +276,12 @@ static void child_write(struct tst_job *job, char ch, void *ptr, ssize_t size)
}
}
-int tst_report(int level, const char *fmt, ...)
+static int tst_vreport(int level, const char *fmt, va_list va)
{
- va_list va;
int ret;
char buf[258];
- va_start(va, fmt);
ret = vsnprintf(buf+3, sizeof(buf) - 3, fmt, va);
- va_end(va);
ssize_t size = ret > 255 ? 255 : ret + 1;
@@ -287,9 +289,41 @@ int tst_report(int level, const char *fmt, ...)
buf[1] = level;
((unsigned char*)buf)[2] = size;
- if (my_job != NULL)
+ if (in_child()) {
if (write(my_job->pipefd, buf, size + 3) != size + 3)
tst_warn("Failed to write msg to pipe.");
+ } else {
+ tst_warn("tst_report() called from parent, msg: '%s'",
+ buf + 3);
+ }
+
+ return ret;
+}
+
+int tst_report(int level, const char *fmt, ...)
+{
+ va_list va;
+ int ret;
+
+ va_start(va, fmt);
+ ret = tst_vreport(level, fmt, va);
+ va_end(va);
+
+ return ret;
+}
+
+int tst_warn(const char *fmt, ...)
+{
+ va_list va;
+ int ret;
+
+ va_start(va, fmt);
+
+ if (in_child())
+ return tst_vreport(-1, fmt, va);
+
+ ret = vfprintf(stderr, fmt, va);
+ va_end(va);
return ret;
}
@@ -403,11 +437,11 @@ void tst_job_run(struct tst_job *job)
}
/* Redirect stderr/stdout TODO: catch its output */
- if (freopen("/dev/null", "w", stderr))
+ if (freopen("/dev/null", "w", stderr) == NULL)
tst_warn("freopen(stderr) failed: %s", strerror(errno));
- if (freopen("/dev/null", "w", stdout))
- tst_warn("freopen(stderr) failed: %s", strerror(errno));
+ if (freopen("/dev/null", "w", stdout) == NULL)
+ tst_warn("freopen(stdout) failed: %s", strerror(errno));
/* Create directory in /tmp/ and chdir into it. */
if (job->test->flags & TST_TMPDIR)
diff --git a/tests/framework/tst_test.c b/tests/framework/tst_test.c
index 4df0ef1..62666da 100644
--- a/tests/framework/tst_test.c
+++ b/tests/framework/tst_test.c
@@ -31,18 +31,6 @@
#include "tst_job.h"
#include "tst_test.h"
-int tst_warn(const char *fmt, ...)
-{
- va_list va;
- int ret;
-
- va_start(va, fmt);
- ret = vfprintf(stderr, fmt, va);
- va_end(va);
-
- return ret;
-}
-
static int run_test(const struct tst_test *test, FILE *html, FILE *json)
{
struct tst_job job;
-----------------------------------------------------------------------
Summary of changes:
tests/core/Context.c | 23 ++++----
tests/core/GetPutPixel.gen.c.t | 12 ++--
tests/core/WritePixel_testsuite.gen.c.t | 4 +-
tests/filters/LinearConvolution.c | 4 +-
tests/framework/test.c | 42 +++++++++-----
tests/framework/tst_job.c | 85 +++++++++++++++++++++++++---
tests/framework/tst_msg.c | 16 +++++-
tests/framework/tst_test.c | 12 ----
tests/framework/tst_test.h | 21 +++++++-
tests/gfx/Circle.c | 4 +-
tests/gfx/CircleSeg.c | 4 +-
tests/gfx/Line.c | 24 +++++++-
tests/gfx/gfx_benchmark.c | 8 +-
tests/loaders/loaders_suite.c | 95 +++++++++++++++----------------
14 files changed, 238 insertions(+), 116 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: 019030bda9e79cde4165d8a9f9ca78be39a5ea28
by metan 02 Nov '12
by metan 02 Nov '12
02 Nov '12
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via 019030bda9e79cde4165d8a9f9ca78be39a5ea28 (commit)
via 8e61c5d90064c9b6ab07cba610604e2de02f4522 (commit)
via 51c0091e49c24df4bf762499d1728fc9271610e3 (commit)
via 95079c548cf33566bfc19a6a2fb861c38b3137b4 (commit)
via 23876fbfc0681a3f3b8694316038679276c95d4e (commit)
from de06f184c1474e76daba31543187ad4b0205c5c3 (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 -----------------------------------------------------------------
http://repo.or.cz/w/gfxprim.git/commit/019030bda9e79cde4165d8a9f9ca78be39a5…
commit 019030bda9e79cde4165d8a9f9ca78be39a5ea28
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Nov 2 14:48:34 2012 +0100
tests: filters: convolution: Make use of ENOSYS.
diff --git a/tests/filters/LinearConvolution.c b/tests/filters/LinearConvolution.c
index cbad724..78d1bd4 100644
--- a/tests/filters/LinearConvolution.c
+++ b/tests/filters/LinearConvolution.c
@@ -68,7 +68,10 @@ static int test_lin_conv_box_3x3(void)
.kernel = box_3x3,
};
- GP_FilterConvolution(in, in, &box_3x3_kernel, NULL);
+ if (GP_FilterConvolution(in, in, &box_3x3_kernel, NULL)) {
+ if (errno == ENOSYS)
+ return TST_SKIPPED;
+ }
/* Check result */
//TODO
@@ -89,8 +92,11 @@ static int test_h_lin_conv_box_3_raw(void)
/* Apply the convolution */
float kernel[] = {1, 1, 1};
- GP_FilterHLinearConvolution_Raw(in, 0, 0, in->w, in->h, in, 0, 0,
- kernel, 3, 3, NULL);
+ if (GP_FilterHLinearConvolution_Raw(in, 0, 0, in->w, in->h, in, 0, 0,
+ kernel, 3, 3, NULL)) {
+ if (errno == ENOSYS)
+ return TST_SKIPPED;
+ }
/* Check result */
//TODO
@@ -113,8 +119,11 @@ static int test_v_lin_conv_box_3_raw(void)
/* Apply the convolution */
float kernel[] = {1, 1, 1};
- GP_FilterVLinearConvolution_Raw(in, 0, 0, in->w, in->h, in, 0, 0,
- kernel, 3, 3, NULL);
+ if (GP_FilterVLinearConvolution_Raw(in, 0, 0, in->w, in->h, in, 0, 0,
+ kernel, 3, 3, NULL)) {
+ if (errno == ENOSYS)
+ return TST_SKIPPED;
+ }
/* Check result */
//TODO
http://repo.or.cz/w/gfxprim.git/commit/8e61c5d90064c9b6ab07cba610604e2de02f…
commit 8e61c5d90064c9b6ab07cba610604e2de02f4522
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Nov 2 14:46:46 2012 +0100
filters: convolution: Fix segfault on unsupported pixel types.
This temporarily solves segfault on unsupported pixel
types by returning ENOSYS.
diff --git a/libs/filters/GP_Linear.c b/libs/filters/GP_Linear.c
index 1655ca8..a87372f 100644
--- a/libs/filters/GP_Linear.c
+++ b/libs/filters/GP_Linear.c
@@ -20,6 +20,8 @@
* *
*****************************************************************************/
+#include <errno.h>
+
#include "core/GP_Context.h"
#include "core/GP_GetPutPixel.h"
#include "core/GP_TempAlloc.h"
@@ -48,6 +50,12 @@ int GP_FilterHLinearConvolution_Raw(const GP_Context *src,
"offset %ix%i rectangle %ux%u",
kw, x_src, y_src, w_src, h_src);
+ /* Not yet implemented */
+ if (src->pixel_type != GP_PIXEL_RGB888) {
+ errno = ENOSYS;
+ return 1;
+ }
+
for (i = 0; i < kw; i++)
ikernel[i] = kernel[i] * MUL + 0.5;
@@ -157,6 +165,12 @@ int GP_FilterVLinearConvolution_Raw(const GP_Context *src,
GP_DEBUG(1, "Vertical linear convolution kernel width %u "
"offset %ix%i rectangle %ux%u",
kh, x_src, y_src, w_src, h_src);
+
+ /* Not yet implemented */
+ if (src->pixel_type != GP_PIXEL_RGB888) {
+ errno = ENOSYS;
+ return 1;
+ }
ikern_div = kern_div * MUL + 0.5;
@@ -310,6 +324,12 @@ int GP_FilterLinearConvolution_Raw(const GP_Context *src,
GP_DEBUG(1, "Linear convolution kernel %ix%i rectangle %ux%u",
kw, kh, w_src, h_src);
+
+ /* Not yet implemented */
+ if (src->pixel_type != GP_PIXEL_RGB888) {
+ errno = ENOSYS;
+ return 1;
+ }
/* Do linear convolution */
for (y = 0; y < (GP_Coord)h_src; y++) {
http://repo.or.cz/w/gfxprim.git/commit/51c0091e49c24df4bf762499d1728fc92716…
commit 51c0091e49c24df4bf762499d1728fc9271610e3
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Nov 2 14:45:42 2012 +0100
tests: framework: Avoid division by zero.
Fix division by zero when no tests were finished.
diff --git a/tests/framework/tst_test.c b/tests/framework/tst_test.c
index 1981302..4df0ef1 100644
--- a/tests/framework/tst_test.c
+++ b/tests/framework/tst_test.c
@@ -96,9 +96,16 @@ void tst_run_suite(const struct tst_suite *suite, const char *tst_name)
tst_log_close(html, TST_LOG_HTML);
tst_log_close(json, TST_LOG_JSON);
+ float percents;
+
+ if (counter == 0)
+ percents = 100;
+ else
+ percents = 100.00 * counters[0] / counter;
+
fprintf(stderr, "nSummary: succedded %u out of "
"%u %.2f%% (skipped %u)n",
- counters[0], counter, 100.00 * counters[0] / counter,
+ counters[0], counter, percents,
counters[TST_SKIPPED]);
}
http://repo.or.cz/w/gfxprim.git/commit/95079c548cf33566bfc19a6a2fb861c38b31…
commit 95079c548cf33566bfc19a6a2fb861c38b3137b4
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Nov 2 14:43:25 2012 +0100
tests: framework: Split tst_job_wait().
This is preparation for parallel test execution.
diff --git a/tests/framework/tst_job.c b/tests/framework/tst_job.c
index 2c19c08..d208b66 100644
--- a/tests/framework/tst_job.c
+++ b/tests/framework/tst_job.c
@@ -487,65 +487,78 @@ static void parent_read(struct tst_job *job, void *ptr, ssize_t size)
tst_warn("parent: read(): %s", strerror(errno));
}
-void tst_job_wait(struct tst_job *job)
+void tst_job_read(struct tst_job *job)
{
- int status, ret;
char ch;
+ int ret;
if (!job->running)
- tst_warn("Job %s (pid %i) not in running state",
+ tst_warn("job_read: Job %s (pid %i) not in running state",
job->test->name, job->pid);
- while (job->running) {
- ret = read(job->pipefd, &ch, 1);
+ errno = 0;
- if (ret < 0) {
- tst_warn("job_wait: read() failed: %s",
- strerror(errno));
- job->running = 0;
- continue;
- }
+ ret = read(job->pipefd, &ch, 1);
- /* Child exited => read returns end of file */
- if (ret == 0) {
- job->running = 0;
- continue;
- }
+ if (ret < 0) {
+ tst_warn("job_read: read() failed: %s", strerror(errno));
+ job->running = 0;
+
+ //TODO: kill the process?
- switch (ch) {
- /* test exited normally */
- case 'x':
- job->running = 0;
- break;
- /* cpu consumed time */
- case 'c':
- read_timespec(job, &job->cpu_time);
- break;
- case 'C':
- read_timespec(job, &job->cpu_time);
- break;
- /* benchmark data */
- case 'M':
- read_timespec(job, &job->bench_mean);
- break;
- case 'V':
- read_timespec(job, &job->bench_var);
- break;
- /* test message as generated by tst_report() */
- case 'm':
- parent_read_msg(job);
- break;
- /* malloc stats */
- case 's':
- parent_read(job, &job->malloc_stats,
- sizeof(job->malloc_stats));
- break;
- default:
- tst_warn("parent: Invalid characters received");
- break;
+ return;
+ }
+
+ /* Child exited => read returns end of file */
+ if (ret == 0) {
+ if (errno == EAGAIN) {
+ tst_warn("job_read: read() returned EAGAIN");
+ return;
}
+
+ job->running = 0;
+
+ return;
}
+ switch (ch) {
+ /* test exited normally */
+ case 'x':
+ job->running = 0;
+ break;
+ /* cpu consumed time */
+ case 'c':
+ read_timespec(job, &job->cpu_time);
+ break;
+ case 'C':
+ read_timespec(job, &job->cpu_time);
+ break;
+ /* benchmark data */
+ case 'M':
+ read_timespec(job, &job->bench_mean);
+ break;
+ case 'V':
+ read_timespec(job, &job->bench_var);
+ break;
+ /* test message as generated by tst_report() */
+ case 'm':
+ parent_read_msg(job);
+ break;
+ /* malloc stats */
+ case 's':
+ parent_read(job, &job->malloc_stats,
+ sizeof(job->malloc_stats));
+ break;
+ default:
+ tst_warn("parent: Invalid characters received");
+ break;
+ }
+}
+
+void tst_job_collect(struct tst_job *job)
+{
+ int status;
+
/* collect the test return status */
waitpid(job->pid, &status, 0);
@@ -578,7 +591,7 @@ void tst_job_wait(struct tst_job *job)
job->result = TST_ABORTED;
break;
default:
- printf("%in", WTERMSIG(status));
+ tst_warn("Test signaled with %in", WTERMSIG(status));
job->result = TST_INTERR;
}
}
@@ -588,3 +601,11 @@ void tst_job_wait(struct tst_job *job)
stop_test(job);
}
+
+void tst_job_wait(struct tst_job *job)
+{
+ while (job->running)
+ tst_job_read(job);
+
+ tst_job_collect(job);
+}
http://repo.or.cz/w/gfxprim.git/commit/23876fbfc0681a3f3b8694316038679276c9…
commit 23876fbfc0681a3f3b8694316038679276c95d4e
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Nov 2 14:41:16 2012 +0100
tests: framework: Change the test driver output.
The line was too long to fit to 80 chars even with
reasonably short test names so this removes the
line with CPU Time.
diff --git a/tests/framework/tst_job.c b/tests/framework/tst_job.c
index 1266f9b..2c19c08 100644
--- a/tests/framework/tst_job.c
+++ b/tests/framework/tst_job.c
@@ -61,7 +61,7 @@ void tst_diff_timespec(int *sec, int *nsec, struct timespec *start,
}
}
-#define NAME_PADD 21
+#define NAME_PADD 35
static void stop_test(struct tst_job *job)
{
@@ -113,11 +113,8 @@ static void stop_test(struct tst_job *job)
for (i = strlen(name); i < NAME_PADD; i++)
fprintf(stderr, " ");
- fprintf(stderr, " finished (Time %3i.%03is, CPU %3i.%03is) %sn",
- sec, nsec/1000000,
- (int)job->cpu_time.tv_sec,
- (int)job->cpu_time.tv_nsec/1000000,
- result);
+ fprintf(stderr, " finished (Time %3i.%03is) %sn",
+ sec, nsec/1000000, result);
if (job->bench_iter) {
for (i = 0; i < NAME_PADD; i++)
-----------------------------------------------------------------------
Summary of changes:
libs/filters/GP_Linear.c | 20 ++++++
tests/filters/LinearConvolution.c | 19 ++++--
tests/framework/tst_job.c | 126 +++++++++++++++++++++----------------
tests/framework/tst_test.c | 9 +++-
4 files changed, 114 insertions(+), 60 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: de06f184c1474e76daba31543187ad4b0205c5c3
by metan 02 Nov '12
by metan 02 Nov '12
02 Nov '12
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via de06f184c1474e76daba31543187ad4b0205c5c3 (commit)
via 0de9265c1f8dbd2860ccea964a7d22507f845657 (commit)
via b8f76479c697120adbb7468aff93a98315dd3dba (commit)
from fa2fab96f4932dece35de36740e2f1e4af38afd2 (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 -----------------------------------------------------------------
http://repo.or.cz/w/gfxprim.git/commit/de06f184c1474e76daba31543187ad4b0205…
commit de06f184c1474e76daba31543187ad4b0205c5c3
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Nov 2 14:20:53 2012 +0100
filters: Add header + minor cleanup.
diff --git a/include/filters/GP_Convolution.h b/include/filters/GP_Convolution.h
index 8c158ff..0cd9089 100644
--- a/include/filters/GP_Convolution.h
+++ b/include/filters/GP_Convolution.h
@@ -30,6 +30,7 @@
#define FILTERS_GP_CONVOLUTION_H
#include "GP_Filter.h"
+#include "GP_Linear.h"
/*
* 2D convolution kernel.
diff --git a/libs/filters/GP_Convolution.c b/libs/filters/GP_Convolution.c
index 7ee3b62..0b81e55 100644
--- a/libs/filters/GP_Convolution.c
+++ b/libs/filters/GP_Convolution.c
@@ -21,10 +21,9 @@
*****************************************************************************/
#include "core/GP_Debug.h"
-
#include "GP_Linear.h"
-
#include "GP_Convolution.h"
+
int GP_FilterConvolutionEx(const GP_Context *src,
GP_Coord x_src, GP_Coord y_src,
GP_Size w_src, GP_Coord h_src,
http://repo.or.cz/w/gfxprim.git/commit/0de9265c1f8dbd2860ccea964a7d22507f84…
commit 0de9265c1f8dbd2860ccea964a7d22507f845657
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Nov 2 14:19:41 2012 +0100
tests: framework: Copy only content of resource dir.
diff --git a/tests/framework/tst_job.c b/tests/framework/tst_job.c
index 8a0789b..1266f9b 100644
--- a/tests/framework/tst_job.c
+++ b/tests/framework/tst_job.c
@@ -29,6 +29,7 @@
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
+#include <sys/stat.h>
#include <stdarg.h>
#include <math.h>
@@ -185,22 +186,40 @@ static void prepare_tmpdir(const char *name, const char *res_path,
}
/* Create template from test name */
- snprintf(template, size, "/tmp/ctest_%s_XXXXXX", tmp);
+ snprintf(template, size, "/tmp/test_%s_XXXXXX", tmp);
if (mkdtemp(template) == NULL) {
tst_warn("mkdtemp(%s) failed: %s", template, strerror(errno));
exit(TST_INTERR);
}
- /* Copy resources if needed */
+ /*
+ * Copy resources if needed
+ *
+ * If resource is directory, copy only it's content.
+ */
if (res_path != NULL) {
- snprintf(tmp, sizeof(tmp), "cp -r '%s' '%s'",
- res_path, template);
+ struct stat st;
+ char *p = "";
+
+ if (stat(res_path, &st)) {
+ tst_warn("failed to stat resource '%s': %s",
+ res_path, strerror(errno));
+ rmdir(template);
+ exit(TST_INTERR);
+ }
+
+ if (S_ISDIR(st.st_mode))
+ p = "/*";
+
+ snprintf(tmp, sizeof(tmp), "cp -r '%s'%s '%s'",
+ res_path, p, template);
ret = system(tmp);
if (ret) {
tst_warn("failed to copy resource '%s'", res_path);
+ rmdir(template);
exit(TST_INTERR);
}
}
http://repo.or.cz/w/gfxprim.git/commit/b8f76479c697120adbb7468aff93a98315dd…
commit b8f76479c697120adbb7468aff93a98315dd3dba
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Nov 2 14:16:24 2012 +0100
tests, filters: Convolution tests, not yet working.
diff --git a/tests/filters/LinearConvolution.c b/tests/filters/LinearConvolution.c
new file mode 100644
index 0000000..cbad724
--- /dev/null
+++ b/tests/filters/LinearConvolution.c
@@ -0,0 +1,142 @@
+/*****************************************************************************
+ * This file is part of gfxprim library. *
+ * *
+ * Gfxprim is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU Lesser General Public *
+ * License as published by the Free Software Foundation; either *
+ * version 2.1 of the License, or (at your option) any later version. *
+ * *
+ * Gfxprim is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with gfxprim; if not, write to the Free Software *
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
+ * Boston, MA 02110-1301 USA *
+ * *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+#include <string.h>
+#include <errno.h>
+#include <sys/stat.h>
+
+#include <core/GP_Context.h>
+#include <loaders/GP_Loaders.h>
+#include <filters/GP_Convolution.h>
+
+#include "tst_test.h"
+
+static int load_resources(const char *path1, const char *path2,
+ GP_Context **c1, GP_Context **c2)
+{
+ *c1 = GP_LoadImage(path1, NULL);
+ *c2 = GP_LoadImage(path2, NULL);
+
+ if (*c1 == NULL || *c2 == NULL) {
+ tst_report(0, "Failed to load resource");
+ return TST_INTERR;
+ }
+
+ return TST_SUCCESS;
+}
+
+static int test_lin_conv_box_3x3(void)
+{
+ GP_Context *in, *out;
+ int ret;
+
+ ret = load_resources("in.pgm", "out.pgm", &in, &out);
+
+ if (ret != TST_SUCCESS)
+ return ret;
+
+ /* Apply the convolution */
+ float box_3x3[] = {
+ 1, 1, 1,
+ 1, 1, 1,
+ 1, 1, 1,
+ };
+
+ GP_FilterKernel2D box_3x3_kernel = {
+ .w = 3,
+ .h = 3,
+ .div = 9,
+ .kernel = box_3x3,
+ };
+
+ GP_FilterConvolution(in, in, &box_3x3_kernel, NULL);
+
+ /* Check result */
+ //TODO
+
+ return TST_SUCCESS;
+}
+
+static int test_h_lin_conv_box_3_raw(void)
+{
+ GP_Context *in, *out;
+ int ret;
+
+ ret = load_resources("in.pgm", "out.pgm", &in, &out);
+
+ if (ret != TST_SUCCESS)
+ return ret;
+
+ /* Apply the convolution */
+ float kernel[] = {1, 1, 1};
+
+ GP_FilterHLinearConvolution_Raw(in, 0, 0, in->w, in->h, in, 0, 0,
+ kernel, 3, 3, NULL);
+
+ /* Check result */
+ //TODO
+
+ return TST_SUCCESS;
+}
+
+static int test_v_lin_conv_box_3_raw(void)
+{
+ GP_Context *in, *out;
+ int ret;
+
+ ret = load_resources("in.pgm", "out.pgm", &in, &out);
+
+ if (ret != TST_SUCCESS)
+ return ret;
+
+ GP_SetDebugLevel(10);
+
+ /* Apply the convolution */
+ float kernel[] = {1, 1, 1};
+
+ GP_FilterVLinearConvolution_Raw(in, 0, 0, in->w, in->h, in, 0, 0,
+ kernel, 3, 3, NULL);
+
+ /* Check result */
+ //TODO
+
+ return TST_SUCCESS;
+}
+
+const struct tst_suite tst_suite = {
+ .suite_name = "Linear Convolution Testsuite",
+ .tests = {
+ {.name = "LinearConvolution Box 3x3",
+ .tst_fn = test_lin_conv_box_3x3,
+ .res_path = "data/conv/box_3x3/",
+ .flags = TST_TMPDIR},
+ {.name = "HLinearConvolution_Raw Kern 3",
+ .tst_fn = test_h_lin_conv_box_3_raw,
+ .res_path = "data/conv/box_3x3/",
+ .flags = TST_TMPDIR},
+ {.name = "VLinearConvolution_Raw Kern 3",
+ .tst_fn = test_v_lin_conv_box_3_raw,
+ .res_path = "data/conv/box_3x3/",
+ .flags = TST_TMPDIR},
+ {.name = NULL}
+ }
+};
diff --git a/tests/filters/Makefile b/tests/filters/Makefile
new file mode 100644
index 0000000..aaa6125
--- /dev/null
+++ b/tests/filters/Makefile
@@ -0,0 +1,11 @@
+TOPDIR=../..
+include $(TOPDIR)/pre.mk
+
+CSOURCES=$(shell echo *.c)
+
+APPS=LinearConvolution
+
+include ../tests.mk
+
+include $(TOPDIR)/app.mk
+include $(TOPDIR)/post.mk
diff --git a/tests/filters/data/conv/box_3x3/in.pgm b/tests/filters/data/conv/box_3x3/in.pgm
new file mode 100644
index 0000000..2adeee4
--- /dev/null
+++ b/tests/filters/data/conv/box_3x3/in.pgm
@@ -0,0 +1,14 @@
+P2
+# This is white square in the middle of an image
+10 10
+255
+ 0 0 0 0 0 0 0 0 0 0
+ 0 0 0 0 0 0 0 0 0 0
+ 0 0 0 0 0 0 0 0 0 0
+ 0 0 0 255 255 255 255 0 0 0
+ 0 0 0 255 255 255 255 0 0 0
+ 0 0 0 255 255 255 255 0 0 0
+ 0 0 0 255 255 255 255 0 0 0
+ 0 0 0 0 0 0 0 0 0 0
+ 0 0 0 0 0 0 0 0 0 0
+ 0 0 0 0 0 0 0 0 0 0
diff --git a/tests/filters/data/conv/box_3x3/out.pgm b/tests/filters/data/conv/box_3x3/out.pgm
new file mode 100644
index 0000000..6eae0df
--- /dev/null
+++ b/tests/filters/data/conv/box_3x3/out.pgm
@@ -0,0 +1,15 @@
+P2
+# This is white square in the middle of an image
+# after applying 3x3 box linear convolution
+10 10
+255
+ 0 0 0 0 0 0 0 0 0 0
+ 0 0 0 0 0 0 0 0 0 0
+ 0 0 28 57 85 85 57 28 0 0
+ 0 0 57 113 170 170 113 57 0 0
+ 0 0 85 170 255 255 170 85 0 0
+ 0 0 85 170 255 255 170 85 0 0
+ 0 0 57 113 170 170 113 57 0 0
+ 0 0 28 57 85 85 57 28 0 0
+ 0 0 0 0 0 0 0 0 0 0
+ 0 0 0 0 0 0 0 0 0 0
diff --git a/tests/filters/runtest.sh b/tests/filters/runtest.sh
new file mode 100755
index 0000000..9efe909
--- /dev/null
+++ b/tests/filters/runtest.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+#
+# By default the glibc __libc_message() writes to /dev/tty before calling
+# the abort(). Exporting this macro makes it to use stderr instead.
+#
+# The main usage of the function are malloc assertions, so this makes us catch
+# the malloc error message by catching stderr output.
+#
+export LIBC_FATAL_STDERR_=1
+
+LD_PRELOAD=`pwd`/../framework/libtst_preload.so LD_LIBRARY_PATH=../../build/ ./LinearConvolution "$@"
-----------------------------------------------------------------------
Summary of changes:
include/filters/GP_Convolution.h | 1 +
libs/filters/GP_Convolution.c | 3 +-
tests/filters/LinearConvolution.c | 142 +++++++++++++++++++++++++++++++
tests/{loaders => filters}/Makefile | 2 +-
tests/filters/data/conv/box_3x3/in.pgm | 14 +++
tests/filters/data/conv/box_3x3/out.pgm | 15 +++
tests/{loaders => filters}/runtest.sh | 2 +-
tests/framework/tst_job.c | 27 +++++-
8 files changed, 198 insertions(+), 8 deletions(-)
create mode 100644 tests/filters/LinearConvolution.c
copy tests/{loaders => filters}/Makefile (85%)
create mode 100644 tests/filters/data/conv/box_3x3/in.pgm
create mode 100644 tests/filters/data/conv/box_3x3/out.pgm
copy tests/{loaders => filters}/runtest.sh (91%)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: fa2fab96f4932dece35de36740e2f1e4af38afd2
by metan 02 Nov '12
by metan 02 Nov '12
02 Nov '12
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via fa2fab96f4932dece35de36740e2f1e4af38afd2 (commit)
from d0bab795ded3a1c36fcc330aa7dcc91748351fd3 (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 -----------------------------------------------------------------
http://repo.or.cz/w/gfxprim.git/commit/fa2fab96f4932dece35de36740e2f1e4af38…
commit fa2fab96f4932dece35de36740e2f1e4af38afd2
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Nov 2 12:38:44 2012 +0100
tests: Remove symboltests.
diff --git a/tests/SDL/Makefile b/tests/SDL/Makefile
index 9e60d18..1a27121 100644
--- a/tests/SDL/Makefile
+++ b/tests/SDL/Makefile
@@ -7,7 +7,7 @@ LDLIBS+=-lGP -L$(TOPDIR)/build/ -lGP_SDL -lSDL
ifeq ($(HAVE_LIBSDL),yes)
CSOURCES=$(shell echo *.c)
-APPS=symbolstest textaligntest blittest subcontext+APPS=textaligntest blittest subcontext aatest mixpixeltest
endif
diff --git a/tests/SDL/symbolstest.c b/tests/SDL/symbolstest.c
deleted file mode 100644
index be96422..0000000
--- a/tests/SDL/symbolstest.c
+++ /dev/null
@@ -1,195 +0,0 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
- * <jiri.bluebear.dluhos(a)gmail.com> *
- * *
- * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <SDL/SDL.h>
-
-#include "GP_SDL.h"
-
-static GP_Pixel black;
-
-/* The surface used as a display (in fact it is a software surface). */
-SDL_Surface *display = NULL;
-GP_Context context;
-
-/* Timer used for refreshing the display */
-SDL_TimerID timer;
-
-/* An event used for signaling that the timer was triggered. */
-SDL_UserEvent timer_event;
-
-static int pause_flag = 0;
-
-static int fill_flag = 0;
-
-Uint32 timer_callback(__attribute__((unused)) Uint32 interval,
- __attribute__((unused)) void *param)
-{
- timer_event.type = SDL_USEREVENT;
- SDL_PushEvent((SDL_Event *) &timer_event);
- return 60;
-}
-
-void random_point(SDL_Surface *surf, int *x, int *y)
-{
- *x = random() % surf->w;
- *y = random() % surf->h;
-}
-
-void draw_random_symbol(GP_Pixel pixel)
-{
- int x, y, w, h;
- random_point(display, &x, &y);
-
- w = (random() % 10) + 5;
- h = (random() % 10) + 5;
-
- if (fill_flag)
- GP_FillSymbol(&context, random() % GP_SYM_MAX, x, y, w, h,
- pixel);
- else
- GP_Symbol(&context, random() % GP_SYM_MAX, x, y, w, h,
- pixel);
-}
-
-void clear_screen(void)
-{
- SDL_LockSurface(display);
- GP_Fill(&context, black);
- SDL_UnlockSurface(display);
-}
-
-void redraw_screen(void)
-{
- if (pause_flag)
- return;
-
- SDL_LockSurface(display);
-
- GP_Pixel pixel;
- pixel = GP_RGBToPixel(random() % 256, random() % 256,
- random() % 256, context.pixel_type);
-
- draw_random_symbol(pixel);
-
- SDL_UnlockSurface(display);
-}
-
-void event_loop(void)
-{
- SDL_Event event;
-
- while (SDL_WaitEvent(&event) > 0) {
-
- switch (event.type) {
-
- case SDL_USEREVENT:
- redraw_screen();
- SDL_Flip(display);
- break;
-
- case SDL_KEYDOWN:
- switch (event.key.keysym.sym) {
- case SDLK_SPACE:
- fill_flag = !fill_flag;
- clear_screen();
- break;
- case SDLK_p:
- pause_flag = !pause_flag;
- break;
- case SDLK_ESCAPE:
- return;
-
- default:
- break;
- }
- break;
- case SDL_QUIT:
- return;
- default:
- break;
- }
- }
-}
-
-int main(int argc, char *argv[])
-{
- /* Bits per pixel to be set for the display surface. */
- int display_bpp = 0;
-
- int i;
- for (i = 1; i < argc; i++) {
- if (strcmp(argv[i], "-16") == 0) {
- display_bpp = 16;
- }
- else if (strcmp(argv[i], "-24") == 0) {
- display_bpp = 24;
- }
- else if (strcmp(argv[i], "-32") == 0) {
- display_bpp = 32;
- }
- }
-
- /* Initialize SDL */
- if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) {
- fprintf(stderr, "Could not initialize SDL: %sn", SDL_GetError());
- return 1;
- }
-
- /* Create a window with a software back surface */
- display = SDL_SetVideoMode(640, 480, display_bpp, SDL_SWSURFACE);
- if (display == NULL) {
- fprintf(stderr, "Could not open display: %sn", SDL_GetError());
- goto fail;
- }
-
- /* Set up a clipping rectangle to test proper clipping of pixels */
- SDL_Rect clip_rect = {10, 10, 620, 460};
- SDL_SetClipRect(display, &clip_rect);
-
- GP_SDL_ContextFromSurface(&context, display);
-
- black = GP_ColorToContextPixel(GP_COL_BLACK, &context);
-
- /* Set up the refresh timer */
- timer = SDL_AddTimer(60, timer_callback, NULL);
- if (timer == 0) {
- fprintf(stderr, "Could not set up timer: %sn", SDL_GetError());
- goto fail;
- }
-
- /* Enter the event loop */
- event_loop();
-
- /* We're done */
- SDL_Quit();
- return 0;
-
-fail:
- SDL_Quit();
- return 1;
-}
-
-----------------------------------------------------------------------
Summary of changes:
tests/SDL/Makefile | 2 +-
tests/SDL/symbolstest.c | 195 -----------------------------------------------
2 files changed, 1 insertions(+), 196 deletions(-)
delete mode 100644 tests/SDL/symbolstest.c
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: d0bab795ded3a1c36fcc330aa7dcc91748351fd3
by metan 02 Nov '12
by metan 02 Nov '12
02 Nov '12
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via d0bab795ded3a1c36fcc330aa7dcc91748351fd3 (commit)
from 1b12b87ffd658031b16cd398bbf7a38637d774ce (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 -----------------------------------------------------------------
http://repo.or.cz/w/gfxprim.git/commit/d0bab795ded3a1c36fcc330aa7dcc9174835…
commit d0bab795ded3a1c36fcc330aa7dcc91748351fd3
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Nov 2 11:52:41 2012 +0100
tests, demos: Ported fonttest to backends.
diff --git a/demos/c_simple/Makefile b/demos/c_simple/Makefile
index 042c208..8cc06a0 100644
--- a/demos/c_simple/Makefile
+++ b/demos/c_simple/Makefile
@@ -9,7 +9,7 @@ LDLIBS+=-lrt `$(TOPDIR)/gfxprim-config --libs --libs-backends`
APPS=backend_example loaders_example loaders filters_symmetry gfx_koch virtual_backend_example meta_data meta_data_dump tmp_file showimage v4l2_show v4l2_grab convolution weighted_median shapetest koch input- fileview linetest randomshapetest
+ fileview linetest randomshapetest fonttest
v4l2_show: LDLIBS+=-lGP_grabbers
v4l2_grab: LDLIBS+=-lGP_grabbers
diff --git a/tests/SDL/fonttest.c b/demos/c_simple/fonttest.c
similarity index 78%
rename from tests/SDL/fonttest.c
rename to demos/c_simple/fonttest.c
index 2fdf194..b9a5898 100644
--- a/tests/SDL/fonttest.c
+++ b/demos/c_simple/fonttest.c
@@ -25,13 +25,11 @@
#include <stdio.h>
#include <stdlib.h>
-#include <SDL/SDL.h>
+#include <string.h>
-#include "GP.h"
-#include "GP_SDL.h"
+#include <GP.h>
-SDL_Surface *display = NULL;
-GP_Context context;
+static GP_Backend *win;
static const char *font_path = NULL;
static unsigned int font_h = 16;
@@ -48,7 +46,7 @@ static const char *test_strings[] = {
static int font_flag = 0;
static int tracking = 0;
-GP_FontFace *font = NULL;
+static GP_FontFace *font = NULL;
static const char *glyph_bitmap_format_name(const GP_FontBitmapFormat format)
{
@@ -103,9 +101,7 @@ static void print_font_properties(const GP_FontFace *font)
void redraw_screen(void)
{
- SDL_LockSurface(display);
-
- GP_Fill(&context, black_pixel);
+ GP_Fill(win->context, black_pixel);
GP_TextStyle style = GP_DEFAULT_TEXT_STYLE;
@@ -139,29 +135,29 @@ void redraw_screen(void)
style.pixel_yspace = 0;
style.char_xspace = tracking;
- GP_FillRectXYWH(&context,
+ GP_FillRectXYWH(win->context,
16, SPACING*i + 16,
GP_TextWidth(&style, test_string),
GP_FontHeight(style.font),
dark_gray_pixel);
- GP_RectXYWH(&context,
+ GP_RectXYWH(win->context,
15, SPACING*i + 15,
GP_TextMaxWidth(&style, strlen(test_string)) + 1,
GP_FontHeight(style.font) + 1,
blue_pixel);
- GP_Text(&context, &style, 16, SPACING*i + 16, align,
+ GP_Text(win->context, &style, 16, SPACING*i + 16, align,
white_pixel, dark_gray_pixel, test_string);
style.pixel_xmul = 2;
style.pixel_ymul = 2;
style.pixel_yspace = 1;
- GP_Text(&context, &style, 34, SPACING * i + 44, align,
+ GP_Text(win->context, &style, 34, SPACING * i + 44, align,
white_pixel, black_pixel, test_string);
- GP_RectXYWH(&context, 33, SPACING * i + 43,
+ GP_RectXYWH(win->context, 33, SPACING * i + 43,
GP_TextWidth(&style, test_string) + 1,
GP_TextHeight(&style) + 1, dark_gray_pixel);
@@ -170,73 +166,64 @@ void redraw_screen(void)
style.pixel_xspace = 1;
style.pixel_yspace = 1;
- GP_Text(&context, &style, 64, SPACING*i + 88, align,
+ GP_Text(win->context, &style, 64, SPACING*i + 88, align,
dark_gray_pixel, black_pixel, test_string);
}
-
- SDL_UnlockSurface(display);
}
void event_loop(void)
{
- SDL_Event event;
-
- while (SDL_WaitEvent(&event) > 0) {
- switch (event.type) {
-
- case SDL_VIDEOEXPOSE:
- redraw_screen();
- SDL_Flip(display);
- break;
-
- case SDL_KEYDOWN:
- switch (event.key.keysym.sym) {
- case SDLK_SPACE:
+ GP_Event ev;
+
+ while (GP_EventGet(&ev)) {
+ switch (ev.type) {
+ case GP_EV_KEY:
+ if (ev.code != GP_EV_KEY_DOWN)
+ continue;
+
+ switch (ev.val.key.key) {
+ case GP_KEY_SPACE:
if (font)
font_flag = (font_flag + 1) % 3;
else
font_flag = (font_flag + 1) % 2;
redraw_screen();
- SDL_Flip(display);
+ GP_BackendFlip(win);
break;
- case SDLK_UP:
+ case GP_KEY_UP:
tracking++;
redraw_screen();
- SDL_Flip(display);
+ GP_BackendFlip(win);
break;
- case SDLK_DOWN:
+ case GP_KEY_DOWN:
tracking--;
redraw_screen();
- SDL_Flip(display);
+ GP_BackendFlip(win);
break;
- case SDLK_b:
+ case GP_KEY_B:
font_h++;
if (font_path) {
GP_FontFaceFree(font);
font = GP_FontFaceLoad(font_path, 0, font_h);
redraw_screen();
- SDL_Flip(display);
+ GP_BackendFlip(win);
}
break;
- case SDLK_s:
+ case GP_KEY_S:
font_h--;
if (font_path) {
GP_FontFaceFree(font);
font = GP_FontFaceLoad(font_path, 0, font_h);
redraw_screen();
- SDL_Flip(display);
+ GP_BackendFlip(win);
}
break;
- case SDLK_ESCAPE:
- return;
- default:
+ case GP_KEY_ESC:
+ GP_BackendExit(win);
+ exit(0);
break;
}
- break;
-
- case SDL_QUIT:
- return;
}
}
}
@@ -252,46 +239,38 @@ void print_instructions(void)
int main(int argc, char *argv[])
{
+ const char *backend_opts = "X11";
+
print_instructions();
GP_SetDebugLevel(10);
-
+
if (argc > 1) {
font_path = argv[1];
fprintf(stderr, "nLoading font '%s'n", argv[1]);
font = GP_FontFaceLoad(argv[1], 0, font_h);
}
+
+ win = GP_BackendInit(backend_opts, "Font Test", stderr);
- if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) {
- fprintf(stderr, "Could not initialize SDL: %sn", SDL_GetError());
+ if (win == NULL) {
+ fprintf(stderr, "Failed to initalize backend '%s'n",
+ backend_opts);
return 1;
}
-
- display = SDL_SetVideoMode(640, 500, 0, SDL_SWSURFACE);
- if (display == NULL) {
- fprintf(stderr, "Could not open display: %sn", SDL_GetError());
- goto fail;
- }
-
- GP_SDL_ContextFromSurface(&context, display);
-
- white_pixel = GP_ColorToContextPixel(GP_COL_WHITE, &context);
- gray_pixel = GP_ColorToContextPixel(GP_COL_GRAY_LIGHT, &context);
- dark_gray_pixel = GP_ColorToContextPixel(GP_COL_GRAY_DARK, &context);
- black_pixel = GP_ColorToContextPixel(GP_COL_BLACK, &context);
- red_pixel = GP_ColorToContextPixel(GP_COL_RED, &context);
- blue_pixel = GP_ColorToContextPixel(GP_COL_BLUE, &context);
+
+ white_pixel = GP_ColorToContextPixel(GP_COL_WHITE, win->context);
+ gray_pixel = GP_ColorToContextPixel(GP_COL_GRAY_LIGHT, win->context);
+ dark_gray_pixel = GP_ColorToContextPixel(GP_COL_GRAY_DARK, win->context);
+ black_pixel = GP_ColorToContextPixel(GP_COL_BLACK, win->context);
+ red_pixel = GP_ColorToContextPixel(GP_COL_RED, win->context);
+ blue_pixel = GP_ColorToContextPixel(GP_COL_BLUE, win->context);
redraw_screen();
- SDL_Flip(display);
+ GP_BackendFlip(win);
- event_loop();
-
- SDL_Quit();
- return 0;
-
-fail:
- SDL_Quit();
- return 1;
+ for (;;) {
+ GP_BackendWait(win);
+ event_loop();
+ }
}
-
diff --git a/tests/SDL/Makefile b/tests/SDL/Makefile
index 35a76e1..9e60d18 100644
--- a/tests/SDL/Makefile
+++ b/tests/SDL/Makefile
@@ -7,8 +7,7 @@ LDLIBS+=-lGP -L$(TOPDIR)/build/ -lGP_SDL -lSDL
ifeq ($(HAVE_LIBSDL),yes)
CSOURCES=$(shell echo *.c)
-APPS=fonttest- symbolstest textaligntest blittest subcontext+APPS=symbolstest textaligntest blittest subcontext aatest mixpixeltest
endif
-----------------------------------------------------------------------
Summary of changes:
demos/c_simple/Makefile | 2 +-
{tests/SDL => demos/c_simple}/fonttest.c | 127 ++++++++++++-----------------
tests/SDL/Makefile | 3 +-
3 files changed, 55 insertions(+), 77 deletions(-)
rename {tests/SDL => demos/c_simple}/fonttest.c (78%)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0