2 // Copyright (C) 2016 Google, Inc.
4 // All rights reserved.
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions
10 // Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
13 // Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following
15 // disclaimer in the documentation and/or other materials provided
16 // with the distribution.
18 // Neither the name of Google Inc. nor the names of its
19 // contributors may be used to endorse or promote products derived
20 // from this software without specific prior written permission.
22 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 // POSSIBILITY OF SUCH DAMAGE.
35 #include "TestFixture.h"
37 namespace glslangtest {
39 std::string FileNameAsCustomTestSuffix(
40 const ::testing::TestParamInfo<std::string>& info)
42 std::string name = info.param;
43 // A valid test case suffix cannot have '.' and '-' inside.
44 std::replace(name.begin(), name.end(), '.', '_');
45 std::replace(name.begin(), name.end(), '-', '_');
49 EShLanguage GetShaderStage(const std::string& stage)
51 if (stage == "vert") {
53 } else if (stage == "tesc") {
54 return EShLangTessControl;
55 } else if (stage == "tese") {
56 return EShLangTessEvaluation;
57 } else if (stage == "geom") {
58 return EShLangGeometry;
59 } else if (stage == "frag") {
60 return EShLangFragment;
61 } else if (stage == "comp") {
62 return EShLangCompute;
64 assert(0 && "Unknown shader stage");
69 EShMessages DeriveOptions(Source source, Semantics semantics, Target target)
71 EShMessages result = EShMsgDefault;
77 result = EShMsgReadHlsl;
83 result = static_cast<EShMessages>(result | EShMsgAST);
86 result = static_cast<EShMessages>(result | EShMsgSpvRules);
88 case Target::BothASTAndSpv:
89 result = static_cast<EShMessages>(result | EShMsgSpvRules | EShMsgAST);
94 case Semantics::OpenGL:
96 case Semantics::Vulkan:
97 result = static_cast<EShMessages>(result | EShMsgVulkanRules | EShMsgSpvRules);
104 std::pair<bool, std::string> ReadFile(const std::string& path)
106 std::ifstream fstream(path, std::ios::in);
108 std::string contents;
109 fstream.seekg(0, std::ios::end);
110 contents.reserve(fstream.tellg());
111 fstream.seekg(0, std::ios::beg);
112 contents.assign((std::istreambuf_iterator<char>(fstream)),
113 std::istreambuf_iterator<char>());
114 return std::make_pair(true, contents);
116 return std::make_pair(false, "");
119 bool WriteFile(const std::string& path, const std::string& contents)
121 std::ofstream fstream(path, std::ios::out);
122 if (!fstream) return false;
128 std::string GetSuffix(const std::string& name)
130 const size_t pos = name.rfind('.');
131 return (pos == std::string::npos) ? "" : name.substr(name.rfind('.') + 1);
134 } // namespace glslangtest