libcruft-util/test/signal.cpp

58 lines
872 B
C++
Raw Normal View History

#include <cstdlib>
#include "../signal.hpp"
#include "../debug.hpp"
void
increment_uint (unsigned int &val)
{ ++val; }
void
test_null (void) {
2011-07-29 17:56:26 +10:00
util::signal<void> void_signal;
void_signal ();
}
void
test_single (void) {
unsigned int val = 0;
2011-07-29 17:56:26 +10:00
util::signal<void, unsigned int&> void_signal;
void_signal.connect (increment_uint);
void_signal (val);
2012-05-11 12:34:21 +10:00
CHECK_EQ (val, 1);
}
void
test_double (void) {
unsigned int val = 0;
2011-07-29 17:56:26 +10:00
util::signal<void, unsigned int&> void_signal;
void_signal.connect (increment_uint);
void_signal.connect (increment_uint);
void_signal (val);
2012-05-11 12:34:21 +10:00
CHECK_EQ (val, 2);
}
void
test_linking_pointers (void) {
2011-07-29 17:56:26 +10:00
util::signal<void, const char*> ptr_signal;
ptr_signal (NULL);
}
int
main (int, char **) {
test_null ();
test_single ();
test_double ();
return EXIT_SUCCESS;
}