// QT includes #include #include // JsonSchema includes #include // hyperion includes #include #include "HyperionConfig.h" bool loadConfig(const QString & configFile, bool correct, bool ignore) { // make sure the resources are loaded (they may be left out after static linking) Q_INIT_RESOURCE(resource); //////////////////////////////////////////////////////////// // read and set the json schema from the resource //////////////////////////////////////////////////////////// QJsonObject schemaJson; try { schemaJson = QJsonFactory::readSchema(":/hyperion-schema"); } catch(const std::runtime_error& error) { throw std::runtime_error(error.what()); } QJsonSchemaChecker schemaChecker; schemaChecker.setSchema(schemaJson); //////////////////////////////////////////////////////////// // read and validate the configuration file from the command line //////////////////////////////////////////////////////////// QJsonObject jsonConfig = QJsonFactory::readConfig(configFile); if (!correct) { if (!schemaChecker.validate(jsonConfig).first) { QStringList schemaErrors = schemaChecker.getMessages(); for (auto & schemaError : schemaErrors) { qDebug() << "config write validation: " << schemaError; } qDebug() << "FAILED"; exit(1); return false; } } else { jsonConfig = schemaChecker.getAutoCorrectedConfig(jsonConfig, ignore); // The second parameter is to ignore the "required" keyword in hyperion schema QJsonFactory::writeJson(configFile, jsonConfig); } return true; } void usage() { qDebug() << "Missing required configuration file to test"; qDebug() << "Usage: test_configfile