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
16namespace flutter {
17namespace testing {
18
19const char* GetSourcePath();
20
21//------------------------------------------------------------------------------
22/// @brief Returns the directory containing the test fixture for the target
23/// if this target has fixtures configured. If there are no
24/// fixtures, this is a link error. If you see a linker error on
25/// this symbol, the unit-test target needs to depend on a
26/// `test_fixtures` target.
27///
28/// @return The fixtures path.
29///
30const char* GetFixturesPath();
31
32//------------------------------------------------------------------------------
33/// @brief Returns the directory containing assets shared across all tests.
34///
35/// @return The testing assets path.
36///
37const char* GetTestingAssetsPath();
38
39//------------------------------------------------------------------------------
40/// @brief Returns the default path to kernel_blob.bin. This file is within
41/// the directory returned by `GetFixturesPath()`.
42///
43/// @return The kernel file path.
44///
45std::string GetDefaultKernelFilePath();
46
47//------------------------------------------------------------------------------
48/// @brief Opens the fixtures directory for the unit-test harness.
49///
50/// @return The file descriptor of the fixtures directory.
51///
52fml::UniqueFD OpenFixturesDirectory();
53
54//------------------------------------------------------------------------------
55/// @brief Opens a fixture of the given file name.
56///
57/// @param[in] fixture_name The fixture name
58///
59/// @return The file descriptor of the given fixture. An invalid file
60/// descriptor is returned in case the fixture is not found.
61///
62fml::UniqueFD OpenFixture(const std::string& fixture_name);
63
64//------------------------------------------------------------------------------
65/// @brief Opens a fixture of the given file name and returns a mapping to
66/// its contents.
67///
68/// @param[in] fixture_name The fixture name
69///
70/// @return A mapping to the contents of fixture or null if the fixture does
71/// not exist or its contents cannot be mapped in.
72///
73std::unique_ptr<fml::Mapping> OpenFixtureAsMapping(
74 const std::string& fixture_name);
75
76//------------------------------------------------------------------------------
77/// @brief Gets the name of the currently running test. This is useful in
78/// generating logs or assets based on test name.
79///
80/// @return The current test name.
81///
82std::string GetCurrentTestName();
83
84enum class MemsetPatternOp {
85 kMemsetPatternOpSetBuffer,
86 kMemsetPatternOpCheckBuffer,
87};
88
89//------------------------------------------------------------------------------
90/// @brief Depending on the operation, either scribbles a known pattern
91/// into the buffer or checks if that pattern is present in an
92/// existing buffer. This is a portable variant of the
93/// memset_pattern class of methods that also happen to do assert
94/// that the same pattern exists.
95///
96/// @param buffer The buffer
97/// @param[in] size The size
98/// @param[in] op The operation
99///
100/// @return If the result of the operation was a success.
101///
102bool MemsetPatternSetOrCheck(uint8_t* buffer, size_t size, MemsetPatternOp op);
103
104bool MemsetPatternSetOrCheck(std::vector<uint8_t>& buffer, MemsetPatternOp op);
105
106} // namespace testing
107} // namespace flutter
108
109#endif // TESTING_TESTING_H_
110

source code of flutter_engine/flutter/testing/testing.h

Morty Proxy This is a proxified and sanitized view of the page, visit original site.