Edit

kc3-lang/angle/src/tests/compiler_tests/RegenerateStructNames_test.cpp

Branch :

  • Show log

    Commit

  • Author : Olli Etuaho
    Date : 2017-12-08 20:49:00
    Hash : ae4dbf32
    Message : Don't allocate name strings for empty symbols This removes unnecessary memory allocations. BUG=angleproject:2267 TEST=angle_unittests Change-Id: Ide575ea19ab2f8e9fc93092490f1352efa6024a3 Reviewed-on: https://chromium-review.googlesource.com/817415 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: Corentin Wallez <cwallez@chromium.org>

  • src/tests/compiler_tests/RegenerateStructNames_test.cpp
  • //
    // Copyright (c) 2017 The ANGLE Project Authors. All rights reserved.
    // Use of this source code is governed by a BSD-style license that can be
    // found in the LICENSE file.
    //
    // RegenerateStructNames_test.cpp:
    //   Tests for regenerating struct names.
    //
    
    #include "GLSLANG/ShaderLang.h"
    #include "angle_gl.h"
    #include "gtest/gtest.h"
    #include "tests/test_utils/compiler_test.h"
    
    using namespace sh;
    
    class RegenerateStructNamesTest : public MatchOutputCodeTest
    {
      public:
        RegenerateStructNamesTest()
            : MatchOutputCodeTest(GL_FRAGMENT_SHADER, SH_REGENERATE_STRUCT_NAMES, SH_ESSL_OUTPUT)
        {
        }
    };
    
    // Test that a struct defined in a function scope is renamed. The global struct that's used as a
    // type of a uniform cannot be renamed.
    TEST_F(RegenerateStructNamesTest, GlobalStructAndLocalStructWithTheSameName)
    {
        const std::string &shaderString =
            R"(precision mediump float;
    
            struct myStruct
            {
                float foo;
            };
    
            uniform myStruct us;
    
            void main()
            {
                struct myStruct
                {
                    vec2 bar;
                };
                myStruct scoped;
                scoped.bar = vec2(1.0, 2.0) * us.foo;
                gl_FragColor = vec4(scoped.bar, 0.0, 1.0);
            })";
        compile(shaderString);
        EXPECT_TRUE(foundInCode("struct _umyStruct"));
        EXPECT_TRUE(foundInCode("struct _u_webgl_struct_"));
    }
    
    // Test that a nameless struct is handled gracefully.
    TEST_F(RegenerateStructNamesTest, NamelessStruct)
    {
        const std::string &shaderString =
            R"(precision mediump float;
    
            uniform float u;
    
            void main()
            {
                struct
                {
                    vec2 bar;
                } scoped;
                scoped.bar = vec2(1.0, 2.0) * u;
                gl_FragColor = vec4(scoped.bar, 0.0, 1.0);
            })";
        compile(shaderString);
        EXPECT_TRUE(foundInCode("struct"));
    }