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