aboutsummaryrefslogtreecommitdiff
path: root/test/common
diff options
context:
space:
mode:
authorJohannes Schickel2008-07-31 13:36:13 +0000
committerJohannes Schickel2008-07-31 13:36:13 +0000
commit342d0bd2876aff9f39ea249b10d61d2a92202791 (patch)
tree7295d4f9456bc4c6b0c0f1c3a52058639a20697a /test/common
parent6ed4beb1bfc1ffe7a2ca9f99dbd63eaf9c245bea (diff)
downloadscummvm-rg350-342d0bd2876aff9f39ea249b10d61d2a92202791.tar.gz
scummvm-rg350-342d0bd2876aff9f39ea249b10d61d2a92202791.tar.bz2
scummvm-rg350-342d0bd2876aff9f39ea249b10d61d2a92202791.zip
- Added Common::mem_fun_ref for object references instead of pointers.
- Added simple tests for a little bit functionallity from common/func.h svn-id: r33470
Diffstat (limited to 'test/common')
-rw-r--r--test/common/func.h60
1 files changed, 60 insertions, 0 deletions
diff --git a/test/common/func.h b/test/common/func.h
new file mode 100644
index 0000000000..bf9b2ddff9
--- /dev/null
+++ b/test/common/func.h
@@ -0,0 +1,60 @@
+#include <cxxtest/TestSuite.h>
+
+#include "common/func.h"
+
+void myFunction1(int &dst, const int src) { dst = src; }
+void myFunction2(const int src, int &dst) { dst = src; }
+
+class FuncTestSuite : public CxxTest::TestSuite
+{
+ public:
+ void test_bind1st() {
+ int dst = 0;
+ Common::bind1st(Common::ptr_fun(myFunction1), dst)(1);
+ TS_ASSERT_EQUALS(dst, 1);
+ }
+
+ void test_bind2nd() {
+ int dst = 0;
+ Common::bind2nd(Common::ptr_fun(myFunction2), dst)(1);
+ TS_ASSERT_EQUALS(dst, 1);
+ }
+
+ struct Foo {
+ void fooAdd(int &foo) {
+ ++foo;
+ }
+
+ void fooSub(int &foo) const {
+ --foo;
+ }
+ };
+
+ void test_mem_fun_ref() {
+ Foo myFoos[4];
+ int counter = 0;
+
+ Common::for_each(myFoos, myFoos+4, Common::bind2nd(Common::mem_fun_ref(&Foo::fooAdd), counter));
+ TS_ASSERT_EQUALS(counter, 4);
+
+ Common::for_each(myFoos, myFoos+4, Common::bind2nd(Common::mem_fun_ref(&Foo::fooSub), counter));
+ TS_ASSERT_EQUALS(counter, 0);
+ }
+
+ void test_mem_fun() {
+ Foo *myFoos[4];
+ for (int i = 0; i < 4; ++i)
+ myFoos[i] = new Foo;
+
+ int counter = 0;
+
+ Common::for_each(myFoos, myFoos+4, Common::bind2nd(Common::mem_fun(&Foo::fooAdd), counter));
+ TS_ASSERT_EQUALS(counter, 4);
+
+ Common::for_each(myFoos, myFoos+4, Common::bind2nd(Common::mem_fun(&Foo::fooSub), counter));
+ TS_ASSERT_EQUALS(counter, 0);
+
+ for (int i = 0; i < 4; ++i)
+ delete myFoos[i];
+ }
+};