Implemented variable substitution in simple print jobs.
This commit is contained in:
@@ -139,6 +139,8 @@ void TestSubstitutionField::simpleEvaluation()
|
||||
{
|
||||
using namespace glabels;
|
||||
|
||||
model::Variables variables;
|
||||
|
||||
model::SubstitutionField f1( "${1}" );
|
||||
model::SubstitutionField f2( "${2}" );
|
||||
model::SubstitutionField f3( "${3}" );
|
||||
@@ -150,10 +152,10 @@ void TestSubstitutionField::simpleEvaluation()
|
||||
record1[ "3" ] = "Opqrstu";
|
||||
record1[ "4" ] = "Vwxyz!@";
|
||||
|
||||
QCOMPARE( f1.evaluate( &record1 ), QString( "Abcdefg" ) );
|
||||
QCOMPARE( f2.evaluate( &record1 ), QString( "Hijklmn" ) );
|
||||
QCOMPARE( f3.evaluate( &record1 ), QString( "Opqrstu" ) );
|
||||
QCOMPARE( f4.evaluate( &record1 ), QString( "Vwxyz!@" ) );
|
||||
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 record2;
|
||||
record2[ "1" ] = "1234567";
|
||||
@@ -161,10 +163,10 @@ void TestSubstitutionField::simpleEvaluation()
|
||||
record2[ "3" ] = "8901234";
|
||||
record2[ "4" ] = "#$%^&*";
|
||||
|
||||
QCOMPARE( f1.evaluate( &record2 ), QString( "1234567" ) );
|
||||
QCOMPARE( f2.evaluate( &record2 ), QString( "FooBar" ) );
|
||||
QCOMPARE( f3.evaluate( &record2 ), QString( "8901234" ) );
|
||||
QCOMPARE( f4.evaluate( &record2 ), QString( "#$%^&*" ) );
|
||||
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( "#$%^&*" ) );
|
||||
}
|
||||
|
||||
|
||||
@@ -172,6 +174,8 @@ void TestSubstitutionField::defaultValueEvaluation()
|
||||
{
|
||||
using namespace glabels;
|
||||
|
||||
model::Variables variables;
|
||||
|
||||
model::SubstitutionField f1( "${1:=foo1}" );
|
||||
model::SubstitutionField f2( "${2:=foo2}" );
|
||||
model::SubstitutionField f3( "${3:=foo3}" );
|
||||
@@ -183,17 +187,17 @@ void TestSubstitutionField::defaultValueEvaluation()
|
||||
record1[ "3" ] = "Opqrstu";
|
||||
record1[ "4" ] = "Vwxyz!@";
|
||||
|
||||
QCOMPARE( f1.evaluate( &record1 ), QString( "Abcdefg" ) );
|
||||
QCOMPARE( f2.evaluate( &record1 ), QString( "Hijklmn" ) );
|
||||
QCOMPARE( f3.evaluate( &record1 ), QString( "Opqrstu" ) );
|
||||
QCOMPARE( f4.evaluate( &record1 ), QString( "Vwxyz!@" ) );
|
||||
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 record2; // All fields empty
|
||||
|
||||
QCOMPARE( f1.evaluate( &record2 ), QString( "foo1" ) );
|
||||
QCOMPARE( f2.evaluate( &record2 ), QString( "foo2" ) );
|
||||
QCOMPARE( f3.evaluate( &record2 ), QString( "foo3" ) );
|
||||
QCOMPARE( f4.evaluate( &record2 ), QString( "foo4" ) );
|
||||
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";
|
||||
@@ -201,10 +205,10 @@ void TestSubstitutionField::defaultValueEvaluation()
|
||||
// Field "3" empty
|
||||
record3[ "4" ] = "plugh";
|
||||
|
||||
QCOMPARE( f1.evaluate( &record3 ), QString( "xyzzy" ) );
|
||||
QCOMPARE( f2.evaluate( &record3 ), QString( "foo2" ) );
|
||||
QCOMPARE( f3.evaluate( &record3 ), QString( "foo3" ) );
|
||||
QCOMPARE( f4.evaluate( &record3 ), QString( "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" ) );
|
||||
}
|
||||
|
||||
|
||||
@@ -212,6 +216,8 @@ void TestSubstitutionField::formattedStringEvaluation()
|
||||
{
|
||||
using namespace glabels;
|
||||
|
||||
model::Variables variables;
|
||||
|
||||
model::SubstitutionField f1( "${1:%10s}" );
|
||||
model::SubstitutionField f2( "${2:%10s}" );
|
||||
model::SubstitutionField f3( "${3:%10s}" );
|
||||
@@ -233,15 +239,15 @@ void TestSubstitutionField::formattedStringEvaluation()
|
||||
record1[ "7" ] = "-100";
|
||||
record1[ "8" ] = "3.14";
|
||||
|
||||
QCOMPARE( f1.evaluate( &record1 ), QString( " 0" ) );
|
||||
QCOMPARE( f2.evaluate( &record1 ), QString( " 1" ) );
|
||||
QCOMPARE( f3.evaluate( &record1 ), QString( " -1" ) );
|
||||
QCOMPARE( f4.evaluate( &record1 ), QString( " 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 ), QString( "0 " ) );
|
||||
QCOMPARE( f6.evaluate( &record1 ), QString( "100 " ) );
|
||||
QCOMPARE( f7.evaluate( &record1 ), QString( "-100 " ) );
|
||||
QCOMPARE( f8.evaluate( &record1 ), 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 " ) );
|
||||
}
|
||||
|
||||
|
||||
@@ -249,6 +255,8 @@ void TestSubstitutionField::formattedFloatEvaluation()
|
||||
{
|
||||
using namespace glabels;
|
||||
|
||||
model::Variables variables;
|
||||
|
||||
model::SubstitutionField f1( "${1:%+5.2f}" );
|
||||
model::SubstitutionField f2( "${2:%+5.2f}" );
|
||||
model::SubstitutionField f3( "${3:%+5.2f}" );
|
||||
@@ -270,15 +278,15 @@ void TestSubstitutionField::formattedFloatEvaluation()
|
||||
record1[ "7" ] = "-100";
|
||||
record1[ "8" ] = "3.14";
|
||||
|
||||
QCOMPARE( f1.evaluate( &record1 ), QString( "+0.00" ) );
|
||||
QCOMPARE( f2.evaluate( &record1 ), QString( "+1.00" ) );
|
||||
QCOMPARE( f3.evaluate( &record1 ), QString( "-1.00" ) );
|
||||
QCOMPARE( f4.evaluate( &record1 ), QString( "+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 ), QString( "+0.00e+00" ) );
|
||||
QCOMPARE( f6.evaluate( &record1 ), QString( "+1.00e+02" ) );
|
||||
QCOMPARE( f7.evaluate( &record1 ), QString( "-1.00e+02" ) );
|
||||
QCOMPARE( f8.evaluate( &record1 ), QString( "+3.14e+00" ) );
|
||||
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" ) );
|
||||
}
|
||||
|
||||
|
||||
@@ -286,6 +294,8 @@ void TestSubstitutionField::formattedIntEvaluation()
|
||||
{
|
||||
using namespace glabels;
|
||||
|
||||
model::Variables variables;
|
||||
|
||||
model::SubstitutionField f1( "${1:%08d}" );
|
||||
model::SubstitutionField f2( "${2:%08d}" );
|
||||
model::SubstitutionField f3( "${3:%08d}" );
|
||||
@@ -307,15 +317,15 @@ void TestSubstitutionField::formattedIntEvaluation()
|
||||
record1[ "7" ] = "-1";
|
||||
record1[ "8" ] = "314";
|
||||
|
||||
QCOMPARE( f1.evaluate( &record1 ), QString( "00000000" ) );
|
||||
QCOMPARE( f2.evaluate( &record1 ), QString( "00000001" ) );
|
||||
QCOMPARE( f3.evaluate( &record1 ), QString( "-0000001" ) );
|
||||
QCOMPARE( f4.evaluate( &record1 ), QString( "00000000" ) ); // Invalid integer value
|
||||
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 ), QString( "00000064" ) ); // 100(decimal) == 64(hex)
|
||||
QCOMPARE( f6.evaluate( &record1 ), QString( "00000100" ) );
|
||||
QCOMPARE( f7.evaluate( &record1 ), QString( "00000000" ) ); // Invalid unsigned integer
|
||||
QCOMPARE( f8.evaluate( &record1 ), QString( "0000013a" ) ); // 314(decimal) == 13a(hex)
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
@@ -323,6 +333,8 @@ void TestSubstitutionField::newLineEvaluation()
|
||||
{
|
||||
using namespace glabels;
|
||||
|
||||
model::Variables variables;
|
||||
|
||||
model::SubstitutionField addr2( "${ADDR2:n}" );
|
||||
QCOMPARE( addr2.fieldName(), QString( "ADDR2" ) );
|
||||
QCOMPARE( addr2.newLine(), true );
|
||||
@@ -336,7 +348,7 @@ void TestSubstitutionField::newLineEvaluation()
|
||||
merge::Record record3;
|
||||
// ADDR2 not defined
|
||||
|
||||
QCOMPARE( addr2.evaluate( &record1 ), QString( "\nApt. 5B" ) ); // Prepends a newline
|
||||
QCOMPARE( addr2.evaluate( &record2 ), QString( "" ) ); // Evaluates empty
|
||||
QCOMPARE( addr2.evaluate( &record3 ), QString( "" ) ); // Evaluates empty
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user