Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit cf403fd

Browse files
committed
Make EntityTest.AdvancedBlendCoverageHintIsNotResetByEntityPass less fragile
1 parent 813bd16 commit cf403fd

File tree

1 file changed

+17
-34
lines changed

1 file changed

+17
-34
lines changed

impeller/entity/entity_unittests.cc

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
#include <algorithm>
56
#include <cstring>
67
#include <memory>
78
#include <optional>
@@ -2606,7 +2607,9 @@ class TestRenderTargetAllocator : public RenderTargetAllocator {
26062607

26072608
void End() override { RenderTargetAllocator::End(); }
26082609

2609-
std::vector<TextureDescriptor> GetDescriptors() const { return allocated_; }
2610+
std::vector<TextureDescriptor> GetAllocatedTextureDescriptors() const {
2611+
return allocated_;
2612+
}
26102613

26112614
void ResetDescriptors() { allocated_.clear(); }
26122615

@@ -2651,39 +2654,19 @@ TEST_P(EntityTest, AdvancedBlendCoverageHintIsNotResetByEntityPass) {
26512654

26522655
EXPECT_TRUE(pass->Render(content_context, rt));
26532656

2654-
if (test_allocator->GetDescriptors().size() == 6u) {
2655-
EXPECT_EQ(test_allocator->GetDescriptors()[0].size, ISize(1000, 1000));
2656-
EXPECT_EQ(test_allocator->GetDescriptors()[1].size, ISize(1000, 1000));
2657-
EXPECT_EQ(test_allocator->GetDescriptors()[2].size, ISize(1000, 1000));
2658-
EXPECT_EQ(test_allocator->GetDescriptors()[3].size, ISize(1000, 1000));
2659-
2660-
EXPECT_EQ(test_allocator->GetDescriptors()[4].size, ISize(200, 200));
2661-
EXPECT_EQ(test_allocator->GetDescriptors()[5].size, ISize(200, 200));
2662-
} else if (test_allocator->GetDescriptors().size() == 7u) {
2663-
// Onscreen render target.
2664-
EXPECT_EQ(test_allocator->GetDescriptors()[0].size, ISize(1000, 1000));
2665-
EXPECT_EQ(test_allocator->GetDescriptors()[1].size, ISize(1000, 1000));
2666-
EXPECT_EQ(test_allocator->GetDescriptors()[2].size, ISize(1000, 1000));
2667-
2668-
EXPECT_EQ(test_allocator->GetDescriptors()[3].size, ISize(200, 200));
2669-
EXPECT_EQ(test_allocator->GetDescriptors()[4].size, ISize(200, 200));
2670-
EXPECT_EQ(test_allocator->GetDescriptors()[5].size, ISize(200, 200));
2671-
EXPECT_EQ(test_allocator->GetDescriptors()[6].size, ISize(200, 200));
2672-
} else if (test_allocator->GetDescriptors().size() == 4u) {
2673-
EXPECT_EQ(test_allocator->GetDescriptors()[0].size, ISize(1000, 1000));
2674-
EXPECT_EQ(test_allocator->GetDescriptors()[1].size, ISize(1000, 1000));
2675-
2676-
EXPECT_EQ(test_allocator->GetDescriptors()[2].size, ISize(200, 200));
2677-
EXPECT_EQ(test_allocator->GetDescriptors()[3].size, ISize(200, 200));
2678-
} else {
2679-
std::stringstream sizes;
2680-
for (const auto& desc : test_allocator->GetDescriptors()) {
2681-
sizes << "\nISize" << desc.size;
2682-
}
2683-
EXPECT_TRUE(false) << "Unexpected number of render targets. Total: "
2684-
<< test_allocator->GetDescriptors().size()
2685-
<< "\nExpected sizes: " << sizes.str();
2686-
}
2657+
std::vector<TextureDescriptor> descriptors =
2658+
test_allocator->GetAllocatedTextureDescriptors();
2659+
2660+
auto contains_size = [&descriptors](ISize size) -> bool {
2661+
return std::find_if(descriptors.begin(), descriptors.end(),
2662+
[&size](auto desc) { return desc.size == size; }) !=
2663+
descriptors.end();
2664+
};
2665+
2666+
EXPECT_TRUE(contains_size(ISize(1000, 1000)))
2667+
<< "The root texture wasn't allocated";
2668+
EXPECT_TRUE(contains_size(ISize(200, 200)))
2669+
<< "The ColorBurned texture wasn't allocated (100x100 scales up 2x)";
26872670
}
26882671

26892672
TEST_P(EntityTest, SpecializationConstantsAreAppliedToVariants) {

0 commit comments

Comments
 (0)