[xiph-commits] r9700 - in trunk/theora: . tests

conrad at svn.xiph.org conrad at svn.xiph.org
Thu Aug 4 23:30:56 PDT 2005


Author: conrad
Date: 2005-08-04 23:30:52 -0700 (Thu, 04 Aug 2005)
New Revision: 9700

Added:
   trunk/theora/tests/
   trunk/theora/tests/Makefile.am
   trunk/theora/tests/comment-test.c
   trunk/theora/tests/noop.c
   trunk/theora/tests/tests.h
Modified:
   trunk/theora/Makefile.am
   trunk/theora/configure.ac
Log:
Add a tests directory to libtheora.
+ Add --enable-valgrind-testing option to ./configure to run test suite under
  valgrind
+ Add noop test which simply creates and deletes an encoder, a decoder, and
  a comment object. The point of this is to provide a baseline for finding
  memory leaks in libtheora-created objects.
  * This noop test identifies a small memory leak in the encoder
  * Testing of the decoder is commented out pending discussion, as the test
  segfaults. Resolving this needs developer feedback on the test code.
+ Add a test of the comments API. This is a simple test which uses all
  theora_comment_*() API functions and checks that return values are correct.
  This provides full coverage of the comments API.


Modified: trunk/theora/Makefile.am
===================================================================
--- trunk/theora/Makefile.am	2005-08-05 04:20:17 UTC (rev 9699)
+++ trunk/theora/Makefile.am	2005-08-05 06:30:52 UTC (rev 9700)
@@ -2,7 +2,7 @@
 
 AUTOMAKE_OPTIONS = foreign 1.6 dist-zip dist-bzip2
 
-SUBDIRS = lib include doc examples debian
+SUBDIRS = lib include doc examples debian tests
 
 EXTRA_DIST = COPYING autogen.sh win32 libtheora.spec libtheora.spec.in \
 	theora-uninstalled.pc.in

Modified: trunk/theora/configure.ac
===================================================================
--- trunk/theora/configure.ac	2005-08-05 04:20:17 UTC (rev 9699)
+++ trunk/theora/configure.ac	2005-08-05 06:30:52 UTC (rev 9700)
@@ -50,6 +50,30 @@
 AC_CHECK_PROG(HAVE_PYTHON, python, true, false)
 AM_CONDITIONAL(HAVE_PYTHON,$HAVE_PYTHON)
 
+dnl Check for valgrind
+VALGRIND_ENVIRONMENT=""
+ac_enable_valgrind=no
+AC_ARG_ENABLE(valgrind-testing,
+     [  --enable-valgrind-testing     enable running of tests inside Valgrind ],     [ ac_enable_valgrind=yes ], [ ac_enable_valgrind=no] )
+
+if test "x${ac_enable_valgrind}" = xyes ; then
+  if test "x${enable_shared}" = xyes ; then
+    VALGRIND_ENVIRONMENT="libtool --mode=execute "
+  fi
+
+  AC_CHECK_PROG(HAVE_VALGRIND, valgrind, yes, no)
+  if test "x$HAVE_VALGRIND" = xyes ; then
+    VALGRIND_ENVIRONMENT="$VALGRIND_ENVIRONMENT valgrind -q --leak-check=yes --show-reachable=yes --num-callers=100"
+    AC_SUBST(VALGRIND_ENVIRONMENT)
+    TESTS_INFO="Type 'make check' to run test suite. Tests will be run under:
+  ${VALGRIND_ENVIRONMENT}"
+  else
+    TESTS_INFO="Type 'make check' to run test suite (Valgrind not found)"
+  fi
+else
+  TESTS_INFO="Type 'make check' to run test suite (Valgrind testing not enabled)"
+fi
+
 dnl --------------------------------------------------
 dnl Set build flags based on environment
 dnl --------------------------------------------------
@@ -237,6 +261,7 @@
   examples/Makefile
   doc/Makefile doc/Doxyfile
   debian/Makefile
+  tests/Makefile
   lib/Version_script
   libtheora.spec
   theora.pc

Added: trunk/theora/tests/Makefile.am
===================================================================
--- trunk/theora/tests/Makefile.am	2005-08-05 04:20:17 UTC (rev 9699)
+++ trunk/theora/tests/Makefile.am	2005-08-05 06:30:52 UTC (rev 9700)
@@ -0,0 +1,18 @@
+INCLUDES = -I$(top_srcdir)/include
+
+THEORADIR = ../lib
+THEORA_LIBS = $(THEORADIR)/libtheora.la $(OGG_LIBS)
+
+test: check
+
+TESTS_ENVIRONMENT = $(VALGRIND_ENVIRONMENT)
+
+TESTS = noop comment-test
+
+noinst_PROGRAMS = $(TESTS)
+
+noop_SOURCES = noop.c
+noop_LDADD = $(THEORA_LIBS)
+
+comment_test_SOURCES = comment-test.c
+comment_test_LDADD = $(THEORA_LIBS)

Added: trunk/theora/tests/comment-test.c
===================================================================
--- trunk/theora/tests/comment-test.c	2005-08-05 04:20:17 UTC (rev 9699)
+++ trunk/theora/tests/comment-test.c	2005-08-05 06:30:52 UTC (rev 9700)
@@ -0,0 +1,72 @@
+#include <theora/theora.h>
+
+#include <string.h>
+#include "tests.h"
+
+#define ARTIST1 "Bug-eyed Fish"
+#define ARTIST2 "VJ Fugu"
+#define COPYRIGHT "Copyright (C) 2005. Some Rights Reserved."
+#define LICENSE "Creative Commons Attribution-ShareAlike 2.5"
+
+static int
+test_comments ()
+{
+  theora_comment tc;
+  int i, n;
+  char * value;
+
+  INFO ("+ Initializing theora_comment");
+  theora_comment_init (&tc);
+
+  INFO ("+ Adding ARTIST1");
+  theora_comment_add (&tc, "ARTIST=" ARTIST1);
+
+  INFO ("+ Adding LICENSE by tag");
+  theora_comment_add_tag (&tc, "LICENSE", LICENSE);
+
+  INFO ("+ Adding ARTIST2 by tag");
+  theora_comment_add_tag (&tc, "ARTIST", ARTIST2);
+
+  INFO ("+ Querying value of LICENSE");
+  value = theora_comment_query (&tc, "LICENSE", 0);
+  if (strcmp (value, LICENSE))
+    FAIL ("Incorrect value for LICENSE");
+
+  INFO ("+ Querying count of ARTIST comments");
+  n = theora_comment_query_count (&tc, "ARTIST");
+
+  if (n != 2)
+    FAIL ("Incorrect count of ARTIST comments");
+
+  INFO ("+ Querying value of ARTIST index 0");
+  value = theora_comment_query (&tc, "ARTIST", 0);
+  if (strcmp (value, ARTIST1))
+    FAIL ("Incorrect value for ARTIST index 0");
+
+  INFO ("+ Querying value of ARTIST index 1");
+  value = theora_comment_query (&tc, "ARTIST", 1);
+  if (strcmp (value, ARTIST2))
+    FAIL ("Incorrect value for ARTIST index 1");
+
+  INFO ("+ Querying value of ARTIST index 2 (out of bounds)");
+  value = theora_comment_query (&tc, "ARTIST", 2);
+  if (value != NULL)
+    FAIL ("Non-NULL value for ARTIST index 2 (out of bounds)");
+
+  INFO ("+ Querying value of UNDEF index 7 (tag not defined)");
+  value = theora_comment_query (&tc, "UNDEF", 7);
+  if (value != NULL)
+    FAIL ("Non-NULL value for UNDEF index 7 (tag not defined)");
+
+  INFO ("+ Clearing theora_comment");
+  theora_comment_clear (&tc);
+
+  return 0;
+}
+
+int main(int argc, char *argv[])
+{
+  test_comments ();
+
+  exit (0);
+}

Added: trunk/theora/tests/noop.c
===================================================================
--- trunk/theora/tests/noop.c	2005-08-05 04:20:17 UTC (rev 9699)
+++ trunk/theora/tests/noop.c	2005-08-05 06:30:52 UTC (rev 9700)
@@ -0,0 +1,67 @@
+#include <theora/theora.h>
+
+#include "tests.h"
+
+static int
+noop_test_encode ()
+{
+  theora_info ti;
+  theora_state th;
+
+  INFO ("+ Initializing theora_info struct");
+  theora_info_init (&ti);
+
+  INFO ("+ Initializing theora_state for encoding");
+  if (theora_encode_init (&th, &ti) != OC_DISABLED) {
+    INFO ("+ Clearing theora_state");
+    theora_clear (&th);
+  }
+
+  INFO ("+ Clearing theora_info struct");
+  theora_info_clear (&ti);
+
+  return 0;
+}
+
+static int
+noop_test_decode ()
+{
+  theora_info ti;
+  theora_state th;
+
+  INFO ("+ Initializing theora_info struct");
+  theora_info_init (&ti);
+
+  INFO ("+ Initializing theora_state for decoding");
+  theora_decode_init (&th, &ti);
+
+  INFO ("+ Clearing theora_state");
+  theora_clear (&th);
+
+  INFO ("+ Clearing theora_info struct");
+  theora_info_clear (&ti);
+
+  return 0;
+}
+
+static int
+noop_test_comments ()
+{
+  theora_comment tc;
+
+  theora_comment_init (&tc);
+  theora_comment_clear (&tc);
+
+  return 0;
+}
+
+int main(int argc, char *argv[])
+{
+  /*noop_test_decode ();*/
+
+  noop_test_encode ();
+
+  noop_test_comments ();
+
+  exit (0);
+}

Added: trunk/theora/tests/tests.h
===================================================================
--- trunk/theora/tests/tests.h	2005-08-05 04:20:17 UTC (rev 9699)
+++ trunk/theora/tests/tests.h	2005-08-05 06:30:52 UTC (rev 9700)
@@ -0,0 +1,16 @@
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#define INFO(str) \
+  { printf ("----  %s ...\n", (str)); }
+
+#define WARN(str) \
+  { printf ("%s:%d: warning: %s\n", __FILE__, __LINE__, (str)); }
+
+#define FAIL(str) \
+  { printf ("%s:%d: %s\n", __FILE__, __LINE__, (str)); exit(1); }
+
+#undef MIN
+#define MIN(a,b) ((a)<(b)?(a):(b))



More information about the commits mailing list