summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuo Jinghua <sunmoon1997@gmail.com>2009-11-01 19:45:06 +0800
committerLuo Jinghua <sunmoon1997@gmail.com>2009-11-01 19:45:06 +0800
commit1050ba2fa9f7afee37de2d2a503f70732df1714c (patch)
tree180911580421ce9a8f6dc38bd12063fe868aae98
parent80baf5aaa5d1e99ffc7993a178c47a86aad31d3c (diff)
milkway/test: add a main loop test case
-rw-r--r--milkway/test/Makefile.am6
-rw-r--r--milkway/test/main-loop-test.c68
2 files changed, 73 insertions, 1 deletions
diff --git a/milkway/test/Makefile.am b/milkway/test/Makefile.am
index 8f6fb35..e1499ef 100644
--- a/milkway/test/Makefile.am
+++ b/milkway/test/Makefile.am
@@ -1,5 +1,5 @@
SUBDIRS =
-check_PROGRAMS = hexlify checksum object poll
+check_PROGRAMS = hexlify checksum object poll main-loop
hexlify_SOURCES = hexlify-test.c
hexlify_CFLAGS = -I$(top_srcdir)/
hexlify_LDADD = $(top_builddir)/milkway/libmilkway.la
@@ -20,3 +20,7 @@ poll_CFLAGS = -I$(top_srcdir)/
poll_LDADD = $(top_builddir)/milkway/libmilkway.la
poll_LDFLAGS = $(MILKWAY_LIBS)
+main_loop_SOURCES = main-loop-test.c
+main_loop_CFLAGS = -I$(top_srcdir)/
+main_loop_LDADD = $(top_builddir)/milkway/libmilkway.la
+main_loop_LDFLAGS = $(MILKWAY_LIBS) \ No newline at end of file
diff --git a/milkway/test/main-loop-test.c b/milkway/test/main-loop-test.c
new file mode 100644
index 0000000..6a4a073
--- /dev/null
+++ b/milkway/test/main-loop-test.c
@@ -0,0 +1,68 @@
+/*
+ * Copyright © 2009 Luo Jinghua <sunmoon1997@gmail.com>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Keith Packard not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. Keith Packard makes no
+ * representations about the suitability of this software for any purpose. It
+ * is provided "as is" without express or implied warranty.
+ *
+ * LUO JINGHUA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+#include <milkway/milkway.h>
+#include <milkway/mw-main-loop.h>
+#include <milkway/mw-timeout-source.h>
+
+#include <string.h>
+#include <stdio.h>
+
+static mw_bool_t
+timeout_cb (mw_source_t *source, mw_pointer_t data)
+{
+ static int times = 1;
+
+ printf ("%d...", times++);
+ if (times > 10) {
+ printf ("DONE.\n");
+ mw_main_loop_quit(data);
+ } else {
+ fflush(stdout);
+ }
+
+ return MW_TRUE;
+}
+
+static void
+test_poll(void)
+{
+ mw_main_context_t *ctx;
+ mw_main_loop_t *loop;
+ mw_source_t *source;
+
+ ctx = mw_main_context_new();
+ loop = mw_main_loop_new(ctx);
+ source = (mw_source_t*)mw_timeout_source_new(500, timeout_cb, loop, NULL);
+ mw_main_context_add_source(ctx, source);
+ mw_object_unref(source);
+ mw_main_loop_run(loop);
+ mw_object_unref(ctx);
+}
+
+int main(int argc, char **argv)
+{
+ test_poll();
+
+ printf ("main loop test: PASS\n");
+
+ return 0;
+}