|
| 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"impeller/aiks/canvas.h" |
| 10 | +#include"impeller/entity/contents/conical_gradient_contents.h" |
| 11 | +#include"impeller/geometry/path_builder.h" |
| 12 | +#include"impeller/golden_tests/golden_digest.h" |
| 13 | +#include"impeller/golden_tests/metal_screenshot.h" |
| 14 | +#include"impeller/golden_tests/metal_screenshoter.h" |
| 15 | +#include"impeller/golden_tests/working_directory.h" |
| 16 | + |
| 17 | +namespaceimpeller { |
| 18 | +namespacetesting { |
| 19 | + |
| 20 | +namespace { |
| 21 | +std::stringGetTestName() { |
| 22 | + std::string suite_name = |
| 23 | +::testing::UnitTest::GetInstance()->current_test_suite()->name(); |
| 24 | + std::string test_name = |
| 25 | +::testing::UnitTest::GetInstance()->current_test_info()->name(); |
| 26 | + std::stringstream ss; |
| 27 | + ss <<"impeller_" << suite_name <<"_" << test_name; |
| 28 | +return ss.str(); |
| 29 | +} |
| 30 | + |
| 31 | +std::stringGetGoldenFilename() { |
| 32 | +returnGetTestName() +".png"; |
| 33 | +} |
| 34 | + |
| 35 | +boolSaveScreenshot(std::unique_ptr<MetalScreenshot> screenshot) { |
| 36 | +if (!screenshot || !screenshot->GetBytes()) { |
| 37 | +returnfalse; |
| 38 | + } |
| 39 | + std::string test_name =GetTestName(); |
| 40 | + std::string filename =GetGoldenFilename(); |
| 41 | +GoldenDigest::Instance()->AddImage( |
| 42 | + test_name, filename, screenshot->GetWidth(), screenshot->GetHeight()); |
| 43 | +return screenshot->WriteToPNG( |
| 44 | +WorkingDirectory::Instance()->GetFilenamePath(filename)); |
| 45 | +} |
| 46 | +}// namespace |
| 47 | + |
| 48 | +classGoldenTests : public ::testing::Test { |
| 49 | +public: |
| 50 | +GoldenTests() : screenshoter_(new MetalScreenshoter()) {} |
| 51 | + |
| 52 | + MetalScreenshoter&Screenshoter() {return *screenshoter_; } |
| 53 | + |
| 54 | +private: |
| 55 | + std::unique_ptr<MetalScreenshoter> screenshoter_; |
| 56 | +}; |
| 57 | + |
| 58 | +TEST_F(GoldenTests, ConicalGradient) { |
| 59 | + Canvas canvas; |
| 60 | + Paint paint; |
| 61 | + paint.color_source_type = Paint::ColorSourceType::kConicalGradient; |
| 62 | + paint.color_source = []() { |
| 63 | +auto result = std::make_shared<ConicalGradientContents>(); |
| 64 | + result->SetCenterAndRadius(Point(125,125),125); |
| 65 | + result->SetColors({Color(1.0,0.0,0.0,1.0),Color(0.0,0.0,1.0,1.0)}); |
| 66 | + result->SetStops({0,1}); |
| 67 | + result->SetFocus(Point(180,180),0); |
| 68 | + result->SetTileMode(Entity::TileMode::kClamp); |
| 69 | +return result; |
| 70 | + }; |
| 71 | + paint.stroke_width =0.0; |
| 72 | + paint.style = Paint::Style::kFill; |
| 73 | + canvas.DrawRect(Rect(10,10,250,250), paint); |
| 74 | + Picture picture = canvas.EndRecordingAsPicture(); |
| 75 | +auto screenshot =Screenshoter().MakeScreenshot(std::move(picture)); |
| 76 | +ASSERT_TRUE(SaveScreenshot(std::move(screenshot))); |
| 77 | +} |
| 78 | +}// namespace testing |
| 79 | +}// namespace impeller |