BoostFunctionTest.cc 770 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Created on: 2010-6-28
  2. // Author: tanghai
  3. #include <boost/function.hpp>
  4. #include <boost/bind.hpp>
  5. #include <gtest/gtest.h>
  6. #include <gflags/gflags.h>
  7. #include <glog/logging.h>
  8. namespace Egametang {
  9. class BoostTest: public testing::Test
  10. {
  11. void SetUp()
  12. {
  13. a = 6;
  14. }
  15. protected:
  16. int a;
  17. boost::function<int(int)> func;
  18. public:
  19. int Max(int a, int b)
  20. {
  21. LOG(INFO) << a << " " << b;
  22. return a > b? a : b;
  23. }
  24. };
  25. TEST_F(BoostTest, Test1)
  26. {
  27. int x = 5;
  28. func = boost::bind(&BoostTest::Max, this, _1, x);
  29. int b = func(a);
  30. LOG(INFO) << b;
  31. }
  32. }
  33. int main(int argc, char* argv[])
  34. {
  35. FLAGS_logtostderr = true;
  36. testing::InitGoogleTest(&argc, argv);
  37. google::ParseCommandLineFlags(&argc, &argv, true);
  38. google::InitGoogleLogging(argv[0]);
  39. return RUN_ALL_TESTS();
  40. }