/**
   * Test {@link cgBase#parseCache(String, int) with "mocked" data
   * @param base
   */
  @MediumTest
  public void testParseCache() {
    List<MockedCache> cachesToTest = new ArrayList<MockedCache>();
    cachesToTest.add(new GC2CJPF());
    cachesToTest.add(new GC1ZXX2());

    for (MockedCache cache : cachesToTest) {
      cgCacheWrap caches = base.parseCache(cache.getData(), 0);
      cgCache cacheParsed = caches.cacheList.get(0);
      Assert.assertEquals(cacheParsed.getGeocode(), cache.getGeocode());
      Assert.assertEquals(cacheParsed.getType(), cache.getType());
      Assert.assertEquals(cacheParsed.getOwner(), cache.getOwner());
      Assert.assertEquals(cacheParsed.getDifficulty(), cache.getDifficulty());
      Assert.assertEquals(cacheParsed.getTerrain(), cache.getTerrain());
      Assert.assertEquals(cacheParsed.getLatitude(), cache.getLatitude());
      Assert.assertEquals(cacheParsed.getLongitude(), cache.getLongitude());
      Assert.assertEquals(cacheParsed.isDisabled(), cache.isDisabled());
      Assert.assertEquals(cacheParsed.isOwn(), cache.isOwn());
      Assert.assertEquals(cacheParsed.isArchived(), cache.isArchived());
      Assert.assertEquals(cacheParsed.isMembersOnly(), cache.isMembersOnly());
      Assert.assertEquals(cacheParsed.getOwnerReal(), cache.getOwnerReal());
      Assert.assertEquals(cacheParsed.getSize(), cache.getSize());
      Assert.assertEquals(cacheParsed.getHint(), cache.getHint());
      Assert.assertTrue(cacheParsed.getDescription().startsWith(cache.getDescription()));
      Assert.assertEquals(cacheParsed.getShortDescription(), cache.getShortDescription());
      Assert.assertEquals(cacheParsed.getName(), cache.getName());
    }
  }
 /** Test cache parsing. Esp. useful after a GC.com update */
 public static void testSearchByGeocodeBasis() {
   for (MockedCache mockedCache : RegExPerformanceTest.MOCKED_CACHES) {
     mockedCache.setMockedDataUser(Settings.getUsername());
     cgCache parsedCache = cgeoApplicationTest.testSearchByGeocode(mockedCache.getGeocode());
     if (null != parsedCache) {
       cgBaseTest.testCompareCaches(mockedCache, parsedCache);
     }
   }
 }
  /** Test {@link cgBase#searchByGeocode(String, String, int, boolean, CancellableHandler)} */
  @MediumTest
  public static void testSearchByGeocodeNotLoggedIn() {
    ImmutablePair<String, String> login = Settings.getLogin();

    try {
      // non premium cache
      MockedCache cache = new GC1ZXX2();

      deleteCacheFromDBAndLogout(cache.getGeocode());

      SearchResult search =
          cgBase.searchByGeocode(
              cache.getGeocode(), null, StoredList.TEMPORARY_LIST_ID, true, null);
      assertNotNull(search);
      assertEquals(1, search.getGeocodes().size());
      assertTrue(search.getGeocodes().contains(cache.getGeocode()));
      cgCache searchedCache = search.getFirstCacheFromResult(LoadFlags.LOADCACHEORDB);
      // coords must be null if the user is not logged in
      assertNull(searchedCache.getCoords());

      // premium cache. Not visible to guests
      cache = new GC2JVEH();

      deleteCacheFromDBAndLogout(cache.getGeocode());

      search =
          cgBase.searchByGeocode(
              cache.getGeocode(), null, StoredList.TEMPORARY_LIST_ID, true, null);
      assertNotNull(search);
      assertEquals(0, search.getGeocodes().size());

    } finally {
      // restore user and password
      Settings.setLogin(login.left, login.right);
      cgBase.login();
    }
  }
  /** Test {@link cgBase#searchByViewport(String, Viewport)} */
  @MediumTest
  public static void testSearchByViewportNotLoggedIn() {

    if (LIVEMAPENABLED) {
      ImmutablePair<String, String> login = Settings.getLogin();

      try {

        final String token = null; // without a valid token we are "logged off"

        // non premium cache
        MockedCache cache = new GC2CJPF();
        deleteCacheFromDBAndLogout(cache.getGeocode());

        Viewport viewport = new Viewport(cache.getCoords(), 0.003, 0.003);
        SearchResult search = cgBase.searchByViewport(token, viewport);

        assertNotNull(search);
        assertTrue(search.getGeocodes().contains(cache.getGeocode()));
        // coords differ
        Log.d(
            Settings.tag,
            "cgeoApplicationTest.testSearchByViewportNotLoggedIn: Coords expected = "
                + cache.getCoords());
        Log.d(
            Settings.tag,
            "cgeoApplicationTest.testSearchByViewportNotLoggedIn: Coords actual = "
                + cgeoapplication
                    .getInstance()
                    .loadCache(cache.getGeocode(), LoadFlags.LOADCACHEORDB)
                    .getCoords());
        assertFalse(
            cache
                .getCoords()
                .isEqualTo(
                    cgeoapplication
                        .getInstance()
                        .loadCache(cache.getGeocode(), LoadFlags.LOADCACHEORDB)
                        .getCoords(),
                    1e-3));
        assertFalse(
            cgeoapplication
                .getInstance()
                .loadCache(cache.getGeocode(), LoadFlags.LOADCACHEORDB)
                .isReliableLatLon());

        // premium cache
        cache = new GC2JVEH();
        deleteCacheFromDBAndLogout(cache.getGeocode());

        viewport = new Viewport(cache.getCoords(), 0.003, 0.003);
        search = cgBase.searchByViewport(token, viewport);

        assertNotNull(search);
        // It's a premium member cache only and thus not visible to guests
        assertFalse(search.getGeocodes().contains(cache.getGeocode()));

      } finally {
        // restore user and password
        Settings.setLogin(login.left, login.right);
        cgBase.login();
      }
    }
  }