Chinmay Garde b111a13d25 Allow embedders to post Dart objects on send ports from the native side. (flutter/engine#14477)
This is a non-breaking addition to the stable Flutter Embedder API and exposes a
subset of the functionality provided by Dart_PostCObject API in a stable and
tested manner to custom embedder implementations.

Send port acquisition can currently be done as described in the unit-test but
there may be opportunities to extend this API in the future to access ports more
easily or create ports from the native side.

The following capabilities of the the Dart_PostCObject API are explicitly NOT
exposed:
* Object arrays: This allows callers to create complex object graphs but only
  using the primitives specified in the native API. I could find no current use
  case for this and would have made the implementation a lot more complex. This
  is something we can add in the future if necessary however.
* Capabilities and ports: Again no use cases and I honestly I didn’t understand
  how to use capabilities. If needed, these can be added at a later point by
  appending to the union.

Fixes https://github.com/flutter/flutter/issues/46624
Fixes b/145982720
2019-12-13 17:28:21 -08:00

92 lines
3.2 KiB
C++

// 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_