Flutter Engine
The Flutter Engine
SkSpanTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2022 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
9#include "tests/Test.h"
10
11#include <array>
12#include <cstddef>
13#include <cstdint>
14#include <utility>
15#include <vector>
16
17DEF_TEST(SkSpanBasicTemplateGuide, reporter) {
18 // Test constness preservation for SkSpan.
19 {
20 std::vector<int> v = {{1, 2, 3, 4, 5}};
21 auto s = SkSpan(v);
22 REPORTER_ASSERT(reporter, s[3] == 4);
23 s[3] = 100;
24 REPORTER_ASSERT(reporter, s[3] == 100);
25 }
26
27 {
28 std::vector<int> t = {{1, 2, 3, 4, 5}};
29 const std::vector<int>& v = t;
30 auto s = SkSpan(v);
31 //s[3] = 100; // Should fail to compile
32 REPORTER_ASSERT(reporter, s[3] == 4);
33 REPORTER_ASSERT(reporter, t[3] == 4);
34 t[3] = 100;
35 REPORTER_ASSERT(reporter, s[3] == 100);
36 }
37
38 {
39 std::array<int, 5> v = {{1, 2, 3, 4, 5}};
40 auto s = SkSpan(v); // {1, 2, 3, 4, 5}
41 REPORTER_ASSERT(reporter, s[3] == 4);
42 s[3] = 100; // {1, 2, 3, 100, 5}
43 REPORTER_ASSERT(reporter, s[3] == 100);
44 auto s1 = s.subspan(1,3); // {2, 3, 100}
45 REPORTER_ASSERT(reporter, s1.size() == 3);
46 REPORTER_ASSERT(reporter, s1.front() == 2);
47 REPORTER_ASSERT(reporter, s1.back() == 100);
48 auto s2 = s.subspan(2); // {3, 100, 5}
49 REPORTER_ASSERT(reporter, s2.size() == 3);
50 REPORTER_ASSERT(reporter, s2.front() == 3);
51 REPORTER_ASSERT(reporter, s2.back() == 5);
52 }
53
54 {
55 std::array<int, 5> t = {{1, 2, 3, 4, 5}};
56 const std::array<int, 5>& v = t;
57 auto s = SkSpan(v);
58 //s[3] = 100; // Should fail to compile
59 REPORTER_ASSERT(reporter, s[3] == 4);
60 REPORTER_ASSERT(reporter, t[3] == 4);
61 t[3] = 100;
62 REPORTER_ASSERT(reporter, s[3] == 100);
63 }
64
65 {
66 std::vector<int> v;
67 auto s = SkSpan(v);
68 REPORTER_ASSERT(reporter, s.empty());
69 }
70
71 auto routine = [&](SkSpan<const int> a) {
72 REPORTER_ASSERT(reporter, a.size() == 4);
73 };
74 routine({1,2,3,4});
75}
76
78 return s[0] == 1 && s[1] == 2 && s[2] == 3;
79}
80
81DEF_TEST(SkSpanDeduceParam, reporter) {
82 {
83 std::vector<int> v = {{1, 2, 3}};
86 }
87
88 {
89 const std::vector<int> v = {{1, 2, 3}};
92 }
93
94 REPORTER_ASSERT(reporter, test_span_parameter(std::vector<int>{1,2,3}));
95
96 {
97 int v[]{1, 2, 3};
99 }
100
101 {
102 test_span_parameter({1, 2, 3});
104 }
105
106 {
107 int v[]{1, 2, 3};
108 auto s = SkSpan(v);
110 }
111}
112
113DEF_TEST(SkSpanDeduceSize, reporter) {
114 int d[] = {1, 2, 3, 4, 5};
115 {
116 int s = std::size(d);
117 SkSpan span = SkSpan{d, s};
119 }
120 {
121 uint32_t s = std::size(d);
122 SkSpan span = SkSpan{d, s};
124 }
125 {
126 size_t s = std::size(d);
127 SkSpan span = SkSpan{d, s};
129 }
130 {
131 struct C {
132 int* data() { return nullptr; }
133 int size() const { return 0; }
134 };
135
136 C c;
137 SkSpan span = SkSpan(c);
138 REPORTER_ASSERT(reporter, span.size() == 0);
139 }
140}
reporter
Definition: FontMgrTest.cpp:39
DEF_TEST(SkSpanBasicTemplateGuide, reporter)
Definition: SkSpanTest.cpp:17
static bool test_span_parameter(SkSpan< const int > s)
Definition: SkSpanTest.cpp:77
SkSpan(Container &&) -> SkSpan< std::remove_pointer_t< decltype(std::data(std::declval< Container >()))> >
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
constexpr size_t size() const
Definition: SkSpan_impl.h:95
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition: main.cc:19
struct MyStruct s
struct MyStruct a[10]
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63