1 | // Copyright 2013 The Flutter Authors. All rights reserved. |
2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. |
4 | |
5 | #ifndef TESTING_TESTING_H_ |
6 | #define TESTING_TESTING_H_ |
7 | |
8 | #include <string> |
9 | #include <vector> |
10 | |
11 | #include "flutter/fml/file.h" |
12 | #include "flutter/fml/mapping.h" |
13 | #include "flutter/testing/assertions.h" |
14 | #include "gtest/gtest.h" |
15 | |
16 | namespace flutter { |
17 | namespace testing { |
18 | |
19 | //------------------------------------------------------------------------------ |
20 | /// @brief Returns the directory containing the test fixture for the target |
21 | /// if this target has fixtures configured. If there are no |
22 | /// fixtures, this is a link error. If you see a linker error on |
23 | /// this symbol, the unit-test target needs to depend on a |
24 | /// `test_fixtures` target. |
25 | /// |
26 | /// @return The fixtures path. |
27 | /// |
28 | const char* GetFixturesPath(); |
29 | |
30 | //------------------------------------------------------------------------------ |
31 | /// @brief Opens the fixtures directory for the unit-test harness. |
32 | /// |
33 | /// @return The file descriptor of the fixtures directory. |
34 | /// |
35 | fml::UniqueFD OpenFixturesDirectory(); |
36 | |
37 | //------------------------------------------------------------------------------ |
38 | /// @brief Opens a fixture of the given file name. |
39 | /// |
40 | /// @param[in] fixture_name The fixture name |
41 | /// |
42 | /// @return The file descriptor of the given fixture. An invalid file |
43 | /// descriptor is returned in case the fixture is not found. |
44 | /// |
45 | fml::UniqueFD OpenFixture(std::string fixture_name); |
46 | |
47 | //------------------------------------------------------------------------------ |
48 | /// @brief Opens a fixture of the given file name and returns a mapping to |
49 | /// its contents. |
50 | /// |
51 | /// @param[in] fixture_name The fixture name |
52 | /// |
53 | /// @return A mapping to the contents of fixture or null if the fixture does |
54 | /// not exist or its contents cannot be mapped in. |
55 | /// |
56 | std::unique_ptr<fml::Mapping> OpenFixtureAsMapping(std::string fixture_name); |
57 | |
58 | //------------------------------------------------------------------------------ |
59 | /// @brief Gets the name of the currently running test. This is useful in |
60 | /// generating logs or assets based on test name. |
61 | /// |
62 | /// @return The current test name. |
63 | /// |
64 | std::string GetCurrentTestName(); |
65 | |
66 | enum class MemsetPatternOp { |
67 | kMemsetPatternOpSetBuffer, |
68 | kMemsetPatternOpCheckBuffer, |
69 | }; |
70 | |
71 | //------------------------------------------------------------------------------ |
72 | /// @brief Depending on the operation, either scribbles a known pattern |
73 | /// into the buffer or checks if that pattern is present in an |
74 | /// existing buffer. This is a portable variant of the |
75 | /// memset_pattern class of methods that also happen to do assert |
76 | /// that the same pattern exists. |
77 | /// |
78 | /// @param buffer The buffer |
79 | /// @param[in] size The size |
80 | /// @param[in] op The operation |
81 | /// |
82 | /// @return If the result of the operation was a success. |
83 | /// |
84 | bool MemsetPatternSetOrCheck(uint8_t* buffer, size_t size, MemsetPatternOp op); |
85 | |
86 | bool MemsetPatternSetOrCheck(std::vector<uint8_t>& buffer, MemsetPatternOp op); |
87 | |
88 | } // namespace testing |
89 | } // namespace flutter |
90 | |
91 | #endif // TESTING_TESTING_H_ |
92 | |