Other: fIxed GUI Tester to comply with latest gRPC changes.

This commit is contained in:
Xavier Michelon
2023-01-06 07:20:53 +01:00
parent 16aaa1b050
commit 700836aea0
10 changed files with 128 additions and 125 deletions

View File

@ -412,15 +412,7 @@ Status GRPCService::Login(ServerContext *, LoginRequest const *request, Empty *)
return Status::OK;
}
SPUser const user = randomUser();
QString const userID = user->id();
user->setUsername(QString::fromStdString(request->username()));
usersTab.userTable().append(user);
if (usersTab.nextUserAlreadyLoggedIn()) {
qtProxy_.sendDelayedEvent(newLoginAlreadyLoggedInEvent(userID));
}
qtProxy_.sendDelayedEvent(newLoginFinishedEvent(userID));
this->finishLogin();
return Status::OK;
}
@ -445,15 +437,7 @@ Status GRPCService::Login2FA(ServerContext *, LoginRequest const *request, Empty
return Status::OK;
}
SPUser const user = randomUser();
QString const userID = user->id();
user->setUsername(QString::fromStdString(request->username()));
usersTab.userTable().append(user);
if (usersTab.nextUserAlreadyLoggedIn()) {
qtProxy_.sendDelayedEvent(newLoginAlreadyLoggedInEvent(userID));
}
qtProxy_.sendDelayedEvent(newLoginFinishedEvent(userID));
this->finishLogin();
return Status::OK;
}
@ -476,15 +460,7 @@ Status GRPCService::Login2Passwords(ServerContext *, LoginRequest const *request
return Status::OK;
}
SPUser const user = randomUser();
QString const userID = user->id();
user->setUsername(QString::fromStdString(request->username()));
usersTab.userTable().append(user);
if (usersTab.nextUserAlreadyLoggedIn()) {
qtProxy_.sendDelayedEvent(newLoginAlreadyLoggedInEvent(userID));
}
qtProxy_.sendDelayedEvent(newLoginFinishedEvent(userID));
this->finishLogin();
return Status::OK;
}
@ -842,3 +818,26 @@ bool GRPCService::sendEvent(SPStreamEvent const &event) {
}
return isStreaming_;
}
//****************************************************************************************************************************************************
//
//****************************************************************************************************************************************************
void GRPCService::finishLogin() {
UsersTab &usersTab = app().mainWindow().usersTab();
SPUser user = usersTab.userWithUsername(loginUsername_);
bool const alreadyExist = user.get();
if (!user) {
user = randomUser();
user->setUsername(loginUsername_);
usersTab.userTable().append(user);
} else {
if (user->state() == EUserState::State::Connected) {
qtProxy_.sendDelayedEvent(newLoginAlreadyLoggedInEvent(user->id()));
} else {
user->setState(EUserState::State::Connected);
}
}
qtProxy_.sendDelayedEvent(newLoginFinishedEvent(user->id(), alreadyExist));
}

View File

@ -98,6 +98,9 @@ public: // member functions.
bool sendEvent(bridgepp::SPStreamEvent const &event); ///< Queue an event for sending through the event stream.
private: // member functions
void finishLogin(); ///< finish the login procedure once the credentials have been validated.
private: // data member
mutable QMutex eventStreamMutex_; ///< Mutex used to access eventQueue_, isStreaming_ and shouldStopStreaming_;
QList<bridgepp::SPStreamEvent> eventQueue_; ///< The event queue. Acces protected by eventStreamMutex_;

View File

@ -71,7 +71,7 @@ void UsersTab::onAddUserButton() {
users_.append(user);
GRPCService &grpc = app().grpc();
if (grpc.isStreaming()) {
grpc.sendEvent(newLoginFinishedEvent(user->id()));
grpc.sendEvent(newLoginFinishedEvent(user->id(), false));
}
}
@ -171,6 +171,16 @@ bridgepp::SPUser UsersTab::userWithID(QString const &userID) {
}
//****************************************************************************************************************************************************
/// \param[in] username The username.
/// \return The user with the given username.
/// \return A null pointer if the user is not in the list.
//****************************************************************************************************************************************************
bridgepp::SPUser UsersTab::userWithUsername(QString const &username) {
return users_.userWithUsername(username);
}
//****************************************************************************************************************************************************
/// \return true iff the next login attempt should trigger a username/password error.
//****************************************************************************************************************************************************
@ -235,14 +245,6 @@ bool UsersTab::nextUserTwoPasswordsAbort() const {
}
//****************************************************************************************************************************************************
/// \return true iff the next login attempt should trigger a 2nd password error with abort.
//****************************************************************************************************************************************************
bool UsersTab::nextUserAlreadyLoggedIn() const {
return ui_.checkAlreadyLoggedIn->isChecked();
}
//****************************************************************************************************************************************************
/// \return the message for the username/password error.
//****************************************************************************************************************************************************

View File

@ -38,6 +38,7 @@ public: // member functions.
UsersTab &operator=(UsersTab &&) = delete; ///< Disabled move assignment operator.
UserTable &userTable(); ///< Returns a reference to the user table.
bridgepp::SPUser userWithID(QString const &userID); ///< Get the user with the given ID.
bridgepp::SPUser userWithUsername(QString const &username); ///< Get the user with the given username.
bool nextUserUsernamePasswordError() const; ///< Check if next user login should trigger a username/password error.
bool nextUserFreeUserError() const; ///< Check if next user login should trigger a Free user error.
bool nextUserTFARequired() const; ///< Check if next user login should requires 2FA.
@ -46,7 +47,6 @@ public: // member functions.
bool nextUserTwoPasswordsRequired() const; ///< Check if next user login requires 2nd password
bool nextUserTwoPasswordsError() const; ///< Check if next user login should trigger 2nd password error.
bool nextUserTwoPasswordsAbort() const; ///< Check if next user login should trigger 2nd password abort.
bool nextUserAlreadyLoggedIn() const; ///< Check if next user login should report user as already logged in.
QString usernamePasswordErrorMessage() const; ///< Return the username password error message.
public slots:

View File

@ -170,13 +170,6 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkAlreadyLoggedIn">
<property name="text">
<string>Already logged in</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View File

@ -41,7 +41,6 @@ UserDialog::UserDialog(bridgepp::SPUser &user, QWidget *parent)
ui_.editAvatarText->setText(user_->avatarText());
this->setState(user->state());
ui_.checkSplitMode->setChecked(user_->splitMode());
ui_.checkSetupGuideSeen->setChecked(user_->setupGuideSeen());
ui_.spinUsedBytes->setValue(user->usedBytes());
ui_.spinTotalBytes->setValue(user->totalBytes());
}
@ -58,7 +57,6 @@ void UserDialog::onOK() {
user_->setAvatarText(ui_.editAvatarText->text());
user_->setState(this->state());
user_->setSplitMode(ui_.checkSplitMode->isChecked());
user_->setSetupGuideSeen(ui_.checkSetupGuideSeen->isChecked());
user_->setUsedBytes(float(ui_.spinUsedBytes->value()));
user_->setTotalBytes(float(ui_.spinTotalBytes->value()));

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>654</width>
<height>544</height>
<width>634</width>
<height>493</height>
</rect>
</property>
<property name="windowTitle">
@ -16,54 +16,18 @@
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,1,0">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="4" column="0">
<widget class="QLabel" name="labelAvatarText">
<item row="5" column="0">
<widget class="QLabel" name="labelUsedBytes">
<property name="text">
<string>Avatar Text</string>
<string>Used Bytes</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="editPassword"/>
<item row="1" column="1">
<widget class="QLineEdit" name="editUsername"/>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="editUserID">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="labelUserID">
<property name="text">
<string>UserID</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="editAvatarText"/>
</item>
<item row="3" column="1">
<widget class="QPlainTextEdit" name="editAddresses">
<property name="minimumSize">
<size>
<width>0</width>
<height>100</height>
</size>
</property>
<property name="baseSize">
<size>
<width>0</width>
<height>150</height>
</size>
</property>
<property name="tabChangesFocus">
<bool>true</bool>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QDoubleSpinBox" name="spinUsedBytes">
<item row="6" column="1">
<widget class="QDoubleSpinBox" name="spinTotalBytes">
<property name="buttonSymbols">
<enum>QAbstractSpinBox::NoButtons</enum>
</property>
@ -75,10 +39,24 @@
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="labelUsedBytes">
<item row="7" column="0">
<widget class="QLabel" name="labelTotalBytes_2">
<property name="text">
<string>Used Bytes</string>
<string>State</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="labelUserID">
<property name="text">
<string>UserID</string>
</property>
</widget>
</item>
<item row="8" column="0" colspan="2">
<widget class="QCheckBox" name="checkSplitMode">
<property name="text">
<string>Split Mode</string>
</property>
</widget>
</item>
@ -121,8 +99,15 @@
</item>
</layout>
</item>
<item row="6" column="1">
<widget class="QDoubleSpinBox" name="spinTotalBytes">
<item row="6" column="0">
<widget class="QLabel" name="labelTotalBytes">
<property name="text">
<string>Total Bytes</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QDoubleSpinBox" name="spinUsedBytes">
<property name="buttonSymbols">
<enum>QAbstractSpinBox::NoButtons</enum>
</property>
@ -151,6 +136,38 @@
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="editPassword"/>
</item>
<item row="3" column="1">
<widget class="QPlainTextEdit" name="editAddresses">
<property name="minimumSize">
<size>
<width>0</width>
<height>100</height>
</size>
</property>
<property name="baseSize">
<size>
<width>0</width>
<height>150</height>
</size>
</property>
<property name="tabChangesFocus">
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="editAvatarText"/>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="editUserID">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelUsername">
<property name="text">
@ -158,34 +175,10 @@
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="labelTotalBytes">
<item row="4" column="0">
<widget class="QLabel" name="labelAvatarText">
<property name="text">
<string>Total Bytes</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="editUsername"/>
</item>
<item row="9" column="0" colspan="2">
<widget class="QCheckBox" name="checkSetupGuideSeen">
<property name="text">
<string>Setup Guide Seen</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="labelTotalBytes_2">
<property name="text">
<string>State</string>
</property>
</widget>
</item>
<item row="8" column="0" colspan="2">
<widget class="QCheckBox" name="checkSplitMode">
<property name="text">
<string>Split Mode</string>
<string>Avatar Text</string>
</property>
</widget>
</item>
@ -249,7 +242,6 @@
<tabstop>spinUsedBytes</tabstop>
<tabstop>spinTotalBytes</tabstop>
<tabstop>checkSplitMode</tabstop>
<tabstop>checkSetupGuideSeen</tabstop>
<tabstop>buttonOK</tabstop>
<tabstop>buttonCancel</tabstop>
</tabstops>

View File

@ -149,6 +149,20 @@ bridgepp::SPUser UserTable::userWithID(QString const &userID) {
}
//****************************************************************************************************************************************************
/// \param[in] username The username.
/// \return The user with the given username.
/// \return A null pointer if the user is not in the list.
//****************************************************************************************************************************************************
bridgepp::SPUser UserTable::userWithUsername(QString const &username) {
QList<SPUser>::const_iterator it = std::find_if(users_.constBegin(), users_.constEnd(), [&username](SPUser const &user) -> bool {
return user->username() == username;
});
return it == users_.end() ? nullptr : *it;
}
//****************************************************************************************************************************************************
/// \param[in] userID The userID.
/// \return the index of the user.
@ -200,3 +214,4 @@ bool UserTable::isIndexValid(qint32 index) const {
QList<bridgepp::SPUser> UserTable::users() const {
return users_;
}

View File

@ -40,6 +40,7 @@ public: // member functions.
void append(bridgepp::SPUser const &user); ///< Append a user.
bridgepp::SPUser userAtIndex(qint32 index); ///< Return the user at the given index.
bridgepp::SPUser userWithID(QString const &userID); ///< Return the user with a given id.
bridgepp::SPUser userWithUsername(QString const &username); ///< Return the user with a given username.
qint32 indexOfUser(QString const &userID); ///< Return the index of a given User.
void touch(qint32 index); ///< touch the user at a given index (indicates it has been modified).
void remove(qint32 index); ///< Remove the user at a given index.

View File

@ -40,7 +40,7 @@ SPStreamEvent newShowMainWindowEvent(); ///< Create a new ShowMainWindowEvent ev
SPStreamEvent newLoginError(grpc::LoginErrorType error, QString const &message); ///< Create a new LoginError event.
SPStreamEvent newLoginTfaRequestedEvent(QString const &username); ///< Create a new LoginTfaRequestedEvent event.
SPStreamEvent newLoginTwoPasswordsRequestedEvent(); ///< Create a new LoginTwoPasswordsRequestedEvent event.
SPStreamEvent newLoginFinishedEvent(QString const &userID); ///< Create a new LoginFinishedEvent event.
SPStreamEvent newLoginFinishedEvent(QString const &userID, bool wasSignedOut); ///< Create a new LoginFinishedEvent event.
SPStreamEvent newLoginAlreadyLoggedInEvent(QString const &userID); ///< Create a new LoginAlreadyLoggedInEvent event.
// Update related events