2019-02-13 13:03:40 +03:00
|
|
|
#include <QtTest>
|
|
|
|
#include <cp.h>
|
|
|
|
#include <sp.h>
|
|
|
|
#include <thread>
|
|
|
|
#include <quasarapp.h>
|
|
|
|
#include <QCoreApplication>
|
2019-03-02 15:35:53 +03:00
|
|
|
#include <QCryptographicHash>
|
2019-04-17 15:16:11 +03:00
|
|
|
#include <sqldbwriter.h>
|
2019-04-30 22:21:36 +03:00
|
|
|
#include <sqldbcache.h>
|
|
|
|
|
2019-04-30 16:29:36 +03:00
|
|
|
#include <snake.h>
|
2019-04-30 17:25:36 +03:00
|
|
|
#include <playerdbdata.h>
|
2019-03-02 15:35:53 +03:00
|
|
|
|
2019-03-05 00:48:32 +03:00
|
|
|
#include "factorynetobjects.h"
|
2019-02-13 13:03:40 +03:00
|
|
|
|
|
|
|
// add necessary includes here
|
|
|
|
|
|
|
|
class testSankeServer : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private:
|
|
|
|
void testPingServerProtockol();
|
2019-03-14 19:21:37 +03:00
|
|
|
void testStateServerProtockol();
|
|
|
|
void testBanServerProtockol();
|
|
|
|
void testUnBanServerProtockol();
|
|
|
|
void testRestartServerProtockol();
|
2019-02-16 17:08:00 +03:00
|
|
|
|
2019-02-13 13:03:40 +03:00
|
|
|
void testPingClientProtockol();
|
2019-03-02 15:35:53 +03:00
|
|
|
void testLogin();
|
|
|
|
void testUserData();
|
|
|
|
void testGetItem();
|
|
|
|
void testApplyData();
|
2019-04-12 17:25:17 +03:00
|
|
|
|
2019-04-30 22:21:36 +03:00
|
|
|
void testBaseSql();
|
|
|
|
void testSqlCache();
|
2019-02-13 13:03:40 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
testSankeServer();
|
2019-04-30 22:21:36 +03:00
|
|
|
|
2019-02-13 13:03:40 +03:00
|
|
|
~testSankeServer();
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void initTestCase();
|
|
|
|
void cleanupTestCase();
|
|
|
|
|
|
|
|
void testServerProtockol();
|
|
|
|
void testClientProtockol();
|
2019-04-30 22:21:36 +03:00
|
|
|
void testSql();
|
2019-04-12 17:25:17 +03:00
|
|
|
|
2019-04-14 13:06:45 +03:00
|
|
|
|
2019-02-13 13:03:40 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
testSankeServer::testSankeServer()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
testSankeServer::~testSankeServer()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void testSankeServer::initTestCase()
|
|
|
|
{
|
2019-04-29 14:39:48 +03:00
|
|
|
ClientProtocol::initClientProtockol();
|
2019-02-13 13:03:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void testSankeServer::cleanupTestCase()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void testSankeServer::testPingServerProtockol()
|
|
|
|
{
|
|
|
|
QuasarAppUtils::Params::setEnable("verbose", true);
|
|
|
|
|
|
|
|
int argc =0;
|
|
|
|
char * argv[] = {nullptr};
|
|
|
|
|
|
|
|
QCoreApplication app(argc, argv);
|
|
|
|
|
|
|
|
auto serv = new ServerProtocol::Server(this);
|
|
|
|
|
|
|
|
QVERIFY(serv->run(DEFAULT_SERVER));
|
|
|
|
|
|
|
|
auto client = new ServerProtocol::Client(this);
|
|
|
|
|
|
|
|
bool isWork = false;
|
|
|
|
QObject::connect(client, &ServerProtocol::Client::sigIncommingData,
|
|
|
|
[&isWork, &app] (const QVariantMap& map) {
|
|
|
|
|
|
|
|
isWork = map["res"].toString() == "Pong";
|
|
|
|
app.exit(0);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2019-03-10 17:30:34 +03:00
|
|
|
QVERIFY(client->ping());
|
2019-02-13 13:03:40 +03:00
|
|
|
|
|
|
|
QTimer::singleShot(1000, [&app](){
|
|
|
|
app.exit(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
app.exec();
|
|
|
|
|
|
|
|
QVERIFY(isWork);
|
|
|
|
|
|
|
|
delete serv;
|
|
|
|
delete client;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-03-14 19:21:37 +03:00
|
|
|
void testSankeServer::testStateServerProtockol()
|
|
|
|
{
|
|
|
|
ServerProtocol::Client cle;
|
|
|
|
QVERIFY(cle.getState());
|
|
|
|
}
|
|
|
|
|
|
|
|
void testSankeServer::testBanServerProtockol()
|
|
|
|
{
|
|
|
|
ServerProtocol::Client cle;
|
|
|
|
QVERIFY(!cle.ban(QHostAddress()));
|
|
|
|
|
|
|
|
QVERIFY(cle.ban(QHostAddress("192.192.192.192")));
|
|
|
|
}
|
|
|
|
|
|
|
|
void testSankeServer::testUnBanServerProtockol()
|
|
|
|
{
|
|
|
|
ServerProtocol::Client cle;
|
|
|
|
QVERIFY(!cle.unBan(QHostAddress()));
|
|
|
|
|
|
|
|
QVERIFY(cle.unBan(QHostAddress("192.192.192.192")));
|
|
|
|
}
|
|
|
|
|
|
|
|
void testSankeServer::testRestartServerProtockol()
|
|
|
|
{
|
|
|
|
ServerProtocol::Client cle;
|
|
|
|
QVERIFY(!cle.restart("lolo", 0));
|
|
|
|
|
|
|
|
QVERIFY(!cle.restart("192.168.1.999", 0));
|
|
|
|
QVERIFY(!cle.restart("192.168.1.99", 0));
|
|
|
|
QVERIFY(!cle.restart("192.168.1.9", 0));
|
|
|
|
|
|
|
|
QVERIFY(!cle.restart("-1.168.1.999", 77));
|
|
|
|
QVERIFY(!cle.restart("192.168.-1.99", 7777));
|
|
|
|
|
|
|
|
QVERIFY(cle.restart("192.168.1.9", 3456));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-02-13 13:03:40 +03:00
|
|
|
void testSankeServer::testPingClientProtockol() {
|
|
|
|
|
|
|
|
QuasarAppUtils::Params::setEnable("verbose", true);
|
|
|
|
|
|
|
|
int argc = 0;
|
|
|
|
char * argv[] = {nullptr};
|
|
|
|
|
|
|
|
QCoreApplication app(argc, argv);
|
|
|
|
|
|
|
|
auto serv = new ClientProtocol::Server(this);
|
|
|
|
|
|
|
|
QVERIFY(serv->run(LOCAL_SNAKE_SERVER, DEFAULT_SNAKE_PORT));
|
|
|
|
|
|
|
|
auto client = new ClientProtocol::Client(this);
|
|
|
|
|
|
|
|
bool isWork = false;
|
|
|
|
QObject::connect(client, &ClientProtocol::Client::sigIncommingData,
|
2019-04-29 14:39:48 +03:00
|
|
|
[&isWork, &app] (const ClientProtocol::Command cmd,
|
|
|
|
const QByteArray&) {
|
2019-02-13 13:03:40 +03:00
|
|
|
|
2019-04-29 14:39:48 +03:00
|
|
|
isWork = cmd == ClientProtocol::Command::Ping;
|
2019-02-13 13:03:40 +03:00
|
|
|
app.exit(0);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2019-03-05 11:11:46 +03:00
|
|
|
QVERIFY(client->ping());
|
2019-02-13 13:03:40 +03:00
|
|
|
|
|
|
|
QTimer::singleShot(1000, [&app](){
|
|
|
|
app.exit(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
app.exec();
|
|
|
|
|
|
|
|
QVERIFY(isWork);
|
|
|
|
|
|
|
|
delete serv;
|
|
|
|
delete client;
|
2019-02-16 17:08:00 +03:00
|
|
|
}
|
|
|
|
|
2019-03-02 15:35:53 +03:00
|
|
|
void testSankeServer::testLogin() {
|
|
|
|
ClientProtocol::Client cle;
|
|
|
|
|
2019-04-29 17:28:01 +03:00
|
|
|
auto pass = QCryptographicHash::hash("testpass", QCryptographicHash::Sha512);
|
|
|
|
QVERIFY(!cle.login("Test@gmail.com", pass));
|
|
|
|
|
|
|
|
pass = QCryptographicHash::hash("testpass", QCryptographicHash::Sha256);
|
2019-03-02 15:35:53 +03:00
|
|
|
QVERIFY(cle.login("Test@gmail.com", pass));
|
2019-02-16 17:08:00 +03:00
|
|
|
|
|
|
|
}
|
2019-02-13 13:03:40 +03:00
|
|
|
|
2019-03-02 15:35:53 +03:00
|
|
|
void testSankeServer::testUserData() {
|
|
|
|
ClientProtocol::Client cle;
|
|
|
|
|
|
|
|
QVERIFY(!cle.updateData());
|
|
|
|
|
|
|
|
auto token = QCryptographicHash::hash("testtoken", QCryptographicHash::Sha256);
|
|
|
|
cle._token = token;
|
2019-03-02 16:47:26 +03:00
|
|
|
cle._online = true;
|
2019-02-16 17:08:00 +03:00
|
|
|
|
2019-03-02 15:35:53 +03:00
|
|
|
QVERIFY(cle.updateData());
|
2019-02-16 17:08:00 +03:00
|
|
|
}
|
|
|
|
|
2019-03-02 15:35:53 +03:00
|
|
|
void testSankeServer::testGetItem() {
|
2019-03-02 16:47:26 +03:00
|
|
|
|
2019-03-02 15:35:53 +03:00
|
|
|
ClientProtocol::Client cle;
|
|
|
|
|
|
|
|
QVERIFY(!cle.updateData());
|
|
|
|
|
|
|
|
auto token = QCryptographicHash::hash("testtoken", QCryptographicHash::Sha256);
|
|
|
|
cle._token = token;
|
2019-03-02 16:47:26 +03:00
|
|
|
cle._online = true;
|
2019-03-02 15:35:53 +03:00
|
|
|
|
2019-03-02 16:47:26 +03:00
|
|
|
QVERIFY(cle.getItem(1));
|
2019-03-02 15:35:53 +03:00
|
|
|
}
|
|
|
|
|
2019-03-02 16:47:26 +03:00
|
|
|
void testSankeServer::testApplyData() {
|
|
|
|
|
2019-03-02 15:35:53 +03:00
|
|
|
ClientProtocol::Client cle;
|
|
|
|
|
|
|
|
|
|
|
|
auto token = QCryptographicHash::hash("testtoken", QCryptographicHash::Sha256);
|
|
|
|
cle._token = token;
|
2019-03-02 16:47:26 +03:00
|
|
|
cle._online = true;
|
2019-03-02 15:35:53 +03:00
|
|
|
|
2019-03-05 00:48:32 +03:00
|
|
|
QVERIFY(!cle.savaData(QList<int>()));
|
2019-03-02 15:35:53 +03:00
|
|
|
|
2019-03-05 00:48:32 +03:00
|
|
|
QList<int> listData = {1};
|
2019-02-13 13:03:40 +03:00
|
|
|
|
2019-03-05 00:48:32 +03:00
|
|
|
QVERIFY(cle.savaData(listData));
|
2019-04-20 15:22:00 +03:00
|
|
|
|
|
|
|
|
2019-02-13 13:03:40 +03:00
|
|
|
}
|
|
|
|
|
2019-04-30 22:21:36 +03:00
|
|
|
void testSankeServer::testBaseSql() {
|
2019-04-30 16:29:36 +03:00
|
|
|
SqlDBWriter db;
|
|
|
|
QFile::remove("./test.db");
|
2019-04-12 17:25:17 +03:00
|
|
|
|
2019-04-30 16:29:36 +03:00
|
|
|
bool init = db.initDb("test.db", "./");
|
2019-04-14 13:06:45 +03:00
|
|
|
|
2019-04-30 16:29:36 +03:00
|
|
|
if (!init) {
|
|
|
|
QFile::remove("./test.db");
|
|
|
|
}
|
2019-04-14 13:06:45 +03:00
|
|
|
|
2019-04-30 16:29:36 +03:00
|
|
|
QVERIFY(init);
|
2019-04-20 16:02:27 +03:00
|
|
|
|
2019-04-30 16:29:36 +03:00
|
|
|
ClientProtocol::Snake snake;
|
|
|
|
snake.setSpeed(10);
|
|
|
|
snake.setSkillet(QList<float>() << 1);
|
|
|
|
snake.setSnakeClass(0);
|
2019-04-22 13:03:30 +03:00
|
|
|
|
2019-04-15 17:12:22 +03:00
|
|
|
|
2019-04-30 16:29:36 +03:00
|
|
|
// TEST ITEM
|
2019-04-15 17:12:22 +03:00
|
|
|
|
2019-05-02 17:39:56 +03:00
|
|
|
ClientProtocol::Snake resSnake;
|
2019-04-15 17:12:22 +03:00
|
|
|
|
2019-04-30 16:29:36 +03:00
|
|
|
QVERIFY(db.saveItem(&snake) < 0);
|
|
|
|
snake.setId(0);
|
|
|
|
int id = db.saveItem(&snake);
|
2019-04-15 17:12:22 +03:00
|
|
|
|
2019-04-30 16:29:36 +03:00
|
|
|
QVERIFY(id == 0);
|
2019-04-22 13:03:30 +03:00
|
|
|
|
2019-05-02 17:39:56 +03:00
|
|
|
QVERIFY(db.getItem(id).parse(resSnake));
|
2019-04-22 13:03:30 +03:00
|
|
|
|
2019-05-02 17:39:56 +03:00
|
|
|
QVERIFY(snake.getSpeed() == resSnake.getSpeed());
|
|
|
|
QVERIFY(snake.getSkillet() == resSnake.getSkillet());
|
|
|
|
QVERIFY(snake.getSnakeClass() == resSnake.getSnakeClass());
|
|
|
|
QVERIFY(snake.getClass() == resSnake.getClass());
|
|
|
|
QVERIFY(snake.id() == resSnake.id());
|
2019-04-22 13:03:30 +03:00
|
|
|
|
2019-05-02 17:39:56 +03:00
|
|
|
resSnake.setSnakeClass(10);
|
|
|
|
QVERIFY(id == db.saveItem(Item(&resSnake)));
|
2019-04-22 13:03:30 +03:00
|
|
|
|
2019-05-02 17:39:56 +03:00
|
|
|
ClientProtocol::Snake temp;
|
|
|
|
QVERIFY(db.getItem(id).parse(temp));
|
2019-04-22 13:03:30 +03:00
|
|
|
|
2019-05-02 17:39:56 +03:00
|
|
|
QVERIFY(temp.getSnakeClass() == 10);
|
2019-04-22 13:03:30 +03:00
|
|
|
|
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
// TEST PLAYER
|
2019-04-22 13:03:30 +03:00
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
PlayerDBData player = PlayerDBData();
|
2019-04-22 13:03:30 +03:00
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
player.setMany(10);
|
|
|
|
player.setLastOnline(1000);
|
|
|
|
player.setOnlineTime(1001);
|
|
|
|
player.setName("test");
|
|
|
|
player.setGmail("test@gmail.com");
|
|
|
|
player.setCureentSnake(0);
|
2019-04-22 13:03:30 +03:00
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
QVERIFY(db.savePlayer(player) < 0);
|
|
|
|
player.setId(0);
|
2019-05-02 17:39:56 +03:00
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
QVERIFY(db.savePlayer(player) < 0);
|
|
|
|
player.setCureentSnake(-1);
|
|
|
|
id = db.savePlayer(player);
|
|
|
|
QVERIFY(id == 0);
|
2019-04-30 20:58:07 +03:00
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
QVERIFY(!db.saveowners(id, QSet<int>() << 1));
|
|
|
|
QVERIFY(db.saveowners(id, QSet<int>() << 0));
|
2019-04-30 22:21:36 +03:00
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
QSet<int> items;
|
|
|
|
QVERIFY(db.getAllItemsOfPalyer(id, items));
|
|
|
|
QVERIFY(items.contains(0));
|
|
|
|
QVERIFY(items.size() == 1);
|
2019-04-30 22:21:36 +03:00
|
|
|
|
2019-04-30 20:58:07 +03:00
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
player.setCureentSnake(0);
|
|
|
|
id = db.savePlayer(player);
|
2019-04-30 17:25:36 +03:00
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
auto resPlayer = db.getPlayer(id);
|
|
|
|
QVERIFY(resPlayer.isValid());
|
|
|
|
QVERIFY(player.getLastOnline() == resPlayer.getLastOnline());
|
|
|
|
QVERIFY(player.getMany() == resPlayer.getMany());
|
|
|
|
QVERIFY(player.getOnlineTime() == resPlayer.getOnlineTime());
|
|
|
|
QVERIFY(player.getName() == resPlayer.getName());
|
|
|
|
QVERIFY(player.getCureentSnake() == resPlayer.getCureentSnake());
|
2019-04-30 17:25:36 +03:00
|
|
|
|
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
player.setCureentSnake(3);
|
2019-04-30 17:25:36 +03:00
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
QVERIFY(db.savePlayer(player) < 0);
|
|
|
|
player.setCureentSnake(0);
|
|
|
|
player.setName("new");
|
|
|
|
QVERIFY(db.savePlayer(player) == id);
|
2019-04-22 13:03:30 +03:00
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
resPlayer = db.getPlayer(id);
|
2019-04-22 13:03:30 +03:00
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
QVERIFY(resPlayer.getName() == "new");
|
2019-04-22 13:03:30 +03:00
|
|
|
|
2019-04-30 22:21:36 +03:00
|
|
|
}
|
2019-04-22 13:03:30 +03:00
|
|
|
|
2019-04-30 22:21:36 +03:00
|
|
|
void testSankeServer::testSqlCache() {
|
2019-05-03 15:01:18 +03:00
|
|
|
SqlDBCache db;
|
2019-04-22 13:03:30 +03:00
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
QFile::remove("./test2.db");
|
2019-04-22 13:03:30 +03:00
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
bool init = db.initDb("test2.db", "./");
|
2019-04-22 13:03:30 +03:00
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
if (!init) {
|
|
|
|
QFile::remove("./test2.db");
|
|
|
|
}
|
2019-04-30 22:21:36 +03:00
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
QVERIFY(init);
|
2019-04-30 22:21:36 +03:00
|
|
|
|
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
ClientProtocol::Snake snake;
|
|
|
|
snake.setSpeed(10);
|
|
|
|
snake.setSkillet(QList<float>() << 1);
|
|
|
|
snake.setSnakeClass(0);
|
2019-04-30 22:21:36 +03:00
|
|
|
|
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
// TEST ITEM
|
2019-04-30 22:21:36 +03:00
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
ClientProtocol::Snake resSnake;
|
2019-04-30 22:21:36 +03:00
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
int id = db.saveItem(&snake);
|
2019-04-30 22:21:36 +03:00
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
QVERIFY(id == 0);
|
|
|
|
snake.setId(id);
|
2019-04-30 22:21:36 +03:00
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
QVERIFY(db.getItem(id).parse(resSnake));
|
2019-04-30 22:21:36 +03:00
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
QVERIFY(snake.getSpeed() == resSnake.getSpeed());
|
|
|
|
QVERIFY(snake.getSkillet() == resSnake.getSkillet());
|
|
|
|
QVERIFY(snake.getSnakeClass() == resSnake.getSnakeClass());
|
|
|
|
QVERIFY(snake.getClass() == resSnake.getClass());
|
|
|
|
QVERIFY(snake.id() == resSnake.id());
|
|
|
|
|
|
|
|
resSnake.setSnakeClass(10);
|
|
|
|
QVERIFY(id == db.saveItem(Item(&resSnake)));
|
2019-04-30 22:21:36 +03:00
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
ClientProtocol::Snake temp;
|
|
|
|
QVERIFY(db.getItem(id).parse(temp));
|
|
|
|
|
|
|
|
QVERIFY(temp.getSnakeClass() == 10);
|
2019-04-30 22:21:36 +03:00
|
|
|
|
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
// TEST PLAYER
|
2019-04-22 13:03:30 +03:00
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
PlayerDBData player = PlayerDBData();
|
2019-04-30 22:21:36 +03:00
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
player.setMany(10);
|
|
|
|
player.setLastOnline(1000);
|
|
|
|
player.setOnlineTime(1001);
|
|
|
|
player.setName("test");
|
|
|
|
player.setGmail("test@gmail.com");
|
|
|
|
player.setCureentSnake(0);
|
|
|
|
|
|
|
|
QVERIFY(db.savePlayer(player) < 0);
|
|
|
|
player.setId(0);
|
|
|
|
|
|
|
|
QVERIFY(db.savePlayer(player) < 0);
|
|
|
|
player.setCureentSnake(-1);
|
|
|
|
id = db.savePlayer(player);
|
|
|
|
QVERIFY(id == 0);
|
2019-04-30 22:21:36 +03:00
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
QVERIFY(!db.getItem(id, 1));
|
|
|
|
QVERIFY(db.getItem(id, 0));
|
2019-04-30 22:21:36 +03:00
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
player.setCureentSnake(0);
|
|
|
|
QVERIFY(db.savePlayer(player) == id);
|
2019-04-30 22:21:36 +03:00
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
auto resPlayer = db.getPlayer(id);
|
|
|
|
QVERIFY(resPlayer.isValid());
|
|
|
|
QVERIFY(player.getLastOnline() == resPlayer.getLastOnline());
|
|
|
|
QVERIFY(player.getMany() == resPlayer.getMany());
|
|
|
|
QVERIFY(player.getOnlineTime() == resPlayer.getOnlineTime());
|
|
|
|
QVERIFY(player.getName() == resPlayer.getName());
|
|
|
|
QVERIFY(player.getCureentSnake() == resPlayer.getCureentSnake());
|
2019-04-30 22:21:36 +03:00
|
|
|
|
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
player.setCureentSnake(3);
|
2019-04-30 22:21:36 +03:00
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
QVERIFY(db.savePlayer(player) < 0);
|
|
|
|
player.setCureentSnake(0);
|
|
|
|
player.setName("new");
|
|
|
|
QVERIFY(db.savePlayer(player) == id);
|
2019-04-30 22:21:36 +03:00
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
resPlayer = db.getPlayer(id);
|
2019-04-30 22:21:36 +03:00
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
QVERIFY(resPlayer.getName() == "new");
|
2019-04-30 22:21:36 +03:00
|
|
|
|
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
PlayerDBData second_player = PlayerDBData();
|
2019-04-30 22:21:36 +03:00
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
second_player.setMany(10);
|
|
|
|
second_player.setLastOnline(1000);
|
|
|
|
second_player.setOnlineTime(1001);
|
|
|
|
second_player.setName("test2");
|
|
|
|
second_player.setGmail("test2@gmail.com");
|
|
|
|
second_player.setCureentSnake(-1);
|
|
|
|
second_player.setId(-1);
|
2019-04-30 22:21:36 +03:00
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
QVERIFY(db.savePlayer(second_player) == 1);
|
2019-04-30 22:21:36 +03:00
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
QVERIFY(db.moveItem(0, 1, 0));
|
2019-04-30 22:21:36 +03:00
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
QSet<int> items;
|
|
|
|
QVERIFY(db.getAllItemsOfPalyer(1, items));
|
|
|
|
QVERIFY(items.contains(0));
|
|
|
|
QVERIFY(items.size() == 1);
|
2019-04-30 22:21:36 +03:00
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
db.updateInterval = 0;
|
2019-04-30 22:21:36 +03:00
|
|
|
|
2019-05-03 15:01:18 +03:00
|
|
|
db.globalUpdateDataBasePrivate(0);
|
2019-04-30 22:21:36 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void testSankeServer::testSql() {
|
|
|
|
testBaseSql();
|
|
|
|
testSqlCache();
|
2019-04-12 17:25:17 +03:00
|
|
|
}
|
|
|
|
|
2019-02-13 13:03:40 +03:00
|
|
|
void testSankeServer::testServerProtockol() {
|
|
|
|
testPingServerProtockol();
|
2019-03-14 19:21:37 +03:00
|
|
|
|
|
|
|
auto serv = new ServerProtocol::Server(this);
|
|
|
|
QVERIFY(serv->run(DEFAULT_SERVER));
|
|
|
|
testStateServerProtockol();
|
|
|
|
testBanServerProtockol();
|
|
|
|
testUnBanServerProtockol();
|
|
|
|
testRestartServerProtockol();
|
2019-02-13 13:03:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void testSankeServer::testClientProtockol() {
|
|
|
|
testPingClientProtockol();
|
2019-02-16 17:08:00 +03:00
|
|
|
|
2019-03-02 16:47:26 +03:00
|
|
|
auto serv = new ClientProtocol::Server(this);
|
|
|
|
QVERIFY(serv->run(LOCAL_SNAKE_SERVER, DEFAULT_SNAKE_PORT));
|
2019-03-09 12:30:42 +03:00
|
|
|
|
2019-03-02 15:35:53 +03:00
|
|
|
testLogin();
|
|
|
|
testGetItem();
|
|
|
|
testUserData();
|
|
|
|
testApplyData();
|
2019-02-13 13:03:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
QTEST_APPLESS_MAIN(testSankeServer)
|
|
|
|
|
|
|
|
#include "tst_testsnakeserver.moc"
|