Commit 6c090f86 by xiaojing.zhang

测试代码独立于开发

parents 69943f80 a423b09c
......@@ -13,7 +13,6 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
#DEFINES += FM_DEBUG
SOURCES += \
fmp_vip.cpp \
......
......@@ -17,6 +17,8 @@ FMPDataBase::FMPDataBase(QString dbname, QString connectname, QObject *parent) :
}
_db.setDatabaseName(dbname);
_isopen = _db.open();
if(!_isopen)
qDebug() << _db.lastError().databaseText();
}
FMPDataBase::~FMPDataBase()
......
......@@ -37,6 +37,7 @@ int FMNetwork::send(const QString &url, const QByteArray &reqData, QByteArray &r
_req->setHeader(QNetworkRequest::ContentLengthHeader, reqData.length());
auto reply = _nam->post(*_req, reqData);
//auto reply = _nam->get(*_req);
// 使用定时器处理超时
QEventLoop loop;
......
......@@ -2,6 +2,14 @@
#include <fmp_settings_i.h>
#include <QDebug>
#ifdef UNIT_TEST
#include <Qsettings>
#include <QApplication>
#endif
FMPVipSettings::FMPVipSettings(QObject *parent) : QObject(parent)
{
}
......@@ -12,15 +20,30 @@ FMPVipSettings *FMPVipSettings::instance()
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()
{
return _GetValue(FMP_INIKEY_VIPSERVER).toString();
}
#endif
void FMPVipSettings::init(FMPSettingsInterface *settings)
{
this->_settings = settings;
}
bool FMPVipSettings::getIsNeedSocketHeader()
{
......@@ -56,3 +79,4 @@ bool FMPVipSettings::_SetValue(const QString &key, QVariant value)
return false;
}
......@@ -5,6 +5,8 @@
#include <QVariant>
#include <fmp_logger_i.h>
class FMPSettingsInterface;
class FMPVipSettings : public QObject
......@@ -12,16 +14,15 @@ class FMPVipSettings : public QObject
Q_OBJECT
public:
static FMPVipSettings *instance();
void init(FMPSettingsInterface *settings);
QString getServerUrl();
bool getIsNeedSocketHeader();
int GetPayPartnerId();
private:
explicit FMPVipSettings(QObject *parent = 0);
public:
void init(FMPSettingsInterface *settings);
bool getIsNeedSocketHeader();
int GetPayPartnerId();
QVariant _GetValue(const QString &key, QVariant defaultValue = 0);
bool _SetValue(const QString &key, QVariant value);
......@@ -29,4 +30,7 @@ private:
FMPSettingsInterface *_settings;
};
#endif // FMP_VIP_SETTINGS_H
......@@ -6,13 +6,11 @@
TEMPLATE = lib
QT += core gui network sql concurrent
QT += core gui network sql concurrent testlib
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
DEFINES += TEST
SOURCES += \
$$PWD/backup/fmbackup.cpp \
$$PWD/backup/resend.cpp \
......
......@@ -94,7 +94,16 @@ void FMTask::showWindow()
if(_window != nullptr) {
_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) {
setError(FM_API_WINDOWCLOSE);
}
......@@ -121,8 +130,11 @@ bool FMTask::sendToServer(bool isShowMsg)
QByteArray rspData;
FMNetwork net;
qDebug()<<"send url is" << url;
qDebug() <<"send to url data is"<< data.data();
net.send(url, data, rspData);
FMP_INFO() << "Server rsponse: " << rspData.data();
// 网络错误
......
......@@ -29,6 +29,7 @@ void TaskLogin::setWindow()
void TaskLogin::packageServerReq()
{
QJsonObject code;
qDebug()<< "code" <<session()->data(PosProps.Member_sign).toString();
code[ServerProps(PosProps.Member_sign)] = session()->data(PosProps.Member_sign).toString();
serverReqJsonObj["data"] = code;
}
......@@ -79,8 +80,10 @@ void TaskLogin::onLogin()
name = "--";
}
bool canPay = (getServerJsonValue(PosProps.CanPay).toInt() == 1);
#ifdef TEST
#ifdef UNIT_TEST
canPay = true;
#endif
if(!canPay) {
......
......@@ -85,6 +85,7 @@ void TaskRefund::packagePOSRsp()
void TaskRefund::onRefundPay(int DBID)
{
qDebug()<< "PosProps.TransId "<<session()->data(PosProps.TransId).toString();
posReqJsonObj[PosProps.TransId] = session()->data(PosProps.TransId).toString();
QSharedPointer<FMItem::Pay> payPointer = DBOP::GetPayByDBId(DBID);
......
......@@ -73,37 +73,45 @@ int FMMsgWnd::_exec(InfoType type, const QString &info)
void FMMsgWnd::FailureWnd(const QString &info, QDialog *parent)
{
#ifndef UNIT_TEST
FMMsgWnd window(parent);
if(parent != nullptr) {
window.setGeometry(parent->geometry());
}
window._exec(FMMsgWnd::T_Failure, info);
#endif
}
void FMMsgWnd::WarningWnd(const QString &info, QDialog *parent)
{
#ifndef UNIT_TEST
FMMsgWnd window(parent);
if(parent != nullptr) {
window.setGeometry(parent->geometry());
}
window._exec(FMMsgWnd::T_Warning, info);
#endif
}
void FMMsgWnd::SuccessWnd(const QString &info, QDialog *parent)
{
#ifndef UNIT_TEST
FMMsgWnd window(parent);
if(parent != nullptr) {
window.setGeometry(parent->geometry());
}
window._exec(FMMsgWnd::T_Success, info);
#endif
}
void FMMsgWnd::LoginSuccess(const QString &account, const QString &name, const QString &birthday, QDialog *parent)
{
#ifndef UNIT_TEST
FMMsgWnd window(parent);
if(parent != nullptr) {
window.setGeometry(parent->geometry());
}
QString info = QString::fromLocal8Bit("账号:%1\n姓名:%2\n生日:%3").arg(account).arg(name).arg(birthday);
window._exec(FMMsgWnd::T_LoginSuccess, info);
#endif
}
int FMMsgWnd::Question(const QString &info, QDialog *parent)
......
......@@ -6,6 +6,19 @@
#include "fmloading.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) :
FMVipWnd(parent),
ui(new Ui::FMVipLogin)
......@@ -37,14 +50,20 @@ bool FMVipLogin::initWnd(Session *session)
} else {
placeText = QString::fromLocal8Bit("输入手机号/会员码/支付码");
}
ui->store_label->setText(session->data(PosProps.StoreId).toString());
ui->pos_label->setText(session->data(PosProps.PosId).toString());
ui->operator_label->setText(session->data(PosProps.OperatorId).toString());
ui->bd_label->setText(session->data(PosProps.BussinessDate).toString());
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;
}
QString FMVipLogin::getVersionInfo()
{
QByteArray versionInfo;
......@@ -87,3 +106,39 @@ void FMVipLogin::on_login_key_clicked()
_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:
Ui::FMVipLogin *ui;
FMNumPad *_numpad;
#ifdef UNIT_TEST
QString GetPayCode(); //测试的时候用于获取付款码
#endif
};
#endif // FMVIPLOGIN_H
......@@ -7,6 +7,11 @@
#include <QScrollBar>
#include <QItemSelectionModel>
#ifdef UNIT_TEST
#include <QTest>
#endif
FMVipOrder::FMVipOrder(QDialog *parent) :
FMVipWnd(parent),
ui(new Ui::FMVipOrder)
......@@ -83,6 +88,11 @@ bool FMVipOrder::initWnd(Session *session)
ui->pay_edit->setValidator(new QRegExpValidator(regexp));
ui->score_edit->setValidator(new QRegExpValidator(regexp));
setWillPayText();
#ifdef UNIT_TEST
QTest::mouseClick(ui->pay_btn,Qt::LeftButton);
#endif
return true;
}
......
......@@ -9,6 +9,9 @@
#include "items/order.h"
#include "items/pay.h"
#include "items/storeinfo.h"
#ifdef UNIT_TEST
#include <QTest>
#endif
FMVipRefund::FMVipRefund(QDialog *parent) :
FMVipWnd(parent),
......@@ -105,7 +108,9 @@ bool FMVipRefund::initWnd(Session *session)
col = 0;
}
}
#ifdef UNIT_TEST
UiAutoTest();
#endif
return true;
}
......@@ -146,3 +151,18 @@ void FMVipRefund::setIsRefundSuccess(bool 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:
bool isRefundSuccess() const;
void setIsRefundSuccess(bool isRefundSuccess);
#ifdef UNIT_TEST
void UiAutoTest();
#endif
signals:
void refundPay(int);
void refundOrder(int);
......
......@@ -5,10 +5,6 @@ include ("../../../FreemudPOS/qtservice/src/qtservice.pri")
QT += testlib sql network core gui
CONFIG += C++11
#DEFINES += UNIT_TEST
CONFIG += qt console warn_on depend_includepath testcase
CONFIG -= app_bundle
......
......@@ -15,7 +15,7 @@
ReadJsonCommand::ReadJsonCommand()
{
qDebug()<<"Test";
qDebug()<<"Test......";
}
QString ReadJsonCommand::Readjson(QString fileName)
......
......@@ -14,6 +14,7 @@
#include <ctkPluginFrameworkFactory.h>
#include <ctkPluginFramework.h>
#include <ctkPluginException.h>
#include <QByteArray>
#include <gtest/gtest.h>
#include <QString>
......@@ -24,10 +25,16 @@
#include <QTest>
using namespace testing;
class FooEnvironment: public testing::Environment
{
public:
virtual void SetUp()
{
//独立加载set模块
......@@ -63,7 +70,6 @@ class FooEnvironment: public testing::Environment
FMPVipSettings::instance()->init(svc);
printf("Environment SetUp!\n");
}
virtual void TearDown()
{
......@@ -164,7 +170,7 @@ QByteArray VipRefund()
////////////////////////////////////////////////////////////////////////
//
TEST(TestNewVip, Vip_InfoFailed)
{
DeleteLocalDB();
......@@ -172,6 +178,7 @@ TEST(TestNewVip, Vip_InfoFailed)
rspData = VipInfo();
ASSERT_FALSE(respDataDetect(rspData));
}
//设置门店信息
TEST(TestNewVip, store_Info)
{
......@@ -193,8 +200,8 @@ TEST(TestNewVip, Vip_InfoSuccess)
//付款
TEST(TestNewVip, Vip_Pay)
{
foo_env->readjson.GetPayCode();
foo_env->readjson.GetPayCode();
QByteArray rspData;
rspData = VipPay();
QString temp = foo_env->readjson.JsonValue(rspData,"paid_amount");
......
......@@ -5,7 +5,7 @@
#define VER_MINOR 1
#define VER_REVISION 0
#define VER_BUILD 38
#define VER_BUILD 39
//! Convert version numbers to string
#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