blob: 45ba89a5912b9d97137ec65337b3ebe66832634c [file] [log] [blame]
Brian Osman088913a2019-12-19 15:44:56 -05001/*
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
Brian Osmanee426f22020-01-02 11:55:24 -05008#include "include/effects/SkRuntimeEffect.h"
Brian Osman088913a2019-12-19 15:44:56 -05009#include "tests/Test.h"
10
Brian Osman82d49702019-12-30 13:44:01 -050011DEF_TEST(SkRuntimeEffectInvalidInputs, r) {
12 auto test = [r](const char* hdr, const char* expected) {
13 SkString src = SkStringPrintf("%s void main(float x, float y, inout half4 color) {}", hdr);
14 auto [effect, errorText] = SkRuntimeEffect::Make(src);
Brian Osman088913a2019-12-19 15:44:56 -050015 REPORTER_ASSERT(r, !effect);
16 REPORTER_ASSERT(r, errorText.contains(expected),
17 "Expected error message to contain \"%s\". Actual message: \"%s\"",
18 expected, errorText.c_str());
19 };
20
21 // Features that are only allowed in .fp files (key, in uniform, ctype, when, tracked).
22 // Ensure that these fail, and the error messages contain the relevant keyword.
Brian Osman82d49702019-12-30 13:44:01 -050023 test("layout(key) in bool Input;", "key");
24 test("in uniform float Input;", "in uniform");
25 test("layout(ctype=SkRect) float4 Input;", "ctype");
26 test("in bool Flag; layout(when=Flag) uniform float Input;", "when");
27 test("layout(tracked) uniform float Input;", "tracked");
Brian Osman088913a2019-12-19 15:44:56 -050028
Brian Osman82d49702019-12-30 13:44:01 -050029 // Runtime SkSL supports a limited set of uniform types. No samplers, for example:
30 test("uniform sampler2D s;", "sampler2D");
Brian Osman088913a2019-12-19 15:44:56 -050031
Brian Osman82d49702019-12-30 13:44:01 -050032 // 'in' variables can't be arrays
33 test("in int Input[2];", "array");
Brian Osman8783b782020-01-06 11:13:45 -050034
35 // Type specific restrictions:
36
37 // 'bool', 'int' can't be 'uniform'
38 test("uniform bool Input;", "'uniform'");
39 test("uniform int Input;", "'uniform'");
40
41 // vector and matrix types can't be 'in'
42 test("in float2 Input;", "'in'");
43 test("in half3x3 Input;", "'in'");
Brian Osman088913a2019-12-19 15:44:56 -050044}