File: callback_test.cc

package info (click to toggle)
literki 0.0.0+20100113.git1da40724-1.2
  • links: PTS, VCS
  • area: main
  • in suites: sid, stretch
  • size: 3,444 kB
  • ctags: 1,153
  • sloc: cpp: 5,263; makefile: 72
file content (50 lines) | stat: -rw-r--r-- 672 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "external/callback.h"
#include "external/logger.h"

bool deleted = false;

class A {
 public:
  A(int y):x(y){}
  
  void SetX(int y){
    x = y;
  }
  
  int X(){
    return x;
  }
  
  ~A(){
    deleted = true;
  }
 
 private:
  int x;
};

int t = 1;

void fun(int a){
  t = a;
}


int main(){
  CHECK(!deleted);
  A* x = new A(5);
  internal::MakeDeleter(x);
  CHECK(deleted);
  A a(1);
  Closure *c = NewCallback(fun, 2);
  CHECK_EQ(t, 1);
  c->Run();
  CHECK_EQ(t, 2);
  c = NewCallback(&a, &A::SetX, 2);
  CHECK_EQ(a.X(), 1);
  c->Run();
  CHECK_EQ(a.X(), 2);
  ReturnClosure<int>* rc = NewReturnCallback(&a, &A::X);
  CHECK_EQ(rc->Run(), 2);
  return 0;
}