commit
050dfa1bf8
19 changed files with 464 additions and 89 deletions
|
|
@ -8,7 +8,7 @@ typedef unsigned long long entity_id;
|
|||
|
||||
class IEntity : public ISerializable {
|
||||
public:
|
||||
virtual entity_id id() = 0;
|
||||
virtual entity_id id() const = 0;
|
||||
};
|
||||
|
||||
#endif // IENTITY_H
|
||||
|
|
|
|||
|
|
@ -8,15 +8,15 @@ cargo_entity::cargo_entity(const QString &title, unsigned int volume) : _title(t
|
|||
}
|
||||
}
|
||||
|
||||
entity_id cargo_entity::id() {
|
||||
entity_id cargo_entity::id() const {
|
||||
return this->_id;
|
||||
}
|
||||
|
||||
QString cargo_entity::title() {
|
||||
QString cargo_entity::title() const {
|
||||
return this->_title;
|
||||
}
|
||||
|
||||
unsigned int cargo_entity::volume() {
|
||||
unsigned int cargo_entity::volume() const {
|
||||
return this->_volume;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,9 +17,9 @@ public:
|
|||
cargo_entity() = default;
|
||||
cargo_entity(const QString &title, unsigned int volume);
|
||||
|
||||
entity_id id();
|
||||
QString title();
|
||||
unsigned int volume();
|
||||
entity_id id() const;
|
||||
QString title() const;
|
||||
unsigned int volume() const;
|
||||
|
||||
void serialize(QDataStream &output);
|
||||
void deserialize(QDataStream &input);
|
||||
|
|
|
|||
|
|
@ -8,11 +8,11 @@ dpoint_entity::dpoint_entity(const QString &title) : _title(title) {
|
|||
}
|
||||
}
|
||||
|
||||
entity_id dpoint_entity::id() {
|
||||
entity_id dpoint_entity::id() const {
|
||||
return this->_id;
|
||||
}
|
||||
|
||||
QString dpoint_entity::title() {
|
||||
QString dpoint_entity::title() const {
|
||||
return this->_title;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ public:
|
|||
dpoint_entity() = default;
|
||||
dpoint_entity(const QString &title);
|
||||
|
||||
entity_id id();
|
||||
QString title();
|
||||
entity_id id() const;
|
||||
QString title() const;
|
||||
const QVector<storage_entity> storages();
|
||||
|
||||
void serialize(QDataStream &output);
|
||||
|
|
|
|||
|
|
@ -8,11 +8,11 @@ storage_entity::storage_entity(unsigned int capacity) : _capacity(capacity) {
|
|||
}
|
||||
|
||||
|
||||
entity_id storage_entity::id() {
|
||||
entity_id storage_entity::id() const {
|
||||
return this->_id;
|
||||
}
|
||||
|
||||
unsigned int storage_entity::capacity() {
|
||||
unsigned int storage_entity::capacity() const {
|
||||
return this->_capacity;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ public:
|
|||
storage_entity() = default;
|
||||
storage_entity(unsigned int capacity);
|
||||
|
||||
entity_id id();
|
||||
unsigned int capacity();
|
||||
entity_id id() const;
|
||||
unsigned int capacity() const;
|
||||
const QVector<cargo_entity> cargo();
|
||||
|
||||
void add_cargo(cargo_entity object, bool &success);
|
||||
|
|
|
|||
|
|
@ -4,15 +4,15 @@ user_entity::user_entity(const QString &login, const QString &password, UserRole
|
|||
this->_pwd_hash = QCryptographicHash::hash(password.toLocal8Bit(), QCryptographicHash::Sha3_256);
|
||||
}
|
||||
|
||||
entity_id user_entity::id() {
|
||||
entity_id user_entity::id() const {
|
||||
return this->_id;
|
||||
}
|
||||
|
||||
const QString user_entity::login() {
|
||||
const QString user_entity::login() const {
|
||||
return this->_login;
|
||||
}
|
||||
|
||||
UserRole user_entity::role() {
|
||||
UserRole user_entity::role() const {
|
||||
return this->_role;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,9 +23,9 @@ public:
|
|||
user_entity() = default;
|
||||
user_entity(const QString &login, const QString &password, UserRole role);
|
||||
|
||||
entity_id id();
|
||||
const QString login();
|
||||
UserRole role();
|
||||
entity_id id() const;
|
||||
const QString login() const;
|
||||
UserRole role() const;
|
||||
bool verify_password(const QString &password) const;
|
||||
|
||||
void serialize(QDataStream &output);
|
||||
|
|
|
|||
|
|
@ -7,15 +7,15 @@ vessel_entity::vessel_entity(const dpoint_entity &harbor, unsigned int capacity)
|
|||
this->_id = ++vessel_entity::__global_id;
|
||||
}
|
||||
|
||||
entity_id vessel_entity::id() {
|
||||
entity_id vessel_entity::id() const {
|
||||
return this->_id;
|
||||
}
|
||||
|
||||
const dpoint_entity vessel_entity::harbor() {
|
||||
const dpoint_entity vessel_entity::harbor() const {
|
||||
return this->_harbor;
|
||||
}
|
||||
|
||||
unsigned int vessel_entity::capacity() {
|
||||
unsigned int vessel_entity::capacity() const {
|
||||
return this->_capacity;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@ public:
|
|||
vessel_entity() = default;
|
||||
vessel_entity(const dpoint_entity &harbor, unsigned int capacity);
|
||||
|
||||
entity_id id();
|
||||
const dpoint_entity harbor();
|
||||
unsigned int capacity();
|
||||
entity_id id() const;
|
||||
const dpoint_entity harbor() const;
|
||||
unsigned int capacity() const;
|
||||
const QVector<cargo_entity> cargo();
|
||||
|
||||
void serialize(QDataStream &output);
|
||||
|
|
|
|||
|
|
@ -4,16 +4,9 @@
|
|||
apparatus *apparatus::_instance = nullptr;
|
||||
const QString apparatus::filename = "data.bin";
|
||||
|
||||
void apparatus::open_reading_stream() {
|
||||
void apparatus::open_stream() {
|
||||
this->_bin_file = new QFile(apparatus::filename);
|
||||
this->_bin_file->open(QIODevice::ReadOnly);
|
||||
|
||||
stream.setDevice(_bin_file);
|
||||
}
|
||||
|
||||
void apparatus::open_writing_stream() {
|
||||
this->_bin_file = new QFile(apparatus::filename);
|
||||
this->_bin_file->open(QIODevice::WriteOnly);
|
||||
this->_bin_file->open(QIODevice::ReadWrite);
|
||||
|
||||
stream.setDevice(_bin_file);
|
||||
}
|
||||
|
|
@ -27,35 +20,27 @@ void apparatus::close_stream() {
|
|||
}
|
||||
|
||||
apparatus::apparatus() {
|
||||
this->open_reading_stream();
|
||||
this->loadGIDS();
|
||||
this->deserialize_data();
|
||||
this->close_stream();
|
||||
|
||||
}
|
||||
|
||||
apparatus::~apparatus() {
|
||||
if (this->_bin_file) {
|
||||
this->_bin_file->flush();
|
||||
this->_bin_file->close();
|
||||
delete this->_bin_file;
|
||||
this->_bin_file = nullptr;
|
||||
}
|
||||
this->shutdown();
|
||||
}
|
||||
|
||||
apparatus& apparatus::instance() {
|
||||
apparatus* apparatus::instance() {
|
||||
if (apparatus::_instance == nullptr) {
|
||||
apparatus::init();
|
||||
throw std::runtime_error("System non initialized!");
|
||||
}
|
||||
|
||||
return *apparatus::_instance;
|
||||
return apparatus::_instance;
|
||||
}
|
||||
|
||||
bool apparatus::isFirstRun() {
|
||||
return QFile(apparatus::filename).exists();
|
||||
return QFile().exists("init");
|
||||
}
|
||||
|
||||
void apparatus::generate_empty_data() {
|
||||
this->open_writing_stream();
|
||||
this->open_stream();
|
||||
this->writeGIDS();
|
||||
this->serialize_data();
|
||||
this->close_stream();
|
||||
|
|
@ -71,15 +56,18 @@ const object_system& apparatus::get_object_subsystem() {
|
|||
|
||||
void apparatus::init() {
|
||||
apparatus::_instance = new apparatus();
|
||||
|
||||
apparatus::instance()->open_stream();
|
||||
apparatus::instance()->loadGIDS();
|
||||
apparatus::instance()->deserialize_data();
|
||||
apparatus::instance()->close_stream();
|
||||
}
|
||||
|
||||
void apparatus::shutdown() {
|
||||
if (apparatus::_instance != nullptr) {
|
||||
apparatus::_instance->open_writing_stream();
|
||||
apparatus::_instance->writeGIDS();
|
||||
apparatus::_instance->serialize_data();
|
||||
apparatus::_instance->close_stream();
|
||||
}
|
||||
apparatus::instance()->open_stream();
|
||||
apparatus::instance()->writeGIDS();
|
||||
apparatus::instance()->serialize_data();
|
||||
apparatus::instance()->close_stream();
|
||||
}
|
||||
|
||||
void apparatus::writeGIDS() {
|
||||
|
|
@ -101,6 +89,7 @@ void apparatus::serialize_data() {
|
|||
}
|
||||
|
||||
void apparatus::deserialize_data() {
|
||||
QFile("init").open(QIODevice::ReadWrite);
|
||||
this->_auth_system.shutdown(this->stream);
|
||||
this->_object_system.shutdown(this->stream);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,13 +4,13 @@
|
|||
#include "auth_system.h"
|
||||
#include "object_system.h"
|
||||
|
||||
#include "../entities/vessel_entity.h"
|
||||
#include "../entities/storage_entity.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QFile>
|
||||
#include <QDataStream>
|
||||
|
||||
#include <entities/vessel_entity.h>
|
||||
#include <entities/storage_entity.h>
|
||||
|
||||
|
||||
class apparatus
|
||||
{
|
||||
|
|
@ -24,8 +24,7 @@ private:
|
|||
auth_system _auth_system;
|
||||
object_system _object_system;
|
||||
|
||||
void open_reading_stream();
|
||||
void open_writing_stream();
|
||||
void open_stream();
|
||||
void close_stream();
|
||||
|
||||
void writeGIDS();
|
||||
|
|
@ -43,7 +42,7 @@ public:
|
|||
const auth_system& get_auth_subsystem();
|
||||
const object_system& get_object_subsystem();
|
||||
|
||||
static apparatus& instance();
|
||||
static apparatus* instance();
|
||||
static void init();
|
||||
static void shutdown();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include<QVector>
|
||||
|
||||
#include <entities/user_entity.h>
|
||||
#include "../entities/user_entity.h"
|
||||
|
||||
|
||||
class auth_system
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
#include <QVector>
|
||||
|
||||
#include <entities/dpoint_entity.h>
|
||||
#include <entities/vessel_entity.h>
|
||||
#include "../entities/dpoint_entity.h"
|
||||
#include "../entities/vessel_entity.h"
|
||||
|
||||
|
||||
class object_system
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
TEMPLATE = subdirs
|
||||
|
||||
SUBDIRS += \
|
||||
sea_transport
|
||||
sea_transport \
|
||||
st_test
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 4.13.3, 2020-12-18T19:15:03. -->
|
||||
<!-- Written by QtCreator 4.13.3, 2020-12-18T19:53:31. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
|
|
@ -19,7 +19,7 @@
|
|||
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0">
|
||||
<value type="QString" key="language">Cpp</value>
|
||||
<valuemap type="QVariantMap" key="value">
|
||||
<value type="QByteArray" key="CurrentPreferences">CppGlobal</value>
|
||||
<value type="QByteArray" key="CurrentPreferences">qt2</value>
|
||||
</valuemap>
|
||||
</valuemap>
|
||||
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.1">
|
||||
|
|
@ -65,24 +65,20 @@
|
|||
<value type="bool" key="AutoTest.Framework.QtTest">true</value>
|
||||
</valuemap>
|
||||
<valuemap type="QVariantMap" key="AutoTest.CheckStates">
|
||||
<value type="Qt::CheckState" key="C:/Users/Admin/Documents/repos/sea_transport/tests/tst_tests.cpp:apparatus_auth_subsystem_check">Checked</value>
|
||||
<value type="Qt::CheckState" key="C:/Users/Admin/Documents/repos/sea_transport/tests/tst_tests.cpp:apparatus_data_serialization">Checked</value>
|
||||
<value type="Qt::CheckState" key="C:/Users/Admin/Documents/repos/sea_transport/tests/tst_tests.cpp:apparatus_firstrun">Checked</value>
|
||||
<value type="Qt::CheckState" key="C:/Users/Admin/Documents/repos/sea_transport/tests/tst_tests.cpp:apparatus_object_subsystem_check">Checked</value>
|
||||
<value type="Qt::CheckState" key="C:/Users/Admin/Documents/repos/sea_transport/tests/tst_tests.cpp:auth_password_validation">Checked</value>
|
||||
<value type="Qt::CheckState" key="C:/Users/Admin/Documents/repos/sea_transport/tests/tst_tests.cpp:auth_user_manipulation">Checked</value>
|
||||
<value type="Qt::CheckState" key="C:/Users/Admin/Documents/repos/sea_transport/tests/tst_tests.cpp:auth_user_query">Checked</value>
|
||||
<value type="Qt::CheckState" key="C:/Users/Admin/Documents/repos/sea_transport/tests/tst_tests.cpp:cargo_entity_check">Checked</value>
|
||||
<value type="Qt::CheckState" key="C:/Users/Admin/Documents/repos/sea_transport/tests/tst_tests.cpp:dpoint_entity_check">Checked</value>
|
||||
<value type="Qt::CheckState" key="C:/Users/Admin/Documents/repos/sea_transport/tests/tst_tests.cpp:object_manipulation">Checked</value>
|
||||
<value type="Qt::CheckState" key="C:/Users/Admin/Documents/repos/sea_transport/tests/tst_tests.cpp:object_query">Checked</value>
|
||||
<value type="Qt::CheckState" key="C:/Users/Admin/Documents/repos/sea_transport/tests/tst_tests.cpp:storage_entity_check">Checked</value>
|
||||
<value type="Qt::CheckState" key="C:/Users/Admin/Documents/repos/sea_transport/tests/tst_tests.cpp:tests">Checked</value>
|
||||
<value type="Qt::CheckState" key="C:/Users/Admin/Documents/repos/sea_transport/tests/tst_tests.cpp:user_entity_check">Checked</value>
|
||||
<value type="Qt::CheckState" key="C:/Users/Admin/Documents/repos/sea_transport/tests/tst_tests.cpp:vessel_entity_check">Checked</value>
|
||||
<value type="Qt::CheckState" key="C:/Users/Admin/Documents/repos/sea_transport_project/st_test/tst_st_test.cpp:cargo_entity_serialization_test">Checked</value>
|
||||
<value type="Qt::CheckState" key="C:/Users/Admin/Documents/repos/sea_transport_project/st_test/tst_st_test.cpp:dpoint_entity_serialization_test">Checked</value>
|
||||
<value type="Qt::CheckState" key="C:/Users/Admin/Documents/repos/sea_transport_project/st_test/tst_st_test.cpp:st_test">Checked</value>
|
||||
<value type="Qt::CheckState" key="C:/Users/Admin/Documents/repos/sea_transport_project/st_test/tst_st_test.cpp:storage_entity_serialization_test">Checked</value>
|
||||
<value type="Qt::CheckState" key="C:/Users/Admin/Documents/repos/sea_transport_project/st_test/tst_st_test.cpp:user_entity_serialization_test">Checked</value>
|
||||
<value type="Qt::CheckState" key="C:/Users/Admin/Documents/repos/sea_transport_project/st_test/tst_st_test.cpp:vessel_entity_serialization_test">Checked</value>
|
||||
</valuemap>
|
||||
<value type="int" key="AutoTest.RunAfterBuild">0</value>
|
||||
<value type="bool" key="AutoTest.UseGlobal">true</value>
|
||||
<valuelist type="QVariantList" key="ClangCodeModel.CustomCommandLineKey">
|
||||
<value type="QString">-fno-delayed-template-parsing</value>
|
||||
</valuelist>
|
||||
<value type="bool" key="ClangCodeModel.UseGlobalConfig">true</value>
|
||||
<value type="QString" key="ClangCodeModel.WarningConfigId">Builtin.Questionable</value>
|
||||
<valuemap type="QVariantMap" key="ClangTools">
|
||||
<value type="bool" key="ClangTools.BuildBeforeAnalysis">true</value>
|
||||
<value type="QString" key="ClangTools.DiagnosticConfig">Builtin.DefaultTidyAndClazy</value>
|
||||
|
|
@ -103,7 +99,7 @@
|
|||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">qt.qt5.5150.win64_mingw81_kit</value>
|
||||
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
|
||||
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
|
||||
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
|
||||
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">1</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
|
||||
<value type="bool">true</value>
|
||||
<value type="int" key="EnableQmlDebugging">0</value>
|
||||
|
|
@ -336,9 +332,8 @@
|
|||
<valuelist type="QVariantList" key="CustomOutputParsers"/>
|
||||
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
|
||||
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">sea_transport2</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:C:/Users/Admin/Documents/repos/sea_transport/sea_transport/sea_transport.pro</value>
|
||||
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey">C:/Users/Admin/Documents/repos/sea_transport/sea_transport/sea_transport.pro</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:C:/Users/Admin/Documents/repos/sea_transport_project/sea_transport/sea_transport.pro</value>
|
||||
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey">C:/Users/Admin/Documents/repos/sea_transport_project/sea_transport/sea_transport.pro</value>
|
||||
<value type="QString" key="RunConfiguration.Arguments"></value>
|
||||
<value type="bool" key="RunConfiguration.Arguments.multi">false</value>
|
||||
<value type="QString" key="RunConfiguration.OverrideDebuggerStartup"></value>
|
||||
|
|
@ -351,7 +346,82 @@
|
|||
<value type="QString" key="RunConfiguration.WorkingDirectory"></value>
|
||||
<value type="QString" key="RunConfiguration.WorkingDirectory.default">C:/Users/Admin/Documents/repos/build-sea_transport_project-Desktop_Qt_5_15_0_MinGW_64_bit-Debug/sea_transport</value>
|
||||
</valuemap>
|
||||
<value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.1">
|
||||
<value type="QString" key="Analyzer.Perf.CallgraphMode">dwarf</value>
|
||||
<valuelist type="QVariantList" key="Analyzer.Perf.Events">
|
||||
<value type="QString">cpu-cycles</value>
|
||||
</valuelist>
|
||||
<valuelist type="QVariantList" key="Analyzer.Perf.ExtraArguments"/>
|
||||
<value type="int" key="Analyzer.Perf.Frequency">250</value>
|
||||
<valuelist type="QVariantList" key="Analyzer.Perf.RecordArguments">
|
||||
<value type="QString">-e</value>
|
||||
<value type="QString">cpu-cycles</value>
|
||||
<value type="QString">--call-graph</value>
|
||||
<value type="QString">dwarf,4096</value>
|
||||
<value type="QString">-F</value>
|
||||
<value type="QString">250</value>
|
||||
</valuelist>
|
||||
<value type="QString" key="Analyzer.Perf.SampleMode">-F</value>
|
||||
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
|
||||
<value type="int" key="Analyzer.Perf.StackSize">4096</value>
|
||||
<value type="bool" key="Analyzer.QmlProfiler.AggregateTraces">false</value>
|
||||
<value type="bool" key="Analyzer.QmlProfiler.FlushEnabled">false</value>
|
||||
<value type="uint" key="Analyzer.QmlProfiler.FlushInterval">1000</value>
|
||||
<value type="QString" key="Analyzer.QmlProfiler.LastTraceFile"></value>
|
||||
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
|
||||
<valuelist type="QVariantList" key="Analyzer.Valgrind.AddedSuppressionFiles"/>
|
||||
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectBusEvents">false</value>
|
||||
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectSystime">false</value>
|
||||
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableBranchSim">false</value>
|
||||
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableCacheSim">false</value>
|
||||
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableEventToolTips">true</value>
|
||||
<value type="double" key="Analyzer.Valgrind.Callgrind.MinimumCostRatio">0.01</value>
|
||||
<value type="double" key="Analyzer.Valgrind.Callgrind.VisualisationMinimumCostRatio">10</value>
|
||||
<value type="bool" key="Analyzer.Valgrind.FilterExternalIssues">true</value>
|
||||
<value type="QString" key="Analyzer.Valgrind.KCachegrindExecutable">kcachegrind</value>
|
||||
<value type="int" key="Analyzer.Valgrind.LeakCheckOnFinish">1</value>
|
||||
<value type="int" key="Analyzer.Valgrind.NumCallers">25</value>
|
||||
<valuelist type="QVariantList" key="Analyzer.Valgrind.RemovedSuppressionFiles"/>
|
||||
<value type="int" key="Analyzer.Valgrind.SelfModifyingCodeDetection">1</value>
|
||||
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
|
||||
<value type="bool" key="Analyzer.Valgrind.ShowReachable">false</value>
|
||||
<value type="bool" key="Analyzer.Valgrind.TrackOrigins">true</value>
|
||||
<value type="QString" key="Analyzer.Valgrind.ValgrindExecutable">valgrind</value>
|
||||
<valuelist type="QVariantList" key="Analyzer.Valgrind.VisibleErrorKinds">
|
||||
<value type="int">0</value>
|
||||
<value type="int">1</value>
|
||||
<value type="int">2</value>
|
||||
<value type="int">3</value>
|
||||
<value type="int">4</value>
|
||||
<value type="int">5</value>
|
||||
<value type="int">6</value>
|
||||
<value type="int">7</value>
|
||||
<value type="int">8</value>
|
||||
<value type="int">9</value>
|
||||
<value type="int">10</value>
|
||||
<value type="int">11</value>
|
||||
<value type="int">12</value>
|
||||
<value type="int">13</value>
|
||||
<value type="int">14</value>
|
||||
</valuelist>
|
||||
<valuelist type="QVariantList" key="CustomOutputParsers"/>
|
||||
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
|
||||
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:C:/Users/Admin/Documents/repos/sea_transport_project/st_test/st_test.pro</value>
|
||||
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey">C:/Users/Admin/Documents/repos/sea_transport_project/st_test/st_test.pro</value>
|
||||
<value type="QString" key="RunConfiguration.Arguments"></value>
|
||||
<value type="bool" key="RunConfiguration.Arguments.multi">false</value>
|
||||
<value type="QString" key="RunConfiguration.OverrideDebuggerStartup"></value>
|
||||
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
|
||||
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
||||
<value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
|
||||
<value type="bool" key="RunConfiguration.UseMultiProcess">false</value>
|
||||
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
|
||||
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
||||
<value type="QString" key="RunConfiguration.WorkingDirectory"></value>
|
||||
<value type="QString" key="RunConfiguration.WorkingDirectory.default">C:/Users/Admin/Documents/repos/build-sea_transport_project-Desktop_Qt_5_15_0_MinGW_64_bit-Debug/st_test</value>
|
||||
</valuemap>
|
||||
<value type="int" key="ProjectExplorer.Target.RunConfigurationCount">2</value>
|
||||
</valuemap>
|
||||
</data>
|
||||
<data>
|
||||
|
|
|
|||
29
st_test/st_test.pro
Normal file
29
st_test/st_test.pro
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
QT += testlib
|
||||
QT -= gui
|
||||
|
||||
CONFIG += qt console warn_on depend_includepath testcase
|
||||
CONFIG -= app_bundle
|
||||
|
||||
TEMPLATE = app
|
||||
|
||||
SOURCES += tst_st_test.cpp \
|
||||
../sea_transport/entities/cargo_entity.cpp \
|
||||
../sea_transport/entities/storage_entity.cpp \
|
||||
../sea_transport/entities/dpoint_entity.cpp \
|
||||
../sea_transport/entities/vessel_entity.cpp \
|
||||
../sea_transport/entities/user_entity.cpp \
|
||||
../sea_transport/system/auth_system.cpp \
|
||||
../sea_transport/system/object_system.cpp \
|
||||
../sea_transport/system/apparatus.cpp
|
||||
|
||||
HEADERS += \
|
||||
../sea_transport/entities/ISerializable.h \
|
||||
../sea_transport/entities/IEntity.h \
|
||||
../sea_transport/entities/cargo_entity.h \
|
||||
../sea_transport/entities/storage_entity.h \
|
||||
../sea_transport/entities/dpoint_entity.h \
|
||||
../sea_transport/entities/vessel_entity.h \
|
||||
../sea_transport/entities/user_entity.h \
|
||||
../sea_transport/system/auth_system.h \
|
||||
../sea_transport/system/object_system.h \
|
||||
../sea_transport/system/apparatus.h
|
||||
287
st_test/tst_st_test.cpp
Normal file
287
st_test/tst_st_test.cpp
Normal file
|
|
@ -0,0 +1,287 @@
|
|||
#include <QtTest>
|
||||
|
||||
#include "../sea_transport/entities/cargo_entity.h"
|
||||
#include "../sea_transport/entities/storage_entity.h"
|
||||
#include "../sea_transport/entities/dpoint_entity.h"
|
||||
#include "../sea_transport/entities/vessel_entity.h"
|
||||
#include "../sea_transport/entities/user_entity.h"
|
||||
|
||||
#include "../sea_transport/system/apparatus.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QDataStream>
|
||||
|
||||
class st_test : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
st_test();
|
||||
~st_test();
|
||||
|
||||
private slots:
|
||||
void initTestCase();
|
||||
void cleanupTestCase();
|
||||
|
||||
void cargo_entity_serialization_test();
|
||||
void storage_entity_serialization_test();
|
||||
void dpoint_entity_serialization_test();
|
||||
void vessel_entity_serialization_test();
|
||||
void user_entity_serialization_test();
|
||||
|
||||
void user_entity_password_verification_test();
|
||||
void apparatus_check_null_throws_error();
|
||||
void apparatus_check_first_run();
|
||||
void apparatus_check_auth_subsystem();
|
||||
void apparatus_check_object_subsystem();
|
||||
};
|
||||
|
||||
st_test::st_test() {
|
||||
|
||||
}
|
||||
|
||||
st_test::~st_test() {
|
||||
|
||||
}
|
||||
|
||||
//=================================================
|
||||
void st_test::initTestCase() {
|
||||
QVERIFY2(
|
||||
!QFile("data.bin").exists(),
|
||||
"There should be no data file!"
|
||||
);
|
||||
}
|
||||
|
||||
void st_test::cleanupTestCase() {
|
||||
QVERIFY2(
|
||||
QFile("data.bin").exists(),
|
||||
"There should be a data file!"
|
||||
);
|
||||
QFile().remove("data.bin");
|
||||
}
|
||||
|
||||
//=================================================
|
||||
void st_test::cargo_entity_serialization_test() {
|
||||
QDataStream stream;
|
||||
cargo_entity ent1;
|
||||
cargo_entity ent2;
|
||||
|
||||
{
|
||||
QFile f("test_file.dat");
|
||||
f.open(QIODevice::WriteOnly);
|
||||
stream.setDevice(&f);
|
||||
|
||||
ent1 = cargo_entity("test title", 256);
|
||||
ent1.serialize(stream);
|
||||
|
||||
stream.setDevice(nullptr);
|
||||
}
|
||||
|
||||
{
|
||||
QFile f("test_file.dat");
|
||||
f.open(QIODevice::ReadOnly);
|
||||
stream.setDevice(&f);
|
||||
|
||||
ent2.deserialize(stream);
|
||||
f.remove();
|
||||
}
|
||||
|
||||
QVERIFY2(
|
||||
ent1.id() == ent2.id() && ent1.title() == ent2.title() && ent1.volume() == ent2.volume(),
|
||||
"Cargo entity not serialized properly"
|
||||
);
|
||||
}
|
||||
|
||||
void st_test::storage_entity_serialization_test() {
|
||||
QDataStream stream;
|
||||
storage_entity ent1;
|
||||
storage_entity ent2;
|
||||
|
||||
{
|
||||
QFile f("test_file.dat");
|
||||
f.open(QIODevice::WriteOnly);
|
||||
stream.setDevice(&f);
|
||||
|
||||
ent1 = storage_entity(128);
|
||||
ent1.serialize(stream);
|
||||
|
||||
stream.setDevice(nullptr);
|
||||
}
|
||||
|
||||
{
|
||||
QFile f("test_file.dat");
|
||||
f.open(QIODevice::ReadOnly);
|
||||
stream.setDevice(&f);
|
||||
|
||||
ent2.deserialize(stream);
|
||||
f.remove();
|
||||
}
|
||||
|
||||
QVERIFY2(
|
||||
ent1.id() == ent2.id() && ent1.capacity() == ent2.capacity(),
|
||||
"Storage entity not serialized properly"
|
||||
);
|
||||
}
|
||||
|
||||
void st_test::dpoint_entity_serialization_test() {
|
||||
QDataStream stream;
|
||||
dpoint_entity ent1;
|
||||
dpoint_entity ent2;
|
||||
|
||||
{
|
||||
QFile f("test_file.dat");
|
||||
f.open(QIODevice::WriteOnly);
|
||||
stream.setDevice(&f);
|
||||
|
||||
ent1 = dpoint_entity("some_test_point");
|
||||
ent1.serialize(stream);
|
||||
|
||||
stream.setDevice(nullptr);
|
||||
}
|
||||
|
||||
{
|
||||
QFile f("test_file.dat");
|
||||
f.open(QIODevice::ReadOnly);
|
||||
stream.setDevice(&f);
|
||||
|
||||
ent2.deserialize(stream);
|
||||
f.remove();
|
||||
}
|
||||
|
||||
QVERIFY2(
|
||||
ent1.id() == ent2.id() && ent1.title() == ent2.title(),
|
||||
"Delivery Point entity not serialized properly"
|
||||
);
|
||||
}
|
||||
|
||||
void st_test::vessel_entity_serialization_test() {
|
||||
QDataStream stream;
|
||||
vessel_entity ent1;
|
||||
vessel_entity ent2;
|
||||
|
||||
{
|
||||
QFile f("test_file.dat");
|
||||
f.open(QIODevice::WriteOnly);
|
||||
stream.setDevice(&f);
|
||||
|
||||
dpoint_entity test_harbor("test_harbor_for_vessel");
|
||||
ent1 = vessel_entity(test_harbor, 256);
|
||||
ent1.serialize(stream);
|
||||
|
||||
stream.setDevice(nullptr);
|
||||
}
|
||||
|
||||
{
|
||||
QFile f("test_file.dat");
|
||||
f.open(QIODevice::ReadOnly);
|
||||
stream.setDevice(&f);
|
||||
|
||||
ent2.deserialize(stream);
|
||||
f.remove();
|
||||
}
|
||||
|
||||
QVERIFY2(
|
||||
ent1.id() == ent2.id() && ent1.harbor().id() == ent2.harbor().id() && ent1.capacity() == ent2.capacity(),
|
||||
"Delivery Point entity not serialized properly"
|
||||
);
|
||||
}
|
||||
|
||||
void st_test::user_entity_serialization_test() {
|
||||
QDataStream stream;
|
||||
user_entity ent1;
|
||||
user_entity ent2;
|
||||
QString test_password = "test_password";
|
||||
|
||||
{
|
||||
QFile f("test_file.dat");
|
||||
f.open(QIODevice::WriteOnly);
|
||||
stream.setDevice(&f);
|
||||
|
||||
ent1 = user_entity("test_login", test_password, UserRole::ADMINISTRATOR);
|
||||
ent1.serialize(stream);
|
||||
|
||||
stream.setDevice(nullptr);
|
||||
}
|
||||
|
||||
{
|
||||
QFile f("test_file.dat");
|
||||
f.open(QIODevice::ReadOnly);
|
||||
stream.setDevice(&f);
|
||||
|
||||
ent2.deserialize(stream);
|
||||
f.remove();
|
||||
}
|
||||
|
||||
QVERIFY2(
|
||||
ent1.id() == ent2.id() && ent1.id() == ent2.id() && ent1.role() == ent2.role() && ent2.verify_password(test_password),
|
||||
"User entity not serialized properly"
|
||||
);
|
||||
}
|
||||
|
||||
//=================================================
|
||||
void st_test::user_entity_password_verification_test() {
|
||||
QString test_password = "test_password";
|
||||
QString wrong_password = "wrong_password";
|
||||
user_entity ent1("test_login", test_password, UserRole::ADMINISTRATOR);
|
||||
|
||||
QVERIFY2(
|
||||
ent1.verify_password(test_password) || ent1.verify_password(wrong_password),
|
||||
"Password verification failed!"
|
||||
);
|
||||
}
|
||||
|
||||
void st_test::apparatus_check_null_throws_error() {
|
||||
QVERIFY_EXCEPTION_THROWN(apparatus::instance(), std::runtime_error);
|
||||
}
|
||||
|
||||
void st_test::apparatus_check_first_run() {
|
||||
apparatus::init();
|
||||
QVERIFY2(
|
||||
apparatus::instance()->isFirstRun(),
|
||||
"Not a first run!"
|
||||
);
|
||||
apparatus::shutdown();
|
||||
}
|
||||
|
||||
void st_test::apparatus_check_auth_subsystem() {
|
||||
apparatus::init();
|
||||
auth_system as = apparatus::instance()->get_auth_subsystem();
|
||||
{
|
||||
bool test = as.register_user("testor", "passwd", UserRole::ADMINISTRATOR);
|
||||
QVERIFY(test);
|
||||
}
|
||||
{
|
||||
bool test;
|
||||
as.get_user("testor", test);
|
||||
QVERIFY(test);
|
||||
}
|
||||
{
|
||||
bool test = as.remove_user("testor");
|
||||
QVERIFY(test);
|
||||
}
|
||||
apparatus::shutdown();
|
||||
}
|
||||
|
||||
void st_test::apparatus_check_object_subsystem() {
|
||||
apparatus::init();
|
||||
object_system os = apparatus::instance()->get_object_subsystem();
|
||||
dpoint_entity p("test");
|
||||
{
|
||||
bool test = os.add_dpoint(p);
|
||||
QVERIFY(test);
|
||||
}
|
||||
{
|
||||
bool test;
|
||||
os.get_dpoint(p.id(), test);
|
||||
QVERIFY(test);
|
||||
}
|
||||
{
|
||||
bool test = os.remove_dpoint(p.id());
|
||||
QVERIFY(test);
|
||||
}
|
||||
apparatus::shutdown();
|
||||
}
|
||||
|
||||
QTEST_APPLESS_MAIN(st_test)
|
||||
|
||||
#include "tst_st_test.moc"
|
||||
Loading…
Add table
Add a link
Reference in a new issue