From 1f4f1b8d6eba48ffb61e1a0965961dd32b3ef29a Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Tue, 2 Jan 2007 15:07:31 +0000 Subject: [PATCH] Add new tests. --- test/Makefile | 6 +++--- test/c-way.cpp | 27 +++++++++++++++++++++++++++ test/functor-way.cpp | 33 +++++++++++++++++++++++++++++++++ test/trivial.cpp | 9 +++++++++ 4 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 test/c-way.cpp create mode 100644 test/functor-way.cpp create mode 100644 test/trivial.cpp diff --git a/test/Makefile b/test/Makefile index 63018a6..f582ca4 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,11 +1,11 @@ -CXXFLAGS=-I.. -g +CXXFLAGS=-I.. -g -Wall # Uncomment this if you have a fixed event_base_free(). # See http://www.mail-archive.com/libevent-users@monkey.org/msg00112.html -#CXXFLAGS+=-DEVENT_BASE_FREE_FIX +CXXFLAGS+=-DEVENT_BASE_FREE_FIX LDFLAGS=-levent -targets=bench test-eof test-time test-weof +targets=bench test-eof test-time test-weof trivial c-way all: $(targets) diff --git a/test/c-way.cpp b/test/c-way.cpp new file mode 100644 index 0000000..889317d --- /dev/null +++ b/test/c-way.cpp @@ -0,0 +1,27 @@ +#include +#include +#include + +eventxx::dispatcher d; + +void sighandler(int signum, short event, void* data) +{ + unsigned &i = *(unsigned*)data; + std::cout << ++i << " interrupts, "; + if (i < 5) std::cout << "keep going...\n"; + else + { + std::cout << "done!\n"; + d.exit(); + } +} + +int main() +{ + int var = 0; + eventxx::csignal sigev(SIGINT, sighandler, &var); + d.add(sigev); + d.dispatch(); + return 0; +} + diff --git a/test/functor-way.cpp b/test/functor-way.cpp new file mode 100644 index 0000000..b9f3b77 --- /dev/null +++ b/test/functor-way.cpp @@ -0,0 +1,33 @@ +#include +#include +#include + +using eventxx::dispatcher; + +struct handler +{ + dispatcher& d; + int i; + handler(dispatcher& d): d(d), i(0) {} + void operator() (int signum, short event) + { + std::cout << ++i << " interrupts, "; + if (i < 5) std::cout << "keep going...\n"; + else + { + std::cout << "done!\n"; + d.exit(); + } + } +}; + +int main() +{ + dispatcher d; + handler h(d); + eventxx::signal< handler > e(SIGINT, h); + d.add(e); + d.dispatch(); + return 0; +} + diff --git a/test/trivial.cpp b/test/trivial.cpp new file mode 100644 index 0000000..779806c --- /dev/null +++ b/test/trivial.cpp @@ -0,0 +1,9 @@ +#include + +int main() +{ + eventxx::dispatcher d; + d.dispatch(); + return 0; +} + -- 2.43.0