Changeset View
Changeset View
Standalone View
Standalone View
tests/TestGeoDataCoordinates.cpp
Show First 20 Lines • Show All 509 Lines • ▼ Show 20 Line(s) | 497 | } else if (unit == "radian") { | |||
---|---|---|---|---|---|
510 | QCOMPARE(ceil(normalized_lat * 1000) / 1000, qreal(0.442)); | 510 | QCOMPARE(ceil(normalized_lat * 1000) / 1000, qreal(0.442)); | ||
511 | } | 511 | } | ||
512 | } | 512 | } | ||
513 | 513 | | |||
514 | enum SignType {NoSign, PositiveSign, NegativeSign}; | 514 | enum SignType {NoSign, PositiveSign, NegativeSign}; | ||
515 | enum SphereType {PosSphere, NegSphere}; | 515 | enum SphereType {PosSphere, NegSphere}; | ||
516 | enum UnitsType {NoUnits, WithUnits}; | 516 | enum UnitsType {NoUnits, WithUnits}; | ||
517 | enum SpacesType {NoSpaces, WithSpaces}; | 517 | enum SpacesType {NoSpaces, WithSpaces}; | ||
518 | enum LocaleType {CLocale, SystemLocale}; | ||||
518 | 519 | | |||
519 | //static QString | 520 | //static QString | ||
520 | //createDegreeString(SignType signType, | 521 | //createDegreeString(SignType signType, | ||
521 | // int degreeValue, int minutesValue, qreal secondsValue, | 522 | // int degreeValue, int minutesValue, qreal secondsValue, | ||
522 | // UnitsType unitsType, SpacesType spacesType) | 523 | // UnitsType unitsType, SpacesType spacesType) | ||
523 | //{ | 524 | //{ | ||
524 | // QString string; | 525 | // QString string; | ||
525 | 526 | | |||
Show All 34 Lines | |||||
560 | // if (spacesType == WithSpaces) string.append(QLatin1Char(' ')); | 561 | // if (spacesType == WithSpaces) string.append(QLatin1Char(' ')); | ||
561 | 562 | | |||
562 | // return string; | 563 | // return string; | ||
563 | //} | 564 | //} | ||
564 | 565 | | |||
565 | static QString | 566 | static QString | ||
566 | createDegreeString(SignType signType, | 567 | createDegreeString(SignType signType, | ||
567 | qreal degreeValue, | 568 | qreal degreeValue, | ||
569 | LocaleType locale, | ||||
568 | UnitsType unitsType, SpacesType spacesType) | 570 | UnitsType unitsType, SpacesType spacesType) | ||
569 | { | 571 | { | ||
570 | QString string; | 572 | QString string; | ||
571 | 573 | | |||
572 | // add degree | 574 | // add degree | ||
573 | if (signType != NoSign) string.append(QLatin1Char(signType==PositiveSign?'+':'-')); | 575 | if (signType != NoSign) string.append(QLatin1Char(signType==PositiveSign?'+':'-')); | ||
574 | string.append(QString::fromLatin1("%L1").arg(degreeValue, 0, 'f', 10)); | 576 | if (locale == CLocale) { | ||
577 | string.append(QString::number(degreeValue, 'f', 10)); | ||||
578 | } else { | ||||
579 | string.append(QLocale::system().toString(degreeValue, 'f', 10)); | ||||
580 | } | ||||
575 | if (unitsType == WithUnits) string.append(QChar(0xb0)); | 581 | if (unitsType == WithUnits) string.append(QChar(0xb0)); | ||
576 | 582 | | |||
577 | if (spacesType == WithSpaces) string.append(QLatin1Char(' ')); | 583 | if (spacesType == WithSpaces) string.append(QLatin1Char(' ')); | ||
578 | 584 | | |||
579 | return string; | 585 | return string; | ||
580 | } | 586 | } | ||
581 | 587 | | |||
582 | /* | 588 | /* | ||
▲ Show 20 Lines • Show All 251 Lines • ▼ Show 20 Line(s) | 835 | { | |||
834 | const QVector<SignType> signTypes = QVector<SignType>() | 840 | const QVector<SignType> signTypes = QVector<SignType>() | ||
835 | << NoSign << PositiveSign << NegativeSign; | 841 | << NoSign << PositiveSign << NegativeSign; | ||
836 | const QVector<SphereType> sphereTypes = QVector<SphereType>() | 842 | const QVector<SphereType> sphereTypes = QVector<SphereType>() | ||
837 | << PosSphere << NegSphere; | 843 | << PosSphere << NegSphere; | ||
838 | const QVector<UnitsType> unitsTypes = QVector<UnitsType>() | 844 | const QVector<UnitsType> unitsTypes = QVector<UnitsType>() | ||
839 | << NoUnits << WithUnits; | 845 | << NoUnits << WithUnits; | ||
840 | const QVector<SpacesType> spacesTypes = QVector<SpacesType>() | 846 | const QVector<SpacesType> spacesTypes = QVector<SpacesType>() | ||
841 | << NoSpaces << WithSpaces; | 847 | << NoSpaces << WithSpaces; | ||
848 | const QVector<LocaleType> localeTypes = QVector<LocaleType>() | ||||
849 | << CLocale << SystemLocale; | ||||
842 | 850 | | |||
843 | const QVector<qreal> degreeSamples = QVector<qreal>() | 851 | const QVector<qreal> degreeSamples = QVector<qreal>() | ||
844 | << qreal(0.0) << qreal(3.14159) << qreal(180.0); | 852 | << qreal(0.0) << qreal(3.14159) << qreal(180.0); | ||
845 | 853 | | |||
846 | foreach(const UnitsType unitsType, unitsTypes) { | 854 | foreach(const UnitsType unitsType, unitsTypes) { | ||
847 | foreach(const SpacesType spacesType, spacesTypes) { | 855 | foreach(const SpacesType spacesType, spacesTypes) { | ||
848 | // lon | 856 | // lon | ||
849 | foreach(const SphereType lonSphere, sphereTypes) { | 857 | foreach(const SphereType lonSphere, sphereTypes) { | ||
850 | foreach(const SignType lonSignType, signTypes) { | 858 | foreach(const SignType lonSignType, signTypes) { | ||
851 | const bool lonIsPositive = | 859 | const bool lonIsPositive = | ||
852 | (lonSphere==PosSphere && lonSignType!=NegativeSign) || | 860 | (lonSphere==PosSphere && lonSignType!=NegativeSign) || | ||
853 | (lonSphere==NegSphere && lonSignType==NegativeSign); | 861 | (lonSphere==NegSphere && lonSignType==NegativeSign); | ||
854 | foreach(const qreal lonDegree, degreeSamples) { | 862 | foreach(const qreal lonDegree, degreeSamples) { | ||
855 | // lat | 863 | // lat | ||
856 | foreach(const SphereType latSphere, sphereTypes) { | 864 | foreach(const SphereType latSphere, sphereTypes) { | ||
857 | foreach(const SignType latSignType, signTypes) { | 865 | foreach(const SignType latSignType, signTypes) { | ||
858 | const bool latIsPositive = | 866 | const bool latIsPositive = | ||
859 | (latSphere==PosSphere && latSignType!=NegativeSign) || | 867 | (latSphere==PosSphere && latSignType!=NegativeSign) || | ||
860 | (latSphere==NegSphere && latSignType==NegativeSign); | 868 | (latSphere==NegSphere && latSignType==NegativeSign); | ||
861 | foreach(const qreal latDegree, degreeSamples) { | 869 | foreach(const qreal latDegree, degreeSamples) { | ||
870 | // locale | ||||
871 | foreach(const LocaleType locale, localeTypes) { | ||||
862 | 872 | | |||
863 | // actual construction | 873 | // actual construction | ||
864 | // Create lon & lat values | 874 | // Create lon & lat values | ||
865 | qreal lon = lonDegree; | 875 | qreal lon = lonDegree; | ||
866 | if (! lonIsPositive) | 876 | if (! lonIsPositive) | ||
867 | lon *= -1; | 877 | lon *= -1; | ||
868 | qreal lat = latDegree; | 878 | qreal lat = latDegree; | ||
869 | if (! latIsPositive) | 879 | if (! latIsPositive) | ||
870 | lat *= -1; | 880 | lat *= -1; | ||
871 | 881 | | |||
872 | // Create string | 882 | // Create string | ||
873 | QString string; | 883 | QString string; | ||
874 | string.append(createDegreeString(latSignType, | 884 | string.append(createDegreeString(latSignType, | ||
875 | latDegree, | 885 | latDegree, | ||
886 | locale, | ||||
876 | unitsType, spacesType)); | 887 | unitsType, spacesType)); | ||
877 | string.append(QLatin1Char(latSphere==PosSphere?'N':'S')); | 888 | string.append(QLatin1Char(latSphere==PosSphere?'N':'S')); | ||
878 | string.append(QLatin1Char(' ')); | 889 | string.append(QLatin1Char(' ')); | ||
879 | string.append(createDegreeString(lonSignType, | 890 | string.append(createDegreeString(lonSignType, | ||
880 | lonDegree, | 891 | lonDegree, | ||
892 | locale, | ||||
881 | unitsType, spacesType)); | 893 | unitsType, spacesType)); | ||
882 | string.append(QLatin1Char(lonSphere==PosSphere?'E':'W')); | 894 | string.append(QLatin1Char(lonSphere==PosSphere?'E':'W')); | ||
883 | 895 | | |||
884 | // Create row title | 896 | // Create row title | ||
885 | QString rowTitle; | 897 | QString rowTitle; | ||
886 | rowTitle.append(QLatin1String(spacesType==WithSpaces?"spaced dir":"unspaced dir")) | 898 | rowTitle.append(QLatin1String(spacesType==WithSpaces?"spaced dir":"unspaced dir")) | ||
887 | .append(QLatin1String(unitsType==WithUnits?"|units":"|no units")) | 899 | .append(QLatin1String(unitsType==WithUnits?"|units":"|no units")) | ||
888 | .append(QLatin1String("|lon:")) | 900 | .append(QLatin1String("|lon:")) | ||
889 | .append(QLatin1Char(lonIsPositive?'+':'-')) | 901 | .append(QLatin1Char(lonIsPositive?'+':'-')) | ||
890 | .append(QString::fromLatin1("%L1").arg(lonDegree, 0, 'f', 10)+QChar(0xb0)) | 902 | .append(QString::number(lonDegree, 'f', 10)+QChar(0xb0)) | ||
891 | .append(QLatin1Char(lonSphere==PosSphere?'P':'N')) | 903 | .append(QLatin1Char(lonSphere==PosSphere?'P':'N')) | ||
892 | .append(QLatin1String("|lat:")) | 904 | .append(QLatin1String("|lat:")) | ||
893 | .append(QLatin1Char(latIsPositive?'+':'-')) | 905 | .append(QLatin1Char(latIsPositive?'+':'-')) | ||
894 | .append(QString::fromLatin1("%L1").arg(latDegree, 0, 'f', 10)+QChar(0xb0)) | 906 | .append(QString::number(latDegree, 'f', 10)+QChar(0xb0)) | ||
895 | .append(QLatin1Char(latSphere==PosSphere?'P':'N')) | 907 | .append(QLatin1Char(latSphere==PosSphere?'P':'N')) | ||
908 | .append(QLatin1Char('|')).append(QLatin1Char(locale==CLocale?'C':'L')) | ||||
896 | .append(QLatin1Char('|')).append(string).append(QLatin1Char('|')); | 909 | .append(QLatin1Char('|')).append(string).append(QLatin1Char('|')); | ||
897 | QTest::newRow(rowTitle.toLatin1()) | 910 | QTest::newRow(rowTitle.toLatin1()) | ||
898 | << string | 911 | << string | ||
899 | << lon | 912 | << lon | ||
900 | << lat; | 913 | << lat; | ||
901 | } | 914 | } | ||
902 | } | 915 | } | ||
903 | } | 916 | } | ||
904 | } | 917 | } | ||
905 | } | 918 | } | ||
906 | } | 919 | } | ||
907 | } | 920 | } | ||
908 | } | 921 | } | ||
922 | } | ||||
909 | 923 | | |||
910 | QTest::newRow("scientific notation") << "0.0,1.0e-2" << qreal(1.0e-2) << qreal(0.0); | 924 | QTest::newRow("scientific notation") << "0.0,1.0e-2" << qreal(1.0e-2) << qreal(0.0); | ||
911 | QTest::newRow("scientific notation") << "-2.4E0 1.0e-18" << qreal(1e-18) << qreal(-2.4e0); | 925 | QTest::newRow("scientific notation") << "-2.4E0 1.0e-18" << qreal(1e-18) << qreal(-2.4e0); | ||
912 | QTest::newRow("scientific notation") << "1.14e-02;1.33e+01" << qreal(1.33e1) << qreal(1.14e-2); | 926 | QTest::newRow("scientific notation") << "1.14e-02;1.33e+01" << qreal(1.33e1) << qreal(1.14e-2); | ||
913 | } | 927 | } | ||
914 | 928 | | |||
915 | /* | 929 | /* | ||
916 | * test fromString() with DM notation | 930 | * test fromString() with DM notation | ||
▲ Show 20 Lines • Show All 956 Lines • Show Last 20 Lines |