From: Konrad Rosenbaum Date: Tue, 12 Mar 2013 08:36:07 +0000 (+0100) Subject: test for locale formatting; X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=32a3cf8f05532b58b54ab93c2af1f3ea49cb5345;p=web%2Fkonrad%2Fsmoke.git test for locale formatting; some basic includes for testing; add profile template for tests --- diff --git a/.gitignore b/.gitignore index 352439f..0f15957 100644 --- a/.gitignore +++ b/.gitignore @@ -59,3 +59,4 @@ tests/db/etc/*.conf tests/db/run tests/appdata tests/appconf +tests/test_* diff --git a/src/libs.pri b/src/libs.pri index 242e829..b7c0ed4 100644 --- a/src/libs.pri +++ b/src/libs.pri @@ -2,22 +2,22 @@ # ZIP library LIBS += -lQtZipHelper -INCLUDEPATH += ../zip/include +INCLUDEPATH += $$PWD/../zip/include # PACK library LIBS += -lqwbase -INCLUDEPATH += ../pack/qtbase/include +INCLUDEPATH += $$PWD/../pack/qtbase/include # Time Zone DB library LIBS += -lQtTzData -INCLUDEPATH += ../tzone/include +INCLUDEPATH += $$PWD/../tzone/include # ELAM library LIBS += -lelam -INCLUDEPATH += ../elam/include +INCLUDEPATH += $$PWD/../elam/include # Chester DPtr library -INCLUDEPATH += ../dptr +INCLUDEPATH += $$PWD/../dptr #QCA #LIBS += -lqca diff --git a/src/misc/misc.cpp b/src/misc/misc.cpp index df3aba2..7c1126a 100644 --- a/src/misc/misc.cpp +++ b/src/misc/misc.cpp @@ -137,6 +137,8 @@ MLocalFormat::MLocalFormat(int) d->m_moneydecimals=2; d->m_thousanddigits=3; d->m_timezone="UTC"; + d->m_am="AM"; + d->m_pm="PM"; //set defaults setWeekDays();setShortWeekDays(); setMonths();setShortMonths(); @@ -461,18 +463,11 @@ QString MLocalFormat::formatDateTime(const TimeStamp& ts, QString format) const //west(-) or east(+)? QString t; if(d<0){t="-";d*=-1;}else t="+"; - //hours - QString s=QString::number(d/60); - if(s.size()<2)s="0"+s; - t+=s; - //T or t? make a colon? - if(format[i].unicode()=='t')t+=":"; - //minutes - s=QString::number(d%60); - if(s.size()<2)s="0"+s; - t+=s; //append - out+=t; + out+=QString("%1%2:%3") + .arg(t) + .arg(int(d/60),2,10,QChar('0')) + .arg(int(d%60),2,10,QChar('0')); break; } case 'o':out+=time.zoneAbbreviation();break; diff --git a/src/tests/locale/locale.cpp b/src/tests/locale/locale.cpp deleted file mode 100644 index 4ec4182..0000000 --- a/src/tests/locale/locale.cpp +++ /dev/null @@ -1,115 +0,0 @@ -// -// C++ Implementation: locale -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2010 -// -// Copyright: See COPYING file that comes with this distribution -// -// - -#include "../../misc/misc.h" -#include - -void printout(MLocalFormat&mf) -{ - qDebug()<<" 10000 as int" << mf.formatNumber(10000); - qDebug()<<" 12345.678 as float" << mf.formatNumber(12345.678); - qDebug()<<" 10000 as money" <, (C) 2010-2013 +// +// Copyright: See COPYING file that comes with this distribution +// +// + +#include "mtest.h" +#include "tlocale.h" +#include + +MSTEST_MAIN(TLocale) + + +void TLocale::printFormatting() +{ + QCOMPARE(mf.formatNumber(10000),(QString)"10000"); + QCOMPARE(mf.formatNumber(1234.5),(QString)"1234.5000"); + QCOMPARE(mf.formatNumber(-10000),(QString)"-10000"); + QCOMPARE(mf.formatNumber(-1234.5),(QString)"-1234.5000"); + QCOMPARE(mf.formatMoney(12345),(QString)"123.45"); + + QDateTime tm(QDate(2003,2,1),QTime(16,5,6,7),Qt::UTC); + QCOMPARE(mf.formatDate(tm.date()),QString("2003-02-01")); + QCOMPARE(mf.formatTime(tm.time()),QString("16:05")); + QCOMPARE(mf.formatDateTime(tm),QString("2003-02-01 16:05")); + QCOMPARE(mf.formatDateTime(tm,"%Y/%y %M/%m/%N/%n %D/%d/%W/%w"), QString("2003/03 02/2/February/Feb 01/1/Saturday/Sat")); + QCOMPARE(mf.formatDateTime(tm,"%H/%h/%A/%a %I/%i %S/%s %P/%p"), QString("16/16/04/4 05/5 06/6 PM/pm")); + TimeStamp ts(tm,"Europe/Berlin"); + QCOMPARE(ts.msecs(),(unsigned short)7); + QCOMPARE(mf.formatDateTime(tm,"%Z/%z"), QString("007/7")); + QCOMPARE(mf.formatDateTime(TimeStamp(1363031849,"Europe/Berlin"),"%t"), QString("+01:00")); +} + +void TLocale::weirdPrintFormatting() +{ + switchToBadFormat(); + + QCOMPARE(mf.formatNumber(10000),(QString)"1_00_00"); + QCOMPARE(mf.formatNumber(1234.5),(QString)"12_34;5000"); + QCOMPARE(mf.formatNumber(-10000),(QString)"-1_00_00"); + QCOMPARE(mf.formatNumber(-1234.5),(QString)"-12_34;5000"); + QCOMPARE(mf.formatMoney(12345),(QString)"12;345 Credits"); + + QDateTime tm(QDate(2003,2,1),QTime(16,5,6,7),Qt::UTC); + QCOMPARE(mf.formatDate(tm.date()),QString("2003-02-01")); + QCOMPARE(mf.formatTime(tm.time()),QString("16:05")); + QCOMPARE(mf.formatDateTime(tm),QString("2003-02-01 16:05")); + QCOMPARE(mf.formatDateTime(tm,"%Y/%y %M/%m/%N/%n %D/%d/%W/%w"), QString("2003/03 02/2/febber/f2 01/1/satt-dai/satt")); + QCOMPARE(mf.formatDateTime(tm,"%H/%h/%A/%a %I/%i %S/%s %P/%p"), QString("16/16/04/4 05/5 06/6 PP/pp")); + TimeStamp ts(tm,"Europe/Berlin"); + QCOMPARE(ts.msecs(),(unsigned short)7); + QCOMPARE(mf.formatDateTime(tm,"%Z/%z"), QString("007/7")); + QCOMPARE(mf.formatDateTime(TimeStamp(1363031849,"Europe/Berlin"),"%t"), QString("+01:00")); +} + + +void TLocale::testMoneyRegexp() +{ + QRegExp r=mf.moneyRegExp(true,true); + QVERIFY(r.isValid()); + QVERIFY(r.exactMatch("123.45")); + QVERIFY(r.exactMatch("1,23.45")); + QVERIFY(r.exactMatch("-1,23.45")); + QVERIFY(!r.exactMatch("1,23.456")); + QVERIFY(!r.exactMatch("1_23;456")); + QVERIFY(!r.exactMatch("123.45x")); + QVERIFY(!r.exactMatch("123;456Credits")); + QVERIFY(!r.exactMatch("-123;456Credits")); + QVERIFY(!r.exactMatch("[123;456]Credits")); +} + +void TLocale::weirdMoneyRegexp() +{ + switchToBadFormat(); + QRegExp r=mf.moneyRegExp(true,true); + QVERIFY(r.isValid()); + QVERIFY(!r.exactMatch("123.45")); + QVERIFY(!r.exactMatch("1,23.45")); + QVERIFY(!r.exactMatch("-1,23.45")); + QVERIFY(!r.exactMatch("1,23.456")); + QVERIFY(r.exactMatch("1_23;456")); + QVERIFY(!r.exactMatch("123.45x")); + QVERIFY(r.exactMatch("123;456Credits")); + QVERIFY(r.exactMatch("[123;456]Credits")); + QVERIFY(!r.exactMatch("-123;456Credits")); +} + + +void TLocale::scanData() +{ + QCOMPARE(mf.scanInt(" 1234 "),1234ll); + QCOMPARE(mf.scanInt(" -1234 "),-1234ll); + QCOMPARE(mf.scanInt(" 12,34 "),1234ll); + QCOMPARE(mf.scanInt(" 12_34 "),12ll); + QCOMPARE(mf.scanInt(" 12/34 "),12ll); + QCOMPARE(mf.scanInt(" 12.34 "),12ll); + + QCOMPARE(mf.scanFloat(" 1234.56 "),1234.56); + QCOMPARE(mf.scanFloat(" 1234 "),1234.); + QCOMPARE(mf.scanFloat(" 12,34.56 "),1234.56); + QCOMPARE(mf.scanFloat(" 12_34;56 "),12.); + QCOMPARE(mf.scanFloat(" -12,34.56 "),-1234.56); + + QCOMPARE(mf.scanMoney(" 1234.56 "),123456ll); + QCOMPARE(mf.scanMoney(" 12,34.56 "),123456ll); + QCOMPARE(mf.scanMoney(" 12_34;56 "),1200ll); + QCOMPARE(mf.scanMoney(" 12,34.5 "),123450ll); + QCOMPARE(mf.scanMoney(" 12,34.567 "),123456ll); + QCOMPARE(mf.scanMoney(" 12,34.5.6 "),123456ll); + QCOMPARE(mf.scanMoney(" 12,34.5,6 "),123456ll); + QCOMPARE(mf.scanMoney(" 12,34.5 6 "),123450ll); + QCOMPARE(mf.scanMoney(" -12,34.56 "),-123456ll); + QCOMPARE(mf.scanMoney(" [12,34.56] "),0ll); + QCOMPARE(mf.scanMoney(" [12_34;56]Cu "),0ll); + QCOMPARE(mf.scanMoney(" -12_34;56Cu "),-1200ll); + QCOMPARE(mf.scanMoney(" -[12_34;56]Cu "),0ll); +} + +void TLocale::weirdScanData() +{ + switchToBadFormat(); + QCOMPARE(mf.scanInt(" 1234 "),1234ll); + QCOMPARE(mf.scanInt(" -1234 "),-1234ll); + QCOMPARE(mf.scanInt(" 12,34 "),12ll); + QCOMPARE(mf.scanInt(" 12_34 "),1234ll); + QCOMPARE(mf.scanInt(" 12/34 "),12ll); + QCOMPARE(mf.scanInt(" 12.34 "),12ll); + + QCOMPARE(mf.scanFloat(" 1234.56 "),1234.); + QCOMPARE(mf.scanFloat(" 1234 "),1234.); + QCOMPARE(mf.scanFloat(" 12,34.56 "),12.); + QCOMPARE(mf.scanFloat(" 12_34;56 "),1234.56); + QCOMPARE(mf.scanFloat(" -12,34.56 "),-12.); + + QCOMPARE(mf.scanMoney(" 1234.56 "),1234000ll); + QCOMPARE(mf.scanMoney(" 12,34.56 "),12000ll); + QCOMPARE(mf.scanMoney(" 12_34;56 "),1234560ll); + QCOMPARE(mf.scanMoney(" 12,34.5 "),12000ll); + QCOMPARE(mf.scanMoney(" 12,34.567 "),12000ll); + QCOMPARE(mf.scanMoney(" 12,34.5.6 "),12000ll); + QCOMPARE(mf.scanMoney(" 12,34.5,6 "),12000ll); + QCOMPARE(mf.scanMoney(" 12,34.5 6 "),12000ll); + QCOMPARE(mf.scanMoney(" -12,34.56 "),-12000ll); + QCOMPARE(mf.scanMoney(" [12,34.56] "),-12000ll); + QCOMPARE(mf.scanMoney(" [12_34;56]Cu "),-1234560ll); + QCOMPARE(mf.scanMoney(" -12_34;56Cu "),0ll); + QCOMPARE(mf.scanMoney(" -[12_34;56]Cu "),0ll); +} + + + +void TLocale::resetMoneyRegexp() +{ + resetFormat(); + testMoneyRegexp(); +} + +void TLocale::resetPrintFormatting() +{ + resetFormat(); + printFormatting(); +} + +void TLocale::resetScanData() +{ + resetFormat(); + scanData(); +} + + + + +void TLocale::initialize() +{ + mf.setTimeZone("Europe/Berlin"); +} + +void TLocale::switchToBadFormat() +{ + if(mf.decimalDot()==';')return; + qDebug()<<"\nchanging settings:"; + qDebug()<<"strange names for days and months"; + mf.setWeekDays(QStringList()<<"sunndai"<<"mundai"<<"toosdai"<<"whensdai"<<"soorsdai"<<"fraidai"<<"satt-dai"); + mf.setShortWeekDays(QStringList()<<"sunn"<<"mun"<<"too"<<"when"<<"soo"<<"frai"<<"satt"); + mf.setMonths(QStringList()<<"janner"<<"febber"<<"marsh"<<"abbrill"<<"mai"<<"shoon"<<"shoolai"<<"ogust"<<"sebtumbr"<<"oggdobr"<<"noffembr"<<"dessembr"); + mf.setShortMonths(QStringList()<<"j1"<<"f2"<<"m3"<<"a4"<<"m5"<<"j6"<<"j7"<<"a8"<<"s9"<<"o10"<<"n11"<<"d12"); + qDebug()<<"decimal dot=; thousand divider=_ 2 digits per block"; + mf.setNumberFormat(';','_',2); + qDebug()<<"currency=Credits, 3 currency decimals, negative is [123.45]"; + mf.setMoneyFormat("Credits",3,"[]"); + mf.setAP("AA","PP"); +} + +void TLocale::resetFormat() +{ + if(mf.decimalDot()=='.')return; + qDebug()<<"Resetting formatting"; + mf=MLocalFormat(); + mf.setTimeZone("Europe/Berlin"); +} diff --git a/tests/locale/tlocale.h b/tests/locale/tlocale.h new file mode 100644 index 0000000..244fb90 --- /dev/null +++ b/tests/locale/tlocale.h @@ -0,0 +1,22 @@ +#include +#include "misc.h" + +class TLocale:public QObject +{ + Q_OBJECT + MLocalFormat mf; + + void switchToBadFormat(); + void resetFormat(); +private slots: + void initialize(); + void printFormatting(); + void scanData(); + void testMoneyRegexp(); + void weirdPrintFormatting(); + void weirdScanData(); + void weirdMoneyRegexp(); + void resetPrintFormatting(); + void resetScanData(); + void resetMoneyRegexp(); +}; \ No newline at end of file diff --git a/tests/mtest.h b/tests/mtest.h new file mode 100644 index 0000000..5597dfd --- /dev/null +++ b/tests/mtest.h @@ -0,0 +1,17 @@ +#ifndef MAGICSMOKE_TEST_H +#define MAGICSMOKE_TEST_H + +#include +#include "main.h" + +#define MSTEST_MAIN(TestObject) \ +int main(int argc, char *argv[]) \ +{ \ + MApplication app(argc, argv); \ + app.setAttribute(Qt::AA_Use96Dpi, true); \ + QTEST_DISABLE_KEYPAD_NAVIGATION \ + TestObject tc; \ + return QTest::qExec(&tc, argc, argv); \ +} + +#endif diff --git a/tests/testbasics.pri b/tests/testbasics.pri new file mode 100644 index 0000000..b4f26e5 --- /dev/null +++ b/tests/testbasics.pri @@ -0,0 +1,26 @@ +LIBS += -lmagicsmoke -L$$PWD/../bin +INCLUDEPATH += $$PWD/../src \ + $$PWD/../src/crypto \ + $$PWD/../src/dialogs \ + $$PWD/../src/iface \ + $$PWD/../src/misc \ + $$PWD/../src/mwin \ + $$PWD/../src/script \ + $$PWD/../src/templates \ + $$PWD/../src/wext \ + $$PWD/../src/widgets \ + $$PWD/../src/wob \ + $$PWD + +include($$PWD/../src/libs.pri) +QT += testlib widgets printsupport + +gcc { QMAKE_CXXFLAGS += -std=gnu++11 } + +linux-* { QMAKE_LFLAGS += -Wl,-rpath,$$PWD/../bin } + +#compilation output: +OBJECTS_DIR = .ctmp +MOC_DIR = .ctmp +RCC_DIR = .ctmp +DESTDIR = $$PWD \ No newline at end of file diff --git a/tests/testprofile/appconf/MagicSmoke/MagicSmoke2.ini b/tests/testprofile/appconf/MagicSmoke/MagicSmoke2.ini new file mode 100644 index 0000000..c720b95 --- /dev/null +++ b/tests/testprofile/appconf/MagicSmoke/MagicSmoke2.ini @@ -0,0 +1,22 @@ +[General] +lang=C +lastUsedDirectory=/home/konrad/src/smoke/tests + +[profiles] +0\hostkey=558fe572747ec293297814cb72fe1097e93281c2b288a08b881963bffc6d2041712831b3026b0cee +0\hostname=testhost +0\name=test +0\proxyname=proxy +0\proxypass= +0\proxyport=74 +0\proxyuser= +0\script\allowbuiltin=true +0\script\allowserver=false +0\script\allowuser=false +0\script\priobuiltin=10 +0\script\prioserver=20 +0\script\priouser=0 +0\script\userpath=/home/konrad/src/smoke/bin/../tests/appdata/userscripts +0\serverurl=localhost:20989/machine.php +0\useproxy=false +0\username=admin diff --git a/tests/testprofile/appdata/helpMenu.xml b/tests/testprofile/appdata/helpMenu.xml new file mode 100644 index 0000000..a5604e5 --- /dev/null +++ b/tests/testprofile/appdata/helpMenu.xml @@ -0,0 +1,3 @@ + + default:// + \ No newline at end of file diff --git a/tests/testprofile/appdata/profile.0/sslexceptions.xml b/tests/testprofile/appdata/profile.0/sslexceptions.xml new file mode 100644 index 0000000..9ebf4f2 --- /dev/null +++ b/tests/testprofile/appdata/profile.0/sslexceptions.xml @@ -0,0 +1,26 @@ + + -----BEGIN CERTIFICATE----- +MIID4TCCAsmgAwIBAgIFLt6Za/MwDQYJKoZIhvcNAQEFBQAwgYgxCzAJBgNVBAYT +Ak9aMRkwFwYDVQQIDBBHcmVlbndpdGNoY291bnR5MRQwEgYDVQQHDAtFbWVyYWxk +Q2l0eTEVMBMGA1UECgwMTG9jYWxob3N0ZXJzMRIwEAYDVQQDDAlsb2NhbGhvc3Qx +HTAbBgkqhkiG9w0BCQEWDnJvb3RAbG9jYWxob3N0MB4XDTEzMDMwOTIxMTE0MFoX +DTI0MDIyMDIxMTE0MFowgYgxCzAJBgNVBAYTAk9aMRkwFwYDVQQIDBBHcmVlbndp +dGNoY291bnR5MRQwEgYDVQQHDAtFbWVyYWxkQ2l0eTEVMBMGA1UECgwMTG9jYWxo +b3N0ZXJzMRIwEAYDVQQDDAlsb2NhbGhvc3QxHTAbBgkqhkiG9w0BCQEWDnJvb3RA +bG9jYWxob3N0MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA5dLUzxir +iGZXJ6J+ALGJ0OVma6PGYFzT9NfpZqBZGxURu7TsoM8UhLeNSuWDCvglmeaEAWQX +IPPEJx3OXUnCmdslrt8wSMW91xYAAdezFM5GBIEA5u74KcCJUJ3VIhpr9dvrT2sf +AGEKp8F8/F6nqf6MTV5RVwa2baO/EBdbSfEHUQ7SUOKPtv30rEwJKVzmCglEI2hg +WyZQv8FztCP3Zn36oZX+kwCYflV8JmhPLqs8jLjQgLB5lvN0PpBk37njrd55WyNJ +kgR4TSahUPQWroEoss8y6BYYjMj6QudYw44TqrCjFJ/zlaz7h3yOeDV8TrMUckHa +1vBYzj6gxzSzGQIDAQABo1AwTjAdBgNVHQ4EFgQUMCaNea3RXbGRPDtE6v/Ko4i6 +WpUwHwYDVR0jBBgwFoAUMCaNea3RXbGRPDtE6v/Ko4i6WpUwDAYDVR0TBAUwAwEB +/zANBgkqhkiG9w0BAQUFAAOCAQEAk8Xhd380cyTk/NP5FeCkgSfmlxtT/6BwWNzb +fyhSjFZ/XExLGXBjBeMtQfuMd6tu6O1IavaI5F6mmlW20JSa9e962j1PHOeUbKdZ +IRk5Hp112uAG5W/AXF3TMR09bXJYNspFId/NonwxT1U8uJeglOhDdCHEkir7cuGS +WYENS4g3zyJcyyMvmJieBgnz99072gk4kT7+m5SOY3iU5Iik0Udzxx7bQi7/u2QD +B5+8Qa4GdKnTb6/saRaYrbL3a/GkvINzJ46Nn9PsKKsC0NiZKXvzDJV0KeRGtxXx +F3qsOEELtXrsG7+lQQs1SR8SikNuBUHUu56lOU/8uPaixyxiYA== +-----END CERTIFICATE----- + + diff --git a/tzone b/tzone index 887a690..b420609 160000 --- a/tzone +++ b/tzone @@ -1 +1 @@ -Subproject commit 887a6906f5b8cc735a50aaaaf1e667994d4f499f +Subproject commit b420609ef5e95e2f0c7fcdfc2081b31f1c56d736