forked from Silverfish/proton-bridge
feat(GODT-2791): Add Unitary test.
This commit is contained in:
committed by
Romain Le Jeune
parent
86e115b2f3
commit
2c2f816f3a
@ -294,7 +294,7 @@ private: // data members
|
|||||||
bool isInternetOn_ { true }; ///< Does bridge consider internet as on?
|
bool isInternetOn_ { true }; ///< Does bridge consider internet as on?
|
||||||
QList<QString> badEventDisplayQueue_; ///< THe queue for displaying 'bad event feedback request dialog'.
|
QList<QString> badEventDisplayQueue_; ///< THe queue for displaying 'bad event feedback request dialog'.
|
||||||
std::unique_ptr<TrayIcon> trayIcon_; ///< The tray icon for the application.
|
std::unique_ptr<TrayIcon> trayIcon_; ///< The tray icon for the application.
|
||||||
BugReportFlow reportFlow_; ///< The bug report flow.
|
bridgepp::BugReportFlow reportFlow_; ///< The bug report flow.
|
||||||
friend class AppController;
|
friend class AppController;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -190,6 +190,7 @@ enable_testing()
|
|||||||
#*****************************************************************************************************************************************************
|
#*****************************************************************************************************************************************************
|
||||||
add_executable(bridgepp-test EXCLUDE_FROM_ALL
|
add_executable(bridgepp-test EXCLUDE_FROM_ALL
|
||||||
Test/TestBridgeUtils.cpp
|
Test/TestBridgeUtils.cpp
|
||||||
|
Test/TestBugReportFlow.cpp Test/TestBugReportFlow.h
|
||||||
Test/TestCLI.cpp
|
Test/TestCLI.cpp
|
||||||
Test/TestException.cpp
|
Test/TestException.cpp
|
||||||
Test/TestSessionID.cpp
|
Test/TestSessionID.cpp
|
||||||
|
|||||||
169
internal/frontend/bridge-gui/bridgepp/Test/TestBugReportFlow.cpp
Normal file
169
internal/frontend/bridge-gui/bridgepp/Test/TestBugReportFlow.cpp
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
// Copyright (c) 2023 Proton AG
|
||||||
|
//
|
||||||
|
// This file is part of Proton Mail Bridge.
|
||||||
|
//
|
||||||
|
// Proton Mail Bridge is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Proton Mail Bridge is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Proton Mail Bridge. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "TestBugReportFlow.h"
|
||||||
|
#include <bridgepp/BugReportFlow/BugReportFlow.h>
|
||||||
|
|
||||||
|
|
||||||
|
using namespace bridgepp;
|
||||||
|
|
||||||
|
|
||||||
|
//****************************************************************************************************************************************************
|
||||||
|
//
|
||||||
|
//****************************************************************************************************************************************************
|
||||||
|
BugReportFlowFixture::BugReportFlowFixture()
|
||||||
|
: testing::Test()
|
||||||
|
, flow_()
|
||||||
|
, file_(){
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//****************************************************************************************************************************************************
|
||||||
|
//
|
||||||
|
//****************************************************************************************************************************************************
|
||||||
|
void BugReportFlowFixture::SetUp() {
|
||||||
|
Test::SetUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//****************************************************************************************************************************************************
|
||||||
|
//
|
||||||
|
//****************************************************************************************************************************************************
|
||||||
|
void BugReportFlowFixture::TearDown() {
|
||||||
|
Test::TearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//****************************************************************************************************************************************************
|
||||||
|
//
|
||||||
|
//****************************************************************************************************************************************************
|
||||||
|
void BugReportFlowFixture::feedTempFile(const QString& json) {
|
||||||
|
QJsonDocument doc = QJsonDocument().fromJson(json.toUtf8());
|
||||||
|
file_.open();
|
||||||
|
file_.write(doc.toJson());
|
||||||
|
file_.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//****************************************************************************************************************************************************
|
||||||
|
//
|
||||||
|
//****************************************************************************************************************************************************
|
||||||
|
TEST_F(BugReportFlowFixture, noFile) {
|
||||||
|
EXPECT_FALSE(flow_.parse(""));
|
||||||
|
EXPECT_EQ(flow_.categories(), QStringList());
|
||||||
|
EXPECT_EQ(flow_.questions(), QVariantList());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//****************************************************************************************************************************************************
|
||||||
|
//
|
||||||
|
//****************************************************************************************************************************************************
|
||||||
|
TEST_F(BugReportFlowFixture, emptyFile) {
|
||||||
|
feedTempFile("");
|
||||||
|
EXPECT_TRUE(flow_.parse(file_.fileName()));
|
||||||
|
EXPECT_EQ(flow_.categories(), QStringList());
|
||||||
|
EXPECT_EQ(flow_.questions(), QVariantList());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//****************************************************************************************************************************************************
|
||||||
|
//
|
||||||
|
//****************************************************************************************************************************************************
|
||||||
|
TEST_F(BugReportFlowFixture, validFile) {
|
||||||
|
feedTempFile("{"
|
||||||
|
" \"metadata\": {"
|
||||||
|
" \"version\": \"1.0.0\""
|
||||||
|
" },"
|
||||||
|
" \"data_v1.0.0\": {"
|
||||||
|
" \"categories\": ["
|
||||||
|
" {"
|
||||||
|
" \"id\": 0,"
|
||||||
|
" \"name\": \"I can't receive mail\","
|
||||||
|
" \"questions\": [0]"
|
||||||
|
" }"
|
||||||
|
" ],"
|
||||||
|
" \"questions\": ["
|
||||||
|
" {"
|
||||||
|
" \"id\": 0,"
|
||||||
|
" \"text\": \"What happened?\","
|
||||||
|
" \"tips\": \"Expected behavior\","
|
||||||
|
" \"type\": 1"
|
||||||
|
" }"
|
||||||
|
" ]"
|
||||||
|
" }"
|
||||||
|
"}");
|
||||||
|
|
||||||
|
EXPECT_TRUE(flow_.parse(file_.fileName()));
|
||||||
|
QStringList categories = flow_.categories();
|
||||||
|
QVariantList questions = flow_.questions();
|
||||||
|
EXPECT_EQ(categories.count(), 1);
|
||||||
|
EXPECT_EQ(categories[0], "I can't receive mail");
|
||||||
|
EXPECT_EQ(questions.count(), 1);
|
||||||
|
QVariantMap q1 = questions[0].toMap();
|
||||||
|
EXPECT_EQ(q1.value("id").toInt(), 0);
|
||||||
|
EXPECT_EQ(q1.value("text").toString(), "What happened?");
|
||||||
|
EXPECT_EQ(q1.value("tips").toString(), "Expected behavior");
|
||||||
|
EXPECT_EQ(q1.value("type").toInt(), 1);
|
||||||
|
|
||||||
|
QVariantList questionSet = flow_.questionSet(0);
|
||||||
|
EXPECT_EQ(questionSet.count(), 1);
|
||||||
|
EXPECT_EQ(questionSet[0].toInt(), 0);
|
||||||
|
|
||||||
|
QVariantList questionSetBad = flow_.questionSet(1);
|
||||||
|
EXPECT_EQ(questionSetBad.count(), 0);
|
||||||
|
|
||||||
|
EXPECT_TRUE(flow_.setAnswer(0, "pwet"));
|
||||||
|
EXPECT_FALSE(flow_.setAnswer(1, "pwet"));
|
||||||
|
qDebug() << flow_.collectAnswers(0);
|
||||||
|
EXPECT_EQ(flow_.collectAnswers(0), " - What happened? pwet\n\r");
|
||||||
|
EXPECT_EQ(flow_.collectAnswers(1), "");
|
||||||
|
flow_.clearAnswers();
|
||||||
|
EXPECT_EQ(flow_.collectAnswers(0), " - What happened? \n\r");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//****************************************************************************************************************************************************
|
||||||
|
//
|
||||||
|
//****************************************************************************************************************************************************
|
||||||
|
TEST_F(BugReportFlowFixture, badVersionFile) {
|
||||||
|
feedTempFile("{"
|
||||||
|
" \"metadata\": {"
|
||||||
|
" \"version\": \"1.0.1\""
|
||||||
|
" },"
|
||||||
|
" \"data_v1.0.1\": {"
|
||||||
|
" \"categories\": ["
|
||||||
|
" {"
|
||||||
|
" \"id\": 0,"
|
||||||
|
" \"name\": \"I can't receive mail\","
|
||||||
|
" \"questions\": [0]"
|
||||||
|
" }"
|
||||||
|
" ],"
|
||||||
|
" \"questions\": ["
|
||||||
|
" {"
|
||||||
|
" \"id\": 0,"
|
||||||
|
" \"text\": \"What happened?\","
|
||||||
|
" \"tips\": \"Expected behavior\","
|
||||||
|
" \"type\": 1"
|
||||||
|
" }"
|
||||||
|
" ]"
|
||||||
|
" }"
|
||||||
|
"}");
|
||||||
|
|
||||||
|
EXPECT_TRUE(flow_.parse(file_.fileName()));
|
||||||
|
EXPECT_EQ(flow_.categories(), QStringList());
|
||||||
|
EXPECT_EQ(flow_.questions(), QVariantList());
|
||||||
|
}
|
||||||
@ -0,0 +1,49 @@
|
|||||||
|
// Copyright (c) 2023 Proton AG
|
||||||
|
//
|
||||||
|
// This file is part of Proton Mail Bridge.
|
||||||
|
//
|
||||||
|
// Proton Mail Bridge is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Proton Mail Bridge is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Proton Mail Bridge. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef BRIDGEPP_TESTBUGREPORTFLOW_H
|
||||||
|
#define BRIDGEPP_TESTBUGREPORTFLOW_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <bridgepp/BugReportFlow/BugReportFlow.h>
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
|
||||||
|
//****************************************************************************************************************************************************
|
||||||
|
/// \brief Fixture class for BugReportFlow tests.
|
||||||
|
//****************************************************************************************************************************************************
|
||||||
|
class BugReportFlowFixture : public testing::Test {
|
||||||
|
public: // member functions.
|
||||||
|
BugReportFlowFixture(); ///< Default constructor.
|
||||||
|
BugReportFlowFixture(BugReportFlowFixture const &) = delete; ///< Disabled copy-constructor.
|
||||||
|
BugReportFlowFixture(BugReportFlowFixture &&) = delete; ///< Disabled assignment copy-constructor.
|
||||||
|
~BugReportFlowFixture() = default; ///< Destructor.
|
||||||
|
BugReportFlowFixture &operator=(BugReportFlowFixture const &) = delete; ///< Disabled assignment operator.
|
||||||
|
BugReportFlowFixture &operator=(BugReportFlowFixture &&) = delete; ///< Disabled move assignment operator.
|
||||||
|
|
||||||
|
protected: // member functions.
|
||||||
|
void SetUp() override; ///< Setup the fixture.
|
||||||
|
void TearDown() override; ///< Tear down the fixture.
|
||||||
|
void feedTempFile(const QString& json); ///< Feed the temp file with raw JSON.
|
||||||
|
|
||||||
|
protected: // data members
|
||||||
|
bridgepp::BugReportFlow flow_; ///< The BugReportFlow.
|
||||||
|
QTemporaryFile file_; ///< The file to be feed and parsed.
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //BRIDGEPP_TESTBUGREPORTFLOW_H
|
||||||
@ -26,6 +26,10 @@ namespace {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
namespace bridgepp {
|
||||||
|
|
||||||
|
|
||||||
//****************************************************************************************************************************************************
|
//****************************************************************************************************************************************************
|
||||||
//
|
//
|
||||||
//****************************************************************************************************************************************************
|
//****************************************************************************************************************************************************
|
||||||
@ -46,12 +50,28 @@ bool BugReportFlow::parse(const QString& filepath) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//****************************************************************************************************************************************************
|
||||||
|
/// \return The value for the 'bugCategories' property.
|
||||||
|
//****************************************************************************************************************************************************
|
||||||
|
QStringList BugReportFlow::categories() const {
|
||||||
|
return categories_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//****************************************************************************************************************************************************
|
||||||
|
/// \return The value for the 'bugQuestions' property.
|
||||||
|
//****************************************************************************************************************************************************
|
||||||
|
QVariantList BugReportFlow::questions() const {
|
||||||
|
return questions_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//****************************************************************************************************************************************************
|
//****************************************************************************************************************************************************
|
||||||
/// \param[in] categoryId The id of the bug category.
|
/// \param[in] categoryId The id of the bug category.
|
||||||
/// \return Set of question for this category.
|
/// \return Set of question for this category.
|
||||||
//****************************************************************************************************************************************************
|
//****************************************************************************************************************************************************
|
||||||
QVariantList BugReportFlow::questionSet(quint8 categoryId) const {
|
QVariantList BugReportFlow::questionSet(quint8 categoryId) const {
|
||||||
if (categoryId >= questionsSet_.count() - 1)
|
if (categoryId > questionsSet_.count() - 1)
|
||||||
return QVariantList();
|
return QVariantList();
|
||||||
return questionsSet_[categoryId];
|
return questionsSet_[categoryId];
|
||||||
};
|
};
|
||||||
@ -63,7 +83,7 @@ QVariantList BugReportFlow::questionSet(quint8 categoryId) const {
|
|||||||
/// \return true iff questionId match an existing question.
|
/// \return true iff questionId match an existing question.
|
||||||
//****************************************************************************************************************************************************
|
//****************************************************************************************************************************************************
|
||||||
bool BugReportFlow::setAnswer(quint8 questionId, QString const &answer) {
|
bool BugReportFlow::setAnswer(quint8 questionId, QString const &answer) {
|
||||||
if (questionId >= questions_.count() - 1)
|
if (questionId > questions_.count() - 1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
this->answers_[questionId] = answer;
|
this->answers_[questionId] = answer;
|
||||||
@ -91,18 +111,10 @@ QString BugReportFlow::collectAnswers(quint8 categoryId) const {
|
|||||||
|
|
||||||
|
|
||||||
//****************************************************************************************************************************************************
|
//****************************************************************************************************************************************************
|
||||||
/// \return The value for the 'bugCategories' property.
|
//
|
||||||
//****************************************************************************************************************************************************
|
//****************************************************************************************************************************************************
|
||||||
QStringList BugReportFlow::categories() const {
|
void BugReportFlow::clearAnswers() {
|
||||||
return categories_;
|
answers_.clear();
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//****************************************************************************************************************************************************
|
|
||||||
/// \return The value for the 'bugQuestions' property.
|
|
||||||
//****************************************************************************************************************************************************
|
|
||||||
QVariantList BugReportFlow::questions() const {
|
|
||||||
return questions_;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -169,4 +181,6 @@ QJsonObject BugReportFlow::migrateData(const QJsonObject& data, const QString& v
|
|||||||
return QJsonObject();
|
return QJsonObject();
|
||||||
// nothing to migrate now but migration should be done here.
|
// nothing to migrate now but migration should be done here.
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace bridgepp
|
||||||
@ -19,6 +19,9 @@
|
|||||||
#ifndef BRIDGE_GUI_BUG_REPORT_FLOW_H
|
#ifndef BRIDGE_GUI_BUG_REPORT_FLOW_H
|
||||||
#define BRIDGE_GUI_BUG_REPORT_FLOW_H
|
#define BRIDGE_GUI_BUG_REPORT_FLOW_H
|
||||||
|
|
||||||
|
namespace bridgepp {
|
||||||
|
|
||||||
|
|
||||||
//****************************************************************************************************************************************************
|
//****************************************************************************************************************************************************
|
||||||
/// \brief Bug Report Flow parser.
|
/// \brief Bug Report Flow parser.
|
||||||
//****************************************************************************************************************************************************
|
//****************************************************************************************************************************************************
|
||||||
@ -32,11 +35,14 @@ public: // member functions.
|
|||||||
|
|
||||||
bool parse(const QString& filepath); ///< Initialize the Bug Report Flow.
|
bool parse(const QString& filepath); ///< Initialize the Bug Report Flow.
|
||||||
|
|
||||||
QVariantList questionSet(quint8 categoryId) const; ///< Retrieve the set of question for a given bug category.
|
|
||||||
bool setAnswer(quint8 questionId, QString const &answer); ///< Feed an answer for a given question.
|
|
||||||
QString collectAnswers(quint8 categoryId) const; ///< Collect answer for a given set of questions.
|
|
||||||
QStringList categories() const; ///< Getter for the 'bugCategories' property.
|
QStringList categories() const; ///< Getter for the 'bugCategories' property.
|
||||||
QVariantList questions() const; ///< Getter for the 'bugQuestions' property.
|
QVariantList questions() const; ///< Getter for the 'bugQuestions' property.
|
||||||
|
QVariantList questionSet(quint8 categoryId) const; ///< Retrieve the set of question for a given bug category.
|
||||||
|
|
||||||
|
bool setAnswer(quint8 questionId, QString const &answer); ///< Feed an answer for a given question.
|
||||||
|
QString collectAnswers(quint8 categoryId) const; ///< Collect answer for a given set of questions.
|
||||||
|
void clearAnswers(); ///< Clear all collected answers.
|
||||||
|
|
||||||
|
|
||||||
private: // member functions
|
private: // member functions
|
||||||
bool parseFile(); ///< Parse the bug report flow description file.
|
bool parseFile(); ///< Parse the bug report flow description file.
|
||||||
@ -54,4 +60,6 @@ private: // data members
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace bridgepp
|
||||||
|
|
||||||
#endif // BRIDGE_GUI_BUG_REPORT_FLOW_H
|
#endif // BRIDGE_GUI_BUG_REPORT_FLOW_H
|
||||||
|
|||||||
Reference in New Issue
Block a user