From 55c4d8066a9e0e3e7b86030057da6733721a6d03 Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Sat, 22 Dec 2012 08:30:36 +0100 Subject: fix #2282: change recognition of unpublished caches --- .../cgeo/geocaching/connector/gc/GCConstants.java | 3 +- .../src/cgeo/geocaching/connector/gc/GCParser.java | 2 +- tests/res/raw/gc430fm_published.html | 2245 +++++++++++++++++++ tests/res/raw/gc431f2_published.html | 2248 ++++++++++++++++++++ tests/res/raw/gc433yc_owner_unpublished.html | 2188 +++++++++++++++++++ .../cgeo/geocaching/connector/gc/GCParserTest.java | 32 +- 6 files changed, 6714 insertions(+), 4 deletions(-) create mode 100644 tests/res/raw/gc430fm_published.html create mode 100644 tests/res/raw/gc431f2_published.html create mode 100644 tests/res/raw/gc433yc_owner_unpublished.html diff --git a/main/src/cgeo/geocaching/connector/gc/GCConstants.java b/main/src/cgeo/geocaching/connector/gc/GCConstants.java index de6a4d8..ca6883c 100644 --- a/main/src/cgeo/geocaching/connector/gc/GCConstants.java +++ b/main/src/cgeo/geocaching/connector/gc/GCConstants.java @@ -165,8 +165,9 @@ public final class GCConstants { public final static String STRING_PREMIUMONLY_2 = "Sorry, the owner of this listing has made it viewable to Premium Members only."; public final static String STRING_PREMIUMONLY_1 = "has chosen to make this cache listing visible to Premium Members only."; - public final static String STRING_UNPUBLISHED_OWNER = "Cache is Unpublished"; + public final static String STRING_UNPUBLISHED_OWNER = "cache has not been published yet"; public final static String STRING_UNPUBLISHED_OTHER = "you cannot view this cache listing until it has been published"; + public final static String STRING_UNPUBLISHED_FROM_SEARCH = "UnpublishedCacheSearchWidget"; public final static String STRING_UNKNOWN_ERROR = "An Error Has Occurred"; public final static String STRING_DISABLED = "
  • This cache is temporarily unavailable."; public final static String STRING_ARCHIVED = "
  • This cache has been archived,"; diff --git a/main/src/cgeo/geocaching/connector/gc/GCParser.java b/main/src/cgeo/geocaching/connector/gc/GCParser.java index 588ca1b..d2896bd 100644 --- a/main/src/cgeo/geocaching/connector/gc/GCParser.java +++ b/main/src/cgeo/geocaching/connector/gc/GCParser.java @@ -334,7 +334,7 @@ public abstract class GCParser { final SearchResult searchResult = new SearchResult(); - if (page.contains(GCConstants.STRING_UNPUBLISHED_OTHER) || page.contains(GCConstants.STRING_UNPUBLISHED_OWNER)) { + if (page.contains(GCConstants.STRING_UNPUBLISHED_OTHER) || page.contains(GCConstants.STRING_UNPUBLISHED_OWNER) || page.contains(GCConstants.STRING_UNPUBLISHED_FROM_SEARCH)) { searchResult.setError(StatusCode.UNPUBLISHED_CACHE); return searchResult; } diff --git a/tests/res/raw/gc430fm_published.html b/tests/res/raw/gc430fm_published.html new file mode 100644 index 0000000..6d7d728 --- /dev/null +++ b/tests/res/raw/gc430fm_published.html @@ -0,0 +1,2245 @@ + + + + + + + GC430FM Cache is Unpublished (Unknown Cache) in California, United States created by The North Star + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + + +
    + + + + + + + + + + + + + + + + + +
    + + +
    + + + + + + + + +
    + +

    + Geocaching.com

    +
    + +
    + +
    + +
    + +

    + Geocaching

    +
    + +
    + +

    Welcome, Visitor!

    +

    + Login with Facebook

    + +
    + +

    Sign In with Geocaching

    + +

    +
    + + +

    +

    +
    + + +

    +

    +
    + + Uncheck if on a shared computer. +

    +

    + + or + Close

    +

    + + Forgot your username or password?

    + +
    + + +
    + + + + +
    + + + + +
    + + +
    +
    + + +
    + + + +
    + + + + + +
    + + + x +
    + + +
    + +
    +

    + Unknown Cache +

    + +

    + Cache is Unpublished

    +
    +
    + A cache by The North Star
    +
    + Hidden: + 12/19/2012 + +
    +
    In California, United States
    +
    +
    +
    + + Difficulty: +
    + Terrain: + +
    + +
    + + 4 out of 5 + 1.5 out of 5 + +
    + +
    + +

    + Size: Size: micro (micro)

    + +
    + + + +
    + + + +
    + + +
    +
    + + Join now to view geocache location details. It's free! + + +
    +
    +
    +
    + +

    + Watch +

    + How Geocaching Works +
    +
    +
    + +
    +
    + +
    + + +

    +

    + + + + + + +
    + + Please note + +

    + Use of geocaching.com services is subject to the terms and conditions in our disclaimer. +

    +
    + + +
    + + + + +
    + +
    +
    + +
    +

    The cache is not at the posted coordinates but is less than 2 miles away

    +

    I obtained a Geocache waypoint (GC#) on 02/12/12 for a cache that was not published. Find the name of the unpublished cache and you will find the coordinates for this cache.
    +
    +The waypoint starts with GC3C and contains 2 additional letters and 1 additional number. Per GC.com Base 31 implementation, the letters ILOSU (US OIL or LOUIS) are not used.
    +
    +I’m not sure if this is a bug or a feature of Recently Viewed Caches, so it’s entirely possible that this puzzle will be unsolvable or not as easily solved in the future. So solve it and grab it while you can!
    +
    +Thanks to Chrysalides for planting the seed ;)
    +
    +There is room for very small trade and signature items. Don't forget to bring your pen.
    +
    +Enjoy!
    +
    +You can validate your puzzle solution with certitude or see who solved this puzzle.
    +
    +Congratulations to TeamOttlet on FTS and FTF.

    +
    + +
    + +

    + + +

    +

    + + Additional Hints + (Decrypt)

    +
    + Qvq lbh xabj gung lbh pna svaq n yvfg bs Erpragyl Ivrjrq Pnpurf haqre Lbhe Cebsvyr? “Ivrj Nyy” gb frr gur ynfg 50 pnpurf gung lbh unir ivrjrq…
    +
    +

    Decryption Key

    A|B|C|D|E|F|G|H|I|J|K|L|M
    -------------------------
    N|O|P|Q|R|S|T|U|V|W|X|Y|Z

    (letter above equals below, and vice versa)

    +
    +
    +
    + +
    + + +
    + + +
    + +

    + Navigation +

    + + + +
    + + + + + + + +
    + +

    + Attributes

    + + +
    + + +
    + +
    + +

    + +

    +

    + Advertising with Us

    + +
    + +
    + + + + +
    +
    + + + + +
    + +

    + Inventory +

    +
    + + +
    + +

    There are no Trackables in this cache.

    + +
    + + + +
    + + +
    + + +
    + +

    Bookmark Lists

    + + + +
    + + + + + +
    + + +
    + +

    +   +
    + + +

    + + + +

    + Find... +
    + +

    +
      +
    • + ...other caches  + hidden  + or  + found  + by this user +
    • + + +
    • + ...nearby Hotels +
    • +
    +

    + +

    + + + +

    + +

    + +
    +

    + 7 Logged Visits

    + +

    Found it 4     Write note 2     Publish Listing 1     

    +

    + View Logbook +

    +

    + **Warning! Spoilers may be included in the descriptions or links. +

    +
    + +
    + + + + + + + + +
    + + +
    +
    +

    + + Current Time:
    Last Updated: on 12/21/2012 3:06:00 AM (UTC-08:00) Pacific Time (US & Canada) (11:06 AM GMT)
    Rendered From:Unknown
    Coordinates are in the WGS84 datum +
    +

    + + +
    + + + + + + + + + + +
    + + + + +
    + + +
    + + + + + + + + + + + + + + +
    + + + + + + + + + + + +
    + + + +
    + + + + + diff --git a/tests/res/raw/gc431f2_published.html b/tests/res/raw/gc431f2_published.html new file mode 100644 index 0000000..869c0f8 --- /dev/null +++ b/tests/res/raw/gc431f2_published.html @@ -0,0 +1,2248 @@ + + + + + + + GC431F2 Needle in a Haystack (Unknown Cache) in California, United States created by The North Star + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + + +
    + + + + + + + + + + + + + + + + + +
    + + +
    + + + + + + + + +
    + +

    + Geocaching.com

    +
    + +
    + +
    + +
    + +

    + Geocaching

    +
    + +
    + +

    Welcome, Visitor!

    +

    + Login with Facebook

    + +
    + +

    Sign In with Geocaching

    + +

    +
    + + +

    +

    +
    + + +

    +

    +
    + + Uncheck if on a shared computer. +

    +

    + + or + Close

    +

    + + Forgot your username or password?

    + +
    + + +
    + + + + +
    + + + + +
    + + +
    +
    + + +
    + + + +
    + + + + + +
    + + + x +
    + + +
    + +
    +

    + Unknown Cache +

    + +

    + Needle in a Haystack

    +
    +
    + A cache by The North Star
    +
    + Hidden: + 12/21/2012 + +
    +
    In California, United States
    +
    +
    +
    + + Difficulty: +
    + Terrain: + +
    + +
    + + 3 out of 5 + 1.5 out of 5 + +
    + +
    + +

    + Size: Size: other (other)

    + +
    + + + +
    + + + +
    + + +
    +
    + + Join now to view geocache location details. It's free! + + +
    +
    +
    +
    + +

    + Watch +

    + How Geocaching Works +
    +
    +
    + +
    +
    + +
    + + +

    +

    + + + + + + +
    + + Please note + +

    + Use of geocaching.com services is subject to the terms and conditions in our disclaimer. +

    +
    + + +
    + + + + +
    + +
    +
    + +
    +

    The cache is not at the posted coordinates but is less than 2 miles away

    +

    Cache is Unpublished is a little like looking for a Needle in a Haystack. The “Needle” should be easier to find in this Haystack.
    +
    +Cache is "sign" only. Don't forget to bring your pen.
    +
    +Enjoy!
    +
    +You can validate your puzzle solution with Certitude or see who solved this puzzle.
    +
    +Congratulations to fmoraes on FTS and TeamOttlet on FTF. That's two The North Star FTF's in a row!

    +
    + +
    + +

    + + +

    +

    + + Additional Hints + (No hints available.)

    +
    +
    +
    + +
    +
    +
    + +
    + + +
    + + +
    + +

    + Navigation +

    + + + +
    + + + + + + + +
    + +

    + Attributes

    + + +
    + + +
    + +
    + +

    + +

    +

    + Advertising with Us

    + +
    + +
    + + + + +
    +
    + + + + +
    + +

    + Inventory +

    +
    + + +
    + +

    There are no Trackables in this cache.

    + +
    + + + +
    + + +
    + + +
    + +

    Bookmark Lists

    + + + +
    + + + + + +
    + + +
    + +

    +   +
    + + +

    + + + +

    + Find... +
    + +

    +
      +
    • + ...other caches  + hidden  + or  + found  + by this user +
    • + + +
    • + ...nearby Hotels +
    • +
    +

    + +

    + + + +

    + +

    + +
    +

    + 2 Logged Visits

    + +

    Found it 1     Publish Listing 1     

    +

    + View Logbook +

    +

    + **Warning! Spoilers may be included in the descriptions or links. +

    +
    + +
    + + + + + + + + +
    + + +
    +
    +

    + + Current Time:
    Last Updated: on 12/21/2012 8:59:00 AM (UTC-08:00) Pacific Time (US & Canada) (4:59 PM GMT)
    Rendered From:Unknown
    Coordinates are in the WGS84 datum +
    +

    + + +
    + + + + + + + + + + +
    + + + + +
    + + +
    + + + + + + + + + + + + + + +
    + + + + + + + + + + + +
    + + + +
    + + + + + diff --git a/tests/res/raw/gc433yc_owner_unpublished.html b/tests/res/raw/gc433yc_owner_unpublished.html new file mode 100644 index 0000000..aa144b0 --- /dev/null +++ b/tests/res/raw/gc433yc_owner_unpublished.html @@ -0,0 +1,2188 @@ + + + + + + GC433YC Stenarna (Earthcache) in Södermanland, Sweden created by ra_sch + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + + +
    + + + + + + + + + + + + + + + + + + + + + +
    + +

    + Geocaching.com

    +
    + +
    + +
    + +
    + +

    + Geocaching

    +
    + + + +
    + +

    +

    +

    + + Hello, ra_sch (Sign Out)
    + Premium Member + + + 957 Caches Found + +

    + +
    + + +
    + + + + +
    + + +
    +
    + + +
    + + + +
    + + + + + +
    + + + x +
    + + +
    + +
    +

    + Earthcache +

    + +

    + Stenarna

    +
    +
    + A cache by ra_sch
    +
    + Hidden: + 12/21/2012 + +
    +
    +
    +
    +
    + + Difficulty: +
    + Terrain: + +
    + +
    + + 1.5 out of 5 + 1.5 out of 5 + +
    + +
    + +

    + Size: Size: not chosen (not chosen)

    Durchschnitt (Mittel) 0.0 von 5 (0)

    + +
    + + + +
    + + + + + +
    + + +

    +

    + + + + +
    +
    +
    +

    + + N 58° 48.021 E 017° 48.603 + +
    + + UTM: 33V E 662347 N 6521227 +
    +
    + Other Conversions + +

    +
    +
    + In Södermanland, Sweden
    + NE NE 1170.9 km from your home location +
    +
    +
    +

    + Print: +
    + + + Print  + No Logs + +   + 5 Logs  + 10 Logs ·  + + Driving Directions  + Driving Directions + +

    + +
    +
    +

    + Download: + + Read about waypoint downloads + +

    + +

    + + | + + | + + | + + |

    + +
    +
    GCTour
    + +
    + + Please note + +

    + Use of geocaching.com services is subject to the terms and conditions in our disclaimer. +

    +
    + + +
    + + Personal Cache Note + + +

    Click to enter a note

    +
    + +
    + + Test + + +
    + +
    +
    + + Test + +
    + +

    + + +

    +

    + + Additional Hints + (No hints available.)

    +
    +
    +
    + +
    +
    +
    + +
    + + +
    + + + + + + + + + + + + +
    + +

    + Attributes

    + + +
    + + +
    + +
    + +

    + +

    +

    + Advertising with Us

    + +
    + +
    + + + + +
    +
    + + + + +
    + +

    + Inventory +

    + + + +
    + + + + +
    + + +
    + +

    + Additional Waypoints (Add / Edit waypoints) +
    + No additional waypoints to display. + +

    + +
    + +
    +
    + +
    +
    + To print the map in Firefox and Opera, enable background images in the print dialog. + + Close + +
    +
    + +
    + +

    + Find... +
    + +

    + +

    + For online maps... +

    + + + + + +

    + +

    + +
    +

    + 1 Logged Visit

    +
    + Decrypt +
    +

    Post Reviewer Note 1     

    +

    + View Logbook +

    +

    + **Warning! Spoilers may be included in the descriptions or links. +

    +
    + +
    + + + + + + + + +

    ra_sch

    Premium Member

    957

    Post Reviewer Note Post Reviewer Note
    12/21/2012
    +
    + Loading + Loading Cache Logs... +
    + +
    +
    +

    + + Current Time:
    Last Updated: on 12/21/2012 11:14:41 (UTC-08:00) Pacific Time (US & Canada) (19:14 GMT)
    Last Found: Never
    This cache has not been published yet.
    Rendered From:Unknown
    Coordinates are in the WGS84 datum +
    +

    + + +
    + + + + + + + + + + +
    + + + + +
    + + +
    + + + + + + + + +
    + + + + + + + + + + + +
    + + + +
    + + + + + +
    New TourLoad a tourDownload TourautoTourShow settingsSend a message to the author.
    Tour 2 (0)
    RenamePrintviewSend to GPSDownload GPXView on mapUpload tourAdd own waypointDelete this tour
      The list is empty.
    \ No newline at end of file diff --git a/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java b/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java index 5323db7..dd71302 100644 --- a/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java +++ b/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java @@ -24,14 +24,42 @@ import android.test.suitebuilder.annotation.MediumTest; import java.util.ArrayList; public class GCParserTest extends AbstractResourceInstrumentationTestCase { - public void testUnpublishedCache() { - final String page = getFileContent(R.raw.cache_unpublished); + + public void testUnpublishedCacheNotOwner() { + final int cache = R.raw.cache_unpublished; + assertUnpublished(cache); + } + + public void testUnpublishedCacheOwner() { + final int cache = R.raw.gc433yc_owner_unpublished; + assertUnpublished(cache); + } + + private void assertUnpublished(final int cache) { + final String page = getFileContent(cache); SearchResult result = GCParser.parseCacheFromText(page, null); assertNotNull(result); assertTrue(result.isEmpty()); assertEquals(StatusCode.UNPUBLISHED_CACHE, result.getError()); } + public void testPublishedCacheWithUnpublishedInDescription1() { + assertPublishedCache(R.raw.gc430fm_published, "Cache is Unpublished"); + } + + public void testPublishedCacheWithUnpublishedInDescription2() { + assertPublishedCache(R.raw.gc431f2_published, "Needle in a Haystack"); + } + + private void assertPublishedCache(final int cachePage, final String cacheName) { + final String page = getFileContent(cachePage); + SearchResult result = GCParser.parseCacheFromText(page, null); + assertNotNull(result); + assertEquals(1, result.getCount()); + cgCache cache = result.getFirstCacheFromResult(LoadFlags.LOAD_CACHE_OR_DB); + assertEquals(cacheName, cache.getName()); + } + public void testOwnCache() { final cgCache cache = parseCache(R.raw.own_cache); assertNotNull(cache); -- cgit v1.1