]> granicus.if.org Git - imagemagick/commitdiff
More MagickWand Tests
authoranthony <anthony@git.imagemagick.org>
Thu, 29 Mar 2012 11:54:02 +0000 (11:54 +0000)
committeranthony <anthony@git.imagemagick.org>
Thu, 29 Mar 2012 11:54:02 +0000 (11:54 +0000)
22 files changed:
MagickWand/tests/Makefile [new file with mode: 0644]
MagickWand/tests/add_first.c [new file with mode: 0644]
MagickWand/tests/add_first_lists.c [new file with mode: 0644]
MagickWand/tests/add_index.c [new file with mode: 0644]
MagickWand/tests/add_last.c [new file with mode: 0644]
MagickWand/tests/add_last_lists.c [new file with mode: 0644]
MagickWand/tests/add_mixed.c [new file with mode: 0644]
MagickWand/tests/add_mixed_lists.c [new file with mode: 0644]
MagickWand/tests/add_norm.c [new file with mode: 0644]
MagickWand/tests/add_norm_lists.c [new file with mode: 0644]
MagickWand/tests/font_0.gif [new file with mode: 0644]
MagickWand/tests/font_1.gif [new file with mode: 0644]
MagickWand/tests/font_2.gif [new file with mode: 0644]
MagickWand/tests/font_3.gif [new file with mode: 0644]
MagickWand/tests/font_4.gif [new file with mode: 0644]
MagickWand/tests/font_5.gif [new file with mode: 0644]
MagickWand/tests/font_6.gif [new file with mode: 0644]
MagickWand/tests/font_7.gif [new file with mode: 0644]
MagickWand/tests/font_8.gif [new file with mode: 0644]
MagickWand/tests/font_9.gif [new file with mode: 0644]
MagickWand/tests/loop_over_lists.c [new file with mode: 0644]
MagickWand/tests/script-token-test.c

diff --git a/MagickWand/tests/Makefile b/MagickWand/tests/Makefile
new file mode 100644 (file)
index 0000000..3eef271
--- /dev/null
@@ -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 (file)
index 0000000..f3b3874
--- /dev/null
@@ -0,0 +1,72 @@
+#include <stdio.h>
+#include <MagickWand/MagickWand.h>
+
+/* 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 (file)
index 0000000..25ff773
--- /dev/null
@@ -0,0 +1,91 @@
+#include <stdio.h>
+#include <MagickWand/MagickWand.h>
+
+/* 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 (file)
index 0000000..4601854
--- /dev/null
@@ -0,0 +1,81 @@
+#include <stdio.h>
+#include <MagickWand/MagickWand.h>
+
+/* 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 (file)
index 0000000..fcf9134
--- /dev/null
@@ -0,0 +1,71 @@
+#include <stdio.h>
+#include <MagickWand/MagickWand.h>
+
+/* 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 (file)
index 0000000..6013e0f
--- /dev/null
@@ -0,0 +1,90 @@
+#include <stdio.h>
+#include <MagickWand/MagickWand.h>
+
+/* 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 (file)
index 0000000..cc947c1
--- /dev/null
@@ -0,0 +1,95 @@
+#include <stdio.h>
+#include <MagickWand/MagickWand.h>
+
+/* 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 (file)
index 0000000..8d33e5c
--- /dev/null
@@ -0,0 +1,90 @@
+#include <stdio.h>
+#include <MagickWand/MagickWand.h>
+
+/* 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 (file)
index 0000000..9f12271
--- /dev/null
@@ -0,0 +1,69 @@
+#include <stdio.h>
+#include <MagickWand/MagickWand.h>
+
+/* 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 (file)
index 0000000..5512f1a
--- /dev/null
@@ -0,0 +1,89 @@
+#include <stdio.h>
+#include <MagickWand/MagickWand.h>
+
+/* 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 (file)
index 0000000..e33bd5f
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 (file)
index 0000000..3444a6f
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 (file)
index 0000000..c40645b
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 (file)
index 0000000..8d6bd73
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 (file)
index 0000000..0c05204
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 (file)
index 0000000..0087a44
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 (file)
index 0000000..38b9862
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 (file)
index 0000000..9bf7297
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 (file)
index 0000000..7c5880b
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 (file)
index 0000000..4f9435f
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 (file)
index 0000000..b5f9858
--- /dev/null
@@ -0,0 +1,128 @@
+#include <stdio.h>
+#include <MagickWand/MagickWand.h>
+
+/* 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();
+}
+
index e1c3249f7020a789c8759aa1ae6c17735f363b79..119a102297005de6b40f0416fafd0ddcb29dc2b3 100644 (file)
@@ -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 */