mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-12-25 15:41:34 +08:00
Build
- Use absolute file paths by using $$PWD variable. - Adds unit testing project + unit-test for serialization. - Adds ADS_IMPORT define possibility for static code include. Core - Fixes usage of QBuffer.. missed the QBuffer::open() call..
This commit is contained in:
parent
5ab1751f9b
commit
158dac5309
@ -1,24 +1,24 @@
|
||||
|
||||
SOURCES += \
|
||||
src/API.cpp \
|
||||
src/ContainerWidget.cpp \
|
||||
src/SectionWidget.cpp \
|
||||
src/SectionContent.cpp \
|
||||
src/SectionTitleWidget.cpp \
|
||||
src/SectionContentWidget.cpp \
|
||||
src/DropOverlay.cpp \
|
||||
src/FloatingWidget.cpp \
|
||||
src/Internal.cpp \
|
||||
src/Serialization.cpp
|
||||
$$PWD/src/API.cpp \
|
||||
$$PWD/src/ContainerWidget.cpp \
|
||||
$$PWD/src/SectionWidget.cpp \
|
||||
$$PWD/src/SectionContent.cpp \
|
||||
$$PWD/src/SectionTitleWidget.cpp \
|
||||
$$PWD/src/SectionContentWidget.cpp \
|
||||
$$PWD/src/DropOverlay.cpp \
|
||||
$$PWD/src/FloatingWidget.cpp \
|
||||
$$PWD/src/Internal.cpp \
|
||||
$$PWD/src/Serialization.cpp
|
||||
|
||||
HEADERS += \
|
||||
include/ads/API.h \
|
||||
include/ads/ContainerWidget.h \
|
||||
include/ads/SectionWidget.h \
|
||||
include/ads/SectionContent.h \
|
||||
include/ads/SectionTitleWidget.h \
|
||||
include/ads/SectionContentWidget.h \
|
||||
include/ads/DropOverlay.h \
|
||||
include/ads/FloatingWidget.h \
|
||||
include/ads/Internal.h \
|
||||
include/ads/Serialization.h
|
||||
$$PWD/include/ads/API.h \
|
||||
$$PWD/include/ads/ContainerWidget.h \
|
||||
$$PWD/include/ads/SectionWidget.h \
|
||||
$$PWD/include/ads/SectionContent.h \
|
||||
$$PWD/include/ads/SectionTitleWidget.h \
|
||||
$$PWD/include/ads/SectionContentWidget.h \
|
||||
$$PWD/include/ads/DropOverlay.h \
|
||||
$$PWD/include/ads/FloatingWidget.h \
|
||||
$$PWD/include/ads/Internal.h \
|
||||
$$PWD/include/ads/Serialization.h
|
||||
|
@ -4,6 +4,7 @@ CONFIG += adsBuildShared
|
||||
|
||||
QT += core gui
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
greaterThan(QT_MAJOR_VERSION, 4): DEFINES += ADS_NAMESPACE_ENABLED
|
||||
|
||||
TEMPLATE = lib
|
||||
|
||||
@ -18,8 +19,6 @@ adsBuildShared {
|
||||
INCLUDEPATH += $$PWD/src
|
||||
INCLUDEPATH += $$PWD/include
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): DEFINES += ADS_NAMESPACE_ENABLED
|
||||
|
||||
windows {
|
||||
# MinGW
|
||||
*-g++* {
|
||||
|
@ -7,7 +7,9 @@ class QSplitter;
|
||||
|
||||
// DLL Export API
|
||||
#ifdef _WIN32
|
||||
#ifdef ADS_EXPORT
|
||||
#if defined(ADS_IMPORT)
|
||||
#define ADS_EXPORT_API
|
||||
#elif defined(ADS_EXPORT)
|
||||
#define ADS_EXPORT_API __declspec(dllexport)
|
||||
#else
|
||||
#define ADS_EXPORT_API __declspec(dllimport)
|
||||
|
@ -129,9 +129,10 @@ class InMemoryWriter
|
||||
{
|
||||
public:
|
||||
InMemoryWriter();
|
||||
bool write(OffsetsHeaderEntry::Type type, const QByteArray& data);
|
||||
bool write(qint32 entryType, const QByteArray& data);
|
||||
bool write(const SectionIndexData& data);
|
||||
QByteArray toByteArray() const;
|
||||
qint32 offsetsCount() const { return _offsetsHeader.entriesCount; }
|
||||
|
||||
private:
|
||||
QBuffer _contentBuffer;
|
||||
@ -146,12 +147,11 @@ class InMemoryReader
|
||||
public:
|
||||
InMemoryReader(const QByteArray& data);
|
||||
bool initReadHeader();
|
||||
bool read(OffsetsHeaderEntry::Type type, QByteArray &data);
|
||||
bool read(qint32 entryType, QByteArray &data);
|
||||
qint32 offsetsCount() const { return _offsetsHeader.entriesCount; }
|
||||
|
||||
private:
|
||||
QByteArray _data;
|
||||
QBuffer _buff;
|
||||
|
||||
OffsetsHeader _offsetsHeader;
|
||||
};
|
||||
|
||||
|
@ -276,12 +276,13 @@ QDataStream& operator>>(QDataStream& in, SectionIndexData& data)
|
||||
|
||||
InMemoryWriter::InMemoryWriter()
|
||||
{
|
||||
_contentBuffer.open(QIODevice::ReadWrite);
|
||||
}
|
||||
|
||||
bool InMemoryWriter::write(OffsetsHeaderEntry::Type type, const QByteArray& data)
|
||||
bool InMemoryWriter::write(qint32 entryType, const QByteArray& data)
|
||||
{
|
||||
OffsetsHeaderEntry entry;
|
||||
entry.type = type;
|
||||
entry.type = entryType;
|
||||
entry.offset = _contentBuffer.pos(); // Relative offset!
|
||||
entry.contentSize = data.size();
|
||||
|
||||
@ -314,9 +315,7 @@ bool InMemoryWriter::write(const SectionIndexData& data)
|
||||
QByteArray InMemoryWriter::toByteArray() const
|
||||
{
|
||||
QByteArray data;
|
||||
QBuffer buff(&data);
|
||||
|
||||
QDataStream out(&buff);
|
||||
QDataStream out(&data, QIODevice::ReadWrite);
|
||||
out.setVersion(QDataStream::Qt_4_5);
|
||||
|
||||
// Basic format header.
|
||||
@ -332,13 +331,13 @@ QByteArray InMemoryWriter::toByteArray() const
|
||||
// - Convert relative- to absolute-offsets
|
||||
// - Seek back to begin-pos and write OffsetsHeader again.
|
||||
// Use a copy of OffsetsHeader to keep the _offsetsHeader relative.
|
||||
const qint64 posOffsetHeaders = buff.pos();
|
||||
const qint64 posOffsetHeaders = out.device()->pos();
|
||||
OffsetsHeader offsetsHeader = _offsetsHeader;
|
||||
out << offsetsHeader;
|
||||
|
||||
// Now we know the size of the entire header.
|
||||
// We can update the relative- to absolute-offsets now.
|
||||
const qint64 allHeaderSize = buff.pos();
|
||||
const qint64 allHeaderSize = out.device()->pos();
|
||||
for (int i = 0; i < offsetsHeader.entriesCount; ++i)
|
||||
{
|
||||
offsetsHeader.entries[i].offset += allHeaderSize;
|
||||
@ -346,11 +345,11 @@ QByteArray InMemoryWriter::toByteArray() const
|
||||
|
||||
// Seek back and write again with absolute offsets.
|
||||
// TODO Thats not nice, but it works...
|
||||
buff.seek(posOffsetHeaders);
|
||||
out.device()->seek(posOffsetHeaders);
|
||||
out << offsetsHeader;
|
||||
|
||||
// Write contents.
|
||||
buff.write(_contentBuffer.data());
|
||||
out.writeRawData(_contentBuffer.data().constData(), _contentBuffer.size());
|
||||
|
||||
return data;
|
||||
}
|
||||
@ -358,13 +357,13 @@ QByteArray InMemoryWriter::toByteArray() const
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
InMemoryReader::InMemoryReader(const QByteArray& data) :
|
||||
_data(data), _buff(&_data)
|
||||
_data(data)
|
||||
{
|
||||
}
|
||||
|
||||
bool InMemoryReader::initReadHeader()
|
||||
{
|
||||
QDataStream in(&_buff);
|
||||
QDataStream in(_data);
|
||||
in.setVersion(QDataStream::Qt_4_5);
|
||||
|
||||
// Basic format header.
|
||||
@ -388,13 +387,13 @@ bool InMemoryReader::initReadHeader()
|
||||
return !in.atEnd();
|
||||
}
|
||||
|
||||
bool InMemoryReader::read(OffsetsHeaderEntry::Type type, QByteArray& data)
|
||||
bool InMemoryReader::read(qint32 entryType, QByteArray& data)
|
||||
{
|
||||
// Find offset for "type".
|
||||
int index = -1;
|
||||
for (int i = 0; i < _offsetsHeader.entriesCount; ++i)
|
||||
{
|
||||
if (_offsetsHeader.entries.at(index).type == type)
|
||||
if (_offsetsHeader.entries.at(i).type == entryType)
|
||||
{
|
||||
index = i;
|
||||
break;
|
||||
@ -406,8 +405,16 @@ bool InMemoryReader::read(OffsetsHeaderEntry::Type type, QByteArray& data)
|
||||
return false;
|
||||
|
||||
const OffsetsHeaderEntry& entry = _offsetsHeader.entries.at(index);
|
||||
_buff.seek(entry.offset);
|
||||
data.append(_buff.read(entry.contentSize));
|
||||
|
||||
QDataStream in(_data);
|
||||
in.setVersion(QDataStream::Qt_4_5);
|
||||
in.device()->seek(entry.offset);
|
||||
|
||||
char* buff = new char[entry.contentSize];
|
||||
in.readRawData(buff, entry.contentSize);
|
||||
data.append(buff, entry.contentSize);
|
||||
delete[] buff;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,7 @@
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/src/TestCore.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/src/main.cpp \
|
||||
$$PWD/src/TestCore.cpp
|
@ -0,0 +1,14 @@
|
||||
TARGET = AdvancedDockingSystemUnitTests
|
||||
|
||||
QT += core gui testlib
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
greaterThan(QT_MAJOR_VERSION, 4): DEFINES += ADS_NAMESPACE_ENABLED
|
||||
DEFINES += ADS_IMPORT
|
||||
|
||||
INCLUDEPATH += $$PWD/src
|
||||
|
||||
INCLUDEPATH += $$PWD/../AdvancedDockingSystem/include
|
||||
DEPENDPATH += $$PWD/../AdvancedDockingSystem/include
|
||||
|
||||
include(AdvancedDockingSystemUnitTests.pri)
|
||||
include(../AdvancedDockingSystem/AdvancedDockingSystem.pri)
|
35
AdvancedDockingSystemUnitTests/src/TestCore.cpp
Normal file
35
AdvancedDockingSystemUnitTests/src/TestCore.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
#include "TestCore.h"
|
||||
|
||||
#include "ads/API.h"
|
||||
#include "ads/Serialization.h"
|
||||
|
||||
void TestCore::serialization()
|
||||
{
|
||||
QList<QByteArray> datas;
|
||||
datas.append(QByteArray("Custom Data Here!!!"));
|
||||
datas.append(QByteArray("Even More..."));
|
||||
datas.append(QByteArray("lalalaalalalalalalal").toBase64());
|
||||
|
||||
// Write some data.
|
||||
ADS_NS_SER::InMemoryWriter writer;
|
||||
for (int i = 0; i < datas.count(); ++i)
|
||||
{
|
||||
QVERIFY(writer.write(i + 1, datas.at(i)));
|
||||
}
|
||||
QVERIFY(writer.offsetsCount() == datas.count());
|
||||
const QByteArray writtenData = writer.toByteArray();
|
||||
QVERIFY(writtenData.size() > 0);
|
||||
|
||||
// Read and validate written data.
|
||||
ADS_NS_SER::InMemoryReader reader(writtenData);
|
||||
QVERIFY(reader.initReadHeader());
|
||||
QVERIFY(reader.offsetsCount() == datas.count());
|
||||
for (int i = 0; i < datas.count(); ++i)
|
||||
{
|
||||
QByteArray readData;
|
||||
QVERIFY(reader.read(i + 1, readData));
|
||||
QVERIFY(readData == datas.at(i));
|
||||
}
|
||||
}
|
||||
|
||||
QTEST_MAIN(TestCore)
|
14
AdvancedDockingSystemUnitTests/src/TestCore.h
Normal file
14
AdvancedDockingSystemUnitTests/src/TestCore.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef TEST_CORE_H
|
||||
#define TEST_CORE_H
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
class TestCore : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void serialization();
|
||||
};
|
||||
|
||||
#endif
|
1
AdvancedDockingSystemUnitTests/src/main.cpp
Normal file
1
AdvancedDockingSystemUnitTests/src/main.cpp
Normal file
@ -0,0 +1 @@
|
||||
#include <QtTest/QtTest>
|
Loading…
Reference in New Issue
Block a user