[pulseaudio-discuss] [PATCH 1/5] basic test framework
Deng Zhengrong
dzrongg at gmail.com
Sun Jul 1 08:50:18 PDT 2012
---
src/Makefile.am | 3 +-
src/pulsecore/test.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/pulsecore/test.h | 57 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 130 insertions(+), 1 deletions(-)
create mode 100644 src/pulsecore/test.c
create mode 100644 src/pulsecore/test.h
diff --git a/src/Makefile.am b/src/Makefile.am
index e191a62..0f4155d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -604,7 +604,8 @@ libpulsecommon_ at PA_MAJORMINOR@_la_SOURCES = \
pulsecore/tokenizer.c pulsecore/tokenizer.h \
pulsecore/usergroup.c pulsecore/usergroup.h \
pulsecore/sndfile-util.c pulsecore/sndfile-util.h \
- pulsecore/socket.h
+ pulsecore/socket.h \
+ pulsecore/test.h pulsecore/test.c
libpulsecommon_ at PA_MAJORMINOR@_la_CFLAGS = $(AM_CFLAGS) $(LIBSNDFILE_CFLAGS)
libpulsecommon_ at PA_MAJORMINOR@_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version
diff --git a/src/pulsecore/test.c b/src/pulsecore/test.c
new file mode 100644
index 0000000..0e068fe
--- /dev/null
+++ b/src/pulsecore/test.c
@@ -0,0 +1,71 @@
+/***
+ This file is part of PulseAudio.
+
+ Copyright 2012 Deng Zhengrong
+
+ PulseAudio 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.
+
+ PulseAudio 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
+ General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with PulseAudio; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <sys/types.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stdio.h>
+
+#include <pulse/xmalloc.h>
+
+#include "test.h"
+
+void pa_test_report_failed(pa_test_reporter *r, const char *file, int line, const char *cond) {
+ r->failed_counts++;
+ pa_strbuf_printf(r->failed_info, " %s:%d: %s\n", file, line, cond);
+}
+
+void pa_test_report_failed_with_message(pa_test_reporter *r, const char *file, int line,
+ const char *cond, const char *message) {
+ r->failed_counts++;
+ pa_strbuf_printf(r->failed_info, " %s %s:%d: %s\n", message, file, line, cond);
+}
+
+void pa_test_run_suites(const char *name, const pa_test_suite *const suites) {
+ size_t i = 0;
+ size_t number = sizeof(suites) / sizeof(suites[0]);
+ pa_test_reporter reporter;
+
+ reporter.failed_counts = 0;
+ reporter.failed_info = pa_strbuf_new();
+
+ /* run tests */
+ for (i = 0; i < number; i++)
+ suites[i].func(&reporter);
+
+ /* report results out */
+ printf("TEST SUITE: %s\n", name);
+ if (reporter.failed_counts) {
+ char *info;
+ printf(" %d FAILED:\n", reporter.failed_counts);
+ info = pa_strbuf_tostring(reporter.failed_info);
+ printf("%s\n", info);
+ pa_xfree(info);
+ } else
+ printf(" ALL PASSED!\n");
+
+ pa_strbuf_free(reporter.failed_info);
+}
diff --git a/src/pulsecore/test.h b/src/pulsecore/test.h
new file mode 100644
index 0000000..927563d
--- /dev/null
+++ b/src/pulsecore/test.h
@@ -0,0 +1,57 @@
+#ifndef footesthfoo
+#define footesthfoo
+
+/***
+ This file is part of PulseAudio.
+
+ Copyright 2012 Deng Zhengrong
+
+ PulseAudio 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.
+
+ PulseAudio 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
+ General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with PulseAudio; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#include <pulsecore/strbuf.h>
+
+typedef struct pa_test_reporter pa_test_reporter;
+typedef struct pa_test_suite pa_test_suite;
+typedef void (*pa_test_func)(pa_test_reporter *);
+
+struct pa_test_reporter {
+ int failed_counts;
+ pa_strbuf *failed_info;
+};
+
+struct pa_test_suite {
+ pa_test_func func;
+};
+
+#define pa_test_assert(r, cond) \
+do { \
+ if (!(cond)) \
+ pa_test_report_failed(r, __FILE__, __LINE__, #cond); \
+} while (0)
+
+#define pa_test_assert_message(r, cond, message) \
+do { \
+ if (!(cond)) \
+ pa_test_report_failed_with_message(r, __FILE__, __LINE__, #cond, message); \
+} while (0)
+
+void pa_test_report_failed(pa_test_reporter *r, const char *file, int line, const char *cond);
+void pa_test_report_failed_with_message(pa_test_reporter *r, const char *file, int line, const char *cond, const char *message);
+
+void pa_test_run_suites(const char *name, const pa_test_suite *const suites);
+
+#endif
--
1.7.7.6
More information about the pulseaudio-discuss
mailing list