Changeset View
Changeset View
Standalone View
Standalone View
tests/TestGeoDataCoordinates.cpp
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | 29 | private Q_SLOTS: | |||
---|---|---|---|---|---|
43 | void testIsPole(); | 43 | void testIsPole(); | ||
44 | void testNotation(); | 44 | void testNotation(); | ||
45 | void testNormalizeLat_data(); | 45 | void testNormalizeLat_data(); | ||
46 | void testNormalizeLat(); | 46 | void testNormalizeLat(); | ||
47 | void testNormalizeLon_data(); | 47 | void testNormalizeLon_data(); | ||
48 | void testNormalizeLon(); | 48 | void testNormalizeLon(); | ||
49 | void testNormalize_data(); | 49 | void testNormalize_data(); | ||
50 | void testNormalize(); | 50 | void testNormalize(); | ||
51 | // void testFromStringDMS_data(); | 51 | void testFromStringDMS_data(); | ||
52 | // void testFromStringDMS(); | 52 | void testFromStringDMS(); | ||
53 | // void testFromStringDM_data(); | 53 | void testFromStringDM_data(); | ||
54 | // void testFromStringDM(); | 54 | void testFromStringDM(); | ||
55 | void testFromStringD_data(); | 55 | void testFromStringD_data(); | ||
56 | void testFromStringD(); | 56 | void testFromStringD(); | ||
57 | void testFromLocaleString_data(); | 57 | void testFromLocaleString_data(); | ||
58 | void testFromLocaleString(); | 58 | void testFromLocaleString(); | ||
59 | void testToString_Decimal_data(); | 59 | void testToString_Decimal_data(); | ||
60 | void testToString_Decimal(); | 60 | void testToString_Decimal(); | ||
61 | void testToString_DMS_data(); | 61 | void testToString_DMS_data(); | ||
62 | void testToString_DMS(); | 62 | void testToString_DMS(); | ||
63 | void testToString_DM_data(); | 63 | void testToString_DM_data(); | ||
64 | void testToString_DM(); | 64 | void testToString_DM(); | ||
65 | void testPack_data(); | 65 | void testPack_data(); | ||
66 | void testPack(); | 66 | void testPack(); | ||
67 | void testUTM_data(); | 67 | void testUTM_data(); | ||
68 | void testUTM(); | 68 | void testUTM(); | ||
69 | }; | 69 | }; | ||
70 | 70 | | |||
71 | void TestGeoDataCoordinates::initTestCase() | 71 | void TestGeoDataCoordinates::initTestCase() | ||
72 | { | 72 | { | ||
73 | QLocale::setDefault( QLocale::c() ); // needed for testing toString* conversions | 73 | QLocale::setDefault( QLocale::c() ); // needed for testing toString* conversions | ||
74 | | ||||
75 | QTime time = QTime::currentTime(); | ||||
76 | qsrand((uint)time.msec()); | ||||
74 | } | 77 | } | ||
75 | 78 | | |||
76 | /* | 79 | /* | ||
77 | * test constructors | 80 | * test constructors | ||
78 | */ | 81 | */ | ||
79 | void TestGeoDataCoordinates::testConstruction() | 82 | void TestGeoDataCoordinates::testConstruction() | ||
80 | { | 83 | { | ||
81 | GeoDataCoordinates invalid1; | 84 | GeoDataCoordinates invalid1; | ||
▲ Show 20 Lines • Show All 428 Lines • ▼ Show 20 Line(s) | |||||
510 | } | 513 | } | ||
511 | 514 | | |||
512 | enum SignType {NoSign, PositiveSign, NegativeSign}; | 515 | enum SignType {NoSign, PositiveSign, NegativeSign}; | ||
513 | enum SphereType {PosSphere, NegSphere}; | 516 | enum SphereType {PosSphere, NegSphere}; | ||
514 | enum UnitsType {NoUnits, WithUnits}; | 517 | enum UnitsType {NoUnits, WithUnits}; | ||
515 | enum SpacesType {NoSpaces, WithSpaces}; | 518 | enum SpacesType {NoSpaces, WithSpaces}; | ||
516 | enum LocaleType {CLocale, SystemLocale}; | 519 | enum LocaleType {CLocale, SystemLocale}; | ||
517 | 520 | | |||
518 | //static QString | 521 | static QString | ||
519 | //createDegreeString(SignType signType, | 522 | createDegreeString(SignType signType, | ||
520 | // int degreeValue, int minutesValue, qreal secondsValue, | 523 | int degreeValue, int minutesValue, qreal secondsValue, | ||
521 | // UnitsType unitsType, SpacesType spacesType) | 524 | LocaleType locale, | ||
522 | //{ | 525 | UnitsType unitsType, SpacesType spacesType) | ||
523 | // QString string; | 526 | { | ||
524 | 527 | QString string; | |||
525 | // // add degree | 528 | | ||
526 | // if (signType != NoSign) string.append(QLatin1Char(signType==PositiveSign?'+':'-')); | 529 | // add degree | ||
527 | // string.append(QString::number(degreeValue)); | 530 | if (signType != NoSign) string.append(QLatin1Char(signType==PositiveSign?'+':'-')); | ||
528 | // if (unitsType == WithUnits) string.append(QChar(0xb0)); | 531 | string.append(QString::number(degreeValue)); | ||
529 | 532 | if (unitsType == WithUnits) string.append(QChar(0xb0)); | |||
530 | // // add minutes | 533 | | ||
531 | // string.append(QLatin1Char(' ') + QString::number(minutesValue)); | 534 | // add minutes | ||
532 | // if (unitsType == WithUnits) string.append(QLatin1Char('\'')); | 535 | string.append(QLatin1Char(' ') + QString::number(minutesValue)); | ||
533 | 536 | if (unitsType == WithUnits) string.append(QLatin1Char('\'')); | |||
534 | // // add seconds | 537 | | ||
535 | // string.append(QString::fromLatin1(" %L1").arg(secondsValue, 0, 'f', 10)); | 538 | // add seconds | ||
536 | // if (unitsType == WithUnits) string.append(QLatin1Char('"')); | 539 | if (locale == CLocale) { | ||
537 | 540 | string.append(QLatin1Char(' ') + QString::number(secondsValue, 'f', 10)); | |||
538 | // if (spacesType == WithSpaces) string.append(QLatin1Char(' ')); | 541 | } else { | ||
539 | 542 | string.append(QLatin1Char(' ') + QLocale::system().toString(secondsValue, 'f', 10)); | |||
540 | // return string; | 543 | } | ||
541 | //} | 544 | if (unitsType == WithUnits) string.append(QLatin1Char('"')); | ||
542 | 545 | | |||
543 | //static QString | 546 | if (spacesType == WithSpaces) string.append(QLatin1Char(' ')); | ||
544 | //createDegreeString(SignType signType, | 547 | | ||
545 | // int degreeValue, qreal minutesValue, | 548 | return string; | ||
546 | // UnitsType unitsType, SpacesType spacesType) | 549 | } | ||
547 | //{ | 550 | | ||
548 | // QString string; | 551 | static QString | ||
549 | 552 | createDegreeString(SignType signType, | |||
550 | // // add degree | 553 | int degreeValue, qreal minutesValue, | ||
551 | // if (signType != NoSign) string.append(QLatin1Char(signType==PositiveSign?'+':'-')); | 554 | LocaleType locale, | ||
552 | // string.append(QString::number(degreeValue)); | 555 | UnitsType unitsType, SpacesType spacesType) | ||
553 | // if (unitsType == WithUnits) string.append(QChar(0xb0)); | 556 | { | ||
554 | 557 | QString string; | |||
555 | // // add minutes | 558 | | ||
556 | // string.append(QString::fromLatin1(" %L1").arg(minutesValue, 0, 'f', 10)); | 559 | // add degree | ||
557 | // if (unitsType == WithUnits) string.append(QLatin1Char('\'')); | 560 | if (signType != NoSign) string.append(QLatin1Char(signType==PositiveSign?'+':'-')); | ||
561 | string.append(QString::number(degreeValue)); | ||||
562 | if (unitsType == WithUnits) string.append(QChar(0xb0)); | ||||
563 | | ||||
564 | // add minutes | ||||
565 | if (locale == CLocale) { | ||||
566 | string.append(QLatin1Char(' ') + QString::number(minutesValue, 'f', 10)); | ||||
567 | } else { | ||||
568 | string.append(QLatin1Char(' ') + QLocale::system().toString(minutesValue, 'f', 10)); | ||||
569 | } | ||||
570 | if (unitsType == WithUnits) string.append(QLatin1Char('\'')); | ||||
558 | 571 | | |||
559 | // if (spacesType == WithSpaces) string.append(QLatin1Char(' ')); | 572 | if (spacesType == WithSpaces) string.append(QLatin1Char(' ')); | ||
560 | 573 | | |||
561 | // return string; | 574 | return string; | ||
562 | //} | 575 | } | ||
563 | 576 | | |||
564 | static QString | 577 | static QString | ||
565 | createDegreeString(SignType signType, | 578 | createDegreeString(SignType signType, | ||
566 | qreal degreeValue, | 579 | qreal degreeValue, | ||
567 | LocaleType locale, | 580 | LocaleType locale, | ||
568 | UnitsType unitsType, SpacesType spacesType) | 581 | UnitsType unitsType, SpacesType spacesType) | ||
569 | { | 582 | { | ||
570 | QString string; | 583 | QString string; | ||
Show All 10 Lines | |||||
581 | if (spacesType == WithSpaces) string.append(QLatin1Char(' ')); | 594 | if (spacesType == WithSpaces) string.append(QLatin1Char(' ')); | ||
582 | 595 | | |||
583 | return string; | 596 | return string; | ||
584 | } | 597 | } | ||
585 | 598 | | |||
586 | /* | 599 | /* | ||
587 | * test data for testStringDMS() | 600 | * test data for testStringDMS() | ||
588 | */ | 601 | */ | ||
589 | //void TestGeoDataCoordinates::testFromStringDMS_data() | 602 | void TestGeoDataCoordinates::testFromStringDMS_data() | ||
590 | //{ | 603 | { | ||
591 | // QTest::addColumn<QString>("string"); | 604 | QTest::addColumn<QString>("string"); | ||
592 | // QTest::addColumn<qreal>("lon"); | 605 | QTest::addColumn<qreal>("lon"); | ||
593 | // QTest::addColumn<qreal>("lat"); | 606 | QTest::addColumn<qreal>("lat"); | ||
594 | 607 | | |||
595 | // const QVector<SignType> signTypes = QVector<SignType>() | 608 | const QVector<SignType> signTypes = QVector<SignType>() | ||
596 | // << NoSign << PositiveSign << NegativeSign; | 609 | << NoSign << PositiveSign << NegativeSign; | ||
597 | // const QVector<SphereType> sphereTypes = QVector<SphereType>() | 610 | const QVector<SphereType> sphereTypes = QVector<SphereType>() | ||
598 | // << PosSphere << NegSphere; | 611 | << PosSphere << NegSphere; | ||
599 | // const QVector<UnitsType> unitsTypes = QVector<UnitsType>() | 612 | const QVector<UnitsType> unitsTypes = QVector<UnitsType>() | ||
600 | // << NoUnits << WithUnits; | 613 | << NoUnits << WithUnits; | ||
601 | // const QVector<SpacesType> spacesTypes = QVector<SpacesType>() | 614 | const QVector<SpacesType> spacesTypes = QVector<SpacesType>() | ||
602 | // << NoSpaces << WithSpaces; | 615 | << NoSpaces << WithSpaces; | ||
603 | 616 | const QVector<LocaleType> localeTypes = QVector<LocaleType>() | |||
604 | // const QVector<uint> degreeSamples = QVector<uint>() | 617 | << CLocale << SystemLocale; | ||
605 | // << 0 << 140 << 180; | 618 | | ||
606 | // const QVector<uint> minutesSamples = QVector<uint>() | 619 | const QVector<uint> degreeSamples = QVector<uint>() | ||
607 | // << 0 << 23 << 59; | 620 | << 0 << 140 << 180; | ||
608 | // const QVector<qreal> secondsSamples = QVector<qreal>() | 621 | const QVector<uint> minutesSamples = QVector<uint>() | ||
609 | // << 0.0 << 3.14159 << 59.9999999; | 622 | << 0 << 23 << 59; | ||
610 | 623 | const QVector<qreal> secondsSamples = QVector<qreal>() | |||
611 | // foreach(const UnitsType unitsType, unitsTypes) { | 624 | << 0.0 << 3.14159 << 59.9999999; | ||
612 | // foreach(const SpacesType spacesType, spacesTypes) { | 625 | | ||
613 | // // lon | 626 | foreach(const UnitsType unitsType, unitsTypes) { | ||
614 | // foreach(const SphereType lonSphere, sphereTypes) { | 627 | foreach(const SpacesType spacesType, spacesTypes) { | ||
615 | // foreach(const SignType lonSignType, signTypes) { | 628 | // lon | ||
616 | // const bool lonIsPositive = | 629 | foreach(const SphereType lonSphere, sphereTypes) { | ||
617 | // (lonSphere==PosSphere && lonSignType!=NegativeSign) || | 630 | foreach(const SignType lonSignType, signTypes) { | ||
618 | // (lonSphere==NegSphere && lonSignType==NegativeSign); | 631 | const bool lonIsPositive = | ||
619 | // foreach(const uint lonDegree, degreeSamples) { | 632 | (lonSphere==PosSphere && lonSignType!=NegativeSign) || | ||
620 | // foreach(const uint lonMinutes, minutesSamples) { | 633 | (lonSphere==NegSphere && lonSignType==NegativeSign); | ||
621 | // if(lonDegree == 180 && lonMinutes != 0) continue; | 634 | foreach(const uint lonDegree, degreeSamples) { | ||
622 | // foreach(const qreal lonSeconds, secondsSamples) { | 635 | foreach(const uint lonMinutes, minutesSamples) { | ||
623 | // if(lonDegree == 180 && lonSeconds != 0.0) continue; | 636 | if(lonDegree == 180 && lonMinutes != 0) continue; | ||
624 | // // lat | 637 | foreach(const qreal lonSeconds, secondsSamples) { | ||
625 | // foreach(const SphereType latSphere, sphereTypes) { | 638 | if(lonDegree == 180 && lonSeconds != 0.0) continue; | ||
626 | // foreach(const SignType latSignType, signTypes) { | 639 | // lat | ||
627 | // const bool latIsPositive = | 640 | foreach(const SphereType latSphere, sphereTypes) { | ||
628 | // (latSphere==PosSphere && latSignType!=NegativeSign) || | 641 | foreach(const SignType latSignType, signTypes) { | ||
629 | // (latSphere==NegSphere && latSignType==NegativeSign); | 642 | const bool latIsPositive = | ||
630 | // foreach(const uint latDegree, degreeSamples) { | 643 | (latSphere==PosSphere && latSignType!=NegativeSign) || | ||
631 | // foreach(const uint latMinutes, minutesSamples) { | 644 | (latSphere==NegSphere && latSignType==NegativeSign); | ||
632 | // if(latDegree == 180 && latMinutes != 0) continue; | 645 | foreach(const uint latDegree, degreeSamples) { | ||
633 | // foreach(const qreal latSeconds, secondsSamples) { | 646 | foreach(const uint latMinutes, minutesSamples) { | ||
634 | // if(latDegree == 180 && latSeconds != 0.0) continue; | 647 | if(latDegree == 180 && latMinutes != 0) continue; | ||
635 | 648 | foreach(const qreal latSeconds, secondsSamples) { | |||
636 | // // actual construction | 649 | if(latDegree == 180 && latSeconds != 0.0) continue; | ||
637 | // // Create lon & lat values | 650 | // locale | ||
638 | // qreal lon = (qreal)lonDegree + lonMinutes*MIN2HOUR + lonSeconds*SEC2HOUR; | 651 | foreach(const LocaleType locale, localeTypes) { | ||
639 | // if( ! lonIsPositive ) | 652 | | ||
640 | // lon *= -1; | 653 | // actual construction | ||
641 | // qreal lat = (qreal)latDegree + latMinutes*MIN2HOUR + latSeconds*SEC2HOUR; | 654 | // Create lon & lat values | ||
642 | // if( ! latIsPositive ) | 655 | qreal lon = (qreal)lonDegree + lonMinutes*MIN2HOUR + lonSeconds*SEC2HOUR; | ||
643 | // lat *= -1; | 656 | if( ! lonIsPositive ) | ||
644 | 657 | lon *= -1; | |||
645 | // // Create string | 658 | qreal lat = (qreal)latDegree + latMinutes*MIN2HOUR + latSeconds*SEC2HOUR; | ||
646 | // QString string; | 659 | if( ! latIsPositive ) | ||
647 | // string.append(createDegreeString(latSignType, | 660 | lat *= -1; | ||
648 | // latDegree, latMinutes, latSeconds, | 661 | | ||
649 | // unitsType, spacesType)); | 662 | // Create string | ||
650 | // string.append(QLatin1Char(latSphere==PosSphere?'N':'S')); | 663 | QString string; | ||
651 | // string.append(QLatin1Char(' ')); | 664 | string.append(createDegreeString(latSignType, | ||
652 | // string.append(createDegreeString(lonSignType, | 665 | latDegree, latMinutes, latSeconds, | ||
653 | // lonDegree, lonMinutes, lonSeconds, | 666 | locale, | ||
654 | // unitsType, spacesType)); | 667 | unitsType, spacesType)); | ||
655 | // string.append(QLatin1Char(lonSphere==PosSphere?'E':'W')); | 668 | string.append(QLatin1Char(latSphere==PosSphere?'N':'S')); | ||
656 | 669 | string.append(QLatin1Char(' ')); | |||
657 | // // Create row title | 670 | string.append(createDegreeString(lonSignType, | ||
658 | // QString rowTitle; | 671 | lonDegree, lonMinutes, lonSeconds, | ||
659 | // rowTitle.append(QLatin1String(spacesType==WithSpaces?"spaced dir":"unspaced dir")) | 672 | locale, | ||
660 | // .append(QLatin1String(unitsType==WithUnits?"|units":"|no units")) | 673 | unitsType, spacesType)); | ||
661 | // .append(QLatin1String("|lon:")) | 674 | string.append(QLatin1Char(lonSphere==PosSphere?'E':'W')); | ||
662 | // .append(QLatin1Char(lonIsPositive?'+':'-')) | 675 | | ||
663 | // .append(QString::number(lonDegree)+QChar(0xb0)) | 676 | // Create row title | ||
664 | // .append(QString::number(lonMinutes)+QLatin1Char('\'')) | 677 | QString rowTitle; | ||
665 | // .append(QString::fromLatin1("%L1").arg(lonSeconds, 0, 'f', 10)+QLatin1Char('"')) | 678 | rowTitle.append(QLatin1String(spacesType==WithSpaces?"spaced dir":"unspaced dir")) | ||
666 | // .append(QLatin1Char(lonSphere==PosSphere?'P':'N')) | 679 | .append(QLatin1String(unitsType==WithUnits?"|units":"|no units")) | ||
667 | // .append(QLatin1String("|lat:")) | 680 | .append(QLatin1String("|lon:")) | ||
668 | // .append(QLatin1Char(latIsPositive?'+':'-')) | 681 | .append(QLatin1Char(lonIsPositive?'+':'-')) | ||
669 | // .append(QString::number(latDegree)+QChar(0xb0)) | 682 | .append(QString::number(lonDegree)+QChar(0xb0)) | ||
670 | // .append(QString::number(latMinutes)+QLatin1Char('\'')) | 683 | .append(QString::number(lonMinutes)+QLatin1Char('\'')) | ||
671 | // .append(QString::fromLatin1("%L1").arg(latSeconds, 0, 'f', 10)+QLatin1Char('"')) | 684 | .append(QString::number(lonSeconds, 'f', 10)+QLatin1Char('"')) | ||
672 | // .append(QLatin1Char(latSphere==PosSphere?'P':'N')) | 685 | .append(QLatin1Char(lonSphere==PosSphere?'P':'N')) | ||
673 | // .append(QLatin1Char('|')).append(string).append(QLatin1Char('|')); | 686 | .append(QLatin1String("|lat:")) | ||
674 | // QTest::newRow(rowTitle.toLatin1()) | 687 | .append(QLatin1Char(latIsPositive?'+':'-')) | ||
675 | // << string | 688 | .append(QString::number(latDegree)+QChar(0xb0)) | ||
676 | // << lon | 689 | .append(QString::number(latMinutes)+QLatin1Char('\'')) | ||
677 | // << lat; | 690 | .append(QString::number(latSeconds, 'f', 10)+QLatin1Char('"')) | ||
678 | // } | 691 | .append(QLatin1Char(latSphere==PosSphere?'P':'N')) | ||
679 | // } | 692 | .append(QLatin1Char('|')).append(QLatin1Char(locale==CLocale?'C':'L')) | ||
680 | // } | 693 | .append(QLatin1Char('|')).append(string).append(QLatin1Char('|')); | ||
681 | // } | 694 | QTest::newRow(rowTitle.toLatin1().constData()) | ||
682 | // } | 695 | << string | ||
683 | // } | 696 | << lon | ||
684 | // } | 697 | << lat; | ||
685 | // } | 698 | } | ||
686 | // } | 699 | } | ||
687 | // } | 700 | } | ||
688 | // } | 701 | } | ||
689 | // } | 702 | } | ||
690 | //} | 703 | } | ||
691 | 704 | } | |||
692 | ///* | 705 | } | ||
693 | // * test fromString() with DMS notation | 706 | } | ||
694 | // */ | 707 | } | ||
695 | //void TestGeoDataCoordinates::testFromStringDMS() | 708 | } | ||
696 | //{ | 709 | } | ||
697 | // QFETCH(QString, string); | 710 | } | ||
698 | // QFETCH(qreal, lon); | 711 | } | ||
699 | // QFETCH(qreal, lat); | 712 | | ||
700 | 713 | /* | |||
701 | // bool succeeded = false; | 714 | * test fromString() with DMS notation | ||
702 | // const GeoDataCoordinates coords = GeoDataCoordinates::fromString(string, succeeded); | 715 | */ | ||
703 | 716 | void TestGeoDataCoordinates::testFromStringDMS() | |||
704 | // if(! succeeded) | 717 | { | ||
705 | // qWarning() << "Could not parse"<<string <<"for"<<lon<<lat; | 718 | // only run random 5% of all possible permutations | ||
706 | 719 | if ((qreal(qrand()) / RAND_MAX) > 0.05) { | |||
707 | // QVERIFY(succeeded); | 720 | QSKIP("Not picked for this run."); | ||
708 | // QCOMPARE(coords.longitude(GeoDataCoordinates::Degree), lon); | 721 | } | ||
709 | // QCOMPARE(coords.latitude(GeoDataCoordinates::Degree), lat); | 722 | | ||
710 | //} | 723 | QFETCH(QString, string); | ||
711 | 724 | QFETCH(qreal, lon); | |||
712 | ///* | 725 | QFETCH(qreal, lat); | ||
713 | // * test data for testStringDM() | 726 | | ||
714 | // */ | 727 | bool succeeded = false; | ||
715 | //void TestGeoDataCoordinates::testFromStringDM_data() | 728 | const GeoDataCoordinates coords = GeoDataCoordinates::fromString(string, succeeded); | ||
716 | //{ | 729 | | ||
717 | // QTest::addColumn<QString>("string"); | 730 | if(! succeeded) | ||
718 | // QTest::addColumn<qreal>("lon"); | 731 | qWarning() << "Could not parse"<<string <<"for"<<lon<<lat; | ||
719 | // QTest::addColumn<qreal>("lat"); | 732 | | ||
720 | 733 | QVERIFY(succeeded); | |||
721 | // const QVector<SignType> signTypes = QVector<SignType>() | 734 | QCOMPARE(coords.longitude(GeoDataCoordinates::Degree), lon); | ||
722 | // << NoSign << PositiveSign << NegativeSign; | 735 | QCOMPARE(coords.latitude(GeoDataCoordinates::Degree), lat); | ||
723 | // const QVector<SphereType> sphereTypes = QVector<SphereType>() | 736 | } | ||
724 | // << PosSphere << NegSphere; | 737 | | ||
725 | // const QVector<UnitsType> unitsTypes = QVector<UnitsType>() | 738 | /* | ||
726 | // << NoUnits << WithUnits; | 739 | * test data for testStringDM() | ||
727 | // const QVector<SpacesType> spacesTypes = QVector<SpacesType>() | 740 | */ | ||
728 | // << NoSpaces << WithSpaces; | 741 | void TestGeoDataCoordinates::testFromStringDM_data() | ||
729 | 742 | { | |||
730 | // const QVector<uint> degreeSamples = QVector<uint>() | 743 | QTest::addColumn<QString>("string"); | ||
731 | // << 0 << 140 << 180; | 744 | QTest::addColumn<qreal>("lon"); | ||
732 | // const QVector<qreal> minutesSamples = QVector<qreal>() | 745 | QTest::addColumn<qreal>("lat"); | ||
733 | // << 0.0 << 3.14159 << 59.9999999; | 746 | | ||
734 | 747 | const QVector<SignType> signTypes = QVector<SignType>() | |||
735 | // foreach(const UnitsType unitsType, unitsTypes) { | 748 | << NoSign << PositiveSign << NegativeSign; | ||
736 | // foreach(const SpacesType spacesType, spacesTypes) { | 749 | const QVector<SphereType> sphereTypes = QVector<SphereType>() | ||
737 | // // lon | 750 | << PosSphere << NegSphere; | ||
738 | // foreach(const SphereType lonSphere, sphereTypes) { | 751 | const QVector<UnitsType> unitsTypes = QVector<UnitsType>() | ||
739 | // foreach(const SignType lonSignType, signTypes) { | 752 | << NoUnits << WithUnits; | ||
740 | // const bool lonIsPositive = | 753 | const QVector<SpacesType> spacesTypes = QVector<SpacesType>() | ||
741 | // (lonSphere==PosSphere && lonSignType!=NegativeSign) || | 754 | << NoSpaces << WithSpaces; | ||
742 | // (lonSphere==NegSphere && lonSignType==NegativeSign); | 755 | const QVector<LocaleType> localeTypes = QVector<LocaleType>() | ||
743 | // foreach(const uint lonDegree, degreeSamples) { | 756 | << CLocale << SystemLocale; | ||
744 | // foreach(const qreal lonMinutes, minutesSamples) { | 757 | | ||
745 | // if(lonDegree == 180 && lonMinutes != 0.0) continue; | 758 | const QVector<uint> degreeSamples = QVector<uint>() | ||
746 | // // lat | 759 | << 0 << 140 << 180; | ||
747 | // foreach(const SphereType latSphere, sphereTypes) { | 760 | const QVector<qreal> minutesSamples = QVector<qreal>() | ||
748 | // foreach(const SignType latSignType, signTypes) { | 761 | << 0.0 << 3.14159 << 59.9999999; | ||
749 | // const bool latIsPositive = | 762 | | ||
750 | // (latSphere==PosSphere && latSignType!=NegativeSign) || | 763 | foreach(const UnitsType unitsType, unitsTypes) { | ||
751 | // (latSphere==NegSphere && latSignType==NegativeSign); | 764 | foreach(const SpacesType spacesType, spacesTypes) { | ||
752 | // foreach(const uint latDegree, degreeSamples) { | 765 | // lon | ||
753 | // foreach(const qreal latMinutes, minutesSamples) { | 766 | foreach(const SphereType lonSphere, sphereTypes) { | ||
754 | // if(latDegree == 180 && latMinutes != 0.0) continue; | 767 | foreach(const SignType lonSignType, signTypes) { | ||
755 | 768 | const bool lonIsPositive = | |||
756 | // // actual construction | 769 | (lonSphere==PosSphere && lonSignType!=NegativeSign) || | ||
757 | // // Create lon & lat values | 770 | (lonSphere==NegSphere && lonSignType==NegativeSign); | ||
758 | // qreal lon = (qreal)lonDegree + lonMinutes*MIN2HOUR; | 771 | foreach(const uint lonDegree, degreeSamples) { | ||
759 | // if( ! lonIsPositive ) | 772 | foreach(const qreal lonMinutes, minutesSamples) { | ||
760 | // lon *= -1; | 773 | if(lonDegree == 180 && lonMinutes != 0.0) continue; | ||
761 | // qreal lat = (qreal)latDegree + latMinutes*MIN2HOUR; | 774 | // lat | ||
762 | // if( ! latIsPositive ) | 775 | foreach(const SphereType latSphere, sphereTypes) { | ||
763 | // lat *= -1; | 776 | foreach(const SignType latSignType, signTypes) { | ||
764 | 777 | const bool latIsPositive = | |||
765 | // // Create string | 778 | (latSphere==PosSphere && latSignType!=NegativeSign) || | ||
766 | // QString string; | 779 | (latSphere==NegSphere && latSignType==NegativeSign); | ||
767 | // string.append(createDegreeString(latSignType, | 780 | foreach(const uint latDegree, degreeSamples) { | ||
768 | // latDegree, latMinutes, | 781 | foreach(const qreal latMinutes, minutesSamples) { | ||
769 | // unitsType, spacesType)); | 782 | if(latDegree == 180 && latMinutes != 0.0) continue; | ||
770 | // string.append(QLatin1Char(latSphere==PosSphere?'N':'S')); | 783 | // locale | ||
771 | // string.append(QLatin1Char(' ')); | 784 | foreach(const LocaleType locale, localeTypes) { | ||
772 | // string.append(createDegreeString(lonSignType, | 785 | | ||
773 | // lonDegree, lonMinutes, | 786 | // actual construction | ||
774 | // unitsType, spacesType)); | 787 | // Create lon & lat values | ||
775 | // string.append(QLatin1Char(lonSphere==PosSphere?'E':'W')); | 788 | qreal lon = (qreal)lonDegree + lonMinutes*MIN2HOUR; | ||
776 | 789 | if( ! lonIsPositive ) | |||
777 | // // Create row title | 790 | lon *= -1; | ||
778 | // QString rowTitle; | 791 | qreal lat = (qreal)latDegree + latMinutes*MIN2HOUR; | ||
779 | // rowTitle.append(QLatin1String(spacesType==WithSpaces?"spaced dir":"unspaced dir")) | 792 | if( ! latIsPositive ) | ||
780 | // .append(QLatin1String(unitsType==WithUnits?"|units":"|no units")) | 793 | lat *= -1; | ||
781 | // .append(QLatin1String("|lon:")) | 794 | | ||
782 | // .append(QLatin1Char(lonIsPositive?'+':'-')) | 795 | // Create string | ||
783 | // .append(QString::number(lonDegree)+QChar(0xb0)) | 796 | QString string; | ||
784 | // .append(QString::fromLatin1("%L1").arg(lonMinutes, 0, 'f', 10)+QLatin1Char('\'')) | 797 | string.append(createDegreeString(latSignType, | ||
785 | // .append(QLatin1Char(lonSphere==PosSphere?'P':'N')) | 798 | latDegree, latMinutes, | ||
786 | // .append(QLatin1String("|lat:")) | 799 | locale, | ||
787 | // .append(QLatin1Char(latIsPositive?'+':'-')) | 800 | unitsType, spacesType)); | ||
788 | // .append(QString::number(latDegree)+QChar(0xb0)) | 801 | string.append(QLatin1Char(latSphere==PosSphere?'N':'S')); | ||
789 | // .append(QString::fromLatin1("%L1").arg(latMinutes, 0, 'f', 10)+QLatin1Char('\'')) | 802 | string.append(QLatin1Char(' ')); | ||
790 | // .append(QLatin1Char(latSphere==PosSphere?'P':'N')) | 803 | string.append(createDegreeString(lonSignType, | ||
791 | // .append(QLatin1Char('|')).append(string).append(QLatin1Char('|')); | 804 | lonDegree, lonMinutes, | ||
792 | // QTest::newRow(rowTitle.toLatin1()) | 805 | locale, | ||
793 | // << string | 806 | unitsType, spacesType)); | ||
794 | // << lon | 807 | string.append(QLatin1Char(lonSphere==PosSphere?'E':'W')); | ||
795 | // << lat; | 808 | | ||
796 | // } | 809 | // Create row title | ||
797 | // } | 810 | QString rowTitle; | ||
798 | // } | 811 | rowTitle.append(QLatin1String(spacesType==WithSpaces?"spaced dir":"unspaced dir")) | ||
799 | // } | 812 | .append(QLatin1String(unitsType==WithUnits?"|units":"|no units")) | ||
800 | // } | 813 | .append(QLatin1String("|lon:")) | ||
801 | // } | 814 | .append(QLatin1Char(lonIsPositive?'+':'-')) | ||
802 | // } | 815 | .append(QString::number(lonDegree)+QChar(0xb0)) | ||
803 | // } | 816 | .append(QString::number(lonMinutes, 'f', 10)+QLatin1Char('\'')) | ||
804 | // } | 817 | .append(QLatin1Char(lonSphere==PosSphere?'P':'N')) | ||
805 | // } | 818 | .append(QLatin1String("|lat:")) | ||
806 | //} | 819 | .append(QLatin1Char(latIsPositive?'+':'-')) | ||
807 | 820 | .append(QString::number(latDegree)+QChar(0xb0)) | |||
808 | ///* | 821 | .append(QString::number(latMinutes, 'f', 10)+QLatin1Char('\'')) | ||
809 | // * test fromString() with DM notation | 822 | .append(QLatin1Char(latSphere==PosSphere?'P':'N')) | ||
810 | // */ | 823 | .append(QLatin1Char('|')).append(QLatin1Char(locale==CLocale?'C':'L')) | ||
811 | //void TestGeoDataCoordinates::testFromStringDM() | 824 | .append(QLatin1Char('|')).append(string).append(QLatin1Char('|')); | ||
812 | //{ | 825 | QTest::newRow(rowTitle.toLatin1().constData()) | ||
813 | // QFETCH(QString, string); | 826 | << string | ||
814 | // QFETCH(qreal, lon); | 827 | << lon | ||
815 | // QFETCH(qreal, lat); | 828 | << lat; | ||
816 | 829 | } | |||
817 | // bool succeeded = false; | 830 | } | ||
818 | // const GeoDataCoordinates coords = GeoDataCoordinates::fromString(string, succeeded); | 831 | } | ||
819 | 832 | } | |||
820 | // if(! succeeded) | 833 | } | ||
821 | // qWarning() << "Could not parse"<<string <<"for"<<lon<<lat; | 834 | } | ||
822 | 835 | } | |||
823 | // QVERIFY(succeeded); | 836 | } | ||
824 | // QCOMPARE(coords.longitude(GeoDataCoordinates::Degree), lon); | 837 | } | ||
825 | // QCOMPARE(coords.latitude(GeoDataCoordinates::Degree), lat); | 838 | } | ||
839 | } | ||||
840 | } | ||||
841 | | ||||
842 | /* | ||||
843 | * test fromString() with DM notation | ||||
844 | */ | ||||
845 | void TestGeoDataCoordinates::testFromStringDM() | ||||
846 | { | ||||
847 | // only run random 5% of all possible permutations | ||||
848 | if ((qreal(qrand()) / RAND_MAX) > 0.05) { | ||||
849 | QSKIP("Not picked for this run."); | ||||
850 | } | ||||
826 | 851 | | |||
827 | //} | 852 | | ||
853 | QFETCH(QString, string); | ||||
854 | QFETCH(qreal, lon); | ||||
855 | QFETCH(qreal, lat); | ||||
856 | | ||||
857 | bool succeeded = false; | ||||
858 | const GeoDataCoordinates coords = GeoDataCoordinates::fromString(string, succeeded); | ||||
859 | | ||||
860 | if(! succeeded) | ||||
861 | qWarning() << "Could not parse"<<string <<"for"<<lon<<lat; | ||||
862 | | ||||
863 | QVERIFY(succeeded); | ||||
864 | QCOMPARE(coords.longitude(GeoDataCoordinates::Degree), lon); | ||||
865 | QCOMPARE(coords.latitude(GeoDataCoordinates::Degree), lat); | ||||
866 | } | ||||
828 | 867 | | |||
829 | /* | 868 | /* | ||
830 | * test data for testStringDM() | 869 | * test data for testStringDM() | ||
831 | */ | 870 | */ | ||
832 | void TestGeoDataCoordinates::testFromStringD_data() | 871 | void TestGeoDataCoordinates::testFromStringD_data() | ||
833 | { | 872 | { | ||
834 | QTest::addColumn<QString>("string"); | 873 | QTest::addColumn<QString>("string"); | ||
835 | QTest::addColumn<qreal>("lon"); | 874 | QTest::addColumn<qreal>("lon"); | ||
▲ Show 20 Lines • Show All 1052 Lines • Show Last 20 Lines |