Big-Ugly Style Update (#278)
* Bulk replaced tabs with spaces * Bulk removed trailing whitespace from lines * Replaced c-style comments with c++-style comments in file banners * Replace nested namespace definitions with single concise definitions (C++17), this keeps the indentation more manageable * Cleanup ordering and spacing of include directives * Bulk renaming of header file extensions from '.h' to '.hpp'. * Update CODING-STYLE.md * Update target_compile_features from cxx_std_11 to cxx_std_20. * Refresh .clang-format file. Still needs a lot of tweaking.
This commit is contained in:
@@ -3,7 +3,7 @@ if (Qt6Test_FOUND)
|
||||
#=======================================
|
||||
# Test SubstitutionField class
|
||||
#=======================================
|
||||
qt6_wrap_cpp (TestSubstitutionField_moc_sources TestSubstitutionField.h)
|
||||
qt6_wrap_cpp (TestSubstitutionField_moc_sources TestSubstitutionField.hpp)
|
||||
add_executable (TestSubstitutionField TestSubstitutionField.cpp ${TestSubstitutionField_moc_sources})
|
||||
target_link_libraries (TestSubstitutionField Model Qt6::Test)
|
||||
add_test (NAME SubstitutionField COMMAND TestSubstitutionField)
|
||||
@@ -11,7 +11,7 @@ if (Qt6Test_FOUND)
|
||||
#=======================================
|
||||
# Test XmlUtil class
|
||||
#=======================================
|
||||
qt6_wrap_cpp (TestXmlUtil_moc_sources TestXmlUtil.h)
|
||||
qt6_wrap_cpp (TestXmlUtil_moc_sources TestXmlUtil.hpp)
|
||||
add_executable (TestXmlUtil TestXmlUtil.cpp ${TestXmlUtil_moc_sources})
|
||||
target_link_libraries (TestXmlUtil Model Qt6::Test)
|
||||
add_test (NAME XmlUtil COMMAND TestXmlUtil)
|
||||
@@ -19,7 +19,7 @@ if (Qt6Test_FOUND)
|
||||
#=======================================
|
||||
# Test XmlLabelCreator/Parser classes
|
||||
#=======================================
|
||||
qt6_wrap_cpp (TestXmlLabel_moc_sources TestXmlLabel.h)
|
||||
qt6_wrap_cpp (TestXmlLabel_moc_sources TestXmlLabel.hpp)
|
||||
add_executable (TestXmlLabel TestXmlLabel.cpp ${TestXmlLabel_moc_sources})
|
||||
target_link_libraries (TestXmlLabel Model Qt6::Test)
|
||||
target_compile_definitions(TestXmlLabel PRIVATE TEST_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
@@ -28,7 +28,7 @@ if (Qt6Test_FOUND)
|
||||
#=======================================
|
||||
# Test ColorNode class
|
||||
#=======================================
|
||||
qt6_wrap_cpp (TestColorNode_moc_sources TestColorNode.h)
|
||||
qt6_wrap_cpp (TestColorNode_moc_sources TestColorNode.hpp)
|
||||
add_executable (TestColorNode TestColorNode.cpp ${TestColorNode_moc_sources})
|
||||
target_link_libraries (TestColorNode Model Qt6::Test)
|
||||
add_test (NAME ColorNode COMMAND TestColorNode)
|
||||
@@ -36,7 +36,7 @@ if (Qt6Test_FOUND)
|
||||
#=======================================
|
||||
# Test FileUtil class
|
||||
#=======================================
|
||||
qt6_wrap_cpp (TestFileUtil_moc_sources TestFileUtil.h)
|
||||
qt6_wrap_cpp (TestFileUtil_moc_sources TestFileUtil.hpp)
|
||||
add_executable (TestFileUtil TestFileUtil.cpp ${TestFileUtil_moc_sources})
|
||||
target_link_libraries (TestFileUtil Model Qt6::Test)
|
||||
add_test (NAME FileUtil COMMAND TestFileUtil)
|
||||
@@ -44,7 +44,7 @@ if (Qt6Test_FOUND)
|
||||
#=======================================
|
||||
# Test Merge classes
|
||||
#=======================================
|
||||
qt6_wrap_cpp (TestMerge_moc_sources TestMerge.h)
|
||||
qt6_wrap_cpp (TestMerge_moc_sources TestMerge.hpp)
|
||||
add_executable (TestMerge TestMerge.cpp ${TestMerge_moc_sources})
|
||||
target_link_libraries (TestMerge Model Qt6::Test)
|
||||
add_test (NAME Merge COMMAND TestMerge)
|
||||
@@ -52,7 +52,7 @@ if (Qt6Test_FOUND)
|
||||
#=======================================
|
||||
# Test Model class
|
||||
#=======================================
|
||||
qt6_wrap_cpp (TestModel_moc_sources TestModel.h)
|
||||
qt6_wrap_cpp (TestModel_moc_sources TestModel.hpp)
|
||||
add_executable (TestModel TestModel.cpp ${TestModel_moc_sources})
|
||||
target_link_libraries (TestModel Model Qt6::Test)
|
||||
add_test (NAME Model COMMAND TestModel)
|
||||
@@ -60,7 +60,7 @@ if (Qt6Test_FOUND)
|
||||
#=======================================
|
||||
# Test ModelImageObject class
|
||||
#=======================================
|
||||
qt6_wrap_cpp (TestModelImageObject_moc_sources TestModelImageObject.h)
|
||||
qt6_wrap_cpp (TestModelImageObject_moc_sources TestModelImageObject.hpp)
|
||||
add_executable (TestModelImageObject TestModelImageObject.cpp ${TestModelImageObject_moc_sources})
|
||||
target_link_libraries (TestModelImageObject Model Qt6::Test)
|
||||
add_test (NAME ModelImageObject COMMAND TestModelImageObject)
|
||||
@@ -68,7 +68,7 @@ if (Qt6Test_FOUND)
|
||||
#=======================================
|
||||
# Test RawText class
|
||||
#=======================================
|
||||
qt6_wrap_cpp (TestRawText_moc_sources TestRawText.h)
|
||||
qt6_wrap_cpp (TestRawText_moc_sources TestRawText.hpp)
|
||||
add_executable (TestRawText TestRawText.cpp ${TestRawText_moc_sources})
|
||||
target_link_libraries (TestRawText Model Qt6::Test)
|
||||
add_test (NAME RawText COMMAND TestRawText)
|
||||
@@ -76,7 +76,7 @@ if (Qt6Test_FOUND)
|
||||
#=======================================
|
||||
# Test TextNode class
|
||||
#=======================================
|
||||
qt6_wrap_cpp (TestTextNode_moc_sources TestTextNode.h)
|
||||
qt6_wrap_cpp (TestTextNode_moc_sources TestTextNode.hpp)
|
||||
add_executable (TestTextNode TestTextNode.cpp ${TestTextNode_moc_sources})
|
||||
target_link_libraries (TestTextNode Model Qt6::Test)
|
||||
add_test (NAME TextNode COMMAND TestTextNode)
|
||||
@@ -84,7 +84,7 @@ if (Qt6Test_FOUND)
|
||||
#=======================================
|
||||
# Test Variable class
|
||||
#=======================================
|
||||
qt6_wrap_cpp (TestVariable_moc_sources TestVariable.h)
|
||||
qt6_wrap_cpp (TestVariable_moc_sources TestVariable.hpp)
|
||||
add_executable (TestVariable TestVariable.cpp ${TestVariable_moc_sources})
|
||||
target_link_libraries (TestVariable Model Qt6::Test)
|
||||
add_test (NAME Variable COMMAND TestVariable)
|
||||
@@ -92,7 +92,7 @@ if (Qt6Test_FOUND)
|
||||
#=======================================
|
||||
# Test Variables class
|
||||
#=======================================
|
||||
qt6_wrap_cpp (TestVariables_moc_sources TestVariables.h)
|
||||
qt6_wrap_cpp (TestVariables_moc_sources TestVariables.hpp)
|
||||
add_executable (TestVariables TestVariables.cpp ${TestVariables_moc_sources})
|
||||
target_link_libraries (TestVariables Model Qt6::Test)
|
||||
add_test (NAME Variables COMMAND TestVariables)
|
||||
@@ -100,7 +100,7 @@ if (Qt6Test_FOUND)
|
||||
#=======================================
|
||||
# Test StrUtil class
|
||||
#=======================================
|
||||
qt6_wrap_cpp (TestStrUtil_moc_sources TestStrUtil.h)
|
||||
qt6_wrap_cpp (TestStrUtil_moc_sources TestStrUtil.hpp)
|
||||
add_executable (TestStrUtil TestStrUtil.cpp ${TestStrUtil_moc_sources})
|
||||
target_link_libraries (TestStrUtil Model Qt6::Test)
|
||||
add_test (NAME StrUtil COMMAND TestStrUtil)
|
||||
|
||||
+135
-135
@@ -1,29 +1,29 @@
|
||||
/* TestColorNode.cpp
|
||||
*
|
||||
* Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// TestColorNode.cpp
|
||||
//
|
||||
// Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of gLabels-qt.
|
||||
//
|
||||
// gLabels-qt is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// gLabels-qt is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
|
||||
#include "TestColorNode.h"
|
||||
#include "TestColorNode.hpp"
|
||||
|
||||
#include "model/ColorNode.h"
|
||||
#include "model/ColorNode.hpp"
|
||||
|
||||
#include <QtDebug>
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
QTEST_MAIN(TestColorNode)
|
||||
@@ -34,141 +34,141 @@ using namespace glabels::merge;
|
||||
|
||||
void TestColorNode::colorNode()
|
||||
{
|
||||
uint32_t rgbaBlackTransparent = 0;
|
||||
uint32_t rgbaWhite = 0xFFFFFFFF;
|
||||
uint32_t rgbaRed = 0xFF0000FF; // ColorNode uses RGBA. QColor set alpha to opaque 0xFF by default
|
||||
uint32_t qRgbaRed = 0xFFFF0000; // QColor uses ARGB, ie alpha at top
|
||||
uint32_t qRgbaGreen80 = 0x8000FF00;
|
||||
uint32_t rgbaBlackTransparent = 0;
|
||||
uint32_t rgbaWhite = 0xFFFFFFFF;
|
||||
uint32_t rgbaRed = 0xFF0000FF; // ColorNode uses RGBA. QColor set alpha to opaque 0xFF by default
|
||||
uint32_t qRgbaRed = 0xFFFF0000; // QColor uses ARGB, ie alpha at top
|
||||
uint32_t qRgbaGreen80 = 0x8000FF00;
|
||||
|
||||
QColor blackTransparent = QColor::fromRgba( rgbaBlackTransparent );
|
||||
QColor white = QColor::fromRgba( rgbaWhite );
|
||||
QColor red = QColor::fromRgba( qRgbaRed );
|
||||
QColor green80 = QColor::fromRgba( qRgbaGreen80 );
|
||||
QColor silver80 = QColor( 192, 192, 192, 128 );
|
||||
QColor blackTransparent = QColor::fromRgba( rgbaBlackTransparent );
|
||||
QColor white = QColor::fromRgba( rgbaWhite );
|
||||
QColor red = QColor::fromRgba( qRgbaRed );
|
||||
QColor green80 = QColor::fromRgba( qRgbaGreen80 );
|
||||
QColor silver80 = QColor( 192, 192, 192, 128 );
|
||||
|
||||
Record record;
|
||||
Variables vars;
|
||||
Record record;
|
||||
Variables vars;
|
||||
|
||||
ColorNode colorNode;
|
||||
QVERIFY( !colorNode.isField() );
|
||||
QCOMPARE( colorNode.color(), blackTransparent );
|
||||
QCOMPARE( colorNode.key(), QString( "" ) );
|
||||
QCOMPARE( colorNode.rgba(), rgbaBlackTransparent );
|
||||
QCOMPARE( colorNode.color( NullRecord(), vars ), blackTransparent );
|
||||
QCOMPARE( colorNode.color( record, vars ), blackTransparent );
|
||||
ColorNode colorNode;
|
||||
QVERIFY( !colorNode.isField() );
|
||||
QCOMPARE( colorNode.color(), blackTransparent );
|
||||
QCOMPARE( colorNode.key(), QString( "" ) );
|
||||
QCOMPARE( colorNode.rgba(), rgbaBlackTransparent );
|
||||
QCOMPARE( colorNode.color( NullRecord(), vars ), blackTransparent );
|
||||
QCOMPARE( colorNode.color( record, vars ), blackTransparent );
|
||||
|
||||
colorNode.setField( true );
|
||||
QVERIFY( colorNode.isField() );
|
||||
colorNode.setField( false );
|
||||
QVERIFY( !colorNode.isField() );
|
||||
colorNode.setField( true );
|
||||
QVERIFY( colorNode.isField() );
|
||||
colorNode.setField( false );
|
||||
QVERIFY( !colorNode.isField() );
|
||||
|
||||
colorNode.setColor( white );
|
||||
QCOMPARE( colorNode.color(), white );
|
||||
QCOMPARE( colorNode.rgba(), rgbaWhite );
|
||||
QCOMPARE( colorNode.color( NullRecord(), vars ), white );
|
||||
QCOMPARE( colorNode.color( record, vars ), white );
|
||||
colorNode.setColor( white );
|
||||
QCOMPARE( colorNode.color(), white );
|
||||
QCOMPARE( colorNode.rgba(), rgbaWhite );
|
||||
QCOMPARE( colorNode.color( NullRecord(), vars ), white );
|
||||
QCOMPARE( colorNode.color( record, vars ), white );
|
||||
|
||||
colorNode.setKey( "key1" );
|
||||
QCOMPARE( colorNode.key(), QString( "key1" ) );
|
||||
colorNode.setKey( "key1" );
|
||||
QCOMPARE( colorNode.key(), QString( "key1" ) );
|
||||
|
||||
///
|
||||
/// Constructors
|
||||
///
|
||||
ColorNode colorNode2( true, white, QString( "key2" ) );
|
||||
QVERIFY( colorNode2.isField() );
|
||||
QCOMPARE( colorNode2.key(), QString( "key2" ) );
|
||||
QCOMPARE( colorNode2.color(), white );
|
||||
///
|
||||
/// Constructors
|
||||
///
|
||||
ColorNode colorNode2( true, white, QString( "key2" ) );
|
||||
QVERIFY( colorNode2.isField() );
|
||||
QCOMPARE( colorNode2.key(), QString( "key2" ) );
|
||||
QCOMPARE( colorNode2.color(), white );
|
||||
|
||||
QVERIFY( colorNode2 != colorNode );
|
||||
colorNode.setField( true );
|
||||
QVERIFY( colorNode2 != colorNode );
|
||||
colorNode.setKey( "key2" );
|
||||
QVERIFY( colorNode2 == colorNode );
|
||||
QVERIFY( colorNode2 != colorNode );
|
||||
colorNode.setField( true );
|
||||
QVERIFY( colorNode2 != colorNode );
|
||||
colorNode.setKey( "key2" );
|
||||
QVERIFY( colorNode2 == colorNode );
|
||||
|
||||
ColorNode colorNode3( red );
|
||||
QVERIFY( !colorNode3.isField() );
|
||||
QCOMPARE( colorNode3.key(), QString( "" ) );
|
||||
QCOMPARE( colorNode3.color(), red );
|
||||
QCOMPARE( colorNode3.rgba(), rgbaRed );
|
||||
ColorNode colorNode3( red );
|
||||
QVERIFY( !colorNode3.isField() );
|
||||
QCOMPARE( colorNode3.key(), QString( "" ) );
|
||||
QCOMPARE( colorNode3.color(), red );
|
||||
QCOMPARE( colorNode3.rgba(), rgbaRed );
|
||||
|
||||
QVERIFY( colorNode3 != colorNode );
|
||||
colorNode.setField( false );
|
||||
QVERIFY( colorNode3 != colorNode );
|
||||
colorNode.setKey( "" );
|
||||
QVERIFY( colorNode3 != colorNode );
|
||||
colorNode.setColor( red );
|
||||
QVERIFY( colorNode3 == colorNode );
|
||||
QVERIFY( colorNode3 != colorNode );
|
||||
colorNode.setField( false );
|
||||
QVERIFY( colorNode3 != colorNode );
|
||||
colorNode.setKey( "" );
|
||||
QVERIFY( colorNode3 != colorNode );
|
||||
colorNode.setColor( red );
|
||||
QVERIFY( colorNode3 == colorNode );
|
||||
|
||||
///
|
||||
/// Record
|
||||
///
|
||||
colorNode = ColorNode( QString( "key1" ) );
|
||||
QVERIFY( colorNode.isField() ); // Defaults to true if given key only
|
||||
QCOMPARE( colorNode.key(), QString( "key1" ) );
|
||||
QCOMPARE( colorNode.color(), blackTransparent );
|
||||
QCOMPARE( colorNode.color( record, vars ), silver80 ); // Defaults to silver if given non-matching record/variables
|
||||
///
|
||||
/// Record
|
||||
///
|
||||
colorNode = ColorNode( QString( "key1" ) );
|
||||
QVERIFY( colorNode.isField() ); // Defaults to true if given key only
|
||||
QCOMPARE( colorNode.key(), QString( "key1" ) );
|
||||
QCOMPARE( colorNode.color(), blackTransparent );
|
||||
QCOMPARE( colorNode.color( record, vars ), silver80 ); // Defaults to silver if given non-matching record/variables
|
||||
|
||||
record["key1"] = "white";
|
||||
QCOMPARE( colorNode.color( record, vars ), white );
|
||||
record["key1"] = "white";
|
||||
QCOMPARE( colorNode.color( record, vars ), white );
|
||||
|
||||
record["key1"] = "red";
|
||||
QCOMPARE( colorNode.color( record, vars ), red );
|
||||
record["key1"] = "red";
|
||||
QCOMPARE( colorNode.color( record, vars ), red );
|
||||
|
||||
record["key1"] = "#FF0000";
|
||||
QCOMPARE( colorNode.color( record, vars ), red );
|
||||
record["key1"] = "#FF0000";
|
||||
QCOMPARE( colorNode.color( record, vars ), red );
|
||||
|
||||
record["key1"] = "#FFFF0000"; // ARGB
|
||||
QCOMPARE( colorNode.color( record, vars ), red );
|
||||
record["key1"] = "#FFFF0000"; // ARGB
|
||||
QCOMPARE( colorNode.color( record, vars ), red );
|
||||
|
||||
record["key1"] = "#8000FF00";
|
||||
QCOMPARE( colorNode.color( record, vars ), green80 );
|
||||
record["key1"] = "#8000FF00";
|
||||
QCOMPARE( colorNode.color( record, vars ), green80 );
|
||||
|
||||
colorNode.setKey( "key2" );
|
||||
QCOMPARE( colorNode.color( record, vars ), silver80 );
|
||||
record["key2"] = "#8000FF00";
|
||||
QCOMPARE( colorNode.color( record, vars ), green80 );
|
||||
colorNode.setKey( "key2" );
|
||||
QCOMPARE( colorNode.color( record, vars ), silver80 );
|
||||
record["key2"] = "#8000FF00";
|
||||
QCOMPARE( colorNode.color( record, vars ), green80 );
|
||||
|
||||
///
|
||||
/// Variable
|
||||
///
|
||||
colorNode = ColorNode( QString( "c1" ) );
|
||||
QVERIFY( colorNode.isField() ); // Defaults to true if given key only
|
||||
QCOMPARE( colorNode.key(), QString( "c1" ) );
|
||||
QCOMPARE( colorNode.color(), blackTransparent );
|
||||
QCOMPARE( colorNode.color( record, vars ), silver80 ); // Defaults to silver if given non-matching record/variables
|
||||
///
|
||||
/// Variable
|
||||
///
|
||||
colorNode = ColorNode( QString( "c1" ) );
|
||||
QVERIFY( colorNode.isField() ); // Defaults to true if given key only
|
||||
QCOMPARE( colorNode.key(), QString( "c1" ) );
|
||||
QCOMPARE( colorNode.color(), blackTransparent );
|
||||
QCOMPARE( colorNode.color( record, vars ), silver80 ); // Defaults to silver if given non-matching record/variables
|
||||
|
||||
{
|
||||
Variable c1( Variable::Type::COLOR, "c1", "white", Variable::Increment::PER_ITEM );
|
||||
vars.addVariable( c1 );
|
||||
}
|
||||
QCOMPARE( colorNode.color( NullRecord(), vars ), white );
|
||||
vars.incrementVariablesOnItem();
|
||||
QCOMPARE( colorNode.color( NullRecord(), vars ), white );
|
||||
{
|
||||
Variable c1( Variable::Type::COLOR, "c1", "white", Variable::Increment::PER_ITEM );
|
||||
vars.addVariable( c1 );
|
||||
}
|
||||
QCOMPARE( colorNode.color( NullRecord(), vars ), white );
|
||||
vars.incrementVariablesOnItem();
|
||||
QCOMPARE( colorNode.color( NullRecord(), vars ), white );
|
||||
|
||||
{
|
||||
Variable c1( Variable::Type::COLOR, "c1", "red", Variable::Increment::PER_ITEM );
|
||||
vars.addVariable( c1 );
|
||||
}
|
||||
QCOMPARE( colorNode.color( NullRecord(), vars ), red );
|
||||
{
|
||||
Variable c1( Variable::Type::COLOR, "c1", "red", Variable::Increment::PER_ITEM );
|
||||
vars.addVariable( c1 );
|
||||
}
|
||||
QCOMPARE( colorNode.color( NullRecord(), vars ), red );
|
||||
|
||||
{
|
||||
Variable c1( Variable::Type::COLOR, "c1", "#8000FF00", Variable::Increment::PER_ITEM );
|
||||
vars.addVariable( c1 );
|
||||
}
|
||||
QCOMPARE( colorNode.color( NullRecord(), vars ), green80 );
|
||||
{
|
||||
Variable c1( Variable::Type::COLOR, "c1", "#8000FF00", Variable::Increment::PER_ITEM );
|
||||
vars.addVariable( c1 );
|
||||
}
|
||||
QCOMPARE( colorNode.color( NullRecord(), vars ), green80 );
|
||||
|
||||
colorNode.setKey( "c2" );
|
||||
QCOMPARE( colorNode.color( record, vars ), silver80 );
|
||||
colorNode.setKey( "c2" );
|
||||
QCOMPARE( colorNode.color( record, vars ), silver80 );
|
||||
|
||||
{
|
||||
Variable c2( Variable::Type::COLOR, "c2", "#8000FF00", Variable::Increment::PER_ITEM );
|
||||
vars.addVariable( c2 );
|
||||
}
|
||||
QCOMPARE( colorNode.color( NullRecord(), vars ), green80 );
|
||||
{
|
||||
Variable c2( Variable::Type::COLOR, "c2", "#8000FF00", Variable::Increment::PER_ITEM );
|
||||
vars.addVariable( c2 );
|
||||
}
|
||||
QCOMPARE( colorNode.color( NullRecord(), vars ), green80 );
|
||||
|
||||
///
|
||||
/// Record beats variable
|
||||
///
|
||||
record["c2"] = "red";
|
||||
QCOMPARE( colorNode.color( record, vars ), red );
|
||||
///
|
||||
/// Record beats variable
|
||||
///
|
||||
record["c2"] = "red";
|
||||
QCOMPARE( colorNode.color( record, vars ), red );
|
||||
}
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
/* TestColorNode.h
|
||||
*
|
||||
* Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
|
||||
class TestColorNode : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void colorNode();
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
// TestColorNode.hpp
|
||||
//
|
||||
// Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of gLabels-qt.
|
||||
//
|
||||
// gLabels-qt is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// gLabels-qt is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
|
||||
class TestColorNode : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void colorNode();
|
||||
};
|
||||
@@ -1,28 +1,29 @@
|
||||
/* TestFileUtil.cpp
|
||||
*
|
||||
* Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// TestFileUtil.cpp
|
||||
//
|
||||
// Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of gLabels-qt.
|
||||
//
|
||||
// gLabels-qt is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// gLabels-qt is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#include "TestFileUtil.h"
|
||||
|
||||
#include "model/FileUtil.h"
|
||||
#include "TestFileUtil.hpp"
|
||||
|
||||
#include <QtDebug>
|
||||
#include "model/FileUtil.hpp"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
QTEST_MAIN(TestFileUtil)
|
||||
@@ -32,73 +33,73 @@ using namespace glabels::model;
|
||||
|
||||
void TestFileUtil::addExtension()
|
||||
{
|
||||
QCOMPARE( FileUtil::addExtension( "/tmp/file", ".ext" ), QString( "/tmp/file.ext" ) );
|
||||
QCOMPARE( FileUtil::addExtension( "/tmp/file.ext", ".ext" ), QString( "/tmp/file.ext" ) );
|
||||
QCOMPARE( FileUtil::addExtension( "/tmp/file.ext", ".txt" ), QString( "/tmp/file.ext.txt" ) );
|
||||
QCOMPARE( FileUtil::addExtension( "/tmp/file", "txt" ), QString( "/tmp/filetxt" ) );
|
||||
QCOMPARE( FileUtil::addExtension( "/tmp/filetxt", "txt" ), QString( "/tmp/filetxt" ) );
|
||||
QCOMPARE( FileUtil::addExtension( "/tmp/file", ".ext" ), QString( "/tmp/file.ext" ) );
|
||||
QCOMPARE( FileUtil::addExtension( "/tmp/file.ext", ".ext" ), QString( "/tmp/file.ext" ) );
|
||||
QCOMPARE( FileUtil::addExtension( "/tmp/file.ext", ".txt" ), QString( "/tmp/file.ext.txt" ) );
|
||||
QCOMPARE( FileUtil::addExtension( "/tmp/file", "txt" ), QString( "/tmp/filetxt" ) );
|
||||
QCOMPARE( FileUtil::addExtension( "/tmp/filetxt", "txt" ), QString( "/tmp/filetxt" ) );
|
||||
}
|
||||
|
||||
|
||||
void TestFileUtil::systemTemplatesDir()
|
||||
{
|
||||
QDir dir = FileUtil::systemTemplatesDir();
|
||||
QVERIFY( dir.exists() );
|
||||
QVERIFY( dir.isReadable() );
|
||||
QVERIFY( dir.path().endsWith( "templates" ) );
|
||||
QDir dir = FileUtil::systemTemplatesDir();
|
||||
QVERIFY( dir.exists() );
|
||||
QVERIFY( dir.isReadable() );
|
||||
QVERIFY( dir.path().endsWith( "templates" ) );
|
||||
}
|
||||
|
||||
|
||||
void TestFileUtil::manualUserTemplatesDir()
|
||||
{
|
||||
QDir dir = FileUtil::manualUserTemplatesDir();
|
||||
QVERIFY( dir.exists() );
|
||||
QVERIFY( dir.isReadable() );
|
||||
QVERIFY( dir.path().endsWith( ".glabels" ) );
|
||||
QDir dir = FileUtil::manualUserTemplatesDir();
|
||||
QVERIFY( dir.exists() );
|
||||
QVERIFY( dir.isReadable() );
|
||||
QVERIFY( dir.path().endsWith( ".glabels" ) );
|
||||
}
|
||||
|
||||
|
||||
void TestFileUtil::userTemplatesDir()
|
||||
{
|
||||
QDir dir = FileUtil::userTemplatesDir();
|
||||
QVERIFY( dir.exists() );
|
||||
QVERIFY( dir.isReadable() );
|
||||
QFileInfo fileInfo( dir.path() );
|
||||
QVERIFY( fileInfo.isWritable() );
|
||||
QDir dir = FileUtil::userTemplatesDir();
|
||||
QVERIFY( dir.exists() );
|
||||
QVERIFY( dir.isReadable() );
|
||||
QFileInfo fileInfo( dir.path() );
|
||||
QVERIFY( fileInfo.isWritable() );
|
||||
}
|
||||
|
||||
|
||||
void TestFileUtil::translationsDir()
|
||||
{
|
||||
QDir dir = FileUtil::translationsDir();
|
||||
QVERIFY( dir.exists() );
|
||||
QVERIFY( dir.isReadable() );
|
||||
QVERIFY( dir.path().endsWith( "translations" ) );
|
||||
QDir dir = FileUtil::translationsDir();
|
||||
QVERIFY( dir.exists() );
|
||||
QVERIFY( dir.isReadable() );
|
||||
QVERIFY( dir.path().endsWith( "translations" ) );
|
||||
}
|
||||
|
||||
|
||||
void TestFileUtil::makeRelativeIfInDir_data()
|
||||
{
|
||||
QTest::addColumn<QString>( "dir" );
|
||||
QTest::addColumn<QString>( "filename" );
|
||||
QTest::addColumn<QString>( "expected" );
|
||||
QTest::addColumn<QString>( "dir" );
|
||||
QTest::addColumn<QString>( "filename" );
|
||||
QTest::addColumn<QString>( "expected" );
|
||||
|
||||
QTest::newRow( "1" ) << "/dir/subdir" << "/dir/subdir/filename" << "filename";
|
||||
QTest::newRow( "2" ) << "/dir/subdir" << "filename" << "filename";
|
||||
QTest::newRow( "3" ) << "/dir" << "subdir/filename" << "subdir/filename";
|
||||
QTest::newRow( "4" ) << "/dir" << "/dir/subdir/subdir/filename" << "subdir/subdir/filename";
|
||||
QTest::newRow( "5" ) << "/dir/subdir" << "/dir/subdir/subdir/filename" << "subdir/filename";
|
||||
QTest::newRow( "6" ) << "/dir/subdir" << "/dir/subdir2/filename" << "/dir/subdir2/filename";
|
||||
QTest::newRow( "7" ) << "/dir2/subdir" << "/dir/subdir/filename" << "/dir/subdir/filename";
|
||||
QTest::newRow( "8" ) << "/dir/subdir" << "/dir/filename" << "/dir/filename";
|
||||
QTest::newRow( "1" ) << "/dir/subdir" << "/dir/subdir/filename" << "filename";
|
||||
QTest::newRow( "2" ) << "/dir/subdir" << "filename" << "filename";
|
||||
QTest::newRow( "3" ) << "/dir" << "subdir/filename" << "subdir/filename";
|
||||
QTest::newRow( "4" ) << "/dir" << "/dir/subdir/subdir/filename" << "subdir/subdir/filename";
|
||||
QTest::newRow( "5" ) << "/dir/subdir" << "/dir/subdir/subdir/filename" << "subdir/filename";
|
||||
QTest::newRow( "6" ) << "/dir/subdir" << "/dir/subdir2/filename" << "/dir/subdir2/filename";
|
||||
QTest::newRow( "7" ) << "/dir2/subdir" << "/dir/subdir/filename" << "/dir/subdir/filename";
|
||||
QTest::newRow( "8" ) << "/dir/subdir" << "/dir/filename" << "/dir/filename";
|
||||
}
|
||||
|
||||
|
||||
void TestFileUtil::makeRelativeIfInDir()
|
||||
{
|
||||
QFETCH( QString, dir );
|
||||
QFETCH( QString, filename );
|
||||
QFETCH( QString, expected );
|
||||
QFETCH( QString, dir );
|
||||
QFETCH( QString, filename );
|
||||
QFETCH( QString, expected );
|
||||
|
||||
QCOMPARE( FileUtil::makeRelativeIfInDir( QDir( dir ), filename ), expected );
|
||||
QCOMPARE( FileUtil::makeRelativeIfInDir( QDir( dir ), filename ), expected );
|
||||
}
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
/* TestFileUtil.h
|
||||
*
|
||||
* Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
|
||||
class TestFileUtil : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void addExtension();
|
||||
void systemTemplatesDir();
|
||||
void manualUserTemplatesDir();
|
||||
void userTemplatesDir();
|
||||
void translationsDir();
|
||||
void makeRelativeIfInDir_data();
|
||||
void makeRelativeIfInDir();
|
||||
};
|
||||
@@ -0,0 +1,37 @@
|
||||
// TestFileUtil.hpp
|
||||
//
|
||||
// Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of gLabels-qt.
|
||||
//
|
||||
// gLabels-qt is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// gLabels-qt is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
|
||||
class TestFileUtil : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void addExtension();
|
||||
void systemTemplatesDir();
|
||||
void manualUserTemplatesDir();
|
||||
void userTemplatesDir();
|
||||
void translationsDir();
|
||||
void makeRelativeIfInDir_data();
|
||||
void makeRelativeIfInDir();
|
||||
};
|
||||
+256
-256
@@ -1,40 +1,40 @@
|
||||
/* TestMerge.cpp
|
||||
*
|
||||
* Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// TestMerge.cpp
|
||||
//
|
||||
// Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of gLabels-qt.
|
||||
//
|
||||
// gLabels-qt is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// gLabels-qt is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
|
||||
#include "TestMerge.h"
|
||||
#include "TestMerge.hpp"
|
||||
|
||||
#include "merge/Factory.h"
|
||||
#include "merge/None.h"
|
||||
#include "merge/TextCsv.h"
|
||||
#include "merge/TextCsvKeys.h"
|
||||
#include "merge/TextTsv.h"
|
||||
#include "merge/TextTsvKeys.h"
|
||||
#include "merge/TextColon.h"
|
||||
#include "merge/TextColonKeys.h"
|
||||
#include "merge/TextSemicolon.h"
|
||||
#include "merge/TextSemicolonKeys.h"
|
||||
#include "merge/Factory.hpp"
|
||||
#include "merge/None.hpp"
|
||||
#include "merge/TextCsv.hpp"
|
||||
#include "merge/TextCsvKeys.hpp"
|
||||
#include "merge/TextTsv.hpp"
|
||||
#include "merge/TextTsvKeys.hpp"
|
||||
#include "merge/TextColon.hpp"
|
||||
#include "merge/TextColonKeys.hpp"
|
||||
#include "merge/TextSemicolon.hpp"
|
||||
#include "merge/TextSemicolonKeys.hpp"
|
||||
|
||||
#include "merge/Record.h"
|
||||
#include "merge/Record.hpp"
|
||||
|
||||
#include <QtDebug>
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
QTEST_MAIN(TestMerge)
|
||||
@@ -46,300 +46,300 @@ using namespace glabels::merge;
|
||||
|
||||
void TestMerge::initTestCase()
|
||||
{
|
||||
Factory::init();
|
||||
Factory::init();
|
||||
}
|
||||
|
||||
|
||||
void TestMerge::factory_data()
|
||||
{
|
||||
QTest::addColumn<QString>( "id" );
|
||||
QTest::addColumn<QString>( "name" );
|
||||
QTest::addColumn<Factory::SourceType>( "type" );
|
||||
QTest::addColumn<int>( "index" );
|
||||
QTest::addColumn<QString>( "id" );
|
||||
QTest::addColumn<QString>( "name" );
|
||||
QTest::addColumn<Factory::SourceType>( "type" );
|
||||
QTest::addColumn<int>( "index" );
|
||||
|
||||
int index = 0;
|
||||
QTest::newRow( "None" ) << None::id() << "None" << Factory::NONE << index++;
|
||||
QTest::newRow( "TextCsv" ) << TextCsv::id() << "Text: Comma Separated Values (CSV)" << Factory::FILE << index++;
|
||||
QTest::newRow( "TextCsvKeys" ) << TextCsvKeys::id() << "Text: Comma Separated Values (CSV), keys on line 1" << Factory::FILE << index++;
|
||||
QTest::newRow( "TextTsv" ) << TextTsv::id() << "Text: Tab Separated Values (TSV)" << Factory::FILE << index++;
|
||||
QTest::newRow( "TextTsvKeys" ) << TextTsvKeys::id() << "Text: Tab Separated Values (TSV), keys on line 1" << Factory::FILE << index++;
|
||||
QTest::newRow( "TextColon" ) << TextColon::id() << "Text: Colon Separated Values" << Factory::FILE << index++;
|
||||
QTest::newRow( "TextColonKeys" ) << TextColonKeys::id() << "Text: Colon Separated Values, keys on line 1" << Factory::FILE << index++;
|
||||
QTest::newRow( "TextSemicolon" ) << TextSemicolon::id() << "Text: Semicolon Separated Values" << Factory::FILE << index++;
|
||||
QTest::newRow( "TextSemicolonKeys" ) << TextSemicolonKeys::id() << "Text: Semicolon Separated Values, keys on line 1" << Factory::FILE << index++;
|
||||
int index = 0;
|
||||
QTest::newRow( "None" ) << None::id() << "None" << Factory::NONE << index++;
|
||||
QTest::newRow( "TextCsv" ) << TextCsv::id() << "Text: Comma Separated Values (CSV)" << Factory::FILE << index++;
|
||||
QTest::newRow( "TextCsvKeys" ) << TextCsvKeys::id() << "Text: Comma Separated Values (CSV), keys on line 1" << Factory::FILE << index++;
|
||||
QTest::newRow( "TextTsv" ) << TextTsv::id() << "Text: Tab Separated Values (TSV)" << Factory::FILE << index++;
|
||||
QTest::newRow( "TextTsvKeys" ) << TextTsvKeys::id() << "Text: Tab Separated Values (TSV), keys on line 1" << Factory::FILE << index++;
|
||||
QTest::newRow( "TextColon" ) << TextColon::id() << "Text: Colon Separated Values" << Factory::FILE << index++;
|
||||
QTest::newRow( "TextColonKeys" ) << TextColonKeys::id() << "Text: Colon Separated Values, keys on line 1" << Factory::FILE << index++;
|
||||
QTest::newRow( "TextSemicolon" ) << TextSemicolon::id() << "Text: Semicolon Separated Values" << Factory::FILE << index++;
|
||||
QTest::newRow( "TextSemicolonKeys" ) << TextSemicolonKeys::id() << "Text: Semicolon Separated Values, keys on line 1" << Factory::FILE << index++;
|
||||
}
|
||||
|
||||
|
||||
void TestMerge::factory()
|
||||
{
|
||||
QFETCH( QString, id );
|
||||
QFETCH( QString, name );
|
||||
QFETCH( Factory::SourceType, type );
|
||||
QFETCH( int, index );
|
||||
QFETCH( QString, id );
|
||||
QFETCH( QString, name );
|
||||
QFETCH( Factory::SourceType, type );
|
||||
QFETCH( int, index );
|
||||
|
||||
QVERIFY( Factory::nameList().contains( name ) );
|
||||
QVERIFY( Factory::nameList().contains( name ) );
|
||||
|
||||
QString outName = Factory::idToName( id );
|
||||
QCOMPARE( outName, name );
|
||||
QString outName = Factory::idToName( id );
|
||||
QCOMPARE( outName, name );
|
||||
|
||||
QString outId = Factory::nameToId( name );
|
||||
QCOMPARE( outId, id );
|
||||
QString outId = Factory::nameToId( name );
|
||||
QCOMPARE( outId, id );
|
||||
|
||||
Factory::SourceType outType = Factory::idToType( id );
|
||||
QCOMPARE( outType, type );
|
||||
Factory::SourceType outType = Factory::idToType( id );
|
||||
QCOMPARE( outType, type );
|
||||
|
||||
outId = Factory::indexToId( index );
|
||||
QCOMPARE( outId, id );
|
||||
outId = Factory::indexToId( index );
|
||||
QCOMPARE( outId, id );
|
||||
|
||||
Merge* merge = Factory::createMerge( id );
|
||||
QVERIFY( merge );
|
||||
QCOMPARE( merge->id(), id );
|
||||
Merge* merge = Factory::createMerge( id );
|
||||
QVERIFY( merge );
|
||||
QCOMPARE( merge->id(), id );
|
||||
|
||||
Merge* cloneMerge = merge->clone();
|
||||
QCOMPARE( cloneMerge->id(), merge->id() );
|
||||
delete cloneMerge;
|
||||
delete merge;
|
||||
Merge* cloneMerge = merge->clone();
|
||||
QCOMPARE( cloneMerge->id(), merge->id() );
|
||||
delete cloneMerge;
|
||||
delete merge;
|
||||
}
|
||||
|
||||
|
||||
void TestMerge::factoryNotRegistered()
|
||||
{
|
||||
QString id( "unregistered" );
|
||||
Merge* merge = Factory::createMerge( id );
|
||||
QVERIFY( merge );
|
||||
QVERIFY( merge->id() != id );
|
||||
QCOMPARE( merge->id(), None::id() );
|
||||
delete merge;
|
||||
QString id( "unregistered" );
|
||||
Merge* merge = Factory::createMerge( id );
|
||||
QVERIFY( merge );
|
||||
QVERIFY( merge->id() != id );
|
||||
QCOMPARE( merge->id(), None::id() );
|
||||
delete merge;
|
||||
}
|
||||
|
||||
|
||||
void TestMerge::text_data()
|
||||
{
|
||||
QTest::addColumn<QString>( "id" );
|
||||
QTest::addColumn<bool>( "keyed" );
|
||||
QTest::addColumn<char>( "delim" );
|
||||
QTest::addColumn<QString>( "id" );
|
||||
QTest::addColumn<bool>( "keyed" );
|
||||
QTest::addColumn<char>( "delim" );
|
||||
|
||||
QTest::newRow( "TextCsv" ) << TextCsv::id() << false << ',';
|
||||
QTest::newRow( "TextCsvKeys" ) << TextCsvKeys::id() << true << ',';
|
||||
QTest::newRow( "TextTsv" ) << TextTsv::id() << false << '\t';
|
||||
QTest::newRow( "TextTsvKeys" ) << TextTsvKeys::id() << true << '\t';
|
||||
QTest::newRow( "TextColon" ) << TextColon::id() << false << ':';
|
||||
QTest::newRow( "TextColonKeys" ) << TextColonKeys::id() << true << ':';
|
||||
QTest::newRow( "TextSemicolon" ) << TextSemicolon::id() << false << ';';
|
||||
QTest::newRow( "TextSemicolonKeys" ) << TextSemicolonKeys::id() << true << ';';
|
||||
QTest::newRow( "TextCsv" ) << TextCsv::id() << false << ',';
|
||||
QTest::newRow( "TextCsvKeys" ) << TextCsvKeys::id() << true << ',';
|
||||
QTest::newRow( "TextTsv" ) << TextTsv::id() << false << '\t';
|
||||
QTest::newRow( "TextTsvKeys" ) << TextTsvKeys::id() << true << '\t';
|
||||
QTest::newRow( "TextColon" ) << TextColon::id() << false << ':';
|
||||
QTest::newRow( "TextColonKeys" ) << TextColonKeys::id() << true << ':';
|
||||
QTest::newRow( "TextSemicolon" ) << TextSemicolon::id() << false << ';';
|
||||
QTest::newRow( "TextSemicolonKeys" ) << TextSemicolonKeys::id() << true << ';';
|
||||
}
|
||||
|
||||
|
||||
void TestMerge::text()
|
||||
{
|
||||
QFETCH( QString, id );
|
||||
QFETCH( bool, keyed );
|
||||
QFETCH( char, delim );
|
||||
QFETCH( QString, id );
|
||||
QFETCH( bool, keyed );
|
||||
QFETCH( char, delim );
|
||||
|
||||
QTemporaryFile file;
|
||||
file.open();
|
||||
if ( keyed )
|
||||
{
|
||||
file.write( "header1" );
|
||||
file.putChar( delim );
|
||||
file.write( "\"header 2\"" );
|
||||
file.putChar( delim );
|
||||
file.write( "header3\r\n" );
|
||||
}
|
||||
file.write( " val11" ); // Leading spaces in SIMPLE entry
|
||||
file.putChar( delim );
|
||||
file.write( "\"\"\"val 12\"\"\"" ); // 2DQUOTE at beginning and end of DQUOTE entry
|
||||
file.putChar( delim );
|
||||
file.write( " \"val 13\"\n" ); // Leading spaces before DQUOTE entry, end line with LF only
|
||||
QTemporaryFile file;
|
||||
file.open();
|
||||
if ( keyed )
|
||||
{
|
||||
file.write( "header1" );
|
||||
file.putChar( delim );
|
||||
file.write( "\"header 2\"" );
|
||||
file.putChar( delim );
|
||||
file.write( "header3\r\n" );
|
||||
}
|
||||
file.write( " val11" ); // Leading spaces in SIMPLE entry
|
||||
file.putChar( delim );
|
||||
file.write( "\"\"\"val 12\"\"\"" ); // 2DQUOTE at beginning and end of DQUOTE entry
|
||||
file.putChar( delim );
|
||||
file.write( " \"val 13\"\n" ); // Leading spaces before DQUOTE entry, end line with LF only
|
||||
|
||||
file.write( "\" val21\"\"\"" ); // Leading spaces within DQUOTE entry, 2DQUOTE at end
|
||||
file.putChar( delim );
|
||||
file.write( "\"\"\"val 22\"" ); // 2DQUOTE at beginning of DQUOTE entry
|
||||
file.putChar( delim );
|
||||
file.write( "\r\n" ); // Last field blank
|
||||
file.write( "\" val21\"\"\"" ); // Leading spaces within DQUOTE entry, 2DQUOTE at end
|
||||
file.putChar( delim );
|
||||
file.write( "\"\"\"val 22\"" ); // 2DQUOTE at beginning of DQUOTE entry
|
||||
file.putChar( delim );
|
||||
file.write( "\r\n" ); // Last field blank
|
||||
|
||||
file.write( "\"\"\"\"\"\"" ); // 2 2DQUOTES alone in DQUOTE entry
|
||||
file.putChar( delim );
|
||||
file.write( "val \"32" ); // DQUOTE in SIMPLE entry
|
||||
file.putChar( delim );
|
||||
file.write( "val \"\\\"33\r\n" ); // DQUOTE backslashed-DQUOTE in SIMPLE entry
|
||||
file.write( "\"\"\"\"\"\"" ); // 2 2DQUOTES alone in DQUOTE entry
|
||||
file.putChar( delim );
|
||||
file.write( "val \"32" ); // DQUOTE in SIMPLE entry
|
||||
file.putChar( delim );
|
||||
file.write( "val \"\\\"33\r\n" ); // DQUOTE backslashed-DQUOTE in SIMPLE entry
|
||||
|
||||
file.putChar( delim ); file.putChar( delim ); // All fields blank
|
||||
file.write( "\r\n" );
|
||||
file.putChar( delim ); file.putChar( delim ); // All fields blank
|
||||
file.write( "\r\n" );
|
||||
|
||||
file.write( "val\\n \\t \\r \\\\ \\x51" ); // Backslashed-n/-t/-r/-backslash/-x in SIMPLE entry
|
||||
file.putChar( delim );
|
||||
file.write( "\"val\\n \\t \\r \\\\ \\x52\"" ); // Backslashed-n/-t/-r/-backslash/-x in QUOTE entry
|
||||
file.write( "\r\n" ); // No last delim
|
||||
file.write( "val\\n \\t \\r \\\\ \\x51" ); // Backslashed-n/-t/-r/-backslash/-x in SIMPLE entry
|
||||
file.putChar( delim );
|
||||
file.write( "\"val\\n \\t \\r \\\\ \\x52\"" ); // Backslashed-n/-t/-r/-backslash/-x in QUOTE entry
|
||||
file.write( "\r\n" ); // No last delim
|
||||
|
||||
file.write( "\"val \"\"61\"" ); // 2DQUOTE in middle of DQUOTE entry
|
||||
file.putChar( delim );
|
||||
file.write( "\"val\"\"" ); file.putChar( delim ); file.write( "\r\n\\\"\u2019\\\\52\"" ); // 2DQUOTE delim CRLF backslashed-DQUOTE U+2019 backslashed-backslash
|
||||
file.putChar( delim );
|
||||
file.write( "\"val63\"" ); // End without CRLF
|
||||
file.close();
|
||||
file.write( "\"val \"\"61\"" ); // 2DQUOTE in middle of DQUOTE entry
|
||||
file.putChar( delim );
|
||||
file.write( "\"val\"\"" ); file.putChar( delim ); file.write( "\r\n\\\"\u2019\\\\52\"" ); // 2DQUOTE delim CRLF backslashed-DQUOTE U+2019 backslashed-backslash
|
||||
file.putChar( delim );
|
||||
file.write( "\"val63\"" ); // End without CRLF
|
||||
file.close();
|
||||
|
||||
Merge* merge = Factory::createMerge( id );
|
||||
QCOMPARE( merge->id(), id );
|
||||
Merge* merge = Factory::createMerge( id );
|
||||
QCOMPARE( merge->id(), id );
|
||||
|
||||
merge->setSource( file.fileName() );
|
||||
QCOMPARE( merge->source(), file.fileName() );
|
||||
merge->setSource( file.fileName() );
|
||||
QCOMPARE( merge->source(), file.fileName() );
|
||||
|
||||
const QList<Record>& recordList = merge->recordList();
|
||||
QCOMPARE( recordList.size(), 6 );
|
||||
const QList<Record>& recordList = merge->recordList();
|
||||
QCOMPARE( recordList.size(), 6 );
|
||||
|
||||
//
|
||||
// Records
|
||||
//
|
||||
const char* h1 = keyed ? "header1" : "1";
|
||||
const char* h2 = keyed ? "header 2" : "2";
|
||||
const char* h3 = keyed ? "header3" : "3";
|
||||
Record record;
|
||||
//
|
||||
// Records
|
||||
//
|
||||
const char* h1 = keyed ? "header1" : "1";
|
||||
const char* h2 = keyed ? "header 2" : "2";
|
||||
const char* h3 = keyed ? "header3" : "3";
|
||||
Record record;
|
||||
|
||||
record = recordList[0];
|
||||
QVERIFY( record.contains( h1 ) );
|
||||
QCOMPARE( record.value( h1 ), QString( " val11" ) );
|
||||
QVERIFY( record.contains( h2 ) );
|
||||
QCOMPARE( record.value( h2 ), QString( "\"val 12\"" ) );
|
||||
QVERIFY( record.contains( h3 ) );
|
||||
QCOMPARE( record.value( h3 ), QString( " \"val 13\"" ) ); // NOTE: Treats as unquoted due to leading spaces
|
||||
record = recordList[0];
|
||||
QVERIFY( record.contains( h1 ) );
|
||||
QCOMPARE( record.value( h1 ), QString( " val11" ) );
|
||||
QVERIFY( record.contains( h2 ) );
|
||||
QCOMPARE( record.value( h2 ), QString( "\"val 12\"" ) );
|
||||
QVERIFY( record.contains( h3 ) );
|
||||
QCOMPARE( record.value( h3 ), QString( " \"val 13\"" ) ); // NOTE: Treats as unquoted due to leading spaces
|
||||
|
||||
record = recordList[1];
|
||||
QVERIFY( record.contains( h1 ) );
|
||||
QCOMPARE( record.value( h1 ), QString( " val21\"" ) );
|
||||
QVERIFY( record.contains( h2 ) );
|
||||
QCOMPARE( record.value( h2 ), QString( "\"val 22" ) );
|
||||
QVERIFY( record.contains( h3 ) );
|
||||
QCOMPARE( record.value( h3 ), QString( "" ) );
|
||||
record = recordList[1];
|
||||
QVERIFY( record.contains( h1 ) );
|
||||
QCOMPARE( record.value( h1 ), QString( " val21\"" ) );
|
||||
QVERIFY( record.contains( h2 ) );
|
||||
QCOMPARE( record.value( h2 ), QString( "\"val 22" ) );
|
||||
QVERIFY( record.contains( h3 ) );
|
||||
QCOMPARE( record.value( h3 ), QString( "" ) );
|
||||
|
||||
record = recordList[2];
|
||||
QVERIFY( record.contains( h1 ) );
|
||||
QCOMPARE( record.value( h1 ), QString( "\"\"" ) );
|
||||
QVERIFY( record.contains( h2 ) );
|
||||
QCOMPARE( record.value( h2 ), QString( "val \"32" ) );
|
||||
QVERIFY( record.contains( h3 ) );
|
||||
QCOMPARE( record.value( h3 ), QString( "val \"\"33" ) );
|
||||
record = recordList[2];
|
||||
QVERIFY( record.contains( h1 ) );
|
||||
QCOMPARE( record.value( h1 ), QString( "\"\"" ) );
|
||||
QVERIFY( record.contains( h2 ) );
|
||||
QCOMPARE( record.value( h2 ), QString( "val \"32" ) );
|
||||
QVERIFY( record.contains( h3 ) );
|
||||
QCOMPARE( record.value( h3 ), QString( "val \"\"33" ) );
|
||||
|
||||
record = recordList[3];
|
||||
QVERIFY( record.contains( h1 ) );
|
||||
QCOMPARE( record.value( h1 ), QString( "" ) );
|
||||
QVERIFY( record.contains( h2 ) );
|
||||
QCOMPARE( record.value( h2 ), QString( "" ) );
|
||||
QVERIFY( record.contains( h3 ) );
|
||||
QCOMPARE( record.value( h3 ), QString( "" ) );
|
||||
record = recordList[3];
|
||||
QVERIFY( record.contains( h1 ) );
|
||||
QCOMPARE( record.value( h1 ), QString( "" ) );
|
||||
QVERIFY( record.contains( h2 ) );
|
||||
QCOMPARE( record.value( h2 ), QString( "" ) );
|
||||
QVERIFY( record.contains( h3 ) );
|
||||
QCOMPARE( record.value( h3 ), QString( "" ) );
|
||||
|
||||
record = recordList[4];
|
||||
QVERIFY( record.contains( h1 ) );
|
||||
QCOMPARE( record.value( h1 ), QString( "val\n \t r \\ x51" ) );
|
||||
QVERIFY( record.contains( h2 ) );
|
||||
QCOMPARE( record.value( h2 ), QString( "val\n \t r \\ x52" ) );
|
||||
QVERIFY( !record.contains( h3 ) );
|
||||
record = recordList[4];
|
||||
QVERIFY( record.contains( h1 ) );
|
||||
QCOMPARE( record.value( h1 ), QString( "val\n \t r \\ x51" ) );
|
||||
QVERIFY( record.contains( h2 ) );
|
||||
QCOMPARE( record.value( h2 ), QString( "val\n \t r \\ x52" ) );
|
||||
QVERIFY( !record.contains( h3 ) );
|
||||
|
||||
record = recordList[5];
|
||||
QVERIFY( record.contains( h1 ) );
|
||||
QCOMPARE( record.value( h1 ), QString( "val \"61" ) );
|
||||
QVERIFY( record.contains( h2 ) );
|
||||
QCOMPARE( record.value( h2 ), QString( "val\"" ).append( delim ).append( "\n\"\u2019\\52" ) ); // NOTE: CR missing (QIODevice::Text strips all CRs from stream)
|
||||
QVERIFY( record.contains( h3 ) );
|
||||
QCOMPARE( record.value( h3 ), QString( "val63" ) );
|
||||
record = recordList[5];
|
||||
QVERIFY( record.contains( h1 ) );
|
||||
QCOMPARE( record.value( h1 ), QString( "val \"61" ) );
|
||||
QVERIFY( record.contains( h2 ) );
|
||||
QCOMPARE( record.value( h2 ), QString( "val\"" ).append( delim ).append( "\n\"\u2019\\52" ) ); // NOTE: CR missing (QIODevice::Text strips all CRs from stream)
|
||||
QVERIFY( record.contains( h3 ) );
|
||||
QCOMPARE( record.value( h3 ), QString( "val63" ) );
|
||||
|
||||
//
|
||||
// Selection
|
||||
//
|
||||
QCOMPARE( merge->nSelectedRecords(), 6 ); // Initially all selected
|
||||
merge->unselectAll();
|
||||
QCOMPARE( merge->nSelectedRecords(), 0 );
|
||||
//
|
||||
// Selection
|
||||
//
|
||||
QCOMPARE( merge->nSelectedRecords(), 6 ); // Initially all selected
|
||||
merge->unselectAll();
|
||||
QCOMPARE( merge->nSelectedRecords(), 0 );
|
||||
|
||||
merge->setSelected( 1 );
|
||||
QCOMPARE( merge->nSelectedRecords(), 1 );
|
||||
QCOMPARE( merge->selectedRecords().size(), 1 );
|
||||
merge->setSelected( 1 );
|
||||
QCOMPARE( merge->nSelectedRecords(), 1 );
|
||||
QCOMPARE( merge->selectedRecords().size(), 1 );
|
||||
|
||||
merge->setSelected( 1, false );
|
||||
QCOMPARE( merge->nSelectedRecords(), 0 );
|
||||
QCOMPARE( merge->selectedRecords().size(), 0 );
|
||||
merge->setSelected( 1, false );
|
||||
QCOMPARE( merge->nSelectedRecords(), 0 );
|
||||
QCOMPARE( merge->selectedRecords().size(), 0 );
|
||||
|
||||
merge->setSelected( 0 );
|
||||
merge->setSelected( 3 );
|
||||
QCOMPARE( merge->nSelectedRecords(), 2 );
|
||||
QCOMPARE( merge->selectedRecords().size(), 2 );
|
||||
QCOMPARE( merge->selectedRecords().first(), recordList[0] );
|
||||
QCOMPARE( merge->selectedRecords().last(), recordList[3] );
|
||||
merge->setSelected( 0 );
|
||||
merge->setSelected( 3 );
|
||||
QCOMPARE( merge->nSelectedRecords(), 2 );
|
||||
QCOMPARE( merge->selectedRecords().size(), 2 );
|
||||
QCOMPARE( merge->selectedRecords().first(), recordList[0] );
|
||||
QCOMPARE( merge->selectedRecords().last(), recordList[3] );
|
||||
|
||||
merge->setSelected( 0, false );
|
||||
QCOMPARE( merge->nSelectedRecords(), 1 );
|
||||
QCOMPARE( merge->selectedRecords().size(), 1 );
|
||||
merge->setSelected( 0, false );
|
||||
QCOMPARE( merge->nSelectedRecords(), 1 );
|
||||
QCOMPARE( merge->selectedRecords().size(), 1 );
|
||||
|
||||
//
|
||||
// Keys
|
||||
//
|
||||
QStringList keys = merge->keys();
|
||||
QCOMPARE( keys.size(), 3 );
|
||||
QCOMPARE( keys[0], QString( h1 ) );
|
||||
QCOMPARE( keys[1], QString( h2 ) );
|
||||
QCOMPARE( keys[2], QString( h3 ) );
|
||||
QCOMPARE( merge->primaryKey(), QString( h1 ) );
|
||||
//
|
||||
// Keys
|
||||
//
|
||||
QStringList keys = merge->keys();
|
||||
QCOMPARE( keys.size(), 3 );
|
||||
QCOMPARE( keys[0], QString( h1 ) );
|
||||
QCOMPARE( keys[1], QString( h2 ) );
|
||||
QCOMPARE( keys[2], QString( h3 ) );
|
||||
QCOMPARE( merge->primaryKey(), QString( h1 ) );
|
||||
|
||||
//
|
||||
// Clone
|
||||
//
|
||||
merge->unselectAll();
|
||||
merge->setSelected( 0 );
|
||||
QCOMPARE( merge->nSelectedRecords(), 1 );
|
||||
//
|
||||
// Clone
|
||||
//
|
||||
merge->unselectAll();
|
||||
merge->setSelected( 0 );
|
||||
QCOMPARE( merge->nSelectedRecords(), 1 );
|
||||
|
||||
Merge* cloneMerge = merge->clone();
|
||||
QCOMPARE( cloneMerge->id(), merge->id() );
|
||||
QCOMPARE( cloneMerge->source(), merge->source() );
|
||||
QCOMPARE( cloneMerge->recordList().size(), merge->recordList().size() );
|
||||
QCOMPARE( cloneMerge->recordList()[0], merge->recordList()[0] );
|
||||
QCOMPARE( cloneMerge->recordList()[1], merge->recordList()[1] );
|
||||
QCOMPARE( cloneMerge->recordList()[2], merge->recordList()[2] );
|
||||
QCOMPARE( cloneMerge->recordList()[3], merge->recordList()[3] );
|
||||
QCOMPARE( cloneMerge->recordList()[4], merge->recordList()[4] );
|
||||
QCOMPARE( cloneMerge->recordList()[5], merge->recordList()[5] );
|
||||
QCOMPARE( cloneMerge->nSelectedRecords(), merge->nSelectedRecords() );
|
||||
QCOMPARE( cloneMerge->selectedRecords().size(), merge->selectedRecords().size() );
|
||||
QCOMPARE( cloneMerge->selectedRecords()[0], merge->selectedRecords()[0] );
|
||||
QCOMPARE( cloneMerge->keys(), merge->keys() );
|
||||
QCOMPARE( cloneMerge->primaryKey(), merge->primaryKey() );
|
||||
delete cloneMerge;
|
||||
delete merge;
|
||||
Merge* cloneMerge = merge->clone();
|
||||
QCOMPARE( cloneMerge->id(), merge->id() );
|
||||
QCOMPARE( cloneMerge->source(), merge->source() );
|
||||
QCOMPARE( cloneMerge->recordList().size(), merge->recordList().size() );
|
||||
QCOMPARE( cloneMerge->recordList()[0], merge->recordList()[0] );
|
||||
QCOMPARE( cloneMerge->recordList()[1], merge->recordList()[1] );
|
||||
QCOMPARE( cloneMerge->recordList()[2], merge->recordList()[2] );
|
||||
QCOMPARE( cloneMerge->recordList()[3], merge->recordList()[3] );
|
||||
QCOMPARE( cloneMerge->recordList()[4], merge->recordList()[4] );
|
||||
QCOMPARE( cloneMerge->recordList()[5], merge->recordList()[5] );
|
||||
QCOMPARE( cloneMerge->nSelectedRecords(), merge->nSelectedRecords() );
|
||||
QCOMPARE( cloneMerge->selectedRecords().size(), merge->selectedRecords().size() );
|
||||
QCOMPARE( cloneMerge->selectedRecords()[0], merge->selectedRecords()[0] );
|
||||
QCOMPARE( cloneMerge->keys(), merge->keys() );
|
||||
QCOMPARE( cloneMerge->primaryKey(), merge->primaryKey() );
|
||||
delete cloneMerge;
|
||||
delete merge;
|
||||
}
|
||||
|
||||
|
||||
void TestMerge::none()
|
||||
{
|
||||
None none;
|
||||
QCOMPARE( none.id(), QString( "None" ) );
|
||||
None none;
|
||||
QCOMPARE( none.id(), QString( "None" ) );
|
||||
|
||||
None* cloneNone = none.clone();
|
||||
QCOMPARE( cloneNone->id(), none.id() );
|
||||
QCOMPARE( cloneNone->keys(), none.keys() );
|
||||
QCOMPARE( cloneNone->primaryKey(), none.primaryKey() );
|
||||
delete cloneNone;
|
||||
None* cloneNone = none.clone();
|
||||
QCOMPARE( cloneNone->id(), none.id() );
|
||||
QCOMPARE( cloneNone->keys(), none.keys() );
|
||||
QCOMPARE( cloneNone->primaryKey(), none.primaryKey() );
|
||||
delete cloneNone;
|
||||
}
|
||||
|
||||
|
||||
void TestMerge::record()
|
||||
{
|
||||
Record record;
|
||||
QCOMPARE( record.isSelected(), true );
|
||||
record.setSelected( false );
|
||||
QCOMPARE( record.isSelected(), false );
|
||||
record.setSelected( true );
|
||||
QCOMPARE( record.isSelected(), true );
|
||||
Record record;
|
||||
QCOMPARE( record.isSelected(), true );
|
||||
record.setSelected( false );
|
||||
QCOMPARE( record.isSelected(), false );
|
||||
record.setSelected( true );
|
||||
QCOMPARE( record.isSelected(), true );
|
||||
|
||||
record["key"] = "val";
|
||||
QVERIFY( record.contains( "key" ) );
|
||||
QCOMPARE( record["key"], QString( "val" ) );
|
||||
record["key"] = "val";
|
||||
QVERIFY( record.contains( "key" ) );
|
||||
QCOMPARE( record["key"], QString( "val" ) );
|
||||
|
||||
Record cloneRecord = record;
|
||||
QCOMPARE( cloneRecord.isSelected(), true );
|
||||
QVERIFY( cloneRecord.contains( "key" ) );
|
||||
QCOMPARE( cloneRecord.value( "key" ), QString( "val" ) );
|
||||
Record cloneRecord = record;
|
||||
QCOMPARE( cloneRecord.isSelected(), true );
|
||||
QVERIFY( cloneRecord.contains( "key" ) );
|
||||
QCOMPARE( cloneRecord.value( "key" ), QString( "val" ) );
|
||||
|
||||
record.setSelected( false );
|
||||
Record record2( record );
|
||||
QCOMPARE( record2.isSelected(), false );
|
||||
QVERIFY( record2.contains( "key" ) );
|
||||
QCOMPARE( record2["key"], QString( "val" ) );
|
||||
record.setSelected( false );
|
||||
Record record2( record );
|
||||
QCOMPARE( record2.isSelected(), false );
|
||||
QVERIFY( record2.contains( "key" ) );
|
||||
QCOMPARE( record2["key"], QString( "val" ) );
|
||||
}
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
/* TestMerge.h
|
||||
*
|
||||
* Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
|
||||
class TestMerge : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void initTestCase();
|
||||
void factory_data();
|
||||
void factory();
|
||||
void factoryNotRegistered();
|
||||
void text_data();
|
||||
void text();
|
||||
void none();
|
||||
void record();
|
||||
};
|
||||
@@ -0,0 +1,38 @@
|
||||
// TestMerge.hpp
|
||||
//
|
||||
// Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of gLabels-qt.
|
||||
//
|
||||
// gLabels-qt is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// gLabels-qt is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
|
||||
class TestMerge : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void initTestCase();
|
||||
void factory_data();
|
||||
void factory();
|
||||
void factoryNotRegistered();
|
||||
void text_data();
|
||||
void text();
|
||||
void none();
|
||||
void record();
|
||||
};
|
||||
+391
-391
@@ -1,42 +1,42 @@
|
||||
/* TestModel.cpp
|
||||
*
|
||||
* Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// TestModel.cpp
|
||||
//
|
||||
// Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of gLabels-qt.
|
||||
//
|
||||
// gLabels-qt is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// gLabels-qt is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
|
||||
#include "TestModel.h"
|
||||
#include "TestModel.hpp"
|
||||
|
||||
#include "model/Model.h"
|
||||
#include "model/ModelBoxObject.h"
|
||||
#include "model/ModelEllipseObject.h"
|
||||
#include "model/ModelLineObject.h"
|
||||
#include "model/ModelTextObject.h"
|
||||
#include "model/FrameRect.h"
|
||||
#include "model/FrameContinuous.h"
|
||||
#include "model/Region.h"
|
||||
#include "model/Settings.h"
|
||||
#include "model/Version.h"
|
||||
#include "model/Model.hpp"
|
||||
#include "model/ModelBoxObject.hpp"
|
||||
#include "model/ModelEllipseObject.hpp"
|
||||
#include "model/ModelLineObject.hpp"
|
||||
#include "model/ModelTextObject.hpp"
|
||||
#include "model/FrameRect.hpp"
|
||||
#include "model/FrameContinuous.hpp"
|
||||
#include "model/Region.hpp"
|
||||
#include "model/Settings.hpp"
|
||||
#include "model/Version.hpp"
|
||||
|
||||
#include "merge/Factory.h"
|
||||
#include "merge/Merge.h"
|
||||
#include "merge/None.h"
|
||||
#include "merge/TextCsv.h"
|
||||
#include "merge/TextCsvKeys.h"
|
||||
#include "merge/Factory.hpp"
|
||||
#include "merge/Merge.hpp"
|
||||
#include "merge/None.hpp"
|
||||
#include "merge/TextCsv.hpp"
|
||||
#include "merge/TextCsvKeys.hpp"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDebug>
|
||||
@@ -51,443 +51,443 @@ using namespace glabels::merge;
|
||||
|
||||
void TestModel::initTestCase()
|
||||
{
|
||||
QCoreApplication::setOrganizationName( glabels::model::Version::ORGANIZATION_NAME );
|
||||
QCoreApplication::setOrganizationName( glabels::model::Version::ORGANIZATION_NAME );
|
||||
|
||||
Settings::init();
|
||||
Factory::init();
|
||||
Settings::init();
|
||||
Factory::init();
|
||||
}
|
||||
|
||||
|
||||
void TestModel::model()
|
||||
{
|
||||
Model model;
|
||||
QVERIFY( model.isModified() );
|
||||
model.clearModified();
|
||||
QVERIFY( !model.isModified() );
|
||||
Model model;
|
||||
QVERIFY( model.isModified() );
|
||||
model.clearModified();
|
||||
QVERIFY( !model.isModified() );
|
||||
|
||||
QVERIFY( model.shortName().contains( QRegularExpression( "^Untitled[1-9][0-9]*$" ) ) );
|
||||
model.setFileName( "dir/file1.ext" );
|
||||
QCOMPARE( model.fileName(), QString( "dir/file1.ext" ) );
|
||||
QCOMPARE( model.shortName(), QString( "file1" ) );
|
||||
QVERIFY( !model.isModified() );
|
||||
QVERIFY( model.shortName().contains( QRegularExpression( "^Untitled[1-9][0-9]*$" ) ) );
|
||||
model.setFileName( "dir/file1.ext" );
|
||||
QCOMPARE( model.fileName(), QString( "dir/file1.ext" ) );
|
||||
QCOMPARE( model.shortName(), QString( "file1" ) );
|
||||
QVERIFY( !model.isModified() );
|
||||
|
||||
QCOMPARE( model.w(), Distance( 0 ) );
|
||||
QCOMPARE( model.h(), Distance( 0 ) );
|
||||
QCOMPARE( model.w(), Distance( 0 ) );
|
||||
QCOMPARE( model.h(), Distance( 0 ) );
|
||||
|
||||
Template tmplate( "Test Brand", "part", "desc", "testPaperId", 100, 400 );
|
||||
FrameRect frame( 100, 200, 5, 0, 0, "rect1" );
|
||||
QVERIFY( frame.w() != frame.h() );
|
||||
tmplate.addFrame( frame );
|
||||
model.setTmplate( tmplate ); // Copies
|
||||
QCOMPARE( model.tmplate().brand(), QString( "Test Brand" ) );
|
||||
QCOMPARE( model.tmplate().part(), QString( "part" ) );
|
||||
QCOMPARE( model.tmplate().description(), QString( "desc" ) );
|
||||
QCOMPARE( model.tmplate().paperId(), QString( "testPaperId" ) );
|
||||
QCOMPARE( model.tmplate().pageWidth(), Distance( 100 ) );
|
||||
QCOMPARE( model.tmplate().pageHeight(), Distance( 400 ) );
|
||||
QVERIFY( model.isModified() );
|
||||
Template tmplate( "Test Brand", "part", "desc", "testPaperId", 100, 400 );
|
||||
FrameRect frame( 100, 200, 5, 0, 0, "rect1" );
|
||||
QVERIFY( frame.w() != frame.h() );
|
||||
tmplate.addFrame( frame );
|
||||
model.setTmplate( tmplate ); // Copies
|
||||
QCOMPARE( model.tmplate().brand(), QString( "Test Brand" ) );
|
||||
QCOMPARE( model.tmplate().part(), QString( "part" ) );
|
||||
QCOMPARE( model.tmplate().description(), QString( "desc" ) );
|
||||
QCOMPARE( model.tmplate().paperId(), QString( "testPaperId" ) );
|
||||
QCOMPARE( model.tmplate().pageWidth(), Distance( 100 ) );
|
||||
QCOMPARE( model.tmplate().pageHeight(), Distance( 400 ) );
|
||||
QVERIFY( model.isModified() );
|
||||
|
||||
QVERIFY( model.frame()->id() == frame.id() );
|
||||
QCOMPARE( model.w(), Distance( 100 ) );
|
||||
QCOMPARE( model.h(), Distance( 200 ) );
|
||||
QCOMPARE( model.w(), frame.w() );
|
||||
QCOMPARE( model.h(), frame.h() );
|
||||
QVERIFY( model.frame()->id() == frame.id() );
|
||||
QCOMPARE( model.w(), Distance( 100 ) );
|
||||
QCOMPARE( model.h(), Distance( 200 ) );
|
||||
QCOMPARE( model.w(), frame.w() );
|
||||
QCOMPARE( model.h(), frame.h() );
|
||||
|
||||
model.clearModified();
|
||||
QVERIFY( !model.isModified() );
|
||||
model.clearModified();
|
||||
QVERIFY( !model.isModified() );
|
||||
|
||||
QVERIFY( !model.rotate() );
|
||||
model.setRotate( false );
|
||||
QVERIFY( !model.rotate() );
|
||||
QVERIFY( !model.isModified() );
|
||||
model.setRotate( true );
|
||||
QVERIFY( model.rotate() );
|
||||
QVERIFY( model.isModified() );
|
||||
QVERIFY( !model.rotate() );
|
||||
model.setRotate( false );
|
||||
QVERIFY( !model.rotate() );
|
||||
QVERIFY( !model.isModified() );
|
||||
model.setRotate( true );
|
||||
QVERIFY( model.rotate() );
|
||||
QVERIFY( model.isModified() );
|
||||
|
||||
QCOMPARE( model.w(), frame.h() );
|
||||
QCOMPARE( model.h(), frame.w() );
|
||||
QCOMPARE( model.w(), frame.h() );
|
||||
QCOMPARE( model.h(), frame.w() );
|
||||
|
||||
model.setRotate( false );
|
||||
QVERIFY( !model.rotate() );
|
||||
model.setRotate( false );
|
||||
QVERIFY( !model.rotate() );
|
||||
|
||||
model.clearModified();
|
||||
QVERIFY( !model.isModified() );
|
||||
model.clearModified();
|
||||
QVERIFY( !model.isModified() );
|
||||
|
||||
model.setH( 300 ); // Default does nothing
|
||||
QCOMPARE( model.h(), Distance( 200 ) ); // Should still bee 200
|
||||
QVERIFY( !model.isModified() ); // Should not be modified
|
||||
model.setH( 300 ); // Default does nothing
|
||||
QCOMPARE( model.h(), Distance( 200 ) ); // Should still bee 200
|
||||
QVERIFY( !model.isModified() ); // Should not be modified
|
||||
|
||||
// Continuous frame implements setH()
|
||||
Template tmplate2( "Test Brand2", "part2", "desc2", "testPaperId2", 100, 400 );
|
||||
FrameContinuous frame2( 100, 0, 500, 200, "continuous1" );
|
||||
QCOMPARE( frame2.h(), Distance( 200 ) );
|
||||
tmplate2.addFrame( frame2 );
|
||||
model.setTmplate( tmplate2 );
|
||||
QVERIFY( model.frame()->id() == frame2.id() );
|
||||
QCOMPARE( model.w(), Distance( 100 ) );
|
||||
QCOMPARE( model.h(), Distance( 200 ) );
|
||||
QCOMPARE( model.w(), frame2.w() );
|
||||
QCOMPARE( model.h(), frame2.h() );
|
||||
// Continuous frame implements setH()
|
||||
Template tmplate2( "Test Brand2", "part2", "desc2", "testPaperId2", 100, 400 );
|
||||
FrameContinuous frame2( 100, 0, 500, 200, "continuous1" );
|
||||
QCOMPARE( frame2.h(), Distance( 200 ) );
|
||||
tmplate2.addFrame( frame2 );
|
||||
model.setTmplate( tmplate2 );
|
||||
QVERIFY( model.frame()->id() == frame2.id() );
|
||||
QCOMPARE( model.w(), Distance( 100 ) );
|
||||
QCOMPARE( model.h(), Distance( 200 ) );
|
||||
QCOMPARE( model.w(), frame2.w() );
|
||||
QCOMPARE( model.h(), frame2.h() );
|
||||
|
||||
model.clearModified();
|
||||
QVERIFY( !model.isModified() );
|
||||
model.clearModified();
|
||||
QVERIFY( !model.isModified() );
|
||||
|
||||
model.setH( 300 );
|
||||
QCOMPARE( model.h(), Distance( 300 ) );
|
||||
QVERIFY( model.isModified() );
|
||||
model.setH( 300 );
|
||||
QCOMPARE( model.h(), Distance( 300 ) );
|
||||
QVERIFY( model.isModified() );
|
||||
|
||||
//
|
||||
// Objects
|
||||
//
|
||||
ColorNode black( Qt::black );
|
||||
ModelObject* ellipse = new ModelEllipseObject( 1, 0, 100, 100, false, 1, black, black );
|
||||
ModelObject* box = new ModelBoxObject( 1, 100, 100, 100, false, 1, black, black );
|
||||
ModelObject* line = new ModelLineObject( 1, 200, 99 /*dx*/, 1 /*dy*/, 1.0, black );
|
||||
ModelObject* text = new ModelTextObject( 1, 201, 100, 30, false, "", "Sans", 10, QFont::Normal, false, false, black, Qt::AlignLeft, Qt::AlignTop, QTextOption::WordWrap, 1, false );
|
||||
//
|
||||
// Objects
|
||||
//
|
||||
ColorNode black( Qt::black );
|
||||
ModelObject* ellipse = new ModelEllipseObject( 1, 0, 100, 100, false, 1, black, black );
|
||||
ModelObject* box = new ModelBoxObject( 1, 100, 100, 100, false, 1, black, black );
|
||||
ModelObject* line = new ModelLineObject( 1, 200, 99 /*dx*/, 1 /*dy*/, 1.0, black );
|
||||
ModelObject* text = new ModelTextObject( 1, 201, 100, 30, false, "", "Sans", 10, QFont::Normal, false, false, black, Qt::AlignLeft, Qt::AlignTop, QTextOption::WordWrap, 1, false );
|
||||
|
||||
model.clearModified();
|
||||
QVERIFY( !model.isModified() );
|
||||
model.clearModified();
|
||||
QVERIFY( !model.isModified() );
|
||||
|
||||
model.addObject( ellipse );
|
||||
QVERIFY( model.isModified() );
|
||||
model.addObject( box );
|
||||
model.addObject( line );
|
||||
model.addObject( text );
|
||||
model.addObject( ellipse );
|
||||
QVERIFY( model.isModified() );
|
||||
model.addObject( box );
|
||||
model.addObject( line );
|
||||
model.addObject( text );
|
||||
|
||||
QCOMPARE( model.objectList().size(), 4 );
|
||||
QCOMPARE( model.objectList().size(), 4 );
|
||||
|
||||
ModelObject* line2 = new ModelLineObject( 1, 231, 100 /*dx*/, 1 /*dy*/, 1.0, black );
|
||||
model.addObject( line2 );
|
||||
QCOMPARE( model.objectList().size(), 5 );
|
||||
ModelObject* line2 = new ModelLineObject( 1, 231, 100 /*dx*/, 1 /*dy*/, 1.0, black );
|
||||
model.addObject( line2 );
|
||||
QCOMPARE( model.objectList().size(), 5 );
|
||||
|
||||
model.clearModified();
|
||||
QVERIFY( !model.isModified() );
|
||||
model.clearModified();
|
||||
QVERIFY( !model.isModified() );
|
||||
|
||||
model.deleteObject( line2 );
|
||||
QCOMPARE( model.objectList().size(), 4 );
|
||||
QVERIFY( model.isModified() );
|
||||
model.deleteObject( line2 );
|
||||
QCOMPARE( model.objectList().size(), 4 );
|
||||
QVERIFY( model.isModified() );
|
||||
|
||||
ModelObject* object;
|
||||
ModelObject* object;
|
||||
|
||||
object = model.objectAt( 1 /*scale*/, 1, 200 );
|
||||
QVERIFY( object );
|
||||
QVERIFY( dynamic_cast<ModelLineObject*>(object) );
|
||||
QCOMPARE( object->id(), line->id() );
|
||||
object = model.objectAt( 1 /*scale*/, 1, 200 );
|
||||
QVERIFY( object );
|
||||
QVERIFY( dynamic_cast<ModelLineObject*>(object) );
|
||||
QCOMPARE( object->id(), line->id() );
|
||||
|
||||
object = model.objectAt( 1 /*scale*/, 100, 150 );
|
||||
QVERIFY( object );
|
||||
QVERIFY( dynamic_cast<ModelBoxObject*>(object) );
|
||||
QCOMPARE( object->id(), box->id() );
|
||||
object = model.objectAt( 1 /*scale*/, 100, 150 );
|
||||
QVERIFY( object );
|
||||
QVERIFY( dynamic_cast<ModelBoxObject*>(object) );
|
||||
QCOMPARE( object->id(), box->id() );
|
||||
|
||||
object = model.objectAt( 1 /*scale*/, 50, 0 );
|
||||
QVERIFY( object );
|
||||
QVERIFY( dynamic_cast<ModelEllipseObject*>(object) );
|
||||
QCOMPARE( object->id(), ellipse->id() );
|
||||
object = model.objectAt( 1 /*scale*/, 50, 0 );
|
||||
QVERIFY( object );
|
||||
QVERIFY( dynamic_cast<ModelEllipseObject*>(object) );
|
||||
QCOMPARE( object->id(), ellipse->id() );
|
||||
|
||||
object = model.objectAt( 1 /*scale*/, 1 + 3, 201 + 3 ); // Allow for text offset
|
||||
QVERIFY( object );
|
||||
QVERIFY( dynamic_cast<ModelTextObject*>(object) );
|
||||
QCOMPARE( object->id(), text->id() );
|
||||
object = model.objectAt( 1 /*scale*/, 1 + 3, 201 + 3 ); // Allow for text offset
|
||||
QVERIFY( object );
|
||||
QVERIFY( dynamic_cast<ModelTextObject*>(object) );
|
||||
QCOMPARE( object->id(), text->id() );
|
||||
|
||||
//
|
||||
// Selection
|
||||
//
|
||||
QVERIFY( model.isSelectionEmpty() );
|
||||
QVERIFY( !model.isSelectionAtomic() );
|
||||
QVERIFY( model.getSelection().isEmpty() );
|
||||
QVERIFY( !model.getFirstSelectedObject() );
|
||||
//
|
||||
// Selection
|
||||
//
|
||||
QVERIFY( model.isSelectionEmpty() );
|
||||
QVERIFY( !model.isSelectionAtomic() );
|
||||
QVERIFY( model.getSelection().isEmpty() );
|
||||
QVERIFY( !model.getFirstSelectedObject() );
|
||||
|
||||
QVERIFY( !model.canSelectionText() );
|
||||
QVERIFY( !model.canSelectionFill() );
|
||||
QVERIFY( !model.canSelectionLineColor() );
|
||||
QVERIFY( !model.canSelectionLineWidth() );
|
||||
QVERIFY( !model.canSelectionText() );
|
||||
QVERIFY( !model.canSelectionFill() );
|
||||
QVERIFY( !model.canSelectionLineColor() );
|
||||
QVERIFY( !model.canSelectionLineWidth() );
|
||||
|
||||
model.selectAll();
|
||||
QVERIFY( !model.isSelectionEmpty() );
|
||||
QVERIFY( !model.isSelectionAtomic() );
|
||||
QVERIFY( !model.getSelection().isEmpty() );
|
||||
QCOMPARE( model.getSelection().size(), 4 );
|
||||
QCOMPARE( model.getSelection().first()->id(), ellipse->id() );
|
||||
QCOMPARE( model.getSelection().at(1)->id(), box->id() );
|
||||
QCOMPARE( model.getSelection().at(2)->id(), line->id() );
|
||||
QCOMPARE( model.getSelection().at(3)->id(), text->id() );
|
||||
QVERIFY( model.getFirstSelectedObject() );
|
||||
QCOMPARE( model.getFirstSelectedObject()->id(), ellipse->id() );
|
||||
model.selectAll();
|
||||
QVERIFY( !model.isSelectionEmpty() );
|
||||
QVERIFY( !model.isSelectionAtomic() );
|
||||
QVERIFY( !model.getSelection().isEmpty() );
|
||||
QCOMPARE( model.getSelection().size(), 4 );
|
||||
QCOMPARE( model.getSelection().first()->id(), ellipse->id() );
|
||||
QCOMPARE( model.getSelection().at(1)->id(), box->id() );
|
||||
QCOMPARE( model.getSelection().at(2)->id(), line->id() );
|
||||
QCOMPARE( model.getSelection().at(3)->id(), text->id() );
|
||||
QVERIFY( model.getFirstSelectedObject() );
|
||||
QCOMPARE( model.getFirstSelectedObject()->id(), ellipse->id() );
|
||||
|
||||
QVERIFY( model.canSelectionText() );
|
||||
QVERIFY( model.canSelectionFill() );
|
||||
QVERIFY( model.canSelectionLineColor() );
|
||||
QVERIFY( model.canSelectionLineWidth() );
|
||||
QVERIFY( model.canSelectionText() );
|
||||
QVERIFY( model.canSelectionFill() );
|
||||
QVERIFY( model.canSelectionLineColor() );
|
||||
QVERIFY( model.canSelectionLineWidth() );
|
||||
|
||||
model.unselectAll();
|
||||
QVERIFY( model.isSelectionEmpty() );
|
||||
QVERIFY( !model.isSelectionAtomic() );
|
||||
QVERIFY( model.getSelection().isEmpty() );
|
||||
QVERIFY( !model.getFirstSelectedObject() );
|
||||
model.unselectAll();
|
||||
QVERIFY( model.isSelectionEmpty() );
|
||||
QVERIFY( !model.isSelectionAtomic() );
|
||||
QVERIFY( model.getSelection().isEmpty() );
|
||||
QVERIFY( !model.getFirstSelectedObject() );
|
||||
|
||||
model.selectObject( text );
|
||||
QVERIFY( !model.isSelectionEmpty() );
|
||||
QVERIFY( model.isSelectionAtomic() );
|
||||
QCOMPARE( model.getSelection().size(), 1 );
|
||||
QCOMPARE( model.getFirstSelectedObject()->id(), text->id() );
|
||||
model.selectObject( text );
|
||||
QVERIFY( !model.isSelectionEmpty() );
|
||||
QVERIFY( model.isSelectionAtomic() );
|
||||
QCOMPARE( model.getSelection().size(), 1 );
|
||||
QCOMPARE( model.getFirstSelectedObject()->id(), text->id() );
|
||||
|
||||
QVERIFY( model.canSelectionText() );
|
||||
QVERIFY( !model.canSelectionFill() );
|
||||
QVERIFY( !model.canSelectionLineColor() );
|
||||
QVERIFY( !model.canSelectionLineWidth() );
|
||||
QVERIFY( model.canSelectionText() );
|
||||
QVERIFY( !model.canSelectionFill() );
|
||||
QVERIFY( !model.canSelectionLineColor() );
|
||||
QVERIFY( !model.canSelectionLineWidth() );
|
||||
|
||||
model.unselectObject( text );
|
||||
QVERIFY( model.isSelectionEmpty() );
|
||||
model.unselectObject( text );
|
||||
QVERIFY( model.isSelectionEmpty() );
|
||||
|
||||
model.selectObject( line );
|
||||
QVERIFY( !model.isSelectionEmpty() );
|
||||
QVERIFY( model.isSelectionAtomic() );
|
||||
QCOMPARE( model.getSelection().size(), 1 );
|
||||
QCOMPARE( model.getFirstSelectedObject()->id(), line->id() );
|
||||
model.selectObject( line );
|
||||
QVERIFY( !model.isSelectionEmpty() );
|
||||
QVERIFY( model.isSelectionAtomic() );
|
||||
QCOMPARE( model.getSelection().size(), 1 );
|
||||
QCOMPARE( model.getFirstSelectedObject()->id(), line->id() );
|
||||
|
||||
QVERIFY( !model.canSelectionText() );
|
||||
QVERIFY( !model.canSelectionFill() );
|
||||
QVERIFY( model.canSelectionLineColor() );
|
||||
QVERIFY( model.canSelectionLineWidth() );
|
||||
QVERIFY( !model.canSelectionText() );
|
||||
QVERIFY( !model.canSelectionFill() );
|
||||
QVERIFY( model.canSelectionLineColor() );
|
||||
QVERIFY( model.canSelectionLineWidth() );
|
||||
|
||||
model.unselectAll();
|
||||
QVERIFY( model.isSelectionEmpty() );
|
||||
model.unselectAll();
|
||||
QVERIFY( model.isSelectionEmpty() );
|
||||
|
||||
double margin = 0.5; // Allow 0.5pt margin
|
||||
Region region( 1 - margin, 302 - margin, 101 + margin /*x2*/, 302 + margin /*y2*/ ); // Outside all objects
|
||||
model.selectRegion( region );
|
||||
QVERIFY( model.getSelection().isEmpty() );
|
||||
QVERIFY( model.isSelectionEmpty() );
|
||||
double margin = 0.5; // Allow 0.5pt margin
|
||||
Region region( 1 - margin, 302 - margin, 101 + margin /*x2*/, 302 + margin /*y2*/ ); // Outside all objects
|
||||
model.selectRegion( region );
|
||||
QVERIFY( model.getSelection().isEmpty() );
|
||||
QVERIFY( model.isSelectionEmpty() );
|
||||
|
||||
region.setY1( 0 - margin ); // Ellipse
|
||||
region.setY2( 100 + margin );
|
||||
model.selectRegion( region );
|
||||
QVERIFY( !model.isSelectionEmpty() );
|
||||
QVERIFY( model.isSelectionAtomic() );
|
||||
QCOMPARE( model.getSelection().size(), 1 );
|
||||
QCOMPARE( model.getFirstSelectedObject()->id(), ellipse->id() );
|
||||
region.setY1( 0 - margin ); // Ellipse
|
||||
region.setY2( 100 + margin );
|
||||
model.selectRegion( region );
|
||||
QVERIFY( !model.isSelectionEmpty() );
|
||||
QVERIFY( model.isSelectionAtomic() );
|
||||
QCOMPARE( model.getSelection().size(), 1 );
|
||||
QCOMPARE( model.getFirstSelectedObject()->id(), ellipse->id() );
|
||||
|
||||
QVERIFY( !model.canSelectionText() );
|
||||
QVERIFY( model.canSelectionFill() );
|
||||
QVERIFY( model.canSelectionLineColor() );
|
||||
QVERIFY( model.canSelectionLineWidth() );
|
||||
QVERIFY( !model.canSelectionText() );
|
||||
QVERIFY( model.canSelectionFill() );
|
||||
QVERIFY( model.canSelectionLineColor() );
|
||||
QVERIFY( model.canSelectionLineWidth() );
|
||||
|
||||
region.setY1( 200 - margin ); // Line
|
||||
region.setY2( 201 + margin );
|
||||
model.selectRegion( region );
|
||||
QVERIFY( !model.isSelectionEmpty() );
|
||||
QVERIFY( !model.isSelectionAtomic() ); // Accumulative
|
||||
QCOMPARE( model.getSelection().size(), 2 );
|
||||
QCOMPARE( model.getSelection().at(0)->id(), ellipse->id() );
|
||||
QCOMPARE( model.getSelection().at(1)->id(), line->id() );
|
||||
region.setY1( 200 - margin ); // Line
|
||||
region.setY2( 201 + margin );
|
||||
model.selectRegion( region );
|
||||
QVERIFY( !model.isSelectionEmpty() );
|
||||
QVERIFY( !model.isSelectionAtomic() ); // Accumulative
|
||||
QCOMPARE( model.getSelection().size(), 2 );
|
||||
QCOMPARE( model.getSelection().at(0)->id(), ellipse->id() );
|
||||
QCOMPARE( model.getSelection().at(1)->id(), line->id() );
|
||||
|
||||
model.unselectObject( ellipse );
|
||||
QVERIFY( !model.isSelectionEmpty() );
|
||||
QVERIFY( model.isSelectionAtomic() );
|
||||
QCOMPARE( model.getSelection().size(), 1 );
|
||||
QCOMPARE( model.getFirstSelectedObject()->id(), line->id() );
|
||||
model.unselectObject( ellipse );
|
||||
QVERIFY( !model.isSelectionEmpty() );
|
||||
QVERIFY( model.isSelectionAtomic() );
|
||||
QCOMPARE( model.getSelection().size(), 1 );
|
||||
QCOMPARE( model.getFirstSelectedObject()->id(), line->id() );
|
||||
|
||||
model.unselectAll();
|
||||
QVERIFY( model.isSelectionEmpty() );
|
||||
model.unselectAll();
|
||||
QVERIFY( model.isSelectionEmpty() );
|
||||
|
||||
// TODO: Operations on selections etc
|
||||
// TODO: Operations on selections etc
|
||||
}
|
||||
|
||||
|
||||
void TestModel::saveRestore()
|
||||
{
|
||||
Model* model = new Model;
|
||||
QVERIFY( model->isModified() );
|
||||
model->clearModified();
|
||||
QVERIFY( !model->isModified() );
|
||||
Model* model = new Model;
|
||||
QVERIFY( model->isModified() );
|
||||
model->clearModified();
|
||||
QVERIFY( !model->isModified() );
|
||||
|
||||
//
|
||||
// Set template/frame
|
||||
//
|
||||
Template tmplate( "Test Brand", "part", "desc", "testPaperId", 110, 410 );
|
||||
FrameRect frame( 120, 220, 5, 0, 0, "rect1" );
|
||||
tmplate.addFrame( frame );
|
||||
model->setTmplate( tmplate ); // Copies
|
||||
QCOMPARE( model->tmplate().brand(), QString( "Test Brand" ) );
|
||||
QVERIFY( model->isModified() );
|
||||
//
|
||||
// Set template/frame
|
||||
//
|
||||
Template tmplate( "Test Brand", "part", "desc", "testPaperId", 110, 410 );
|
||||
FrameRect frame( 120, 220, 5, 0, 0, "rect1" );
|
||||
tmplate.addFrame( frame );
|
||||
model->setTmplate( tmplate ); // Copies
|
||||
QCOMPARE( model->tmplate().brand(), QString( "Test Brand" ) );
|
||||
QVERIFY( model->isModified() );
|
||||
|
||||
model->clearModified();
|
||||
QVERIFY( !model->isModified() );
|
||||
model->clearModified();
|
||||
QVERIFY( !model->isModified() );
|
||||
|
||||
//
|
||||
// Set merge
|
||||
//
|
||||
Merge* merge = Factory::createMerge( TextCsvKeys::id() );
|
||||
QCOMPARE( merge->id(), TextCsvKeys::id() );
|
||||
//
|
||||
// Set merge
|
||||
//
|
||||
Merge* merge = Factory::createMerge( TextCsvKeys::id() );
|
||||
QCOMPARE( merge->id(), TextCsvKeys::id() );
|
||||
|
||||
model->setMerge( merge );
|
||||
QCOMPARE( model->merge(), merge );
|
||||
QVERIFY( model->isModified() );
|
||||
model->setMerge( merge );
|
||||
QCOMPARE( model->merge(), merge );
|
||||
QVERIFY( model->isModified() );
|
||||
|
||||
//
|
||||
// Add some variables
|
||||
//
|
||||
model->clearModified();
|
||||
QVERIFY( !model->isModified() );
|
||||
//
|
||||
// Add some variables
|
||||
//
|
||||
model->clearModified();
|
||||
QVERIFY( !model->isModified() );
|
||||
|
||||
Variable i( Variable::Type::INTEGER, "i", "2", Variable::Increment::PER_ITEM, "2" );
|
||||
Variable f( Variable::Type::FLOATING_POINT, "f", "6.54", Variable::Increment::PER_COPY, "0.12" );
|
||||
model->variables().addVariable( i );
|
||||
QVERIFY( model->isModified() );
|
||||
model->variables().addVariable( f );
|
||||
QVERIFY( model->isModified() );
|
||||
Variable i( Variable::Type::INTEGER, "i", "2", Variable::Increment::PER_ITEM, "2" );
|
||||
Variable f( Variable::Type::FLOATING_POINT, "f", "6.54", Variable::Increment::PER_COPY, "0.12" );
|
||||
model->variables().addVariable( i );
|
||||
QVERIFY( model->isModified() );
|
||||
model->variables().addVariable( f );
|
||||
QVERIFY( model->isModified() );
|
||||
|
||||
model->clearModified();
|
||||
QVERIFY( !model->isModified() );
|
||||
model->clearModified();
|
||||
QVERIFY( !model->isModified() );
|
||||
|
||||
QTemporaryFile csv;
|
||||
csv.open();
|
||||
csv.write( "id,text\n1,text1\n2,text2\n3,text3\n" );
|
||||
csv.close();
|
||||
QTemporaryFile csv;
|
||||
csv.open();
|
||||
csv.write( "id,text\n1,text1\n2,text2\n3,text3\n" );
|
||||
csv.close();
|
||||
|
||||
merge->setSource( csv.fileName() );
|
||||
QCOMPARE( merge->source(), csv.fileName() );
|
||||
QCOMPARE( merge->recordList().size(), 3 );
|
||||
QVERIFY( model->isModified() );
|
||||
merge->setSource( csv.fileName() );
|
||||
QCOMPARE( merge->source(), csv.fileName() );
|
||||
QCOMPARE( merge->recordList().size(), 3 );
|
||||
QVERIFY( model->isModified() );
|
||||
|
||||
model->clearModified();
|
||||
QVERIFY( !model->isModified() );
|
||||
model->clearModified();
|
||||
QVERIFY( !model->isModified() );
|
||||
|
||||
//
|
||||
// Add some objects
|
||||
//
|
||||
ColorNode black( Qt::black );
|
||||
ModelObject* object1 = new ModelLineObject( 1, 1, 90, 80, 1.0, black );
|
||||
model->addObject( object1 );
|
||||
QVERIFY( model->isModified() );
|
||||
QCOMPARE( model->objectList().size(), 1 );
|
||||
QCOMPARE( model->objectList().first(), object1 );
|
||||
//
|
||||
// Add some objects
|
||||
//
|
||||
ColorNode black( Qt::black );
|
||||
ModelObject* object1 = new ModelLineObject( 1, 1, 90, 80, 1.0, black );
|
||||
model->addObject( object1 );
|
||||
QVERIFY( model->isModified() );
|
||||
QCOMPARE( model->objectList().size(), 1 );
|
||||
QCOMPARE( model->objectList().first(), object1 );
|
||||
|
||||
model->clearModified();
|
||||
QVERIFY( !model->isModified() );
|
||||
model->clearModified();
|
||||
QVERIFY( !model->isModified() );
|
||||
|
||||
ModelObject* object2 = new ModelTextObject( 2, 2, 70, 30, false, "", "Sans", 10, QFont::Normal, false, false, black, Qt::AlignLeft, Qt::AlignTop, QTextOption::WordWrap, 1, false );
|
||||
model->addObject( object2 );
|
||||
QVERIFY( model->isModified() );
|
||||
QCOMPARE( model->objectList().size(), 2 );
|
||||
QCOMPARE( model->objectList().last(), object2 );
|
||||
ModelObject* object2 = new ModelTextObject( 2, 2, 70, 30, false, "", "Sans", 10, QFont::Normal, false, false, black, Qt::AlignLeft, Qt::AlignTop, QTextOption::WordWrap, 1, false );
|
||||
model->addObject( object2 );
|
||||
QVERIFY( model->isModified() );
|
||||
QCOMPARE( model->objectList().size(), 2 );
|
||||
QCOMPARE( model->objectList().last(), object2 );
|
||||
|
||||
QString modelShortName = model->shortName(); // If no fileName set then model expects to have have this called before being saved/restored (otherwise get differing untitled names)
|
||||
QString modelShortName = model->shortName(); // If no fileName set then model expects to have have this called before being saved/restored (otherwise get differing untitled names)
|
||||
|
||||
//
|
||||
// Test
|
||||
//
|
||||
Model* saved = model->save();
|
||||
QVERIFY( saved->isModified() );
|
||||
QCOMPARE( saved->merge(), model->merge() ); // Shared
|
||||
QCOMPARE( saved->isModified(), model->isModified() );
|
||||
QCOMPARE( saved->shortName(), modelShortName );
|
||||
QCOMPARE( saved->shortName(), model->shortName() );
|
||||
QCOMPARE( saved->fileName(), model->fileName() );
|
||||
QCOMPARE( saved->rotate(), model->rotate() );
|
||||
QCOMPARE( saved->objectList().size(), model->objectList().size() );
|
||||
QVERIFY( saved->objectList().at(0) != object1 ); // Objects copied
|
||||
QVERIFY( saved->objectList().at(1) != object2 ); // Objects copied
|
||||
QCOMPARE( saved->objectList().at(0)->x0(), model->objectList().at(0)->x0() );
|
||||
QCOMPARE( saved->objectList().at(0)->y0(), model->objectList().at(0)->y0() );
|
||||
QCOMPARE( saved->objectList().at(1)->x0(), model->objectList().at(1)->x0() );
|
||||
QCOMPARE( saved->objectList().at(1)->y0(), model->objectList().at(1)->y0() );
|
||||
//
|
||||
// Test
|
||||
//
|
||||
Model* saved = model->save();
|
||||
QVERIFY( saved->isModified() );
|
||||
QCOMPARE( saved->merge(), model->merge() ); // Shared
|
||||
QCOMPARE( saved->isModified(), model->isModified() );
|
||||
QCOMPARE( saved->shortName(), modelShortName );
|
||||
QCOMPARE( saved->shortName(), model->shortName() );
|
||||
QCOMPARE( saved->fileName(), model->fileName() );
|
||||
QCOMPARE( saved->rotate(), model->rotate() );
|
||||
QCOMPARE( saved->objectList().size(), model->objectList().size() );
|
||||
QVERIFY( saved->objectList().at(0) != object1 ); // Objects copied
|
||||
QVERIFY( saved->objectList().at(1) != object2 ); // Objects copied
|
||||
QCOMPARE( saved->objectList().at(0)->x0(), model->objectList().at(0)->x0() );
|
||||
QCOMPARE( saved->objectList().at(0)->y0(), model->objectList().at(0)->y0() );
|
||||
QCOMPARE( saved->objectList().at(1)->x0(), model->objectList().at(1)->x0() );
|
||||
QCOMPARE( saved->objectList().at(1)->y0(), model->objectList().at(1)->y0() );
|
||||
|
||||
// Modify original
|
||||
Template tmplate2( "Test Brand2", "part2", "desc2", "testPaperId2", 230, 630 );
|
||||
FrameRect frame2( 240, 340, 5, 0, 0, "rect2" );
|
||||
tmplate2.addFrame( frame2 );
|
||||
model->setTmplate( tmplate2 );
|
||||
QCOMPARE( model->tmplate().brand(), QString( "Test Brand2" ) );
|
||||
QCOMPARE( model->w(), Distance( 240 ) );
|
||||
QCOMPARE( model->h(), Distance( 340 ) );
|
||||
// Modify original
|
||||
Template tmplate2( "Test Brand2", "part2", "desc2", "testPaperId2", 230, 630 );
|
||||
FrameRect frame2( 240, 340, 5, 0, 0, "rect2" );
|
||||
tmplate2.addFrame( frame2 );
|
||||
model->setTmplate( tmplate2 );
|
||||
QCOMPARE( model->tmplate().brand(), QString( "Test Brand2" ) );
|
||||
QCOMPARE( model->w(), Distance( 240 ) );
|
||||
QCOMPARE( model->h(), Distance( 340 ) );
|
||||
|
||||
model->setFileName( "dir/file1.ext" );
|
||||
QCOMPARE( model->shortName(), QString( "file1" ) );
|
||||
model->setFileName( "dir/file1.ext" );
|
||||
QCOMPARE( model->shortName(), QString( "file1" ) );
|
||||
|
||||
model->setRotate( true );
|
||||
QVERIFY( model->rotate() );
|
||||
QCOMPARE( model->w(), Distance( 340 ) );
|
||||
QCOMPARE( model->h(), Distance( 240 ) );
|
||||
model->setRotate( true );
|
||||
QVERIFY( model->rotate() );
|
||||
QCOMPARE( model->w(), Distance( 340 ) );
|
||||
QCOMPARE( model->h(), Distance( 240 ) );
|
||||
|
||||
model->deleteObject( model->objectList().first() );
|
||||
QCOMPARE( model->objectList().size(), 1 );
|
||||
QCOMPARE( model->objectList().first(), object2 );
|
||||
model->deleteObject( model->objectList().first() );
|
||||
QCOMPARE( model->objectList().size(), 1 );
|
||||
QCOMPARE( model->objectList().first(), object2 );
|
||||
|
||||
model->objectList().first()->setY0( model->objectList().first()->y0() + 1 );
|
||||
model->objectList().first()->setY0( model->objectList().first()->y0() + 1 );
|
||||
|
||||
Merge* merge2 = Factory::createMerge( TextCsv::id() );
|
||||
QCOMPARE( merge2->id(), TextCsv::id() );
|
||||
QTemporaryFile csv2; csv2.open(); csv2.write( "21,text21\n22,text22\n23,text23\n24,text24\n" ); csv2.close();
|
||||
merge2->setSource( csv2.fileName() );
|
||||
QCOMPARE( merge2->source(), csv2.fileName() );
|
||||
QCOMPARE( merge2->recordList().size(), 4 );
|
||||
Merge* merge2 = Factory::createMerge( TextCsv::id() );
|
||||
QCOMPARE( merge2->id(), TextCsv::id() );
|
||||
QTemporaryFile csv2; csv2.open(); csv2.write( "21,text21\n22,text22\n23,text23\n24,text24\n" ); csv2.close();
|
||||
merge2->setSource( csv2.fileName() );
|
||||
QCOMPARE( merge2->source(), csv2.fileName() );
|
||||
QCOMPARE( merge2->recordList().size(), 4 );
|
||||
|
||||
model->setMerge( merge2 );
|
||||
QCOMPARE( model->merge(), merge2 );
|
||||
model->setMerge( merge2 );
|
||||
QCOMPARE( model->merge(), merge2 );
|
||||
|
||||
Model* modified = model->save();
|
||||
QCOMPARE( modified->merge(), merge2 ); // Shared
|
||||
Model* modified = model->save();
|
||||
QCOMPARE( modified->merge(), merge2 ); // Shared
|
||||
|
||||
Variable c( Variable::Type::COLOR, "c", "blue", Variable::Increment::PER_PAGE );
|
||||
model->variables().addVariable( c );
|
||||
Variable c( Variable::Type::COLOR, "c", "blue", Variable::Increment::PER_PAGE );
|
||||
model->variables().addVariable( c );
|
||||
|
||||
// Verify differences
|
||||
QVERIFY( model->shortName() != modelShortName );
|
||||
QVERIFY( model->shortName() != saved->shortName() );
|
||||
QVERIFY( model->fileName() != saved->fileName() );
|
||||
QVERIFY( model->tmplate().brand() != saved->tmplate().brand() );
|
||||
QVERIFY( model->rotate() != saved->rotate() );
|
||||
QVERIFY( model->w() != saved->w() );
|
||||
QVERIFY( model->h() != saved->h() );
|
||||
QVERIFY( model->objectList().size() != saved->objectList().size() );
|
||||
QVERIFY( model->objectList().at(0)->x0() != saved->objectList().at(0)->x0() );
|
||||
QVERIFY( model->objectList().at(0)->y0() != saved->objectList().at(0)->y0() );
|
||||
QCOMPARE( model->objectList().at(0)->x0(), saved->objectList().at(1)->x0() ); // Unchanged
|
||||
QVERIFY( model->objectList().at(0)->y0() != saved->objectList().at(1)->y0() );
|
||||
// Verify differences
|
||||
QVERIFY( model->shortName() != modelShortName );
|
||||
QVERIFY( model->shortName() != saved->shortName() );
|
||||
QVERIFY( model->fileName() != saved->fileName() );
|
||||
QVERIFY( model->tmplate().brand() != saved->tmplate().brand() );
|
||||
QVERIFY( model->rotate() != saved->rotate() );
|
||||
QVERIFY( model->w() != saved->w() );
|
||||
QVERIFY( model->h() != saved->h() );
|
||||
QVERIFY( model->objectList().size() != saved->objectList().size() );
|
||||
QVERIFY( model->objectList().at(0)->x0() != saved->objectList().at(0)->x0() );
|
||||
QVERIFY( model->objectList().at(0)->y0() != saved->objectList().at(0)->y0() );
|
||||
QCOMPARE( model->objectList().at(0)->x0(), saved->objectList().at(1)->x0() ); // Unchanged
|
||||
QVERIFY( model->objectList().at(0)->y0() != saved->objectList().at(1)->y0() );
|
||||
|
||||
// Restore
|
||||
model->restore( saved );
|
||||
QCOMPARE( model->shortName(), modelShortName );
|
||||
QCOMPARE( model->shortName(), saved->shortName() );
|
||||
QCOMPARE( model->fileName(), saved->fileName() );
|
||||
QCOMPARE( model->tmplate().brand(), saved->tmplate().brand() );
|
||||
QCOMPARE( model->rotate(), saved->rotate() );
|
||||
QCOMPARE( model->w(), saved->w() );
|
||||
QCOMPARE( model->h(), saved->h() );
|
||||
QCOMPARE( model->objectList().size(), saved->objectList().size() );
|
||||
QCOMPARE( model->objectList().size(), 2 );
|
||||
QCOMPARE( model->objectList().at(0)->x0(), saved->objectList().at(0)->x0() );
|
||||
QCOMPARE( model->objectList().at(0)->y0(), saved->objectList().at(0)->y0() );
|
||||
QCOMPARE( model->objectList().at(1)->x0(), saved->objectList().at(1)->x0() );
|
||||
QCOMPARE( model->objectList().at(1)->y0(), saved->objectList().at(1)->y0() );
|
||||
// Restore
|
||||
model->restore( saved );
|
||||
QCOMPARE( model->shortName(), modelShortName );
|
||||
QCOMPARE( model->shortName(), saved->shortName() );
|
||||
QCOMPARE( model->fileName(), saved->fileName() );
|
||||
QCOMPARE( model->tmplate().brand(), saved->tmplate().brand() );
|
||||
QCOMPARE( model->rotate(), saved->rotate() );
|
||||
QCOMPARE( model->w(), saved->w() );
|
||||
QCOMPARE( model->h(), saved->h() );
|
||||
QCOMPARE( model->objectList().size(), saved->objectList().size() );
|
||||
QCOMPARE( model->objectList().size(), 2 );
|
||||
QCOMPARE( model->objectList().at(0)->x0(), saved->objectList().at(0)->x0() );
|
||||
QCOMPARE( model->objectList().at(0)->y0(), saved->objectList().at(0)->y0() );
|
||||
QCOMPARE( model->objectList().at(1)->x0(), saved->objectList().at(1)->x0() );
|
||||
QCOMPARE( model->objectList().at(1)->y0(), saved->objectList().at(1)->y0() );
|
||||
|
||||
// Unrestore
|
||||
model->restore( modified );
|
||||
QVERIFY( model->shortName() != modelShortName );
|
||||
QVERIFY( model->shortName() != saved->shortName() );
|
||||
QVERIFY( model->fileName() != saved->fileName() );
|
||||
QVERIFY( model->tmplate().brand() != saved->tmplate().brand() );
|
||||
QVERIFY( model->rotate() != saved->rotate() );
|
||||
QVERIFY( model->w() != saved->w() );
|
||||
QVERIFY( model->h() != saved->h() );
|
||||
QCOMPARE( model->objectList().size(), 1 );
|
||||
QVERIFY( model->objectList().size() != saved->objectList().size() );
|
||||
QVERIFY( model->objectList().at(0)->x0() != saved->objectList().at(0)->x0() );
|
||||
QVERIFY( model->objectList().at(0)->y0() != saved->objectList().at(0)->y0() );
|
||||
QCOMPARE( model->merge(), merge2 ); // Same
|
||||
// Unrestore
|
||||
model->restore( modified );
|
||||
QVERIFY( model->shortName() != modelShortName );
|
||||
QVERIFY( model->shortName() != saved->shortName() );
|
||||
QVERIFY( model->fileName() != saved->fileName() );
|
||||
QVERIFY( model->tmplate().brand() != saved->tmplate().brand() );
|
||||
QVERIFY( model->rotate() != saved->rotate() );
|
||||
QVERIFY( model->w() != saved->w() );
|
||||
QVERIFY( model->h() != saved->h() );
|
||||
QCOMPARE( model->objectList().size(), 1 );
|
||||
QVERIFY( model->objectList().size() != saved->objectList().size() );
|
||||
QVERIFY( model->objectList().at(0)->x0() != saved->objectList().at(0)->x0() );
|
||||
QVERIFY( model->objectList().at(0)->y0() != saved->objectList().at(0)->y0() );
|
||||
QCOMPARE( model->merge(), merge2 ); // Same
|
||||
|
||||
QCOMPARE( model->shortName(), modified->shortName() );
|
||||
QCOMPARE( model->fileName(), modified->fileName() );
|
||||
QCOMPARE( model->tmplate().brand(), modified->tmplate().brand() );
|
||||
QCOMPARE( model->rotate(), modified->rotate() );
|
||||
QCOMPARE( model->w(), modified->w() );
|
||||
QCOMPARE( model->h(), modified->h() );
|
||||
QCOMPARE( model->objectList().size(), modified->objectList().size() );
|
||||
QCOMPARE( model->objectList().at(0)->x0(), modified->objectList().at(0)->x0() );
|
||||
QCOMPARE( model->objectList().at(0)->y0(), modified->objectList().at(0)->y0() );
|
||||
QCOMPARE( model->shortName(), modified->shortName() );
|
||||
QCOMPARE( model->fileName(), modified->fileName() );
|
||||
QCOMPARE( model->tmplate().brand(), modified->tmplate().brand() );
|
||||
QCOMPARE( model->rotate(), modified->rotate() );
|
||||
QCOMPARE( model->w(), modified->w() );
|
||||
QCOMPARE( model->h(), modified->h() );
|
||||
QCOMPARE( model->objectList().size(), modified->objectList().size() );
|
||||
QCOMPARE( model->objectList().at(0)->x0(), modified->objectList().at(0)->x0() );
|
||||
QCOMPARE( model->objectList().at(0)->y0(), modified->objectList().at(0)->y0() );
|
||||
|
||||
delete model;
|
||||
delete saved;
|
||||
delete modified;
|
||||
delete model;
|
||||
delete saved;
|
||||
delete modified;
|
||||
}
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
/* TestModel.h
|
||||
*
|
||||
* Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
|
||||
class TestModel : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void initTestCase();
|
||||
void model();
|
||||
void saveRestore();
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
// TestModel.hpp
|
||||
//
|
||||
// Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of gLabels-qt.
|
||||
//
|
||||
// gLabels-qt is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// gLabels-qt is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
|
||||
class TestModel : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void initTestCase();
|
||||
void model();
|
||||
void saveRestore();
|
||||
};
|
||||
@@ -1,36 +1,36 @@
|
||||
/* TestModelImageObject.cpp
|
||||
*
|
||||
* Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// TestModelImageObject.cpp
|
||||
//
|
||||
// Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of gLabels-qt.
|
||||
//
|
||||
// gLabels-qt is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// gLabels-qt is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
|
||||
#include "TestModelImageObject.h"
|
||||
#include "Test_Constants.h"
|
||||
#include "TestModelImageObject.hpp"
|
||||
#include "Test_Constants.hpp"
|
||||
|
||||
#include "model/Model.h"
|
||||
#include "model/ModelImageObject.h"
|
||||
#include "model/Size.h"
|
||||
#include "model/Model.hpp"
|
||||
#include "model/ModelImageObject.hpp"
|
||||
#include "model/Size.hpp"
|
||||
|
||||
#include "merge/Factory.h"
|
||||
#include "merge/TextCsvKeys.h"
|
||||
#include "merge/Record.h"
|
||||
#include "merge/Factory.hpp"
|
||||
#include "merge/TextCsvKeys.hpp"
|
||||
#include "merge/Record.hpp"
|
||||
|
||||
#include <QtDebug>
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
QTEST_MAIN(TestModelImageObject)
|
||||
@@ -41,210 +41,210 @@ using namespace glabels::merge;
|
||||
|
||||
void TestModelImageObject::initTestCase()
|
||||
{
|
||||
Factory::init();
|
||||
Factory::init();
|
||||
}
|
||||
|
||||
|
||||
void TestModelImageObject::readImageFile()
|
||||
{
|
||||
QByteArray pngArray;
|
||||
QImage png;
|
||||
QString svgTemplate = QDir::tempPath().append( "/TestModelImageObject_XXXXXX.svg" ); // Note: directory separators canonicalized to slash by Qt path methods
|
||||
QByteArray pngArray;
|
||||
QImage png;
|
||||
QString svgTemplate = QDir::tempPath().append( "/TestModelImageObject_XXXXXX.svg" ); // Note: directory separators canonicalized to slash by Qt path methods
|
||||
|
||||
Model model;
|
||||
Model model;
|
||||
|
||||
// Needed for relative file names to work
|
||||
QString modelFileName = QDir::tempPath().append( "/TestModelImageObject.glabels" );
|
||||
model.setFileName( modelFileName );
|
||||
// Needed for relative file names to work
|
||||
QString modelFileName = QDir::tempPath().append( "/TestModelImageObject.glabels" );
|
||||
model.setFileName( modelFileName );
|
||||
|
||||
ModelImageObject object;
|
||||
ModelImageObject object;
|
||||
|
||||
///
|
||||
/// Merge object, no shadow
|
||||
///
|
||||
object.setX0( 1 );
|
||||
object.setY0( 1 );
|
||||
object.setSize( 8, 8 );
|
||||
object.setFilenameNode( TextNode( true, "image" ) );
|
||||
///
|
||||
/// Merge object, no shadow
|
||||
///
|
||||
object.setX0( 1 );
|
||||
object.setY0( 1 );
|
||||
object.setSize( 8, 8 );
|
||||
object.setFilenameNode( TextNode( true, "image" ) );
|
||||
|
||||
model.addObject( object.clone() );
|
||||
model.addObject( object.clone() );
|
||||
|
||||
///
|
||||
/// Variable object, green pgn, gray shadow
|
||||
///
|
||||
object.setY0( 11 );
|
||||
object.setShadow( true );
|
||||
object.setShadowColorNode( ColorNode( Qt::gray ) );
|
||||
object.setShadowOpacity( 1 );
|
||||
TextNode( true, "var" );
|
||||
object.setFilenameNode( TextNode( true, "var" ) );
|
||||
///
|
||||
/// Variable object, green pgn, gray shadow
|
||||
///
|
||||
object.setY0( 11 );
|
||||
object.setShadow( true );
|
||||
object.setShadowColorNode( ColorNode( Qt::gray ) );
|
||||
object.setShadowOpacity( 1 );
|
||||
TextNode( true, "var" );
|
||||
object.setFilenameNode( TextNode( true, "var" ) );
|
||||
|
||||
// Green 8x8 square pgn
|
||||
pngArray = QByteArray::fromBase64( glabels::test::green_8x8_png );
|
||||
QVERIFY( png.loadFromData( pngArray, "PNG" ) );
|
||||
QTemporaryFile pngGreen; pngGreen.open(); pngGreen.close(); png.save( pngGreen.fileName(), "PNG" );
|
||||
QFileInfo pngGreenFileInfo( pngGreen.fileName() );
|
||||
// Green 8x8 square pgn
|
||||
pngArray = QByteArray::fromBase64( glabels::test::green_8x8_png );
|
||||
QVERIFY( png.loadFromData( pngArray, "PNG" ) );
|
||||
QTemporaryFile pngGreen; pngGreen.open(); pngGreen.close(); png.save( pngGreen.fileName(), "PNG" );
|
||||
QFileInfo pngGreenFileInfo( pngGreen.fileName() );
|
||||
|
||||
Variable var( Variable::Type::STRING, "var", pngGreenFileInfo.fileName(), Variable::Increment::PER_ITEM ); // Relative path
|
||||
model.variables().addVariable( var );
|
||||
Variable var( Variable::Type::STRING, "var", pngGreenFileInfo.fileName(), Variable::Increment::PER_ITEM ); // Relative path
|
||||
model.variables().addVariable( var );
|
||||
|
||||
model.addObject( object.clone() );
|
||||
model.addObject( object.clone() );
|
||||
|
||||
///
|
||||
/// Variable object 2, magenta svg, yellow shadow
|
||||
///
|
||||
object.setY0( 21 );
|
||||
object.setShadow( true );
|
||||
object.setShadowColorNode( ColorNode( Qt::yellow ) );
|
||||
object.setShadowOpacity( 1 );
|
||||
object.setFilenameNode( TextNode( true, "var2" ) );
|
||||
///
|
||||
/// Variable object 2, magenta svg, yellow shadow
|
||||
///
|
||||
object.setY0( 21 );
|
||||
object.setShadow( true );
|
||||
object.setShadowColorNode( ColorNode( Qt::yellow ) );
|
||||
object.setShadowOpacity( 1 );
|
||||
object.setFilenameNode( TextNode( true, "var2" ) );
|
||||
|
||||
// Magenta 8x8 square svg
|
||||
QTemporaryFile svgMagenta( svgTemplate ); svgMagenta.open(); svgMagenta.write( glabels::test::magenta_8x8_svg ); svgMagenta.close();
|
||||
QFileInfo svgMagentaFileInfo( svgMagenta.fileName() );
|
||||
// Magenta 8x8 square svg
|
||||
QTemporaryFile svgMagenta( svgTemplate ); svgMagenta.open(); svgMagenta.write( glabels::test::magenta_8x8_svg ); svgMagenta.close();
|
||||
QFileInfo svgMagentaFileInfo( svgMagenta.fileName() );
|
||||
|
||||
Variable var2( Variable::Type::STRING, "var2", svgMagentaFileInfo.fileName(), Variable::Increment::PER_ITEM ); // Absolute path
|
||||
model.variables().addVariable( var2 );
|
||||
Variable var2( Variable::Type::STRING, "var2", svgMagentaFileInfo.fileName(), Variable::Increment::PER_ITEM ); // Absolute path
|
||||
model.variables().addVariable( var2 );
|
||||
|
||||
model.addObject( object.clone() );
|
||||
model.addObject( object.clone() );
|
||||
|
||||
///
|
||||
/// Filename object, yellow png, cyan shadow
|
||||
///
|
||||
object.setY0( 31 );
|
||||
object.setShadow( true );
|
||||
object.setShadowColorNode( ColorNode( Qt::cyan ) );
|
||||
object.setShadowOpacity( 1 );
|
||||
///
|
||||
/// Filename object, yellow png, cyan shadow
|
||||
///
|
||||
object.setY0( 31 );
|
||||
object.setShadow( true );
|
||||
object.setShadowColorNode( ColorNode( Qt::cyan ) );
|
||||
object.setShadowOpacity( 1 );
|
||||
|
||||
// Yellow 8x8 square pgn
|
||||
pngArray = QByteArray::fromBase64( glabels::test::yellow_8x8_png );
|
||||
QVERIFY( png.loadFromData( pngArray, "PNG" ) );
|
||||
QTemporaryFile pngYellowFile; pngYellowFile.open(); pngYellowFile.close(); png.save( pngYellowFile.fileName(), "PNG" );
|
||||
// Yellow 8x8 square pgn
|
||||
pngArray = QByteArray::fromBase64( glabels::test::yellow_8x8_png );
|
||||
QVERIFY( png.loadFromData( pngArray, "PNG" ) );
|
||||
QTemporaryFile pngYellowFile; pngYellowFile.open(); pngYellowFile.close(); png.save( pngYellowFile.fileName(), "PNG" );
|
||||
|
||||
QFileInfo pngYellowFileInfo( pngYellowFile.fileName() );
|
||||
QFileInfo pngYellowFileInfo( pngYellowFile.fileName() );
|
||||
|
||||
// Need to set object parent for relative paths to work
|
||||
object.setParent( &model );
|
||||
// Need to set object parent for relative paths to work
|
||||
object.setParent( &model );
|
||||
|
||||
object.setFilenameNode( TextNode( false, pngYellowFileInfo.fileName() ) ); // Relative path
|
||||
object.setFilenameNode( TextNode( false, pngYellowFileInfo.fileName() ) ); // Relative path
|
||||
|
||||
model.addObject( object.clone() );
|
||||
model.addObject( object.clone() );
|
||||
|
||||
///
|
||||
/// Filename object, cyan svg, magenta shadow
|
||||
///
|
||||
object.setY0( 41 );
|
||||
object.setSize( 8, 8 );
|
||||
object.setShadow( true );
|
||||
object.setShadowColorNode( ColorNode( Qt::magenta ) );
|
||||
object.setShadowOpacity( 1 );
|
||||
///
|
||||
/// Filename object, cyan svg, magenta shadow
|
||||
///
|
||||
object.setY0( 41 );
|
||||
object.setSize( 8, 8 );
|
||||
object.setShadow( true );
|
||||
object.setShadowColorNode( ColorNode( Qt::magenta ) );
|
||||
object.setShadowOpacity( 1 );
|
||||
|
||||
// Cyan 8x8 square svg
|
||||
QTemporaryFile svgCyanFile( svgTemplate ); svgCyanFile.open(); svgCyanFile.write( glabels::test::cyan_8x8_svg ); svgCyanFile.close();
|
||||
// Cyan 8x8 square svg
|
||||
QTemporaryFile svgCyanFile( svgTemplate ); svgCyanFile.open(); svgCyanFile.write( glabels::test::cyan_8x8_svg ); svgCyanFile.close();
|
||||
|
||||
QFileInfo svgCyanFileInfo( svgCyanFile.fileName() );
|
||||
object.setFilenameNode( TextNode( false, svgCyanFileInfo.filePath() ) ); // Absolute path
|
||||
QFileInfo svgCyanFileInfo( svgCyanFile.fileName() );
|
||||
object.setFilenameNode( TextNode( false, svgCyanFileInfo.filePath() ) ); // Absolute path
|
||||
|
||||
model.addObject( object.clone() );
|
||||
model.addObject( object.clone() );
|
||||
|
||||
///
|
||||
/// Set up merge
|
||||
///
|
||||
///
|
||||
/// Set up merge
|
||||
///
|
||||
|
||||
// Blue 8x8 square pgn
|
||||
pngArray = QByteArray::fromBase64( glabels::test::blue_8x8_png );
|
||||
QVERIFY( png.loadFromData( pngArray, "PNG" ) );
|
||||
QTemporaryFile png1; png1.open(); png1.close(); png.save( png1.fileName(), "PNG" );
|
||||
QTemporaryFile png2; png2.open(); png2.close(); png.save( png2.fileName(), "PNG" );
|
||||
// Blue 8x8 square pgn
|
||||
pngArray = QByteArray::fromBase64( glabels::test::blue_8x8_png );
|
||||
QVERIFY( png.loadFromData( pngArray, "PNG" ) );
|
||||
QTemporaryFile png1; png1.open(); png1.close(); png.save( png1.fileName(), "PNG" );
|
||||
QTemporaryFile png2; png2.open(); png2.close(); png.save( png2.fileName(), "PNG" );
|
||||
|
||||
// Red 8x8 square svg
|
||||
QTemporaryFile svg1( svgTemplate ); svg1.open(); svg1.write( glabels::test::red_8x8_svg ); svg1.close();
|
||||
QTemporaryFile svg2( svgTemplate ); svg2.open(); svg2.write( glabels::test::red_8x8_svg ); svg2.close();
|
||||
// Red 8x8 square svg
|
||||
QTemporaryFile svg1( svgTemplate ); svg1.open(); svg1.write( glabels::test::red_8x8_svg ); svg1.close();
|
||||
QTemporaryFile svg2( svgTemplate ); svg2.open(); svg2.write( glabels::test::red_8x8_svg ); svg2.close();
|
||||
|
||||
QFileInfo png1FileInfo( png1.fileName() );
|
||||
QFileInfo png2FileInfo( png2.fileName() );
|
||||
QFileInfo svg1FileInfo( svg1.fileName() );
|
||||
QFileInfo svg2FileInfo( svg2.fileName() );
|
||||
QFileInfo png1FileInfo( png1.fileName() );
|
||||
QFileInfo png2FileInfo( png2.fileName() );
|
||||
QFileInfo svg1FileInfo( svg1.fileName() );
|
||||
QFileInfo svg2FileInfo( svg2.fileName() );
|
||||
|
||||
QTemporaryFile csv;
|
||||
csv.open();
|
||||
csv.write( "id,image,type\n" );
|
||||
csv.write( "1," ); csv.write( png1FileInfo.fileName().toUtf8() ); csv.write( ",png\n" );
|
||||
csv.write( "2," ); csv.write( png1FileInfo.filePath().toUtf8() ); csv.write( ",png\n" );
|
||||
csv.write( "3," ); csv.write( svg1FileInfo.fileName().toUtf8() ); csv.write( ",svg\n" );
|
||||
csv.write( "4," ); csv.write( svg2FileInfo.filePath().toUtf8() ); csv.write( ",svg\n" );
|
||||
csv.write( "5," ); csv.write( svg2FileInfo.fileName().toUtf8() ); csv.write( ",svg\n" );
|
||||
csv.write( "6," ); csv.write( png2FileInfo.fileName().toUtf8() ); csv.write( ",png\n" );
|
||||
csv.write( "7," ); csv.write( svg1FileInfo.filePath().toUtf8() ); csv.write( ",svg\n" );
|
||||
csv.write( "8," ); csv.write( png2FileInfo.filePath().toUtf8() ); csv.write( ",png\n" );
|
||||
csv.close();
|
||||
QTemporaryFile csv;
|
||||
csv.open();
|
||||
csv.write( "id,image,type\n" );
|
||||
csv.write( "1," ); csv.write( png1FileInfo.fileName().toUtf8() ); csv.write( ",png\n" );
|
||||
csv.write( "2," ); csv.write( png1FileInfo.filePath().toUtf8() ); csv.write( ",png\n" );
|
||||
csv.write( "3," ); csv.write( svg1FileInfo.fileName().toUtf8() ); csv.write( ",svg\n" );
|
||||
csv.write( "4," ); csv.write( svg2FileInfo.filePath().toUtf8() ); csv.write( ",svg\n" );
|
||||
csv.write( "5," ); csv.write( svg2FileInfo.fileName().toUtf8() ); csv.write( ",svg\n" );
|
||||
csv.write( "6," ); csv.write( png2FileInfo.fileName().toUtf8() ); csv.write( ",png\n" );
|
||||
csv.write( "7," ); csv.write( svg1FileInfo.filePath().toUtf8() ); csv.write( ",svg\n" );
|
||||
csv.write( "8," ); csv.write( png2FileInfo.filePath().toUtf8() ); csv.write( ",png\n" );
|
||||
csv.close();
|
||||
|
||||
Merge* merge = Factory::createMerge( TextCsvKeys::id() );
|
||||
QVERIFY( merge );
|
||||
QCOMPARE( merge->id(), TextCsvKeys::id() );
|
||||
merge->setSource( csv.fileName() );
|
||||
model.setMerge( merge );
|
||||
Merge* merge = Factory::createMerge( TextCsvKeys::id() );
|
||||
QVERIFY( merge );
|
||||
QCOMPARE( merge->id(), TextCsvKeys::id() );
|
||||
merge->setSource( csv.fileName() );
|
||||
model.setMerge( merge );
|
||||
|
||||
///
|
||||
/// Draw
|
||||
///
|
||||
const QList<Record> records = merge->selectedRecords();
|
||||
QCOMPARE( records.size(), 8 );
|
||||
///
|
||||
/// Draw
|
||||
///
|
||||
const QList<Record> records = merge->selectedRecords();
|
||||
QCOMPARE( records.size(), 8 );
|
||||
|
||||
QImage paintDevice( 10, 10 * model.objectList().size() * records.size(), QImage::Format_RGB32 );
|
||||
paintDevice.fill( Qt::white );
|
||||
QPainter painter( &paintDevice );
|
||||
QImage paintDevice( 10, 10 * model.objectList().size() * records.size(), QImage::Format_RGB32 );
|
||||
paintDevice.fill( Qt::white );
|
||||
QPainter painter( &paintDevice );
|
||||
|
||||
int i, cnt;
|
||||
int yTranslate = 10 * model.objectList().size();
|
||||
for ( i = 0, cnt = records.size(); i < cnt; i++ )
|
||||
{
|
||||
model.draw( &painter, false, records[i], model.variables() );
|
||||
painter.translate( 0, yTranslate );
|
||||
}
|
||||
int i, cnt;
|
||||
int yTranslate = 10 * model.objectList().size();
|
||||
for ( i = 0, cnt = records.size(); i < cnt; i++ )
|
||||
{
|
||||
model.draw( &painter, false, records[i], model.variables() );
|
||||
painter.translate( 0, yTranslate );
|
||||
}
|
||||
|
||||
QColor color, white = Qt::white, grayShadow = Qt::gray, yellowShadow = Qt::yellow, cyanShadow = Qt::cyan, magentaShadow = Qt::magenta;
|
||||
for ( i = 0, cnt = records.size(); i < cnt; i++ )
|
||||
{
|
||||
// Merge
|
||||
qDebug() << "record" << i;
|
||||
color = records[i].value( "type" ) == "png" ? Qt::blue : Qt::red;
|
||||
QCOMPARE( paintDevice.pixelColor( 1, 0 + i * yTranslate ), white );
|
||||
QCOMPARE( paintDevice.pixelColor( 1, 1 + i * yTranslate ), color );
|
||||
QCOMPARE( paintDevice.pixelColor( 1, 8 + i * yTranslate ), color );
|
||||
QCOMPARE( paintDevice.pixelColor( 1, 9 + i * yTranslate ), white );
|
||||
QCOMPARE( paintDevice.pixelColor( 9, 9 + i * yTranslate ), white ); // No shadow
|
||||
QColor color, white = Qt::white, grayShadow = Qt::gray, yellowShadow = Qt::yellow, cyanShadow = Qt::cyan, magentaShadow = Qt::magenta;
|
||||
for ( i = 0, cnt = records.size(); i < cnt; i++ )
|
||||
{
|
||||
// Merge
|
||||
qDebug() << "record" << i;
|
||||
color = records[i].value( "type" ) == "png" ? Qt::blue : Qt::red;
|
||||
QCOMPARE( paintDevice.pixelColor( 1, 0 + i * yTranslate ), white );
|
||||
QCOMPARE( paintDevice.pixelColor( 1, 1 + i * yTranslate ), color );
|
||||
QCOMPARE( paintDevice.pixelColor( 1, 8 + i * yTranslate ), color );
|
||||
QCOMPARE( paintDevice.pixelColor( 1, 9 + i * yTranslate ), white );
|
||||
QCOMPARE( paintDevice.pixelColor( 9, 9 + i * yTranslate ), white ); // No shadow
|
||||
|
||||
// Variable
|
||||
color = Qt::green;
|
||||
QCOMPARE( paintDevice.pixelColor( 1, 10 + i * yTranslate ), white );
|
||||
QCOMPARE( paintDevice.pixelColor( 1, 11 + i * yTranslate ), color );
|
||||
QCOMPARE( paintDevice.pixelColor( 1, 18 + i * yTranslate ), color );
|
||||
QCOMPARE( paintDevice.pixelColor( 1, 19 + i * yTranslate ), white );
|
||||
QCOMPARE( paintDevice.pixelColor( 9, 19 + i * yTranslate ), grayShadow );
|
||||
// Variable
|
||||
color = Qt::green;
|
||||
QCOMPARE( paintDevice.pixelColor( 1, 10 + i * yTranslate ), white );
|
||||
QCOMPARE( paintDevice.pixelColor( 1, 11 + i * yTranslate ), color );
|
||||
QCOMPARE( paintDevice.pixelColor( 1, 18 + i * yTranslate ), color );
|
||||
QCOMPARE( paintDevice.pixelColor( 1, 19 + i * yTranslate ), white );
|
||||
QCOMPARE( paintDevice.pixelColor( 9, 19 + i * yTranslate ), grayShadow );
|
||||
|
||||
// Variable 2
|
||||
color = Qt::magenta;
|
||||
QCOMPARE( paintDevice.pixelColor( 1, 20 + i * yTranslate ), white );
|
||||
QCOMPARE( paintDevice.pixelColor( 1, 21 + i * yTranslate ), color );
|
||||
QCOMPARE( paintDevice.pixelColor( 1, 28 + i * yTranslate ), color );
|
||||
QCOMPARE( paintDevice.pixelColor( 1, 29 + i * yTranslate ), white );
|
||||
QCOMPARE( paintDevice.pixelColor( 9, 29 + i * yTranslate ), yellowShadow );
|
||||
// Variable 2
|
||||
color = Qt::magenta;
|
||||
QCOMPARE( paintDevice.pixelColor( 1, 20 + i * yTranslate ), white );
|
||||
QCOMPARE( paintDevice.pixelColor( 1, 21 + i * yTranslate ), color );
|
||||
QCOMPARE( paintDevice.pixelColor( 1, 28 + i * yTranslate ), color );
|
||||
QCOMPARE( paintDevice.pixelColor( 1, 29 + i * yTranslate ), white );
|
||||
QCOMPARE( paintDevice.pixelColor( 9, 29 + i * yTranslate ), yellowShadow );
|
||||
|
||||
// Filename pgn
|
||||
color = Qt::yellow;
|
||||
QCOMPARE( paintDevice.pixelColor( 1, 30 + i * yTranslate ), white );
|
||||
QCOMPARE( paintDevice.pixelColor( 1, 31 + i * yTranslate ), color );
|
||||
QCOMPARE( paintDevice.pixelColor( 1, 38 + i * yTranslate ), color );
|
||||
QCOMPARE( paintDevice.pixelColor( 1, 39 + i * yTranslate ), white );
|
||||
QCOMPARE( paintDevice.pixelColor( 9, 39 + i * yTranslate ), cyanShadow );
|
||||
// Filename pgn
|
||||
color = Qt::yellow;
|
||||
QCOMPARE( paintDevice.pixelColor( 1, 30 + i * yTranslate ), white );
|
||||
QCOMPARE( paintDevice.pixelColor( 1, 31 + i * yTranslate ), color );
|
||||
QCOMPARE( paintDevice.pixelColor( 1, 38 + i * yTranslate ), color );
|
||||
QCOMPARE( paintDevice.pixelColor( 1, 39 + i * yTranslate ), white );
|
||||
QCOMPARE( paintDevice.pixelColor( 9, 39 + i * yTranslate ), cyanShadow );
|
||||
|
||||
// Filename svg
|
||||
color = Qt::cyan;
|
||||
QCOMPARE( paintDevice.pixelColor( 1, 40 + i * yTranslate ), white );
|
||||
QCOMPARE( paintDevice.pixelColor( 1, 41 + i * yTranslate ), color );
|
||||
QCOMPARE( paintDevice.pixelColor( 1, 48 + i * yTranslate ), color );
|
||||
QCOMPARE( paintDevice.pixelColor( 1, 49 + i * yTranslate ), white );
|
||||
QCOMPARE( paintDevice.pixelColor( 9, 49 + i * yTranslate ), magentaShadow );
|
||||
}
|
||||
// Filename svg
|
||||
color = Qt::cyan;
|
||||
QCOMPARE( paintDevice.pixelColor( 1, 40 + i * yTranslate ), white );
|
||||
QCOMPARE( paintDevice.pixelColor( 1, 41 + i * yTranslate ), color );
|
||||
QCOMPARE( paintDevice.pixelColor( 1, 48 + i * yTranslate ), color );
|
||||
QCOMPARE( paintDevice.pixelColor( 1, 49 + i * yTranslate ), white );
|
||||
QCOMPARE( paintDevice.pixelColor( 9, 49 + i * yTranslate ), magentaShadow );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
/* TestModelImageObject.h
|
||||
*
|
||||
* Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
|
||||
class TestModelImageObject : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void initTestCase();
|
||||
void readImageFile();
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
// TestModelImageObject.hpp
|
||||
//
|
||||
// Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of gLabels-qt.
|
||||
//
|
||||
// gLabels-qt is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// gLabels-qt is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
|
||||
class TestModelImageObject : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void initTestCase();
|
||||
void readImageFile();
|
||||
};
|
||||
@@ -1,29 +1,29 @@
|
||||
/* TestRawText.cpp
|
||||
*
|
||||
* Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// TestRawText.cpp
|
||||
//
|
||||
// Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of gLabels-qt.
|
||||
//
|
||||
// gLabels-qt is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// gLabels-qt is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
|
||||
#include "TestRawText.h"
|
||||
#include "TestRawText.hpp"
|
||||
|
||||
#include "model/RawText.h"
|
||||
#include "model/RawText.hpp"
|
||||
|
||||
#include "merge/Record.h"
|
||||
#include "merge/Record.hpp"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
@@ -36,62 +36,62 @@ using namespace glabels::merge;
|
||||
|
||||
void TestRawText::rawText()
|
||||
{
|
||||
RawText rawText;
|
||||
Record record;
|
||||
RawText rawText;
|
||||
Record record;
|
||||
|
||||
Variables variables;
|
||||
Variables variables;
|
||||
|
||||
QVERIFY( rawText.isEmpty() );
|
||||
QVERIFY( !rawText.hasPlaceHolders() );
|
||||
QCOMPARE( rawText.toString(), QString( "" ) );
|
||||
QCOMPARE( rawText.toStdString(), std::string( "" ) );
|
||||
QCOMPARE( rawText.expand( record, variables ), QString( "" ) );
|
||||
QVERIFY( rawText.isEmpty() );
|
||||
QVERIFY( !rawText.hasPlaceHolders() );
|
||||
QCOMPARE( rawText.toString(), QString( "" ) );
|
||||
QCOMPARE( rawText.toStdString(), std::string( "" ) );
|
||||
QCOMPARE( rawText.expand( record, variables ), QString( "" ) );
|
||||
|
||||
rawText = "text";
|
||||
QVERIFY( !rawText.isEmpty() );
|
||||
QVERIFY( !rawText.hasPlaceHolders() );
|
||||
QCOMPARE( rawText.toString(), QString( "text" ) );
|
||||
QCOMPARE( rawText.toStdString(), std::string( "text" ) );
|
||||
QCOMPARE( rawText.expand( record, variables ), QString( "text" ) );
|
||||
rawText = "text";
|
||||
QVERIFY( !rawText.isEmpty() );
|
||||
QVERIFY( !rawText.hasPlaceHolders() );
|
||||
QCOMPARE( rawText.toString(), QString( "text" ) );
|
||||
QCOMPARE( rawText.toStdString(), std::string( "text" ) );
|
||||
QCOMPARE( rawText.expand( record, variables ), QString( "text" ) );
|
||||
|
||||
RawText rawText2( "text" );
|
||||
QVERIFY( !rawText2.isEmpty() );
|
||||
QVERIFY( !rawText2.hasPlaceHolders() );
|
||||
QCOMPARE( rawText2.toString(), QString( "text" ) );
|
||||
RawText rawText2( "text" );
|
||||
QVERIFY( !rawText2.isEmpty() );
|
||||
QVERIFY( !rawText2.hasPlaceHolders() );
|
||||
QCOMPARE( rawText2.toString(), QString( "text" ) );
|
||||
|
||||
rawText = "${key1}";
|
||||
QVERIFY( !rawText.isEmpty() );
|
||||
QVERIFY( rawText.hasPlaceHolders() );
|
||||
QCOMPARE( rawText.toString(), QString( "${key1}" ) );
|
||||
QCOMPARE( rawText.toStdString(), std::string( "${key1}" ) );
|
||||
QCOMPARE( rawText.expand( record, variables ), QString( "" ) );
|
||||
rawText = "${key1}";
|
||||
QVERIFY( !rawText.isEmpty() );
|
||||
QVERIFY( rawText.hasPlaceHolders() );
|
||||
QCOMPARE( rawText.toString(), QString( "${key1}" ) );
|
||||
QCOMPARE( rawText.toStdString(), std::string( "${key1}" ) );
|
||||
QCOMPARE( rawText.expand( record, variables ), QString( "" ) );
|
||||
|
||||
///
|
||||
/// Record
|
||||
///
|
||||
record["key1"] = "val1";
|
||||
QCOMPARE( rawText.expand( record, variables ), QString( "val1" ) );
|
||||
///
|
||||
/// Record
|
||||
///
|
||||
record["key1"] = "val1";
|
||||
QCOMPARE( rawText.expand( record, variables ), QString( "val1" ) );
|
||||
|
||||
rawText = "${key1}${key2}";
|
||||
QVERIFY( rawText.hasPlaceHolders() );
|
||||
QCOMPARE( rawText.expand( record, variables ), QString( "val1" ) );
|
||||
rawText = "${key1}${key2}";
|
||||
QVERIFY( rawText.hasPlaceHolders() );
|
||||
QCOMPARE( rawText.expand( record, variables ), QString( "val1" ) );
|
||||
|
||||
record["key2"] = "val2";
|
||||
QCOMPARE( rawText.expand( record, variables ), QString( "val1val2" ) );
|
||||
record["key2"] = "val2";
|
||||
QCOMPARE( rawText.expand( record, variables ), QString( "val1val2" ) );
|
||||
|
||||
rawText = "${key1}text${key2}";
|
||||
QVERIFY( rawText.hasPlaceHolders() );
|
||||
QCOMPARE( rawText.expand( record, variables ), QString( "val1textval2" ) );
|
||||
rawText = "${key1}text${key2}";
|
||||
QVERIFY( rawText.hasPlaceHolders() );
|
||||
QCOMPARE( rawText.expand( record, variables ), QString( "val1textval2" ) );
|
||||
|
||||
rawText = "text1${key1}text2${key2}text3";
|
||||
QVERIFY( rawText.hasPlaceHolders() );
|
||||
QCOMPARE( rawText.expand( record, variables ), QString( "text1val1text2val2text3" ) );
|
||||
rawText = "text1${key1}text2${key2}text3";
|
||||
QVERIFY( rawText.hasPlaceHolders() );
|
||||
QCOMPARE( rawText.expand( record, variables ), QString( "text1val1text2val2text3" ) );
|
||||
|
||||
rawText = "${key1}text${key2}${key3}";
|
||||
QVERIFY( rawText.hasPlaceHolders() );
|
||||
QCOMPARE( rawText.expand( record, variables ), QString( "val1textval2" ) );
|
||||
rawText = "${key1}text${key2}${key3}";
|
||||
QVERIFY( rawText.hasPlaceHolders() );
|
||||
QCOMPARE( rawText.expand( record, variables ), QString( "val1textval2" ) );
|
||||
|
||||
rawText = "${key2}${key3}${key1}";
|
||||
QVERIFY( rawText.hasPlaceHolders() );
|
||||
QCOMPARE( rawText.expand( record, variables ), QString( "val2val1" ) );
|
||||
rawText = "${key2}${key3}${key1}";
|
||||
QVERIFY( rawText.hasPlaceHolders() );
|
||||
QCOMPARE( rawText.expand( record, variables ), QString( "val2val1" ) );
|
||||
}
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
/* TestRawText.h
|
||||
*
|
||||
* Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
|
||||
class TestRawText : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void rawText();
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
// TestRawText.hpp
|
||||
//
|
||||
// Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of gLabels-qt.
|
||||
//
|
||||
// gLabels-qt is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// gLabels-qt is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
|
||||
class TestRawText : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void rawText();
|
||||
};
|
||||
@@ -1,28 +1,29 @@
|
||||
/* TestColorNode.cpp
|
||||
*
|
||||
* Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// TestColorNode.cpp
|
||||
//
|
||||
// Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of gLabels-qt.
|
||||
//
|
||||
// gLabels-qt is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// gLabels-qt is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#include "TestStrUtil.h"
|
||||
|
||||
#include "model/StrUtil.h"
|
||||
#include "TestStrUtil.hpp"
|
||||
|
||||
#include <QtDebug>
|
||||
#include "model/StrUtil.hpp"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
QTEST_MAIN(TestStrUtil)
|
||||
@@ -33,22 +34,22 @@ using namespace glabels::model;
|
||||
|
||||
void TestStrUtil::formatFraction()
|
||||
{
|
||||
QCOMPARE( StrUtil::formatFraction( 3.5 ), QString( "3¹/₂" ) );
|
||||
QCOMPARE( StrUtil::formatFraction( 11.5 ), QString( "11¹/₂" ) );
|
||||
QCOMPARE( StrUtil::formatFraction( 0.5 ), QString( "¹/₂" ) );
|
||||
QCOMPARE( StrUtil::formatFraction( 1.25 ), QString( "1¹/₄" ) );
|
||||
QCOMPARE( StrUtil::formatFraction( 2.125 ), QString( "2¹/₈" ) );
|
||||
QCOMPARE( StrUtil::formatFraction( 2.875 ), QString( "2⁷/₈" ) );
|
||||
QCOMPARE( StrUtil::formatFraction( 3.875 ), QString( "3⁷/₈" ) );
|
||||
QCOMPARE( StrUtil::formatFraction( 4.0625 ), QString( "4¹/₁₆" ) );
|
||||
QCOMPARE( StrUtil::formatFraction( 5.3125 ), QString( "5⁵/₁₆" ) );
|
||||
QCOMPARE( StrUtil::formatFraction( 6.03125 ), QString( "6¹/₃₂" ) );
|
||||
QCOMPARE( StrUtil::formatFraction( 7.84375 ), QString( "7²⁷/₃₂" ) );
|
||||
QCOMPARE( StrUtil::formatFraction( 3.5 ), QString( "3¹/₂" ) );
|
||||
QCOMPARE( StrUtil::formatFraction( 11.5 ), QString( "11¹/₂" ) );
|
||||
QCOMPARE( StrUtil::formatFraction( 0.5 ), QString( "¹/₂" ) );
|
||||
QCOMPARE( StrUtil::formatFraction( 1.25 ), QString( "1¹/₄" ) );
|
||||
QCOMPARE( StrUtil::formatFraction( 2.125 ), QString( "2¹/₈" ) );
|
||||
QCOMPARE( StrUtil::formatFraction( 2.875 ), QString( "2⁷/₈" ) );
|
||||
QCOMPARE( StrUtil::formatFraction( 3.875 ), QString( "3⁷/₈" ) );
|
||||
QCOMPARE( StrUtil::formatFraction( 4.0625 ), QString( "4¹/₁₆" ) );
|
||||
QCOMPARE( StrUtil::formatFraction( 5.3125 ), QString( "5⁵/₁₆" ) );
|
||||
QCOMPARE( StrUtil::formatFraction( 6.03125 ), QString( "6¹/₃₂" ) );
|
||||
QCOMPARE( StrUtil::formatFraction( 7.84375 ), QString( "7²⁷/₃₂" ) );
|
||||
|
||||
QCOMPARE( StrUtil::formatFraction( 0 ), QString( "0" ) );
|
||||
QCOMPARE( StrUtil::formatFraction( 2 ), QString( "2" ) );
|
||||
QCOMPARE( StrUtil::formatFraction( 3 ), QString( "3" ) );
|
||||
QCOMPARE( StrUtil::formatFraction( 11 ), QString( "11" ) );
|
||||
QCOMPARE( StrUtil::formatFraction( 0 ), QString( "0" ) );
|
||||
QCOMPARE( StrUtil::formatFraction( 2 ), QString( "2" ) );
|
||||
QCOMPARE( StrUtil::formatFraction( 3 ), QString( "3" ) );
|
||||
QCOMPARE( StrUtil::formatFraction( 11 ), QString( "11" ) );
|
||||
|
||||
QCOMPARE( StrUtil::formatFraction( 3.1415926 ), QString( "3.142" ) );
|
||||
QCOMPARE( StrUtil::formatFraction( 3.1415926 ), QString( "3.142" ) );
|
||||
}
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
/* TestColorNode.h
|
||||
*
|
||||
* Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
|
||||
class TestStrUtil : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void formatFraction();
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
// TestColorNode.hpp
|
||||
//
|
||||
// Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of gLabels-qt.
|
||||
//
|
||||
// gLabels-qt is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// gLabels-qt is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
|
||||
class TestStrUtil : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void formatFraction();
|
||||
};
|
||||
@@ -1,27 +1,27 @@
|
||||
/* TestSubstitutionField.cpp
|
||||
*
|
||||
* Copyright (C) 2017 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// TestSubstitutionField.cpp
|
||||
//
|
||||
// Copyright (C) 2017 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of gLabels-qt.
|
||||
//
|
||||
// gLabels-qt is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// gLabels-qt is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
|
||||
#include "TestSubstitutionField.h"
|
||||
#include "TestSubstitutionField.hpp"
|
||||
|
||||
#include "model/SubstitutionField.h"
|
||||
#include "model/SubstitutionField.hpp"
|
||||
|
||||
|
||||
QTEST_MAIN(TestSubstitutionField)
|
||||
@@ -29,349 +29,349 @@ QTEST_MAIN(TestSubstitutionField)
|
||||
|
||||
void TestSubstitutionField::parseValid()
|
||||
{
|
||||
using namespace glabels;
|
||||
using namespace glabels;
|
||||
|
||||
//
|
||||
// Valid substitution fields (concatenated in single input string)
|
||||
//
|
||||
QString input = "${1234}${abc:=ABC}${x:%08.2f}${y:%08.2f:=12.34}${ADDR2:n}${FüññýßútLæg@lѪmê}${Also_a legal-name}";
|
||||
model::ParserState s( input );
|
||||
|
||||
model::SubstitutionField f1;
|
||||
QCOMPARE( model::SubstitutionField::parse( s, f1 ), true );
|
||||
QCOMPARE( f1.fieldName(), QString( "1234" ) );
|
||||
QCOMPARE( f1.newLine(), false );
|
||||
//
|
||||
// Valid substitution fields (concatenated in single input string)
|
||||
//
|
||||
QString input = "${1234}${abc:=ABC}${x:%08.2f}${y:%08.2f:=12.34}${ADDR2:n}${FüññýßútLæg@lѪmê}${Also_a legal-name}";
|
||||
model::ParserState s( input );
|
||||
|
||||
model::SubstitutionField f2;
|
||||
QCOMPARE( model::SubstitutionField::parse( s, f2 ), true );
|
||||
QCOMPARE( f2.fieldName(), QString( "abc" ) );
|
||||
QCOMPARE( f2.defaultValue(), QString( "ABC" ) );
|
||||
QCOMPARE( f2.newLine(), false );
|
||||
model::SubstitutionField f1;
|
||||
QCOMPARE( model::SubstitutionField::parse( s, f1 ), true );
|
||||
QCOMPARE( f1.fieldName(), QString( "1234" ) );
|
||||
QCOMPARE( f1.newLine(), false );
|
||||
|
||||
model::SubstitutionField f3;
|
||||
QCOMPARE( model::SubstitutionField::parse( s, f3 ), true );
|
||||
QCOMPARE( f3.fieldName(), QString( "x" ) );
|
||||
QCOMPARE( f3.format(), QString( "%08.2f" ) );
|
||||
QCOMPARE( f3.formatType(), QChar('f') );
|
||||
QCOMPARE( f3.newLine(), false );
|
||||
model::SubstitutionField f2;
|
||||
QCOMPARE( model::SubstitutionField::parse( s, f2 ), true );
|
||||
QCOMPARE( f2.fieldName(), QString( "abc" ) );
|
||||
QCOMPARE( f2.defaultValue(), QString( "ABC" ) );
|
||||
QCOMPARE( f2.newLine(), false );
|
||||
|
||||
model::SubstitutionField f4;
|
||||
QCOMPARE( model::SubstitutionField::parse( s, f4 ), true );
|
||||
QCOMPARE( f4.fieldName(), QString( "y" ) );
|
||||
QCOMPARE( f4.defaultValue(), QString( "12.34" ) );
|
||||
QCOMPARE( f4.format(), QString( "%08.2f" ) );
|
||||
QCOMPARE( f4.formatType(), QChar('f') );
|
||||
QCOMPARE( f4.newLine(), false );
|
||||
model::SubstitutionField f3;
|
||||
QCOMPARE( model::SubstitutionField::parse( s, f3 ), true );
|
||||
QCOMPARE( f3.fieldName(), QString( "x" ) );
|
||||
QCOMPARE( f3.format(), QString( "%08.2f" ) );
|
||||
QCOMPARE( f3.formatType(), QChar('f') );
|
||||
QCOMPARE( f3.newLine(), false );
|
||||
|
||||
model::SubstitutionField f5;
|
||||
QCOMPARE( model::SubstitutionField::parse( s, f5 ), true );
|
||||
QCOMPARE( f5.fieldName(), QString( "ADDR2" ) );
|
||||
QCOMPARE( f5.newLine(), true );
|
||||
model::SubstitutionField f4;
|
||||
QCOMPARE( model::SubstitutionField::parse( s, f4 ), true );
|
||||
QCOMPARE( f4.fieldName(), QString( "y" ) );
|
||||
QCOMPARE( f4.defaultValue(), QString( "12.34" ) );
|
||||
QCOMPARE( f4.format(), QString( "%08.2f" ) );
|
||||
QCOMPARE( f4.formatType(), QChar('f') );
|
||||
QCOMPARE( f4.newLine(), false );
|
||||
|
||||
model::SubstitutionField f6;
|
||||
QCOMPARE( model::SubstitutionField::parse( s, f6 ), true );
|
||||
QCOMPARE( f6.fieldName(), QString( "FüññýßútLæg@lѪmê" ) );
|
||||
QCOMPARE( f6.newLine(), false );
|
||||
model::SubstitutionField f5;
|
||||
QCOMPARE( model::SubstitutionField::parse( s, f5 ), true );
|
||||
QCOMPARE( f5.fieldName(), QString( "ADDR2" ) );
|
||||
QCOMPARE( f5.newLine(), true );
|
||||
|
||||
model::SubstitutionField f7;
|
||||
QCOMPARE( model::SubstitutionField::parse( s, f7 ), true );
|
||||
QCOMPARE( f7.fieldName(), QString( "Also_a legal-name" ) );
|
||||
QCOMPARE( f7.newLine(), false );
|
||||
model::SubstitutionField f6;
|
||||
QCOMPARE( model::SubstitutionField::parse( s, f6 ), true );
|
||||
QCOMPARE( f6.fieldName(), QString( "FüññýßútLæg@lѪmê" ) );
|
||||
QCOMPARE( f6.newLine(), false );
|
||||
|
||||
model::SubstitutionField f7;
|
||||
QCOMPARE( model::SubstitutionField::parse( s, f7 ), true );
|
||||
QCOMPARE( f7.fieldName(), QString( "Also_a legal-name" ) );
|
||||
QCOMPARE( f7.newLine(), false );
|
||||
}
|
||||
|
||||
|
||||
void TestSubstitutionField::parseInvalid()
|
||||
{
|
||||
using namespace glabels;
|
||||
using namespace glabels;
|
||||
|
||||
//
|
||||
// Ordinary text
|
||||
//
|
||||
QString input5 = "Abcdefg";
|
||||
model::ParserState s5( input5 );
|
||||
model::SubstitutionField f5;
|
||||
QCOMPARE( model::SubstitutionField::parse( s5, f5 ), false );
|
||||
QCOMPARE( s5.pos(), model::ParserState( input5 ).pos() ); // Should not advance string reference
|
||||
//
|
||||
// Ordinary text
|
||||
//
|
||||
QString input5 = "Abcdefg";
|
||||
model::ParserState s5( input5 );
|
||||
model::SubstitutionField f5;
|
||||
QCOMPARE( model::SubstitutionField::parse( s5, f5 ), false );
|
||||
QCOMPARE( s5.pos(), model::ParserState( input5 ).pos() ); // Should not advance string reference
|
||||
|
||||
//
|
||||
// Invalid substitution fields (which are treated as ordinary text)
|
||||
//
|
||||
QString input6 = "$abc";
|
||||
model::ParserState s6( input6 );
|
||||
model::SubstitutionField f6;
|
||||
QCOMPARE( model::SubstitutionField::parse( s6, f6 ), false );
|
||||
QCOMPARE( s6.pos(), model::ParserState( input6 ).pos() ); // Should not advance string reference
|
||||
//
|
||||
// Invalid substitution fields (which are treated as ordinary text)
|
||||
//
|
||||
QString input6 = "$abc";
|
||||
model::ParserState s6( input6 );
|
||||
model::SubstitutionField f6;
|
||||
QCOMPARE( model::SubstitutionField::parse( s6, f6 ), false );
|
||||
QCOMPARE( s6.pos(), model::ParserState( input6 ).pos() ); // Should not advance string reference
|
||||
|
||||
QString input7 = "${abc";
|
||||
model::ParserState s7( input7 );
|
||||
model::SubstitutionField f7;
|
||||
QCOMPARE( model::SubstitutionField::parse( s7, f7 ), false );
|
||||
QCOMPARE( s7.pos(), model::ParserState( input7 ).pos() ); // Should not advance string reference
|
||||
QString input7 = "${abc";
|
||||
model::ParserState s7( input7 );
|
||||
model::SubstitutionField f7;
|
||||
QCOMPARE( model::SubstitutionField::parse( s7, f7 ), false );
|
||||
QCOMPARE( s7.pos(), model::ParserState( input7 ).pos() ); // Should not advance string reference
|
||||
|
||||
QString input8 = "${abc:}";
|
||||
model::ParserState s8( input8 );
|
||||
model::SubstitutionField f8;
|
||||
QCOMPARE( model::SubstitutionField::parse( s8, f8 ), false );
|
||||
QCOMPARE( s8.pos(), model::ParserState( input8 ).pos() ); // Should not advance string reference
|
||||
QString input8 = "${abc:}";
|
||||
model::ParserState s8( input8 );
|
||||
model::SubstitutionField f8;
|
||||
QCOMPARE( model::SubstitutionField::parse( s8, f8 ), false );
|
||||
QCOMPARE( s8.pos(), model::ParserState( input8 ).pos() ); // Should not advance string reference
|
||||
|
||||
// Even though format is invalid, let it slide. Overall structure still good. Format will be ignored.
|
||||
QString input9 = "${abc:%3.2}";
|
||||
model::ParserState s9( input9 );
|
||||
model::SubstitutionField f9;
|
||||
QCOMPARE( model::SubstitutionField::parse( s9, f9 ), true );
|
||||
// Even though format is invalid, let it slide. Overall structure still good. Format will be ignored.
|
||||
QString input9 = "${abc:%3.2}";
|
||||
model::ParserState s9( input9 );
|
||||
model::SubstitutionField f9;
|
||||
QCOMPARE( model::SubstitutionField::parse( s9, f9 ), true );
|
||||
|
||||
QString input10 = "${embedded\nnew-line}";
|
||||
model::ParserState s10( input10 );
|
||||
model::SubstitutionField f10;
|
||||
QCOMPARE( model::SubstitutionField::parse( s10, f10 ), false );
|
||||
QCOMPARE( s10.pos(), model::ParserState( input10 ).pos() ); // Should not advance string reference
|
||||
QString input10 = "${embedded\nnew-line}";
|
||||
model::ParserState s10( input10 );
|
||||
model::SubstitutionField f10;
|
||||
QCOMPARE( model::SubstitutionField::parse( s10, f10 ), false );
|
||||
QCOMPARE( s10.pos(), model::ParserState( input10 ).pos() ); // Should not advance string reference
|
||||
|
||||
QString input11 = "${how-about-a\ttab}";
|
||||
model::ParserState s11( input11 );
|
||||
model::SubstitutionField f11;
|
||||
QCOMPARE( model::SubstitutionField::parse( s11, f11 ), false );
|
||||
QCOMPARE( s11.pos(), model::ParserState( input11 ).pos() ); // Should not advance string reference
|
||||
QString input11 = "${how-about-a\ttab}";
|
||||
model::ParserState s11( input11 );
|
||||
model::SubstitutionField f11;
|
||||
QCOMPARE( model::SubstitutionField::parse( s11, f11 ), false );
|
||||
QCOMPARE( s11.pos(), model::ParserState( input11 ).pos() ); // Should not advance string reference
|
||||
}
|
||||
|
||||
|
||||
void TestSubstitutionField::construction()
|
||||
{
|
||||
using namespace glabels;
|
||||
using namespace glabels;
|
||||
|
||||
model::SubstitutionField f1( "${1234}" );
|
||||
QCOMPARE( f1.fieldName(), QString( "1234" ) );
|
||||
model::SubstitutionField f1( "${1234}" );
|
||||
QCOMPARE( f1.fieldName(), QString( "1234" ) );
|
||||
|
||||
model::SubstitutionField f2( "${abc:=ABC}" );
|
||||
QCOMPARE( f2.fieldName(), QString( "abc" ) );
|
||||
QCOMPARE( f2.defaultValue(), QString( "ABC" ) );
|
||||
model::SubstitutionField f2( "${abc:=ABC}" );
|
||||
QCOMPARE( f2.fieldName(), QString( "abc" ) );
|
||||
QCOMPARE( f2.defaultValue(), QString( "ABC" ) );
|
||||
|
||||
model::SubstitutionField f3( "${x:%08.2f}" );
|
||||
QCOMPARE( f3.fieldName(), QString( "x" ) );
|
||||
QCOMPARE( f3.format(), QString( "%08.2f" ) );
|
||||
QCOMPARE( f3.formatType(), QChar('f') );
|
||||
model::SubstitutionField f3( "${x:%08.2f}" );
|
||||
QCOMPARE( f3.fieldName(), QString( "x" ) );
|
||||
QCOMPARE( f3.format(), QString( "%08.2f" ) );
|
||||
QCOMPARE( f3.formatType(), QChar('f') );
|
||||
|
||||
model::SubstitutionField f4( "${y:%08.2f:=12.34}" );
|
||||
QCOMPARE( f4.fieldName(), QString( "y" ) );
|
||||
QCOMPARE( f4.defaultValue(), QString( "12.34" ) );
|
||||
QCOMPARE( f4.format(), QString( "%08.2f" ) );
|
||||
QCOMPARE( f4.formatType(), QChar('f') );
|
||||
model::SubstitutionField f4( "${y:%08.2f:=12.34}" );
|
||||
QCOMPARE( f4.fieldName(), QString( "y" ) );
|
||||
QCOMPARE( f4.defaultValue(), QString( "12.34" ) );
|
||||
QCOMPARE( f4.format(), QString( "%08.2f" ) );
|
||||
QCOMPARE( f4.formatType(), QChar('f') );
|
||||
}
|
||||
|
||||
|
||||
void TestSubstitutionField::simpleEvaluation()
|
||||
{
|
||||
using namespace glabels;
|
||||
using namespace glabels;
|
||||
|
||||
model::Variables variables;
|
||||
|
||||
model::SubstitutionField f1( "${1}" );
|
||||
model::SubstitutionField f2( "${2}" );
|
||||
model::SubstitutionField f3( "${3}" );
|
||||
model::SubstitutionField f4( "${4}" );
|
||||
model::Variables variables;
|
||||
|
||||
merge::Record record1;
|
||||
record1[ "1" ] = "Abcdefg";
|
||||
record1[ "2" ] = "Hijklmn";
|
||||
record1[ "3" ] = "Opqrstu";
|
||||
record1[ "4" ] = "Vwxyz!@";
|
||||
model::SubstitutionField f1( "${1}" );
|
||||
model::SubstitutionField f2( "${2}" );
|
||||
model::SubstitutionField f3( "${3}" );
|
||||
model::SubstitutionField f4( "${4}" );
|
||||
|
||||
QCOMPARE( f1.evaluate( record1, variables ), QString( "Abcdefg" ) );
|
||||
QCOMPARE( f2.evaluate( record1, variables ), QString( "Hijklmn" ) );
|
||||
QCOMPARE( f3.evaluate( record1, variables ), QString( "Opqrstu" ) );
|
||||
QCOMPARE( f4.evaluate( record1, variables ), QString( "Vwxyz!@" ) );
|
||||
merge::Record record1;
|
||||
record1[ "1" ] = "Abcdefg";
|
||||
record1[ "2" ] = "Hijklmn";
|
||||
record1[ "3" ] = "Opqrstu";
|
||||
record1[ "4" ] = "Vwxyz!@";
|
||||
|
||||
merge::Record record2;
|
||||
record2[ "1" ] = "1234567";
|
||||
record2[ "2" ] = "FooBar";
|
||||
record2[ "3" ] = "8901234";
|
||||
record2[ "4" ] = "#$%^&*";
|
||||
QCOMPARE( f1.evaluate( record1, variables ), QString( "Abcdefg" ) );
|
||||
QCOMPARE( f2.evaluate( record1, variables ), QString( "Hijklmn" ) );
|
||||
QCOMPARE( f3.evaluate( record1, variables ), QString( "Opqrstu" ) );
|
||||
QCOMPARE( f4.evaluate( record1, variables ), QString( "Vwxyz!@" ) );
|
||||
|
||||
QCOMPARE( f1.evaluate( record2, variables ), QString( "1234567" ) );
|
||||
QCOMPARE( f2.evaluate( record2, variables ), QString( "FooBar" ) );
|
||||
QCOMPARE( f3.evaluate( record2, variables ), QString( "8901234" ) );
|
||||
QCOMPARE( f4.evaluate( record2, variables ), QString( "#$%^&*" ) );
|
||||
merge::Record record2;
|
||||
record2[ "1" ] = "1234567";
|
||||
record2[ "2" ] = "FooBar";
|
||||
record2[ "3" ] = "8901234";
|
||||
record2[ "4" ] = "#$%^&*";
|
||||
|
||||
QCOMPARE( f1.evaluate( record2, variables ), QString( "1234567" ) );
|
||||
QCOMPARE( f2.evaluate( record2, variables ), QString( "FooBar" ) );
|
||||
QCOMPARE( f3.evaluate( record2, variables ), QString( "8901234" ) );
|
||||
QCOMPARE( f4.evaluate( record2, variables ), QString( "#$%^&*" ) );
|
||||
}
|
||||
|
||||
|
||||
void TestSubstitutionField::defaultValueEvaluation()
|
||||
{
|
||||
using namespace glabels;
|
||||
using namespace glabels;
|
||||
|
||||
model::Variables variables;
|
||||
|
||||
model::SubstitutionField f1( "${1:=foo1}" );
|
||||
model::SubstitutionField f2( "${2:=foo2}" );
|
||||
model::SubstitutionField f3( "${3:=foo3}" );
|
||||
model::SubstitutionField f4( "${4:=foo4}" );
|
||||
model::Variables variables;
|
||||
|
||||
merge::Record record1;
|
||||
record1[ "1" ] = "Abcdefg";
|
||||
record1[ "2" ] = "Hijklmn";
|
||||
record1[ "3" ] = "Opqrstu";
|
||||
record1[ "4" ] = "Vwxyz!@";
|
||||
model::SubstitutionField f1( "${1:=foo1}" );
|
||||
model::SubstitutionField f2( "${2:=foo2}" );
|
||||
model::SubstitutionField f3( "${3:=foo3}" );
|
||||
model::SubstitutionField f4( "${4:=foo4}" );
|
||||
|
||||
QCOMPARE( f1.evaluate( record1, variables ), QString( "Abcdefg" ) );
|
||||
QCOMPARE( f2.evaluate( record1, variables ), QString( "Hijklmn" ) );
|
||||
QCOMPARE( f3.evaluate( record1, variables ), QString( "Opqrstu" ) );
|
||||
QCOMPARE( f4.evaluate( record1, variables ), QString( "Vwxyz!@" ) );
|
||||
merge::Record record1;
|
||||
record1[ "1" ] = "Abcdefg";
|
||||
record1[ "2" ] = "Hijklmn";
|
||||
record1[ "3" ] = "Opqrstu";
|
||||
record1[ "4" ] = "Vwxyz!@";
|
||||
|
||||
merge::Record record2; // All fields empty
|
||||
QCOMPARE( f1.evaluate( record1, variables ), QString( "Abcdefg" ) );
|
||||
QCOMPARE( f2.evaluate( record1, variables ), QString( "Hijklmn" ) );
|
||||
QCOMPARE( f3.evaluate( record1, variables ), QString( "Opqrstu" ) );
|
||||
QCOMPARE( f4.evaluate( record1, variables ), QString( "Vwxyz!@" ) );
|
||||
|
||||
QCOMPARE( f1.evaluate( record2, variables ), QString( "foo1" ) );
|
||||
QCOMPARE( f2.evaluate( record2, variables ), QString( "foo2" ) );
|
||||
QCOMPARE( f3.evaluate( record2, variables ), QString( "foo3" ) );
|
||||
QCOMPARE( f4.evaluate( record2, variables ), QString( "foo4" ) );
|
||||
merge::Record record2; // All fields empty
|
||||
|
||||
merge::Record record3;
|
||||
record3[ "1" ] = "xyzzy";
|
||||
// Field "2" empty
|
||||
// Field "3" empty
|
||||
record3[ "4" ] = "plugh";
|
||||
|
||||
QCOMPARE( f1.evaluate( record3, variables ), QString( "xyzzy" ) );
|
||||
QCOMPARE( f2.evaluate( record3, variables ), QString( "foo2" ) );
|
||||
QCOMPARE( f3.evaluate( record3, variables ), QString( "foo3" ) );
|
||||
QCOMPARE( f4.evaluate( record3, variables ), QString( "plugh" ) );
|
||||
QCOMPARE( f1.evaluate( record2, variables ), QString( "foo1" ) );
|
||||
QCOMPARE( f2.evaluate( record2, variables ), QString( "foo2" ) );
|
||||
QCOMPARE( f3.evaluate( record2, variables ), QString( "foo3" ) );
|
||||
QCOMPARE( f4.evaluate( record2, variables ), QString( "foo4" ) );
|
||||
|
||||
merge::Record record3;
|
||||
record3[ "1" ] = "xyzzy";
|
||||
// Field "2" empty
|
||||
// Field "3" empty
|
||||
record3[ "4" ] = "plugh";
|
||||
|
||||
QCOMPARE( f1.evaluate( record3, variables ), QString( "xyzzy" ) );
|
||||
QCOMPARE( f2.evaluate( record3, variables ), QString( "foo2" ) );
|
||||
QCOMPARE( f3.evaluate( record3, variables ), QString( "foo3" ) );
|
||||
QCOMPARE( f4.evaluate( record3, variables ), QString( "plugh" ) );
|
||||
}
|
||||
|
||||
|
||||
void TestSubstitutionField::formattedStringEvaluation()
|
||||
{
|
||||
using namespace glabels;
|
||||
using namespace glabels;
|
||||
|
||||
model::Variables variables;
|
||||
|
||||
model::SubstitutionField f1( "${1:%10s}" );
|
||||
model::SubstitutionField f2( "${2:%10s}" );
|
||||
model::SubstitutionField f3( "${3:%10s}" );
|
||||
model::SubstitutionField f4( "${4:%10s}" );
|
||||
model::Variables variables;
|
||||
|
||||
model::SubstitutionField f5( "${5:%-10s}" );
|
||||
model::SubstitutionField f6( "${6:%-10s}" );
|
||||
model::SubstitutionField f7( "${7:%-10s}" );
|
||||
model::SubstitutionField f8( "${8:%-10s}" );
|
||||
model::SubstitutionField f1( "${1:%10s}" );
|
||||
model::SubstitutionField f2( "${2:%10s}" );
|
||||
model::SubstitutionField f3( "${3:%10s}" );
|
||||
model::SubstitutionField f4( "${4:%10s}" );
|
||||
|
||||
merge::Record record1;
|
||||
record1[ "1" ] = "0";
|
||||
record1[ "2" ] = "1";
|
||||
record1[ "3" ] = "-1";
|
||||
record1[ "4" ] = "3.14";
|
||||
model::SubstitutionField f5( "${5:%-10s}" );
|
||||
model::SubstitutionField f6( "${6:%-10s}" );
|
||||
model::SubstitutionField f7( "${7:%-10s}" );
|
||||
model::SubstitutionField f8( "${8:%-10s}" );
|
||||
|
||||
record1[ "5" ] = "0";
|
||||
record1[ "6" ] = "100";
|
||||
record1[ "7" ] = "-100";
|
||||
record1[ "8" ] = "3.14";
|
||||
|
||||
QCOMPARE( f1.evaluate( record1, variables ), QString( " 0" ) );
|
||||
QCOMPARE( f2.evaluate( record1, variables ), QString( " 1" ) );
|
||||
QCOMPARE( f3.evaluate( record1, variables ), QString( " -1" ) );
|
||||
QCOMPARE( f4.evaluate( record1, variables ), QString( " 3.14" ) );
|
||||
merge::Record record1;
|
||||
record1[ "1" ] = "0";
|
||||
record1[ "2" ] = "1";
|
||||
record1[ "3" ] = "-1";
|
||||
record1[ "4" ] = "3.14";
|
||||
|
||||
QCOMPARE( f5.evaluate( record1, variables ), QString( "0 " ) );
|
||||
QCOMPARE( f6.evaluate( record1, variables ), QString( "100 " ) );
|
||||
QCOMPARE( f7.evaluate( record1, variables ), QString( "-100 " ) );
|
||||
QCOMPARE( f8.evaluate( record1, variables ), QString( "3.14 " ) );
|
||||
record1[ "5" ] = "0";
|
||||
record1[ "6" ] = "100";
|
||||
record1[ "7" ] = "-100";
|
||||
record1[ "8" ] = "3.14";
|
||||
|
||||
QCOMPARE( f1.evaluate( record1, variables ), QString( " 0" ) );
|
||||
QCOMPARE( f2.evaluate( record1, variables ), QString( " 1" ) );
|
||||
QCOMPARE( f3.evaluate( record1, variables ), QString( " -1" ) );
|
||||
QCOMPARE( f4.evaluate( record1, variables ), QString( " 3.14" ) );
|
||||
|
||||
QCOMPARE( f5.evaluate( record1, variables ), QString( "0 " ) );
|
||||
QCOMPARE( f6.evaluate( record1, variables ), QString( "100 " ) );
|
||||
QCOMPARE( f7.evaluate( record1, variables ), QString( "-100 " ) );
|
||||
QCOMPARE( f8.evaluate( record1, variables ), QString( "3.14 " ) );
|
||||
}
|
||||
|
||||
|
||||
void TestSubstitutionField::formattedFloatEvaluation()
|
||||
{
|
||||
using namespace glabels;
|
||||
using namespace glabels;
|
||||
|
||||
model::Variables variables;
|
||||
|
||||
model::SubstitutionField f1( "${1:%+5.2f}" );
|
||||
model::SubstitutionField f2( "${2:%+5.2f}" );
|
||||
model::SubstitutionField f3( "${3:%+5.2f}" );
|
||||
model::SubstitutionField f4( "${4:%+5.2f}" );
|
||||
model::Variables variables;
|
||||
|
||||
model::SubstitutionField f5( "${5:%+5.2e}" );
|
||||
model::SubstitutionField f6( "${6:%+5.2e}" );
|
||||
model::SubstitutionField f7( "${7:%+5.2e}" );
|
||||
model::SubstitutionField f8( "${8:%+5.2e}" );
|
||||
model::SubstitutionField f1( "${1:%+5.2f}" );
|
||||
model::SubstitutionField f2( "${2:%+5.2f}" );
|
||||
model::SubstitutionField f3( "${3:%+5.2f}" );
|
||||
model::SubstitutionField f4( "${4:%+5.2f}" );
|
||||
|
||||
merge::Record record1;
|
||||
record1[ "1" ] = "0";
|
||||
record1[ "2" ] = "1";
|
||||
record1[ "3" ] = "-1";
|
||||
record1[ "4" ] = "3.14";
|
||||
model::SubstitutionField f5( "${5:%+5.2e}" );
|
||||
model::SubstitutionField f6( "${6:%+5.2e}" );
|
||||
model::SubstitutionField f7( "${7:%+5.2e}" );
|
||||
model::SubstitutionField f8( "${8:%+5.2e}" );
|
||||
|
||||
record1[ "5" ] = "0";
|
||||
record1[ "6" ] = "100";
|
||||
record1[ "7" ] = "-100";
|
||||
record1[ "8" ] = "3.14";
|
||||
|
||||
QCOMPARE( f1.evaluate( record1, variables ), QString( "+0.00" ) );
|
||||
QCOMPARE( f2.evaluate( record1, variables ), QString( "+1.00" ) );
|
||||
QCOMPARE( f3.evaluate( record1, variables ), QString( "-1.00" ) );
|
||||
QCOMPARE( f4.evaluate( record1, variables ), QString( "+3.14" ) );
|
||||
merge::Record record1;
|
||||
record1[ "1" ] = "0";
|
||||
record1[ "2" ] = "1";
|
||||
record1[ "3" ] = "-1";
|
||||
record1[ "4" ] = "3.14";
|
||||
|
||||
QCOMPARE( f5.evaluate( record1, variables ), QString( "+0.00e+00" ) );
|
||||
QCOMPARE( f6.evaluate( record1, variables ), QString( "+1.00e+02" ) );
|
||||
QCOMPARE( f7.evaluate( record1, variables ), QString( "-1.00e+02" ) );
|
||||
QCOMPARE( f8.evaluate( record1, variables ), QString( "+3.14e+00" ) );
|
||||
record1[ "5" ] = "0";
|
||||
record1[ "6" ] = "100";
|
||||
record1[ "7" ] = "-100";
|
||||
record1[ "8" ] = "3.14";
|
||||
|
||||
QCOMPARE( f1.evaluate( record1, variables ), QString( "+0.00" ) );
|
||||
QCOMPARE( f2.evaluate( record1, variables ), QString( "+1.00" ) );
|
||||
QCOMPARE( f3.evaluate( record1, variables ), QString( "-1.00" ) );
|
||||
QCOMPARE( f4.evaluate( record1, variables ), QString( "+3.14" ) );
|
||||
|
||||
QCOMPARE( f5.evaluate( record1, variables ), QString( "+0.00e+00" ) );
|
||||
QCOMPARE( f6.evaluate( record1, variables ), QString( "+1.00e+02" ) );
|
||||
QCOMPARE( f7.evaluate( record1, variables ), QString( "-1.00e+02" ) );
|
||||
QCOMPARE( f8.evaluate( record1, variables ), QString( "+3.14e+00" ) );
|
||||
}
|
||||
|
||||
|
||||
void TestSubstitutionField::formattedIntEvaluation()
|
||||
{
|
||||
using namespace glabels;
|
||||
using namespace glabels;
|
||||
|
||||
model::Variables variables;
|
||||
|
||||
model::SubstitutionField f1( "${1:%08d}" );
|
||||
model::SubstitutionField f2( "${2:%08d}" );
|
||||
model::SubstitutionField f3( "${3:%08d}" );
|
||||
model::SubstitutionField f4( "${4:%08d}" );
|
||||
model::Variables variables;
|
||||
|
||||
model::SubstitutionField f5( "${5:%08x}" );
|
||||
model::SubstitutionField f6( "${6:%08x}" );
|
||||
model::SubstitutionField f7( "${7:%08x}" );
|
||||
model::SubstitutionField f8( "${8:%08x}" );
|
||||
model::SubstitutionField f1( "${1:%08d}" );
|
||||
model::SubstitutionField f2( "${2:%08d}" );
|
||||
model::SubstitutionField f3( "${3:%08d}" );
|
||||
model::SubstitutionField f4( "${4:%08d}" );
|
||||
|
||||
merge::Record record1;
|
||||
record1[ "1" ] = "0";
|
||||
record1[ "2" ] = "1";
|
||||
record1[ "3" ] = "-1";
|
||||
record1[ "4" ] = "3.14";
|
||||
model::SubstitutionField f5( "${5:%08x}" );
|
||||
model::SubstitutionField f6( "${6:%08x}" );
|
||||
model::SubstitutionField f7( "${7:%08x}" );
|
||||
model::SubstitutionField f8( "${8:%08x}" );
|
||||
|
||||
record1[ "5" ] = "100";
|
||||
record1[ "6" ] = "0x100";
|
||||
record1[ "7" ] = "-1";
|
||||
record1[ "8" ] = "314";
|
||||
|
||||
QCOMPARE( f1.evaluate( record1, variables ), QString( "00000000" ) );
|
||||
QCOMPARE( f2.evaluate( record1, variables ), QString( "00000001" ) );
|
||||
QCOMPARE( f3.evaluate( record1, variables ), QString( "-0000001" ) );
|
||||
QCOMPARE( f4.evaluate( record1, variables ), QString( "00000000" ) ); // Invalid integer value
|
||||
merge::Record record1;
|
||||
record1[ "1" ] = "0";
|
||||
record1[ "2" ] = "1";
|
||||
record1[ "3" ] = "-1";
|
||||
record1[ "4" ] = "3.14";
|
||||
|
||||
QCOMPARE( f5.evaluate( record1, variables ), QString( "00000064" ) ); // 100(decimal) == 64(hex)
|
||||
QCOMPARE( f6.evaluate( record1, variables ), QString( "00000100" ) );
|
||||
QCOMPARE( f7.evaluate( record1, variables ), QString( "00000000" ) ); // Invalid unsigned integer
|
||||
QCOMPARE( f8.evaluate( record1, variables ), QString( "0000013a" ) ); // 314(decimal) == 13a(hex)
|
||||
record1[ "5" ] = "100";
|
||||
record1[ "6" ] = "0x100";
|
||||
record1[ "7" ] = "-1";
|
||||
record1[ "8" ] = "314";
|
||||
|
||||
QCOMPARE( f1.evaluate( record1, variables ), QString( "00000000" ) );
|
||||
QCOMPARE( f2.evaluate( record1, variables ), QString( "00000001" ) );
|
||||
QCOMPARE( f3.evaluate( record1, variables ), QString( "-0000001" ) );
|
||||
QCOMPARE( f4.evaluate( record1, variables ), QString( "00000000" ) ); // Invalid integer value
|
||||
|
||||
QCOMPARE( f5.evaluate( record1, variables ), QString( "00000064" ) ); // 100(decimal) == 64(hex)
|
||||
QCOMPARE( f6.evaluate( record1, variables ), QString( "00000100" ) );
|
||||
QCOMPARE( f7.evaluate( record1, variables ), QString( "00000000" ) ); // Invalid unsigned integer
|
||||
QCOMPARE( f8.evaluate( record1, variables ), QString( "0000013a" ) ); // 314(decimal) == 13a(hex)
|
||||
}
|
||||
|
||||
|
||||
void TestSubstitutionField::newLineEvaluation()
|
||||
{
|
||||
using namespace glabels;
|
||||
using namespace glabels;
|
||||
|
||||
model::Variables variables;
|
||||
|
||||
model::SubstitutionField addr2( "${ADDR2:n}" );
|
||||
QCOMPARE( addr2.fieldName(), QString( "ADDR2" ) );
|
||||
QCOMPARE( addr2.newLine(), true );
|
||||
model::Variables variables;
|
||||
|
||||
merge::Record record1;
|
||||
record1[ "ADDR2" ] = "Apt. 5B";
|
||||
model::SubstitutionField addr2( "${ADDR2:n}" );
|
||||
QCOMPARE( addr2.fieldName(), QString( "ADDR2" ) );
|
||||
QCOMPARE( addr2.newLine(), true );
|
||||
|
||||
merge::Record record2;
|
||||
record2[ "ADDR2" ] = ""; // ADDR2 Empty
|
||||
|
||||
merge::Record record3;
|
||||
// ADDR2 not defined
|
||||
merge::Record record1;
|
||||
record1[ "ADDR2" ] = "Apt. 5B";
|
||||
|
||||
QCOMPARE( addr2.evaluate( record1, variables ), QString( "\nApt. 5B" ) ); // Prepends a newline
|
||||
QCOMPARE( addr2.evaluate( record2, variables ), QString( "" ) ); // Evaluates empty
|
||||
QCOMPARE( addr2.evaluate( record3, variables ), QString( "" ) ); // Evaluates empty
|
||||
merge::Record record2;
|
||||
record2[ "ADDR2" ] = ""; // ADDR2 Empty
|
||||
|
||||
merge::Record record3;
|
||||
// ADDR2 not defined
|
||||
|
||||
QCOMPARE( addr2.evaluate( record1, variables ), QString( "\nApt. 5B" ) ); // Prepends a newline
|
||||
QCOMPARE( addr2.evaluate( record2, variables ), QString( "" ) ); // Evaluates empty
|
||||
QCOMPARE( addr2.evaluate( record3, variables ), QString( "" ) ); // Evaluates empty
|
||||
}
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
/* TestSubstitutionField.h
|
||||
*
|
||||
* Copyright (C) 2017 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
|
||||
class TestSubstitutionField : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void parseValid();
|
||||
void parseInvalid();
|
||||
void construction();
|
||||
void simpleEvaluation();
|
||||
void defaultValueEvaluation();
|
||||
void formattedStringEvaluation();
|
||||
void formattedFloatEvaluation();
|
||||
void formattedIntEvaluation();
|
||||
void newLineEvaluation();
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
// TestSubstitutionField.hpp
|
||||
//
|
||||
// Copyright (C) 2017 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of gLabels-qt.
|
||||
//
|
||||
// gLabels-qt is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// gLabels-qt is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
|
||||
class TestSubstitutionField : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void parseValid();
|
||||
void parseInvalid();
|
||||
void construction();
|
||||
void simpleEvaluation();
|
||||
void defaultValueEvaluation();
|
||||
void formattedStringEvaluation();
|
||||
void formattedFloatEvaluation();
|
||||
void formattedIntEvaluation();
|
||||
void newLineEvaluation();
|
||||
};
|
||||
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
/* TestTextNode.cpp
|
||||
*
|
||||
* Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// TestTextNode.cpp
|
||||
//
|
||||
// Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of gLabels-qt.
|
||||
//
|
||||
// gLabels-qt is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// gLabels-qt is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
|
||||
#include "TestTextNode.h"
|
||||
#include "TestTextNode.hpp"
|
||||
|
||||
#include "model/TextNode.h"
|
||||
#include "model/TextNode.hpp"
|
||||
|
||||
#include <QtDebug>
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
QTEST_MAIN(TestTextNode)
|
||||
@@ -34,86 +34,86 @@ using namespace glabels::merge;
|
||||
|
||||
void TestTextNode::textNode()
|
||||
{
|
||||
Record record;
|
||||
Variables vars;
|
||||
Record record;
|
||||
Variables vars;
|
||||
|
||||
TextNode textNode;
|
||||
QVERIFY( !textNode.isField() );
|
||||
QCOMPARE( textNode.data(), QString( "" ) );
|
||||
QVERIFY( textNode == TextNode() );
|
||||
QVERIFY( !(textNode != TextNode()) );
|
||||
QCOMPARE( textNode.text( NullRecord(), vars ), QString( "" ) );
|
||||
QCOMPARE( textNode.text( record, vars ), QString( "" ) );
|
||||
TextNode textNode;
|
||||
QVERIFY( !textNode.isField() );
|
||||
QCOMPARE( textNode.data(), QString( "" ) );
|
||||
QVERIFY( textNode == TextNode() );
|
||||
QVERIFY( !(textNode != TextNode()) );
|
||||
QCOMPARE( textNode.text( NullRecord(), vars ), QString( "" ) );
|
||||
QCOMPARE( textNode.text( record, vars ), QString( "" ) );
|
||||
|
||||
textNode.setField( true );
|
||||
QVERIFY( textNode.isField() );
|
||||
QCOMPARE( textNode.text( record, vars ), QString( "" ) );
|
||||
textNode.setField( true );
|
||||
QVERIFY( textNode.isField() );
|
||||
QCOMPARE( textNode.text( record, vars ), QString( "" ) );
|
||||
|
||||
textNode.setField( false );
|
||||
QVERIFY( !textNode.isField() );
|
||||
textNode.setField( false );
|
||||
QVERIFY( !textNode.isField() );
|
||||
|
||||
textNode.setData( QString( "data1" ) );
|
||||
QCOMPARE( textNode.data(), QString( "data1" ) );
|
||||
QCOMPARE( textNode.text( NullRecord(), vars ), QString( "data1" ) );
|
||||
QCOMPARE( textNode.text( record, vars ), QString( "data1" ) );
|
||||
textNode.setData( QString( "data1" ) );
|
||||
QCOMPARE( textNode.data(), QString( "data1" ) );
|
||||
QCOMPARE( textNode.text( NullRecord(), vars ), QString( "data1" ) );
|
||||
QCOMPARE( textNode.text( record, vars ), QString( "data1" ) );
|
||||
|
||||
textNode.setField( true );
|
||||
QCOMPARE( textNode.text( NullRecord(), vars ), QString( "" ) );
|
||||
QCOMPARE( textNode.text( record, vars ), QString( "" ) );
|
||||
textNode.setField( true );
|
||||
QCOMPARE( textNode.text( NullRecord(), vars ), QString( "" ) );
|
||||
QCOMPARE( textNode.text( record, vars ), QString( "" ) );
|
||||
|
||||
///
|
||||
/// Constructors
|
||||
///
|
||||
TextNode textNode2( true, "data2" );
|
||||
QVERIFY( textNode2.isField() );
|
||||
QCOMPARE( textNode2.data(), QString( "data2" ) );
|
||||
textNode.setField( false );
|
||||
QVERIFY( !(textNode2 == textNode) );
|
||||
QVERIFY( textNode2 != textNode );
|
||||
textNode.setField( true );
|
||||
QVERIFY( !(textNode2 == textNode) );
|
||||
QVERIFY( textNode2 != textNode );
|
||||
textNode.setData( QString( "data2" ) );
|
||||
QVERIFY( textNode2 == textNode );
|
||||
QVERIFY( !(textNode2 != textNode) );
|
||||
///
|
||||
/// Constructors
|
||||
///
|
||||
TextNode textNode2( true, "data2" );
|
||||
QVERIFY( textNode2.isField() );
|
||||
QCOMPARE( textNode2.data(), QString( "data2" ) );
|
||||
textNode.setField( false );
|
||||
QVERIFY( !(textNode2 == textNode) );
|
||||
QVERIFY( textNode2 != textNode );
|
||||
textNode.setField( true );
|
||||
QVERIFY( !(textNode2 == textNode) );
|
||||
QVERIFY( textNode2 != textNode );
|
||||
textNode.setData( QString( "data2" ) );
|
||||
QVERIFY( textNode2 == textNode );
|
||||
QVERIFY( !(textNode2 != textNode) );
|
||||
|
||||
///
|
||||
/// Record
|
||||
///
|
||||
record["key1"] = "";
|
||||
QCOMPARE( textNode.text( record, vars ), QString( "" ) );
|
||||
///
|
||||
/// Record
|
||||
///
|
||||
record["key1"] = "";
|
||||
QCOMPARE( textNode.text( record, vars ), QString( "" ) );
|
||||
|
||||
textNode.setData( QString( "key1" ) );
|
||||
QCOMPARE( textNode.text( record, vars ), QString( "" ) );
|
||||
textNode.setData( QString( "key1" ) );
|
||||
QCOMPARE( textNode.text( record, vars ), QString( "" ) );
|
||||
|
||||
record["key1"] = "val1";
|
||||
QCOMPARE( textNode.text( record, vars ), QString( "val1" ) );
|
||||
record["key1"] = "val1";
|
||||
QCOMPARE( textNode.text( record, vars ), QString( "val1" ) );
|
||||
|
||||
///
|
||||
/// Variable
|
||||
///
|
||||
{
|
||||
Variable key1( Variable::Type::STRING, "key1", "", Variable::Increment::PER_ITEM );
|
||||
vars.addVariable( key1 );
|
||||
}
|
||||
QCOMPARE( textNode.text( NullRecord(), vars ), QString( "" ) );
|
||||
///
|
||||
/// Variable
|
||||
///
|
||||
{
|
||||
Variable key1( Variable::Type::STRING, "key1", "", Variable::Increment::PER_ITEM );
|
||||
vars.addVariable( key1 );
|
||||
}
|
||||
QCOMPARE( textNode.text( NullRecord(), vars ), QString( "" ) );
|
||||
|
||||
{
|
||||
Variable key1( Variable::Type::STRING, "key1", "val1", Variable::Increment::PER_ITEM );
|
||||
vars.addVariable( key1 );
|
||||
}
|
||||
QCOMPARE( textNode.text( NullRecord(), vars ), QString( "val1" ) );
|
||||
{
|
||||
Variable key1( Variable::Type::STRING, "key1", "val1", Variable::Increment::PER_ITEM );
|
||||
vars.addVariable( key1 );
|
||||
}
|
||||
QCOMPARE( textNode.text( NullRecord(), vars ), QString( "val1" ) );
|
||||
|
||||
{
|
||||
Variable key1( Variable::Type::INTEGER, "key1", "1", Variable::Increment::PER_ITEM, "1" );
|
||||
vars.addVariable( key1 );
|
||||
}
|
||||
QCOMPARE( textNode.text( NullRecord(), vars ), QString( "1" ) );
|
||||
vars.incrementVariablesOnItem();
|
||||
QCOMPARE( textNode.text( NullRecord(), vars ), QString( "2" ) );
|
||||
{
|
||||
Variable key1( Variable::Type::INTEGER, "key1", "1", Variable::Increment::PER_ITEM, "1" );
|
||||
vars.addVariable( key1 );
|
||||
}
|
||||
QCOMPARE( textNode.text( NullRecord(), vars ), QString( "1" ) );
|
||||
vars.incrementVariablesOnItem();
|
||||
QCOMPARE( textNode.text( NullRecord(), vars ), QString( "2" ) );
|
||||
|
||||
///
|
||||
/// Record beats variable
|
||||
///
|
||||
QCOMPARE( textNode.text( record, vars ), QString( "val1" ) );
|
||||
///
|
||||
/// Record beats variable
|
||||
///
|
||||
QCOMPARE( textNode.text( record, vars ), QString( "val1" ) );
|
||||
}
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
/* TestTextNode.h
|
||||
*
|
||||
* Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
|
||||
class TestTextNode : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void textNode();
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
// TestTextNode.hpp
|
||||
//
|
||||
// Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of gLabels-qt.
|
||||
//
|
||||
// gLabels-qt is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// gLabels-qt is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
|
||||
class TestTextNode : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void textNode();
|
||||
};
|
||||
+234
-233
@@ -1,28 +1,29 @@
|
||||
/* TestVariable.cpp
|
||||
*
|
||||
* Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// TestVariable.cpp
|
||||
//
|
||||
// Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of gLabels-qt.
|
||||
//
|
||||
// gLabels-qt is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// gLabels-qt is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#include "TestVariable.h"
|
||||
|
||||
#include "model/Variable.h"
|
||||
#include "TestVariable.hpp"
|
||||
|
||||
#include <QtDebug>
|
||||
#include "model/Variable.hpp"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
QTEST_MAIN(TestVariable)
|
||||
@@ -32,269 +33,269 @@ using namespace glabels::model;
|
||||
|
||||
void TestVariable::variable()
|
||||
{
|
||||
{
|
||||
Variable var;
|
||||
{
|
||||
Variable var;
|
||||
|
||||
QCOMPARE( var.type(), Variable::Type::STRING );
|
||||
QCOMPARE( var.name(), QString() );
|
||||
QCOMPARE( var.initialValue(), QString() );
|
||||
QCOMPARE( var.increment(), Variable::Increment::NEVER );
|
||||
QCOMPARE( var.stepSize(), QString( "0" ) );
|
||||
QCOMPARE( var.value(), QString() );
|
||||
QCOMPARE( var.type(), Variable::Type::STRING );
|
||||
QCOMPARE( var.name(), QString() );
|
||||
QCOMPARE( var.initialValue(), QString() );
|
||||
QCOMPARE( var.increment(), Variable::Increment::NEVER );
|
||||
QCOMPARE( var.stepSize(), QString( "0" ) );
|
||||
QCOMPARE( var.value(), QString() );
|
||||
|
||||
var.resetValue();
|
||||
QCOMPARE( var.type(), Variable::Type::STRING );
|
||||
QCOMPARE( var.name(), QString() );
|
||||
QCOMPARE( var.initialValue(), QString() );
|
||||
QCOMPARE( var.increment(), Variable::Increment::NEVER );
|
||||
QCOMPARE( var.stepSize(), QString( "0" ) );
|
||||
QCOMPARE( var.value(), QString() );
|
||||
var.resetValue();
|
||||
QCOMPARE( var.type(), Variable::Type::STRING );
|
||||
QCOMPARE( var.name(), QString() );
|
||||
QCOMPARE( var.initialValue(), QString() );
|
||||
QCOMPARE( var.increment(), Variable::Increment::NEVER );
|
||||
QCOMPARE( var.stepSize(), QString( "0" ) );
|
||||
QCOMPARE( var.value(), QString() );
|
||||
|
||||
var.incrementValueOnItem();
|
||||
QCOMPARE( var.value(), QString() );
|
||||
var.incrementValueOnItem();
|
||||
QCOMPARE( var.value(), QString() );
|
||||
|
||||
var.incrementValueOnCopy();
|
||||
QCOMPARE( var.value(), QString() );
|
||||
var.incrementValueOnCopy();
|
||||
QCOMPARE( var.value(), QString() );
|
||||
|
||||
var.incrementValueOnPage();
|
||||
QCOMPARE( var.value(), QString() );
|
||||
}
|
||||
{
|
||||
Variable var( Variable::Type::STRING, "s", "initial", Variable::Increment::PER_ITEM, "2" );
|
||||
var.incrementValueOnPage();
|
||||
QCOMPARE( var.value(), QString() );
|
||||
}
|
||||
{
|
||||
Variable var( Variable::Type::STRING, "s", "initial", Variable::Increment::PER_ITEM, "2" );
|
||||
|
||||
QCOMPARE( var.type(), Variable::Type::STRING );
|
||||
QCOMPARE( var.name(), QString( "s" ) );
|
||||
QCOMPARE( var.initialValue(), QString( "initial" ) );
|
||||
QCOMPARE( var.increment(), Variable::Increment::PER_ITEM );
|
||||
QCOMPARE( var.stepSize(), QString( "2" ) );
|
||||
QCOMPARE( var.value(), QString( "initial" ) );
|
||||
QCOMPARE( var.type(), Variable::Type::STRING );
|
||||
QCOMPARE( var.name(), QString( "s" ) );
|
||||
QCOMPARE( var.initialValue(), QString( "initial" ) );
|
||||
QCOMPARE( var.increment(), Variable::Increment::PER_ITEM );
|
||||
QCOMPARE( var.stepSize(), QString( "2" ) );
|
||||
QCOMPARE( var.value(), QString( "initial" ) );
|
||||
|
||||
var.resetValue();
|
||||
QCOMPARE( var.name(), QString( "s" ) );
|
||||
QCOMPARE( var.initialValue(), QString( "initial" ) );
|
||||
QCOMPARE( var.increment(), Variable::Increment::PER_ITEM );
|
||||
QCOMPARE( var.stepSize(), QString( "2" ) );
|
||||
QCOMPARE( var.value(), QString( "initial" ) );
|
||||
var.resetValue();
|
||||
QCOMPARE( var.name(), QString( "s" ) );
|
||||
QCOMPARE( var.initialValue(), QString( "initial" ) );
|
||||
QCOMPARE( var.increment(), Variable::Increment::PER_ITEM );
|
||||
QCOMPARE( var.stepSize(), QString( "2" ) );
|
||||
QCOMPARE( var.value(), QString( "initial" ) );
|
||||
|
||||
var.incrementValueOnItem();
|
||||
QCOMPARE( var.value(), QString( "initial" ) );
|
||||
var.incrementValueOnItem();
|
||||
QCOMPARE( var.value(), QString( "initial" ) );
|
||||
|
||||
var.incrementValueOnCopy();
|
||||
QCOMPARE( var.value(), QString( "initial" ) );
|
||||
var.incrementValueOnCopy();
|
||||
QCOMPARE( var.value(), QString( "initial" ) );
|
||||
|
||||
var.incrementValueOnPage();
|
||||
QCOMPARE( var.value(), QString( "initial" ) );
|
||||
var.incrementValueOnPage();
|
||||
QCOMPARE( var.value(), QString( "initial" ) );
|
||||
|
||||
var.resetValue();
|
||||
QCOMPARE( var.name(), QString( "s" ) );
|
||||
QCOMPARE( var.initialValue(), QString( "initial" ) );
|
||||
QCOMPARE( var.increment(), Variable::Increment::PER_ITEM );
|
||||
QCOMPARE( var.stepSize(), QString( "2" ) );
|
||||
QCOMPARE( var.value(), QString( "initial" ) );
|
||||
}
|
||||
{
|
||||
Variable var( Variable::Type::INTEGER, "i", "123", Variable::Increment::PER_ITEM, "1" );
|
||||
var.resetValue();
|
||||
QCOMPARE( var.name(), QString( "s" ) );
|
||||
QCOMPARE( var.initialValue(), QString( "initial" ) );
|
||||
QCOMPARE( var.increment(), Variable::Increment::PER_ITEM );
|
||||
QCOMPARE( var.stepSize(), QString( "2" ) );
|
||||
QCOMPARE( var.value(), QString( "initial" ) );
|
||||
}
|
||||
{
|
||||
Variable var( Variable::Type::INTEGER, "i", "123", Variable::Increment::PER_ITEM, "1" );
|
||||
|
||||
QCOMPARE( var.type(), Variable::Type::INTEGER );
|
||||
QCOMPARE( var.name(), QString( "i" ) );
|
||||
QCOMPARE( var.initialValue(), QString( "123" ) );
|
||||
QCOMPARE( var.increment(), Variable::Increment::PER_ITEM );
|
||||
QCOMPARE( var.stepSize(), QString( "1" ) );
|
||||
QCOMPARE( var.value(), QString( "123" ) );
|
||||
QCOMPARE( var.type(), Variable::Type::INTEGER );
|
||||
QCOMPARE( var.name(), QString( "i" ) );
|
||||
QCOMPARE( var.initialValue(), QString( "123" ) );
|
||||
QCOMPARE( var.increment(), Variable::Increment::PER_ITEM );
|
||||
QCOMPARE( var.stepSize(), QString( "1" ) );
|
||||
QCOMPARE( var.value(), QString( "123" ) );
|
||||
|
||||
var.resetValue();
|
||||
QCOMPARE( var.type(), Variable::Type::INTEGER );
|
||||
QCOMPARE( var.name(), QString( "i" ) );
|
||||
QCOMPARE( var.initialValue(), QString( "123" ) );
|
||||
QCOMPARE( var.increment(), Variable::Increment::PER_ITEM );
|
||||
QCOMPARE( var.stepSize(), QString( "1" ) );
|
||||
QCOMPARE( var.value(), QString( "123" ) );
|
||||
var.resetValue();
|
||||
QCOMPARE( var.type(), Variable::Type::INTEGER );
|
||||
QCOMPARE( var.name(), QString( "i" ) );
|
||||
QCOMPARE( var.initialValue(), QString( "123" ) );
|
||||
QCOMPARE( var.increment(), Variable::Increment::PER_ITEM );
|
||||
QCOMPARE( var.stepSize(), QString( "1" ) );
|
||||
QCOMPARE( var.value(), QString( "123" ) );
|
||||
|
||||
var.incrementValueOnItem();
|
||||
QCOMPARE( var.value(), QString( "124" ) );
|
||||
var.incrementValueOnItem();
|
||||
QCOMPARE( var.value(), QString( "124" ) );
|
||||
|
||||
var.incrementValueOnCopy();
|
||||
QCOMPARE( var.value(), QString( "124" ) );
|
||||
var.incrementValueOnCopy();
|
||||
QCOMPARE( var.value(), QString( "124" ) );
|
||||
|
||||
var.incrementValueOnPage();
|
||||
QCOMPARE( var.value(), QString( "124" ) );
|
||||
var.incrementValueOnPage();
|
||||
QCOMPARE( var.value(), QString( "124" ) );
|
||||
|
||||
var.incrementValueOnItem();
|
||||
QCOMPARE( var.value(), QString( "125" ) );
|
||||
var.incrementValueOnItem();
|
||||
QCOMPARE( var.value(), QString( "125" ) );
|
||||
|
||||
var.incrementValueOnCopy();
|
||||
QCOMPARE( var.value(), QString( "125" ) );
|
||||
var.incrementValueOnCopy();
|
||||
QCOMPARE( var.value(), QString( "125" ) );
|
||||
|
||||
var.incrementValueOnPage();
|
||||
QCOMPARE( var.value(), QString( "125" ) );
|
||||
var.incrementValueOnPage();
|
||||
QCOMPARE( var.value(), QString( "125" ) );
|
||||
|
||||
var.resetValue();
|
||||
QCOMPARE( var.type(), Variable::Type::INTEGER );
|
||||
QCOMPARE( var.name(), QString( "i" ) );
|
||||
QCOMPARE( var.initialValue(), QString( "123" ) );
|
||||
QCOMPARE( var.increment(), Variable::Increment::PER_ITEM );
|
||||
QCOMPARE( var.stepSize(), QString( "1" ) );
|
||||
QCOMPARE( var.value(), QString( "123" ) );
|
||||
}
|
||||
{
|
||||
Variable var( Variable::Type::INTEGER, "i", "1", Variable::Increment::PER_PAGE, "2" );
|
||||
var.resetValue();
|
||||
QCOMPARE( var.type(), Variable::Type::INTEGER );
|
||||
QCOMPARE( var.name(), QString( "i" ) );
|
||||
QCOMPARE( var.initialValue(), QString( "123" ) );
|
||||
QCOMPARE( var.increment(), Variable::Increment::PER_ITEM );
|
||||
QCOMPARE( var.stepSize(), QString( "1" ) );
|
||||
QCOMPARE( var.value(), QString( "123" ) );
|
||||
}
|
||||
{
|
||||
Variable var( Variable::Type::INTEGER, "i", "1", Variable::Increment::PER_PAGE, "2" );
|
||||
|
||||
QCOMPARE( var.type(), Variable::Type::INTEGER );
|
||||
QCOMPARE( var.name(), QString( "i" ) );
|
||||
QCOMPARE( var.initialValue(), QString( "1" ) );
|
||||
QCOMPARE( var.increment(), Variable::Increment::PER_PAGE );
|
||||
QCOMPARE( var.stepSize(), QString( "2" ) );
|
||||
QCOMPARE( var.value(), QString( "1" ) );
|
||||
QCOMPARE( var.type(), Variable::Type::INTEGER );
|
||||
QCOMPARE( var.name(), QString( "i" ) );
|
||||
QCOMPARE( var.initialValue(), QString( "1" ) );
|
||||
QCOMPARE( var.increment(), Variable::Increment::PER_PAGE );
|
||||
QCOMPARE( var.stepSize(), QString( "2" ) );
|
||||
QCOMPARE( var.value(), QString( "1" ) );
|
||||
|
||||
var.resetValue();
|
||||
QCOMPARE( var.type(), Variable::Type::INTEGER );
|
||||
QCOMPARE( var.name(), QString( "i" ) );
|
||||
QCOMPARE( var.initialValue(), QString( "1" ) );
|
||||
QCOMPARE( var.increment(), Variable::Increment::PER_PAGE );
|
||||
QCOMPARE( var.stepSize(), QString( "2" ) );
|
||||
QCOMPARE( var.value(), QString( "1" ) );
|
||||
var.resetValue();
|
||||
QCOMPARE( var.type(), Variable::Type::INTEGER );
|
||||
QCOMPARE( var.name(), QString( "i" ) );
|
||||
QCOMPARE( var.initialValue(), QString( "1" ) );
|
||||
QCOMPARE( var.increment(), Variable::Increment::PER_PAGE );
|
||||
QCOMPARE( var.stepSize(), QString( "2" ) );
|
||||
QCOMPARE( var.value(), QString( "1" ) );
|
||||
|
||||
var.incrementValueOnItem();
|
||||
QCOMPARE( var.value(), QString( "1" ) );
|
||||
var.incrementValueOnItem();
|
||||
QCOMPARE( var.value(), QString( "1" ) );
|
||||
|
||||
var.incrementValueOnCopy();
|
||||
QCOMPARE( var.value(), QString( "1" ) );
|
||||
var.incrementValueOnCopy();
|
||||
QCOMPARE( var.value(), QString( "1" ) );
|
||||
|
||||
var.incrementValueOnPage();
|
||||
QCOMPARE( var.value(), QString( "3" ) );
|
||||
var.incrementValueOnPage();
|
||||
QCOMPARE( var.value(), QString( "3" ) );
|
||||
|
||||
var.incrementValueOnItem();
|
||||
QCOMPARE( var.value(), QString( "3" ) );
|
||||
var.incrementValueOnItem();
|
||||
QCOMPARE( var.value(), QString( "3" ) );
|
||||
|
||||
var.incrementValueOnCopy();
|
||||
QCOMPARE( var.value(), QString( "3" ) );
|
||||
var.incrementValueOnCopy();
|
||||
QCOMPARE( var.value(), QString( "3" ) );
|
||||
|
||||
var.incrementValueOnPage();
|
||||
QCOMPARE( var.value(), QString( "5" ) );
|
||||
var.incrementValueOnPage();
|
||||
QCOMPARE( var.value(), QString( "5" ) );
|
||||
|
||||
var.resetValue();
|
||||
QCOMPARE( var.type(), Variable::Type::INTEGER );
|
||||
QCOMPARE( var.name(), QString( "i" ) );
|
||||
QCOMPARE( var.initialValue(), QString( "1" ) );
|
||||
QCOMPARE( var.increment(), Variable::Increment::PER_PAGE );
|
||||
QCOMPARE( var.stepSize(), QString( "2" ) );
|
||||
QCOMPARE( var.value(), QString( "1" ) );
|
||||
}
|
||||
{
|
||||
Variable var( Variable::Type::FLOATING_POINT, "f", "1.2", Variable::Increment::PER_COPY, "0.2" );
|
||||
var.resetValue();
|
||||
QCOMPARE( var.type(), Variable::Type::INTEGER );
|
||||
QCOMPARE( var.name(), QString( "i" ) );
|
||||
QCOMPARE( var.initialValue(), QString( "1" ) );
|
||||
QCOMPARE( var.increment(), Variable::Increment::PER_PAGE );
|
||||
QCOMPARE( var.stepSize(), QString( "2" ) );
|
||||
QCOMPARE( var.value(), QString( "1" ) );
|
||||
}
|
||||
{
|
||||
Variable var( Variable::Type::FLOATING_POINT, "f", "1.2", Variable::Increment::PER_COPY, "0.2" );
|
||||
|
||||
QCOMPARE( var.type(), Variable::Type::FLOATING_POINT );
|
||||
QCOMPARE( var.name(), QString( "f" ) );
|
||||
QCOMPARE( var.initialValue(), QString( "1.2" ) );
|
||||
QCOMPARE( var.increment(), Variable::Increment::PER_COPY );
|
||||
QCOMPARE( var.stepSize(), QString( "0.2" ) );
|
||||
QCOMPARE( var.value(), QString( "1.2" ) );
|
||||
QCOMPARE( var.type(), Variable::Type::FLOATING_POINT );
|
||||
QCOMPARE( var.name(), QString( "f" ) );
|
||||
QCOMPARE( var.initialValue(), QString( "1.2" ) );
|
||||
QCOMPARE( var.increment(), Variable::Increment::PER_COPY );
|
||||
QCOMPARE( var.stepSize(), QString( "0.2" ) );
|
||||
QCOMPARE( var.value(), QString( "1.2" ) );
|
||||
|
||||
var.resetValue();
|
||||
QCOMPARE( var.type(), Variable::Type::FLOATING_POINT );
|
||||
QCOMPARE( var.name(), QString( "f" ) );
|
||||
QCOMPARE( var.initialValue(), QString( "1.2" ) );
|
||||
QCOMPARE( var.increment(), Variable::Increment::PER_COPY );
|
||||
QCOMPARE( var.stepSize(), QString( "0.2" ) );
|
||||
QCOMPARE( var.value(), QString( "1.2" ) );
|
||||
var.resetValue();
|
||||
QCOMPARE( var.type(), Variable::Type::FLOATING_POINT );
|
||||
QCOMPARE( var.name(), QString( "f" ) );
|
||||
QCOMPARE( var.initialValue(), QString( "1.2" ) );
|
||||
QCOMPARE( var.increment(), Variable::Increment::PER_COPY );
|
||||
QCOMPARE( var.stepSize(), QString( "0.2" ) );
|
||||
QCOMPARE( var.value(), QString( "1.2" ) );
|
||||
|
||||
var.incrementValueOnItem();
|
||||
QCOMPARE( var.value(), QString( "1.2" ) );
|
||||
var.incrementValueOnItem();
|
||||
QCOMPARE( var.value(), QString( "1.2" ) );
|
||||
|
||||
var.incrementValueOnCopy();
|
||||
QCOMPARE( var.value(), QString( "1.4" ) );
|
||||
var.incrementValueOnCopy();
|
||||
QCOMPARE( var.value(), QString( "1.4" ) );
|
||||
|
||||
var.incrementValueOnPage();
|
||||
QCOMPARE( var.value(), QString( "1.4" ) );
|
||||
var.incrementValueOnPage();
|
||||
QCOMPARE( var.value(), QString( "1.4" ) );
|
||||
|
||||
var.incrementValueOnItem();
|
||||
QCOMPARE( var.value(), QString( "1.4" ) );
|
||||
var.incrementValueOnItem();
|
||||
QCOMPARE( var.value(), QString( "1.4" ) );
|
||||
|
||||
var.incrementValueOnCopy();
|
||||
QCOMPARE( var.value(), QString( "1.6" ) );
|
||||
var.incrementValueOnCopy();
|
||||
QCOMPARE( var.value(), QString( "1.6" ) );
|
||||
|
||||
var.incrementValueOnPage();
|
||||
QCOMPARE( var.value(), QString( "1.6" ) );
|
||||
var.incrementValueOnPage();
|
||||
QCOMPARE( var.value(), QString( "1.6" ) );
|
||||
|
||||
var.resetValue();
|
||||
QCOMPARE( var.type(), Variable::Type::FLOATING_POINT );
|
||||
QCOMPARE( var.name(), QString( "f" ) );
|
||||
QCOMPARE( var.initialValue(), QString( "1.2" ) );
|
||||
QCOMPARE( var.increment(), Variable::Increment::PER_COPY );
|
||||
QCOMPARE( var.stepSize(), QString( "0.2" ) );
|
||||
QCOMPARE( var.value(), QString( "1.2" ) );
|
||||
}
|
||||
{
|
||||
Variable var( Variable::Type::COLOR, "c", "white", Variable::Increment::PER_PAGE );
|
||||
var.resetValue();
|
||||
QCOMPARE( var.type(), Variable::Type::FLOATING_POINT );
|
||||
QCOMPARE( var.name(), QString( "f" ) );
|
||||
QCOMPARE( var.initialValue(), QString( "1.2" ) );
|
||||
QCOMPARE( var.increment(), Variable::Increment::PER_COPY );
|
||||
QCOMPARE( var.stepSize(), QString( "0.2" ) );
|
||||
QCOMPARE( var.value(), QString( "1.2" ) );
|
||||
}
|
||||
{
|
||||
Variable var( Variable::Type::COLOR, "c", "white", Variable::Increment::PER_PAGE );
|
||||
|
||||
QCOMPARE( var.type(), Variable::Type::COLOR );
|
||||
QCOMPARE( var.name(), QString( "c" ) );
|
||||
QCOMPARE( var.initialValue(), QString( "white" ) );
|
||||
QCOMPARE( var.increment(), Variable::Increment::PER_PAGE );
|
||||
QCOMPARE( var.stepSize(), QString( "0" ) );
|
||||
QCOMPARE( var.value(), QString( "white" ) );
|
||||
QCOMPARE( var.type(), Variable::Type::COLOR );
|
||||
QCOMPARE( var.name(), QString( "c" ) );
|
||||
QCOMPARE( var.initialValue(), QString( "white" ) );
|
||||
QCOMPARE( var.increment(), Variable::Increment::PER_PAGE );
|
||||
QCOMPARE( var.stepSize(), QString( "0" ) );
|
||||
QCOMPARE( var.value(), QString( "white" ) );
|
||||
|
||||
var.resetValue();
|
||||
QCOMPARE( var.name(), QString( "c" ) );
|
||||
QCOMPARE( var.initialValue(), QString( "white" ) );
|
||||
QCOMPARE( var.increment(), Variable::Increment::PER_PAGE );
|
||||
QCOMPARE( var.stepSize(), QString( "0" ) );
|
||||
QCOMPARE( var.value(), QString( "white" ) );
|
||||
var.resetValue();
|
||||
QCOMPARE( var.name(), QString( "c" ) );
|
||||
QCOMPARE( var.initialValue(), QString( "white" ) );
|
||||
QCOMPARE( var.increment(), Variable::Increment::PER_PAGE );
|
||||
QCOMPARE( var.stepSize(), QString( "0" ) );
|
||||
QCOMPARE( var.value(), QString( "white" ) );
|
||||
|
||||
var.incrementValueOnItem();
|
||||
QCOMPARE( var.value(), QString( "white" ) );
|
||||
var.incrementValueOnItem();
|
||||
QCOMPARE( var.value(), QString( "white" ) );
|
||||
|
||||
var.incrementValueOnCopy();
|
||||
QCOMPARE( var.value(), QString( "white" ) );
|
||||
var.incrementValueOnCopy();
|
||||
QCOMPARE( var.value(), QString( "white" ) );
|
||||
|
||||
var.incrementValueOnPage();
|
||||
QCOMPARE( var.value(), QString( "white" ) );
|
||||
var.incrementValueOnPage();
|
||||
QCOMPARE( var.value(), QString( "white" ) );
|
||||
|
||||
var.resetValue();
|
||||
QCOMPARE( var.name(), QString( "c" ) );
|
||||
QCOMPARE( var.initialValue(), QString( "white" ) );
|
||||
QCOMPARE( var.increment(), Variable::Increment::PER_PAGE );
|
||||
QCOMPARE( var.stepSize(), QString( "0" ) );
|
||||
QCOMPARE( var.value(), QString( "white" ) );
|
||||
}
|
||||
var.resetValue();
|
||||
QCOMPARE( var.name(), QString( "c" ) );
|
||||
QCOMPARE( var.initialValue(), QString( "white" ) );
|
||||
QCOMPARE( var.increment(), Variable::Increment::PER_PAGE );
|
||||
QCOMPARE( var.stepSize(), QString( "0" ) );
|
||||
QCOMPARE( var.value(), QString( "white" ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TestVariable::statics()
|
||||
{
|
||||
QCOMPARE( Variable::typeToI18nString( Variable::Type::STRING ), QString( "String" ) );
|
||||
QCOMPARE( Variable::typeToI18nString( Variable::Type::INTEGER ), QString( "Integer" ) );
|
||||
QCOMPARE( Variable::typeToI18nString( Variable::Type::FLOATING_POINT ), QString( "Floating Point" ) );
|
||||
QCOMPARE( Variable::typeToI18nString( Variable::Type::COLOR ), QString( "Color" ) );
|
||||
QCOMPARE( Variable::typeToI18nString( (Variable::Type)4 ), QString( "String" ) );
|
||||
QCOMPARE( Variable::typeToI18nString( Variable::Type::STRING ), QString( "String" ) );
|
||||
QCOMPARE( Variable::typeToI18nString( Variable::Type::INTEGER ), QString( "Integer" ) );
|
||||
QCOMPARE( Variable::typeToI18nString( Variable::Type::FLOATING_POINT ), QString( "Floating Point" ) );
|
||||
QCOMPARE( Variable::typeToI18nString( Variable::Type::COLOR ), QString( "Color" ) );
|
||||
QCOMPARE( Variable::typeToI18nString( (Variable::Type)4 ), QString( "String" ) );
|
||||
|
||||
QCOMPARE( Variable::typeToIdString( Variable::Type::STRING ), QString( "string" ) );
|
||||
QCOMPARE( Variable::typeToIdString( Variable::Type::INTEGER ), QString( "integer" ) );
|
||||
QCOMPARE( Variable::typeToIdString( Variable::Type::FLOATING_POINT ), QString( "float" ) );
|
||||
QCOMPARE( Variable::typeToIdString( Variable::Type::COLOR ), QString( "color" ) );
|
||||
QCOMPARE( Variable::typeToIdString( (Variable::Type)4 ), QString( "string" ) );
|
||||
QCOMPARE( Variable::typeToIdString( Variable::Type::STRING ), QString( "string" ) );
|
||||
QCOMPARE( Variable::typeToIdString( Variable::Type::INTEGER ), QString( "integer" ) );
|
||||
QCOMPARE( Variable::typeToIdString( Variable::Type::FLOATING_POINT ), QString( "float" ) );
|
||||
QCOMPARE( Variable::typeToIdString( Variable::Type::COLOR ), QString( "color" ) );
|
||||
QCOMPARE( Variable::typeToIdString( (Variable::Type)4 ), QString( "string" ) );
|
||||
|
||||
QCOMPARE( Variable::idStringToType( "string" ), Variable::Type::STRING );
|
||||
QCOMPARE( Variable::idStringToType( "integer"), Variable::Type::INTEGER );
|
||||
QCOMPARE( Variable::idStringToType( "float" ), Variable::Type::FLOATING_POINT );
|
||||
QCOMPARE( Variable::idStringToType( "color" ), Variable::Type::COLOR );
|
||||
QCOMPARE( Variable::idStringToType( "non_existent" ), Variable::Type::STRING );
|
||||
QCOMPARE( Variable::idStringToType( "string" ), Variable::Type::STRING );
|
||||
QCOMPARE( Variable::idStringToType( "integer"), Variable::Type::INTEGER );
|
||||
QCOMPARE( Variable::idStringToType( "float" ), Variable::Type::FLOATING_POINT );
|
||||
QCOMPARE( Variable::idStringToType( "color" ), Variable::Type::COLOR );
|
||||
QCOMPARE( Variable::idStringToType( "non_existent" ), Variable::Type::STRING );
|
||||
|
||||
QCOMPARE( Variable::incrementToI18nString( Variable::Increment::NEVER ), QString( "Never" ) );
|
||||
QCOMPARE( Variable::incrementToI18nString( Variable::Increment::PER_ITEM ), QString( "Per item" ) );
|
||||
QCOMPARE( Variable::incrementToI18nString( Variable::Increment::PER_COPY ), QString( "Per copy" ) );
|
||||
QCOMPARE( Variable::incrementToI18nString( Variable::Increment::PER_PAGE ), QString( "Per page" ) );
|
||||
QCOMPARE( Variable::incrementToI18nString( (Variable::Increment)4 ), QString( "Never" ) );
|
||||
QCOMPARE( Variable::incrementToI18nString( Variable::Increment::NEVER ), QString( "Never" ) );
|
||||
QCOMPARE( Variable::incrementToI18nString( Variable::Increment::PER_ITEM ), QString( "Per item" ) );
|
||||
QCOMPARE( Variable::incrementToI18nString( Variable::Increment::PER_COPY ), QString( "Per copy" ) );
|
||||
QCOMPARE( Variable::incrementToI18nString( Variable::Increment::PER_PAGE ), QString( "Per page" ) );
|
||||
QCOMPARE( Variable::incrementToI18nString( (Variable::Increment)4 ), QString( "Never" ) );
|
||||
|
||||
QCOMPARE( Variable::incrementToIdString( Variable::Increment::NEVER ), QString( "never" ) );
|
||||
QCOMPARE( Variable::incrementToIdString( Variable::Increment::PER_ITEM ), QString( "per_item" ) );
|
||||
QCOMPARE( Variable::incrementToIdString( Variable::Increment::PER_COPY ), QString( "per_copy" ) );
|
||||
QCOMPARE( Variable::incrementToIdString( Variable::Increment::PER_PAGE ), QString( "per_page" ) );
|
||||
QCOMPARE( Variable::incrementToIdString( (Variable::Increment)4 ), QString( "never" ) );
|
||||
QCOMPARE( Variable::incrementToIdString( Variable::Increment::NEVER ), QString( "never" ) );
|
||||
QCOMPARE( Variable::incrementToIdString( Variable::Increment::PER_ITEM ), QString( "per_item" ) );
|
||||
QCOMPARE( Variable::incrementToIdString( Variable::Increment::PER_COPY ), QString( "per_copy" ) );
|
||||
QCOMPARE( Variable::incrementToIdString( Variable::Increment::PER_PAGE ), QString( "per_page" ) );
|
||||
QCOMPARE( Variable::incrementToIdString( (Variable::Increment)4 ), QString( "never" ) );
|
||||
|
||||
QCOMPARE( Variable::idStringToIncrement( "never" ), Variable::Increment::NEVER );
|
||||
QCOMPARE( Variable::idStringToIncrement( "per_item" ), Variable::Increment::PER_ITEM );
|
||||
QCOMPARE( Variable::idStringToIncrement( "per_copy" ), Variable::Increment::PER_COPY );
|
||||
QCOMPARE( Variable::idStringToIncrement( "per_page" ), Variable::Increment::PER_PAGE );
|
||||
QCOMPARE( Variable::idStringToIncrement( "non_existent" ), Variable::Increment::NEVER );
|
||||
QCOMPARE( Variable::idStringToIncrement( "never" ), Variable::Increment::NEVER );
|
||||
QCOMPARE( Variable::idStringToIncrement( "per_item" ), Variable::Increment::PER_ITEM );
|
||||
QCOMPARE( Variable::idStringToIncrement( "per_copy" ), Variable::Increment::PER_COPY );
|
||||
QCOMPARE( Variable::idStringToIncrement( "per_page" ), Variable::Increment::PER_PAGE );
|
||||
QCOMPARE( Variable::idStringToIncrement( "non_existent" ), Variable::Increment::NEVER );
|
||||
}
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
/* TestVariable.h
|
||||
*
|
||||
* Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
|
||||
class TestVariable : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void variable();
|
||||
void statics();
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
// TestVariable.hpp
|
||||
//
|
||||
// Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of gLabels-qt.
|
||||
//
|
||||
// gLabels-qt is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// gLabels-qt is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
|
||||
class TestVariable : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void variable();
|
||||
void statics();
|
||||
};
|
||||
+118
-117
@@ -1,28 +1,29 @@
|
||||
/* TestVariables.cpp
|
||||
*
|
||||
* Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// TestVariables.cpp
|
||||
//
|
||||
// Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of gLabels-qt.
|
||||
//
|
||||
// gLabels-qt is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// gLabels-qt is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#include "TestVariables.h"
|
||||
|
||||
#include "model/Variables.h"
|
||||
#include "TestVariables.hpp"
|
||||
|
||||
#include <QtDebug>
|
||||
#include "model/Variables.hpp"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
QTEST_MAIN(TestVariables)
|
||||
@@ -32,126 +33,126 @@ using namespace glabels::model;
|
||||
|
||||
void TestVariables::variables()
|
||||
{
|
||||
Variables vars;
|
||||
Variables vars;
|
||||
|
||||
Variable i( Variable::Type::INTEGER, "i", "3", Variable::Increment::PER_ITEM, "3" );
|
||||
QCOMPARE( i.value(), QString( "3" ) );
|
||||
Variable i( Variable::Type::INTEGER, "i", "3", Variable::Increment::PER_ITEM, "3" );
|
||||
QCOMPARE( i.value(), QString( "3" ) );
|
||||
|
||||
Variable i2( Variable::Type::INTEGER, "i2", "100", Variable::Increment::PER_COPY, "2" );
|
||||
QCOMPARE( i2.value(), QString( "100" ) );
|
||||
Variable i2( Variable::Type::INTEGER, "i2", "100", Variable::Increment::PER_COPY, "2" );
|
||||
QCOMPARE( i2.value(), QString( "100" ) );
|
||||
|
||||
Variable f( Variable::Type::FLOATING_POINT, "f", "0.0", Variable::Increment::PER_PAGE, "0.1" );
|
||||
QCOMPARE( f.value(), QString( "0" ) );
|
||||
Variable f( Variable::Type::FLOATING_POINT, "f", "0.0", Variable::Increment::PER_PAGE, "0.1" );
|
||||
QCOMPARE( f.value(), QString( "0" ) );
|
||||
|
||||
Variable s( Variable::Type::STRING, "s", "initial", Variable::Increment::PER_ITEM, "1" );
|
||||
QCOMPARE( s.value(), QString( "initial" ) );
|
||||
Variable s( Variable::Type::STRING, "s", "initial", Variable::Increment::PER_ITEM, "1" );
|
||||
QCOMPARE( s.value(), QString( "initial" ) );
|
||||
|
||||
Variable c( Variable::Type::COLOR, "c", "white", Variable::Increment::PER_ITEM, "01" );
|
||||
QCOMPARE( c.value(), QString( "white" ) );
|
||||
Variable c( Variable::Type::COLOR, "c", "white", Variable::Increment::PER_ITEM, "01" );
|
||||
QCOMPARE( c.value(), QString( "white" ) );
|
||||
|
||||
QVERIFY( !vars.hasVariable( "i" ) );
|
||||
QVERIFY( !vars.hasVariable( "i2" ) );
|
||||
QVERIFY( !vars.hasVariable( "i" ) );
|
||||
QVERIFY( !vars.hasVariable( "i2" ) );
|
||||
|
||||
// Add, delete
|
||||
vars.addVariable( i );
|
||||
QVERIFY( vars.hasVariable( "i" ) );
|
||||
QCOMPARE( vars["i"].value(), i.value() );
|
||||
vars.deleteVariable( "i" );
|
||||
QVERIFY( !vars.hasVariable( "i" ) );
|
||||
QCOMPARE( vars["i"].value(), QString() );
|
||||
// Add, delete
|
||||
vars.addVariable( i );
|
||||
QVERIFY( vars.hasVariable( "i" ) );
|
||||
QCOMPARE( vars["i"].value(), i.value() );
|
||||
vars.deleteVariable( "i" );
|
||||
QVERIFY( !vars.hasVariable( "i" ) );
|
||||
QCOMPARE( vars["i"].value(), QString() );
|
||||
|
||||
// Add, replace
|
||||
vars.addVariable( i );
|
||||
QVERIFY( vars.hasVariable( "i" ) );
|
||||
QCOMPARE( vars["i"].value(), i.value() );
|
||||
vars.replaceVariable( "i", i2 );
|
||||
QVERIFY( !vars.hasVariable( "i" ) );
|
||||
QVERIFY( vars.hasVariable( "i2" ) );
|
||||
QCOMPARE( vars["i2"].value(), i2.value() );
|
||||
QCOMPARE( vars["i"].value(), QString() );
|
||||
vars.deleteVariable( "i2" );
|
||||
QVERIFY( !vars.hasVariable( "i2" ) );
|
||||
// Add, replace
|
||||
vars.addVariable( i );
|
||||
QVERIFY( vars.hasVariable( "i" ) );
|
||||
QCOMPARE( vars["i"].value(), i.value() );
|
||||
vars.replaceVariable( "i", i2 );
|
||||
QVERIFY( !vars.hasVariable( "i" ) );
|
||||
QVERIFY( vars.hasVariable( "i2" ) );
|
||||
QCOMPARE( vars["i2"].value(), i2.value() );
|
||||
QCOMPARE( vars["i"].value(), QString() );
|
||||
vars.deleteVariable( "i2" );
|
||||
QVERIFY( !vars.hasVariable( "i2" ) );
|
||||
|
||||
// Increment
|
||||
vars.addVariable( i );
|
||||
vars.addVariable( i2 );
|
||||
vars.addVariable( f );
|
||||
vars.addVariable( s );
|
||||
vars.addVariable( c );
|
||||
// Increment
|
||||
vars.addVariable( i );
|
||||
vars.addVariable( i2 );
|
||||
vars.addVariable( f );
|
||||
vars.addVariable( s );
|
||||
vars.addVariable( c );
|
||||
|
||||
QVERIFY( vars.hasVariable( "i" ) ); // PER_ITEM
|
||||
QVERIFY( vars.hasVariable( "i2" ) ); // PER_COPY
|
||||
QVERIFY( vars.hasVariable( "f" ) ); // PER_PAGE
|
||||
QVERIFY( vars.hasVariable( "s" ) );
|
||||
QVERIFY( vars.hasVariable( "c" ) );
|
||||
QVERIFY( vars.hasVariable( "i" ) ); // PER_ITEM
|
||||
QVERIFY( vars.hasVariable( "i2" ) ); // PER_COPY
|
||||
QVERIFY( vars.hasVariable( "f" ) ); // PER_PAGE
|
||||
QVERIFY( vars.hasVariable( "s" ) );
|
||||
QVERIFY( vars.hasVariable( "c" ) );
|
||||
|
||||
QCOMPARE( vars["i"].value(), QString( "3" ) );
|
||||
QCOMPARE( vars["i2"].value(), QString( "100" ) ); // PRE_COPY
|
||||
QCOMPARE( vars["f"].value(), QString( "0" ) ); // PER_PAGE
|
||||
QCOMPARE( vars["s"].value(), QString( "initial" ) );
|
||||
QCOMPARE( vars["c"].value(), QString( "white" ) );
|
||||
QCOMPARE( vars["i"].value(), QString( "3" ) );
|
||||
QCOMPARE( vars["i2"].value(), QString( "100" ) ); // PRE_COPY
|
||||
QCOMPARE( vars["f"].value(), QString( "0" ) ); // PER_PAGE
|
||||
QCOMPARE( vars["s"].value(), QString( "initial" ) );
|
||||
QCOMPARE( vars["c"].value(), QString( "white" ) );
|
||||
|
||||
vars.resetVariables();
|
||||
vars.resetVariables();
|
||||
|
||||
QCOMPARE( vars["i"].value(), QString( "3" ) ); // PER_ITEM
|
||||
QCOMPARE( vars["i2"].value(), QString( "100" ) ); // PRE_COPY
|
||||
QCOMPARE( vars["f"].value(), QString( "0" ) ); // PER_PAGE
|
||||
QCOMPARE( vars["s"].value(), QString( "initial" ) );
|
||||
QCOMPARE( vars["c"].value(), QString( "white" ) );
|
||||
QCOMPARE( vars["i"].value(), QString( "3" ) ); // PER_ITEM
|
||||
QCOMPARE( vars["i2"].value(), QString( "100" ) ); // PRE_COPY
|
||||
QCOMPARE( vars["f"].value(), QString( "0" ) ); // PER_PAGE
|
||||
QCOMPARE( vars["s"].value(), QString( "initial" ) );
|
||||
QCOMPARE( vars["c"].value(), QString( "white" ) );
|
||||
|
||||
vars.incrementVariablesOnItem();
|
||||
vars.incrementVariablesOnItem();
|
||||
|
||||
QCOMPARE( vars["i"].value(), QString( "6" ) ); // PER_ITEM
|
||||
QCOMPARE( vars["i2"].value(), QString( "100" ) ); // PER_COPY
|
||||
QCOMPARE( vars["f"].value(), QString( "0" ) ); // PER_PAGE
|
||||
QCOMPARE( vars["s"].value(), QString( "initial" ) );
|
||||
QCOMPARE( vars["c"].value(), QString( "white" ) );
|
||||
QCOMPARE( vars["i"].value(), QString( "6" ) ); // PER_ITEM
|
||||
QCOMPARE( vars["i2"].value(), QString( "100" ) ); // PER_COPY
|
||||
QCOMPARE( vars["f"].value(), QString( "0" ) ); // PER_PAGE
|
||||
QCOMPARE( vars["s"].value(), QString( "initial" ) );
|
||||
QCOMPARE( vars["c"].value(), QString( "white" ) );
|
||||
|
||||
vars.incrementVariablesOnItem();
|
||||
vars.incrementVariablesOnItem();
|
||||
|
||||
QCOMPARE( vars["i"].value(), QString( "9" ) ); // PER_ITEM
|
||||
QCOMPARE( vars["i2"].value(), QString( "100" ) ); // PER_COPY
|
||||
QCOMPARE( vars["f"].value(), QString( "0" ) ); // PER_PAGE
|
||||
QCOMPARE( vars["s"].value(), QString( "initial" ) );
|
||||
QCOMPARE( vars["c"].value(), QString( "white" ) );
|
||||
QCOMPARE( vars["i"].value(), QString( "9" ) ); // PER_ITEM
|
||||
QCOMPARE( vars["i2"].value(), QString( "100" ) ); // PER_COPY
|
||||
QCOMPARE( vars["f"].value(), QString( "0" ) ); // PER_PAGE
|
||||
QCOMPARE( vars["s"].value(), QString( "initial" ) );
|
||||
QCOMPARE( vars["c"].value(), QString( "white" ) );
|
||||
|
||||
vars.incrementVariablesOnCopy();
|
||||
vars.incrementVariablesOnCopy();
|
||||
|
||||
QCOMPARE( vars["i"].value(), QString( "9" ) ); // PER_ITEM
|
||||
QCOMPARE( vars["i2"].value(), QString( "102" ) ); // PER_COPY
|
||||
QCOMPARE( vars["f"].value(), QString( "0" ) ); // PER_PAGE
|
||||
QCOMPARE( vars["s"].value(), QString( "initial" ) );
|
||||
QCOMPARE( vars["c"].value(), QString( "white" ) );
|
||||
QCOMPARE( vars["i"].value(), QString( "9" ) ); // PER_ITEM
|
||||
QCOMPARE( vars["i2"].value(), QString( "102" ) ); // PER_COPY
|
||||
QCOMPARE( vars["f"].value(), QString( "0" ) ); // PER_PAGE
|
||||
QCOMPARE( vars["s"].value(), QString( "initial" ) );
|
||||
QCOMPARE( vars["c"].value(), QString( "white" ) );
|
||||
|
||||
vars.incrementVariablesOnCopy();
|
||||
vars.incrementVariablesOnCopy();
|
||||
|
||||
QCOMPARE( vars["i"].value(), QString( "9" ) ); // PER_ITEM
|
||||
QCOMPARE( vars["i2"].value(), QString( "104" ) ); // PER_COPY
|
||||
QCOMPARE( vars["f"].value(), QString( "0" ) ); // PER_PAGE
|
||||
QCOMPARE( vars["s"].value(), QString( "initial" ) );
|
||||
QCOMPARE( vars["c"].value(), QString( "white" ) );
|
||||
QCOMPARE( vars["i"].value(), QString( "9" ) ); // PER_ITEM
|
||||
QCOMPARE( vars["i2"].value(), QString( "104" ) ); // PER_COPY
|
||||
QCOMPARE( vars["f"].value(), QString( "0" ) ); // PER_PAGE
|
||||
QCOMPARE( vars["s"].value(), QString( "initial" ) );
|
||||
QCOMPARE( vars["c"].value(), QString( "white" ) );
|
||||
|
||||
vars.incrementVariablesOnPage();
|
||||
vars.incrementVariablesOnPage();
|
||||
|
||||
QCOMPARE( vars["i"].value(), QString( "9" ) ); // PER_ITEM
|
||||
QCOMPARE( vars["i2"].value(), QString( "104" ) ); // PER_COPY
|
||||
QCOMPARE( vars["f"].value(), QString( "0.1" ) ); // PER_PAGE
|
||||
QCOMPARE( vars["s"].value(), QString( "initial" ) );
|
||||
QCOMPARE( vars["c"].value(), QString( "white" ) );
|
||||
QCOMPARE( vars["i"].value(), QString( "9" ) ); // PER_ITEM
|
||||
QCOMPARE( vars["i2"].value(), QString( "104" ) ); // PER_COPY
|
||||
QCOMPARE( vars["f"].value(), QString( "0.1" ) ); // PER_PAGE
|
||||
QCOMPARE( vars["s"].value(), QString( "initial" ) );
|
||||
QCOMPARE( vars["c"].value(), QString( "white" ) );
|
||||
|
||||
vars.incrementVariablesOnPage();
|
||||
vars.incrementVariablesOnPage();
|
||||
|
||||
QCOMPARE( vars["i"].value(), QString( "9" ) ); // PER_ITEM
|
||||
QCOMPARE( vars["i2"].value(), QString( "104" ) ); // PER_COPY
|
||||
QCOMPARE( vars["f"].value(), QString( "0.2" ) ); // PER_PAGE
|
||||
QCOMPARE( vars["s"].value(), QString( "initial" ) );
|
||||
QCOMPARE( vars["c"].value(), QString( "white" ) );
|
||||
QCOMPARE( vars["i"].value(), QString( "9" ) ); // PER_ITEM
|
||||
QCOMPARE( vars["i2"].value(), QString( "104" ) ); // PER_COPY
|
||||
QCOMPARE( vars["f"].value(), QString( "0.2" ) ); // PER_PAGE
|
||||
QCOMPARE( vars["s"].value(), QString( "initial" ) );
|
||||
QCOMPARE( vars["c"].value(), QString( "white" ) );
|
||||
|
||||
vars.resetVariables();
|
||||
vars.resetVariables();
|
||||
|
||||
QCOMPARE( vars["i"].value(), QString( "3" ) ); // PER_ITEM
|
||||
QCOMPARE( vars["i2"].value(), QString( "100" ) ); // PRE_COPY
|
||||
QCOMPARE( vars["f"].value(), QString( "0" ) ); // PER_PAGE
|
||||
QCOMPARE( vars["s"].value(), QString( "initial" ) );
|
||||
QCOMPARE( vars["c"].value(), QString( "white" ) );
|
||||
QCOMPARE( vars["i"].value(), QString( "3" ) ); // PER_ITEM
|
||||
QCOMPARE( vars["i2"].value(), QString( "100" ) ); // PRE_COPY
|
||||
QCOMPARE( vars["f"].value(), QString( "0" ) ); // PER_PAGE
|
||||
QCOMPARE( vars["s"].value(), QString( "initial" ) );
|
||||
QCOMPARE( vars["c"].value(), QString( "white" ) );
|
||||
}
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
/* TestVariables.h
|
||||
*
|
||||
* Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
|
||||
class TestVariables : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void variables();
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
// TestVariables.hpp
|
||||
//
|
||||
// Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of gLabels-qt.
|
||||
//
|
||||
// gLabels-qt is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// gLabels-qt is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
|
||||
class TestVariables : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void variables();
|
||||
};
|
||||
+563
-563
File diff suppressed because it is too large
Load Diff
@@ -1,36 +0,0 @@
|
||||
/* TestXmlLabel.h
|
||||
*
|
||||
* Copyright (C) 2018 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
|
||||
class TestXmlLabel : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void initTestCase();
|
||||
void serializeDeserialize();
|
||||
void writeReadFile();
|
||||
void parser_3ReadFile();
|
||||
void parser_3Barcode();
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
// TestXmlLabel.hpp
|
||||
//
|
||||
// Copyright (C) 2018 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of gLabels-qt.
|
||||
//
|
||||
// gLabels-qt is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// gLabels-qt is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
|
||||
class TestXmlLabel : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void initTestCase();
|
||||
void serializeDeserialize();
|
||||
void writeReadFile();
|
||||
void parser_3ReadFile();
|
||||
void parser_3Barcode();
|
||||
};
|
||||
|
||||
|
||||
+208
-207
@@ -1,26 +1,27 @@
|
||||
/* TestXmlUtil.cpp
|
||||
*
|
||||
* Copyright (C) 2018 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// TestXmlUtil.cpp
|
||||
//
|
||||
// Copyright (C) 2018 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of gLabels-qt.
|
||||
//
|
||||
// gLabels-qt is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// gLabels-qt is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#include "TestXmlUtil.h"
|
||||
|
||||
#include "model/XmlUtil.h"
|
||||
#include "TestXmlUtil.hpp"
|
||||
|
||||
#include "model/XmlUtil.hpp"
|
||||
|
||||
|
||||
QTEST_MAIN(TestXmlUtil)
|
||||
@@ -28,271 +29,271 @@ QTEST_MAIN(TestXmlUtil)
|
||||
|
||||
void TestXmlUtil::getStringAttr()
|
||||
{
|
||||
using namespace glabels::model;
|
||||
using namespace glabels::model;
|
||||
|
||||
// Test XML
|
||||
QString xml = "<root a='A test string' />";
|
||||
// Test XML
|
||||
QString xml = "<root a='A test string' />";
|
||||
|
||||
// Setup document and extract root node
|
||||
QDomDocument doc;
|
||||
QCOMPARE( doc.setContent( xml, false ), true );
|
||||
QDomElement node = doc.documentElement();
|
||||
QCOMPARE( node.tagName(), QString("root") );
|
||||
// Setup document and extract root node
|
||||
QDomDocument doc;
|
||||
QCOMPARE( doc.setContent( xml, false ), true );
|
||||
QDomElement node = doc.documentElement();
|
||||
QCOMPARE( node.tagName(), QString("root") );
|
||||
|
||||
//
|
||||
// Tests
|
||||
//
|
||||
QCOMPARE( XmlUtil::getStringAttr( node, "a", "Default" ), QString( "A test string" ) );
|
||||
//
|
||||
// Tests
|
||||
//
|
||||
QCOMPARE( XmlUtil::getStringAttr( node, "a", "Default" ), QString( "A test string" ) );
|
||||
|
||||
// non-existant attribute, use default
|
||||
QCOMPARE( XmlUtil::getStringAttr( node, "b", "Default" ), QString( "Default" ) );
|
||||
// non-existant attribute, use default
|
||||
QCOMPARE( XmlUtil::getStringAttr( node, "b", "Default" ), QString( "Default" ) );
|
||||
}
|
||||
|
||||
|
||||
void TestXmlUtil::getDoubleAttr()
|
||||
{
|
||||
using namespace glabels::model;
|
||||
using namespace glabels::model;
|
||||
|
||||
// Test XML
|
||||
QString xml = "<root a='0' b='0.' c='1' d='1.5' e='-1.5e-1' f='x' />";
|
||||
// Test XML
|
||||
QString xml = "<root a='0' b='0.' c='1' d='1.5' e='-1.5e-1' f='x' />";
|
||||
|
||||
// Setup document and extract root node
|
||||
QDomDocument doc;
|
||||
QCOMPARE( doc.setContent( xml, false ), true );
|
||||
QDomElement node = doc.documentElement();
|
||||
QCOMPARE( node.tagName(), QString("root") );
|
||||
// Setup document and extract root node
|
||||
QDomDocument doc;
|
||||
QCOMPARE( doc.setContent( xml, false ), true );
|
||||
QDomElement node = doc.documentElement();
|
||||
QCOMPARE( node.tagName(), QString("root") );
|
||||
|
||||
//
|
||||
// Tests
|
||||
//
|
||||
QCOMPARE( XmlUtil::getDoubleAttr( node, "a", 3.14 ), 0.0 );
|
||||
QCOMPARE( XmlUtil::getDoubleAttr( node, "b", 3.14 ), 0.0 );
|
||||
QCOMPARE( XmlUtil::getDoubleAttr( node, "c", 3.14 ), 1.0 );
|
||||
QCOMPARE( XmlUtil::getDoubleAttr( node, "d", 3.14 ), 1.5 );
|
||||
QCOMPARE( XmlUtil::getDoubleAttr( node, "e", 3.14 ), -0.15 );
|
||||
//
|
||||
// Tests
|
||||
//
|
||||
QCOMPARE( XmlUtil::getDoubleAttr( node, "a", 3.14 ), 0.0 );
|
||||
QCOMPARE( XmlUtil::getDoubleAttr( node, "b", 3.14 ), 0.0 );
|
||||
QCOMPARE( XmlUtil::getDoubleAttr( node, "c", 3.14 ), 1.0 );
|
||||
QCOMPARE( XmlUtil::getDoubleAttr( node, "d", 3.14 ), 1.5 );
|
||||
QCOMPARE( XmlUtil::getDoubleAttr( node, "e", 3.14 ), -0.15 );
|
||||
|
||||
// bad value, use default
|
||||
QCOMPARE( XmlUtil::getDoubleAttr( node, "f", 3.14 ), 3.14 );
|
||||
// bad value, use default
|
||||
QCOMPARE( XmlUtil::getDoubleAttr( node, "f", 3.14 ), 3.14 );
|
||||
|
||||
// non-existant attribute, use default
|
||||
QCOMPARE( XmlUtil::getDoubleAttr( node, "g", 3.14 ), 3.14 );
|
||||
// non-existant attribute, use default
|
||||
QCOMPARE( XmlUtil::getDoubleAttr( node, "g", 3.14 ), 3.14 );
|
||||
}
|
||||
|
||||
|
||||
void TestXmlUtil::getBoolAttr()
|
||||
{
|
||||
using namespace glabels::model;
|
||||
using namespace glabels::model;
|
||||
|
||||
// Test XML
|
||||
QString xml = "<root a='0' b='1' c='true' d='false' e='x' />";
|
||||
// Test XML
|
||||
QString xml = "<root a='0' b='1' c='true' d='false' e='x' />";
|
||||
|
||||
// Setup document and extract root node
|
||||
QDomDocument doc;
|
||||
QCOMPARE( doc.setContent( xml, false ), true );
|
||||
QDomElement node = doc.documentElement();
|
||||
QCOMPARE( node.tagName(), QString("root") );
|
||||
// Setup document and extract root node
|
||||
QDomDocument doc;
|
||||
QCOMPARE( doc.setContent( xml, false ), true );
|
||||
QDomElement node = doc.documentElement();
|
||||
QCOMPARE( node.tagName(), QString("root") );
|
||||
|
||||
//
|
||||
// Tests
|
||||
//
|
||||
QCOMPARE( XmlUtil::getBoolAttr( node, "a", false ), false );
|
||||
QCOMPARE( XmlUtil::getBoolAttr( node, "a", true ), false );
|
||||
QCOMPARE( XmlUtil::getBoolAttr( node, "b", false ), true );
|
||||
QCOMPARE( XmlUtil::getBoolAttr( node, "b", true ), true );
|
||||
QCOMPARE( XmlUtil::getBoolAttr( node, "c", false ), true );
|
||||
QCOMPARE( XmlUtil::getBoolAttr( node, "c", true ), true );
|
||||
QCOMPARE( XmlUtil::getBoolAttr( node, "d", false ), false );
|
||||
QCOMPARE( XmlUtil::getBoolAttr( node, "d", true ), false );
|
||||
//
|
||||
// Tests
|
||||
//
|
||||
QCOMPARE( XmlUtil::getBoolAttr( node, "a", false ), false );
|
||||
QCOMPARE( XmlUtil::getBoolAttr( node, "a", true ), false );
|
||||
QCOMPARE( XmlUtil::getBoolAttr( node, "b", false ), true );
|
||||
QCOMPARE( XmlUtil::getBoolAttr( node, "b", true ), true );
|
||||
QCOMPARE( XmlUtil::getBoolAttr( node, "c", false ), true );
|
||||
QCOMPARE( XmlUtil::getBoolAttr( node, "c", true ), true );
|
||||
QCOMPARE( XmlUtil::getBoolAttr( node, "d", false ), false );
|
||||
QCOMPARE( XmlUtil::getBoolAttr( node, "d", true ), false );
|
||||
|
||||
// bad value, use default
|
||||
QCOMPARE( XmlUtil::getBoolAttr( node, "e", false ), false );
|
||||
QCOMPARE( XmlUtil::getBoolAttr( node, "e", true ), true );
|
||||
// bad value, use default
|
||||
QCOMPARE( XmlUtil::getBoolAttr( node, "e", false ), false );
|
||||
QCOMPARE( XmlUtil::getBoolAttr( node, "e", true ), true );
|
||||
|
||||
// non-existant attribute, use default
|
||||
QCOMPARE( XmlUtil::getBoolAttr( node, "f", false ), false );
|
||||
QCOMPARE( XmlUtil::getBoolAttr( node, "f", true ), true );
|
||||
// non-existant attribute, use default
|
||||
QCOMPARE( XmlUtil::getBoolAttr( node, "f", false ), false );
|
||||
QCOMPARE( XmlUtil::getBoolAttr( node, "f", true ), true );
|
||||
}
|
||||
|
||||
|
||||
void TestXmlUtil::getIntAttr()
|
||||
{
|
||||
using namespace glabels::model;
|
||||
using namespace glabels::model;
|
||||
|
||||
// Test XML
|
||||
QString xml = "<root a='0' b='1' c='-11' d='1234567890' e='x' />";
|
||||
// Test XML
|
||||
QString xml = "<root a='0' b='1' c='-11' d='1234567890' e='x' />";
|
||||
|
||||
// Setup document and extract root node
|
||||
QDomDocument doc;
|
||||
QCOMPARE( doc.setContent( xml, false ), true );
|
||||
QDomElement node = doc.documentElement();
|
||||
QCOMPARE( node.tagName(), QString("root") );
|
||||
// Setup document and extract root node
|
||||
QDomDocument doc;
|
||||
QCOMPARE( doc.setContent( xml, false ), true );
|
||||
QDomElement node = doc.documentElement();
|
||||
QCOMPARE( node.tagName(), QString("root") );
|
||||
|
||||
//
|
||||
// Tests
|
||||
//
|
||||
QCOMPARE( XmlUtil::getIntAttr( node, "a", 456 ), 0 );
|
||||
QCOMPARE( XmlUtil::getIntAttr( node, "b", 456 ), 1 );
|
||||
QCOMPARE( XmlUtil::getIntAttr( node, "c", 456 ), -11 );
|
||||
QCOMPARE( XmlUtil::getIntAttr( node, "d", 456 ), 1234567890 );
|
||||
//
|
||||
// Tests
|
||||
//
|
||||
QCOMPARE( XmlUtil::getIntAttr( node, "a", 456 ), 0 );
|
||||
QCOMPARE( XmlUtil::getIntAttr( node, "b", 456 ), 1 );
|
||||
QCOMPARE( XmlUtil::getIntAttr( node, "c", 456 ), -11 );
|
||||
QCOMPARE( XmlUtil::getIntAttr( node, "d", 456 ), 1234567890 );
|
||||
|
||||
// bad value, use default
|
||||
QCOMPARE( XmlUtil::getIntAttr( node, "e", 456 ), 456 );
|
||||
// bad value, use default
|
||||
QCOMPARE( XmlUtil::getIntAttr( node, "e", 456 ), 456 );
|
||||
|
||||
// non-existant attribute, use default
|
||||
QCOMPARE( XmlUtil::getIntAttr( node, "f", 456 ), 456 );
|
||||
// non-existant attribute, use default
|
||||
QCOMPARE( XmlUtil::getIntAttr( node, "f", 456 ), 456 );
|
||||
}
|
||||
|
||||
|
||||
void TestXmlUtil::getUIntAttr()
|
||||
{
|
||||
using namespace glabels::model;
|
||||
using namespace glabels::model;
|
||||
|
||||
// Test XML
|
||||
QString xml = "<root a='0' b='1' c='1234567890' d='0xBAADBEEF' e='0xc001000f' f='0xillegal' />";
|
||||
// Test XML
|
||||
QString xml = "<root a='0' b='1' c='1234567890' d='0xBAADBEEF' e='0xc001000f' f='0xillegal' />";
|
||||
|
||||
// Setup document and extract root node
|
||||
QDomDocument doc;
|
||||
QCOMPARE( doc.setContent( xml, false ), true );
|
||||
QDomElement node = doc.documentElement();
|
||||
QCOMPARE( node.tagName(), QString("root") );
|
||||
// Setup document and extract root node
|
||||
QDomDocument doc;
|
||||
QCOMPARE( doc.setContent( xml, false ), true );
|
||||
QDomElement node = doc.documentElement();
|
||||
QCOMPARE( node.tagName(), QString("root") );
|
||||
|
||||
//
|
||||
// Tests
|
||||
//
|
||||
QCOMPARE( XmlUtil::getUIntAttr( node, "a", 0xdefa17 ), 0u );
|
||||
QCOMPARE( XmlUtil::getUIntAttr( node, "b", 0xdefa17 ), 1u );
|
||||
QCOMPARE( XmlUtil::getUIntAttr( node, "c", 0xdefa17 ), 1234567890u );
|
||||
QCOMPARE( XmlUtil::getUIntAttr( node, "d", 0xdefa17 ), 0xbaadbeef );
|
||||
QCOMPARE( XmlUtil::getUIntAttr( node, "e", 0xdefa17 ), 0xc001000f );
|
||||
//
|
||||
// Tests
|
||||
//
|
||||
QCOMPARE( XmlUtil::getUIntAttr( node, "a", 0xdefa17 ), 0u );
|
||||
QCOMPARE( XmlUtil::getUIntAttr( node, "b", 0xdefa17 ), 1u );
|
||||
QCOMPARE( XmlUtil::getUIntAttr( node, "c", 0xdefa17 ), 1234567890u );
|
||||
QCOMPARE( XmlUtil::getUIntAttr( node, "d", 0xdefa17 ), 0xbaadbeef );
|
||||
QCOMPARE( XmlUtil::getUIntAttr( node, "e", 0xdefa17 ), 0xc001000f );
|
||||
|
||||
// bad value, use default
|
||||
QCOMPARE( XmlUtil::getUIntAttr( node, "f", 0xdefa17 ), 0xdefa17u );
|
||||
// bad value, use default
|
||||
QCOMPARE( XmlUtil::getUIntAttr( node, "f", 0xdefa17 ), 0xdefa17u );
|
||||
|
||||
// non-existant attribute, use default
|
||||
QCOMPARE( XmlUtil::getUIntAttr( node, "g", 0xdefa17 ), 0xdefa17u );
|
||||
// non-existant attribute, use default
|
||||
QCOMPARE( XmlUtil::getUIntAttr( node, "g", 0xdefa17 ), 0xdefa17u );
|
||||
}
|
||||
|
||||
|
||||
void TestXmlUtil::getLengthAttr()
|
||||
{
|
||||
using namespace glabels::model;
|
||||
using namespace glabels::model;
|
||||
|
||||
// Test XML
|
||||
QString xml = "<root a='0' b='-1' c='10in' d='1.5mm' e='-1.5e-1cm' f='3pt' g='1.2bad' h='x' />";
|
||||
// Test XML
|
||||
QString xml = "<root a='0' b='-1' c='10in' d='1.5mm' e='-1.5e-1cm' f='3pt' g='1.2bad' h='x' />";
|
||||
|
||||
// Setup document and extract root node
|
||||
QDomDocument doc;
|
||||
QCOMPARE( doc.setContent( xml, false ), true );
|
||||
QDomElement node = doc.documentElement();
|
||||
QCOMPARE( node.tagName(), QString("root") );
|
||||
// Setup document and extract root node
|
||||
QDomDocument doc;
|
||||
QCOMPARE( doc.setContent( xml, false ), true );
|
||||
QDomElement node = doc.documentElement();
|
||||
QCOMPARE( node.tagName(), QString("root") );
|
||||
|
||||
//
|
||||
// Tests
|
||||
//
|
||||
QCOMPARE( XmlUtil::getLengthAttr( node, "a", Distance::pt(1234) ), Distance::pt(0.0) );
|
||||
QCOMPARE( XmlUtil::getLengthAttr( node, "b", Distance::pt(1234) ), Distance::pt(-1.0) );
|
||||
QCOMPARE( XmlUtil::getLengthAttr( node, "c", Distance::pt(1234) ), Distance::pt(720) );
|
||||
QCOMPARE( XmlUtil::getLengthAttr( node, "d", Distance::pt(1234) ), Distance::mm(1.5) );
|
||||
QCOMPARE( XmlUtil::getLengthAttr( node, "e", Distance::pt(1234) ), Distance::cm(-0.15) );
|
||||
QCOMPARE( XmlUtil::getLengthAttr( node, "f", Distance::pt(1234) ), Distance::pt(3) );
|
||||
//
|
||||
// Tests
|
||||
//
|
||||
QCOMPARE( XmlUtil::getLengthAttr( node, "a", Distance::pt(1234) ), Distance::pt(0.0) );
|
||||
QCOMPARE( XmlUtil::getLengthAttr( node, "b", Distance::pt(1234) ), Distance::pt(-1.0) );
|
||||
QCOMPARE( XmlUtil::getLengthAttr( node, "c", Distance::pt(1234) ), Distance::pt(720) );
|
||||
QCOMPARE( XmlUtil::getLengthAttr( node, "d", Distance::pt(1234) ), Distance::mm(1.5) );
|
||||
QCOMPARE( XmlUtil::getLengthAttr( node, "e", Distance::pt(1234) ), Distance::cm(-0.15) );
|
||||
QCOMPARE( XmlUtil::getLengthAttr( node, "f", Distance::pt(1234) ), Distance::pt(3) );
|
||||
|
||||
// bad value, use default
|
||||
QCOMPARE( XmlUtil::getLengthAttr( node, "g", Distance::pt(1234) ), Distance::pt(1234) );
|
||||
QCOMPARE( XmlUtil::getLengthAttr( node, "h", Distance::pt(1234) ), Distance::pt(1234) );
|
||||
// bad value, use default
|
||||
QCOMPARE( XmlUtil::getLengthAttr( node, "g", Distance::pt(1234) ), Distance::pt(1234) );
|
||||
QCOMPARE( XmlUtil::getLengthAttr( node, "h", Distance::pt(1234) ), Distance::pt(1234) );
|
||||
|
||||
// non-existant attribute, use default
|
||||
QCOMPARE( XmlUtil::getLengthAttr( node, "i", Distance::pt(1234) ), Distance::pt(1234) );
|
||||
// non-existant attribute, use default
|
||||
QCOMPARE( XmlUtil::getLengthAttr( node, "i", Distance::pt(1234) ), Distance::pt(1234) );
|
||||
}
|
||||
|
||||
|
||||
void TestXmlUtil::getWeightAttr()
|
||||
{
|
||||
using namespace glabels::model;
|
||||
using namespace glabels::model;
|
||||
|
||||
// Test XML
|
||||
QString xml = "<root a='bold' b='normal' c='xxxx' />";
|
||||
// Test XML
|
||||
QString xml = "<root a='bold' b='normal' c='xxxx' />";
|
||||
|
||||
// Setup document and extract root node
|
||||
QDomDocument doc;
|
||||
QCOMPARE( doc.setContent( xml, false ), true );
|
||||
QDomElement node = doc.documentElement();
|
||||
QCOMPARE( node.tagName(), QString("root") );
|
||||
// Setup document and extract root node
|
||||
QDomDocument doc;
|
||||
QCOMPARE( doc.setContent( xml, false ), true );
|
||||
QDomElement node = doc.documentElement();
|
||||
QCOMPARE( node.tagName(), QString("root") );
|
||||
|
||||
//
|
||||
// Tests
|
||||
//
|
||||
QCOMPARE( XmlUtil::getWeightAttr( node, "a", QFont::Normal ), QFont::Bold );
|
||||
QCOMPARE( XmlUtil::getWeightAttr( node, "a", QFont::Bold ), QFont::Bold );
|
||||
QCOMPARE( XmlUtil::getWeightAttr( node, "b", QFont::Normal ), QFont::Normal );
|
||||
QCOMPARE( XmlUtil::getWeightAttr( node, "b", QFont::Bold ), QFont::Normal );
|
||||
|
||||
// bad value, use default
|
||||
QCOMPARE( XmlUtil::getWeightAttr( node, "c", QFont::Normal ), QFont::Normal );
|
||||
QCOMPARE( XmlUtil::getWeightAttr( node, "c", QFont::Bold ), QFont::Bold );
|
||||
//
|
||||
// Tests
|
||||
//
|
||||
QCOMPARE( XmlUtil::getWeightAttr( node, "a", QFont::Normal ), QFont::Bold );
|
||||
QCOMPARE( XmlUtil::getWeightAttr( node, "a", QFont::Bold ), QFont::Bold );
|
||||
QCOMPARE( XmlUtil::getWeightAttr( node, "b", QFont::Normal ), QFont::Normal );
|
||||
QCOMPARE( XmlUtil::getWeightAttr( node, "b", QFont::Bold ), QFont::Normal );
|
||||
|
||||
// non-existant attribute, use default
|
||||
QCOMPARE( XmlUtil::getWeightAttr( node, "d", QFont::Normal ), QFont::Normal );
|
||||
QCOMPARE( XmlUtil::getWeightAttr( node, "d", QFont::Bold ), QFont::Bold );
|
||||
// bad value, use default
|
||||
QCOMPARE( XmlUtil::getWeightAttr( node, "c", QFont::Normal ), QFont::Normal );
|
||||
QCOMPARE( XmlUtil::getWeightAttr( node, "c", QFont::Bold ), QFont::Bold );
|
||||
|
||||
// non-existant attribute, use default
|
||||
QCOMPARE( XmlUtil::getWeightAttr( node, "d", QFont::Normal ), QFont::Normal );
|
||||
QCOMPARE( XmlUtil::getWeightAttr( node, "d", QFont::Bold ), QFont::Bold );
|
||||
}
|
||||
|
||||
|
||||
void TestXmlUtil::getAlignmentAttr()
|
||||
{
|
||||
using namespace glabels::model;
|
||||
using namespace glabels::model;
|
||||
|
||||
// Test XML
|
||||
QString xml = "<root a='left' b='hcenter' c='right' d='bottom' e='vcenter' f='top' g='yyyy' />";
|
||||
// Test XML
|
||||
QString xml = "<root a='left' b='hcenter' c='right' d='bottom' e='vcenter' f='top' g='yyyy' />";
|
||||
|
||||
// Setup document and extract root node
|
||||
QDomDocument doc;
|
||||
QCOMPARE( doc.setContent( xml, false ), true );
|
||||
QDomElement node = doc.documentElement();
|
||||
QCOMPARE( node.tagName(), QString("root") );
|
||||
// Setup document and extract root node
|
||||
QDomDocument doc;
|
||||
QCOMPARE( doc.setContent( xml, false ), true );
|
||||
QDomElement node = doc.documentElement();
|
||||
QCOMPARE( node.tagName(), QString("root") );
|
||||
|
||||
//
|
||||
// Tests
|
||||
//
|
||||
QCOMPARE( XmlUtil::getAlignmentAttr( node, "a", Qt::AlignRight ), Qt::AlignLeft );
|
||||
QCOMPARE( XmlUtil::getAlignmentAttr( node, "b", Qt::AlignRight ), Qt::AlignHCenter );
|
||||
QCOMPARE( XmlUtil::getAlignmentAttr( node, "c", Qt::AlignLeft ), Qt::AlignRight );
|
||||
QCOMPARE( XmlUtil::getAlignmentAttr( node, "d", Qt::AlignTop ), Qt::AlignBottom );
|
||||
QCOMPARE( XmlUtil::getAlignmentAttr( node, "e", Qt::AlignTop ), Qt::AlignVCenter );
|
||||
QCOMPARE( XmlUtil::getAlignmentAttr( node, "f", Qt::AlignBottom ), Qt::AlignTop );
|
||||
|
||||
// bad value, use default
|
||||
QCOMPARE( XmlUtil::getAlignmentAttr( node, "g", Qt::AlignTop ), Qt::AlignTop );
|
||||
QCOMPARE( XmlUtil::getAlignmentAttr( node, "g", Qt::AlignLeft ), Qt::AlignLeft );
|
||||
//
|
||||
// Tests
|
||||
//
|
||||
QCOMPARE( XmlUtil::getAlignmentAttr( node, "a", Qt::AlignRight ), Qt::AlignLeft );
|
||||
QCOMPARE( XmlUtil::getAlignmentAttr( node, "b", Qt::AlignRight ), Qt::AlignHCenter );
|
||||
QCOMPARE( XmlUtil::getAlignmentAttr( node, "c", Qt::AlignLeft ), Qt::AlignRight );
|
||||
QCOMPARE( XmlUtil::getAlignmentAttr( node, "d", Qt::AlignTop ), Qt::AlignBottom );
|
||||
QCOMPARE( XmlUtil::getAlignmentAttr( node, "e", Qt::AlignTop ), Qt::AlignVCenter );
|
||||
QCOMPARE( XmlUtil::getAlignmentAttr( node, "f", Qt::AlignBottom ), Qt::AlignTop );
|
||||
|
||||
// non-existant attribute, use default
|
||||
QCOMPARE( XmlUtil::getAlignmentAttr( node, "h", Qt::AlignBottom ), Qt::AlignBottom );
|
||||
// bad value, use default
|
||||
QCOMPARE( XmlUtil::getAlignmentAttr( node, "g", Qt::AlignTop ), Qt::AlignTop );
|
||||
QCOMPARE( XmlUtil::getAlignmentAttr( node, "g", Qt::AlignLeft ), Qt::AlignLeft );
|
||||
|
||||
// non-existant attribute, use default
|
||||
QCOMPARE( XmlUtil::getAlignmentAttr( node, "h", Qt::AlignBottom ), Qt::AlignBottom );
|
||||
}
|
||||
|
||||
|
||||
void TestXmlUtil::getWrapModeAttr()
|
||||
{
|
||||
using namespace glabels::model;
|
||||
using namespace glabels::model;
|
||||
|
||||
// Test XML
|
||||
QString xml = "<root a='word' b='anywhere' c='none' d='zzzz' />";
|
||||
// Test XML
|
||||
QString xml = "<root a='word' b='anywhere' c='none' d='zzzz' />";
|
||||
|
||||
// Setup document and extract root node
|
||||
QDomDocument doc;
|
||||
QCOMPARE( doc.setContent( xml, false ), true );
|
||||
QDomElement node = doc.documentElement();
|
||||
QCOMPARE( node.tagName(), QString("root") );
|
||||
// Setup document and extract root node
|
||||
QDomDocument doc;
|
||||
QCOMPARE( doc.setContent( xml, false ), true );
|
||||
QDomElement node = doc.documentElement();
|
||||
QCOMPARE( node.tagName(), QString("root") );
|
||||
|
||||
//
|
||||
// Tests
|
||||
//
|
||||
QCOMPARE( XmlUtil::getWrapModeAttr( node, "a", QTextOption::NoWrap ), QTextOption::WordWrap );
|
||||
QCOMPARE( XmlUtil::getWrapModeAttr( node, "b", QTextOption::NoWrap ), QTextOption::WrapAnywhere );
|
||||
QCOMPARE( XmlUtil::getWrapModeAttr( node, "c", QTextOption::WordWrap ), QTextOption::NoWrap );
|
||||
|
||||
// bad value, use default
|
||||
QCOMPARE( XmlUtil::getWrapModeAttr( node, "d", QTextOption::NoWrap ), QTextOption::NoWrap );
|
||||
QCOMPARE( XmlUtil::getWrapModeAttr( node, "d", QTextOption::WordWrap ), QTextOption::WordWrap );
|
||||
//
|
||||
// Tests
|
||||
//
|
||||
QCOMPARE( XmlUtil::getWrapModeAttr( node, "a", QTextOption::NoWrap ), QTextOption::WordWrap );
|
||||
QCOMPARE( XmlUtil::getWrapModeAttr( node, "b", QTextOption::NoWrap ), QTextOption::WrapAnywhere );
|
||||
QCOMPARE( XmlUtil::getWrapModeAttr( node, "c", QTextOption::WordWrap ), QTextOption::NoWrap );
|
||||
|
||||
// non-existant attribute, use default
|
||||
QCOMPARE( XmlUtil::getWrapModeAttr( node, "e", QTextOption::NoWrap ), QTextOption::NoWrap );
|
||||
QCOMPARE( XmlUtil::getWrapModeAttr( node, "e", QTextOption::WrapAnywhere ), QTextOption::WrapAnywhere );
|
||||
// bad value, use default
|
||||
QCOMPARE( XmlUtil::getWrapModeAttr( node, "d", QTextOption::NoWrap ), QTextOption::NoWrap );
|
||||
QCOMPARE( XmlUtil::getWrapModeAttr( node, "d", QTextOption::WordWrap ), QTextOption::WordWrap );
|
||||
|
||||
// non-existant attribute, use default
|
||||
QCOMPARE( XmlUtil::getWrapModeAttr( node, "e", QTextOption::NoWrap ), QTextOption::NoWrap );
|
||||
QCOMPARE( XmlUtil::getWrapModeAttr( node, "e", QTextOption::WrapAnywhere ), QTextOption::WrapAnywhere );
|
||||
}
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
/* TestXmlUtil.h
|
||||
*
|
||||
* Copyright (C) 2018 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
|
||||
class TestXmlUtil : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void getStringAttr();
|
||||
void getDoubleAttr();
|
||||
void getBoolAttr();
|
||||
void getIntAttr();
|
||||
void getUIntAttr();
|
||||
void getLengthAttr();
|
||||
void getWeightAttr();
|
||||
void getAlignmentAttr();
|
||||
void getWrapModeAttr();
|
||||
|
||||
// TODO: test setters
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
// TestXmlUtil.hpp
|
||||
//
|
||||
// Copyright (C) 2018 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of gLabels-qt.
|
||||
//
|
||||
// gLabels-qt is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// gLabels-qt is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
|
||||
class TestXmlUtil : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void getStringAttr();
|
||||
void getDoubleAttr();
|
||||
void getBoolAttr();
|
||||
void getIntAttr();
|
||||
void getUIntAttr();
|
||||
void getLengthAttr();
|
||||
void getWeightAttr();
|
||||
void getAlignmentAttr();
|
||||
void getWrapModeAttr();
|
||||
|
||||
// TODO: test setters
|
||||
};
|
||||
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
/* Test_Constants.h
|
||||
*
|
||||
* Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef test_Constants_h
|
||||
#define test_Constants_h
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace test
|
||||
{
|
||||
|
||||
const char* blue_8x8_png = "iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAABhGlDQ1BJQ0MgcHJvZmlsZQAAKJF9kT1Iw1AUhU9TpVIqDhYRcchQnSyIijhqFYpQIdQKrTqYvPQPmjQkKS6OgmvBwZ/FqoOLs64OroIg+APi4uqk6CIl3pcUWsR44fE+zrvn8N59gNCoMM3qGgc03TbTyYSYza2KoVeEEMYAAhBkZhlzkpSCb33dUx/VXZxn+ff9Wb1q3mJAQCSeZYZpE28QT2/aBud94igrySrxOfGYSRckfuS64vEb56LLAs+Mmpn0PHGUWCx2sNLBrGRqxFPEMVXTKV/Ieqxy3uKsVWqsdU/+wkheX1nmOq1hJLGIJUgQoaCGMiqwEaddJ8VCms4TPv4h1y+RSyFXGYwcC6hCg+z6wf/g92ytwuSElxRJAN0vjvMxAoR2gWbdcb6PHad5AgSfgSu97a82gJlP0uttLXYE9G0DF9dtTdkDLneAwSdDNmVXCtISCgXg/Yy+KQf03wLhNW9urXOcPgAZmlXqBjg4BEaLlL3u8+6ezrn929Oa3w/Q2XJm1/XlIwAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAAuIwAALiMBeKU/dgAAAAd0SU1FB+MHChYzAoNXJCYAAAAWSURBVBjTY2Rg+P+fAQ9gYiAAhocCABBdAg7zMxsKAAAAAElFTkSuQmCC";
|
||||
const char* green_8x8_png = "iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAABhGlDQ1BJQ0MgcHJvZmlsZQAAKJF9kTtIw1AUhv+mikUqDlYQcchQnSz4Qhy1CkWoEGqFVh1MbvqCJg1Jiouj4Fpw8LFYdXBx1tXBVRAEHyAurk6KLlLiuUmhRYwXDvfjv/f/OfdcQKiXmWZ1jAGabpupRFzMZFfFrleE0E81jpDMLGNOkpLwXV/3CPD9Lsaz/O/9uXrUnMWAgEg8ywzTJt4gnt60Dc77xBFWlFXic+JRkxokfuS64vEb54LLAs+MmOnUPHGEWCy0sdLGrGhqxFPEUVXTKV/IeKxy3uKslaus2Sd/YTinryxznWoICSxiCRJEKKiihDJsxGjXSbGQovO4j3/Q9UvkUshVAiPHAirQILt+8D/4PVsrPznhJYXjQOeL43wMA127QKPmON/HjtM4AYLPwJXe8lfqwMwn6bWWFj0CereBi+uWpuwBlzvAwJMhm7IrBamEfB54P6NvygJ9t0D3mje35jlOH4A0zSp5AxwcAiMFyl73eXeofW7/3mnO7wdSvnKatbS90wAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAAOxAAADsQBlSsOGwAAAAd0SU1FB+MIFQovFXnldrAAAAAWSURBVBjTY2T4z/CfAQ9gYiAAhocCABFcAg5KXrI7AAAAAElFTkSuQmCC";
|
||||
const char* yellow_8x8_png = "iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAABhGlDQ1BJQ0MgcHJvZmlsZQAAKJF9kT1Iw0AcxV9TpUUqIhYs4pChOlkQFXHUKhShQqgVWnUwufQLmjQkLS6OgmvBwY/FqoOLs64OroIg+AHi4uqk6CIl/i8ptIjx4Lgf7+497t4BQqPMNKtrHND0qplKxMVMdlUMvCKIQfjRj4jMLGNOkpLwHF/38PH1LsazvM/9OXrVnMUAn0g8ywyzSrxBPL1ZNTjvE4dZUVaJz4nHTLog8SPXFZffOBccFnhm2Eyn5onDxGKhg5UOZkVTI54ijqqaTvlCxmWV8xZnrVxjrXvyF4Zy+soy12kOI4FFLEGCCAU1lFBGFTFadVIspGg/7uEfcvwSuRRylcDIsYAKNMiOH/wPfndr5Scn3KRQHOh+se2PESCwCzTrtv19bNvNE8D/DFzpbX+lAcx8kl5va9EjoG8buLhua8oecLkDRJ4M2ZQdyU9TyOeB9zP6piwwcAv0rLm9tfZx+gCkqavkDXBwCIwWKHvd493Bzt7+PdPq7wcjL3KHuPu4MgAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAAOxAAADsQBlSsOGwAAAAd0SU1FB+MIFwMyBT7m+cwAAAAWSURBVBjTY/z/n+E/Ax7AxEAADA8FABdkAw08uCaCAAAAAElFTkSuQmCC";
|
||||
const char* red_8x8_svg = "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"8\" height=\"8\" ><rect x=\"0\" y=\"0\" height=\"8\" width=\"8\" style=\"fill:#FF0000;\" /></svg>";
|
||||
const char* cyan_8x8_svg = "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"8\" height=\"8\" ><rect x=\"0\" y=\"0\" height=\"8\" width=\"8\" style=\"fill:#00FFFF;\" /></svg>";
|
||||
const char* magenta_8x8_svg = "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"8\" height=\"8\" ><rect x=\"0\" y=\"0\" height=\"8\" width=\"8\" style=\"fill:#FF00FF;\" /></svg>";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // test_Constants_h
|
||||
@@ -0,0 +1,38 @@
|
||||
// Test_Constants.hpp
|
||||
//
|
||||
// Copyright (C) 2019 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of gLabels-qt.
|
||||
//
|
||||
// gLabels-qt is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// gLabels-qt is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#ifndef test_Constants_hpp
|
||||
#define test_Constants_hpp
|
||||
|
||||
|
||||
namespace glabels::test
|
||||
{
|
||||
|
||||
const char* blue_8x8_png = "iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAABhGlDQ1BJQ0MgcHJvZmlsZQAAKJF9kT1Iw1AUhU9TpVIqDhYRcchQnSyIijhqFYpQIdQKrTqYvPQPmjQkKS6OgmvBwZ/FqoOLs64OroIg+APi4uqk6CIl3pcUWsR44fE+zrvn8N59gNCoMM3qGgc03TbTyYSYza2KoVeEEMYAAhBkZhlzkpSCb33dUx/VXZxn+ff9Wb1q3mJAQCSeZYZpE28QT2/aBud94igrySrxOfGYSRckfuS64vEb56LLAs+Mmpn0PHGUWCx2sNLBrGRqxFPEMVXTKV/Ieqxy3uKsVWqsdU/+wkheX1nmOq1hJLGIJUgQoaCGMiqwEaddJ8VCms4TPv4h1y+RSyFXGYwcC6hCg+z6wf/g92ytwuSElxRJAN0vjvMxAoR2gWbdcb6PHad5AgSfgSu97a82gJlP0uttLXYE9G0DF9dtTdkDLneAwSdDNmVXCtISCgXg/Yy+KQf03wLhNW9urXOcPgAZmlXqBjg4BEaLlL3u8+6ezrn929Oa3w/Q2XJm1/XlIwAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAAuIwAALiMBeKU/dgAAAAd0SU1FB+MHChYzAoNXJCYAAAAWSURBVBjTY2Rg+P+fAQ9gYiAAhocCABBdAg7zMxsKAAAAAElFTkSuQmCC";
|
||||
const char* green_8x8_png = "iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAABhGlDQ1BJQ0MgcHJvZmlsZQAAKJF9kTtIw1AUhv+mikUqDlYQcchQnSz4Qhy1CkWoEGqFVh1MbvqCJg1Jiouj4Fpw8LFYdXBx1tXBVRAEHyAurk6KLlLiuUmhRYwXDvfjv/f/OfdcQKiXmWZ1jAGabpupRFzMZFfFrleE0E81jpDMLGNOkpLwXV/3CPD9Lsaz/O/9uXrUnMWAgEg8ywzTJt4gnt60Dc77xBFWlFXic+JRkxokfuS64vEb54LLAs+MmOnUPHGEWCy0sdLGrGhqxFPEUVXTKV/IeKxy3uKslaus2Sd/YTinryxznWoICSxiCRJEKKiihDJsxGjXSbGQovO4j3/Q9UvkUshVAiPHAirQILt+8D/4PVsrPznhJYXjQOeL43wMA127QKPmON/HjtM4AYLPwJXe8lfqwMwn6bWWFj0CereBi+uWpuwBlzvAwJMhm7IrBamEfB54P6NvygJ9t0D3mje35jlOH4A0zSp5AxwcAiMFyl73eXeofW7/3mnO7wdSvnKatbS90wAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAAOxAAADsQBlSsOGwAAAAd0SU1FB+MIFQovFXnldrAAAAAWSURBVBjTY2T4z/CfAQ9gYiAAhocCABFcAg5KXrI7AAAAAElFTkSuQmCC";
|
||||
const char* yellow_8x8_png = "iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAABhGlDQ1BJQ0MgcHJvZmlsZQAAKJF9kT1Iw0AcxV9TpUUqIhYs4pChOlkQFXHUKhShQqgVWnUwufQLmjQkLS6OgmvBwY/FqoOLs64OroIg+AHi4uqk6CIl/i8ptIjx4Lgf7+497t4BQqPMNKtrHND0qplKxMVMdlUMvCKIQfjRj4jMLGNOkpLwHF/38PH1LsazvM/9OXrVnMUAn0g8ywyzSrxBPL1ZNTjvE4dZUVaJz4nHTLog8SPXFZffOBccFnhm2Eyn5onDxGKhg5UOZkVTI54ijqqaTvlCxmWV8xZnrVxjrXvyF4Zy+soy12kOI4FFLEGCCAU1lFBGFTFadVIspGg/7uEfcvwSuRRylcDIsYAKNMiOH/wPfndr5Scn3KRQHOh+se2PESCwCzTrtv19bNvNE8D/DFzpbX+lAcx8kl5va9EjoG8buLhua8oecLkDRJ4M2ZQdyU9TyOeB9zP6piwwcAv0rLm9tfZx+gCkqavkDXBwCIwWKHvd493Bzt7+PdPq7wcjL3KHuPu4MgAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAAOxAAADsQBlSsOGwAAAAd0SU1FB+MIFwMyBT7m+cwAAAAWSURBVBjTY/z/n+E/Ax7AxEAADA8FABdkAw08uCaCAAAAAElFTkSuQmCC";
|
||||
const char* red_8x8_svg = "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"8\" height=\"8\" ><rect x=\"0\" y=\"0\" height=\"8\" width=\"8\" style=\"fill:#FF0000;\" /></svg>";
|
||||
const char* cyan_8x8_svg = "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"8\" height=\"8\" ><rect x=\"0\" y=\"0\" height=\"8\" width=\"8\" style=\"fill:#00FFFF;\" /></svg>";
|
||||
const char* magenta_8x8_svg = "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"8\" height=\"8\" ><rect x=\"0\" y=\"0\" height=\"8\" width=\"8\" style=\"fill:#FF00FF;\" /></svg>";
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // test_Constants_hpp
|
||||
Reference in New Issue
Block a user