diff options
Diffstat (limited to 'tests')
17 files changed, 197 insertions, 65 deletions
diff --git a/tests/lint.xml b/tests/lint.xml new file mode 100644 index 0000000..8e1c48c --- /dev/null +++ b/tests/lint.xml @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="UTF-8"?> +<lint> + <issue id="IconMissingDensityFolder" severity="ignore" /> +</lint>
\ No newline at end of file diff --git a/tests/proguard-project.txt b/tests/proguard-project.txt index f0b04dc..20b2222 100644 --- a/tests/proguard-project.txt +++ b/tests/proguard-project.txt @@ -1,40 +1,20 @@ --optimizationpasses 5
--dontusemixedcaseclassnames
--dontskipnonpubliclibraryclasses
--dontpreverify
--verbose
--optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
+# To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
--keep public class * extends android.app.Activity
--keep public class * extends android.app.Application
--keep public class * extends android.app.Service
--keep public class * extends android.content.BroadcastReceiver
--keep public class * extends android.content.ContentProvider
--keep public class * extends android.app.backup.BackupAgentHelper
--keep public class * extends android.preference.Preference
--keep public class com.android.vending.licensing.ILicensingService
+# Add any project specific keep options here:
--keepclasseswithmembernames class * {
- native <methods>;
-}
-
--keepclasseswithmembers class * {
- public <init>(android.content.Context, android.util.AttributeSet);
-}
-
--keepclasseswithmembers class * {
- public <init>(android.content.Context, android.util.AttributeSet, int);
-}
-
--keepclassmembers class * extends android.app.Activity {
- public void *(android.view.View);
-}
-
--keepclassmembers enum * {
- public static **[] values();
- public static ** valueOf(java.lang.String);
-}
-
--keep class * implements android.os.Parcelable {
- public static final android.os.Parcelable$Creator *;
-}
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
\ No newline at end of file diff --git a/tests/src/cgeo/geocaching/CgeoApplicationTest.java b/tests/src/cgeo/geocaching/CgeoApplicationTest.java index 3e63481..bdde2b6 100644 --- a/tests/src/cgeo/geocaching/CgeoApplicationTest.java +++ b/tests/src/cgeo/geocaching/CgeoApplicationTest.java @@ -158,6 +158,7 @@ public class CgeoApplicationTest extends CGeoTestCase { public static void testSearchByGeocodeNotLoggedIn() { withMockedLoginDo(new Runnable() { + @Override public void run() { // non premium cache MockedCache cache = new GC2CJPF(); @@ -193,6 +194,7 @@ public class CgeoApplicationTest extends CGeoTestCase { public static void testSearchErrorOccured() { withMockedLoginDo(new Runnable() { + @Override public void run() { // non premium cache final MockedCache cache = new GC1ZXX2(); @@ -342,6 +344,7 @@ public class CgeoApplicationTest extends CGeoTestCase { public static void testSearchByViewportNotLoggedIn() { withMockedLoginDo(new Runnable() { + @Override public void run() { final Strategy strategy = Settings.getLiveMapStrategy(); final Strategy testStrategy = Strategy.FAST; // FASTEST, FAST or DETAILED for tests diff --git a/tests/src/cgeo/geocaching/StaticMapsProviderTest.java b/tests/src/cgeo/geocaching/StaticMapsProviderTest.java index 02c6660..42ad2c5 100644 --- a/tests/src/cgeo/geocaching/StaticMapsProviderTest.java +++ b/tests/src/cgeo/geocaching/StaticMapsProviderTest.java @@ -7,13 +7,14 @@ import cgeo.geocaching.files.LocalStorage; import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.settings.Settings; import cgeo.geocaching.settings.TestSettings; +import cgeo.geocaching.utils.RxUtils; + +import junit.framework.TestCase; import android.test.suitebuilder.annotation.Suppress; import java.io.File; -import junit.framework.TestCase; - @Suppress public class StaticMapsProviderTest extends TestCase { @@ -52,7 +53,7 @@ public class StaticMapsProviderTest extends TestCase { assertThat(StaticMapsProvider.hasStaticMapForWaypoint(geocode, trailhead)).isFalse(); // download - StaticMapsProvider.downloadMaps(cache); + RxUtils.waitForCompletion(StaticMapsProvider.downloadMaps(cache)); try { Thread.sleep(10000); diff --git a/tests/src/cgeo/geocaching/apps/cache/WhereYouGoAppTest.java b/tests/src/cgeo/geocaching/apps/cache/WhereYouGoAppTest.java new file mode 100644 index 0000000..5290c35 --- /dev/null +++ b/tests/src/cgeo/geocaching/apps/cache/WhereYouGoAppTest.java @@ -0,0 +1,15 @@ +package cgeo.geocaching.apps.cache; + +import static org.assertj.core.api.Assertions.assertThat; + +import cgeo.geocaching.Geocache; + +import junit.framework.TestCase; + +public class WhereYouGoAppTest extends TestCase { + public static void testGetWhereIGoUrl() throws Exception { + Geocache cache = new Geocache(); + cache.setDescription("<p style=\"max-width:670px;\"><a href=\"http://www.wherigo.com/cartridge/details.aspx?CGUID=c4577c31-09e9-44f0-ae48-83737e57adbd\"><img class=\"InsideTable\""); + assertThat(WhereYouGoApp.getWhereIGoUrl(cache)).isEqualTo("http://www.wherigo.com/cartridge/details.aspx?CGUID=c4577c31-09e9-44f0-ae48-83737e57adbd"); + } +} diff --git a/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java b/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java index 2897b54..1c64568 100644 --- a/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java +++ b/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java @@ -36,7 +36,7 @@ public class GCParserTest extends AbstractResourceInstrumentationTestCase { private void assertUnpublished(final int cache) { final String page = getFileContent(cache); - final SearchResult result = GCParser.parseCacheFromText(page, null); + final SearchResult result = GCParser.parseAndSaveCacheFromText(page, null); assertThat(result).isNotNull(); assertThat(result.isEmpty()).isTrue(); assertThat(result.getError()).isEqualTo(StatusCode.UNPUBLISHED_CACHE); @@ -52,7 +52,7 @@ public class GCParserTest extends AbstractResourceInstrumentationTestCase { private void assertPublishedCache(final int cachePage, final String cacheName) { final String page = getFileContent(cachePage); - final SearchResult result = GCParser.parseCacheFromText(page, null); + final SearchResult result = GCParser.parseAndSaveCacheFromText(page, null); assertThat(result).isNotNull(); assertThat(result.getCount()).isEqualTo(1); final Geocache cache = result.getFirstCacheFromResult(LoadFlags.LOAD_CACHE_OR_DB); @@ -79,7 +79,7 @@ public class GCParserTest extends AbstractResourceInstrumentationTestCase { final SearchResult searchResult; try { Settings.setGcCustomDate(MockedCache.getDateFormat()); - searchResult = GCParser.parseCacheFromText(mockedCache.getData(), null); + searchResult = GCParser.parseAndSaveCacheFromText(mockedCache.getData(), null); } finally { Settings.setGcCustomDate(oldCustomDate); } @@ -103,7 +103,7 @@ public class GCParserTest extends AbstractResourceInstrumentationTestCase { for (MockedCache mockedCache : RegExPerformanceTest.MOCKED_CACHES) { // to get the same results we have to use the date format used when the mocked data was created Settings.setGcCustomDate(MockedCache.getDateFormat()); - SearchResult searchResult = GCParser.parseCacheFromText(mockedCache.getData(), null); + SearchResult searchResult = GCParser.parseAndSaveCacheFromText(mockedCache.getData(), null); Geocache parsedCache = searchResult.getFirstCacheFromResult(LoadFlags.LOAD_CACHE_OR_DB); assertThat(StringUtils.isNotBlank(mockedCache.getMockedDataUser())).isTrue(); Compare.assertCompareCaches(mockedCache, parsedCache, true); @@ -158,7 +158,7 @@ public class GCParserTest extends AbstractResourceInstrumentationTestCase { GCParser.editModifiedCoordinates(cache, new Geopoint("N51 21.544", "E07 02.566")); cache.dropSynchronous(); final String page = GCParser.requestHtmlPage(cache.getGeocode(), null, "n", "0"); - final Geocache cache2 = GCParser.parseCacheFromText(page, null).getFirstCacheFromResult(LoadFlags.LOAD_CACHE_ONLY); + final Geocache cache2 = GCParser.parseAndSaveCacheFromText(page, null).getFirstCacheFromResult(LoadFlags.LOAD_CACHE_ONLY); assertThat(cache2).isNotNull(); assert (cache2 != null); // eclipse bug assertThat(cache2.hasUserModifiedCoords()).isTrue(); @@ -167,7 +167,7 @@ public class GCParserTest extends AbstractResourceInstrumentationTestCase { GCParser.deleteModifiedCoordinates(cache2); cache2.dropSynchronous(); final String page2 = GCParser.requestHtmlPage(cache.getGeocode(), null, "n", "0"); - final Geocache cache3 = GCParser.parseCacheFromText(page2, null).getFirstCacheFromResult(LoadFlags.LOAD_CACHE_ONLY); + final Geocache cache3 = GCParser.parseAndSaveCacheFromText(page2, null).getFirstCacheFromResult(LoadFlags.LOAD_CACHE_ONLY); assertThat(cache3).isNotNull(); assert (cache3 != null); // eclipse bug assertThat(cache3.hasUserModifiedCoords()).isFalse(); @@ -210,7 +210,7 @@ public class GCParserTest extends AbstractResourceInstrumentationTestCase { private Geocache parseCache(int resourceId) { final String page = getFileContent(resourceId); - final SearchResult result = GCParser.parseCacheFromText(page, null); + final SearchResult result = GCParser.parseAndSaveCacheFromText(page, null); assertThat(result).isNotNull(); assertThat(result.isEmpty()).isFalse(); return result.getFirstCacheFromResult(LoadFlags.LOAD_CACHE_OR_DB); diff --git a/tests/src/cgeo/geocaching/connector/oc/OkapiClientTest.java b/tests/src/cgeo/geocaching/connector/oc/OkapiClientTest.java index 05d676b..0c65d87 100644 --- a/tests/src/cgeo/geocaching/connector/oc/OkapiClientTest.java +++ b/tests/src/cgeo/geocaching/connector/oc/OkapiClientTest.java @@ -22,6 +22,8 @@ public class OkapiClientTest extends CGeoTestCase { assertThat(cache.getGeocode()).isEqualTo(geoCode); assertThat(cache.getName()).isEqualTo("Oshkosh Municipal Tank"); assertThat(cache.isDetailed()).isTrue(); + assertThat(cache.getOwnerDisplayName()).isNotEmpty(); + assertThat(cache.getOwnerUserId()).isEqualTo(cache.getOwnerDisplayName()); } public static void testOCSearchMustWorkWithoutOAuthAccessTokens() { @@ -42,7 +44,7 @@ public class OkapiClientTest extends CGeoTestCase { assertThat(cache.getWaypoints()).hasSize(3); // load again - cache.refreshSynchronous(cache.getListId(), null); + cache.refreshSynchronous(null); assertThat(cache.getWaypoints()).hasSize(3); } diff --git a/tests/src/cgeo/geocaching/export/ExportTest.java b/tests/src/cgeo/geocaching/export/ExportTest.java index a9fceec..848a1f7 100644 --- a/tests/src/cgeo/geocaching/export/ExportTest.java +++ b/tests/src/cgeo/geocaching/export/ExportTest.java @@ -52,10 +52,6 @@ public class ExportTest extends CGeoTestCase { private static class GpxExportTester extends GpxExport { - protected GpxExportTester() { - super(); - } - public File testExportSync(List<Geocache> caches) throws InterruptedException, ExecutionException { final ArrayList<String> geocodes = new ArrayList<String>(caches.size()); for (final Geocache cache : caches) { diff --git a/tests/src/cgeo/geocaching/files/FileTypeDetectorTest.java b/tests/src/cgeo/geocaching/files/FileTypeDetectorTest.java new file mode 100644 index 0000000..5dbf3c2 --- /dev/null +++ b/tests/src/cgeo/geocaching/files/FileTypeDetectorTest.java @@ -0,0 +1,52 @@ +package cgeo.geocaching.files; + +import static org.assertj.core.api.Assertions.assertThat; + +import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase; +import cgeo.geocaching.test.R; + +import org.eclipse.jdt.annotation.NonNull; + +import android.content.ContentResolver; +import android.content.Context; +import android.net.Uri; + +public class FileTypeDetectorTest extends AbstractResourceInstrumentationTestCase { + + private static class FileContentResolver extends ContentResolver { + + public FileContentResolver(Context context) { + super(context); + } + } + + public void testUnknown() throws Exception { + assertFileType(R.raw.gc2cjpf_html, FileType.UNKNOWN); + assertFileType(R.raw.map1, FileType.UNKNOWN); + } + + public void testLoc() throws Exception { + assertFileType(R.raw.gc1bkp3_loc, FileType.LOC); + assertFileType(R.raw.oc5952_loc, FileType.LOC); + assertFileType(R.raw.waymarking_loc, FileType.LOC); + } + + public void testGpx() throws Exception { + assertFileType(R.raw.gc1bkp3_gpx100, FileType.GPX); + assertFileType(R.raw.gc1bkp3_gpx101, FileType.GPX); + assertFileType(R.raw.oc5952_gpx, FileType.GPX); + assertFileType(R.raw.renamed_waypoints_wpts, FileType.GPX); + assertFileType(R.raw.waymarking_gpx, FileType.GPX); + } + + public void testZip() throws Exception { + assertFileType(R.raw.pq_error, FileType.ZIP); + assertFileType(R.raw.pq7545915, FileType.ZIP); + } + + private void assertFileType(final int resourceId, final @NonNull FileType fileType) { + final Uri resourceURI = getResourceURI(resourceId); + final FileContentResolver contentResolver = new FileContentResolver(getInstrumentation().getContext()); + assertThat(new FileTypeDetector(resourceURI, contentResolver).getFileType()).isEqualTo(fileType); + } +} diff --git a/tests/src/cgeo/geocaching/files/GPXParserTest.java b/tests/src/cgeo/geocaching/files/GPXParserTest.java index bb91243..a463dd8 100644 --- a/tests/src/cgeo/geocaching/files/GPXParserTest.java +++ b/tests/src/cgeo/geocaching/files/GPXParserTest.java @@ -16,8 +16,6 @@ import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase; import cgeo.geocaching.test.R; import cgeo.geocaching.utils.SynchronizedDateFormat; -import org.apache.commons.lang3.StringUtils; - import java.io.IOException; import java.io.InputStream; import java.text.ParseException; @@ -320,7 +318,7 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase { assertThat(waymark).isNotNull(); assertThat(waymark.getGeocode()).isEqualTo("WM7BM7"); assertThat(waymark.getName()).isEqualTo("Roman water pipe Kornwestheim"); - assertThat(StringUtils.isNotBlank(waymark.getUrl())).isTrue(); // connector must be able to create it + assertThat(waymark.getUrl()).isNotEmpty(); // connector must be able to create it assertThat(waymark.getType()).isEqualTo(CacheType.UNKNOWN); assertThat(waymark.getSize()).isEqualTo(CacheSize.UNKNOWN); } diff --git a/tests/src/cgeo/geocaching/files/InvalidXMLCharacterFilterReaderTest.java b/tests/src/cgeo/geocaching/files/InvalidXMLCharacterFilterReaderTest.java index 0641b5d..515d8a6 100644 --- a/tests/src/cgeo/geocaching/files/InvalidXMLCharacterFilterReaderTest.java +++ b/tests/src/cgeo/geocaching/files/InvalidXMLCharacterFilterReaderTest.java @@ -17,6 +17,7 @@ public class InvalidXMLCharacterFilterReaderTest extends AndroidTestCase { final AtomicReference<String> description = new AtomicReference<String>(); root.setEndTextElementListener(new EndTextElementListener() { + @Override public void end(String body) { description.set(body); } diff --git a/tests/src/cgeo/geocaching/filter/StateNotFoundFilterTest.java b/tests/src/cgeo/geocaching/filter/StateNotFoundFilterTest.java new file mode 100644 index 0000000..2bf9d94 --- /dev/null +++ b/tests/src/cgeo/geocaching/filter/StateNotFoundFilterTest.java @@ -0,0 +1,28 @@ +package cgeo.geocaching.filter; + +import static org.assertj.core.api.Assertions.assertThat; + +import cgeo.CGeoTestCase; +import cgeo.geocaching.Geocache; +import cgeo.geocaching.filter.StateFilter.StateNotFoundFilter; + +public class StateNotFoundFilterTest extends CGeoTestCase { + + private StateFilter.StateNotFoundFilter notFoundFilter; + private Geocache foundCache; + + @Override + protected void setUp() throws Exception { + super.setUp(); + + notFoundFilter = new StateNotFoundFilter(); + foundCache = new Geocache(); + foundCache.setFound(true); + } + + public void testAccepts() { + assertThat(notFoundFilter.accepts(foundCache)).isFalse(); + assertThat(notFoundFilter.accepts(new Geocache())).isTrue(); + } + +} diff --git a/tests/src/cgeo/geocaching/geopoint/UnitsTest.java b/tests/src/cgeo/geocaching/geopoint/UnitsTest.java index acc964a..f208984 100644 --- a/tests/src/cgeo/geocaching/geopoint/UnitsTest.java +++ b/tests/src/cgeo/geocaching/geopoint/UnitsTest.java @@ -51,13 +51,13 @@ public class UnitsTest extends CGeoTestCase { TestSettings.setUseImperialUnits(false); assertSpeed("123 km/h", 122.782f); assertSpeed("123 km/h", 123.456f); - assertSpeed("12.3 km/h", 12.3456f); - assertSpeed("1.23 km/h", 1.23456f); - assertSpeed("123 m/h", 0.123456f); + assertSpeed("12 km/h", 12.3456f); + assertSpeed("1 km/h", 1.23456f); + assertSpeed("0 km/h", 0.123456f); TestSettings.setUseImperialUnits(true); - assertSpeed("76.7 mph", 123.456f); - assertSpeed("7.67 mph", 12.3456f); - assertSpeed("0.77 mph", 1.23456f); + assertSpeed("77 mph", 123.456f); + assertSpeed("8 mph", 12.3456f); + assertSpeed("1 mph", 1.23456f); } finally { TestSettings.setUseImperialUnits(savedImperial); } diff --git a/tests/src/cgeo/geocaching/settings/TestSettings.java b/tests/src/cgeo/geocaching/settings/TestSettings.java index 2e6809f..279f658 100644 --- a/tests/src/cgeo/geocaching/settings/TestSettings.java +++ b/tests/src/cgeo/geocaching/settings/TestSettings.java @@ -48,4 +48,8 @@ public final class TestSettings extends Settings { putString(R.string.pref_twitter_trackable_message, template); } + public static void setSignature(final String signature) { + putString(R.string.pref_signature, signature); + } + } diff --git a/tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java b/tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java index df8dc1f..cbad794 100644 --- a/tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java +++ b/tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java @@ -12,7 +12,9 @@ import cgeo.geocaching.files.GPX10Parser; import cgeo.geocaching.files.ParserException; import cgeo.geocaching.list.StoredList; +import android.content.ContentResolver; import android.content.res.Resources; +import android.net.Uri; import android.test.InstrumentationTestCase; import java.io.File; @@ -102,4 +104,9 @@ public abstract class AbstractResourceInstrumentationTestCase extends Instrument instream.close(); } } + + protected Uri getResourceURI(int resId) { + Resources resources = getInstrumentation().getContext().getResources(); + return Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + resources.getResourcePackageName(resId) + '/' + resources.getResourceTypeName(resId) + '/' + resources.getResourceEntryName(resId)); + } } diff --git a/tests/src/cgeo/geocaching/test/mock/MockedCache.java b/tests/src/cgeo/geocaching/test/mock/MockedCache.java index d06e715..cd482f8 100644 --- a/tests/src/cgeo/geocaching/test/mock/MockedCache.java +++ b/tests/src/cgeo/geocaching/test/mock/MockedCache.java @@ -150,6 +150,7 @@ public abstract class MockedCache implements ICache { return getName(); } + @Override public Geopoint getCoords() { return coords; } diff --git a/tests/src/cgeo/geocaching/utils/LogTemplateProviderTest.java b/tests/src/cgeo/geocaching/utils/LogTemplateProviderTest.java index a7dcb2b..77832b0 100644 --- a/tests/src/cgeo/geocaching/utils/LogTemplateProviderTest.java +++ b/tests/src/cgeo/geocaching/utils/LogTemplateProviderTest.java @@ -2,6 +2,8 @@ package cgeo.geocaching.utils; import static org.assertj.core.api.Assertions.assertThat; +import cgeo.geocaching.settings.Settings; +import cgeo.geocaching.settings.TestSettings; import cgeo.geocaching.utils.LogTemplateProvider.LogContext; import java.util.Calendar; @@ -10,13 +12,51 @@ import junit.framework.TestCase; public class LogTemplateProviderTest extends TestCase { - public static void testApplyTemplates() { + public static void testApplyTemplatesNone() { final String noTemplates = " no templates "; - assertEquals(noTemplates, LogTemplateProvider.applyTemplates(noTemplates, new LogContext(null, null, true))); + final String signature = LogTemplateProvider.applyTemplates(noTemplates, new LogContext(null, null, true)); + assertThat(signature).isEqualTo(noTemplates); + } + public static void testApplyTemplates() { // This test can occasionally fail if the current year changes right after the next line. final String currentYear = Integer.toString(Calendar.YEAR); - assertThat(LogTemplateProvider.applyTemplates("[DATE]", new LogContext(null, null, true)).contains(currentYear)).isTrue(); + final String signature = LogTemplateProvider.applyTemplates("[DATE]", new LogContext(null, null, true)); + assertThat(signature).contains(currentYear); + } + + /** + * signature itself can contain templates, therefore nested applying is necessary + */ + public static void testApplySignature() { + String oldSignature = Settings.getSignature(); + try { + TestSettings.setSignature("[DATE]"); + String currentDate = LogTemplateProvider.applyTemplates(Settings.getSignature(), new LogContext(null, null, true)); + final String signatureTemplate = "Signature [SIGNATURE]"; + final String signature = LogTemplateProvider.applyTemplates(signatureTemplate, new LogContext(null, null, true)); + assertThat(signature).isEqualTo("Signature " + currentDate); + + final String currentYear = Integer.toString(Calendar.YEAR); + assertThat(signature).contains(currentYear); + } finally { + TestSettings.setSignature(oldSignature); + } + } + + /** + * signature must not contain itself as template + */ + public static void testApplyInvalidSignature() { + String oldSignature = Settings.getSignature(); + try { + final String signatureTemplate = "[SIGNATURE]"; + TestSettings.setSignature(signatureTemplate); + final String signature = LogTemplateProvider.applyTemplates(signatureTemplate, new LogContext(null, null, true)); + assertThat(signature).isEqualTo("invalid signature template"); + } finally { + TestSettings.setSignature(oldSignature); + } } } |
