Add includer to gtest for include file tests.

Turn on debug info flag for non-semantic debug test.
This commit is contained in:
Qingyuan Zheng 2024-03-01 13:09:15 -08:00 committed by arcady-lunarg
parent a92c61f845
commit d8f5681ec0
9 changed files with 338 additions and 552 deletions

View file

@ -35,6 +35,7 @@
#ifndef GLSLANG_GTESTS_TEST_FIXTURE_H
#define GLSLANG_GTESTS_TEST_FIXTURE_H
#include <algorithm>
#include <cstdint>
#include <fstream>
#include <sstream>
@ -199,9 +200,42 @@ public:
} else
shader->setStringsWithLengths(&shaderStrings, &shaderLengths, 1);
if (!entryPointName.empty()) shader->setEntryPoint(entryPointName.c_str());
return shader->parse(
(resources ? resources : GetDefaultResources()),
defaultVersion, isForwardCompatible, controls);
// A includer that always assumes header name is a relative path to the test folder.
class GlslangTestIncluder : public glslang::TShader::Includer {
public:
virtual IncludeResult* includeLocal(const char* headerName, const char* /*includerName*/,
size_t /*inclusionDepth*/) override
{
std::string path = GLSLANG_TEST_DIRECTORY;
path += '/';
path += headerName;
std::replace(path.begin(), path.end(), '\\', '/');
auto [success, fileContent] = ReadFile(path);
if (success) {
auto buffer = new char[fileContent.size() + 1];
std::copy(fileContent.begin(), fileContent.end(), buffer);
buffer[fileContent.size()] = '\0';
return new IncludeResult(headerName, buffer, fileContent.size(), buffer);
}
return nullptr;
}
virtual void releaseInclude(IncludeResult* result) override
{
if (result != nullptr) {
delete[] static_cast<char*>(result->userData);
delete result;
}
}
};
GlslangTestIncluder includer;
return shader->parse((resources ? resources : GetDefaultResources()), defaultVersion, isForwardCompatible,
controls, includer);
}
// Compiles and links the given source |code| of the given shader