Flutter Impeller
playground_test.cc
Go to the documentation of this file.
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 #include "flutter/fml/time/time_point.h"
6 
7 #include "impeller/base/timing.h"
10 
11 namespace impeller {
12 
14  : Playground(GetParam(),
15  PlaygroundSwitches{flutter::testing::GetArgsForProcess()}) {
17  [](const char* message, const char* file, int line) -> bool {
18  // GTEST_MESSAGE_AT_ can only be used in a function that returns void.
19  // Hence the goofy lambda. The failure message and location will still
20  // be correct however.
21  //
22  // https://google.github.io/googletest/advanced.html#assertion-placement
23  [message, file, line]() -> void {
24  GTEST_MESSAGE_AT_(file, line, "Impeller Validation Error",
25  ::testing::TestPartResult::kFatalFailure)
26  << message;
27  }();
28  return true;
29  });
30 }
31 
34 }
35 
37  if (!Playground::SupportsBackend(GetParam())) {
38  GTEST_SKIP() << "Playground doesn't support this backend type.";
39  return;
40  }
41 
43  GTEST_SKIP() << "Skipping due to user action.";
44  return;
45  }
46 }
47 
50 }
51 
53  return GetParam();
54 }
55 
56 // |Playground|
57 std::unique_ptr<fml::Mapping> PlaygroundTest::OpenAssetAsMapping(
58  std::string asset_name) const {
59  return flutter::testing::OpenFixtureAsMapping(asset_name);
60 }
61 
62 absl::StatusOr<RuntimeStage::Map> PlaygroundTest::OpenAssetAsRuntimeStage(
63  const char* asset_name) const {
64  const std::shared_ptr<fml::Mapping> fixture =
65  flutter::testing::OpenFixtureAsMapping(asset_name);
66  if (!fixture || fixture->GetSize() == 0) {
67  return absl::NotFoundError("Asset not found or empty.");
68  }
69  return RuntimeStage::DecodeRuntimeStages(fixture);
70 }
71 
72 // |Playground|
73 std::string PlaygroundTest::GetWindowTitle() const {
74  std::stringstream stream;
75  stream << "Impeller Playground for '"
76  << flutter::testing::GetCurrentTestName() << "' ";
77  switch (GetBackend()) {
80  break;
83  if (GetSwitches().use_angle) {
84  stream << " (Angle) ";
85  }
86  break;
88  if (GetSwitches().use_swiftshader) {
89  stream << " (SwiftShader) ";
90  }
91  break;
92  }
93  stream << " (Press ESC to quit)";
94  return stream.str();
95 }
96 
97 // |Playground|
98 bool PlaygroundTest::ShouldKeepRendering() const {
99  if (!GetSwitches().timeout.has_value()) {
100  return true;
101  }
102 
103  if (SecondsF{GetSecondsElapsed()} > GetSwitches().timeout.value()) {
104  return false;
105  }
106 
107  return true;
108 }
109 
110 } // namespace impeller
static bool ShouldOpenNewPlaygrounds()
Definition: playground.cc:246
const PlaygroundSwitches & GetSwitches() const
Return an unmodifiable reference to the current switches. The switches might change at the start of a...
Definition: playground.h:167
static bool SupportsBackend(PlaygroundBackend backend)
Definition: playground.cc:169
Scalar GetSecondsElapsed() const
Get the amount of time elapsed from the start of the playground's execution.
Definition: playground.cc:279
std::unique_ptr< fml::Mapping > OpenAssetAsMapping(std::string asset_name) const override
std::string GetWindowTitle() const override
absl::StatusOr< RuntimeStage::Map > OpenAssetAsRuntimeStage(const char *asset_name) const
PlaygroundBackend GetBackend() const
static absl::StatusOr< Map > DecodeRuntimeStages(const std::shared_ptr< fml::Mapping > &payload)
void ImpellerValidationErrorsSetCallback(ValidationFailureCallback callback)
Sets a callback that callers (usually tests) can set to intercept validation failures.
Definition: validation.cc:21
PlaygroundBackend
Definition: playground.h:27
std::chrono::duration< float > SecondsF
Definition: timing.h:13
std::optional< std::chrono::milliseconds > timeout
Definition: switches.h:21