Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
golden_tests.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 "gtest/gtest.h"
6
7#include <sstream>
8
9#include "flutter/fml/platform/darwin/scoped_nsautorelease_pool.h"
18
19namespace impeller {
20namespace testing {
21
22namespace {
23std::string GetTestName() {
24 std::string suite_name =
25 ::testing::UnitTest::GetInstance()->current_test_suite()->name();
26 std::string test_name =
27 ::testing::UnitTest::GetInstance()->current_test_info()->name();
28 std::stringstream ss;
29 ss << "impeller_" << suite_name << "_" << test_name;
30 return ss.str();
31}
32
33std::string GetGoldenFilename() {
34 return GetTestName() + ".png";
35}
36
37bool SaveScreenshot(std::unique_ptr<Screenshot> screenshot) {
38 if (!screenshot || !screenshot->GetBytes()) {
39 return false;
40 }
41 std::string test_name = GetTestName();
42 std::string filename = GetGoldenFilename();
44 test_name, filename, screenshot->GetWidth(), screenshot->GetHeight());
45 return screenshot->WriteToPNG(
46 WorkingDirectory::Instance()->GetFilenamePath(filename));
47}
48
49} // namespace
50
51class GoldenTests : public ::testing::Test {
52 public:
54 : screenshotter_(new MetalScreenshotter(/*enable_wide_gamut=*/false)) {}
55
56 MetalScreenshotter& Screenshotter() { return *screenshotter_; }
57
58 void SetUp() override {
60 "gpu_string",
61 Screenshotter().GetPlayground().GetContext()->DescribeGpuModel());
62 }
63
64 private:
65 // This must be placed before any other members that may use the
66 // autorelease pool.
67 fml::ScopedNSAutoreleasePool autorelease_pool_;
68
69 std::unique_ptr<MetalScreenshotter> screenshotter_;
70};
71
72TEST_F(GoldenTests, ConicalGradient) {
73 Canvas canvas;
75
77 {125, 125}, 125, {Color(1.0, 0.0, 0.0, 1.0), Color(0.0, 0.0, 1.0, 1.0)},
78 {0, 1}, {180, 180}, 0, Entity::TileMode::kClamp, {});
79
80 paint.stroke_width = 0.0;
82 canvas.DrawRect(Rect::MakeXYWH(10, 10, 250, 250), paint);
83 Picture picture = canvas.EndRecordingAsPicture();
84
85 auto aiks_context =
86 AiksContext(Screenshotter().GetPlayground().GetContext(), nullptr);
87 auto screenshot = Screenshotter().MakeScreenshot(aiks_context, picture);
88 ASSERT_TRUE(SaveScreenshot(std::move(screenshot)));
89}
90} // namespace testing
91} // namespace impeller
Picture EndRecordingAsPicture()
Definition canvas.cc:802
void DrawRect(const Rect &rect, const Paint &paint)
Definition canvas.cc:493
static ColorSource MakeConicalGradient(Point center, Scalar radius, std::vector< Color > colors, std::vector< Scalar > stops, Point focus_center, Scalar focus_radius, Entity::TileMode tile_mode, Matrix effect_transform)
static GoldenDigest * Instance()
void AddDimension(const std::string &name, const std::string &value)
void AddImage(const std::string &test_name, const std::string &filename, int32_t width, int32_t height)
MetalScreenshotter & Screenshotter()
virtual std::unique_ptr< Screenshot > MakeScreenshot(AiksContext &aiks_context, const Picture &picture, const ISize &size={300, 300}, bool scale_content=true)=0
static WorkingDirectory * Instance()
const Paint & paint
TEST_F(GoldenTests, ConicalGradient)
static constexpr TRect MakeXYWH(Type x, Type y, Type width, Type height)
Definition rect.h:136