Commit 6c090f86 by xiaojing.zhang

测试代码独立于开发

parents 69943f80 a423b09c
...@@ -13,7 +13,6 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets ...@@ -13,7 +13,6 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11 CONFIG += c++11
#DEFINES += FM_DEBUG
SOURCES += \ SOURCES += \
fmp_vip.cpp \ fmp_vip.cpp \
......
...@@ -17,6 +17,8 @@ FMPDataBase::FMPDataBase(QString dbname, QString connectname, QObject *parent) : ...@@ -17,6 +17,8 @@ FMPDataBase::FMPDataBase(QString dbname, QString connectname, QObject *parent) :
} }
_db.setDatabaseName(dbname); _db.setDatabaseName(dbname);
_isopen = _db.open(); _isopen = _db.open();
if(!_isopen)
qDebug() << _db.lastError().databaseText();
} }
FMPDataBase::~FMPDataBase() FMPDataBase::~FMPDataBase()
......
...@@ -37,6 +37,7 @@ int FMNetwork::send(const QString &url, const QByteArray &reqData, QByteArray &r ...@@ -37,6 +37,7 @@ int FMNetwork::send(const QString &url, const QByteArray &reqData, QByteArray &r
_req->setHeader(QNetworkRequest::ContentLengthHeader, reqData.length()); _req->setHeader(QNetworkRequest::ContentLengthHeader, reqData.length());
auto reply = _nam->post(*_req, reqData); auto reply = _nam->post(*_req, reqData);
//auto reply = _nam->get(*_req);
// 使用定时器处理超时 // 使用定时器处理超时
QEventLoop loop; QEventLoop loop;
......
...@@ -2,6 +2,14 @@ ...@@ -2,6 +2,14 @@
#include <fmp_settings_i.h> #include <fmp_settings_i.h>
#include <QDebug> #include <QDebug>
#ifdef UNIT_TEST
#include <Qsettings>
#include <QApplication>
#endif
FMPVipSettings::FMPVipSettings(QObject *parent) : QObject(parent) FMPVipSettings::FMPVipSettings(QObject *parent) : QObject(parent)
{ {
} }
...@@ -12,15 +20,30 @@ FMPVipSettings *FMPVipSettings::instance() ...@@ -12,15 +20,30 @@ FMPVipSettings *FMPVipSettings::instance()
return &vipSettings; return &vipSettings;
} }
void FMPVipSettings::init(FMPSettingsInterface *settings)
#ifdef UNIT_TEST
QString FMPVipSettings::getServerUrl()
{ {
this->_settings = settings; QSettings * _setting = new QSettings(qApp->applicationDirPath() + "/" + "FreemudPOS.ini", QSettings::IniFormat);
QString serverUrl = _setting->value(FMP_INIKEY_VIPSERVER, "Server").toString();
return serverUrl;
} }
#else
QString FMPVipSettings::getServerUrl() QString FMPVipSettings::getServerUrl()
{ {
return _GetValue(FMP_INIKEY_VIPSERVER).toString(); return _GetValue(FMP_INIKEY_VIPSERVER).toString();
} }
#endif
void FMPVipSettings::init(FMPSettingsInterface *settings)
{
this->_settings = settings;
}
bool FMPVipSettings::getIsNeedSocketHeader() bool FMPVipSettings::getIsNeedSocketHeader()
{ {
...@@ -56,3 +79,4 @@ bool FMPVipSettings::_SetValue(const QString &key, QVariant value) ...@@ -56,3 +79,4 @@ bool FMPVipSettings::_SetValue(const QString &key, QVariant value)
return false; return false;
} }
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#include <QVariant> #include <QVariant>
#include <fmp_logger_i.h> #include <fmp_logger_i.h>
class FMPSettingsInterface; class FMPSettingsInterface;
class FMPVipSettings : public QObject class FMPVipSettings : public QObject
...@@ -12,16 +14,15 @@ class FMPVipSettings : public QObject ...@@ -12,16 +14,15 @@ class FMPVipSettings : public QObject
Q_OBJECT Q_OBJECT
public: public:
static FMPVipSettings *instance(); static FMPVipSettings *instance();
void init(FMPSettingsInterface *settings);
QString getServerUrl(); QString getServerUrl();
bool getIsNeedSocketHeader();
int GetPayPartnerId();
private: private:
explicit FMPVipSettings(QObject *parent = 0); explicit FMPVipSettings(QObject *parent = 0);
public:
void init(FMPSettingsInterface *settings);
bool getIsNeedSocketHeader();
int GetPayPartnerId();
QVariant _GetValue(const QString &key, QVariant defaultValue = 0); QVariant _GetValue(const QString &key, QVariant defaultValue = 0);
bool _SetValue(const QString &key, QVariant value); bool _SetValue(const QString &key, QVariant value);
...@@ -29,4 +30,7 @@ private: ...@@ -29,4 +30,7 @@ private:
FMPSettingsInterface *_settings; FMPSettingsInterface *_settings;
}; };
#endif // FMP_VIP_SETTINGS_H #endif // FMP_VIP_SETTINGS_H
...@@ -6,13 +6,11 @@ ...@@ -6,13 +6,11 @@
TEMPLATE = lib TEMPLATE = lib
QT += core gui network sql concurrent QT += core gui network sql concurrent testlib
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11 CONFIG += c++11
DEFINES += TEST
SOURCES += \ SOURCES += \
$$PWD/backup/fmbackup.cpp \ $$PWD/backup/fmbackup.cpp \
$$PWD/backup/resend.cpp \ $$PWD/backup/resend.cpp \
......
...@@ -94,7 +94,16 @@ void FMTask::showWindow() ...@@ -94,7 +94,16 @@ void FMTask::showWindow()
if(_window != nullptr) { if(_window != nullptr) {
_window->initWnd(this->session()); _window->initWnd(this->session());
int ret = _window->exec(); int ret;
#ifdef UNIT_TEST
if(_FM_Type == FM_Login || _FM_Type == FM_Pay ||_FM_Type == FM_Refund )
ret = 1;
else
ret = _window->exec();
#else
ret = _window->exec();
#endif
if(ret != 1) { if(ret != 1) {
setError(FM_API_WINDOWCLOSE); setError(FM_API_WINDOWCLOSE);
} }
...@@ -121,8 +130,11 @@ bool FMTask::sendToServer(bool isShowMsg) ...@@ -121,8 +130,11 @@ bool FMTask::sendToServer(bool isShowMsg)
QByteArray rspData; QByteArray rspData;
FMNetwork net; FMNetwork net;
qDebug()<<"send url is" << url;
qDebug() <<"send to url data is"<< data.data();
net.send(url, data, rspData); net.send(url, data, rspData);
FMP_INFO() << "Server rsponse: " << rspData.data(); FMP_INFO() << "Server rsponse: " << rspData.data();
// 网络错误 // 网络错误
......
...@@ -29,6 +29,7 @@ void TaskLogin::setWindow() ...@@ -29,6 +29,7 @@ void TaskLogin::setWindow()
void TaskLogin::packageServerReq() void TaskLogin::packageServerReq()
{ {
QJsonObject code; QJsonObject code;
qDebug()<< "code" <<session()->data(PosProps.Member_sign).toString();
code[ServerProps(PosProps.Member_sign)] = session()->data(PosProps.Member_sign).toString(); code[ServerProps(PosProps.Member_sign)] = session()->data(PosProps.Member_sign).toString();
serverReqJsonObj["data"] = code; serverReqJsonObj["data"] = code;
} }
...@@ -79,8 +80,10 @@ void TaskLogin::onLogin() ...@@ -79,8 +80,10 @@ void TaskLogin::onLogin()
name = "--"; name = "--";
} }
bool canPay = (getServerJsonValue(PosProps.CanPay).toInt() == 1); bool canPay = (getServerJsonValue(PosProps.CanPay).toInt() == 1);
#ifdef TEST
#ifdef UNIT_TEST
canPay = true; canPay = true;
#endif #endif
if(!canPay) { if(!canPay) {
......
...@@ -85,6 +85,7 @@ void TaskRefund::packagePOSRsp() ...@@ -85,6 +85,7 @@ void TaskRefund::packagePOSRsp()
void TaskRefund::onRefundPay(int DBID) void TaskRefund::onRefundPay(int DBID)
{ {
qDebug()<< "PosProps.TransId "<<session()->data(PosProps.TransId).toString();
posReqJsonObj[PosProps.TransId] = session()->data(PosProps.TransId).toString(); posReqJsonObj[PosProps.TransId] = session()->data(PosProps.TransId).toString();
QSharedPointer<FMItem::Pay> payPointer = DBOP::GetPayByDBId(DBID); QSharedPointer<FMItem::Pay> payPointer = DBOP::GetPayByDBId(DBID);
......
...@@ -73,37 +73,45 @@ int FMMsgWnd::_exec(InfoType type, const QString &info) ...@@ -73,37 +73,45 @@ int FMMsgWnd::_exec(InfoType type, const QString &info)
void FMMsgWnd::FailureWnd(const QString &info, QDialog *parent) void FMMsgWnd::FailureWnd(const QString &info, QDialog *parent)
{ {
#ifndef UNIT_TEST
FMMsgWnd window(parent); FMMsgWnd window(parent);
if(parent != nullptr) { if(parent != nullptr) {
window.setGeometry(parent->geometry()); window.setGeometry(parent->geometry());
} }
window._exec(FMMsgWnd::T_Failure, info); window._exec(FMMsgWnd::T_Failure, info);
#endif
} }
void FMMsgWnd::WarningWnd(const QString &info, QDialog *parent) void FMMsgWnd::WarningWnd(const QString &info, QDialog *parent)
{ {
#ifndef UNIT_TEST
FMMsgWnd window(parent); FMMsgWnd window(parent);
if(parent != nullptr) { if(parent != nullptr) {
window.setGeometry(parent->geometry()); window.setGeometry(parent->geometry());
} }
window._exec(FMMsgWnd::T_Warning, info); window._exec(FMMsgWnd::T_Warning, info);
#endif
} }
void FMMsgWnd::SuccessWnd(const QString &info, QDialog *parent) void FMMsgWnd::SuccessWnd(const QString &info, QDialog *parent)
{ {
#ifndef UNIT_TEST
FMMsgWnd window(parent); FMMsgWnd window(parent);
if(parent != nullptr) { if(parent != nullptr) {
window.setGeometry(parent->geometry()); window.setGeometry(parent->geometry());
} }
window._exec(FMMsgWnd::T_Success, info); window._exec(FMMsgWnd::T_Success, info);
#endif
} }
void FMMsgWnd::LoginSuccess(const QString &account, const QString &name, const QString &birthday, QDialog *parent) void FMMsgWnd::LoginSuccess(const QString &account, const QString &name, const QString &birthday, QDialog *parent)
{ {
#ifndef UNIT_TEST
FMMsgWnd window(parent); FMMsgWnd window(parent);
if(parent != nullptr) { if(parent != nullptr) {
window.setGeometry(parent->geometry()); window.setGeometry(parent->geometry());
} }
QString info = QString::fromLocal8Bit("账号:%1\n姓名:%2\n生日:%3").arg(account).arg(name).arg(birthday); QString info = QString::fromLocal8Bit("账号:%1\n姓名:%2\n生日:%3").arg(account).arg(name).arg(birthday);
window._exec(FMMsgWnd::T_LoginSuccess, info); window._exec(FMMsgWnd::T_LoginSuccess, info);
#endif
} }
int FMMsgWnd::Question(const QString &info, QDialog *parent) int FMMsgWnd::Question(const QString &info, QDialog *parent)
......
...@@ -6,6 +6,19 @@ ...@@ -6,6 +6,19 @@
#include "fmloading.h" #include "fmloading.h"
#include "fmnumpad.h" #include "fmnumpad.h"
#ifdef UNIT_TEST
#include <QTest>
#include <QEventLoop>
#include <QJsonDocument>
#include <QJsonParseError>
#include <QJsonObject>
#include <QNetworkAccessManager>
#include <QUrl>
#include <QNetworkReply>
#include <QNetworkRequest>
#endif
FMVipLogin::FMVipLogin(QDialog *parent) : FMVipLogin::FMVipLogin(QDialog *parent) :
FMVipWnd(parent), FMVipWnd(parent),
ui(new Ui::FMVipLogin) ui(new Ui::FMVipLogin)
...@@ -37,14 +50,20 @@ bool FMVipLogin::initWnd(Session *session) ...@@ -37,14 +50,20 @@ bool FMVipLogin::initWnd(Session *session)
} else { } else {
placeText = QString::fromLocal8Bit("输入手机号/会员码/支付码"); placeText = QString::fromLocal8Bit("输入手机号/会员码/支付码");
} }
ui->store_label->setText(session->data(PosProps.StoreId).toString()); ui->store_label->setText(session->data(PosProps.StoreId).toString());
ui->pos_label->setText(session->data(PosProps.PosId).toString()); ui->pos_label->setText(session->data(PosProps.PosId).toString());
ui->operator_label->setText(session->data(PosProps.OperatorId).toString()); ui->operator_label->setText(session->data(PosProps.OperatorId).toString());
ui->bd_label->setText(session->data(PosProps.BussinessDate).toString()); ui->bd_label->setText(session->data(PosProps.BussinessDate).toString());
ui->login_edit->setPlaceholderText(placeText); ui->login_edit->setPlaceholderText(placeText);
#ifdef UNIT_TEST
QString paycode = GetPayCode();
QTest::keyClicks(ui->login_edit, paycode);
QTest::mouseClick(ui->login_btn,Qt::LeftButton);
#endif
return true; return true;
} }
QString FMVipLogin::getVersionInfo() QString FMVipLogin::getVersionInfo()
{ {
QByteArray versionInfo; QByteArray versionInfo;
...@@ -87,3 +106,39 @@ void FMVipLogin::on_login_key_clicked() ...@@ -87,3 +106,39 @@ void FMVipLogin::on_login_key_clicked()
_numpad->exec(); _numpad->exec();
} }
} }
#ifdef UNIT_TEST
QString FMVipLogin::GetPayCode()
{
QNetworkAccessManager networkAcessManager;
QNetworkRequest _req;
QString codeFormat;
QString url = "http://membertest1.sandload.cn:8748/wechat/card/getPayCode?partnerId=7f657d18-9f3f-41fd-b97f-1a71f7d1ffa0&openId=o4_93jjwHWPke-U1IT2IkUO5hbII&mobile=15821343897&URL=http%3A%2F%2Fjtest.sandload.cn";
_req.setUrl(url);
auto reply = networkAcessManager.get(_req);
QEventLoop loop;
connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec();
QByteArray rspData= reply->readAll();
qDebug()<<"reply get "<<rspData;
QJsonParseError jsonErr;
QJsonDocument rspJson = QJsonDocument::fromJson(rspData, &jsonErr);
//QJsonObject serverRspJsonObj;
if(jsonErr.error == QJsonParseError::NoError) {
//serverRspJsonObj = rspJson.object();
if(rspJson.isObject())
{
QVariantMap result = rspJson.toVariant().toMap();
QVariantMap nestedMap = result["data"].toMap();
codeFormat = nestedMap["codeFormat"].toString();
codeFormat.remove(QRegExp("\\s"));
qDebug() << "length:" << codeFormat;
}
}
return codeFormat;
}
#endif
...@@ -34,6 +34,8 @@ private: ...@@ -34,6 +34,8 @@ private:
Ui::FMVipLogin *ui; Ui::FMVipLogin *ui;
FMNumPad *_numpad; FMNumPad *_numpad;
#ifdef UNIT_TEST
QString GetPayCode(); //测试的时候用于获取付款码
#endif
}; };
#endif // FMVIPLOGIN_H #endif // FMVIPLOGIN_H
...@@ -7,6 +7,11 @@ ...@@ -7,6 +7,11 @@
#include <QScrollBar> #include <QScrollBar>
#include <QItemSelectionModel> #include <QItemSelectionModel>
#ifdef UNIT_TEST
#include <QTest>
#endif
FMVipOrder::FMVipOrder(QDialog *parent) : FMVipOrder::FMVipOrder(QDialog *parent) :
FMVipWnd(parent), FMVipWnd(parent),
ui(new Ui::FMVipOrder) ui(new Ui::FMVipOrder)
...@@ -83,6 +88,11 @@ bool FMVipOrder::initWnd(Session *session) ...@@ -83,6 +88,11 @@ bool FMVipOrder::initWnd(Session *session)
ui->pay_edit->setValidator(new QRegExpValidator(regexp)); ui->pay_edit->setValidator(new QRegExpValidator(regexp));
ui->score_edit->setValidator(new QRegExpValidator(regexp)); ui->score_edit->setValidator(new QRegExpValidator(regexp));
setWillPayText(); setWillPayText();
#ifdef UNIT_TEST
QTest::mouseClick(ui->pay_btn,Qt::LeftButton);
#endif
return true; return true;
} }
......
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
#include "items/order.h" #include "items/order.h"
#include "items/pay.h" #include "items/pay.h"
#include "items/storeinfo.h" #include "items/storeinfo.h"
#ifdef UNIT_TEST
#include <QTest>
#endif
FMVipRefund::FMVipRefund(QDialog *parent) : FMVipRefund::FMVipRefund(QDialog *parent) :
FMVipWnd(parent), FMVipWnd(parent),
...@@ -105,7 +108,9 @@ bool FMVipRefund::initWnd(Session *session) ...@@ -105,7 +108,9 @@ bool FMVipRefund::initWnd(Session *session)
col = 0; col = 0;
} }
} }
#ifdef UNIT_TEST
UiAutoTest();
#endif
return true; return true;
} }
...@@ -146,3 +151,18 @@ void FMVipRefund::setIsRefundSuccess(bool isRefundSuccess) ...@@ -146,3 +151,18 @@ void FMVipRefund::setIsRefundSuccess(bool isRefundSuccess)
{ {
_isRefundSuccess = isRefundSuccess; _isRefundSuccess = isRefundSuccess;
} }
//测试程序自动退款时退最近的一笔
#ifdef UNIT_TEST
void FMVipRefund::UiAutoTest()
{
int rows = ui->tableWidget_pays->rowCount();
ui->tableWidget_pays->setCurrentCell(rows-1, QItemSelectionModel::Select);
QWidget* cell= ui->tableWidget_pays->cellWidget(rows-1,3);
QPushButton* button = dynamic_cast<QPushButton*>(cell);
QTest::mouseClick(button,Qt::LeftButton);
QTest::mouseClick(ui->close_btn,Qt::LeftButton);
}
#endif
...@@ -28,6 +28,11 @@ public: ...@@ -28,6 +28,11 @@ public:
bool isRefundSuccess() const; bool isRefundSuccess() const;
void setIsRefundSuccess(bool isRefundSuccess); void setIsRefundSuccess(bool isRefundSuccess);
#ifdef UNIT_TEST
void UiAutoTest();
#endif
signals: signals:
void refundPay(int); void refundPay(int);
void refundOrder(int); void refundOrder(int);
......
...@@ -5,10 +5,6 @@ include ("../../../FreemudPOS/qtservice/src/qtservice.pri") ...@@ -5,10 +5,6 @@ include ("../../../FreemudPOS/qtservice/src/qtservice.pri")
QT += testlib sql network core gui QT += testlib sql network core gui
CONFIG += C++11 CONFIG += C++11
#DEFINES += UNIT_TEST
CONFIG += qt console warn_on depend_includepath testcase CONFIG += qt console warn_on depend_includepath testcase
CONFIG -= app_bundle CONFIG -= app_bundle
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
ReadJsonCommand::ReadJsonCommand() ReadJsonCommand::ReadJsonCommand()
{ {
qDebug()<<"Test"; qDebug()<<"Test......";
} }
QString ReadJsonCommand::Readjson(QString fileName) QString ReadJsonCommand::Readjson(QString fileName)
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <ctkPluginFrameworkFactory.h> #include <ctkPluginFrameworkFactory.h>
#include <ctkPluginFramework.h> #include <ctkPluginFramework.h>
#include <ctkPluginException.h> #include <ctkPluginException.h>
#include <QByteArray> #include <QByteArray>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <QString> #include <QString>
...@@ -24,10 +25,16 @@ ...@@ -24,10 +25,16 @@
#include <QTest> #include <QTest>
using namespace testing;
class FooEnvironment: public testing::Environment class FooEnvironment: public testing::Environment
{ {
public: public:
virtual void SetUp() virtual void SetUp()
{ {
//独立加载set模块 //独立加载set模块
...@@ -63,7 +70,6 @@ class FooEnvironment: public testing::Environment ...@@ -63,7 +70,6 @@ class FooEnvironment: public testing::Environment
FMPVipSettings::instance()->init(svc); FMPVipSettings::instance()->init(svc);
printf("Environment SetUp!\n"); printf("Environment SetUp!\n");
} }
virtual void TearDown() virtual void TearDown()
{ {
...@@ -164,7 +170,7 @@ QByteArray VipRefund() ...@@ -164,7 +170,7 @@ QByteArray VipRefund()
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
//
TEST(TestNewVip, Vip_InfoFailed) TEST(TestNewVip, Vip_InfoFailed)
{ {
DeleteLocalDB(); DeleteLocalDB();
...@@ -172,6 +178,7 @@ TEST(TestNewVip, Vip_InfoFailed) ...@@ -172,6 +178,7 @@ TEST(TestNewVip, Vip_InfoFailed)
rspData = VipInfo(); rspData = VipInfo();
ASSERT_FALSE(respDataDetect(rspData)); ASSERT_FALSE(respDataDetect(rspData));
} }
//设置门店信息 //设置门店信息
TEST(TestNewVip, store_Info) TEST(TestNewVip, store_Info)
{ {
...@@ -193,8 +200,8 @@ TEST(TestNewVip, Vip_InfoSuccess) ...@@ -193,8 +200,8 @@ TEST(TestNewVip, Vip_InfoSuccess)
//付款 //付款
TEST(TestNewVip, Vip_Pay) TEST(TestNewVip, Vip_Pay)
{ {
foo_env->readjson.GetPayCode();
foo_env->readjson.GetPayCode();
QByteArray rspData; QByteArray rspData;
rspData = VipPay(); rspData = VipPay();
QString temp = foo_env->readjson.JsonValue(rspData,"paid_amount"); QString temp = foo_env->readjson.JsonValue(rspData,"paid_amount");
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#define VER_MINOR 1 #define VER_MINOR 1
#define VER_REVISION 0 #define VER_REVISION 0
#define VER_BUILD 38 #define VER_BUILD 39
//! Convert version numbers to string //! Convert version numbers to string
#define _STR(S) #S #define _STR(S) #S
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment