mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-06-21 19:09:15 +02:00
Can store JSON object.
This commit is contained in:
parent
480fa912ba
commit
1364f4391d
4 changed files with 52 additions and 12 deletions
|
@ -734,9 +734,9 @@ extern InputPluginList getInputPlugins();
|
||||||
extern void saveInputPluginSettings(const InputPluginList& plugins);
|
extern void saveInputPluginSettings(const InputPluginList& plugins);
|
||||||
|
|
||||||
// Parameters used for running tests from teh command line
|
// Parameters used for running tests from teh command line
|
||||||
const QString TEST_SCRIPT_COMMAND { "--testScript" };
|
const QString TEST_SCRIPT_COMMAND{ "--testScript" };
|
||||||
const QString TEST_QUIT_WHEN_FINISHED_OPTION { "quitWhenFinished" };
|
const QString TEST_QUIT_WHEN_FINISHED_OPTION{ "quitWhenFinished" };
|
||||||
const QString TEST_SNAPSHOT_LOCATION_COMMAND { "--testSnapshotLocation" };
|
const QString TEST_RESULTS_LOCATION_COMMAND{ "--testResultsLocation" };
|
||||||
|
|
||||||
bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) {
|
bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) {
|
||||||
const char** constArgv = const_cast<const char**>(argv);
|
const char** constArgv = const_cast<const char**>(argv);
|
||||||
|
@ -1014,7 +1014,9 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
|
||||||
|
|
||||||
// If the URL scheme is http(s) or ftp, then use as is, else - treat it as a local file
|
// If the URL scheme is http(s) or ftp, then use as is, else - treat it as a local file
|
||||||
// This is done so as not break previous command line scripts
|
// This is done so as not break previous command line scripts
|
||||||
if (testScriptPath.left(URL_SCHEME_HTTP.length()) == URL_SCHEME_HTTP || testScriptPath.left(URL_SCHEME_FTP.length()) == URL_SCHEME_FTP) {
|
if (testScriptPath.left(URL_SCHEME_HTTP.length()) == URL_SCHEME_HTTP ||
|
||||||
|
testScriptPath.left(URL_SCHEME_FTP.length()) == URL_SCHEME_FTP) {
|
||||||
|
|
||||||
setProperty(hifi::properties::TEST, QUrl::fromUserInput(testScriptPath));
|
setProperty(hifi::properties::TEST, QUrl::fromUserInput(testScriptPath));
|
||||||
} else if (QFileInfo(testScriptPath).exists()) {
|
} else if (QFileInfo(testScriptPath).exists()) {
|
||||||
setProperty(hifi::properties::TEST, QUrl::fromLocalFile(testScriptPath));
|
setProperty(hifi::properties::TEST, QUrl::fromLocalFile(testScriptPath));
|
||||||
|
@ -1024,12 +1026,13 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
|
||||||
if ((i + 2) < args.size() && args.at(i + 2) == TEST_QUIT_WHEN_FINISHED_OPTION) {
|
if ((i + 2) < args.size() && args.at(i + 2) == TEST_QUIT_WHEN_FINISHED_OPTION) {
|
||||||
quitWhenFinished = true;
|
quitWhenFinished = true;
|
||||||
}
|
}
|
||||||
} else if (args.at(i) == TEST_SNAPSHOT_LOCATION_COMMAND) {
|
} else if (args.at(i) == TEST_RESULTS_LOCATION_COMMAND) {
|
||||||
// Set test snapshot location only if it is a writeable directory
|
// Set test snapshot location only if it is a writeable directory
|
||||||
QString pathname(args.at(i + 1));
|
QString path(args.at(i + 1));
|
||||||
QFileInfo fileInfo(pathname);
|
|
||||||
|
QFileInfo fileInfo(path);
|
||||||
if (fileInfo.isDir() && fileInfo.isWritable()) {
|
if (fileInfo.isDir() && fileInfo.isWritable()) {
|
||||||
testSnapshotLocation = pathname;
|
testResultsLocation = path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7475,7 +7478,9 @@ void Application::loadAvatarBrowser() const {
|
||||||
void Application::takeSnapshot(bool notify, bool includeAnimated, float aspectRatio, const QString& filename) {
|
void Application::takeSnapshot(bool notify, bool includeAnimated, float aspectRatio, const QString& filename) {
|
||||||
postLambdaEvent([notify, includeAnimated, aspectRatio, filename, this] {
|
postLambdaEvent([notify, includeAnimated, aspectRatio, filename, this] {
|
||||||
// Get a screenshot and save it
|
// Get a screenshot and save it
|
||||||
QString path = Snapshot::saveSnapshot(getActiveDisplayPlugin()->getScreenshot(aspectRatio), filename, testSnapshotLocation);
|
QString path =
|
||||||
|
Snapshot::saveSnapshot(getActiveDisplayPlugin()->getScreenshot(aspectRatio), filename, testResultsLocation);
|
||||||
|
|
||||||
// If we're not doing an animated snapshot as well...
|
// If we're not doing an animated snapshot as well...
|
||||||
if (!includeAnimated) {
|
if (!includeAnimated) {
|
||||||
// Tell the dependency manager that the capture of the still snapshot has taken place.
|
// Tell the dependency manager that the capture of the still snapshot has taken place.
|
||||||
|
@ -7489,7 +7494,9 @@ void Application::takeSnapshot(bool notify, bool includeAnimated, float aspectRa
|
||||||
|
|
||||||
void Application::takeSecondaryCameraSnapshot(const QString& filename) {
|
void Application::takeSecondaryCameraSnapshot(const QString& filename) {
|
||||||
postLambdaEvent([filename, this] {
|
postLambdaEvent([filename, this] {
|
||||||
QString snapshotPath = Snapshot::saveSnapshot(getActiveDisplayPlugin()->getSecondaryCameraScreenshot(), filename, testSnapshotLocation);
|
QString snapshotPath =
|
||||||
|
Snapshot::saveSnapshot(getActiveDisplayPlugin()->getSecondaryCameraScreenshot(), filename, testResultsLocation);
|
||||||
|
|
||||||
emit DependencyManager::get<WindowScriptingInterface>()->stillSnapshotTaken(snapshotPath, true);
|
emit DependencyManager::get<WindowScriptingInterface>()->stillSnapshotTaken(snapshotPath, true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -418,6 +418,7 @@ public slots:
|
||||||
void updateVerboseLogging();
|
void updateVerboseLogging();
|
||||||
Q_INVOKABLE void openAndroidActivity(const QString& activityName);
|
Q_INVOKABLE void openAndroidActivity(const QString& activityName);
|
||||||
|
|
||||||
|
QString getTestResultsLocation() { return testResultsLocation; };
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onDesktopRootItemCreated(QQuickItem* qmlContext);
|
void onDesktopRootItemCreated(QQuickItem* qmlContext);
|
||||||
|
@ -751,7 +752,7 @@ private:
|
||||||
std::atomic<bool> _pendingIdleEvent { true };
|
std::atomic<bool> _pendingIdleEvent { true };
|
||||||
std::atomic<bool> _pendingRenderEvent { true };
|
std::atomic<bool> _pendingRenderEvent { true };
|
||||||
|
|
||||||
QString testSnapshotLocation;
|
QString testResultsLocation;
|
||||||
bool quitWhenFinished { false };
|
bool quitWhenFinished { false };
|
||||||
};
|
};
|
||||||
#endif // hifi_Application_h
|
#endif // hifi_Application_h
|
||||||
|
|
|
@ -160,3 +160,30 @@ void TestScriptingInterface::clearCaches() {
|
||||||
qApp->reloadResourceCaches();
|
qApp->reloadResourceCaches();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Writes a JSON object from javascript to a file
|
||||||
|
void TestScriptingInterface::saveObject(QVariant variant, const QString& filename) {
|
||||||
|
QString testResultsLocation = qApp->getTestResultsLocation();
|
||||||
|
if (testResultsLocation.isNull()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonDocument jsonDocument;
|
||||||
|
jsonDocument = QJsonDocument::fromVariant(variant);
|
||||||
|
if (jsonDocument.isNull()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray jsonData = jsonDocument.toJson();
|
||||||
|
|
||||||
|
// Append trailing slash if needed
|
||||||
|
if (testResultsLocation.right(1) != "/") {
|
||||||
|
testResultsLocation += "/";
|
||||||
|
}
|
||||||
|
|
||||||
|
QString filepath = QDir::cleanPath(testResultsLocation + filename);
|
||||||
|
QFile file(filepath);
|
||||||
|
|
||||||
|
file.open(QFile::WriteOnly);
|
||||||
|
file.write(jsonData);
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
|
|
@ -83,6 +83,11 @@ public slots:
|
||||||
*/
|
*/
|
||||||
void clearCaches();
|
void clearCaches();
|
||||||
|
|
||||||
|
/**jsdoc
|
||||||
|
* Save a JSON object to a file in the test results location
|
||||||
|
*/
|
||||||
|
void saveObject(QVariant v, const QString& filename);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool waitForCondition(qint64 maxWaitMs, std::function<bool()> condition);
|
bool waitForCondition(qint64 maxWaitMs, std::function<bool()> condition);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue