Brian Osman | 088913a | 2019-12-19 15:44:56 -0500 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2019 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 | |
| 8 | #include "src/core/SkRuntimeEffect.h" |
| 9 | #include "tests/Test.h" |
| 10 | |
| 11 | DEF_TEST(SkRuntimeEffectInvalidPrograms, r) { |
| 12 | auto test = [r](const char* src, const char* expected) { |
| 13 | auto [effect, errorText] = SkRuntimeEffect::Make(SkString(src)); |
| 14 | REPORTER_ASSERT(r, !effect); |
| 15 | REPORTER_ASSERT(r, errorText.contains(expected), |
| 16 | "Expected error message to contain \"%s\". Actual message: \"%s\"", |
| 17 | expected, errorText.c_str()); |
| 18 | }; |
| 19 | |
| 20 | // Features that are only allowed in .fp files (key, in uniform, ctype, when, tracked). |
| 21 | // Ensure that these fail, and the error messages contain the relevant keyword. |
| 22 | test("layout(key) in bool Input;" |
| 23 | "void main(float x, float y, inout half4 color) {}", |
| 24 | "key"); |
| 25 | |
| 26 | test("in uniform float Input;" |
| 27 | "void main(float x, float y, inout half4 color) {}", |
| 28 | "in uniform"); |
| 29 | |
| 30 | test("layout(ctype=SkRect) float4 Input;" |
| 31 | "void main(float x, float y, inout half4 color) {}", |
| 32 | "ctype"); |
| 33 | |
| 34 | test("in bool Flag; layout(when=Flag) uniform float Input;" |
| 35 | "void main(float x, float y, inout half4 color) {}", |
| 36 | "when"); |
| 37 | |
| 38 | test("layout(tracked) uniform float Input;" |
| 39 | "void main(float x, float y, inout half4 color) {}", |
| 40 | "tracked"); |
| 41 | } |