Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
SkSpanTest.cpp File Reference
#include "include/core/SkSpan.h"
#include "tests/Test.h"
#include <array>
#include <cstddef>
#include <cstdint>
#include <utility>
#include <vector>

Go to the source code of this file.

Functions

 DEF_TEST (SkSpanBasicTemplateGuide, reporter)
 
static bool test_span_parameter (SkSpan< const int > s)
 
 DEF_TEST (SkSpanDeduceParam, reporter)
 
 DEF_TEST (SkSpanDeduceSize, reporter)
 

Function Documentation

◆ DEF_TEST() [1/3]

DEF_TEST ( SkSpanBasicTemplateGuide  ,
reporter   
)

Definition at line 17 of file SkSpanTest.cpp.

17 {
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}
reporter
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
struct MyStruct s
struct MyStruct a[10]

◆ DEF_TEST() [2/3]

DEF_TEST ( SkSpanDeduceParam  ,
reporter   
)

Definition at line 81 of file SkSpanTest.cpp.

81 {
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}
static bool test_span_parameter(SkSpan< const int > s)

◆ DEF_TEST() [3/3]

DEF_TEST ( SkSpanDeduceSize  ,
reporter   
)

Definition at line 113 of file SkSpanTest.cpp.

113 {
114 int d[] = {1, 2, 3, 4, 5};
115 {
116 int s = std::size(d);
117 SkSpan span = SkSpan{d, s};
118 REPORTER_ASSERT(reporter, span.size() == std::size(d));
119 }
120 {
121 uint32_t s = std::size(d);
122 SkSpan span = SkSpan{d, s};
123 REPORTER_ASSERT(reporter, span.size() == std::size(d));
124 }
125 {
126 size_t s = std::size(d);
127 SkSpan span = SkSpan{d, s};
128 REPORTER_ASSERT(reporter, span.size() == std::size(d));
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}
constexpr size_t size() const
Definition SkSpan_impl.h:95
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition main.cc:19
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41
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

◆ test_span_parameter()

static bool test_span_parameter ( SkSpan< const int s)
static

Definition at line 77 of file SkSpanTest.cpp.

77 {
78 return s[0] == 1 && s[1] == 2 && s[2] == 3;
79}