BoostFunctionTest.cc 820 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. protected:
  12. int a;
  13. boost::function<int(int)> func;
  14. void SetUp()
  15. {
  16. a = 6;
  17. }
  18. public:
  19. BoostTest()
  20. {
  21. }
  22. virtual ~BoostTest()
  23. {
  24. }
  25. int Max(int a, int b)
  26. {
  27. LOG(INFO) << a << " " << b;
  28. return a > b? a : b;
  29. }
  30. };
  31. TEST_F(BoostTest, Test1)
  32. {
  33. int x = 5;
  34. func = boost::bind(&BoostTest::Max, this, _1, x);
  35. int b = func(a);
  36. LOG(INFO) << b;
  37. }
  38. }
  39. int main(int argc, char* argv[])
  40. {
  41. FLAGS_logtostderr = true;
  42. testing::InitGoogleTest(&argc, argv);
  43. google::ParseCommandLineFlags(&argc, &argv, true);
  44. google::InitGoogleLogging(argv[0]);
  45. return RUN_ALL_TESTS();
  46. }