From 2a43f5fbef5baba08ce3a7acb7ed92ffe722f78e Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Mon, 12 Dec 2016 14:51:11 -0800 Subject: [PATCH] Add test mode to interface --- interface/src/Application.cpp | 158 ++++++++++-------- .../src/scripting/TestScriptingInterface.cpp | 30 ++++ .../src/scripting/TestScriptingInterface.h | 43 +++++ .../shared/src/shared/GlobalAppProperties.cpp | 1 + .../shared/src/shared/GlobalAppProperties.h | 1 + scripts/developer/tests/testTestMode.js | 15 ++ 6 files changed, 182 insertions(+), 66 deletions(-) create mode 100644 interface/src/scripting/TestScriptingInterface.cpp create mode 100644 interface/src/scripting/TestScriptingInterface.h create mode 100644 scripts/developer/tests/testTestMode.js diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 7c2eeece28..17514ac213 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -131,6 +131,7 @@ #include "LODManager.h" #include "ModelPackager.h" #include "networking/HFWebEngineProfile.h" +#include "scripting/TestScriptingInterface.h" #include "scripting/AccountScriptingInterface.h" #include "scripting/AssetMappingsScriptingInterface.h" #include "scripting/AudioDeviceScriptingInterface.h" @@ -541,6 +542,20 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo setProperty(hifi::properties::STEAM, SteamClient::isRunning()); setProperty(hifi::properties::CRASHED, _previousSessionCrashed); + { + const QString TEST_SCRIPT = "--testScript"; + const QStringList args = arguments(); + for (int i = 0; i < args.size() - 1; ++i) { + if (args.at(i) == TEST_SCRIPT) { + QString testScriptPath = args.at(i + 1); + if (QFileInfo(testScriptPath).exists()) { + setProperty(hifi::properties::TEST, QUrl::fromLocalFile(testScriptPath)); + } + } + } + } + + _runningMarker.startRunningMarker(); PluginContainer* pluginContainer = dynamic_cast(this); // set the container for any plugins that care @@ -1329,90 +1344,96 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo return entityServerNode && !isPhysicsEnabled(); }); + QVariant testProperty = property(hifi::properties::TEST); + qDebug() << testProperty; + if (testProperty.isValid()) { + auto scriptEngines = DependencyManager::get(); + const auto testScript = property(hifi::properties::TEST).toUrl(); + scriptEngines->loadScript(testScript, false); + } else { + // Get sandbox content set version, if available + auto acDirPath = PathUtils::getRootDataDirectory() + BuildInfo::MODIFIED_ORGANIZATION + "/assignment-client/"; + auto contentVersionPath = acDirPath + "content-version.txt"; + qCDebug(interfaceapp) << "Checking " << contentVersionPath << " for content version"; + auto contentVersion = 0; + QFile contentVersionFile(contentVersionPath); + if (contentVersionFile.open(QIODevice::ReadOnly | QIODevice::Text)) { + QString line = contentVersionFile.readAll(); + // toInt() returns 0 if the conversion fails, so we don't need to specifically check for failure + contentVersion = line.toInt(); + } + qCDebug(interfaceapp) << "Server content version: " << contentVersion; + bool hasTutorialContent = contentVersion >= 1; - // Get sandbox content set version, if available - auto acDirPath = PathUtils::getRootDataDirectory() + BuildInfo::MODIFIED_ORGANIZATION + "/assignment-client/"; - auto contentVersionPath = acDirPath + "content-version.txt"; - qCDebug(interfaceapp) << "Checking " << contentVersionPath << " for content version"; - auto contentVersion = 0; - QFile contentVersionFile(contentVersionPath); - if (contentVersionFile.open(QIODevice::ReadOnly | QIODevice::Text)) { - QString line = contentVersionFile.readAll(); - // toInt() returns 0 if the conversion fails, so we don't need to specifically check for failure - contentVersion = line.toInt(); - } - qCDebug(interfaceapp) << "Server content version: " << contentVersion; + Setting::Handle firstRun { Settings::firstRun, true }; + bool hasHMDAndHandControllers = PluginUtils::isHMDAvailable("OpenVR (Vive)") && PluginUtils::isHandControllerAvailable(); + Setting::Handle tutorialComplete { "tutorialComplete", false }; - bool hasTutorialContent = contentVersion >= 1; + bool shouldGoToTutorial = hasHMDAndHandControllers && hasTutorialContent && !tutorialComplete.get(); - Setting::Handle firstRun { Settings::firstRun, true }; - bool hasHMDAndHandControllers = PluginUtils::isHMDAvailable("OpenVR (Vive)") && PluginUtils::isHandControllerAvailable(); - Setting::Handle tutorialComplete { "tutorialComplete", false }; + qCDebug(interfaceapp) << "Has HMD + Hand Controllers: " << hasHMDAndHandControllers << ", current plugin: " << _displayPlugin->getName(); + qCDebug(interfaceapp) << "Has tutorial content: " << hasTutorialContent; + qCDebug(interfaceapp) << "Tutorial complete: " << tutorialComplete.get(); + qCDebug(interfaceapp) << "Should go to tutorial: " << shouldGoToTutorial; - bool shouldGoToTutorial = hasHMDAndHandControllers && hasTutorialContent && !tutorialComplete.get(); + // when --url in command line, teleport to location + const QString HIFI_URL_COMMAND_LINE_KEY = "--url"; + int urlIndex = arguments().indexOf(HIFI_URL_COMMAND_LINE_KEY); + QString addressLookupString; + if (urlIndex != -1) { + addressLookupString = arguments().value(urlIndex + 1); + } - qCDebug(interfaceapp) << "Has HMD + Hand Controllers: " << hasHMDAndHandControllers << ", current plugin: " << _displayPlugin->getName(); - qCDebug(interfaceapp) << "Has tutorial content: " << hasTutorialContent; - qCDebug(interfaceapp) << "Tutorial complete: " << tutorialComplete.get(); - qCDebug(interfaceapp) << "Should go to tutorial: " << shouldGoToTutorial; + const QString TUTORIAL_PATH = "/tutorial_begin"; - // when --url in command line, teleport to location - const QString HIFI_URL_COMMAND_LINE_KEY = "--url"; - int urlIndex = arguments().indexOf(HIFI_URL_COMMAND_LINE_KEY); - QString addressLookupString; - if (urlIndex != -1) { - addressLookupString = arguments().value(urlIndex + 1); - } - - const QString TUTORIAL_PATH = "/tutorial_begin"; - - if (shouldGoToTutorial) { - if(sandboxIsRunning) { - qCDebug(interfaceapp) << "Home sandbox appears to be running, going to Home."; - DependencyManager::get()->goToLocalSandbox(TUTORIAL_PATH); + if (shouldGoToTutorial) { + if (sandboxIsRunning) { + qCDebug(interfaceapp) << "Home sandbox appears to be running, going to Home."; + DependencyManager::get()->goToLocalSandbox(TUTORIAL_PATH); + } else { + qCDebug(interfaceapp) << "Home sandbox does not appear to be running, going to Entry."; + if (firstRun.get()) { + showHelp(); + } + if (addressLookupString.isEmpty()) { + DependencyManager::get()->goToEntry(); + } else { + DependencyManager::get()->loadSettings(addressLookupString); + } + } } else { - qCDebug(interfaceapp) << "Home sandbox does not appear to be running, going to Entry."; - if (firstRun.get()) { + + bool isFirstRun = firstRun.get(); + + if (isFirstRun) { showHelp(); } - if (addressLookupString.isEmpty()) { - DependencyManager::get()->goToEntry(); - } else { - DependencyManager::get()->loadSettings(addressLookupString); - } - } - } else { - bool isFirstRun = firstRun.get(); - - if (isFirstRun) { - showHelp(); - } - - // If this is a first run we short-circuit the address passed in - if (isFirstRun) { - if (hasHMDAndHandControllers) { - if(sandboxIsRunning) { - qCDebug(interfaceapp) << "Home sandbox appears to be running, going to Home."; - DependencyManager::get()->goToLocalSandbox(); + // If this is a first run we short-circuit the address passed in + if (isFirstRun) { + if (hasHMDAndHandControllers) { + if (sandboxIsRunning) { + qCDebug(interfaceapp) << "Home sandbox appears to be running, going to Home."; + DependencyManager::get()->goToLocalSandbox(); + } else { + qCDebug(interfaceapp) << "Home sandbox does not appear to be running, going to Entry."; + DependencyManager::get()->goToEntry(); + } } else { - qCDebug(interfaceapp) << "Home sandbox does not appear to be running, going to Entry."; DependencyManager::get()->goToEntry(); } } else { - DependencyManager::get()->goToEntry(); + qCDebug(interfaceapp) << "Not first run... going to" << qPrintable(addressLookupString.isEmpty() ? QString("previous location") : addressLookupString); + DependencyManager::get()->loadSettings(addressLookupString); } - } else { - qCDebug(interfaceapp) << "Not first run... going to" << qPrintable(addressLookupString.isEmpty() ? QString("previous location") : addressLookupString); - DependencyManager::get()->loadSettings(addressLookupString); } + + _connectionMonitor.init(); + + // After all of the constructor is completed, then set firstRun to false. + firstRun.set(false); } - - _connectionMonitor.init(); - - // After all of the constructor is completed, then set firstRun to false. - firstRun.set(false); } void Application::domainConnectionRefused(const QString& reasonMessage, int reasonCodeInt, const QString& extraInfo) { @@ -5056,6 +5077,11 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri // AvatarManager has some custom types AvatarManager::registerMetaTypes(scriptEngine); + if (property(hifi::properties::TEST).isValid()) { + scriptEngine->registerGlobalObject("Test", TestScriptingInterface::getInstance()); + } + + scriptEngine->registerGlobalObject("Overlays", &_overlays); scriptEngine->registerGlobalObject("Rates", new RatesScriptingInterface(this)); // hook our avatar and avatar hash map object into this script engine diff --git a/interface/src/scripting/TestScriptingInterface.cpp b/interface/src/scripting/TestScriptingInterface.cpp new file mode 100644 index 0000000000..46310c9e40 --- /dev/null +++ b/interface/src/scripting/TestScriptingInterface.cpp @@ -0,0 +1,30 @@ +// +// Created by Bradley Austin Davis on 2016/12/12 +// Copyright 2013-2016 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + + +#include "TestScriptingInterface.h" + +#include + +TestScriptingInterface* TestScriptingInterface::getInstance() { + static TestScriptingInterface sharedInstance; + return &sharedInstance; +} + +void TestScriptingInterface::quit() { + qApp->quit(); +} + +void TestScriptingInterface::waitForTextureIdle() { +} + +void TestScriptingInterface::waitForDownloadIdle() { +} + +void TestScriptingInterface::waitIdle() { +} diff --git a/interface/src/scripting/TestScriptingInterface.h b/interface/src/scripting/TestScriptingInterface.h new file mode 100644 index 0000000000..91277ebc78 --- /dev/null +++ b/interface/src/scripting/TestScriptingInterface.h @@ -0,0 +1,43 @@ +// +// Created by Bradley Austin Davis on 2016/12/12 +// Copyright 2013-2016 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#pragma once +#ifndef hifi_TestScriptingInterface_h +#define hifi_TestScriptingInterface_h + +#include + +class TestScriptingInterface : public QObject { + Q_OBJECT + +public slots: + static TestScriptingInterface* getInstance(); + + /**jsdoc + * Exits the application + */ + void quit(); + + /**jsdoc + * Waits for all texture transfers to be complete + */ + void waitForTextureIdle(); + + /**jsdoc + * Waits for all pending downloads to be complete + */ + void waitForDownloadIdle(); + + /**jsdoc + * Waits for all pending downloads and texture transfers to be complete + */ + void waitIdle(); + +}; + +#endif // hifi_TestScriptingInterface_h diff --git a/libraries/shared/src/shared/GlobalAppProperties.cpp b/libraries/shared/src/shared/GlobalAppProperties.cpp index 512096b86a..bfb8f744f1 100644 --- a/libraries/shared/src/shared/GlobalAppProperties.cpp +++ b/libraries/shared/src/shared/GlobalAppProperties.cpp @@ -13,6 +13,7 @@ namespace hifi { namespace properties { const char* CRASHED = "com.highfidelity.crashed"; const char* STEAM = "com.highfidelity.launchedFromSteam"; const char* LOGGER = "com.highfidelity.logger"; + const char* TEST = "com.highfidelity.test"; namespace gl { const char* BACKEND = "com.highfidelity.gl.backend"; diff --git a/libraries/shared/src/shared/GlobalAppProperties.h b/libraries/shared/src/shared/GlobalAppProperties.h index 08deeddc03..4786142a08 100644 --- a/libraries/shared/src/shared/GlobalAppProperties.h +++ b/libraries/shared/src/shared/GlobalAppProperties.h @@ -15,6 +15,7 @@ namespace hifi { namespace properties { extern const char* CRASHED; extern const char* STEAM; extern const char* LOGGER; + extern const char* TEST; namespace gl { extern const char* BACKEND; diff --git a/scripts/developer/tests/testTestMode.js b/scripts/developer/tests/testTestMode.js new file mode 100644 index 0000000000..add106ab72 --- /dev/null +++ b/scripts/developer/tests/testTestMode.js @@ -0,0 +1,15 @@ +// +// Created by Bradley Austin Davis on 2016/12/12 +// Copyright 2013-2016 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +print("Fooooo"); + +Script.setTimeout(function() { + Test.quit(); +}, 10 * 1000); + +