Browse Source

ShaderTools: port to the new Utility::Path, including plugins,

Again, exists() + read() is now an atomic and more robust Path::read(),
apart from that not much interesting.
pull/556/head
Vladimír Vondruš 4 years ago
parent
commit
3e2bbb6ad0
  1. 19
      doc/snippets/MagnumShaderTools.cpp
  2. 45
      src/Magnum/ShaderTools/AbstractConverter.cpp
  3. 211
      src/Magnum/ShaderTools/Test/AbstractConverterTest.cpp
  4. 14
      src/Magnum/ShaderTools/Test/SpirvTest.cpp
  5. 210
      src/MagnumPlugins/AnyShaderConverter/Test/AnyConverterTest.cpp

19
doc/snippets/MagnumShaderTools.cpp

@ -101,7 +101,8 @@ Containers::Pointer<ShaderTools::AbstractConverter> converter;
Containers::Array<char> extract(const std::string&, const std::string&); Containers::Array<char> extract(const std::string&, const std::string&);
/* [AbstractConverter-usage-callbacks] */ /* [AbstractConverter-usage-callbacks] */
struct Data { struct Data {
std::unordered_map<std::string, Containers::Array<char>> files; std::unordered_map<std::string, Containers::Optional<
Containers::Array<char>>> files;
} data; } data;
converter->setInputFileCallback([](const std::string& filename, converter->setInputFileCallback([](const std::string& filename,
@ -116,16 +117,14 @@ converter->setInputFileCallback([](const std::string& filename,
return {}; return {};
} }
/* Extract from an archive if not there yet; fail if not extraction /* Extract from an archive if not there yet. If the extraction fails,
failed */ remember that to not attempt to extract the same file again next
if(found == data.files.end()) { time. */
Containers::Array<char> file = extract("shaders.zip", filename); if(found == data.files.end()) found = data.files.emplace(
if(!file) return {}; filename, extract("shaders.zip", filename)).first;
found = data.files.emplace(filename, std::move(file)).first; if(!found->second) return {};
} return Containers::ArrayView<const char>{*found->second};
return Containers::ArrayView<const char>{found->second};
}, data); }, data);
/* extracted from a ZIP */ /* extracted from a ZIP */

45
src/Magnum/ShaderTools/AbstractConverter.cpp

@ -29,9 +29,8 @@
#include <Corrade/Containers/EnumSet.hpp> #include <Corrade/Containers/EnumSet.hpp>
#include <Corrade/Containers/Optional.h> #include <Corrade/Containers/Optional.h>
#include <Corrade/Containers/String.h> #include <Corrade/Containers/String.h>
#include <Corrade/Containers/StringStl.h> #include <Corrade/Containers/StringStl.h> /** @todo remove once file callbacks are <string>-free */
#include <Corrade/Utility/DebugStl.h> #include <Corrade/Utility/Path.h>
#include <Corrade/Utility/Directory.h>
#include "Magnum/FileCallback.h" #include "Magnum/FileCallback.h"
@ -51,9 +50,10 @@ std::string AbstractConverter::pluginInterface() {
#ifndef CORRADE_PLUGINMANAGER_NO_DYNAMIC_PLUGIN_SUPPORT #ifndef CORRADE_PLUGINMANAGER_NO_DYNAMIC_PLUGIN_SUPPORT
std::vector<std::string> AbstractConverter::pluginSearchPaths() { std::vector<std::string> AbstractConverter::pluginSearchPaths() {
const Containers::Optional<Containers::String> libraryLocation = Utility::Path::libraryLocation(&pluginInterface);
return PluginManager::implicitPluginSearchPaths( return PluginManager::implicitPluginSearchPaths(
#ifndef MAGNUM_BUILD_STATIC #ifndef MAGNUM_BUILD_STATIC
Utility::Directory::libraryLocation(&pluginInterface), libraryLocation ? *libraryLocation : Containers::String{},
#else #else
{}, {},
#endif #endif
@ -244,12 +244,13 @@ std::pair<bool, Containers::String> AbstractConverter::doValidateFile(const Stag
/* Otherwise open the file directly */ /* Otherwise open the file directly */
} else { } else {
if(!Utility::Directory::exists(filename)) { const Containers::Optional<Containers::Array<char>> data = Utility::Path::read(filename);
if(!data) {
Error() << "ShaderTools::AbstractConverter::validateFile(): cannot open file" << filename; Error() << "ShaderTools::AbstractConverter::validateFile(): cannot open file" << filename;
return {}; return {};
} }
return doValidateData(stage, Utility::Directory::read(filename)); return doValidateData(stage, *data);
} }
} }
@ -278,7 +279,7 @@ bool AbstractConverter::convertDataToFile(const Stage stage, const Containers::A
const Containers::Array<char> out = doConvertDataToData(stage, Containers::arrayCast<const char>(data)); const Containers::Array<char> out = doConvertDataToData(stage, Containers::arrayCast<const char>(data));
if(!out) return false; if(!out) return false;
if(!Utility::Directory::write(filename, out)) { if(!Utility::Path::write(filename, out)) {
Error{} << "ShaderTools::AbstractConverter::convertDataToFile(): cannot write to file" << filename; Error{} << "ShaderTools::AbstractConverter::convertDataToFile(): cannot write to file" << filename;
return false; return false;
} }
@ -325,7 +326,7 @@ bool AbstractConverter::convertFileToFile(const Stage stage, const Containers::S
const Containers::Array<char> out = convertDataToDataUsingInputFileCallbacks("ShaderTools::AbstractConverter::convertFileToFile():", stage, from); const Containers::Array<char> out = convertDataToDataUsingInputFileCallbacks("ShaderTools::AbstractConverter::convertFileToFile():", stage, from);
if(!out) return false; if(!out) return false;
if(!Utility::Directory::write(to, out)) { if(!Utility::Path::write(to, out)) {
Error{} << "ShaderTools::AbstractConverter::convertFileToFile(): cannot write to file" << to; Error{} << "ShaderTools::AbstractConverter::convertFileToFile(): cannot write to file" << to;
return false; return false;
} }
@ -349,17 +350,18 @@ bool AbstractConverter::doConvertFileToFile(const Stage stage, const Containers:
/* Otherwise open the file directly */ /* Otherwise open the file directly */
} else { } else {
if(!Utility::Directory::exists(from)) { const Containers::Optional<Containers::Array<char>> data = Utility::Path::read(from);
if(!data) {
Error() << "ShaderTools::AbstractConverter::convertFileToFile(): cannot open file" << from; Error() << "ShaderTools::AbstractConverter::convertFileToFile(): cannot open file" << from;
return {}; return {};
} }
out = doConvertDataToData(stage, Utility::Directory::read(from)); out = doConvertDataToData(stage, *data);
} }
if(!out) return false; if(!out) return false;
if(!Utility::Directory::write(to, out)) { if(!Utility::Path::write(to, out)) {
Error{} << "ShaderTools::AbstractConverter::convertFileToFile(): cannot write to file" << to; Error{} << "ShaderTools::AbstractConverter::convertFileToFile(): cannot write to file" << to;
return false; return false;
} }
@ -408,12 +410,13 @@ Containers::Array<char> AbstractConverter::doConvertFileToData(const Stage stage
/* Otherwise open the file directly */ /* Otherwise open the file directly */
} else { } else {
if(!Utility::Directory::exists(filename)) { const Containers::Optional<Containers::Array<char>> data = Utility::Path::read(filename);
if(!data) {
Error() << "ShaderTools::AbstractConverter::convertFileToData(): cannot open file" << filename; Error() << "ShaderTools::AbstractConverter::convertFileToData(): cannot open file" << filename;
return {}; return {};
} }
return doConvertDataToData(stage, Utility::Directory::read(filename)); return doConvertDataToData(stage, *data);
} }
} }
@ -454,7 +457,7 @@ bool AbstractConverter::linkDataToFile(const Containers::ArrayView<const std::pa
const Containers::Array<char> out = doLinkDataToData(Containers::arrayCast<const std::pair<Stage, Containers::ArrayView<const char>>>(data)); const Containers::Array<char> out = doLinkDataToData(Containers::arrayCast<const std::pair<Stage, Containers::ArrayView<const char>>>(data));
if(!out) return false; if(!out) return false;
if(!Utility::Directory::write(filename, out)) { if(!Utility::Path::write(filename, out)) {
Error{} << "ShaderTools::AbstractConverter::linkDataToFile(): cannot write to file" << filename; Error{} << "ShaderTools::AbstractConverter::linkDataToFile(): cannot write to file" << filename;
return false; return false;
} }
@ -533,7 +536,7 @@ bool AbstractConverter::linkFilesToFile(const Containers::ArrayView<const std::p
const Containers::Array<char> out = linkDataToDataUsingInputFileCallbacks("ShaderTools::AbstractConverter::linkFilesToFile():", from); const Containers::Array<char> out = linkDataToDataUsingInputFileCallbacks("ShaderTools::AbstractConverter::linkFilesToFile():", from);
if(!out) return false; if(!out) return false;
if(!Utility::Directory::write(to, out)) { if(!Utility::Path::write(to, out)) {
Error{} << "ShaderTools::AbstractConverter::linkFilesToFile(): cannot write to file" << to; Error{} << "ShaderTools::AbstractConverter::linkFilesToFile(): cannot write to file" << to;
return false; return false;
} }
@ -563,12 +566,13 @@ bool AbstractConverter::doLinkFilesToFile(const Containers::ArrayView<const std:
} else { } else {
Containers::Array<Containers::Array<char>> fileData{from.size()}; Containers::Array<Containers::Array<char>> fileData{from.size()};
for(std::size_t i = 0; i != from.size(); ++i) { for(std::size_t i = 0; i != from.size(); ++i) {
if(!Utility::Directory::exists(from[i].second)) { Containers::Optional<Containers::Array<char>> data = Utility::Path::read(from[i].second);
if(!data) {
Error() << "ShaderTools::AbstractConverter::linkFilesToFile(): cannot open file" << from[i].second; Error() << "ShaderTools::AbstractConverter::linkFilesToFile(): cannot open file" << from[i].second;
return {}; return {};
} }
fileData[i] = Utility::Directory::read(from[i].second); fileData[i] = *std::move(data);
} }
/** @todo merge the allocations once we have an ArrayTuple (actually, /** @todo merge the allocations once we have an ArrayTuple (actually,
@ -584,7 +588,7 @@ bool AbstractConverter::doLinkFilesToFile(const Containers::ArrayView<const std:
if(!out) return false; if(!out) return false;
if(!Utility::Directory::write(to, out)) { if(!Utility::Path::write(to, out)) {
Error{} << "ShaderTools::AbstractConverter::linkFilesToFile(): cannot write to file" << to; Error{} << "ShaderTools::AbstractConverter::linkFilesToFile(): cannot write to file" << to;
return false; return false;
} }
@ -643,12 +647,13 @@ Containers::Array<char> AbstractConverter::doLinkFilesToData(const Containers::A
} else { } else {
Containers::Array<Containers::Array<char>> fileData{filenames.size()}; Containers::Array<Containers::Array<char>> fileData{filenames.size()};
for(std::size_t i = 0; i != filenames.size(); ++i) { for(std::size_t i = 0; i != filenames.size(); ++i) {
if(!Utility::Directory::exists(filenames[i].second)) { Containers::Optional<Containers::Array<char>> data = Utility::Path::read(filenames[i].second);
if(!data) {
Error() << "ShaderTools::AbstractConverter::linkFilesToData(): cannot open file" << filenames[i].second; Error() << "ShaderTools::AbstractConverter::linkFilesToData(): cannot open file" << filenames[i].second;
return {}; return {};
} }
fileData[i] = Utility::Directory::read(filenames[i].second); fileData[i] = *std::move(data);
} }
/** @todo merge the allocations once we have an ArrayTuple */ /** @todo merge the allocations once we have an ArrayTuple */

211
src/Magnum/ShaderTools/Test/AbstractConverterTest.cpp

@ -27,13 +27,13 @@
#include <Corrade/Containers/Array.h> #include <Corrade/Containers/Array.h>
#include <Corrade/Containers/Optional.h> #include <Corrade/Containers/Optional.h>
#include <Corrade/Containers/String.h> #include <Corrade/Containers/String.h>
#include <Corrade/Containers/StringStl.h> #include <Corrade/Containers/StringStl.h> /** @todo remove once Debug is stream-free */
#include <Corrade/TestSuite/Tester.h> #include <Corrade/TestSuite/Tester.h>
#include <Corrade/TestSuite/Compare/Container.h> #include <Corrade/TestSuite/Compare/Container.h>
#include <Corrade/TestSuite/Compare/FileToString.h> #include <Corrade/TestSuite/Compare/FileToString.h>
#include <Corrade/TestSuite/Compare/String.h> #include <Corrade/TestSuite/Compare/String.h>
#include <Corrade/Utility/DebugStl.h> #include <Corrade/Utility/DebugStl.h>
#include <Corrade/Utility/Directory.h> #include <Corrade/Utility/Path.h>
#include "Magnum/FileCallback.h" #include "Magnum/FileCallback.h"
#include "Magnum/ShaderTools/AbstractConverter.h" #include "Magnum/ShaderTools/AbstractConverter.h"
@ -325,7 +325,7 @@ AbstractConverterTest::AbstractConverterTest() {
&AbstractConverterTest::debugFormat}); &AbstractConverterTest::debugFormat});
/* Create testing dir */ /* Create testing dir */
Utility::Directory::mkpath(SHADERTOOLS_TEST_OUTPUT_DIR); Utility::Path::make(SHADERTOOLS_TEST_OUTPUT_DIR);
} }
void AbstractConverterTest::featuresNone() { void AbstractConverterTest::featuresNone() {
@ -808,7 +808,7 @@ void AbstractConverterTest::validateFileAsData() {
} }
} converter; } converter;
std::pair<bool, Containers::String> out = converter.validateFile(Stage::Compute, Utility::Directory::join(SHADERTOOLS_TEST_DIR, "file.dat")); std::pair<bool, Containers::String> out = converter.validateFile(Stage::Compute, Utility::Path::join(SHADERTOOLS_TEST_DIR, "file.dat"));
CORRADE_VERIFY(out.first); CORRADE_VERIFY(out.first);
CORRADE_COMPARE(out.second, "Yes, this is valid"); CORRADE_COMPARE(out.second, "Yes, this is valid");
} }
@ -832,7 +832,10 @@ void AbstractConverterTest::validateFileAsDataNotFound() {
std::pair<bool, Containers::String> out2 = converter.validateFile({}, "nonexistent.bin"); std::pair<bool, Containers::String> out2 = converter.validateFile({}, "nonexistent.bin");
CORRADE_VERIFY(!out2.first); CORRADE_VERIFY(!out2.first);
CORRADE_COMPARE(out2.second, ""); CORRADE_COMPARE(out2.second, "");
CORRADE_COMPARE(out.str(), "ShaderTools::AbstractConverter::validateFile(): cannot open file nonexistent.bin\n"); /* There's an error message from Path::read() before */
CORRADE_COMPARE_AS(out.str(),
"\nShaderTools::AbstractConverter::validateFile(): cannot open file nonexistent.bin\n",
TestSuite::Compare::StringHasSuffix);
} }
void AbstractConverterTest::validateFileNotSupported() { void AbstractConverterTest::validateFileNotSupported() {
@ -1017,11 +1020,10 @@ void AbstractConverterTest::convertDataToFileThroughData() {
} }
} converter; } converter;
const std::string filename = Utility::Directory::join(SHADERTOOLS_TEST_OUTPUT_DIR, "file.dat");
/* Remove previous file, if any */ /* Remove previous file, if any */
if(Utility::Directory::exists(filename)) Containers::String filename = Utility::Path::join(SHADERTOOLS_TEST_OUTPUT_DIR, "file.dat");
CORRADE_VERIFY(Utility::Directory::rm(filename)); if(Utility::Path::exists(filename))
CORRADE_VERIFY(Utility::Path::remove(filename));
const char data[] = {'S', 'P', 'I', 'R', 'V'}; const char data[] = {'S', 'P', 'I', 'R', 'V'};
CORRADE_VERIFY(converter.convertDataToFile({}, data, filename)); CORRADE_VERIFY(converter.convertDataToFile({}, data, filename));
@ -1042,18 +1044,17 @@ void AbstractConverterTest::convertDataToFileThroughDataFailed() {
} }
} converter; } converter;
const std::string filename = Utility::Directory::join(SHADERTOOLS_TEST_OUTPUT_DIR, "file.dat");
/* Remove previous file, if any */ /* Remove previous file, if any */
if(Utility::Directory::exists(filename)) Containers::String filename = Utility::Path::join(SHADERTOOLS_TEST_OUTPUT_DIR, "file.dat");
CORRADE_VERIFY(Utility::Directory::rm(filename)); if(Utility::Path::exists(filename))
CORRADE_VERIFY(Utility::Path::remove(filename));
/* Function should fail, no file should get written and no error output /* Function should fail, no file should get written and no error output
should be printed (the base implementation assumes the plugin does it) */ should be printed (the base implementation assumes the plugin does it) */
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
CORRADE_VERIFY(!converter.convertDataToFile({}, {}, filename)); CORRADE_VERIFY(!converter.convertDataToFile({}, {}, filename));
CORRADE_VERIFY(!Utility::Directory::exists(filename)); CORRADE_VERIFY(!Utility::Path::exists(filename));
CORRADE_COMPARE(out.str(), ""); CORRADE_COMPARE(out.str(), "");
} }
@ -1125,18 +1126,20 @@ void AbstractConverterTest::convertFileToFile() {
void doSetOutputFormat(Format, Containers::StringView) override {} void doSetOutputFormat(Format, Containers::StringView) override {}
bool doConvertFileToFile(Stage, const Containers::StringView from, const Containers::StringView to) override { bool doConvertFileToFile(Stage, const Containers::StringView from, const Containers::StringView to) override {
Containers::Array<char> data = Utility::Directory::read(from); Containers::Optional<Containers::Array<char>> data = Utility::Path::read(from);
return Utility::Directory::write(to, Containers::array({data.back(), data.front()})); CORRADE_VERIFY(data);
return Utility::Path::write(to, Containers::array({data->back(), data->front()}));
} }
} converter; } converter;
const std::string filename = Utility::Directory::join(SHADERTOOLS_TEST_OUTPUT_DIR, "file.dat"); CORRADE_VERIFY(true); /* Capture correct function name first */
/* Remove previous file, if any */ /* Remove previous file, if any */
if(Utility::Directory::exists(filename)) Containers::String filename = Utility::Path::join(SHADERTOOLS_TEST_OUTPUT_DIR, "file.dat");
CORRADE_VERIFY(Utility::Directory::rm(filename)); if(Utility::Path::exists(filename))
CORRADE_VERIFY(Utility::Path::remove(filename));
CORRADE_VERIFY(converter.convertFileToFile({}, Utility::Directory::join(SHADERTOOLS_TEST_DIR, "file.dat"), filename)); CORRADE_VERIFY(converter.convertFileToFile({}, Utility::Path::join(SHADERTOOLS_TEST_DIR, "file.dat"), filename));
CORRADE_COMPARE_AS(filename, "VS", CORRADE_COMPARE_AS(filename, "VS",
TestSuite::Compare::FileToString); TestSuite::Compare::FileToString);
} }
@ -1154,13 +1157,12 @@ void AbstractConverterTest::convertFileToFileThroughData() {
} }
} converter; } converter;
const std::string filename = Utility::Directory::join(SHADERTOOLS_TEST_OUTPUT_DIR, "file.dat");
/* Remove previous file, if any */ /* Remove previous file, if any */
if(Utility::Directory::exists(filename)) Containers::String filename = Utility::Path::join(SHADERTOOLS_TEST_OUTPUT_DIR, "file.dat");
CORRADE_VERIFY(Utility::Directory::rm(filename)); if(Utility::Path::exists(filename))
CORRADE_VERIFY(Utility::Path::remove(filename));
CORRADE_VERIFY(converter.convertFileToFile({}, Utility::Directory::join(SHADERTOOLS_TEST_DIR, "file.dat"), filename)); CORRADE_VERIFY(converter.convertFileToFile({}, Utility::Path::join(SHADERTOOLS_TEST_DIR, "file.dat"), filename));
CORRADE_COMPARE_AS(filename, "VS", CORRADE_COMPARE_AS(filename, "VS",
TestSuite::Compare::FileToString); TestSuite::Compare::FileToString);
} }
@ -1182,7 +1184,10 @@ void AbstractConverterTest::convertFileToFileThroughDataNotFound() {
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
CORRADE_VERIFY(!converter.convertFileToFile({}, "nonexistent.bin", "file.dat")); CORRADE_VERIFY(!converter.convertFileToFile({}, "nonexistent.bin", "file.dat"));
CORRADE_COMPARE(out.str(), "ShaderTools::AbstractConverter::convertFileToFile(): cannot open file nonexistent.bin\n"); /* There's an error message from Path::read() before */
CORRADE_COMPARE_AS(out.str(),
"\nShaderTools::AbstractConverter::convertFileToFile(): cannot open file nonexistent.bin\n",
TestSuite::Compare::StringHasSuffix);
} }
void AbstractConverterTest::convertFileToFileThroughDataFailed() { void AbstractConverterTest::convertFileToFileThroughDataFailed() {
@ -1198,18 +1203,17 @@ void AbstractConverterTest::convertFileToFileThroughDataFailed() {
} }
} converter; } converter;
const std::string filename = Utility::Directory::join(SHADERTOOLS_TEST_OUTPUT_DIR, "file.dat");
/* Remove previous file, if any */ /* Remove previous file, if any */
if(Utility::Directory::exists(filename)) Containers::String filename = Utility::Path::join(SHADERTOOLS_TEST_OUTPUT_DIR, "file.dat");
CORRADE_VERIFY(Utility::Directory::rm(filename)); if(Utility::Path::exists(filename))
CORRADE_VERIFY(Utility::Path::remove(filename));
/* Function should fail, no file should get written and no error output /* Function should fail, no file should get written and no error output
should be printed (the base implementation assumes the plugin does it) */ should be printed (the base implementation assumes the plugin does it) */
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
CORRADE_VERIFY(!converter.convertFileToFile({}, Utility::Directory::join(SHADERTOOLS_TEST_DIR, "file.dat"), filename)); CORRADE_VERIFY(!converter.convertFileToFile({}, Utility::Path::join(SHADERTOOLS_TEST_DIR, "file.dat"), filename));
CORRADE_VERIFY(!Utility::Directory::exists(filename)); CORRADE_VERIFY(!Utility::Path::exists(filename));
CORRADE_COMPARE(out.str(), ""); CORRADE_COMPARE(out.str(), "");
} }
@ -1228,7 +1232,7 @@ void AbstractConverterTest::convertFileToFileThroughDataNotWritable() {
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
CORRADE_VERIFY(!converter.convertFileToFile({}, Utility::Directory::join(SHADERTOOLS_TEST_DIR, "file.dat"), "/some/path/that/does/not/exist")); CORRADE_VERIFY(!converter.convertFileToFile({}, Utility::Path::join(SHADERTOOLS_TEST_DIR, "file.dat"), "/some/path/that/does/not/exist"));
CORRADE_COMPARE_AS(out.str(), CORRADE_COMPARE_AS(out.str(),
"ShaderTools::AbstractConverter::convertFileToFile(): cannot write to file /some/path/that/does/not/exist\n", "ShaderTools::AbstractConverter::convertFileToFile(): cannot write to file /some/path/that/does/not/exist\n",
TestSuite::Compare::StringHasSuffix); TestSuite::Compare::StringHasSuffix);
@ -1281,12 +1285,15 @@ void AbstractConverterTest::convertFileToData() {
void doSetOutputFormat(Format, Containers::StringView) override {} void doSetOutputFormat(Format, Containers::StringView) override {}
Containers::Array<char> doConvertFileToData(Stage, const Containers::StringView from) override { Containers::Array<char> doConvertFileToData(Stage, const Containers::StringView from) override {
Containers::Array<char> data = Utility::Directory::read(from); Containers::Optional<Containers::Array<char>> data = Utility::Path::read(from);
return Containers::array({data.back(), data.front()}); CORRADE_VERIFY(data);
return Containers::array({data->back(), data->front()});
} }
} converter; } converter;
Containers::Array<char> out = converter.convertFileToData({}, Utility::Directory::join(SHADERTOOLS_TEST_DIR, "file.dat")); CORRADE_VERIFY(true); /* Capture correct function name first */
Containers::Array<char> out = converter.convertFileToData({}, Utility::Path::join(SHADERTOOLS_TEST_DIR, "file.dat"));
CORRADE_COMPARE_AS(out, Containers::arrayView({'V', 'S'}), CORRADE_COMPARE_AS(out, Containers::arrayView({'V', 'S'}),
TestSuite::Compare::Container); TestSuite::Compare::Container);
} }
@ -1304,7 +1311,7 @@ void AbstractConverterTest::convertFileToDataAsData() {
} }
} converter; } converter;
Containers::Array<char> out = converter.convertFileToData({}, Utility::Directory::join(SHADERTOOLS_TEST_DIR, "file.dat")); Containers::Array<char> out = converter.convertFileToData({}, Utility::Path::join(SHADERTOOLS_TEST_DIR, "file.dat"));
CORRADE_COMPARE_AS(out, Containers::arrayView({'V', 'S'}), CORRADE_COMPARE_AS(out, Containers::arrayView({'V', 'S'}),
TestSuite::Compare::Container); TestSuite::Compare::Container);
} }
@ -1326,7 +1333,10 @@ void AbstractConverterTest::convertFileToDataAsDataNotFound() {
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
CORRADE_VERIFY(!converter.convertFileToData({}, "nonexistent.bin")); CORRADE_VERIFY(!converter.convertFileToData({}, "nonexistent.bin"));
CORRADE_COMPARE(out.str(), "ShaderTools::AbstractConverter::convertFileToData(): cannot open file nonexistent.bin\n"); /* There's an error message from Path::read() before */
CORRADE_COMPARE_AS(out.str(),
"\nShaderTools::AbstractConverter::convertFileToData(): cannot open file nonexistent.bin\n",
TestSuite::Compare::StringHasSuffix);
} }
void AbstractConverterTest::convertFileToDataNotSupported() { void AbstractConverterTest::convertFileToDataNotSupported() {
@ -1364,7 +1374,7 @@ void AbstractConverterTest::convertFileToDataNotImplemented() {
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
converter.convertFileToData({}, Utility::Directory::join(SHADERTOOLS_TEST_DIR, "file.dat")); converter.convertFileToData({}, Utility::Path::join(SHADERTOOLS_TEST_DIR, "file.dat"));
CORRADE_COMPARE(out.str(), "ShaderTools::AbstractConverter::convertDataToData(): feature advertised but not implemented\n"); CORRADE_COMPARE(out.str(), "ShaderTools::AbstractConverter::convertDataToData(): feature advertised but not implemented\n");
} }
@ -1537,11 +1547,10 @@ void AbstractConverterTest::linkDataToFileThroughData() {
} }
} converter; } converter;
const std::string filename = Utility::Directory::join(SHADERTOOLS_TEST_OUTPUT_DIR, "file.dat");
/* Remove previous file, if any */ /* Remove previous file, if any */
if(Utility::Directory::exists(filename)) Containers::String filename = Utility::Path::join(SHADERTOOLS_TEST_OUTPUT_DIR, "file.dat");
CORRADE_VERIFY(Utility::Directory::rm(filename)); if(Utility::Path::exists(filename))
CORRADE_VERIFY(Utility::Path::remove(filename));
CORRADE_VERIFY(converter.linkDataToFile({ CORRADE_VERIFY(converter.linkDataToFile({
{Stage::Vertex, Containers::arrayView({'V', 'E'})}, {Stage::Vertex, Containers::arrayView({'V', 'E'})},
@ -1564,11 +1573,10 @@ void AbstractConverterTest::linkDataToFileThroughDataFailed() {
} }
} converter; } converter;
const std::string filename = Utility::Directory::join(SHADERTOOLS_TEST_OUTPUT_DIR, "file.dat");
/* Remove previous file, if any */ /* Remove previous file, if any */
if(Utility::Directory::exists(filename)) Containers::String filename = Utility::Path::join(SHADERTOOLS_TEST_OUTPUT_DIR, "file.dat");
CORRADE_VERIFY(Utility::Directory::rm(filename)); if(Utility::Path::exists(filename))
CORRADE_VERIFY(Utility::Path::remove(filename));
/* Function should fail, no file should get written and no error output /* Function should fail, no file should get written and no error output
should be printed (the base implementation assumes the plugin does it) */ should be printed (the base implementation assumes the plugin does it) */
@ -1576,7 +1584,7 @@ void AbstractConverterTest::linkDataToFileThroughDataFailed() {
Error redirectError{&out}; Error redirectError{&out};
/* {{}} makes GCC 4.8 warn about zero as null pointer constant */ /* {{}} makes GCC 4.8 warn about zero as null pointer constant */
CORRADE_VERIFY(!converter.linkDataToFile({std::pair<Stage, Containers::ArrayView<const void>>{}}, filename)); CORRADE_VERIFY(!converter.linkDataToFile({std::pair<Stage, Containers::ArrayView<const void>>{}}, filename));
CORRADE_VERIFY(!Utility::Directory::exists(filename)); CORRADE_VERIFY(!Utility::Path::exists(filename));
CORRADE_COMPARE(out.str(), ""); CORRADE_COMPARE(out.str(), "");
} }
@ -1690,26 +1698,27 @@ void AbstractConverterTest::linkFilesToFile() {
bool doLinkFilesToFile(Containers::ArrayView<const std::pair<Stage, Containers::StringView>> from, Containers::StringView to) override { bool doLinkFilesToFile(Containers::ArrayView<const std::pair<Stage, Containers::StringView>> from, Containers::StringView to) override {
CORRADE_COMPARE(from.size(), 2); CORRADE_COMPARE(from.size(), 2);
Containers::Array<char> first = Utility::Directory::read(from[0].second); Containers::Optional<Containers::Array<char>> first = Utility::Path::read(from[0].second);
Containers::Array<char> second = Utility::Directory::read(from[1].second); Containers::Optional<Containers::Array<char>> second = Utility::Path::read(from[1].second);
CORRADE_VERIFY(first); CORRADE_VERIFY(first);
CORRADE_VERIFY(second); CORRADE_VERIFY(second);
return Utility::Directory::write(to, Containers::array({ return Utility::Path::write(to, Containers::array({
from[0].first == Stage::Vertex ? first[0] : ' ', from[0].first == Stage::Vertex ? (*first)[0] : ' ',
from[1].first == Stage::Fragment ? second[0] : ' ' from[1].first == Stage::Fragment ? (*second)[0] : ' '
})); }));
} }
} converter; } converter;
const std::string filename = Utility::Directory::join(SHADERTOOLS_TEST_OUTPUT_DIR, "file.dat");
/* Remove previous file, if any */ /* Remove previous file, if any */
if(Utility::Directory::exists(filename)) Containers::String filename = Utility::Path::join(SHADERTOOLS_TEST_OUTPUT_DIR, "file.dat");
CORRADE_VERIFY(Utility::Directory::rm(filename)); if(Utility::Path::exists(filename))
CORRADE_VERIFY(Utility::Path::remove(filename));
CORRADE_VERIFY(true); /* Capture correct function name first */
CORRADE_VERIFY(converter.linkFilesToFile({ CORRADE_VERIFY(converter.linkFilesToFile({
{Stage::Vertex, Utility::Directory::join(SHADERTOOLS_TEST_DIR, "another.dat")}, {Stage::Vertex, Utility::Path::join(SHADERTOOLS_TEST_DIR, "another.dat")},
{Stage::Fragment, Utility::Directory::join(SHADERTOOLS_TEST_DIR, "file.dat")} {Stage::Fragment, Utility::Path::join(SHADERTOOLS_TEST_DIR, "file.dat")}
}, filename)); }, filename));
CORRADE_COMPARE_AS(filename, "VS", CORRADE_COMPARE_AS(filename, "VS",
TestSuite::Compare::FileToString); TestSuite::Compare::FileToString);
@ -1732,15 +1741,14 @@ void AbstractConverterTest::linkFilesToFileThroughData() {
} }
} converter; } converter;
const std::string filename = Utility::Directory::join(SHADERTOOLS_TEST_OUTPUT_DIR, "file.dat");
/* Remove previous file, if any */ /* Remove previous file, if any */
if(Utility::Directory::exists(filename)) Containers::String filename = Utility::Path::join(SHADERTOOLS_TEST_OUTPUT_DIR, "file.dat");
CORRADE_VERIFY(Utility::Directory::rm(filename)); if(Utility::Path::exists(filename))
CORRADE_VERIFY(Utility::Path::remove(filename));
CORRADE_VERIFY(converter.linkFilesToFile({ CORRADE_VERIFY(converter.linkFilesToFile({
{Stage::Vertex, Utility::Directory::join(SHADERTOOLS_TEST_DIR, "another.dat")}, {Stage::Vertex, Utility::Path::join(SHADERTOOLS_TEST_DIR, "another.dat")},
{Stage::Fragment, Utility::Directory::join(SHADERTOOLS_TEST_DIR, "file.dat")} {Stage::Fragment, Utility::Path::join(SHADERTOOLS_TEST_DIR, "file.dat")}
}, filename)); }, filename));
CORRADE_COMPARE_AS(filename, "VS", CORRADE_COMPARE_AS(filename, "VS",
TestSuite::Compare::FileToString); TestSuite::Compare::FileToString);
@ -1763,10 +1771,13 @@ void AbstractConverterTest::linkFilesToFileThroughDataNotFound() {
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
CORRADE_VERIFY(!converter.linkFilesToFile({ CORRADE_VERIFY(!converter.linkFilesToFile({
{{}, Utility::Directory::join(SHADERTOOLS_TEST_DIR, "another.dat")}, {{}, Utility::Path::join(SHADERTOOLS_TEST_DIR, "another.dat")},
{{}, "nonexistent.bin"} {{}, "nonexistent.bin"}
}, "file.dat")); }, "file.dat"));
CORRADE_COMPARE(out.str(), "ShaderTools::AbstractConverter::linkFilesToFile(): cannot open file nonexistent.bin\n"); /* There's an error message from Path::read() before */
CORRADE_COMPARE_AS(out.str(),
"\nShaderTools::AbstractConverter::linkFilesToFile(): cannot open file nonexistent.bin\n",
TestSuite::Compare::StringHasSuffix);
} }
void AbstractConverterTest::linkFilesToFileThroughDataFailed() { void AbstractConverterTest::linkFilesToFileThroughDataFailed() {
@ -1782,20 +1793,19 @@ void AbstractConverterTest::linkFilesToFileThroughDataFailed() {
} }
} converter; } converter;
const std::string filename = Utility::Directory::join(SHADERTOOLS_TEST_OUTPUT_DIR, "file.dat");
/* Remove previous file, if any */ /* Remove previous file, if any */
if(Utility::Directory::exists(filename)) Containers::String filename = Utility::Path::join(SHADERTOOLS_TEST_OUTPUT_DIR, "file.dat");
CORRADE_VERIFY(Utility::Directory::rm(filename)); if(Utility::Path::exists(filename))
CORRADE_VERIFY(Utility::Path::remove(filename));
/* Function should fail, no file should get written and no error output /* Function should fail, no file should get written and no error output
should be printed (the base implementation assumes the plugin does it) */ should be printed (the base implementation assumes the plugin does it) */
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
CORRADE_VERIFY(!converter.linkFilesToFile({ CORRADE_VERIFY(!converter.linkFilesToFile({
{{}, Utility::Directory::join(SHADERTOOLS_TEST_DIR, "file.dat")} {{}, Utility::Path::join(SHADERTOOLS_TEST_DIR, "file.dat")}
}, filename)); }, filename));
CORRADE_VERIFY(!Utility::Directory::exists(filename)); CORRADE_VERIFY(!Utility::Path::exists(filename));
CORRADE_COMPARE(out.str(), ""); CORRADE_COMPARE(out.str(), "");
} }
@ -1815,7 +1825,7 @@ void AbstractConverterTest::linkFilesToFileThroughDataNotWritable() {
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
CORRADE_VERIFY(!converter.linkFilesToFile({ CORRADE_VERIFY(!converter.linkFilesToFile({
{{}, Utility::Directory::join(SHADERTOOLS_TEST_DIR, "file.dat")} {{}, Utility::Path::join(SHADERTOOLS_TEST_DIR, "file.dat")}
}, "/some/path/that/does/not/exist")); }, "/some/path/that/does/not/exist"));
CORRADE_COMPARE_AS(out.str(), CORRADE_COMPARE_AS(out.str(),
"ShaderTools::AbstractConverter::linkFilesToFile(): cannot write to file /some/path/that/does/not/exist\n", "ShaderTools::AbstractConverter::linkFilesToFile(): cannot write to file /some/path/that/does/not/exist\n",
@ -1910,22 +1920,22 @@ void AbstractConverterTest::linkFilesToData() {
Containers::Array<char> doLinkFilesToData(Containers::ArrayView<const std::pair<Stage, Containers::StringView>> from) override { Containers::Array<char> doLinkFilesToData(Containers::ArrayView<const std::pair<Stage, Containers::StringView>> from) override {
CORRADE_COMPARE(from.size(), 2); CORRADE_COMPARE(from.size(), 2);
Containers::Array<char> first = Utility::Directory::read(from[0].second); Containers::Optional<Containers::Array<char>> first = Utility::Path::read(from[0].second);
Containers::Array<char> second = Utility::Directory::read(from[1].second); Containers::Optional<Containers::Array<char>> second = Utility::Path::read(from[1].second);
CORRADE_VERIFY(first); CORRADE_VERIFY(first);
CORRADE_VERIFY(second); CORRADE_VERIFY(second);
return Containers::array({ return Containers::array({
from[0].first == Stage::Vertex ? first[0] : ' ', from[0].first == Stage::Vertex ? (*first)[0] : ' ',
from[1].first == Stage::Fragment ? second[0] : ' ' from[1].first == Stage::Fragment ? (*second)[0] : ' '
}); });
} }
} converter; } converter;
CORRADE_VERIFY(true); /* so it picks up correct test case name */ CORRADE_VERIFY(true); /* Capture correct function name first */
Containers::Array<char> out = converter.linkFilesToData({ Containers::Array<char> out = converter.linkFilesToData({
{Stage::Vertex, Utility::Directory::join(SHADERTOOLS_TEST_DIR, "another.dat")}, {Stage::Vertex, Utility::Path::join(SHADERTOOLS_TEST_DIR, "another.dat")},
{Stage::Fragment, Utility::Directory::join(SHADERTOOLS_TEST_DIR, "file.dat")} {Stage::Fragment, Utility::Path::join(SHADERTOOLS_TEST_DIR, "file.dat")}
}); });
CORRADE_COMPARE_AS(out, Containers::arrayView({'V', 'S'}), CORRADE_COMPARE_AS(out, Containers::arrayView({'V', 'S'}),
TestSuite::Compare::Container); TestSuite::Compare::Container);
@ -1948,9 +1958,11 @@ void AbstractConverterTest::linkFilesToDataAsData() {
} }
} converter; } converter;
CORRADE_VERIFY(true); /* Capture correct function name first */
Containers::Array<char> out = converter.linkFilesToData({ Containers::Array<char> out = converter.linkFilesToData({
{Stage::Vertex, Utility::Directory::join(SHADERTOOLS_TEST_DIR, "another.dat")}, {Stage::Vertex, Utility::Path::join(SHADERTOOLS_TEST_DIR, "another.dat")},
{Stage::Fragment, Utility::Directory::join(SHADERTOOLS_TEST_DIR, "file.dat")} {Stage::Fragment, Utility::Path::join(SHADERTOOLS_TEST_DIR, "file.dat")}
}); });
CORRADE_COMPARE_AS(out, Containers::arrayView({'V', 'S'}), CORRADE_COMPARE_AS(out, Containers::arrayView({'V', 'S'}),
TestSuite::Compare::Container); TestSuite::Compare::Container);
@ -1970,12 +1982,17 @@ void AbstractConverterTest::linkFilesToDataAsDataNotFound() {
} }
} converter; } converter;
CORRADE_VERIFY(true); /* Capture correct function name first */
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
CORRADE_VERIFY(!converter.linkFilesToData({ CORRADE_VERIFY(!converter.linkFilesToData({
{{}, "nonexistent.bin"} {{}, "nonexistent.bin"}
})); }));
CORRADE_COMPARE(out.str(), "ShaderTools::AbstractConverter::linkFilesToData(): cannot open file nonexistent.bin\n"); /* There's an error message from Path::read() before */
CORRADE_COMPARE_AS(out.str(),
"\nShaderTools::AbstractConverter::linkFilesToData(): cannot open file nonexistent.bin\n",
TestSuite::Compare::StringHasSuffix);
} }
void AbstractConverterTest::linkFilesToDataNotSupported() { void AbstractConverterTest::linkFilesToDataNotSupported() {
@ -2013,7 +2030,7 @@ void AbstractConverterTest::linkFilesToDataNotImplemented() {
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
converter.linkFilesToData({ converter.linkFilesToData({
{{}, Utility::Directory::join(SHADERTOOLS_TEST_DIR, "file.dat")} {{}, Utility::Path::join(SHADERTOOLS_TEST_DIR, "file.dat")}
}); });
CORRADE_COMPARE(out.str(), "ShaderTools::AbstractConverter::linkDataToData(): feature advertised but not implemented\n"); CORRADE_COMPARE(out.str(), "ShaderTools::AbstractConverter::linkDataToData(): feature advertised but not implemented\n");
} }
@ -2474,9 +2491,9 @@ void AbstractConverterTest::setInputFileCallbackConvertFileToFileThroughBaseImpl
}, state); }, state);
/* Remove previous file, if any */ /* Remove previous file, if any */
const std::string filename = Utility::Directory::join(SHADERTOOLS_TEST_OUTPUT_DIR, "file.out"); Containers::String filename = Utility::Path::join(SHADERTOOLS_TEST_OUTPUT_DIR, "file.out");
if(Utility::Directory::exists(filename)) if(Utility::Path::exists(filename))
CORRADE_VERIFY(Utility::Directory::rm(filename)); CORRADE_VERIFY(Utility::Path::remove(filename));
CORRADE_VERIFY(converter.convertFileToFile(Stage::Geometry, "file.dat", filename)); CORRADE_VERIFY(converter.convertFileToFile(Stage::Geometry, "file.dat", filename));
CORRADE_VERIFY(converter.convertFileToFileCalled); CORRADE_VERIFY(converter.convertFileToFileCalled);
@ -2555,9 +2572,9 @@ void AbstractConverterTest::setInputFileCallbackConvertFileToFileAsData() {
}, state); }, state);
/* Remove previous file, if any */ /* Remove previous file, if any */
const std::string filename = Utility::Directory::join(SHADERTOOLS_TEST_OUTPUT_DIR, "file.out"); Containers::String filename = Utility::Path::join(SHADERTOOLS_TEST_OUTPUT_DIR, "file.out");
if(Utility::Directory::exists(filename)) if(Utility::Path::exists(filename))
CORRADE_VERIFY(Utility::Directory::rm(filename)); CORRADE_VERIFY(Utility::Path::remove(filename));
CORRADE_VERIFY(converter.convertFileToFile(Stage::RayAnyHit, "file.dat", filename)); CORRADE_VERIFY(converter.convertFileToFile(Stage::RayAnyHit, "file.dat", filename));
CORRADE_VERIFY(state.loaded); CORRADE_VERIFY(state.loaded);
@ -2909,9 +2926,9 @@ void AbstractConverterTest::setInputFileCallbackLinkFilesToFileThroughBaseImplem
}, state); }, state);
/* Remove previous file, if any */ /* Remove previous file, if any */
const std::string filename = Utility::Directory::join(SHADERTOOLS_TEST_OUTPUT_DIR, "file.out"); Containers::String filename = Utility::Path::join(SHADERTOOLS_TEST_OUTPUT_DIR, "file.out");
if(Utility::Directory::exists(filename)) if(Utility::Path::exists(filename))
CORRADE_VERIFY(Utility::Directory::rm(filename)); CORRADE_VERIFY(Utility::Path::remove(filename));
CORRADE_VERIFY(converter.linkFilesToFile({ CORRADE_VERIFY(converter.linkFilesToFile({
{Stage::Vertex, "another.dat"}, {Stage::Vertex, "another.dat"},
@ -3032,9 +3049,9 @@ void AbstractConverterTest::setInputFileCallbackLinkFilesToFileAsData() {
}, state); }, state);
/* Remove previous file, if any */ /* Remove previous file, if any */
const std::string filename = Utility::Directory::join(SHADERTOOLS_TEST_OUTPUT_DIR, "file.out"); Containers::String filename = Utility::Path::join(SHADERTOOLS_TEST_OUTPUT_DIR, "file.out");
if(Utility::Directory::exists(filename)) if(Utility::Path::exists(filename))
CORRADE_VERIFY(Utility::Directory::rm(filename)); CORRADE_VERIFY(Utility::Path::remove(filename));
CORRADE_VERIFY(converter.linkFilesToFile({ CORRADE_VERIFY(converter.linkFilesToFile({
{Stage::Vertex, "another.dat"}, {Stage::Vertex, "another.dat"},

14
src/Magnum/ShaderTools/Test/SpirvTest.cpp

@ -23,10 +23,10 @@
DEALINGS IN THE SOFTWARE. DEALINGS IN THE SOFTWARE.
*/ */
#include <string>
#include <Corrade/Containers/Array.h> #include <Corrade/Containers/Array.h>
#include <Corrade/Containers/String.h>
#include <Corrade/TestSuite/Tester.h> #include <Corrade/TestSuite/Tester.h>
#include <Corrade/Utility/Directory.h> #include <Corrade/Utility/Path.h>
#include "Magnum/ShaderTools/Implementation/spirv.h" #include "Magnum/ShaderTools/Implementation/spirv.h"
#include "MagnumExternal/Vulkan/spirv.h" #include "MagnumExternal/Vulkan/spirv.h"
@ -150,10 +150,11 @@ void SpirvTest::findInstructionNotEnoughData() {
} }
void SpirvTest::nextEntrypoint() { void SpirvTest::nextEntrypoint() {
Containers::Array<char> data = Utility::Directory::read(Utility::Directory::join(SHADERTOOLS_TEST_DIR, "SpirvTestFiles/entrypoint-interface.spv")); Containers::Optional<Containers::Array<char>> data = Utility::Path::read(Utility::Path::join(SHADERTOOLS_TEST_DIR, "SpirvTestFiles/entrypoint-interface.spv"));
CORRADE_VERIFY(data);
/* The file is a full SPIR-V, strip the header first */ /* The file is a full SPIR-V, strip the header first */
Containers::ArrayView<const UnsignedInt> view = Implementation::spirvData(data, data.size()); Containers::ArrayView<const UnsignedInt> view = Implementation::spirvData(*data, data->size());
CORRADE_VERIFY(view); CORRADE_VERIFY(view);
Containers::Optional<Implementation::SpirvEntrypoint> vert = Implementation::spirvNextEntrypoint(view); Containers::Optional<Implementation::SpirvEntrypoint> vert = Implementation::spirvNextEntrypoint(view);
@ -188,10 +189,11 @@ void SpirvTest::nextEntrypointInvalidInstruction() {
} }
void SpirvTest::entrypointInterface() { void SpirvTest::entrypointInterface() {
Containers::Array<char> data = Utility::Directory::read(Utility::Directory::join(SHADERTOOLS_TEST_DIR, "SpirvTestFiles/entrypoint-interface.spv")); Containers::Optional<Containers::Array<char>> data = Utility::Path::read(Utility::Path::join(SHADERTOOLS_TEST_DIR, "SpirvTestFiles/entrypoint-interface.spv"));
CORRADE_VERIFY(data);
/* The file is a full SPIR-V, strip the header first */ /* The file is a full SPIR-V, strip the header first */
Containers::ArrayView<const UnsignedInt> view = Implementation::spirvData(data, data.size()); Containers::ArrayView<const UnsignedInt> view = Implementation::spirvData(*data, data->size());
CORRADE_VERIFY(view); CORRADE_VERIFY(view);
Containers::Optional<Implementation::SpirvEntrypoint> vert = Implementation::spirvNextEntrypoint(view); Containers::Optional<Implementation::SpirvEntrypoint> vert = Implementation::spirvNextEntrypoint(view);

210
src/MagnumPlugins/AnyShaderConverter/Test/AnyConverterTest.cpp

@ -25,14 +25,15 @@
#include <sstream> #include <sstream>
#include <Corrade/Containers/Array.h> #include <Corrade/Containers/Array.h>
#include <Corrade/Containers/Optional.h>
#include <Corrade/Containers/String.h> #include <Corrade/Containers/String.h>
#include <Corrade/Containers/StringStl.h> #include <Corrade/Containers/StringStl.h>
#include <Corrade/PluginManager/Manager.h> #include <Corrade/PluginManager/Manager.h>
#include <Corrade/TestSuite/Tester.h> #include <Corrade/TestSuite/Tester.h>
#include <Corrade/Utility/ConfigurationGroup.h> #include <Corrade/Utility/ConfigurationGroup.h>
#include <Corrade/Utility/DebugStl.h> #include <Corrade/Utility/DebugStl.h>
#include <Corrade/Utility/Directory.h>
#include <Corrade/Utility/FormatStl.h> #include <Corrade/Utility/FormatStl.h>
#include <Corrade/Utility/Path.h>
#include "Magnum/ShaderTools/AbstractConverter.h" #include "Magnum/ShaderTools/AbstractConverter.h"
#include "Magnum/ShaderTools/Stage.h" #include "Magnum/ShaderTools/Stage.h"
@ -245,7 +246,7 @@ AnyConverterTest::AnyConverterTest() {
#endif #endif
/* Create the output directory if it doesn't exist yet */ /* Create the output directory if it doesn't exist yet */
CORRADE_INTERNAL_ASSERT_OUTPUT(Utility::Directory::mkpath(ANYSHADERCONVERTER_TEST_OUTPUT_DIR)); CORRADE_INTERNAL_ASSERT_OUTPUT(Utility::Path::make(ANYSHADERCONVERTER_TEST_OUTPUT_DIR));
} }
void AnyConverterTest::validateFile() { void AnyConverterTest::validateFile() {
@ -259,7 +260,7 @@ void AnyConverterTest::validateFile() {
Containers::Pointer<AbstractConverter> converter = manager.instantiate("AnyShaderConverter"); Containers::Pointer<AbstractConverter> converter = manager.instantiate("AnyShaderConverter");
const std::string filename = Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"); Containers::String filename = Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl");
/* Make it print a warning so we know it's doing something */ /* Make it print a warning so we know it's doing something */
CORRADE_COMPARE(converter->validateFile(Stage::Fragment, filename), CORRADE_COMPARE(converter->validateFile(Stage::Fragment, filename),
@ -315,7 +316,7 @@ void AnyConverterTest::validateFilePreprocessNotSupported() {
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
CORRADE_COMPARE(converter->validateFile({}, Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.spv")), CORRADE_COMPARE(converter->validateFile({}, Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.spv")),
std::make_pair(false, "")); std::make_pair(false, ""));
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"ShaderTools::AnyConverter::validateFile(): SpirvToolsShaderConverter does not support preprocessing\n"); "ShaderTools::AnyConverter::validateFile(): SpirvToolsShaderConverter does not support preprocessing\n");
@ -332,7 +333,7 @@ void AnyConverterTest::validateFilePropagateFlags() {
Containers::Pointer<AbstractConverter> converter = manager.instantiate("AnyShaderConverter"); Containers::Pointer<AbstractConverter> converter = manager.instantiate("AnyShaderConverter");
const std::string filename = Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"); Containers::String filename = Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl");
/* With this, the warning should turn into an error. The converter should /* With this, the warning should turn into an error. The converter should
also print the verbose info. */ also print the verbose info. */
@ -364,7 +365,7 @@ void AnyConverterTest::validateFilePropagateInputVersion() {
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
CORRADE_COMPARE(converter->validateFile(Stage::Fragment, Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl")), CORRADE_COMPARE(converter->validateFile(Stage::Fragment, Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl")),
std::make_pair(false, "")); std::make_pair(false, ""));
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"ShaderTools::GlslangConverter::validateData(): input format version should be one of supported GLSL #version strings but got 100\n"); "ShaderTools::GlslangConverter::validateData(): input format version should be one of supported GLSL #version strings but got 100\n");
@ -388,7 +389,7 @@ void AnyConverterTest::validateFilePropagateOutputVersion() {
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
CORRADE_COMPARE(converter->validateFile(Stage::Fragment, Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl")), CORRADE_COMPARE(converter->validateFile(Stage::Fragment, Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl")),
std::make_pair(false, "")); std::make_pair(false, ""));
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"ShaderTools::GlslangConverter::validateData(): output format should be Spirv or Unspecified but got ShaderTools::Format::Glsl\n"); "ShaderTools::GlslangConverter::validateData(): output format should be Spirv or Unspecified but got ShaderTools::Format::Glsl\n");
@ -405,7 +406,7 @@ void AnyConverterTest::validateFilePropagatePreprocess() {
Containers::Pointer<AbstractConverter> converter = manager.instantiate("AnyShaderConverter"); Containers::Pointer<AbstractConverter> converter = manager.instantiate("AnyShaderConverter");
const std::string filename = Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"); Containers::String filename = Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl");
/* Check that undefining works properly -- if it stays defined, the source /* Check that undefining works properly -- if it stays defined, the source
won't compile */ won't compile */
@ -430,7 +431,7 @@ void AnyConverterTest::validateFilePropagateConfiguration() {
Containers::Pointer<AbstractConverter> converter = manager.instantiate("AnyShaderConverter"); Containers::Pointer<AbstractConverter> converter = manager.instantiate("AnyShaderConverter");
const std::string filename = Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "version-not-first.glsl"); Containers::String filename = Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "version-not-first.glsl");
{ {
CORRADE_COMPARE(converter->validateFile(Stage::Fragment, filename), CORRADE_COMPARE(converter->validateFile(Stage::Fragment, filename),
@ -460,7 +461,7 @@ void AnyConverterTest::validateFilePropagateConfigurationUnknown() {
std::ostringstream out; std::ostringstream out;
Warning redirectWarning{&out}; Warning redirectWarning{&out};
CORRADE_COMPARE(converter->validateFile(Stage::Fragment, Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl")), CORRADE_COMPARE(converter->validateFile(Stage::Fragment, Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl")),
std::make_pair(true, "")); std::make_pair(true, ""));
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"ShaderTools::AnyConverter::validateFile(): option noSuchOption not recognized by GlslangShaderConverter\n"); "ShaderTools::AnyConverter::validateFile(): option noSuchOption not recognized by GlslangShaderConverter\n");
@ -480,7 +481,9 @@ void AnyConverterTest::validateData() {
converter->setInputFormat(Format::Glsl); converter->setInputFormat(Format::Glsl);
/* Make it print a warning so we know it's doing something */ /* Make it print a warning so we know it's doing something */
CORRADE_COMPARE(converter->validateData(Stage::Fragment, Utility::Directory::read(Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"))), Containers::Optional<Containers::Array<char>> data = Utility::Path::read(Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"));
CORRADE_VERIFY(data);
CORRADE_COMPARE(converter->validateData(Stage::Fragment, *data),
std::make_pair(true, "WARNING: 0:10: 'reserved__identifier' : identifiers containing consecutive underscores (\"__\") are reserved")); std::make_pair(true, "WARNING: 0:10: 'reserved__identifier' : identifiers containing consecutive underscores (\"__\") are reserved"));
} }
@ -535,9 +538,12 @@ void AnyConverterTest::validateDataPreprocessNotSupported() {
{"DEFINE", "hahahahah"} {"DEFINE", "hahahahah"}
}); });
Containers::Optional<Containers::Array<char>> data = Utility::Path::read(Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.spv"));
CORRADE_VERIFY(data);
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
CORRADE_COMPARE(converter->validateData({}, Utility::Directory::read(Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.spv"))), CORRADE_COMPARE(converter->validateData({}, *data),
std::make_pair(false, "")); std::make_pair(false, ""));
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"ShaderTools::AnyConverter::validateData(): SpirvToolsShaderConverter does not support preprocessing\n"); "ShaderTools::AnyConverter::validateData(): SpirvToolsShaderConverter does not support preprocessing\n");
@ -560,9 +566,12 @@ void AnyConverterTest::validateDataPropagateFlags() {
also print the verbose info. */ also print the verbose info. */
converter->setFlags(ConverterFlag::Verbose|ConverterFlag::WarningAsError); converter->setFlags(ConverterFlag::Verbose|ConverterFlag::WarningAsError);
Containers::Optional<Containers::Array<char>> data = Utility::Path::read(Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"));
CORRADE_VERIFY(data);
std::ostringstream out; std::ostringstream out;
Debug redirectDebug{&out}; Debug redirectDebug{&out};
CORRADE_COMPARE(converter->validateData(Stage::Fragment, Utility::Directory::read(Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"))), CORRADE_COMPARE(converter->validateData(Stage::Fragment, *data),
std::make_pair(false, "WARNING: 0:10: 'reserved__identifier' : identifiers containing consecutive underscores (\"__\") are reserved")); std::make_pair(false, "WARNING: 0:10: 'reserved__identifier' : identifiers containing consecutive underscores (\"__\") are reserved"));
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"ShaderTools::AnyConverter::validateData(): using GlslShaderConverter (provided by GlslangShaderConverter)\n"); "ShaderTools::AnyConverter::validateData(): using GlslShaderConverter (provided by GlslangShaderConverter)\n");
@ -586,9 +595,12 @@ void AnyConverterTest::validateDataPropagateInputVersion() {
AbstractConverter::doValidateFile() with the file contents. */ AbstractConverter::doValidateFile() with the file contents. */
converter->setInputFormat(Format::Glsl, "100"); converter->setInputFormat(Format::Glsl, "100");
Containers::Optional<Containers::Array<char>> data = Utility::Path::read(Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"));
CORRADE_VERIFY(data);
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
CORRADE_COMPARE(converter->validateData(Stage::Fragment, Utility::Directory::read(Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"))), CORRADE_COMPARE(converter->validateData(Stage::Fragment, *data),
std::make_pair(false, "")); std::make_pair(false, ""));
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"ShaderTools::GlslangConverter::validateData(): input format version should be one of supported GLSL #version strings but got 100\n"); "ShaderTools::GlslangConverter::validateData(): input format version should be one of supported GLSL #version strings but got 100\n");
@ -612,9 +624,12 @@ void AnyConverterTest::validateDataPropagateOutputVersion() {
AbstractConverter::doValidateFile() with the file contents. */ AbstractConverter::doValidateFile() with the file contents. */
converter->setOutputFormat(Format::Glsl, "opengl4.0"); converter->setOutputFormat(Format::Glsl, "opengl4.0");
Containers::Optional<Containers::Array<char>> data = Utility::Path::read(Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"));
CORRADE_VERIFY(data);
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
CORRADE_COMPARE(converter->validateData(Stage::Fragment, Utility::Directory::read(Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"))), CORRADE_COMPARE(converter->validateData(Stage::Fragment, *data),
std::make_pair(false, "")); std::make_pair(false, ""));
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"ShaderTools::GlslangConverter::validateData(): output format should be Spirv or Unspecified but got ShaderTools::Format::Glsl\n"); "ShaderTools::GlslangConverter::validateData(): output format should be Spirv or Unspecified but got ShaderTools::Format::Glsl\n");
@ -641,7 +656,10 @@ void AnyConverterTest::validateDataPropagatePreprocess() {
{"reserved__identifier", "different__but_also_wrong"} {"reserved__identifier", "different__but_also_wrong"}
}); });
CORRADE_COMPARE(converter->validateData(Stage::Fragment, Utility::Directory::read(Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"))), Containers::Optional<Containers::Array<char>> data = Utility::Path::read(Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"));
CORRADE_VERIFY(data);
CORRADE_COMPARE(converter->validateData(Stage::Fragment, *data),
std::make_pair(true, "WARNING: 0:10: 'different__but_also_wrong' : identifiers containing consecutive underscores (\"__\") are reserved")); std::make_pair(true, "WARNING: 0:10: 'different__but_also_wrong' : identifiers containing consecutive underscores (\"__\") are reserved"));
} }
@ -657,16 +675,17 @@ void AnyConverterTest::validateDataPropagateConfiguration() {
Containers::Pointer<AbstractConverter> converter = manager.instantiate("AnyShaderConverter"); Containers::Pointer<AbstractConverter> converter = manager.instantiate("AnyShaderConverter");
converter->setInputFormat(Format::Glsl); converter->setInputFormat(Format::Glsl);
const std::string filename = Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "version-not-first.glsl"); Containers::Optional<Containers::Array<char>> data = Utility::Path::read(Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "version-not-first.glsl"));
CORRADE_VERIFY(data);
{ {
CORRADE_COMPARE(converter->validateData(Stage::Fragment, Utility::Directory::read(filename)), CORRADE_COMPARE(converter->validateData(Stage::Fragment, *data),
std::make_pair(false, "ERROR: 0:2: '#version' : must occur first in shader \nERROR: 1 compilation errors. No code generated.")); std::make_pair(false, "ERROR: 0:2: '#version' : must occur first in shader \nERROR: 1 compilation errors. No code generated."));
} { } {
converter->configuration().setValue("permissive", true); converter->configuration().setValue("permissive", true);
/* Lol stupid thing, apparently it has two differently worded messages /* Lol stupid thing, apparently it has two differently worded messages
for the same thing? Dumpster fire. */ for the same thing? Dumpster fire. */
CORRADE_COMPARE(converter->validateData(Stage::Fragment, Utility::Directory::read(filename)), CORRADE_COMPARE(converter->validateData(Stage::Fragment, *data),
std::make_pair(true, Utility::format("WARNING: 0:0: '#version' : Illegal to have non-comment, non-whitespace tokens before #version"))); std::make_pair(true, Utility::format("WARNING: 0:0: '#version' : Illegal to have non-comment, non-whitespace tokens before #version")));
} }
} }
@ -686,9 +705,12 @@ void AnyConverterTest::validateDataPropagateConfigurationUnknown() {
/* So it doesn't warn about anything */ /* So it doesn't warn about anything */
converter->setDefinitions({{"reserved__identifier", "sorry"}}); converter->setDefinitions({{"reserved__identifier", "sorry"}});
Containers::Optional<Containers::Array<char>> data = Utility::Path::read(Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"));
CORRADE_VERIFY(data);
std::ostringstream out; std::ostringstream out;
Warning redirectWarning{&out}; Warning redirectWarning{&out};
CORRADE_COMPARE(converter->validateData(Stage::Fragment, Utility::Directory::read(Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"))), CORRADE_COMPARE(converter->validateData(Stage::Fragment, *data),
std::make_pair(true, "")); std::make_pair(true, ""));
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"ShaderTools::AnyConverter::validateData(): option noSuchOption not recognized by GlslangShaderConverter\n"); "ShaderTools::AnyConverter::validateData(): option noSuchOption not recognized by GlslangShaderConverter\n");
@ -705,16 +727,16 @@ void AnyConverterTest::convertFileToFile() {
Containers::Pointer<AbstractConverter> converter = manager.instantiate("AnyShaderConverter"); Containers::Pointer<AbstractConverter> converter = manager.instantiate("AnyShaderConverter");
const std::string inputFilename = Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"); Containers::String inputFilename = Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl");
const std::string outputFilename = Utility::Directory::join(ANYSHADERCONVERTER_TEST_OUTPUT_DIR, "file.spv"); Containers::String outputFilename = Utility::Path::join(ANYSHADERCONVERTER_TEST_OUTPUT_DIR, "file.spv");
if(Utility::Directory::exists(outputFilename)) if(Utility::Path::exists(outputFilename))
CORRADE_VERIFY(Utility::Directory::rm(outputFilename)); CORRADE_VERIFY(Utility::Path::remove(outputFilename));
/* Make it print a warning so we know it's doing something */ /* Make it print a warning so we know it's doing something */
std::ostringstream out; std::ostringstream out;
Warning redirectWarning{&out}; Warning redirectWarning{&out};
CORRADE_VERIFY(converter->convertFileToFile(Stage::Fragment, inputFilename, outputFilename)); CORRADE_VERIFY(converter->convertFileToFile(Stage::Fragment, inputFilename, outputFilename));
CORRADE_VERIFY(Utility::Directory::exists(outputFilename)); CORRADE_VERIFY(Utility::Path::exists(outputFilename));
CORRADE_COMPARE(out.str(), Utility::formatString( CORRADE_COMPARE(out.str(), Utility::formatString(
"ShaderTools::GlslangConverter::convertDataToData(): compilation succeeded with the following message:\n" "ShaderTools::GlslangConverter::convertDataToData(): compilation succeeded with the following message:\n"
"WARNING: {}:10: 'reserved__identifier' : identifiers containing consecutive underscores (\"__\") are reserved\n", inputFilename)); "WARNING: {}:10: 'reserved__identifier' : identifiers containing consecutive underscores (\"__\") are reserved\n", inputFilename));
@ -776,8 +798,8 @@ void AnyConverterTest::convertFileToFilePreprocessNotSupported() {
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
CORRADE_VERIFY(!converter->convertFileToFile({}, Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.spv"), CORRADE_VERIFY(!converter->convertFileToFile({}, Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.spv"),
Utility::Directory::join(ANYSHADERCONVERTER_TEST_OUTPUT_DIR, "file.spvasm"))); Utility::Path::join(ANYSHADERCONVERTER_TEST_OUTPUT_DIR, "file.spvasm")));
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"ShaderTools::AnyConverter::convertFileToFile(): SpirvToolsShaderConverter does not support preprocessing\n"); "ShaderTools::AnyConverter::convertFileToFile(): SpirvToolsShaderConverter does not support preprocessing\n");
@ -785,8 +807,8 @@ void AnyConverterTest::convertFileToFilePreprocessNotSupported() {
out.str({}); out.str({});
converter->setDefinitions({}); converter->setDefinitions({});
converter->setFlags(ConverterFlag::PreprocessOnly); converter->setFlags(ConverterFlag::PreprocessOnly);
CORRADE_VERIFY(!converter->convertFileToFile({}, Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.spv"), CORRADE_VERIFY(!converter->convertFileToFile({}, Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.spv"),
Utility::Directory::join(ANYSHADERCONVERTER_TEST_OUTPUT_DIR, "file.spvasm"))); Utility::Path::join(ANYSHADERCONVERTER_TEST_OUTPUT_DIR, "file.spvasm")));
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"ShaderTools::AnyConverter::convertFileToFile(): SpirvToolsShaderConverter does not support preprocessing\n"); "ShaderTools::AnyConverter::convertFileToFile(): SpirvToolsShaderConverter does not support preprocessing\n");
} }
@ -806,8 +828,8 @@ void AnyConverterTest::convertFileToFileDebugInfoNotSupported() {
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
CORRADE_VERIFY(!converter->convertFileToFile({}, Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.spv"), CORRADE_VERIFY(!converter->convertFileToFile({}, Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.spv"),
Utility::Directory::join(ANYSHADERCONVERTER_TEST_OUTPUT_DIR, "file.spvasm"))); Utility::Path::join(ANYSHADERCONVERTER_TEST_OUTPUT_DIR, "file.spvasm")));
/** @todo it once may support that, in which case we need to find another /** @todo it once may support that, in which case we need to find another
victim */ victim */
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
@ -829,8 +851,8 @@ void AnyConverterTest::convertFileToFileOptimizationNotSupported() {
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
CORRADE_VERIFY(!converter->convertFileToFile({}, Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"), CORRADE_VERIFY(!converter->convertFileToFile({}, Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"),
Utility::Directory::join(ANYSHADERCONVERTER_TEST_OUTPUT_DIR, "file.spv"))); Utility::Path::join(ANYSHADERCONVERTER_TEST_OUTPUT_DIR, "file.spv")));
/** @todo it once may support that, in which case we need to find another /** @todo it once may support that, in which case we need to find another
victim */ victim */
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
@ -848,7 +870,7 @@ void AnyConverterTest::convertFileToFilePropagateFlags() {
Containers::Pointer<AbstractConverter> converter = manager.instantiate("AnyShaderConverter"); Containers::Pointer<AbstractConverter> converter = manager.instantiate("AnyShaderConverter");
const std::string filename = Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"); Containers::String filename = Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl");
/* With this, the warning should turn into an error. The converter should /* With this, the warning should turn into an error. The converter should
also print the verbose info. */ also print the verbose info. */
@ -860,7 +882,7 @@ void AnyConverterTest::convertFileToFilePropagateFlags() {
std::ostringstream out; std::ostringstream out;
Debug redirectDebug{&out}; Debug redirectDebug{&out};
Error redirectError{&out}; Error redirectError{&out};
CORRADE_VERIFY(!converter->convertFileToFile(Stage::Fragment, filename, Utility::Directory::join(ANYSHADERCONVERTER_TEST_OUTPUT_DIR, "file.spv"))); CORRADE_VERIFY(!converter->convertFileToFile(Stage::Fragment, filename, Utility::Path::join(ANYSHADERCONVERTER_TEST_OUTPUT_DIR, "file.spv")));
CORRADE_COMPARE(out.str(), Utility::formatString( CORRADE_COMPARE(out.str(), Utility::formatString(
"ShaderTools::AnyConverter::convertFileToFile(): using GlslToSpirvShaderConverter (provided by GlslangShaderConverter)\n" "ShaderTools::AnyConverter::convertFileToFile(): using GlslToSpirvShaderConverter (provided by GlslangShaderConverter)\n"
"ShaderTools::GlslangConverter::convertDataToData(): compilation failed:\n" "ShaderTools::GlslangConverter::convertDataToData(): compilation failed:\n"
@ -886,7 +908,7 @@ void AnyConverterTest::convertFileToFilePropagateInputVersion() {
with the file contents. */ with the file contents. */
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
CORRADE_VERIFY(!converter->convertFileToFile(Stage::Fragment, Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"), Utility::Directory::join(ANYSHADERCONVERTER_TEST_OUTPUT_DIR, "file.spv"))); CORRADE_VERIFY(!converter->convertFileToFile(Stage::Fragment, Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"), Utility::Path::join(ANYSHADERCONVERTER_TEST_OUTPUT_DIR, "file.spv")));
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"ShaderTools::GlslangConverter::convertDataToData(): input format version should be one of supported GLSL #version strings but got 100\n"); "ShaderTools::GlslangConverter::convertDataToData(): input format version should be one of supported GLSL #version strings but got 100\n");
} }
@ -910,7 +932,7 @@ void AnyConverterTest::convertFileToFilePropagateOutputVersion() {
with the file contents. */ with the file contents. */
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
CORRADE_VERIFY(!converter->convertFileToFile(Stage::Fragment, Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"), Utility::Directory::join(ANYSHADERCONVERTER_TEST_OUTPUT_DIR, "file.spv"))); CORRADE_VERIFY(!converter->convertFileToFile(Stage::Fragment, Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"), Utility::Path::join(ANYSHADERCONVERTER_TEST_OUTPUT_DIR, "file.spv")));
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"ShaderTools::GlslangConverter::convertDataToData(): output format version target should be opengl4.5 or vulkanX.Y but got opengl4.0\n"); "ShaderTools::GlslangConverter::convertDataToData(): output format version target should be opengl4.5 or vulkanX.Y but got opengl4.0\n");
} }
@ -934,16 +956,16 @@ void AnyConverterTest::convertFileToFilePropagatePreprocess() {
{"reserved__identifier", "different__but_also_wrong"} {"reserved__identifier", "different__but_also_wrong"}
}); });
const std::string inputFilename = Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"); Containers::String inputFilename = Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl");
const std::string outputFilename = Utility::Directory::join(ANYSHADERCONVERTER_TEST_OUTPUT_DIR, "file.spv"); Containers::String outputFilename = Utility::Path::join(ANYSHADERCONVERTER_TEST_OUTPUT_DIR, "file.spv");
if(Utility::Directory::exists(outputFilename)) if(Utility::Path::exists(outputFilename))
CORRADE_VERIFY(Utility::Directory::rm(outputFilename)); CORRADE_VERIFY(Utility::Path::remove(outputFilename));
/* Make it print a warning so we know it's doing something */ /* Make it print a warning so we know it's doing something */
std::ostringstream out; std::ostringstream out;
Warning redirectWarning{&out}; Warning redirectWarning{&out};
CORRADE_VERIFY(converter->convertFileToFile(Stage::Fragment, inputFilename, outputFilename)); CORRADE_VERIFY(converter->convertFileToFile(Stage::Fragment, inputFilename, outputFilename));
CORRADE_VERIFY(Utility::Directory::exists(outputFilename)); CORRADE_VERIFY(Utility::Path::exists(outputFilename));
CORRADE_COMPARE(out.str(), Utility::formatString( CORRADE_COMPARE(out.str(), Utility::formatString(
"ShaderTools::GlslangConverter::convertDataToData(): compilation succeeded with the following message:\n" "ShaderTools::GlslangConverter::convertDataToData(): compilation succeeded with the following message:\n"
"WARNING: {}:10: 'different__but_also_wrong' : identifiers containing consecutive underscores (\"__\") are reserved\n", inputFilename)); "WARNING: {}:10: 'different__but_also_wrong' : identifiers containing consecutive underscores (\"__\") are reserved\n", inputFilename));
@ -968,7 +990,7 @@ void AnyConverterTest::convertFileToFilePropagateDebugInfo() {
with the file contents. */ with the file contents. */
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
CORRADE_VERIFY(!converter->convertFileToFile(Stage::Fragment, Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"), Utility::Directory::join(ANYSHADERCONVERTER_TEST_OUTPUT_DIR, "file.spv"))); CORRADE_VERIFY(!converter->convertFileToFile(Stage::Fragment, Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"), Utility::Path::join(ANYSHADERCONVERTER_TEST_OUTPUT_DIR, "file.spv")));
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"ShaderTools::GlslangConverter::convertDataToData(): debug info level should be 0, 1 or empty but got 2\n"); "ShaderTools::GlslangConverter::convertDataToData(): debug info level should be 0, 1 or empty but got 2\n");
} }
@ -992,7 +1014,7 @@ void AnyConverterTest::convertFileToFilePropagateOptimization() {
with the file contents. */ with the file contents. */
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
CORRADE_VERIFY(!converter->convertFileToFile(Stage::Fragment, Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.spv"), Utility::Directory::join(ANYSHADERCONVERTER_TEST_OUTPUT_DIR, "file.spv"))); CORRADE_VERIFY(!converter->convertFileToFile(Stage::Fragment, Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.spv"), Utility::Path::join(ANYSHADERCONVERTER_TEST_OUTPUT_DIR, "file.spv")));
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"ShaderTools::SpirvToolsConverter::convertDataToData(): optimization level should be 0, 1, s, legalizeHlsl or empty but got 2\n"); "ShaderTools::SpirvToolsConverter::convertDataToData(): optimization level should be 0, 1, s, legalizeHlsl or empty but got 2\n");
} }
@ -1008,8 +1030,8 @@ void AnyConverterTest::convertFileToFilePropagateConfiguration() {
Containers::Pointer<AbstractConverter> converter = manager.instantiate("AnyShaderConverter"); Containers::Pointer<AbstractConverter> converter = manager.instantiate("AnyShaderConverter");
const std::string input = Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "version-not-first.glsl"); Containers::String input = Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "version-not-first.glsl");
const std::string output = Utility::Directory::join(ANYSHADERCONVERTER_TEST_OUTPUT_DIR, "file.spv"); Containers::String output = Utility::Path::join(ANYSHADERCONVERTER_TEST_OUTPUT_DIR, "file.spv");
{ {
std::ostringstream out; std::ostringstream out;
@ -1045,7 +1067,7 @@ void AnyConverterTest::convertFileToFilePropagateConfigurationUnknown() {
std::ostringstream out; std::ostringstream out;
Warning redirectWarning{&out}; Warning redirectWarning{&out};
CORRADE_VERIFY(converter->convertFileToFile(Stage::Fragment, Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"), Utility::Directory::join(ANYSHADERCONVERTER_TEST_OUTPUT_DIR, "file.glsl"))); CORRADE_VERIFY(converter->convertFileToFile(Stage::Fragment, Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"), Utility::Path::join(ANYSHADERCONVERTER_TEST_OUTPUT_DIR, "file.glsl")));
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"ShaderTools::AnyConverter::convertFileToFile(): option noSuchOption not recognized by GlslangShaderConverter\n"); "ShaderTools::AnyConverter::convertFileToFile(): option noSuchOption not recognized by GlslangShaderConverter\n");
} }
@ -1063,7 +1085,7 @@ void AnyConverterTest::convertFileToData() {
converter->setOutputFormat(Format::Spirv); converter->setOutputFormat(Format::Spirv);
const std::string inputFilename = Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"); Containers::String inputFilename = Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl");
/* Make it print a warning so we know it's doing something */ /* Make it print a warning so we know it's doing something */
std::ostringstream out; std::ostringstream out;
@ -1134,7 +1156,7 @@ void AnyConverterTest::convertFileToDataPreprocessNotSupported() {
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
CORRADE_VERIFY(!converter->convertFileToData({}, Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.spv"))); CORRADE_VERIFY(!converter->convertFileToData({}, Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.spv")));
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"ShaderTools::AnyConverter::convertFileToData(): SpirvToolsShaderConverter does not support preprocessing\n"); "ShaderTools::AnyConverter::convertFileToData(): SpirvToolsShaderConverter does not support preprocessing\n");
@ -1142,7 +1164,7 @@ void AnyConverterTest::convertFileToDataPreprocessNotSupported() {
out.str({}); out.str({});
converter->setDefinitions({}); converter->setDefinitions({});
converter->setFlags(ConverterFlag::PreprocessOnly); converter->setFlags(ConverterFlag::PreprocessOnly);
CORRADE_VERIFY(!converter->convertFileToData({}, Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.spv"))); CORRADE_VERIFY(!converter->convertFileToData({}, Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.spv")));
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"ShaderTools::AnyConverter::convertFileToData(): SpirvToolsShaderConverter does not support preprocessing\n"); "ShaderTools::AnyConverter::convertFileToData(): SpirvToolsShaderConverter does not support preprocessing\n");
} }
@ -1164,7 +1186,7 @@ void AnyConverterTest::convertFileToDataDebugInfoNotSupported() {
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
CORRADE_VERIFY(!converter->convertFileToData({}, Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.spv"))); CORRADE_VERIFY(!converter->convertFileToData({}, Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.spv")));
/** @todo it once may support that, in which case we need to find another /** @todo it once may support that, in which case we need to find another
victim */ victim */
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
@ -1188,7 +1210,7 @@ void AnyConverterTest::convertFileToDataOptimizationNotSupported() {
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
CORRADE_VERIFY(!converter->convertFileToData({}, Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"))); CORRADE_VERIFY(!converter->convertFileToData({}, Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl")));
/** @todo it once may support that, in which case we need to find another /** @todo it once may support that, in which case we need to find another
victim */ victim */
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
@ -1206,7 +1228,7 @@ void AnyConverterTest::convertFileToDataPropagateFlags() {
Containers::Pointer<AbstractConverter> converter = manager.instantiate("AnyShaderConverter"); Containers::Pointer<AbstractConverter> converter = manager.instantiate("AnyShaderConverter");
const std::string filename = Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"); Containers::String filename = Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl");
converter->setOutputFormat(Format::Spirv); converter->setOutputFormat(Format::Spirv);
@ -1248,7 +1270,7 @@ void AnyConverterTest::convertFileToDataPropagateInputVersion() {
with the file contents. */ with the file contents. */
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
CORRADE_VERIFY(!converter->convertFileToData(Stage::Fragment, Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"))); CORRADE_VERIFY(!converter->convertFileToData(Stage::Fragment, Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl")));
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"ShaderTools::GlslangConverter::convertDataToData(): input format version should be one of supported GLSL #version strings but got 100\n"); "ShaderTools::GlslangConverter::convertDataToData(): input format version should be one of supported GLSL #version strings but got 100\n");
} }
@ -1272,7 +1294,7 @@ void AnyConverterTest::convertFileToDataPropagateOutputVersion() {
with the file contents. */ with the file contents. */
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
CORRADE_VERIFY(!converter->convertFileToData(Stage::Fragment, Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"))); CORRADE_VERIFY(!converter->convertFileToData(Stage::Fragment, Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl")));
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"ShaderTools::GlslangConverter::convertDataToData(): output format version target should be opengl4.5 or vulkanX.Y but got opengl4.0\n"); "ShaderTools::GlslangConverter::convertDataToData(): output format version target should be opengl4.5 or vulkanX.Y but got opengl4.0\n");
} }
@ -1298,7 +1320,7 @@ void AnyConverterTest::convertFileToDataPropagatePreprocess() {
{"reserved__identifier", "different__but_also_wrong"} {"reserved__identifier", "different__but_also_wrong"}
}); });
const std::string inputFilename = Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"); Containers::String inputFilename = Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl");
/* Make it print a warning so we know it's doing something */ /* Make it print a warning so we know it's doing something */
std::ostringstream out; std::ostringstream out;
@ -1330,7 +1352,7 @@ void AnyConverterTest::convertFileToDataPropagateDebugInfo() {
with the file contents. */ with the file contents. */
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
CORRADE_VERIFY(!converter->convertFileToData(Stage::Fragment, Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"))); CORRADE_VERIFY(!converter->convertFileToData(Stage::Fragment, Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl")));
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"ShaderTools::GlslangConverter::convertDataToData(): debug info level should be 0, 1 or empty but got 2\n"); "ShaderTools::GlslangConverter::convertDataToData(): debug info level should be 0, 1 or empty but got 2\n");
} }
@ -1356,7 +1378,7 @@ void AnyConverterTest::convertFileToDataPropagateOptimization() {
with the file contents. */ with the file contents. */
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
CORRADE_VERIFY(!converter->convertFileToData(Stage::Fragment, Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.spv"))); CORRADE_VERIFY(!converter->convertFileToData(Stage::Fragment, Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.spv")));
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"ShaderTools::SpirvToolsConverter::convertDataToData(): optimization level should be 0, 1, s, legalizeHlsl or empty but got 2\n"); "ShaderTools::SpirvToolsConverter::convertDataToData(): optimization level should be 0, 1, s, legalizeHlsl or empty but got 2\n");
} }
@ -1374,7 +1396,7 @@ void AnyConverterTest::convertFileToDataPropagateConfiguration() {
converter->setOutputFormat(Format::Spirv); converter->setOutputFormat(Format::Spirv);
const std::string input = Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "version-not-first.glsl"); Containers::String input = Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "version-not-first.glsl");
{ {
std::ostringstream out; std::ostringstream out;
@ -1411,7 +1433,7 @@ void AnyConverterTest::convertFileToDataPropagateConfigurationUnknown() {
std::ostringstream out; std::ostringstream out;
Warning redirectWarning{&out}; Warning redirectWarning{&out};
CORRADE_VERIFY(converter->convertFileToData(Stage::Fragment, Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"))); CORRADE_VERIFY(converter->convertFileToData(Stage::Fragment, Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl")));
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"ShaderTools::AnyConverter::convertFileToData(): option noSuchOption not recognized by GlslangShaderConverter\n"); "ShaderTools::AnyConverter::convertFileToData(): option noSuchOption not recognized by GlslangShaderConverter\n");
} }
@ -1430,10 +1452,13 @@ void AnyConverterTest::convertDataToData() {
converter->setInputFormat(Format::Glsl); converter->setInputFormat(Format::Glsl);
converter->setOutputFormat(Format::Spirv); converter->setOutputFormat(Format::Spirv);
Containers::Optional<Containers::Array<char>> data = Utility::Path::read(Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"));
CORRADE_VERIFY(data);
/* Make it print a warning so we know it's doing something */ /* Make it print a warning so we know it's doing something */
std::ostringstream out; std::ostringstream out;
Warning redirectWarning{&out}; Warning redirectWarning{&out};
CORRADE_VERIFY(converter->convertDataToData(Stage::Fragment, Utility::Directory::read(Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl")))); CORRADE_VERIFY(converter->convertDataToData(Stage::Fragment, *data));
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"ShaderTools::GlslangConverter::convertDataToData(): compilation succeeded with the following message:\n" "ShaderTools::GlslangConverter::convertDataToData(): compilation succeeded with the following message:\n"
"WARNING: 0:10: 'reserved__identifier' : identifiers containing consecutive underscores (\"__\") are reserved\n"); "WARNING: 0:10: 'reserved__identifier' : identifiers containing consecutive underscores (\"__\") are reserved\n");
@ -1501,9 +1526,12 @@ void AnyConverterTest::convertDataToDataPreprocessNotSupported() {
{"DEFINE", "hahahahah"} {"DEFINE", "hahahahah"}
}); });
Containers::Optional<Containers::Array<char>> data = Utility::Path::read(Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.spv"));
CORRADE_VERIFY(data);
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
CORRADE_VERIFY(!converter->convertDataToData({}, Utility::Directory::read(Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.spv")))); CORRADE_VERIFY(!converter->convertDataToData({}, *data));
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"ShaderTools::AnyConverter::convertDataToData(): SpirvToolsShaderConverter does not support preprocessing\n"); "ShaderTools::AnyConverter::convertDataToData(): SpirvToolsShaderConverter does not support preprocessing\n");
@ -1511,7 +1539,7 @@ void AnyConverterTest::convertDataToDataPreprocessNotSupported() {
out.str({}); out.str({});
converter->setDefinitions({}); converter->setDefinitions({});
converter->setFlags(ConverterFlag::PreprocessOnly); converter->setFlags(ConverterFlag::PreprocessOnly);
CORRADE_VERIFY(!converter->convertDataToData({}, Utility::Directory::read(Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.spv")))); CORRADE_VERIFY(!converter->convertDataToData({}, *data));
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"ShaderTools::AnyConverter::convertDataToData(): SpirvToolsShaderConverter does not support preprocessing\n"); "ShaderTools::AnyConverter::convertDataToData(): SpirvToolsShaderConverter does not support preprocessing\n");
} }
@ -1532,9 +1560,12 @@ void AnyConverterTest::convertDataToDataDebugInfoNotSupported() {
converter->setDebugInfoLevel("1"); converter->setDebugInfoLevel("1");
Containers::Optional<Containers::Array<char>> data = Utility::Path::read(Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.spv"));
CORRADE_VERIFY(data);
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
CORRADE_VERIFY(!converter->convertDataToData({}, Utility::Directory::read(Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.spv")))); CORRADE_VERIFY(!converter->convertDataToData({}, *data));
/** @todo it once may support that, in which case we need to find another /** @todo it once may support that, in which case we need to find another
victim */ victim */
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
@ -1557,9 +1588,12 @@ void AnyConverterTest::convertDataToDataOptimizationNotSupported() {
converter->setOptimizationLevel("1"); converter->setOptimizationLevel("1");
Containers::Optional<Containers::Array<char>> data = Utility::Path::read(Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"));
CORRADE_VERIFY(data);
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
CORRADE_VERIFY(!converter->convertDataToData({}, Utility::Directory::read(Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl")))); CORRADE_VERIFY(!converter->convertDataToData({}, *data));
/** @todo it once may support that, in which case we need to find another /** @todo it once may support that, in which case we need to find another
victim */ victim */
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
@ -1584,13 +1618,16 @@ void AnyConverterTest::convertDataToDataPropagateFlags() {
also print the verbose info. */ also print the verbose info. */
converter->setFlags(ConverterFlag::Verbose|ConverterFlag::WarningAsError); converter->setFlags(ConverterFlag::Verbose|ConverterFlag::WarningAsError);
Containers::Optional<Containers::Array<char>> data = Utility::Path::read(Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"));
CORRADE_VERIFY(data);
/* We have to supply a valid file path because the version gets checked in /* We have to supply a valid file path because the version gets checked in
doConvertDataToData(), called from AbstractConverter::doConvertFileToFile() doConvertDataToData(), called from AbstractConverter::doConvertFileToFile()
with the file contents. */ with the file contents. */
std::ostringstream out; std::ostringstream out;
Debug redirectDebug{&out}; Debug redirectDebug{&out};
Error redirectError{&out}; Error redirectError{&out};
CORRADE_VERIFY(!converter->convertDataToData(Stage::Fragment, Utility::Directory::read(Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl")))); CORRADE_VERIFY(!converter->convertDataToData(Stage::Fragment, *data));
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"ShaderTools::AnyConverter::convertDataToData(): using GlslToSpirvShaderConverter (provided by GlslangShaderConverter)\n" "ShaderTools::AnyConverter::convertDataToData(): using GlslToSpirvShaderConverter (provided by GlslangShaderConverter)\n"
"ShaderTools::GlslangConverter::convertDataToData(): compilation failed:\n" "ShaderTools::GlslangConverter::convertDataToData(): compilation failed:\n"
@ -1613,12 +1650,15 @@ void AnyConverterTest::convertDataToDataPropagateInputVersion() {
converter->setOutputFormat(Format::Spirv); converter->setOutputFormat(Format::Spirv);
Containers::Optional<Containers::Array<char>> data = Utility::Path::read(Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"));
CORRADE_VERIFY(data);
/* We have to supply a valid file path because the version gets checked in /* We have to supply a valid file path because the version gets checked in
doConvertDataToData(), called from AbstractConverter::doConvertFileToFile() doConvertDataToData(), called from AbstractConverter::doConvertFileToFile()
with the file contents. */ with the file contents. */
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
CORRADE_VERIFY(!converter->convertDataToData(Stage::Fragment, Utility::Directory::read(Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl")))); CORRADE_VERIFY(!converter->convertDataToData(Stage::Fragment, *data));
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"ShaderTools::GlslangConverter::convertDataToData(): input format version should be one of supported GLSL #version strings but got 100\n"); "ShaderTools::GlslangConverter::convertDataToData(): input format version should be one of supported GLSL #version strings but got 100\n");
} }
@ -1639,12 +1679,15 @@ void AnyConverterTest::convertDataToDataPropagateOutputVersion() {
/* This is an invalid version */ /* This is an invalid version */
converter->setOutputFormat(Format::Spirv, "opengl4.0"); converter->setOutputFormat(Format::Spirv, "opengl4.0");
Containers::Optional<Containers::Array<char>> data = Utility::Path::read(Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"));
CORRADE_VERIFY(data);
/* We have to supply a valid file path because the version gets checked in /* We have to supply a valid file path because the version gets checked in
doConvertDataToData(), called from AbstractConverter::doConvertFileToFile() doConvertDataToData(), called from AbstractConverter::doConvertFileToFile()
with the file contents. */ with the file contents. */
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
CORRADE_VERIFY(!converter->convertDataToData(Stage::Fragment, Utility::Directory::read(Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl")))); CORRADE_VERIFY(!converter->convertDataToData(Stage::Fragment, *data));
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"ShaderTools::GlslangConverter::convertDataToData(): output format version target should be opengl4.5 or vulkanX.Y but got opengl4.0\n"); "ShaderTools::GlslangConverter::convertDataToData(): output format version target should be opengl4.5 or vulkanX.Y but got opengl4.0\n");
} }
@ -1671,10 +1714,13 @@ void AnyConverterTest::convertDataToDataPropagatePreprocess() {
{"reserved__identifier", "different__but_also_wrong"} {"reserved__identifier", "different__but_also_wrong"}
}); });
Containers::Optional<Containers::Array<char>> data = Utility::Path::read(Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"));
CORRADE_VERIFY(data);
/* Make it print a warning so we know it's doing something */ /* Make it print a warning so we know it's doing something */
std::ostringstream out; std::ostringstream out;
Warning redirectWarning{&out}; Warning redirectWarning{&out};
CORRADE_VERIFY(converter->convertDataToData(Stage::Fragment, Utility::Directory::read(Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl")))); CORRADE_VERIFY(converter->convertDataToData(Stage::Fragment, *data));
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"ShaderTools::GlslangConverter::convertDataToData(): compilation succeeded with the following message:\n" "ShaderTools::GlslangConverter::convertDataToData(): compilation succeeded with the following message:\n"
"WARNING: 0:10: 'different__but_also_wrong' : identifiers containing consecutive underscores (\"__\") are reserved\n"); "WARNING: 0:10: 'different__but_also_wrong' : identifiers containing consecutive underscores (\"__\") are reserved\n");
@ -1697,12 +1743,15 @@ void AnyConverterTest::convertDataToDataPropagateDebugInfo() {
/* This is an invalid level */ /* This is an invalid level */
converter->setDebugInfoLevel("2"); converter->setDebugInfoLevel("2");
Containers::Optional<Containers::Array<char>> data = Utility::Path::read(Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"));
CORRADE_VERIFY(data);
/* We have to supply a valid file path because the version gets checked in /* We have to supply a valid file path because the version gets checked in
doConvertDataToData(), called from AbstractConverter::doConvertFileToFile() doConvertDataToData(), called from AbstractConverter::doConvertFileToFile()
with the file contents. */ with the file contents. */
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
CORRADE_VERIFY(!converter->convertDataToData(Stage::Fragment, Utility::Directory::read(Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl")))); CORRADE_VERIFY(!converter->convertDataToData(Stage::Fragment, *data));
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"ShaderTools::GlslangConverter::convertDataToData(): debug info level should be 0, 1 or empty but got 2\n"); "ShaderTools::GlslangConverter::convertDataToData(): debug info level should be 0, 1 or empty but got 2\n");
} }
@ -1724,12 +1773,15 @@ void AnyConverterTest::convertDataToDataPropagateOptimization() {
/* This is an invalid level */ /* This is an invalid level */
converter->setOptimizationLevel("2"); converter->setOptimizationLevel("2");
Containers::Optional<Containers::Array<char>> data = Utility::Path::read(Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.spv"));
CORRADE_VERIFY(data);
/* We have to supply a valid file path because the version gets checked in /* We have to supply a valid file path because the version gets checked in
doConvertDataToData(), called from AbstractConverter::doConvertFileToFile() doConvertDataToData(), called from AbstractConverter::doConvertFileToFile()
with the file contents. */ with the file contents. */
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
CORRADE_VERIFY(!converter->convertDataToData(Stage::Fragment, Utility::Directory::read(Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.spv")))); CORRADE_VERIFY(!converter->convertDataToData(Stage::Fragment, *data));
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"ShaderTools::SpirvToolsConverter::convertDataToData(): optimization level should be 0, 1, s, legalizeHlsl or empty but got 2\n"); "ShaderTools::SpirvToolsConverter::convertDataToData(): optimization level should be 0, 1, s, legalizeHlsl or empty but got 2\n");
} }
@ -1748,12 +1800,13 @@ void AnyConverterTest::convertDataToDataPropagateConfiguration() {
converter->setInputFormat(Format::Glsl); converter->setInputFormat(Format::Glsl);
converter->setOutputFormat(Format::Spirv); converter->setOutputFormat(Format::Spirv);
const std::string input = Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "version-not-first.glsl"); Containers::Optional<Containers::Array<char>> data = Utility::Path::read(Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "version-not-first.glsl"));
CORRADE_VERIFY(data);
{ {
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
CORRADE_VERIFY(!converter->convertDataToData(Stage::Fragment, Utility::Directory::read(input))); CORRADE_VERIFY(!converter->convertDataToData(Stage::Fragment, *data));
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"ShaderTools::GlslangConverter::convertDataToData(): compilation failed:\nERROR: 0:2: '#version' : must occur first in shader \nERROR: 1 compilation errors. No code generated.\n"); "ShaderTools::GlslangConverter::convertDataToData(): compilation failed:\nERROR: 0:2: '#version' : must occur first in shader \nERROR: 1 compilation errors. No code generated.\n");
} { } {
@ -1762,7 +1815,7 @@ void AnyConverterTest::convertDataToDataPropagateConfiguration() {
for the same thing? Dumpster fire. */ for the same thing? Dumpster fire. */
std::ostringstream out; std::ostringstream out;
Warning redirectWarning{&out}; Warning redirectWarning{&out};
CORRADE_VERIFY(converter->convertDataToData(Stage::Fragment, Utility::Directory::read(input))); CORRADE_VERIFY(converter->convertDataToData(Stage::Fragment, *data));
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"ShaderTools::GlslangConverter::convertDataToData(): compilation succeeded with the following message:\nWARNING: 0:0: '#version' : Illegal to have non-comment, non-whitespace tokens before #version\n"); "ShaderTools::GlslangConverter::convertDataToData(): compilation succeeded with the following message:\nWARNING: 0:0: '#version' : Illegal to have non-comment, non-whitespace tokens before #version\n");
} }
@ -1784,9 +1837,12 @@ void AnyConverterTest::convertDataToDataPropagateConfigurationUnknown() {
/* So it doesn't warn about anything */ /* So it doesn't warn about anything */
converter->setDefinitions({{"reserved__identifier", "sorry"}}); converter->setDefinitions({{"reserved__identifier", "sorry"}});
Containers::Optional<Containers::Array<char>> data = Utility::Path::read(Utility::Path::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl"));
CORRADE_VERIFY(data);
std::ostringstream out; std::ostringstream out;
Warning redirectWarning{&out}; Warning redirectWarning{&out};
CORRADE_VERIFY(converter->convertDataToData(Stage::Fragment, Utility::Directory::read(Utility::Directory::join(ANYSHADERCONVERTER_TEST_DIR, "file.glsl")))); CORRADE_VERIFY(converter->convertDataToData(Stage::Fragment, *data));
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"ShaderTools::AnyConverter::convertDataToData(): option noSuchOption not recognized by GlslangShaderConverter\n"); "ShaderTools::AnyConverter::convertDataToData(): option noSuchOption not recognized by GlslangShaderConverter\n");
} }
@ -1841,7 +1897,7 @@ void AnyConverterTest::detectConvert() {
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
CORRADE_VERIFY(!converter->convertFileToFile({}, data.from, Utility::Directory::join(ANYSHADERCONVERTER_TEST_OUTPUT_DIR, data.to))); CORRADE_VERIFY(!converter->convertFileToFile({}, data.from, Utility::Path::join(ANYSHADERCONVERTER_TEST_OUTPUT_DIR, data.to)));
#ifndef CORRADE_PLUGINMANAGER_NO_DYNAMIC_PLUGIN_SUPPORT #ifndef CORRADE_PLUGINMANAGER_NO_DYNAMIC_PLUGIN_SUPPORT
CORRADE_COMPARE(out.str(), Utility::formatString( CORRADE_COMPARE(out.str(), Utility::formatString(
"PluginManager::Manager::load(): plugin {0} is not static and was not found in nonexistent\n" "PluginManager::Manager::load(): plugin {0} is not static and was not found in nonexistent\n"
@ -1862,7 +1918,7 @@ void AnyConverterTest::detectConvertExplicitFormat() {
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
CORRADE_VERIFY(!converter->convertFileToFile({}, "file.spv", Utility::Directory::join(ANYSHADERCONVERTER_TEST_OUTPUT_DIR, "file.glsl"))); CORRADE_VERIFY(!converter->convertFileToFile({}, "file.spv", Utility::Path::join(ANYSHADERCONVERTER_TEST_OUTPUT_DIR, "file.glsl")));
#ifndef CORRADE_PLUGINMANAGER_NO_DYNAMIC_PLUGIN_SUPPORT #ifndef CORRADE_PLUGINMANAGER_NO_DYNAMIC_PLUGIN_SUPPORT
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"PluginManager::Manager::load(): plugin HlslToWgslShaderConverter is not static and was not found in nonexistent\n" "PluginManager::Manager::load(): plugin HlslToWgslShaderConverter is not static and was not found in nonexistent\n"

Loading…
Cancel
Save