• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016 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 
8 #include "src/sksl/SkSLCompiler.h"
9 
10 #include "tests/Test.h"
11 
test_failure(skiatest::Reporter * r,const char * src,const char * error)12 static void test_failure(skiatest::Reporter* r, const char* src, const char* error) {
13     SkSL::Compiler compiler;
14     SkSL::Program::Settings settings;
15     sk_sp<GrShaderCaps> caps = SkSL::ShaderCapsFactory::Default();
16     settings.fCaps = caps.get();
17     std::unique_ptr<SkSL::Program> program = compiler.convertProgram(SkSL::Program::kFragment_Kind,
18                                                                      SkSL::String(src), settings);
19     if (program) {
20         SkSL::String ignored;
21         compiler.toSPIRV(*program, &ignored);
22     }
23     SkSL::String skError(error);
24     if (compiler.errorText() != skError) {
25         SkDebugf("SKSL ERROR:\n    source: %s\n    expected: %s    received: %s", src, error,
26                  compiler.errorText().c_str());
27     }
28     REPORTER_ASSERT(r, compiler.errorText() == skError);
29 }
30 
DEF_TEST(SkSLBadOffset,r)31 DEF_TEST(SkSLBadOffset, r) {
32     test_failure(r,
33                  "struct Bad { layout (offset = 5) int x; } bad; void main() { bad.x = 5; "
34                  "sk_FragColor.r = half(bad.x); }",
35                  "error: 1: offset of field 'x' must be a multiple of 4\n1 error\n");
36     test_failure(r,
37                  "struct Bad { int x; layout (offset = 0) int y; } bad; void main() { bad.x = 5; "
38                  "sk_FragColor.r = half(bad.x); }",
39                  "error: 1: offset of field 'y' must be at least 4\n1 error\n");
40 }
41