示例#1
0
 private void writeWaypoints(final cgCache cache) throws IOException {
   List<cgWaypoint> waypoints = cache.getWaypoints();
   List<cgWaypoint> ownWaypoints = new ArrayList<cgWaypoint>(waypoints.size());
   List<cgWaypoint> originWaypoints = new ArrayList<cgWaypoint>(waypoints.size());
   for (cgWaypoint wp : cache.getWaypoints()) {
     if (wp.isUserDefined()) {
       ownWaypoints.add(wp);
     } else {
       originWaypoints.add(wp);
     }
   }
   int maxPrefix = 0;
   for (cgWaypoint wp : originWaypoints) {
     String prefix = wp.getPrefix();
     try {
       maxPrefix = Math.max(Integer.parseInt(prefix), maxPrefix);
     } catch (NumberFormatException ex) {
       Log.e("Unexpected origin waypoint prefix='" + prefix + "'", ex);
     }
     writeCacheWaypoint(wp, prefix);
   }
   for (cgWaypoint wp : ownWaypoints) {
     maxPrefix++;
     String prefix = StringUtils.leftPad(String.valueOf(maxPrefix), 2, '0');
     writeCacheWaypoint(wp, prefix);
   }
 }
  public void testImportGpxZip() throws IOException {
    File pq7545915 = new File(tempDir, "7545915.zip");
    copyResourceToFile(R.raw.pq7545915, pq7545915);

    GPXImporter.ImportGpxZipFileThread importThread =
        new GPXImporter.ImportGpxZipFileThread(
            pq7545915, listId, importStepHandler, progressHandler);
    runImportThread(importThread);

    assertImportStepMessages(
        GPXImporter.IMPORT_STEP_START,
        GPXImporter.IMPORT_STEP_READ_FILE,
        GPXImporter.IMPORT_STEP_READ_WPT_FILE,
        GPXImporter.IMPORT_STEP_STORE_CACHES,
        GPXImporter.IMPORT_STEP_STORE_STATIC_MAPS,
        GPXImporter.IMPORT_STEP_FINISHED);
    SearchResult search = (SearchResult) importStepHandler.messages.get(5).obj;
    assertEquals(Collections.singletonList("GC31J2H"), new ArrayList<String>(search.getGeocodes()));

    cgCache cache = cgeoapplication.getInstance().loadCache("GC31J2H", LoadFlags.LOAD_CACHE_OR_DB);
    assertCacheProperties(cache);
    assertEquals(
        1,
        cache
            .getWaypoints()
            .size()); // this is the original pocket query result without test waypoint
  }
  public void testImportGpxZipAttachment() {
    Uri uri = Uri.parse("android.resource://cgeo.geocaching.test/raw/pq7545915");

    GPXImporter.ImportGpxZipAttachmentThread importThread =
        new GPXImporter.ImportGpxZipAttachmentThread(
            uri,
            getInstrumentation().getContext().getContentResolver(),
            listId,
            importStepHandler,
            progressHandler);
    runImportThread(importThread);

    assertImportStepMessages(
        GPXImporter.IMPORT_STEP_START,
        GPXImporter.IMPORT_STEP_READ_FILE,
        GPXImporter.IMPORT_STEP_READ_WPT_FILE,
        GPXImporter.IMPORT_STEP_STORE_CACHES,
        GPXImporter.IMPORT_STEP_STORE_STATIC_MAPS,
        GPXImporter.IMPORT_STEP_FINISHED);
    SearchResult search = (SearchResult) importStepHandler.messages.get(5).obj;
    assertEquals(Collections.singletonList("GC31J2H"), new ArrayList<String>(search.getGeocodes()));

    cgCache cache = cgeoapplication.getInstance().loadCache("GC31J2H", LoadFlags.LOAD_CACHE_OR_DB);
    assertCacheProperties(cache);
    assertEquals(
        1,
        cache
            .getWaypoints()
            .size()); // this is the original pocket query result without test waypoint
  }
  public void testImportGpxWithWaypoints() throws IOException {
    File gc31j2h = new File(tempDir, "gc31j2h.gpx");
    copyResourceToFile(R.raw.gc31j2h, gc31j2h);
    copyResourceToFile(R.raw.gc31j2h_wpts, new File(tempDir, "gc31j2h-wpts.gpx"));

    GPXImporter.ImportGpxFileThread importThread =
        new GPXImporter.ImportGpxFileThread(gc31j2h, listId, importStepHandler, progressHandler);
    runImportThread(importThread);

    assertImportStepMessages(
        GPXImporter.IMPORT_STEP_START,
        GPXImporter.IMPORT_STEP_READ_FILE,
        GPXImporter.IMPORT_STEP_READ_WPT_FILE,
        GPXImporter.IMPORT_STEP_STORE_CACHES,
        GPXImporter.IMPORT_STEP_STORE_STATIC_MAPS,
        GPXImporter.IMPORT_STEP_FINISHED);
    SearchResult search = (SearchResult) importStepHandler.messages.get(5).obj;
    assertEquals(Collections.singletonList("GC31J2H"), new ArrayList<String>(search.getGeocodes()));

    cgCache cache = cgeoapplication.getInstance().loadCache("GC31J2H", LoadFlags.LOAD_CACHE_OR_DB);
    assertCacheProperties(cache);
    assertEquals(2, cache.getWaypoints().size());
  }