#include "ClientTests.h" #include <QDebug> #include <algorithm> namespace test { using namespace hws; using namespace std; //------------------------------------------------------------------------ // QTest Framework Setup //------------------------------------------------------------------------ void ClientTests::initTestCase() { mHelper.mTests = this; initClient(); } void ClientTests::init() { mSession.reset(NULL); mLogInDone = false; mExecuteMethodDone = false; mMethod = ""; mPath = ""; mData.reset(NULL); mRequestError.reset(NULL); } //------------------------------------------------------------------------ // Test Methods //------------------------------------------------------------------------ void ClientTests::logIn() { mClient->logIn("jdoe", "johndoe1A!"); waitForLogIn(); QVERIFY(mSession.isNull() == false); QVERIFY(mSession->user() == "jdoe"); } void ClientTests::logInError() { mClient->logIn("jdoe", "illegal"); waitForLogIn(); QVERIFY(mRequestError->code() == RequestError::AUTHENTICATION_ERROR); } void ClientTests::listDepots() { mClient->logIn("jdoe", "johndoe1A!"); waitForLogIn(); mClient->executeMethod("GET", "/helix_versioning_engine/v78/depots"); waitForExecuteMethod(); QVERIFY(mMethod == "GET"); QVERIFY(mPath == "/helix_versioning_engine/v78/depots"); // TODO verify a depot } void ClientTests::listProjects() { mClient->addRequestConfig("HVE_PROJECTS_PATH", "//depot/main"); mClient->logIn("jdoe", "johndoe1A!"); waitForLogIn(); mClient->executeMethod("GET", "/projects/v1"); waitForExecuteMethod(); QVERIFY(mMethod == "GET"); QVERIFY(mPath == "/projects/v1"); QString projectId = "My~20Project"; bool exists = false; foreach(QVariantMap map, *mData) { if (map["value"] == projectId) { exists = true; break; } } QVERIFY2(exists, "Did not locate project"); } //------------------------------------------------------------------------ // Test Helpers //------------------------------------------------------------------------ void ClientTests::initClient() { mClient.reset(new hws::Client(this)); QString urlString = QProcessEnvironment::systemEnvironment() .value("HWS_URL", "http://localhost:9000"); mClient->setUrl(QUrl(urlString)); // This will, by default, not go through the nginx prefix path convention QString prefix = QProcessEnvironment::systemEnvironment().value("HWS_PREFIX", ""); mClient->setHWSPrefixPath(prefix); connect(mClient.data(), &hws::Client::logInDone, &mHelper, &ClientHelper::logInDone); connect(mClient.data(), &hws::Client::executeMethodDone, &mHelper, &ClientHelper::executeMethodDone); } void ClientHelper::logInDone(RequestErrorPtr err, SessionPtr session) { if (!err) { qDebug() << "session " << session->toString(); mTests->mSession = session; } else { qDebug() << "Received RequestErrorPtr" << err->messageText(); mTests->mRequestError = err; } mTests->mLogInDone = true; } void ClientHelper::executeMethodDone(hws::RequestErrorPtr error, const QString & method, const QString & path, const QSharedPointer<hws::Client::QVariantMapList> data) { if (!error) { qDebug() << method << " " << path; if (data) qDebug() << ": " << *data; mTests->mData = data; mTests->mMethod = method; mTests->mPath = path; } else { qDebug() << "Received RequestErrorPtr" << error->messageText(); mTests->mRequestError = error; } mTests->mExecuteMethodDone = true; } void ClientTests::waitForLogIn() { for (int retries = 0; !mLogInDone && retries < 50; retries++) { QTest::qWait(250); } } void ClientTests::waitForExecuteMethod() { for (int retries = 0; !mExecuteMethodDone && retries < 50; retries++) { QTest::qWait(250); } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 15741 | ptomiak | Branch HWS for my use. | ||
//guest/perforce_software/helix-web-services/main/build/helix_web_services_client_qt/test/ClientTests.cpp | |||||
#4 | 15578 | tjuricek |
Removing QSettings* usage from hws::Client. The way QSettings was being used only is relevant for one connection at a time, and, it didn't seem to work on windows nicely anyway. |
||
#3 | 15448 | tjuricek |
Qt SDK revision: remove higher-level objects from the SDK. It's likely we could add higher-level objects that adapt the executeMethodDone and convert the variant maps to something, well, typed and easier to use. That's not in my current scope of work, however. |
||
#2 | 14055 | tjuricek | Updating helix_web_services_client build for new 'my' vs 'all' projects feature | ||
#1 | 14050 | tjuricek | Prep versioned release directory for inclusion into Helix Sync app. |