Changeset 11648 in josm for trunk/test


Ignore:
Timestamp:
2017-03-02T01:28:53+01:00 (3 years ago)
Author:
Don-vip
Message:

see #14422 - update unit test

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/data/projection/ProjectionRefTest.java

    r11324 r11648  
    3131
    3232import org.junit.Assert;
     33import org.junit.Rule;
    3334import org.junit.Test;
    3435import org.openstreetmap.josm.data.Bounds;
     
    3637import org.openstreetmap.josm.data.coor.LatLon;
    3738import org.openstreetmap.josm.gui.preferences.projection.CodeProjectionChoice;
     39import org.openstreetmap.josm.testutils.JOSMTestRules;
    3840import org.openstreetmap.josm.tools.Pair;
    3941import org.openstreetmap.josm.tools.Utils;
     
    4850 * program from the proj.4 library in path (or use <code>CS2CS_EXE</code> to set
    4951 * the full path of the executable). Make sure the required *.gsb grid files
    50  * can be accessed, i.e. copy them from <code>data/projection</code> to <code>/usr/share/proj</code> or
     52 * can be accessed, i.e. copy them from <code>data_nodist/projection</code> to <code>/usr/share/proj</code> or
    5153 * wherever cs2cs expects them to be placed.
    5254 *
     
    7577
    7678    static Random rand = new SecureRandom();
     79
     80    /**
     81     * Setup test.
     82     */
     83    @Rule
     84    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
     85    public JOSMTestRules test = new JOSMTestRules().platform();
    7786
    7887    /**
     
    284293    }
    285294
     295    /**
     296     * Test projections.
     297     * @throws IOException if any I/O error occurs
     298     */
    286299    @Test
    287300    public void testProjections() throws IOException {
     
    296309            }
    297310            if (!ref.def.equals(def0)) {
    298                 Assert.fail("definitions for " + ref.code + " do not match");
    299             }
    300             Projection proj = Projections.getProjectionByCode(ref.code);
    301             double scale = ((CustomProjection) proj).getToMeter();
    302             for (Pair<LatLon, EastNorth> p : ref.data) {
    303                 LatLon ll = p.a;
    304                 EastNorth enRef = p.b;
    305                 enRef = new EastNorth(enRef.east() * scale, enRef.north() * scale); // convert to meter
    306 
    307                 EastNorth en = proj.latlon2eastNorth(ll);
    308                 if (proj.switchXY()) {
    309                     en = new EastNorth(en.north(), en.east());
    310                 }
    311                 en = new EastNorth(en.east() * scale, en.north() * scale); // convert to meter
    312                 final double EPSILON_EN = 1e-2; // 1cm
    313                 if (!isEqual(enRef, en, EPSILON_EN, true)) {
    314                     String errorEN = String.format("%s (%s): Projecting latlon(%s,%s):%n" +
    315                             "        expected: eastnorth(%s,%s),%n" +
    316                             "        but got:  eastnorth(%s,%s)!%n",
    317                             proj.toString(), proj.toCode(), ll.lat(), ll.lon(), enRef.east(), enRef.north(), en.east(), en.north());
    318                     fail.append(errorEN);
     311                fail.append("definitions for ").append(ref.code).append(" do not match\n");
     312            } else {
     313                Projection proj = Projections.getProjectionByCode(ref.code);
     314                double scale = ((CustomProjection) proj).getToMeter();
     315                for (Pair<LatLon, EastNorth> p : ref.data) {
     316                    LatLon ll = p.a;
     317                    EastNorth enRef = p.b;
     318                    enRef = new EastNorth(enRef.east() * scale, enRef.north() * scale); // convert to meter
     319
     320                    EastNorth en = proj.latlon2eastNorth(ll);
     321                    if (proj.switchXY()) {
     322                        en = new EastNorth(en.north(), en.east());
     323                    }
     324                    en = new EastNorth(en.east() * scale, en.north() * scale); // convert to meter
     325                    final double EPSILON_EN = 1e-2; // 1cm
     326                    if (!isEqual(enRef, en, EPSILON_EN, true)) {
     327                        String errorEN = String.format("%s (%s): Projecting latlon(%s,%s):%n" +
     328                                "        expected: eastnorth(%s,%s),%n" +
     329                                "        but got:  eastnorth(%s,%s)!%n",
     330                                proj.toString(), proj.toCode(), ll.lat(), ll.lon(), enRef.east(), enRef.north(), en.east(), en.north());
     331                        fail.append(errorEN);
     332                    }
    319333                }
    320334            }
Note: See TracChangeset for help on using the changeset viewer.