| 83 | } |
| 84 | |
| 85 | void SC::ThreadPoolTest::testThreadPoolErrors() |
| 86 | { |
| 87 | static const size_t numTasks = 4; |
| 88 | |
| 89 | // Define tasks before threadpool to avoid threadpool destructor accessing invalid tasks |
| 90 | SC::ThreadPool::Task tasks[numTasks]; |
| 91 | |
| 92 | SC::ThreadPool threadPool; |
| 93 | Result result = threadPool.create(0); |
| 94 | SC_TEST_EXPECT(result.isError(ThreadingResultCategory, ThreadingError::InvalidWorkerThreadCount)); |
| 95 | |
| 96 | SC_TEST_EXPECT(threadPool.create(2)); |
| 97 | result = threadPool.create(2); |
| 98 | SC_TEST_EXPECT(result.isError(ThreadingResultCategory, ThreadingError::ThreadPoolAlreadyCreated)); |
| 99 | |
| 100 | SC::ThreadPool threadPool2; |
| 101 | SC_TEST_EXPECT(threadPool2.create(1)); |
| 102 | |
| 103 | SC::ThreadPool uninitializedThreadPool; |
| 104 | result = uninitializedThreadPool.queueTask(tasks[0]); |
| 105 | SC_TEST_EXPECT(result.isError(ThreadingResultCategory, ThreadingError::ThreadPoolNotCreated)); |
| 106 | result = uninitializedThreadPool.waitForTask(tasks[0]); |
| 107 | SC_TEST_EXPECT(result.isError(ThreadingResultCategory, ThreadingError::ThreadPoolNotCreated)); |
| 108 | |
| 109 | for (size_t idx = 0; idx < numTasks; idx++) |
| 110 | { |