| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- #include <boost/function.hpp>
- #include <boost/bind.hpp>
- #include <gtest/gtest.h>
- #include "Thread/ThreadPool.h"
- namespace Egametang {
- class ThreadPoolTest: public testing::Test
- {
- protected:
- ThreadPool pool;
- public:
- ThreadPoolTest() : pool(10)
- {
- }
- virtual ~ThreadPoolTest()
- {
- }
- void Max(int a, int b, int* z)
- {
- *z = a > b? a : b;
- }
- };
- TEST_F(ThreadPoolTest, Test1)
- {
- std::vector<int> x(100, 8);
- std::vector<int> y(100, 9);
- std::vector<int> z(100, 0);
- for (int i = 0; i < 100; ++i)
- {
- pool.Schedule(
- boost::bind(&ThreadPoolTest::Max,
- this, x[i], y[i], &z[i]));
- }
- pool.Wait();
- for (int i = 0; i < 100; ++i)
- {
- ASSERT_EQ(9, z[i]);
- }
- }
- } // namespace Egametang
- int main(int argc, char* argv[])
- {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
- }
|