mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-04 15:13:10 +02:00
Merge pull request #13154 from NissimHadar/perfTest_1
Added method to test namespace to save JSON object to a file.
This commit is contained in:
commit
574a52fdbe
4 changed files with 55 additions and 15 deletions
|
@ -735,9 +735,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);
|
||||||
|
@ -1015,7 +1015,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));
|
||||||
|
@ -1025,12 +1027,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;
|
TestScriptingInterface::getInstance()->setTestResultsLocation(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7588,7 +7591,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,
|
||||||
|
TestScriptingInterface::getInstance()->getTestResultsLocation());
|
||||||
|
|
||||||
// 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.
|
||||||
|
@ -7602,7 +7607,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,
|
||||||
|
TestScriptingInterface::getInstance()->getTestResultsLocation());
|
||||||
|
|
||||||
emit DependencyManager::get<WindowScriptingInterface>()->stillSnapshotTaken(snapshotPath, true);
|
emit DependencyManager::get<WindowScriptingInterface>()->stillSnapshotTaken(snapshotPath, true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -419,7 +419,6 @@ public slots:
|
||||||
void updateVerboseLogging();
|
void updateVerboseLogging();
|
||||||
Q_INVOKABLE void openAndroidActivity(const QString& activityName);
|
Q_INVOKABLE void openAndroidActivity(const QString& activityName);
|
||||||
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onDesktopRootItemCreated(QQuickItem* qmlContext);
|
void onDesktopRootItemCreated(QQuickItem* qmlContext);
|
||||||
void onDesktopRootContextCreated(QQmlContext* qmlContext);
|
void onDesktopRootContextCreated(QQmlContext* qmlContext);
|
||||||
|
@ -753,7 +752,6 @@ private:
|
||||||
std::atomic<bool> _pendingIdleEvent { true };
|
std::atomic<bool> _pendingIdleEvent { true };
|
||||||
std::atomic<bool> _pendingRenderEvent { true };
|
std::atomic<bool> _pendingRenderEvent { true };
|
||||||
|
|
||||||
QString testSnapshotLocation;
|
|
||||||
bool quitWhenFinished { false };
|
bool quitWhenFinished { false };
|
||||||
};
|
};
|
||||||
#endif // hifi_Application_h
|
#endif // hifi_Application_h
|
||||||
|
|
|
@ -160,3 +160,29 @@ void TestScriptingInterface::clearCaches() {
|
||||||
qApp->reloadResourceCaches();
|
qApp->reloadResourceCaches();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Writes a JSON object from javascript to a file
|
||||||
|
void TestScriptingInterface::saveObject(QVariant variant, const QString& filename) {
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
|
@ -18,6 +18,10 @@ class QScriptValue;
|
||||||
class TestScriptingInterface : public QObject {
|
class TestScriptingInterface : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
void setTestResultsLocation(const QString path) { _testResultsLocation = path; }
|
||||||
|
const QString& getTestResultsLocation() { return _testResultsLocation; };
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
static TestScriptingInterface* getInstance();
|
static TestScriptingInterface* getInstance();
|
||||||
|
|
||||||
|
@ -46,7 +50,6 @@ public slots:
|
||||||
*/
|
*/
|
||||||
void waitIdle();
|
void waitIdle();
|
||||||
|
|
||||||
|
|
||||||
bool waitForConnection(qint64 maxWaitMs = 10000);
|
bool waitForConnection(qint64 maxWaitMs = 10000);
|
||||||
|
|
||||||
void wait(int milliseconds);
|
void wait(int milliseconds);
|
||||||
|
@ -83,8 +86,14 @@ 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);
|
||||||
|
QString _testResultsLocation;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_TestScriptingInterface_h
|
#endif // hifi_TestScriptingInterface_h
|
||||||
|
|
Loading…
Reference in a new issue