mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-05-28 21:10:31 +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);
|
||||
|
||||
// Parameters used for running tests from teh command line
|
||||
const QString TEST_SCRIPT_COMMAND { "--testScript" };
|
||||
const QString TEST_QUIT_WHEN_FINISHED_OPTION { "quitWhenFinished" };
|
||||
const QString TEST_SNAPSHOT_LOCATION_COMMAND { "--testSnapshotLocation" };
|
||||
const QString TEST_SCRIPT_COMMAND{ "--testScript" };
|
||||
const QString TEST_QUIT_WHEN_FINISHED_OPTION{ "quitWhenFinished" };
|
||||
const QString TEST_RESULTS_LOCATION_COMMAND{ "--testResultsLocation" };
|
||||
|
||||
bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) {
|
||||
const char** constArgv = const_cast<const char**>(argv);
|
||||
|
@ -1014,22 +1014,25 @@ 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
|
||||
// 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));
|
||||
} else if (QFileInfo(testScriptPath).exists()) {
|
||||
setProperty(hifi::properties::TEST, QUrl::fromLocalFile(testScriptPath));
|
||||
}
|
||||
|
||||
// quite when finished parameter must directly follow the test script
|
||||
// quite when finished parameter must directly follow the test script
|
||||
if ((i + 2) < args.size() && args.at(i + 2) == TEST_QUIT_WHEN_FINISHED_OPTION) {
|
||||
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
|
||||
QString pathname(args.at(i + 1));
|
||||
QFileInfo fileInfo(pathname);
|
||||
QString path(args.at(i + 1));
|
||||
|
||||
QFileInfo fileInfo(path);
|
||||
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) {
|
||||
postLambdaEvent([notify, includeAnimated, aspectRatio, filename, this] {
|
||||
// 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 (!includeAnimated) {
|
||||
// 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) {
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -418,6 +418,7 @@ public slots:
|
|||
void updateVerboseLogging();
|
||||
Q_INVOKABLE void openAndroidActivity(const QString& activityName);
|
||||
|
||||
QString getTestResultsLocation() { return testResultsLocation; };
|
||||
|
||||
private slots:
|
||||
void onDesktopRootItemCreated(QQuickItem* qmlContext);
|
||||
|
@ -751,7 +752,7 @@ private:
|
|||
std::atomic<bool> _pendingIdleEvent { true };
|
||||
std::atomic<bool> _pendingRenderEvent { true };
|
||||
|
||||
QString testSnapshotLocation;
|
||||
QString testResultsLocation;
|
||||
bool quitWhenFinished { false };
|
||||
};
|
||||
#endif // hifi_Application_h
|
||||
|
|
|
@ -160,3 +160,30 @@ void TestScriptingInterface::clearCaches() {
|
|||
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();
|
||||
|
||||
/**jsdoc
|
||||
* Save a JSON object to a file in the test results location
|
||||
*/
|
||||
void saveObject(QVariant v, const QString& filename);
|
||||
|
||||
private:
|
||||
bool waitForCondition(qint64 maxWaitMs, std::function<bool()> condition);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue