From: anthony Date: Thu, 29 Mar 2012 11:54:02 +0000 (+0000) Subject: More MagickWand Tests X-Git-Tag: 7.0.1-0~5946 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=85836c5f813bb25879f1db7feace5317e7653af4;p=imagemagick More MagickWand Tests --- diff --git a/MagickWand/tests/Makefile b/MagickWand/tests/Makefile new file mode 100644 index 000000000..3eef27123 --- /dev/null +++ b/MagickWand/tests/Makefile @@ -0,0 +1,20 @@ + +# get includes and libraries from source directory +SRC=$(shell pwd )/../.. +CFLAGS=-I$(SRC) -L$(SRC)/MagickWand/.libs -L$(SRC)/MagickCore/.libs + +# get includes and libraries from installed ImageMagick-devel Package +#CFLAGS=-I/usr/include/ImageMagick + +LDLIBS=-lMagickWand -lMagickCore + +files=$(wildcard *.c) +tests=$(files:%.c=%) + +all: $(tests) + +script-token-test: script-token-test.c ../script-token.[ch] + $(CC) -o script-token-test script-token-test.c + +clean: + rm -f $(tests) diff --git a/MagickWand/tests/add_first.c b/MagickWand/tests/add_first.c new file mode 100644 index 000000000..f3b387464 --- /dev/null +++ b/MagickWand/tests/add_first.c @@ -0,0 +1,72 @@ +#include +#include + +/* Simplify the exception handling + * technically we should abort the program if + * severity >= ErrorException + */ +void ThrowWandException(MagickWand *wand) +{ char + *description; + + ExceptionType + severity; + + description=MagickGetException(wand,&severity); + (void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); + description=(char *) MagickRelinquishMemory(description); +} + +/* useful function especially after appending two wands together */ +#define SwapWands(a,b) { MagickWand *tmp=a; a=b; b=tmp; } + +int main(int argc, char *argv[]) +{ + MagickWand + *wand, + *input, + *output; + + MagickBooleanType + status; + + printf("Check prepend when using 'FirstIterator' on empty wand\n"); + printf("Result shoud be: 3210\n"); + + MagickWandGenesis(); + + wand = NewMagickWand(); + + MagickSetFirstIterator(wand); /* set first iterator to empty wand */ + + status = MagickReadImage(wand, "font_0.gif" ); + if (status == MagickFalse) + ThrowWandException(wand); + + status = MagickReadImage(wand, "font_1.gif" ); + if (status == MagickFalse) + ThrowWandException(wand); + + status = MagickReadImage(wand, "font_2.gif" ); + if (status == MagickFalse) + ThrowWandException(wand); + + status = MagickReadImage(wand, "font_3.gif" ); + if (status == MagickFalse) + ThrowWandException(wand); + + /* append all images together to create the output wand */ + MagickResetIterator(wand); /* append all images */ + output = MagickAppendImages(wand,MagickFalse); + wand = DestroyMagickWand(wand); /* finished - could swap here */ + + /* Final output */ + status = MagickWriteImage(output,"show:"); + if (status == MagickFalse) + ThrowWandException(output); + + output = DestroyMagickWand(output); + + MagickWandTerminus(); +} + diff --git a/MagickWand/tests/add_first_lists.c b/MagickWand/tests/add_first_lists.c new file mode 100644 index 000000000..25ff7736a --- /dev/null +++ b/MagickWand/tests/add_first_lists.c @@ -0,0 +1,91 @@ +#include +#include + +/* Simplify the exception handling + * technically we should abort the program if + * severity >= ErrorException + */ +void ThrowWandException(MagickWand *wand) +{ char + *description; + + ExceptionType + severity; + + description=MagickGetException(wand,&severity); + (void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); + description=(char *) MagickRelinquishMemory(description); +} + +/* useful function especially after appending two wands together */ +#define SwapWands(a,b) { MagickWand *tmp=a; a=b; b=tmp; } + +int main(int argc, char *argv[]) +{ + MagickWand + *wand, + *input, + *output; + + MagickBooleanType + status; + + printf("Add 3 sets of images after setting 'first' on empty wand\n"); + printf("Result shoud be: 678 345 012\n"); + + MagickWandGenesis(); + + wand = NewMagickWand(); + input = NewMagickWand(); + + MagickSetFirstIterator(wand); + + status = MagickReadImage(input, "font_0.gif" ) + && MagickReadImage(input, "font_1.gif" ) + && MagickReadImage(input, "font_2.gif" ); + if (status == MagickFalse) + ThrowWandException(input); + + status = MagickAddImage(wand, input); + if (status == MagickFalse) + ThrowWandException(wand); + + ClearMagickWand(input); + status = MagickReadImage(input, "font_3.gif" ) + && MagickReadImage(input, "font_4.gif" ) + && MagickReadImage(input, "font_5.gif" ); + if (status == MagickFalse) + ThrowWandException(input); + + status = MagickAddImage(wand, input); + if (status == MagickFalse) + ThrowWandException(wand); + + ClearMagickWand(input); + status = MagickReadImage(input, "font_6.gif" ) + && MagickReadImage(input, "font_7.gif" ) + && MagickReadImage(input, "font_8.gif" ); + if (status == MagickFalse) + ThrowWandException(input); + + + status = MagickAddImage(wand, input); + if (status == MagickFalse) + ThrowWandException(wand); + input=DestroyMagickWand(input); /* finished */ + + /* append all images together to create the output wand */ + MagickResetIterator(wand); /* append all images */ + output = MagickAppendImages(wand,MagickFalse); + wand = DestroyMagickWand(wand); /* finished - could swap here */ + + /* Final output */ + status = MagickWriteImage(output,"show:"); + if (status == MagickFalse) + ThrowWandException(output); + + output = DestroyMagickWand(output); + + MagickWandTerminus(); +} + diff --git a/MagickWand/tests/add_index.c b/MagickWand/tests/add_index.c new file mode 100644 index 000000000..4601854e8 --- /dev/null +++ b/MagickWand/tests/add_index.c @@ -0,0 +1,81 @@ +#include +#include + +/* Simplify the exception handling + * technically we should abort the program if + * severity >= ErrorException + */ +void ThrowWandException(MagickWand *wand) +{ char + *description; + + ExceptionType + severity; + + description=MagickGetException(wand,&severity); + (void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); + description=(char *) MagickRelinquishMemory(description); +} + +/* useful function especially after appending two wands together */ +#define SwapWands(a,b) { MagickWand *tmp=a; a=b; b=tmp; } + +int main(int argc, char *argv[]) +{ + MagickWand + *wand, + *input, + *output; + + MagickBooleanType + status; + + printf("Read 4 images, then set index 1 and read more individual images\n"); + printf("Result shoud be: 01 654 23\n"); + + MagickWandGenesis(); + + wand = NewMagickWand(); + input = NewMagickWand(); + + status = MagickReadImage(input, "font_0.gif" ) + && MagickReadImage(input, "font_1.gif" ) + && MagickReadImage(input, "font_2.gif" ) + && MagickReadImage(input, "font_3.gif" ); + if (status == MagickFalse) + ThrowWandException(input); + + status = MagickAddImage(wand, input); + if (status == MagickFalse) + ThrowWandException(wand); + input=DestroyMagickWand(input); /* finished */ + + MagickSetIteratorIndex(wand, 1); + + status = MagickReadImage(wand, "font_4.gif" ); + if (status == MagickFalse) + ThrowWandException(wand); + + status = MagickReadImage(wand, "font_5.gif" ); + if (status == MagickFalse) + ThrowWandException(wand); + + status = MagickReadImage(wand, "font_6.gif" ); + if (status == MagickFalse) + ThrowWandException(wand); + + /* append all images together to create the output wand */ + MagickResetIterator(wand); /* append all images */ + output = MagickAppendImages(wand,MagickFalse); + wand = DestroyMagickWand(wand); /* finished - could swap here */ + + /* Final output */ + status = MagickWriteImage(output,"show:"); + if (status == MagickFalse) + ThrowWandException(output); + + output = DestroyMagickWand(output); + + MagickWandTerminus(); +} + diff --git a/MagickWand/tests/add_last.c b/MagickWand/tests/add_last.c new file mode 100644 index 000000000..fcf913423 --- /dev/null +++ b/MagickWand/tests/add_last.c @@ -0,0 +1,71 @@ +#include +#include + +/* Simplify the exception handling + * technically we should abort the program if + * severity >= ErrorException + */ +void ThrowWandException(MagickWand *wand) +{ char + *description; + + ExceptionType + severity; + + description=MagickGetException(wand,&severity); + (void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); + description=(char *) MagickRelinquishMemory(description); +} + +/* useful function especially after appending two wands together */ +#define SwapWands(a,b) { MagickWand *tmp=a; a=b; b=tmp; } + +int main(int argc, char *argv[]) +{ + MagickWand + *wand, + *output; + + MagickBooleanType + status; + + printf("Check append when using 'LastIterator' on empty wand\n"); + printf("Result shoud be: 0123\n"); + + MagickWandGenesis(); + + wand = NewMagickWand(); + + MagickSetLastIterator(wand); /* to empty wand */ + + status = MagickReadImage(wand, "font_0.gif" ); + if (status == MagickFalse) + ThrowWandException(wand); + + status = MagickReadImage(wand, "font_1.gif" ); + if (status == MagickFalse) + ThrowWandException(wand); + + status = MagickReadImage(wand, "font_2.gif" ); + if (status == MagickFalse) + ThrowWandException(wand); + + status = MagickReadImage(wand, "font_3.gif" ); + if (status == MagickFalse) + ThrowWandException(wand); + + /* append all images together to create the output wand */ + MagickResetIterator(wand); /* append all images */ + output = MagickAppendImages(wand,MagickFalse); + wand = DestroyMagickWand(wand); /* finished - could swap here */ + + /* Final output */ + status = MagickWriteImage(output,"show:"); + if (status == MagickFalse) + ThrowWandException(output); + + output = DestroyMagickWand(output); + + MagickWandTerminus(); +} + diff --git a/MagickWand/tests/add_last_lists.c b/MagickWand/tests/add_last_lists.c new file mode 100644 index 000000000..6013e0f38 --- /dev/null +++ b/MagickWand/tests/add_last_lists.c @@ -0,0 +1,90 @@ +#include +#include + +/* Simplify the exception handling + * technically we should abort the program if + * severity >= ErrorException + */ +void ThrowWandException(MagickWand *wand) +{ char + *description; + + ExceptionType + severity; + + description=MagickGetException(wand,&severity); + (void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); + description=(char *) MagickRelinquishMemory(description); +} + +/* useful function especially after appending two wands together */ +#define SwapWands(a,b) { MagickWand *tmp=a; a=b; b=tmp; } + +int main(int argc, char *argv[]) +{ + MagickWand + *wand, + *input, + *output; + + MagickBooleanType + status; + + printf("Add 3 sets of images after setting 'last' on empty wand\n"); + printf("Result shoud be: 012 345 678\n"); + + MagickWandGenesis(); + + wand = NewMagickWand(); + input = NewMagickWand(); + + MagickSetLastIterator(wand); + + status = MagickReadImage(input, "font_0.gif" ) + && MagickReadImage(input, "font_1.gif" ) + && MagickReadImage(input, "font_2.gif" ); + if (status == MagickFalse) + ThrowWandException(input); + + status = MagickAddImage(wand, input); + if (status == MagickFalse) + ThrowWandException(wand); + + ClearMagickWand(input); + status = MagickReadImage(input, "font_3.gif" ) + && MagickReadImage(input, "font_4.gif" ) + && MagickReadImage(input, "font_5.gif" ); + if (status == MagickFalse) + ThrowWandException(input); + + status = MagickAddImage(wand, input); + if (status == MagickFalse) + ThrowWandException(wand); + + ClearMagickWand(input); + status = MagickReadImage(input, "font_6.gif" ) + && MagickReadImage(input, "font_7.gif" ) + && MagickReadImage(input, "font_8.gif" ); + if (status == MagickFalse) + ThrowWandException(input); + + status = MagickAddImage(wand, input); + if (status == MagickFalse) + ThrowWandException(wand); + input=DestroyMagickWand(input); + + /* append all images together to create the output wand */ + MagickResetIterator(wand); /* append all images */ + output = MagickAppendImages(wand,MagickFalse); + wand = DestroyMagickWand(wand); /* finished - could swap here */ + + /* Final output */ + status = MagickWriteImage(output,"show:"); + if (status == MagickFalse) + ThrowWandException(output); + + output = DestroyMagickWand(output); + + MagickWandTerminus(); +} + diff --git a/MagickWand/tests/add_mixed.c b/MagickWand/tests/add_mixed.c new file mode 100644 index 000000000..cc947c154 --- /dev/null +++ b/MagickWand/tests/add_mixed.c @@ -0,0 +1,95 @@ +#include +#include + +/* Simplify the exception handling + * technically we should abort the program if + * severity >= ErrorException + */ +void ThrowWandException(MagickWand *wand) +{ char + *description; + + ExceptionType + severity; + + description=MagickGetException(wand,&severity); + (void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); + description=(char *) MagickRelinquishMemory(description); +} + +/* useful function especially after appending two wands together */ +#define SwapWands(a,b) { MagickWand *tmp=a; a=b; b=tmp; } + +int main(int argc, char *argv[]) +{ + MagickWand + *wand, /* red image wand */ + *output; + + MagickBooleanType + status; + + printf("Read 3 sets of 3 Images, each set with settings: none, first, last\n"); + printf("Result shoud be: 543 012 678\n"); + + MagickWandGenesis(); + + /* read in the red image */ + wand = NewMagickWand(); + + /* add test from empty wand */ + status = MagickReadImage(wand, "font_0.gif" ); + if (status == MagickFalse) + ThrowWandException(wand); + + status = MagickReadImage(wand, "font_1.gif" ); + if (status == MagickFalse) + ThrowWandException(wand); + + status = MagickReadImage(wand, "font_2.gif" ); + if (status == MagickFalse) + ThrowWandException(wand); + + /* add test to start */ + MagickSetFirstIterator(wand); + status = MagickReadImage(wand, "font_3.gif" ); + if (status == MagickFalse) + ThrowWandException(wand); + + status = MagickReadImage(wand, "font_4.gif" ); + if (status == MagickFalse) + ThrowWandException(wand); + + status = MagickReadImage(wand, "font_5.gif" ); + if (status == MagickFalse) + ThrowWandException(wand); + + /* add test to end */ + MagickSetLastIterator(wand); + status = MagickReadImage(wand, "font_6.gif" ); + if (status == MagickFalse) + ThrowWandException(wand); + + status = MagickReadImage(wand, "font_7.gif" ); + if (status == MagickFalse) + ThrowWandException(wand); + + status = MagickReadImage(wand, "font_8.gif" ); + if (status == MagickFalse) + ThrowWandException(wand); + + /* append all images together to create the output wand */ + MagickResetIterator(wand); /* append all images */ + output = MagickAppendImages(wand,MagickFalse); + wand = DestroyMagickWand(wand); /* finished - could swap here */ + + /* Final output */ + status = MagickWriteImage(output,"show:"); + if (status == MagickFalse) + ThrowWandException(output); + + output = DestroyMagickWand(output); + + MagickWandTerminus(); +} + diff --git a/MagickWand/tests/add_mixed_lists.c b/MagickWand/tests/add_mixed_lists.c new file mode 100644 index 000000000..8d33e5caf --- /dev/null +++ b/MagickWand/tests/add_mixed_lists.c @@ -0,0 +1,90 @@ +#include +#include + +/* Simplify the exception handling + * technically we should abort the program if + * severity >= ErrorException + */ +void ThrowWandException(MagickWand *wand) +{ char + *description; + + ExceptionType + severity; + + description=MagickGetException(wand,&severity); + (void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); + description=(char *) MagickRelinquishMemory(description); +} + +/* useful function especially after appending two wands together */ +#define SwapWands(a,b) { MagickWand *tmp=a; a=b; b=tmp; } + +int main(int argc, char *argv[]) +{ + MagickWand + *wand, /* red image wand */ + *input, /* red image wand */ + *output; + + MagickBooleanType + status; + + printf("Add 3 sets of image using settings: none, first, last\n"); + printf("Result shoud be: 345 012 678\n"); + + MagickWandGenesis(); + + wand = NewMagickWand(); + input = NewMagickWand(); + + status = MagickReadImage(input, "font_0.gif" ) + && MagickReadImage(input, "font_1.gif" ) + && MagickReadImage(input, "font_2.gif" ); + if (status == MagickFalse) + ThrowWandException(input); + + status = MagickAddImage(wand, input); + if (status == MagickFalse) + ThrowWandException(wand); + + ClearMagickWand(input); + status = MagickReadImage(input, "font_3.gif" ) + && MagickReadImage(input, "font_4.gif" ) + && MagickReadImage(input, "font_5.gif" ); + if (status == MagickFalse) + ThrowWandException(input); + + MagickSetFirstIterator(wand); + status = MagickAddImage(wand, input); + if (status == MagickFalse) + ThrowWandException(wand); + + ClearMagickWand(input); + status = MagickReadImage(input, "font_6.gif" ) + && MagickReadImage(input, "font_7.gif" ) + && MagickReadImage(input, "font_8.gif" ); + if (status == MagickFalse) + ThrowWandException(input); + + MagickSetLastIterator(wand); + status = MagickAddImage(wand, input); + if (status == MagickFalse) + ThrowWandException(wand); + input=DestroyMagickWand(input); + + /* append all images together to create the output wand */ + MagickResetIterator(wand); /* append all images */ + output = MagickAppendImages(wand,MagickFalse); + wand = DestroyMagickWand(wand); /* finished - could swap here */ + + /* Final output */ + status = MagickWriteImage(output,"show:"); + if (status == MagickFalse) + ThrowWandException(output); + + output = DestroyMagickWand(output); + + MagickWandTerminus(); +} + diff --git a/MagickWand/tests/add_norm.c b/MagickWand/tests/add_norm.c new file mode 100644 index 000000000..9f122715e --- /dev/null +++ b/MagickWand/tests/add_norm.c @@ -0,0 +1,69 @@ +#include +#include + +/* Simplify the exception handling + * technically we should abort the program if + * severity >= ErrorException + */ +void ThrowWandException(MagickWand *wand) +{ char + *description; + + ExceptionType + severity; + + description=MagickGetException(wand,&severity); + (void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); + description=(char *) MagickRelinquishMemory(description); +} + +/* useful function especially after appending two wands together */ +#define SwapWands(a,b) { MagickWand *tmp=a; a=b; b=tmp; } + +int main(int argc, char *argv[]) +{ + MagickWand + *wand, + *output; + + MagickBooleanType + status; + + printf("Just read images one at a time, no settings\n"); + printf("Result shoud be: 0123\n"); + + MagickWandGenesis(); + + wand = NewMagickWand(); + + status = MagickReadImage(wand, "font_0.gif" ); + if (status == MagickFalse) + ThrowWandException(wand); + + status = MagickReadImage(wand, "font_1.gif" ); + if (status == MagickFalse) + ThrowWandException(wand); + + status = MagickReadImage(wand, "font_2.gif" ); + if (status == MagickFalse) + ThrowWandException(wand); + + status = MagickReadImage(wand, "font_3.gif" ); + if (status == MagickFalse) + ThrowWandException(wand); + + /* append all images together to create the output wand */ + MagickResetIterator(wand); /* append all images */ + output = MagickAppendImages(wand,MagickFalse); + wand = DestroyMagickWand(wand); /* finished - could swap here */ + + /* Final output */ + status = MagickWriteImage(output,"show:"); + if (status == MagickFalse) + ThrowWandException(output); + + output = DestroyMagickWand(output); + + MagickWandTerminus(); +} + diff --git a/MagickWand/tests/add_norm_lists.c b/MagickWand/tests/add_norm_lists.c new file mode 100644 index 000000000..5512f1a62 --- /dev/null +++ b/MagickWand/tests/add_norm_lists.c @@ -0,0 +1,89 @@ +#include +#include + +/* Simplify the exception handling + * technically we should abort the program if + * severity >= ErrorException + */ +void ThrowWandException(MagickWand *wand) +{ char + *description; + + ExceptionType + severity; + + description=MagickGetException(wand,&severity); + (void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); + description=(char *) MagickRelinquishMemory(description); +} + +/* useful function especially after appending two wands together */ +#define SwapWands(a,b) { MagickWand *tmp=a; a=b; b=tmp; } + +int main(int argc, char *argv[]) +{ + MagickWand + *wand, + *input, + *output; + + MagickBooleanType + status; + + printf("Just read images in three groups, no settings used\n"); + printf("Result shoud be: 012 345 678\n"); + + MagickWandGenesis(); + + wand = NewMagickWand(); + input = NewMagickWand(); + + status = MagickReadImage(input, "font_0.gif" ) + && MagickReadImage(input, "font_1.gif" ) + && MagickReadImage(input, "font_2.gif" ); + if (status == MagickFalse) + ThrowWandException(input); + + status = MagickAddImage(wand, input); + if (status == MagickFalse) + ThrowWandException(wand); + + ClearMagickWand(input); + status = MagickReadImage(input, "font_3.gif" ) + && MagickReadImage(input, "font_4.gif" ) + && MagickReadImage(input, "font_5.gif" ); + if (status == MagickFalse) + ThrowWandException(input); + + status = MagickAddImage(wand, input); + if (status == MagickFalse) + ThrowWandException(wand); + ClearMagickWand(input); + + ClearMagickWand(input); + status = MagickReadImage(input, "font_6.gif" ) + && MagickReadImage(input, "font_7.gif" ) + && MagickReadImage(input, "font_8.gif" ); + if (status == MagickFalse) + ThrowWandException(input); + + status = MagickAddImage(wand, input); + if (status == MagickFalse) + ThrowWandException(wand); + input=DestroyMagickWand(input); + + /* append all images together to create the output wand */ + MagickResetIterator(wand); /* append all images */ + output = MagickAppendImages(wand,MagickFalse); + wand = DestroyMagickWand(wand); /* finished - could swap here */ + + /* Final output */ + status = MagickWriteImage(output,"show:"); + if (status == MagickFalse) + ThrowWandException(output); + + output = DestroyMagickWand(output); + + MagickWandTerminus(); +} + diff --git a/MagickWand/tests/font_0.gif b/MagickWand/tests/font_0.gif new file mode 100644 index 000000000..e33bd5f0e Binary files /dev/null and b/MagickWand/tests/font_0.gif differ diff --git a/MagickWand/tests/font_1.gif b/MagickWand/tests/font_1.gif new file mode 100644 index 000000000..3444a6f45 Binary files /dev/null and b/MagickWand/tests/font_1.gif differ diff --git a/MagickWand/tests/font_2.gif b/MagickWand/tests/font_2.gif new file mode 100644 index 000000000..c40645b7f Binary files /dev/null and b/MagickWand/tests/font_2.gif differ diff --git a/MagickWand/tests/font_3.gif b/MagickWand/tests/font_3.gif new file mode 100644 index 000000000..8d6bd7395 Binary files /dev/null and b/MagickWand/tests/font_3.gif differ diff --git a/MagickWand/tests/font_4.gif b/MagickWand/tests/font_4.gif new file mode 100644 index 000000000..0c052048c Binary files /dev/null and b/MagickWand/tests/font_4.gif differ diff --git a/MagickWand/tests/font_5.gif b/MagickWand/tests/font_5.gif new file mode 100644 index 000000000..0087a4447 Binary files /dev/null and b/MagickWand/tests/font_5.gif differ diff --git a/MagickWand/tests/font_6.gif b/MagickWand/tests/font_6.gif new file mode 100644 index 000000000..38b9862fa Binary files /dev/null and b/MagickWand/tests/font_6.gif differ diff --git a/MagickWand/tests/font_7.gif b/MagickWand/tests/font_7.gif new file mode 100644 index 000000000..9bf729730 Binary files /dev/null and b/MagickWand/tests/font_7.gif differ diff --git a/MagickWand/tests/font_8.gif b/MagickWand/tests/font_8.gif new file mode 100644 index 000000000..7c5880b4b Binary files /dev/null and b/MagickWand/tests/font_8.gif differ diff --git a/MagickWand/tests/font_9.gif b/MagickWand/tests/font_9.gif new file mode 100644 index 000000000..4f9435fff Binary files /dev/null and b/MagickWand/tests/font_9.gif differ diff --git a/MagickWand/tests/loop_over_lists.c b/MagickWand/tests/loop_over_lists.c new file mode 100644 index 000000000..b5f985817 --- /dev/null +++ b/MagickWand/tests/loop_over_lists.c @@ -0,0 +1,128 @@ +#include +#include + +/* set this to true to test loops methods with a empty wand */ +#define TEST_EMPTY_WAND 0 + +/* Simplify the exception handling + * technically we should abort the program if + * severity >= ErrorException + */ +void ThrowWandException(MagickWand *wand) +{ char + *description; + + ExceptionType + severity; + + description=MagickGetException(wand,&severity); + (void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); + description=(char *) MagickRelinquishMemory(description); +} + +/* useful function especially after appending two wands together */ +#define SwapWands(a,b) { MagickWand *tmp=a; a=b; b=tmp; } + +int main(int argc, char *argv[]) +{ + MagickWand + *wand, + *output; + + MagickBooleanType + status; + + MagickWandGenesis(); + + printf("Read in a list of 6 images...\n"); + + wand = NewMagickWand(); +#if !TEST_EMPTY_WAND + status = MagickReadImage(wand, "font_0.gif" ) + && MagickReadImage(wand, "font_1.gif" ) + && MagickReadImage(wand, "font_2.gif" ) + && MagickReadImage(wand, "font_3.gif" ) + && MagickReadImage(wand, "font_4.gif" ) + && MagickReadImage(wand, "font_5.gif" ); + if (status == MagickFalse) + ThrowWandException(wand); +#endif + + printf("I actually read in %u images\n", + (unsigned) MagickGetNumberImages(wand) ); + printf("\n"); + + printf("After reading current image is #%d \"%s\"\n", + (unsigned) MagickGetIteratorIndex(wand), + MagickGetImageFilename(wand) ); + printf("\n"); + + // Note that using MagickGetIteratorIndex() is slower than just + // keeping track of the current image index yourself! But not a great cost. + + printf("Standard 'Reset while Next' loop through images\n"); + // keeping track of it to start with! + MagickResetIterator(wand); + while (MagickNextImage(wand) != MagickFalse) + printf("image #%u \"%s\"\n", + (unsigned) MagickGetIteratorIndex(wand), + MagickGetImageFilename(wand) ); + printf("\n"); + + printf("At this point, any image 'added' to wand will be appended!\n"); + printf("This special condition can be set by using either\n"); + printf("just MagickSetLastIterator(w)\n"); + printf("or MagickSetIteratorIndex(w,-1)\n"); + printf("\n"); + + printf("Now that we are at the end, lets loop backward using 'Previous'\n"); + while (MagickPreviousImage(wand) != MagickFalse) + printf("image #%u \"%s\"\n", + (unsigned) MagickGetIteratorIndex(wand), + MagickGetImageFilename(wand) ); + printf("\n"); + + + printf("Note at this point, any image 'added' to wand will be prepended!\n"); + printf("This special condition can be set by using either\n"); + printf("just MagickSetFirstIterator(w)\n"); + printf("Or MagickResetIterator(w); MagickPreviousImage(w);\n"); + printf("The latter method being the cause of the current condition\n"); + printf("\n"); + + + printf("Directly loop though images backward using 'Last, while Previous'\n"); + MagickSetLastIterator(wand); + while ( MagickPreviousImage(wand) != MagickFalse ) + printf("image #%u \"%s\"\n", + (unsigned) MagickGetIteratorIndex(wand), + MagickGetImageFilename(wand) ); + printf("\n"); + + + printf("Loop through images using Indexes, in a weird flip-flop way!\n"); + printf("Note that indexing using a negative number, indexes from end \n"); + { ssize_t i; + ssize_t n = (ssize_t) MagickGetNumberImages(wand); + + for ( i=0; i!=n; i= (i>=0) ? -(i+1):-i ) { + (void) MagickSetIteratorIndex(wand,i); + /* Note that a return of MagickFalse by the above is not actually an + * error (no exception will be generated). It just means that the + * index value used (positive or negative) is too large for the + * size of the current image list (EG: range error: -n <= i < n ) + * When it does happen, no change is made to the current image + */ + printf("index %2d -> #%u \"%s\"\n", (int) i, + (unsigned) MagickGetIteratorIndex(wand), + MagickGetImageFilename(wand) ); + } + } + printf("\n"); + + + wand=DestroyMagickWand(wand); + + MagickWandTerminus(); +} + diff --git a/MagickWand/tests/script-token-test.c b/MagickWand/tests/script-token-test.c index e1c3249f7..119a10229 100644 --- a/MagickWand/tests/script-token-test.c +++ b/MagickWand/tests/script-token-test.c @@ -71,6 +71,7 @@ #define LocaleCompare(p,q) strcasecmp(p,q) #define LocaleNCompare(p,q,l) strncasecmp(p,q,l) #define WandSignature 0xabacadabUL +#define fopen_utf8(p,q) fopen(p,q) #define WandExport /* Include the actual code for ScriptToken functions */