Flutter Engine
The Flutter Engine
TestTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2015 Google Inc.
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
11struct GrContextOptions;
12
13// This is an example of a normal test. It should not require any GPU backends, that is, it is a
14// CPU test.
15DEF_TEST(TestNormal, reporter) {
17}
18
19// This is an example of a conditional test with a true condition.
20DEF_CONDITIONAL_TEST(TestTrueCondition, reporter, 1 == 1) {
22}
23
24// This is an example of a conditional test with a false condition.
25DEF_CONDITIONAL_TEST(TestFalseCondition, reporter, 1 == 0) {
26 ERRORF(reporter, "DEF_CONDITIONAL_TEST executed a test with a false condition");
27}
28
29// This is an example of a GPU test that runs if any Ganesh backend is compiled in. The test itself
30// is responsible for making the relevant GrDirectContext (e.g. using
31// sk_gpu_test::GrContextFactory).
34}
35
36// This is an example of a GPU test that tests a property that should work for all Ganesh contexts.
37// Note: Some of the contexts might not produce a rendering output.
40 REPORTER_ASSERT(reporter, ctxInfo.directContext());
41}
42
43// This is an example of a GPU test that tests a property that should work for all Ganesh contexts
44// that produce a rendering output.
47 ctxInfo,
50 REPORTER_ASSERT(reporter, ctxInfo.directContext());
51}
52
53// This is an example of a GPU test that tests a property that uses the mock Ganesh context.
54// It should be used if the test tests some behavior that is mocked with the mock context.
55DEF_GANESH_TEST_FOR_MOCK_CONTEXT(TestMockContext, reporter, ctxInfo) {
57 REPORTER_ASSERT(reporter, ctxInfo.directContext());
58}
59
60// Conditional variant of DEF_GANESH_TEST_FOR_ALL_CONTEXTS. It will only execute if the provided
61// condition parameter is true.
63 TestGpuAllContextsWithTrueCondition, reporter, ctxInfo, true, CtsEnforcement::kNever) {
65 REPORTER_ASSERT(reporter, ctxInfo.directContext());
66}
67
69 TestGpuAllContextsWithFalseCondition, reporter, ctxInfo, false, CtsEnforcement::kNever) {
70 ERRORF(reporter, "DEF_CONDITIONAL_GANESH_TEST_FOR_ALL_CONTEXTS ran with a false condition");
71}
72
73// Conditional variant of DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS. It will only execute if the
74// provided condition parameter is true.
75DEF_CONDITIONAL_GANESH_TEST_FOR_RENDERING_CONTEXTS(TestGpuRenderingContextsWithTrueCondition,
77 ctxInfo,
78 true,
81 REPORTER_ASSERT(reporter, ctxInfo.directContext());
82}
83
84DEF_CONDITIONAL_GANESH_TEST_FOR_RENDERING_CONTEXTS(TestGpuRenderingContextsWithFalseCondition,
86 ctxInfo,
87 false,
90 "DEF_CONDITIONAL_GANESH_TEST_FOR_RENDERING_CONTEXTS ran "
91 "with a false condition");
92}
93
94DEF_TEST(TestCtsEnforcement, reporter) {
95 auto verifyRunMode = [&](CtsEnforcement e, int apiLevel, CtsEnforcement::RunMode runMode) {
96 REPORTER_ASSERT(reporter, e.eval(apiLevel) == runMode);
97 };
98
100 verifyRunMode(e1, 0, CtsEnforcement::RunMode::kSkip);
103
105 verifyRunMode(e2, 0, CtsEnforcement::RunMode::kSkip);
108
110 verifyRunMode(e3, 0, CtsEnforcement::RunMode::kSkip);
113
116 verifyRunMode(e4, 0, CtsEnforcement::RunMode::kSkip);
119}
reporter
Definition: FontMgrTest.cpp:39
float e1
DEF_CONDITIONAL_TEST(TestTrueCondition, reporter, 1==1)
Definition: TestTest.cpp:20
DEF_GANESH_TEST_FOR_ALL_CONTEXTS(TestGpuAllContexts, reporter, ctxInfo, CtsEnforcement::kNever)
Definition: TestTest.cpp:38
DEF_GANESH_TEST(TestGpuFactory, reporter, factory, CtsEnforcement::kNever)
Definition: TestTest.cpp:32
DEF_TEST(TestNormal, reporter)
Definition: TestTest.cpp:15
DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(TestGpuRenderingContexts, reporter, ctxInfo, CtsEnforcement::kNever)
Definition: TestTest.cpp:45
DEF_CONDITIONAL_GANESH_TEST_FOR_ALL_CONTEXTS(TestGpuAllContextsWithTrueCondition, reporter, ctxInfo, true, CtsEnforcement::kNever)
Definition: TestTest.cpp:62
DEF_CONDITIONAL_GANESH_TEST_FOR_RENDERING_CONTEXTS(TestGpuRenderingContextsWithTrueCondition, reporter, ctxInfo, true, CtsEnforcement::kNever)
Definition: TestTest.cpp:75
DEF_GANESH_TEST_FOR_MOCK_CONTEXT(TestMockContext, reporter, ctxInfo)
Definition: TestTest.cpp:55
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
#define ERRORF(r,...)
Definition: Test.h:293
constexpr CtsEnforcement & withWorkarounds(ApiLevel workaroundVersion)