Ignore:
Timestamp:
2012-05-12T23:27:39+02:00 (12 years ago)
Author:
bastiK
Message:
  • removed offset option from UTM which is probably rarely used. (custom projection can be used for this now, e.g. +proj=tmerc +lon_0=-3 +k_0=0.9996 +x_0=3500000 or +init=epsg:32630 +x_0=3500000)
  • fixed tests
File:
1 edited

Legend:

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

    r5073 r5236  
    22package org.openstreetmap.josm.data.projection;
    33
    4 import static org.openstreetmap.josm.tools.I18n.tr;
    54
    65import java.io.BufferedReader;
     
    1211import java.io.IOException;
    1312import java.util.ArrayList;
    14 import java.util.Arrays;
    1513import java.util.Collection;
    16 import java.util.Collections;
    1714import java.util.HashMap;
    1815import java.util.HashSet;
    19 import java.util.LinkedHashMap;
     16import java.util.LinkedHashSet;
    2017import java.util.List;
    2118import java.util.Map;
     
    3128import org.openstreetmap.josm.data.coor.EastNorth;
    3229import org.openstreetmap.josm.data.coor.LatLon;
    33 import org.openstreetmap.josm.tools.Utils;
     30import org.openstreetmap.josm.gui.preferences.projection.ProjectionChoice;
     31import org.openstreetmap.josm.gui.preferences.projection.ProjectionPreference;
    3432import org.openstreetmap.josm.tools.Pair;
    3533
     
    5856    public static void main(String[] args) throws IOException, FileNotFoundException {
    5957        setUp();
    60         Map<String, Projection> allCodes = new LinkedHashMap<String, Projection>();
    61         List<Projection> projs = Projections.getProjections();
    62         for (Projection p: projs) {
    63             if (p instanceof ProjectionSubPrefs) {
    64                 for (String code : ((ProjectionSubPrefs)p).allCodes()) {
    65                     ProjectionSubPrefs projSub = recreateProj((ProjectionSubPrefs)p);
    66                     Collection<String> prefs = projSub.getPreferencesFromCode(code);
    67                     projSub.setPreferences(prefs);
    68                     allCodes.put(code, projSub);
    69                 }
    70             } else {
    71                 allCodes.put(p.toCode(), p);
     58
     59        Map<String, Projection> supportedCodesMap = new HashMap<String, Projection>();
     60        for (ProjectionChoice pc : ProjectionPreference.getProjectionChoices()) {
     61            for (String code : pc.allCodes()) {
     62                Collection<String> pref = pc.getPreferencesFromCode(code);
     63                pc.setPreferences(pref);
     64                Projection p = pc.getProjection();
     65                supportedCodesMap.put(code, p);
    7266            }
    7367        }
     
    7771            prevData = readData();
    7872        }
    79         Map<String,TestData> prevCodes = new HashMap<String,TestData>();
     73        Map<String,TestData> prevCodesMap = new HashMap<String,TestData>();
    8074        for (TestData data : prevData) {
    81             prevCodes.put(data.code, data);
     75            prevCodesMap.put(data.code, data);
     76        }
     77
     78        Set<String> codesToWrite = new LinkedHashSet<String>();
     79        for (TestData data : prevData) {
     80            if (supportedCodesMap.containsKey(data.code)) {
     81                codesToWrite.add(data.code);
     82            }
     83        }
     84        for (String code : supportedCodesMap.keySet()) {
     85            if (!codesToWrite.contains(code)) {
     86                codesToWrite.add(code);
     87            }
    8288        }
    8389
     
    8692        out.write("# Data for test/unit/org/openstreetmap/josm/data/projection/ProjectionRegressionTest.java\n");
    8793        out.write("# Format: 1. Projection code; 2. lat/lon; 3. lat/lon projected -> east/north; 4. east/north (3.) inverse projected\n");
    88         for (Entry<String, Projection> e : allCodes.entrySet()) {
    89             Projection proj = e.getValue();
     94        for (Entry<String, Projection> e : supportedCodesMap.entrySet()) {
     95        }
     96        for (String code : codesToWrite) {
     97            Projection proj = supportedCodesMap.get(code);
    9098            Bounds b = proj.getWorldBoundsLatLon();
    9199            double lat, lon;
    92             TestData prev = prevCodes.get(proj.toCode());
     100            TestData prev = prevCodesMap.get(proj.toCode());
    93101            if (prev != null) {
    94102                lat = prev.ll.lat();
     
    103111        }
    104112        out.close();
    105     }
    106 
    107     private static ProjectionSubPrefs recreateProj(ProjectionSubPrefs proj) {
    108         try {
    109             return proj.getClass().newInstance();
    110         } catch (Exception e) {
    111             throw new IllegalStateException(
    112                     tr("Cannot instantiate projection ''{0}''", proj.getClass().toString()), e);
    113         }
    114113    }
    115114
     
    163162        StringBuilder fail = new StringBuilder();
    164163
    165         List<Projection> projs = Projections.getProjections();
    166         for (Projection p: projs) {
    167             Collection<String> codes = null;
    168             if (p instanceof ProjectionSubPrefs) {
    169                 codes = Arrays.asList(((ProjectionSubPrefs)p).allCodes());
    170             } else {
    171                 codes = Collections.singleton(p.toCode());
    172             }
    173             for (String code : codes) {
     164        for (ProjectionChoice pc : ProjectionPreference.getProjectionChoices()) {
     165            for (String code : pc.allCodes()) {
    174166               if (!dataCodes.contains(code)) {
    175167                    fail.append("Did not find projection "+code+" in test data!\n");
Note: See TracChangeset for help on using the changeset viewer.