mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2025-12-31 16:30:07 -06:00
* Added pboettch/json-schema-validator submodule * Added initial code for selecting window config to edit * Use updated sgct submodule with json-validate * Bump sgct submodule version reference * Bump sgct submodule version reference * Version checking of sgct window config in progress * Json schema validator submodule is now in sgct * Added support for read-only window configs, and additional changes * More changes with opening config in window edit, plus schema files added * Update sgct schema version with more defs to work with sgctedit schema * Fixes to get sgct edit schema working with dialog for error messages * Improvements in exception handling * Improved handling of multiple sgct & json exception types * Minor improvements in exception messages * Extra spaces in error message output * Fixing importing of json config data from launcher to sgctedit * Fixed window size & position update * Changes for preserving settings in edit vs new mode * Changes to import settings from config file * More changes for importing testing of config file based on file tests * Fixed window placement dims in monitor, and some code refactoring * Move json validation before initial read * Add CMake copy of sgct schema file to OpenSpace post-build * Bump sgct submodule reference * Modify calls for json schema validation and bump to latest sgct * Bump to new sgct repo with unit testing and updated schema * Added first test for window config editor schema * Finished tests for sgcteditor validation * Code cleanup pass * Fix of sgctedit test for remove description * CMake and include config changes to fix build after merge * Bump sgct submodule version * Improve paths in sgctedit test * Bump sgct reference for test path fix * Check for imported monitor number being in valid range * Make sgct config 'monitor' key/value optional * Have 'save' or 'save as' buttons depending on edit or new modes * Code review feedback changes * Fix to include the last file in the user config dir list * Addressing some PR request * Change to pass-by-reference in editRefusalDialog * Separating errors into summary and detailed messages in error dialog * Disable edit button with hover text if config read shows invalid format --------- Co-authored-by: Alexander Bock <alexander.bock@liu.se>
620 lines
15 KiB
C++
620 lines
15 KiB
C++
/*****************************************************************************************
|
|
* *
|
|
* OpenSpace *
|
|
* *
|
|
* Copyright (c) 2014-2023 *
|
|
* *
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
|
* software and associated documentation files (the "Software"), to deal in the Software *
|
|
* without restriction, including without limitation the rights to use, copy, modify, *
|
|
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
|
* permit persons to whom the Software is furnished to do so, subject to the following *
|
|
* conditions: *
|
|
* *
|
|
* The above copyright notice and this permission notice shall be included in all copies *
|
|
* or substantial portions of the Software. *
|
|
* *
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
|
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
|
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
|
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
|
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
|
****************************************************************************************/
|
|
|
|
#include <catch2/catch_test_macros.hpp>
|
|
#include <catch2/matchers/catch_matchers_exception.hpp>
|
|
|
|
#include <ghoul/filesystem/filesystem.h>
|
|
#include <ghoul/fmt.h>
|
|
#include <nlohmann/json.hpp>
|
|
#include <nlohmann/json-schema.hpp>
|
|
#include <sgct/readconfig.h>
|
|
#include <openspace/engine/configuration.h>
|
|
#include <filesystem>
|
|
#include <fstream>
|
|
|
|
using namespace openspace::configuration;
|
|
|
|
namespace {
|
|
std::string stringify(const std::string filename) {
|
|
std::ifstream myfile;
|
|
myfile.open(filename);
|
|
std::stringstream buffer;
|
|
buffer << myfile.rdbuf();
|
|
return buffer.str();
|
|
}
|
|
|
|
void attemptValidation(const std::string cfgString) {
|
|
std::filesystem::path schemaDir = absPath("${TESTDIR}/../config/schema");
|
|
std::string schemaString = stringify(
|
|
schemaDir.string() + "/sgcteditor.schema.json"
|
|
);
|
|
sgct::validateConfigAgainstSchema(cfgString, schemaString, schemaDir);
|
|
}
|
|
} // namespace
|
|
|
|
TEST_CASE("SgctEdit: pass", "[sgctedit]") {
|
|
const std::string config =
|
|
R"({
|
|
"generator": {
|
|
"major": 1,
|
|
"minor": 1,
|
|
"name": "SgctWindowConfig"
|
|
},
|
|
"masteraddress": "localhost",
|
|
"nodes": [
|
|
{
|
|
"address": "localhost",
|
|
"port": 20401,
|
|
"windows": [
|
|
{
|
|
"border": true,
|
|
"id": 0,
|
|
"monitor": 0,
|
|
"name": "ffss",
|
|
"pos": {
|
|
"x": 112,
|
|
"y": 77
|
|
},
|
|
"size": {
|
|
"x": 1280,
|
|
"y": 720
|
|
},
|
|
"viewports": [
|
|
{
|
|
"pos": {
|
|
"x": 0.0,
|
|
"y": 0.0
|
|
},
|
|
"projection": {
|
|
"heightoffset": 0.0,
|
|
"quality": "1024",
|
|
"type": "CylindricalProjection"
|
|
},
|
|
"size": {
|
|
"x": 1.0,
|
|
"y": 1.0
|
|
},
|
|
"tracked": true
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
],
|
|
"scene": {
|
|
"orientation": {
|
|
"w": 0.0,
|
|
"x": 0.0,
|
|
"y": 0.0,
|
|
"z": 0.0
|
|
}
|
|
},
|
|
"users": [
|
|
{
|
|
"eyeseparation": 0.06499999761581421,
|
|
"pos": {
|
|
"x": 0.0,
|
|
"y": 0.0,
|
|
"z": 4.0
|
|
}
|
|
}
|
|
],
|
|
"version": 1
|
|
})";
|
|
CHECK_NOTHROW(attemptValidation(config));
|
|
}
|
|
|
|
TEST_CASE("SgctEdit: addedTrailingBracket", "[sgctedit]") {
|
|
const std::string config =
|
|
R"({
|
|
"generator": {
|
|
"major": 0,
|
|
"minor": 1,
|
|
"name": "SgctWindowConfig"
|
|
},
|
|
"masteraddress": "localhost",
|
|
"nodes": [
|
|
{
|
|
"address": "localhost",
|
|
"port": 20401,
|
|
"windows": [
|
|
{
|
|
"border": true,
|
|
"id": 0,
|
|
"monitor": 0,
|
|
"name": "ffss",
|
|
"pos": {
|
|
"x": 112,
|
|
"y": 77
|
|
},
|
|
"size": {
|
|
"x": 1280,
|
|
"y": 720
|
|
},
|
|
"viewports": [
|
|
{
|
|
"pos": {
|
|
"x": 0.0,
|
|
"y": 0.0
|
|
},
|
|
"projection": {
|
|
"heightoffset": 0.0,
|
|
"quality": "1024",
|
|
"type": "CylindricalProjection"
|
|
},
|
|
"size": {
|
|
"x": 1.0,
|
|
"y": 1.0
|
|
},
|
|
"tracked": true
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
],
|
|
"scene": {
|
|
"orientation": {
|
|
"w": 0.0,
|
|
"x": 0.0,
|
|
"y": 0.0,
|
|
"z": 0.0
|
|
}
|
|
},
|
|
"users": [
|
|
{
|
|
"eyeseparation": 0.06499999761581421,
|
|
"pos": {
|
|
"x": 0.0,
|
|
"y": 0.0,
|
|
"z": 4.0
|
|
}
|
|
}
|
|
],
|
|
"version": 1
|
|
}})";
|
|
CHECK_THROWS_MATCHES(
|
|
attemptValidation(config),
|
|
nlohmann::json::parse_error,
|
|
Catch::Matchers::Message(
|
|
"[json.exception.parse_error.101] parse error at line 67, column 2: "
|
|
"syntax error while parsing value - unexpected '}'; expected "
|
|
"end of input"
|
|
)
|
|
);
|
|
}
|
|
|
|
TEST_CASE("SgctEdit: missingMasterAddress", "[sgctedit]") {
|
|
const std::string config =
|
|
R"({
|
|
"generator": {
|
|
"major": 1,
|
|
"minor": 1,
|
|
"name": "SgctWindowConfig"
|
|
},
|
|
"nodes": [
|
|
{
|
|
"address": "localhost",
|
|
"port": 20401,
|
|
"windows": [
|
|
{
|
|
"border": true,
|
|
"id": 0,
|
|
"monitor": 1,
|
|
"name": "name",
|
|
"pos": {
|
|
"x": 112,
|
|
"y": 77
|
|
},
|
|
"size": {
|
|
"x": 1280,
|
|
"y": 720
|
|
},
|
|
"viewports": [
|
|
{
|
|
"pos": {
|
|
"x": 0.0,
|
|
"y": 0.0
|
|
},
|
|
"projection": {
|
|
"heightoffset": 0.0,
|
|
"quality": "1024",
|
|
"type": "CylindricalProjection"
|
|
},
|
|
"size": {
|
|
"x": 1.0,
|
|
"y": 1.0
|
|
},
|
|
"tracked": true
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
],
|
|
"scene": {
|
|
"orientation": {
|
|
"w": 0.0,
|
|
"x": 0.0,
|
|
"y": 0.0,
|
|
"z": 0.0
|
|
}
|
|
},
|
|
"users": [
|
|
{
|
|
"eyeseparation": 0.06499999761581421,
|
|
"pos": {
|
|
"x": 0.0,
|
|
"y": 0.0,
|
|
"z": 4.0
|
|
}
|
|
}
|
|
],
|
|
"version": 1
|
|
})";
|
|
CHECK_THROWS_MATCHES(
|
|
attemptValidation(config),
|
|
std::exception,
|
|
Catch::Matchers::Message(
|
|
"At of {\"generator\":{\"major\":1,\"minor\":1,\"name\":"
|
|
"\"SgctWindowConfig\"},\"nodes\":[{\"address\":\"localhost\",\"port\":"
|
|
"20401,\"windows\":[{\"border\":true,\"id\":0,\"monitor\":1,\"name\":"
|
|
"\"name\",\"pos\":{\"x\":112,\"y\":77},\"size\":{\"x\":1280,\"y\":720},"
|
|
"\"viewports\":[{\"pos\":{\"x\":0.0,\"y\":0.0},\"projection\":"
|
|
"{\"heightoffset\":0.0,\"quality\":\"1024\",\"type\":"
|
|
"\"CylindricalProjection\"},\"size\":{\"x\":1.0,\"y\":1.0},\"tracked\":"
|
|
"true}]}]}],\"scene\":{\"orientation\":{\"w\":0.0,\"x\":0.0,\"y\":0.0,"
|
|
"\"z\":0.0}},\"users\":[{\"eyeseparation\":0.06499999761581421,\"pos\":"
|
|
"{\"x\":0.0,\"y\":0.0,\"z\":4.0}}],\"version\":1} - required property "
|
|
"'masteraddress' not found in object\n"
|
|
)
|
|
);
|
|
}
|
|
|
|
TEST_CASE("SgctEdit: missingPos", "[sgctedit]") {
|
|
const std::string config =
|
|
R"({
|
|
"generator": {
|
|
"major": 1,
|
|
"minor": 1,
|
|
"name": "SgctWindowConfig"
|
|
},
|
|
"masteraddress": "localhost",
|
|
"nodes": [
|
|
{
|
|
"address": "localhost",
|
|
"port": 20401,
|
|
"windows": [
|
|
{
|
|
"border": true,
|
|
"id": 0,
|
|
"monitor": 0,
|
|
"name": "name",
|
|
"pos": {
|
|
"x": 112,
|
|
"y": 77
|
|
},
|
|
"size": {
|
|
"x": 1280,
|
|
"y": 720
|
|
},
|
|
"viewports": [
|
|
{
|
|
"pos": {
|
|
"x": 0.0,
|
|
"y": 0.0
|
|
},
|
|
"projection": {
|
|
"heightoffset": 0.0,
|
|
"quality": "1024",
|
|
"type": "CylindricalProjection"
|
|
},
|
|
"size": {
|
|
"x": 1.0,
|
|
"y": 1.0
|
|
},
|
|
"tracked": true
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
],
|
|
"scene": {
|
|
"orientation": {
|
|
"w": 0.0,
|
|
"x": 0.0,
|
|
"y": 0.0,
|
|
"z": 0.0
|
|
}
|
|
},
|
|
"users": [
|
|
{
|
|
"eyeseparation": 0.06499999761581421
|
|
}
|
|
],
|
|
"version": 1
|
|
})";
|
|
CHECK_THROWS_MATCHES(
|
|
attemptValidation(config),
|
|
std::exception,
|
|
Catch::Matchers::Message(
|
|
"At /users/0 of {\"eyeseparation\":0.06499999761581421} - required "
|
|
"property 'pos' not found in object\n"
|
|
)
|
|
);
|
|
}
|
|
|
|
TEST_CASE("SgctEdit: missingGenerator", "[sgctedit]") {
|
|
const std::string config =
|
|
R"({
|
|
"masteraddress": "localhost",
|
|
"nodes": [
|
|
{
|
|
"address": "localhost",
|
|
"port": 20401,
|
|
"windows": [
|
|
{
|
|
"border": true,
|
|
"id": 0,
|
|
"monitor": 0,
|
|
"name": "name",
|
|
"pos": {
|
|
"x": 112,
|
|
"y": 77
|
|
},
|
|
"size": {
|
|
"x": 1280,
|
|
"y": 720
|
|
},
|
|
"viewports": [
|
|
{
|
|
"pos": {
|
|
"x": 0.0,
|
|
"y": 0.0
|
|
},
|
|
"projection": {
|
|
"heightoffset": 0.0,
|
|
"quality": "1024",
|
|
"type": "CylindricalProjection"
|
|
},
|
|
"size": {
|
|
"x": 1.0,
|
|
"y": 1.0
|
|
},
|
|
"tracked": true
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
],
|
|
"scene": {
|
|
"orientation": {
|
|
"w": 0.0,
|
|
"x": 0.0,
|
|
"y": 0.0,
|
|
"z": 0.0
|
|
}
|
|
},
|
|
"users": [
|
|
{
|
|
"eyeseparation": 0.06499999761581421,
|
|
"pos": {
|
|
"x": 0.0,
|
|
"y": 0.0,
|
|
"z": 4.0
|
|
}
|
|
}
|
|
],
|
|
"version": 1
|
|
})";
|
|
CHECK_THROWS_MATCHES(
|
|
attemptValidation(config),
|
|
std::exception,
|
|
Catch::Matchers::Message(
|
|
"At of {\"masteraddress\":\"localhost\",\"nodes\":[{\"address\":"
|
|
"\"localhost\",\"port\":20401,\"windows\":[{\"border\":true,\"id\":"
|
|
"0,\"monitor\":0,\"name\":\"name\",\"pos\":{\"x\":112,\"y\":77},\"size\":"
|
|
"{\"x\":1280,\"y\":720},\"viewports\":[{\"pos\":{\"x\":0.0,\"y\":0.0},"
|
|
"\"projection\":{\"heightoffset\":0.0,\"quality\":\"1024\",\"type\":"
|
|
"\"CylindricalProjection\"},\"size\":{\"x\":1.0,\"y\":1.0},\"tracked\":"
|
|
"true}]}]}],\"scene\":{\"orientation\":{\"w\":0.0,\"x\":0.0,\"y\":0.0,\"z\":"
|
|
"0.0}},\"users\":[{\"eyeseparation\":0.06499999761581421,\"pos\":{\"x\":"
|
|
"0.0,\"y\":0.0,\"z\":4.0}}],\"version\":1} - required property 'generator' "
|
|
"not found in object\n"
|
|
)
|
|
);
|
|
}
|
|
|
|
TEST_CASE("SgctEdit: minimumVersion", "[sgctedit]") {
|
|
const sgct::config::GeneratorVersion minVersion { "SgctWindowConfig", 1, 1 };
|
|
std::string inputCfg =
|
|
absPath("${TESTDIR}/sgctedit/fails_minimum_version.json").string();
|
|
sgct::config::GeneratorVersion ver = sgct::readConfigGenerator(inputCfg);
|
|
CHECK_FALSE(ver.versionCheck(minVersion));
|
|
}
|
|
|
|
TEST_CASE("SgctEdit: invalidZvalue", "[sgctedit]") {
|
|
const std::string config =
|
|
R"({
|
|
"generator": {
|
|
"major": 1,
|
|
"minor": 1,
|
|
"name": "SgctWindowConfig"
|
|
},
|
|
"masteraddress": "localhost",
|
|
"nodes": [
|
|
{
|
|
"address": "localhost",
|
|
"port": 20401,
|
|
"windows": [
|
|
{
|
|
"border": true,
|
|
"id": 0,
|
|
"monitor": 1,
|
|
"name": "ffss",
|
|
"pos": {
|
|
"x": 112,
|
|
"y": 77
|
|
},
|
|
"size": {
|
|
"x": 1280,
|
|
"y": 720,
|
|
"z": s
|
|
},
|
|
"viewports": [
|
|
{
|
|
"pos": {
|
|
"x": 0.0,
|
|
"y": 0.0
|
|
},
|
|
"projection": {
|
|
"heightoffset": 0.0,
|
|
"quality": "1024",
|
|
"type": "CylindricalProjection"
|
|
},
|
|
"size": {
|
|
"x": 1.0,
|
|
"y": 1.0
|
|
},
|
|
"tracked": true
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
],
|
|
"scene": {
|
|
"orientation": {
|
|
"w": 0.0,
|
|
"x": 0.0,
|
|
"y": 0.0,
|
|
"z": 0.0
|
|
}
|
|
},
|
|
"users": [
|
|
{
|
|
"eyeseparation": 0.06499999761581421,
|
|
"pos": {
|
|
"x": 0.0,
|
|
"y": 0.0,
|
|
"z": 4.0
|
|
}
|
|
}
|
|
],
|
|
"version": 1
|
|
})";
|
|
CHECK_THROWS_MATCHES(
|
|
attemptValidation(config),
|
|
std::exception,
|
|
Catch::Matchers::Message(
|
|
"[json.exception.parse_error.101] parse error at line 25, column 11: "
|
|
"syntax error while parsing value - invalid literal; last read: '\"z\": s'"
|
|
)
|
|
);
|
|
}
|
|
|
|
TEST_CASE("SgctEdit: unwelcomeValue", "[sgctedit]") {
|
|
const std::string config =
|
|
R"({
|
|
"generator": {
|
|
"major": 1,
|
|
"minor": 1,
|
|
"name": "SgctWindowConfig"
|
|
},
|
|
"masteraddress": "localhost",
|
|
"nodes": [
|
|
{
|
|
"address": "localhost",
|
|
"port": 20401,
|
|
"windows": [
|
|
{
|
|
"border": true,
|
|
"id": 0,
|
|
"monitor": 0,
|
|
"name": "ffss",
|
|
"pos": {
|
|
"x": 112,
|
|
"y": 77
|
|
},
|
|
"size": {
|
|
"x": 1280,
|
|
"y": 720
|
|
},
|
|
"viewports": [
|
|
{
|
|
"pos": {
|
|
"x": 0.0,
|
|
"y": 0.0
|
|
},
|
|
"projection": {
|
|
"heightoffset": 0.0,
|
|
"quality": "1024",
|
|
"type": "CylindricalProjection"
|
|
},
|
|
"size": {
|
|
"x": 1.0,
|
|
"y": 1.0
|
|
},
|
|
"tracked": true
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
],
|
|
"scene": {
|
|
"orientation": {
|
|
"w": 0.0,
|
|
"x": 0.0,
|
|
"y": 0.0,
|
|
"z": 0.0
|
|
}
|
|
},
|
|
"users": [
|
|
{
|
|
"extra": "???",
|
|
"eyeseparation": 0.6,
|
|
"pos": {
|
|
"x": 0.0,
|
|
"y": 0.0,
|
|
"z": 4.0
|
|
}
|
|
}
|
|
],
|
|
"version": 1
|
|
})";
|
|
CHECK_THROWS_MATCHES(
|
|
attemptValidation(config),
|
|
std::exception,
|
|
Catch::Matchers::Message(
|
|
"At /users/0 of {\"extra\":\"???\",\"eyeseparation\":0.6,\"pos\":"
|
|
"{\"x\":0.0,\"y\":0.0,\"z\":4.0}} - validation failed for additional "
|
|
"property 'extra': instance invalid as per false-schema\n"
|
|
)
|
|
);
|
|
}
|