]> git.llucax.com Git - software/ev.d.git/commitdiff
Add a D-ish API test. 0.1
authorLeandro Lucarella <llucax@gmail.com>
Wed, 13 Feb 2008 22:00:48 +0000 (20:00 -0200)
committerLeandro Lucarella <llucax@gmail.com>
Wed, 13 Feb 2008 22:00:48 +0000 (20:00 -0200)
Signed-off-by: Leandro Lucarella <llucax@gmail.com>
Makefile
dtest.d [new file with mode: 0644]

index ba9b462d827242fba2d03174d57dad23c91eb28b..ac564e91daa3b62509b758875adc9afe1ff8e541 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -9,19 +9,30 @@ DFLAGS += -funittest -fversion=UnitTest
 # Release
 #DFLAGS += -frelease -O3
 
-all: ctest
+TARGETS = ctest dtest
+
+all: $(TARGETS)
 
 ctest.o: ctest.d ev/c.d
        gdc -c $(DFLAGS) ctest.d
 
+dtest.o: dtest.d ev/c.d ev/d.d
+       gdc -c $(DFLAGS) dtest.d
+
 ev/c.o: ev/c.d
        gdc -c -o ev/c.o $(DFLAGS) ev/c.d
 
+ev/d.o: ev/d.d
+       gdc -c -o ev/d.o $(DFLAGS) ev/d.d
+
 ctest: ctest.o ev/c.o
        gdc -o ctest -lev $(DFLAGS) ctest.o ev/c.o
 
+dtest: dtest.o ev/c.o ev/d.o
+       gdc -o dtest -lev $(DFLAGS) dtest.o ev/c.o ev/d.o
+
 clean:
-       $(RM) -v *.o ev/*.o ctest
+       $(RM) -v *.o ev/*.o $(TARGETS)
 
 .PHONY: clean all
 
diff --git a/dtest.d b/dtest.d
new file mode 100644 (file)
index 0000000..0eb7a35
--- /dev/null
+++ b/dtest.d
@@ -0,0 +1,41 @@
+/+
+ + D Programming Language "bindings" to libev
+ + <http://software.schmorp.de/pkg/libev.html> test program.
+ +
+ + Written by Leandro Lucarella (2008).
+ +
+ + Placed under BOLA license <http://auriga.wearlab.de/~alb/bola/> which is
+ + basically public domain.
+ +
+ +/
+
+import std.stdio;
+import ev.d;
+
+void main()
+{
+       auto iow = new Io(0, READ,
+               (Io w, int revents)
+               {
+                       writefln("stdin ready");
+                       char[] ln = readln();
+                       writef("read %d bytes: %s", ln.length, ln);
+                       w.stop; // just a syntax example
+                       assert (w.loop !is null);
+                       w.loop.unloop(Unloop.ALL); // leave all loop calls
+               }
+       );
+       assert (iow.loop !is null);
+       iow.start;
+       auto timerw = new Timer(5.5,
+               (Timer w, int revents)
+               {
+                       writefln("timeout, revents = ", revents);
+                       w.loop.unloop(Unloop.ONE); // example syntax
+               }
+       );
+       assert (timerw.loop !is null);
+       timerw.start;
+       loop.loop;
+}
+