Avi Drissman | 505076bc | 2022-10-06 21:15:30 | [diff] [blame] | 1 | // Copyright 2022 The Chromium Authors |
Victor Costan | d4993a7 | 2022-01-04 17:53:19 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
Avi Drissman | 505076bc | 2022-10-06 21:15:30 | [diff] [blame] | 3 | // found in the LICENSE file. |
Victor Costan | d4993a7 | 2022-01-04 17:53:19 | [diff] [blame] | 4 | |
David Benjamin | 4e47ccd36 | 2024-07-11 21:29:50 | [diff] [blame] | 5 | #include <optional> |
| 6 | |
Reilly Grant | d6c5653 | 2023-04-06 03:13:03 | [diff] [blame] | 7 | #include "base/test/launcher/unit_test_launcher.h" |
Victor Costan | d4993a7 | 2022-01-04 17:53:19 | [diff] [blame] | 8 | #include "base/test/task_environment.h" |
Reilly Grant | d6c5653 | 2023-04-06 03:13:03 | [diff] [blame] | 9 | #include "base/test/test_suite.h" |
Reilly Grant | d6c5653 | 2023-04-06 03:13:03 | [diff] [blame] | 10 | |
| 11 | namespace { |
| 12 | |
| 13 | class LevelDbTestSuite : public base::TestSuite { |
| 14 | public: |
| 15 | LevelDbTestSuite(int argc, char** argv) : base::TestSuite(argc, argv) {} |
| 16 | |
| 17 | LevelDbTestSuite(const LevelDbTestSuite&) = delete; |
| 18 | LevelDbTestSuite& operator=(const LevelDbTestSuite&) = delete; |
| 19 | |
| 20 | ~LevelDbTestSuite() override = default; |
| 21 | |
| 22 | void Initialize() override { |
| 23 | base::TestSuite::Initialize(); |
| 24 | task_environment_.emplace(); |
| 25 | } |
| 26 | |
| 27 | void Shutdown() override { |
| 28 | task_environment_.reset(); |
| 29 | base::TestSuite::Shutdown(); |
| 30 | } |
| 31 | |
| 32 | private: |
| 33 | // Chromium's leveldb::Env uses PostTask. |
David Benjamin | 4e47ccd36 | 2024-07-11 21:29:50 | [diff] [blame] | 34 | std::optional<base::test::TaskEnvironment> task_environment_; |
Reilly Grant | d6c5653 | 2023-04-06 03:13:03 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | } // namespace |
Victor Costan | d4993a7 | 2022-01-04 17:53:19 | [diff] [blame] | 38 | |
| 39 | int main(int argc, char** argv) { |
Reilly Grant | d6c5653 | 2023-04-06 03:13:03 | [diff] [blame] | 40 | LevelDbTestSuite test_suite(argc, argv); |
Victor Costan | d4993a7 | 2022-01-04 17:53:19 | [diff] [blame] | 41 | |
Reilly Grant | d6c5653 | 2023-04-06 03:13:03 | [diff] [blame] | 42 | // Many tests reuse the same database path and so must run serially. |
| 43 | return base::LaunchUnitTestsSerially( |
| 44 | argc, argv, |
| 45 | base::BindOnce(&LevelDbTestSuite::Run, base::Unretained(&test_suite))); |
Victor Costan | d4993a7 | 2022-01-04 17:53:19 | [diff] [blame] | 46 | } |