@josuelmm/cordova-background-geolocation 2.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.npmignore +23 -0
- package/CHANGELOG.md +787 -0
- package/CONTRIBUTORS.md +15 -0
- package/HISTORY.md +734 -0
- package/LICENSE +191 -0
- package/README.md +125 -0
- package/RELEASE.MD +5 -0
- package/android/CDVBackgroundGeolocation/src/main/AndroidManifest.xml +23 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/evgenii/jsevaluator/HandlerWrapper.java +18 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/evgenii/jsevaluator/JavaScriptInterface.java +22 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/evgenii/jsevaluator/JsEvaluator.java +133 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/evgenii/jsevaluator/JsFunctionCallFormatter.java +37 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/evgenii/jsevaluator/WebViewWrapper.java +71 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/evgenii/jsevaluator/interfaces/CallJavaResultInterface.java +8 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/evgenii/jsevaluator/interfaces/HandlerWrapperInterface.java +5 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/evgenii/jsevaluator/interfaces/JsCallback.java +10 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/evgenii/jsevaluator/interfaces/JsEvaluatorInterface.java +18 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/evgenii/jsevaluator/interfaces/WebViewWrapperInterface.java +14 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/marianhello/bgloc/cordova/ConfigMapper.java +148 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/marianhello/bgloc/cordova/PluginRegistry.java +25 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/marianhello/bgloc/cordova/headless/JsEvaluatorTaskRunner.java +53 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/tenforwardconsulting/bgloc/cordova/BackgroundGeolocationPlugin.java +603 -0
- package/android/CDVBackgroundGeolocation/src/main/res/values/strings.xml +4 -0
- package/android/CDVBackgroundGeolocation/src/test/java/com/marianhello/ConfigMapperTest.java +208 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/BackgroundGeolocationFacadeTest.java +45 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/BatchManagerTest.java +570 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/ConfigTest.java +76 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/ContentProviderLocationDAOTest.java +437 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/DBLogReaderTest.java +95 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/LocationContentProviderTest.java +159 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/LocationServiceProxyTest.java +161 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/LocationServiceTest.java +247 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/SQLiteConfigurationDAOTest.java +200 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/SQLiteLocationDAOTest.java +457 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/SQLiteLocationDAOThreadTest.java +96 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/SQLiteOpenHelperTest.java +225 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/TestPluginDelegate.java +46 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/TestResourceResolver.java +14 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/provider/MockLocationProvider.java +50 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/provider/TestLocationProviderFactory.java +17 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/sqlite/SQLiteOpenHelper10.java +92 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/test/LocationProviderTestCase.java +107 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/test/TestConstants.java +5 -0
- package/android/common/src/main/AndroidManifest.xml +72 -0
- package/android/common/src/main/java/com/marianhello/bgloc/BackgroundGeolocationFacade.java +523 -0
- package/android/common/src/main/java/com/marianhello/bgloc/BootCompletedReceiver.java +59 -0
- package/android/common/src/main/java/com/marianhello/bgloc/Config.java +652 -0
- package/android/common/src/main/java/com/marianhello/bgloc/ConnectivityListener.java +5 -0
- package/android/common/src/main/java/com/marianhello/bgloc/HttpPostService.java +224 -0
- package/android/common/src/main/java/com/marianhello/bgloc/LocationManager.java +138 -0
- package/android/common/src/main/java/com/marianhello/bgloc/PluginDelegate.java +19 -0
- package/android/common/src/main/java/com/marianhello/bgloc/PluginException.java +38 -0
- package/android/common/src/main/java/com/marianhello/bgloc/PostLocationTask.java +188 -0
- package/android/common/src/main/java/com/marianhello/bgloc/ResourceResolver.java +55 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/AbstractLocationTemplate.java +69 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/ArrayListLocationTemplate.java +88 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/BackgroundActivity.java +108 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/BackgroundLocation.java +994 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/ConfigurationDAO.java +13 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/DAOFactory.java +17 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/HashMapLocationTemplate.java +82 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/LocationDAO.java +22 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/LocationTemplate.java +12 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/LocationTemplateFactory.java +65 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/LocationTransform.java +19 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/provider/ContentProviderLocationDAO.java +395 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/provider/LocationContentProvider.java +321 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteConfigurationContract.java +76 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteConfigurationDAO.java +160 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteLocationContract.java +112 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteLocationDAO.java +506 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteOpenHelper.java +151 -0
- package/android/common/src/main/java/com/marianhello/bgloc/headless/AbstractTaskRunner.java +15 -0
- package/android/common/src/main/java/com/marianhello/bgloc/headless/ActivityTask.java +48 -0
- package/android/common/src/main/java/com/marianhello/bgloc/headless/JsCallback.java +10 -0
- package/android/common/src/main/java/com/marianhello/bgloc/headless/LocationTask.java +60 -0
- package/android/common/src/main/java/com/marianhello/bgloc/headless/StationaryTask.java +25 -0
- package/android/common/src/main/java/com/marianhello/bgloc/headless/Task.java +8 -0
- package/android/common/src/main/java/com/marianhello/bgloc/headless/TaskRunner.java +5 -0
- package/android/common/src/main/java/com/marianhello/bgloc/headless/TaskRunnerFactory.java +8 -0
- package/android/common/src/main/java/com/marianhello/bgloc/provider/AbstractLocationProvider.java +171 -0
- package/android/common/src/main/java/com/marianhello/bgloc/provider/ActivityRecognitionLocationProvider.java +282 -0
- package/android/common/src/main/java/com/marianhello/bgloc/provider/DistanceFilterLocationProvider.java +610 -0
- package/android/common/src/main/java/com/marianhello/bgloc/provider/LocationProvider.java +32 -0
- package/android/common/src/main/java/com/marianhello/bgloc/provider/LocationProviderFactory.java +47 -0
- package/android/common/src/main/java/com/marianhello/bgloc/provider/ProviderDelegate.java +12 -0
- package/android/common/src/main/java/com/marianhello/bgloc/provider/RawLocationProvider.java +145 -0
- package/android/common/src/main/java/com/marianhello/bgloc/service/LocationService.java +16 -0
- package/android/common/src/main/java/com/marianhello/bgloc/service/LocationServiceImpl.java +749 -0
- package/android/common/src/main/java/com/marianhello/bgloc/service/LocationServiceInfo.java +6 -0
- package/android/common/src/main/java/com/marianhello/bgloc/service/LocationServiceInfoImpl.java +41 -0
- package/android/common/src/main/java/com/marianhello/bgloc/service/LocationServiceIntentBuilder.java +203 -0
- package/android/common/src/main/java/com/marianhello/bgloc/service/LocationServiceProxy.java +130 -0
- package/android/common/src/main/java/com/marianhello/bgloc/sync/AccountHelper.java +39 -0
- package/android/common/src/main/java/com/marianhello/bgloc/sync/Authenticator.java +68 -0
- package/android/common/src/main/java/com/marianhello/bgloc/sync/AuthenticatorService.java +28 -0
- package/android/common/src/main/java/com/marianhello/bgloc/sync/BatchManager.java +278 -0
- package/android/common/src/main/java/com/marianhello/bgloc/sync/NotificationHelper.java +148 -0
- package/android/common/src/main/java/com/marianhello/bgloc/sync/SyncAdapter.java +249 -0
- package/android/common/src/main/java/com/marianhello/bgloc/sync/SyncService.java +68 -0
- package/android/common/src/main/java/com/marianhello/logging/DBLogReader.java +203 -0
- package/android/common/src/main/java/com/marianhello/logging/LogEntry.java +99 -0
- package/android/common/src/main/java/com/marianhello/logging/LoggerManager.java +70 -0
- package/android/common/src/main/java/com/marianhello/logging/UncaughtExceptionLogger.java +36 -0
- package/android/common/src/main/java/com/marianhello/utils/CloneHelper.java +22 -0
- package/android/common/src/main/java/com/marianhello/utils/Convert.java +56 -0
- package/android/common/src/main/java/com/marianhello/utils/TextUtils.java +72 -0
- package/android/common/src/main/java/com/marianhello/utils/ToneGenerator.java +68 -0
- package/android/common/src/main/java/org/apache/commons/io/Charsets.java +153 -0
- package/android/common/src/main/java/org/apache/commons/io/input/ReversedLinesFileReader.java +344 -0
- package/android/common/src/main/java/org/chromium/content/browser/ThreadUtils.java +134 -0
- package/android/common/src/main/java/ru/andremoniy/sqlbuilder/SqlExpression.java +398 -0
- package/android/common/src/main/java/ru/andremoniy/sqlbuilder/SqlSelectStatement.java +671 -0
- package/android/common/src/main/java/ru/andremoniy/sqlbuilder/SqlStatement.java +29 -0
- package/android/common/src/main/java/ru/andremoniy/utils/TextUtils.java +61 -0
- package/android/common/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
- package/android/common/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
- package/android/common/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
- package/android/common/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
- package/android/common/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
- package/android/common/src/main/res/values/strings.xml +4 -0
- package/android/common/src/main/res/xml/authenticator.xml +7 -0
- package/android/common/src/main/res/xml/syncadapter.xml +9 -0
- package/android/common/src/test/java/com/marianhello/backgroundgeolocation/ArrayListLocationTemplateTest.java +82 -0
- package/android/common/src/test/java/com/marianhello/backgroundgeolocation/BackgroundLocationTest.java +128 -0
- package/android/common/src/test/java/com/marianhello/backgroundgeolocation/ConfigTest.java +191 -0
- package/android/common/src/test/java/com/marianhello/backgroundgeolocation/DBLogReaderTest.java +37 -0
- package/android/common/src/test/java/com/marianhello/backgroundgeolocation/HashMapLocationTemplateTest.java +216 -0
- package/android/common/src/test/java/com/marianhello/backgroundgeolocation/HttpPostServiceTest.java +223 -0
- package/android/common/src/test/java/com/marianhello/backgroundgeolocation/LocationTemplateFactoryTest.java +50 -0
- package/android/common/src/test/java/com/marianhello/backgroundgeolocation/PostLocationTaskTest.java +180 -0
- package/android/common/src/test/java/com/marianhello/backgroundgeolocation/TestHelper.java +16 -0
- package/android/dependencies.gradle +13 -0
- package/ios/CDVBackgroundGeolocation/CDVBackgroundGeolocation.h +41 -0
- package/ios/CDVBackgroundGeolocation/CDVBackgroundGeolocation.m +526 -0
- package/ios/common/BackgroundGeolocation/CocoaLumberjack.h +1945 -0
- package/ios/common/BackgroundGeolocation/CocoaLumberjack.m +5255 -0
- package/ios/common/BackgroundGeolocation/FMDB.h +2357 -0
- package/ios/common/BackgroundGeolocation/FMDB.m +2672 -0
- package/ios/common/BackgroundGeolocation/FMDBLogger.h +42 -0
- package/ios/common/BackgroundGeolocation/FMDBLogger.m +264 -0
- package/ios/common/BackgroundGeolocation/INTULocationManager/INTUHeadingRequest.h +41 -0
- package/ios/common/BackgroundGeolocation/INTULocationManager/INTUHeadingRequest.m +68 -0
- package/ios/common/BackgroundGeolocation/INTULocationManager/INTULocationManager+Internal.h +33 -0
- package/ios/common/BackgroundGeolocation/INTULocationManager/INTULocationManager.h +178 -0
- package/ios/common/BackgroundGeolocation/INTULocationManager/INTULocationManager.m +1025 -0
- package/ios/common/BackgroundGeolocation/INTULocationManager/INTULocationRequest.h +103 -0
- package/ios/common/BackgroundGeolocation/INTULocationManager/INTULocationRequest.m +238 -0
- package/ios/common/BackgroundGeolocation/INTULocationManager/INTULocationRequestDefines.h +163 -0
- package/ios/common/BackgroundGeolocation/INTULocationManager/INTURequestIDGenerator.h +39 -0
- package/ios/common/BackgroundGeolocation/INTULocationManager/INTURequestIDGenerator.m +37 -0
- package/ios/common/BackgroundGeolocation/MAURAbstractLocationProvider.h +51 -0
- package/ios/common/BackgroundGeolocation/MAURAbstractLocationProvider.m +53 -0
- package/ios/common/BackgroundGeolocation/MAURActivity.h +23 -0
- package/ios/common/BackgroundGeolocation/MAURActivity.m +52 -0
- package/ios/common/BackgroundGeolocation/MAURActivityLocationProvider.h +18 -0
- package/ios/common/BackgroundGeolocation/MAURActivityLocationProvider.m +202 -0
- package/ios/common/BackgroundGeolocation/MAURBackgroundGeolocationFacade.h +60 -0
- package/ios/common/BackgroundGeolocation/MAURBackgroundGeolocationFacade.m +638 -0
- package/ios/common/BackgroundGeolocation/MAURBackgroundSync.h +34 -0
- package/ios/common/BackgroundGeolocation/MAURBackgroundSync.m +185 -0
- package/ios/common/BackgroundGeolocation/MAURBackgroundTaskManager.h +25 -0
- package/ios/common/BackgroundGeolocation/MAURBackgroundTaskManager.m +105 -0
- package/ios/common/BackgroundGeolocation/MAURConfig.h +74 -0
- package/ios/common/BackgroundGeolocation/MAURConfig.m +485 -0
- package/ios/common/BackgroundGeolocation/MAURConfigurationContract.h +49 -0
- package/ios/common/BackgroundGeolocation/MAURConfigurationContract.m +51 -0
- package/ios/common/BackgroundGeolocation/MAURDistanceFilterLocationProvider.h +20 -0
- package/ios/common/BackgroundGeolocation/MAURDistanceFilterLocationProvider.m +514 -0
- package/ios/common/BackgroundGeolocation/MAURGeolocationOpenHelper.h +17 -0
- package/ios/common/BackgroundGeolocation/MAURGeolocationOpenHelper.m +97 -0
- package/ios/common/BackgroundGeolocation/MAURLocation.h +59 -0
- package/ios/common/BackgroundGeolocation/MAURLocation.m +349 -0
- package/ios/common/BackgroundGeolocation/MAURLocationContract.h +34 -0
- package/ios/common/BackgroundGeolocation/MAURLocationContract.m +35 -0
- package/ios/common/BackgroundGeolocation/MAURLocationManager.h +53 -0
- package/ios/common/BackgroundGeolocation/MAURLocationManager.m +287 -0
- package/ios/common/BackgroundGeolocation/MAURLogReader.h +26 -0
- package/ios/common/BackgroundGeolocation/MAURLogReader.m +122 -0
- package/ios/common/BackgroundGeolocation/MAURLogging.h +19 -0
- package/ios/common/BackgroundGeolocation/MAURPostLocationTask.h +40 -0
- package/ios/common/BackgroundGeolocation/MAURPostLocationTask.m +250 -0
- package/ios/common/BackgroundGeolocation/MAURProviderDelegate.h +52 -0
- package/ios/common/BackgroundGeolocation/MAURRawLocationProvider.h +18 -0
- package/ios/common/BackgroundGeolocation/MAURRawLocationProvider.m +129 -0
- package/ios/common/BackgroundGeolocation/MAURSQLiteConfigurationDAO.h +26 -0
- package/ios/common/BackgroundGeolocation/MAURSQLiteConfigurationDAO.m +278 -0
- package/ios/common/BackgroundGeolocation/MAURSQLiteHelper.h +57 -0
- package/ios/common/BackgroundGeolocation/MAURSQLiteHelper.m +93 -0
- package/ios/common/BackgroundGeolocation/MAURSQLiteLocationDAO.h +38 -0
- package/ios/common/BackgroundGeolocation/MAURSQLiteLocationDAO.m +380 -0
- package/ios/common/BackgroundGeolocation/MAURSQLiteOpenHelper.h +32 -0
- package/ios/common/BackgroundGeolocation/MAURSQLiteOpenHelper.m +276 -0
- package/ios/common/BackgroundGeolocation/MAURUncaughtExceptionLogger.h +20 -0
- package/ios/common/BackgroundGeolocation/MAURUncaughtExceptionLogger.m +62 -0
- package/ios/common/BackgroundGeolocation/Reachability.h +102 -0
- package/ios/common/BackgroundGeolocation/Reachability.m +475 -0
- package/ios/common/BackgroundGeolocation/SOMotionDetector/CHANGELOG.md +2 -0
- package/ios/common/BackgroundGeolocation/SOMotionDetector/LICENSE +21 -0
- package/ios/common/BackgroundGeolocation/SOMotionDetector/README.md +135 -0
- package/ios/common/BackgroundGeolocation/SOMotionDetector/SOLocationManager.h +80 -0
- package/ios/common/BackgroundGeolocation/SOMotionDetector/SOLocationManager.m +147 -0
- package/ios/common/BackgroundGeolocation/SOMotionDetector/SOMotionActivity.h +30 -0
- package/ios/common/BackgroundGeolocation/SOMotionDetector/SOMotionActivity.m +42 -0
- package/ios/common/BackgroundGeolocation/SOMotionDetector/SOMotionDetector.h +99 -0
- package/ios/common/BackgroundGeolocation/SOMotionDetector/SOMotionDetector.m +327 -0
- package/ios/common/BackgroundGeolocation/SOMotionDetector/SOStepDetector.h +44 -0
- package/ios/common/BackgroundGeolocation/SOMotionDetector/SOStepDetector.m +94 -0
- package/ios/common/BackgroundGeolocation/SQLQueryBuilder/README.md +170 -0
- package/ios/common/BackgroundGeolocation/SQLQueryBuilder/ext/NSString+ZIMString.h +55 -0
- package/ios/common/BackgroundGeolocation/SQLQueryBuilder/ext/NSString+ZIMString.m +47 -0
- package/ios/common/BackgroundGeolocation/SQLQueryBuilder/sql/ZIMSqlDataManipulationCommand.h +27 -0
- package/ios/common/BackgroundGeolocation/SQLQueryBuilder/sql/ZIMSqlExpression.h +250 -0
- package/ios/common/BackgroundGeolocation/SQLQueryBuilder/sql/ZIMSqlExpression.m +259 -0
- package/ios/common/BackgroundGeolocation/SQLQueryBuilder/sql/ZIMSqlSelectStatement.h +360 -0
- package/ios/common/BackgroundGeolocation/SQLQueryBuilder/sql/ZIMSqlSelectStatement.m +427 -0
- package/ios/common/BackgroundGeolocation/SQLQueryBuilder/sql/ZIMSqlStatement.h +37 -0
- package/ios/common/BackgroundGeolocation.xcodeproj/project.pbxproj +760 -0
- package/ios/common/BackgroundGeolocationTests/Info.plist +24 -0
- package/ios/common/BackgroundGeolocationTests/MAURBackgroundLocationTest.m +185 -0
- package/ios/common/BackgroundGeolocationTests/MAURConfigTest.m +161 -0
- package/ios/common/BackgroundGeolocationTests/MAURGeolocationOpenHelperTest.m +102 -0
- package/ios/common/BackgroundGeolocationTests/MAURLocationTest.m +216 -0
- package/ios/common/BackgroundGeolocationTests/MAURLocationUploaderTest.m +55 -0
- package/ios/common/BackgroundGeolocationTests/MAURLogReaderTest.m +43 -0
- package/ios/common/BackgroundGeolocationTests/MAURSQLiteConfigurationDAOTest.m +102 -0
- package/ios/common/BackgroundGeolocationTests/MAURSQLiteHelperTest.m +41 -0
- package/ios/common/BackgroundGeolocationTests/MAURSQLiteLocationDAOTests.m +240 -0
- package/ios/common/BackgroundGeolocationTests/MAURSQLiteLocationDAOThreadTest.m +84 -0
- package/ios/common/BackgroundGeolocationTests/MAURSQLiteOpenHelperTest.m +144 -0
- package/ios/common/CONTRIBUTORS.md +10 -0
- package/ios/common/LICENSE +191 -0
- package/ios/common/README.md +7 -0
- package/ios/common/scripts/xcode-refactor.js +184 -0
- package/package.json +44 -0
- package/plugin.xml +355 -0
- package/www/BackgroundGeolocation.d.ts +910 -0
- package/www/BackgroundGeolocation.js +247 -0
- package/www/radio.js +177 -0
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
package com.marianhello.bgloc;
|
|
2
|
+
|
|
3
|
+
import android.database.sqlite.SQLiteDatabase;
|
|
4
|
+
import android.location.Location;
|
|
5
|
+
|
|
6
|
+
import com.marianhello.bgloc.data.BackgroundLocation;
|
|
7
|
+
import com.marianhello.bgloc.data.LocationDAO;
|
|
8
|
+
import com.marianhello.bgloc.data.provider.ContentProviderLocationDAO;
|
|
9
|
+
import com.marianhello.bgloc.data.sqlite.SQLiteOpenHelper;
|
|
10
|
+
import com.marianhello.bgloc.test.LocationProviderTestCase;
|
|
11
|
+
|
|
12
|
+
import org.junit.Before;
|
|
13
|
+
import org.junit.Test;
|
|
14
|
+
|
|
15
|
+
import java.util.ArrayList;
|
|
16
|
+
import java.util.Collection;
|
|
17
|
+
import java.util.Iterator;
|
|
18
|
+
|
|
19
|
+
import static androidx.test.platform.app.InstrumentationRegistry.getContext;
|
|
20
|
+
import static com.marianhello.bgloc.data.sqlite.SQLiteLocationContract.LocationEntry.SQL_DROP_LOCATION_TABLE;
|
|
21
|
+
import static junit.framework.Assert.assertEquals;
|
|
22
|
+
|
|
23
|
+
public class ContentProviderLocationDAOTest extends LocationProviderTestCase {
|
|
24
|
+
public void deleteDatabase() {
|
|
25
|
+
SQLiteOpenHelper dbHelper = new SQLiteOpenHelper(getContext());
|
|
26
|
+
SQLiteDatabase db = dbHelper.getWritableDatabase();
|
|
27
|
+
dbHelper.execAndLogSql(db, SQL_DROP_LOCATION_TABLE);
|
|
28
|
+
dbHelper.onCreate(db);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@Before
|
|
32
|
+
@Override
|
|
33
|
+
public void setUp() throws Exception {
|
|
34
|
+
super.setUp();
|
|
35
|
+
deleteDatabase();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@Test
|
|
39
|
+
public void testPersistLocation() {
|
|
40
|
+
LocationDAO dao = new ContentProviderLocationDAO(getContext());
|
|
41
|
+
|
|
42
|
+
Location location = new Location("fake");
|
|
43
|
+
location.setAccuracy(200);
|
|
44
|
+
location.setAltitude(900);
|
|
45
|
+
location.setBearing(2);
|
|
46
|
+
location.setLatitude(40.21);
|
|
47
|
+
location.setLongitude(23.45);
|
|
48
|
+
location.setSpeed(20);
|
|
49
|
+
location.setProvider("test");
|
|
50
|
+
location.setTime(1000);
|
|
51
|
+
BackgroundLocation bgLocation = BackgroundLocation.fromLocation(location);
|
|
52
|
+
|
|
53
|
+
dao.persistLocation(bgLocation);
|
|
54
|
+
|
|
55
|
+
ArrayList<BackgroundLocation> locations = new ArrayList(dao.getAllLocations());
|
|
56
|
+
assertEquals(1, locations.size());
|
|
57
|
+
|
|
58
|
+
BackgroundLocation storedLocation = locations.get(0);
|
|
59
|
+
assertEquals(200, storedLocation.getAccuracy(), 0);
|
|
60
|
+
assertEquals(900, storedLocation.getAltitude(), 0);
|
|
61
|
+
assertEquals(2, storedLocation.getBearing(), 0);
|
|
62
|
+
assertEquals(40.21, storedLocation.getLatitude(), 0);
|
|
63
|
+
assertEquals(23.45, storedLocation.getLongitude(), 0);
|
|
64
|
+
assertEquals(20, storedLocation.getSpeed(), 0);
|
|
65
|
+
assertEquals("test", storedLocation.getProvider(), "test");
|
|
66
|
+
assertEquals(1000, storedLocation.getTime(), 0);
|
|
67
|
+
junit.framework.Assert.assertFalse(storedLocation.hasMockLocationsEnabled());
|
|
68
|
+
junit.framework.Assert.assertFalse(storedLocation.areMockLocationsEnabled());
|
|
69
|
+
junit.framework.Assert.assertTrue(storedLocation.hasIsFromMockProvider()); // because setIsFromMockProvider is called in constructor
|
|
70
|
+
junit.framework.Assert.assertFalse(storedLocation.isFromMockProvider());
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@Test
|
|
74
|
+
public void testPersistLocationIsMock() {
|
|
75
|
+
LocationDAO dao = new ContentProviderLocationDAO(getContext());
|
|
76
|
+
|
|
77
|
+
BackgroundLocation bgLocation = new BackgroundLocation();
|
|
78
|
+
bgLocation.setMockLocationsEnabled(true);
|
|
79
|
+
bgLocation.setIsFromMockProvider(true);
|
|
80
|
+
|
|
81
|
+
dao.persistLocation(bgLocation);
|
|
82
|
+
|
|
83
|
+
ArrayList<BackgroundLocation> locations = new ArrayList(dao.getAllLocations());
|
|
84
|
+
assertEquals(1, locations.size());
|
|
85
|
+
|
|
86
|
+
BackgroundLocation storedLocation = locations.get(0);
|
|
87
|
+
junit.framework.Assert.assertTrue(storedLocation.hasMockLocationsEnabled());
|
|
88
|
+
junit.framework.Assert.assertTrue(storedLocation.areMockLocationsEnabled());
|
|
89
|
+
junit.framework.Assert.assertTrue(storedLocation.hasIsFromMockProvider());
|
|
90
|
+
junit.framework.Assert.assertTrue(storedLocation.isFromMockProvider());
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
@Test
|
|
94
|
+
public void testDeleteLocationById() {
|
|
95
|
+
LocationDAO dao = new ContentProviderLocationDAO(getContext());
|
|
96
|
+
|
|
97
|
+
BackgroundLocation bgLocation = BackgroundLocation.fromLocation(new Location("fake"));
|
|
98
|
+
Collection<BackgroundLocation> locations = null;
|
|
99
|
+
|
|
100
|
+
Long locationId = dao.persistLocation(bgLocation);
|
|
101
|
+
|
|
102
|
+
locations = dao.getAllLocations();
|
|
103
|
+
assertEquals(1, locations.size());
|
|
104
|
+
|
|
105
|
+
dao.deleteLocationById(locationId);
|
|
106
|
+
|
|
107
|
+
locations = dao.getValidLocations();
|
|
108
|
+
assertEquals(0, locations.size());
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
@Test
|
|
112
|
+
public void testDeleteAllLocations() {
|
|
113
|
+
LocationDAO dao = new ContentProviderLocationDAO(getContext());
|
|
114
|
+
Collection<BackgroundLocation> locations = null;
|
|
115
|
+
|
|
116
|
+
for (int i = 0; i < 10; i++) {
|
|
117
|
+
dao.persistLocation(BackgroundLocation.fromLocation(new Location("fake")));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
locations = dao.getValidLocations();
|
|
121
|
+
assertEquals(10, locations.size());
|
|
122
|
+
|
|
123
|
+
dao.deleteAllLocations();
|
|
124
|
+
|
|
125
|
+
locations = dao.getValidLocations();
|
|
126
|
+
assertEquals(0, locations.size());
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
@Test
|
|
130
|
+
public void testGetAllLocations() {
|
|
131
|
+
LocationDAO dao = new ContentProviderLocationDAO(getContext());
|
|
132
|
+
|
|
133
|
+
Location location = null;
|
|
134
|
+
BackgroundLocation bgLocation = null;
|
|
135
|
+
|
|
136
|
+
for (int i = 0; i < 10; i++) {
|
|
137
|
+
location = new Location("fake");
|
|
138
|
+
location.setAccuracy(200 + i);
|
|
139
|
+
location.setAltitude(900 + i);
|
|
140
|
+
location.setBearing(2 + i);
|
|
141
|
+
location.setLatitude(40.21 + i);
|
|
142
|
+
location.setLongitude(23.45 + i);
|
|
143
|
+
location.setSpeed(20 + i);
|
|
144
|
+
location.setProvider("test");
|
|
145
|
+
location.setTime(1000 + i);
|
|
146
|
+
bgLocation = BackgroundLocation.fromLocation(location);
|
|
147
|
+
dao.persistLocation(bgLocation);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
Collection<BackgroundLocation> locations = dao.getAllLocations();
|
|
151
|
+
Iterator<BackgroundLocation> it = locations.iterator();
|
|
152
|
+
BackgroundLocation storedLocation = null;
|
|
153
|
+
for (int i = 0; i < 10; i++) {
|
|
154
|
+
storedLocation = it.next();
|
|
155
|
+
assertEquals(200 + i, storedLocation.getAccuracy(), 0);
|
|
156
|
+
assertEquals(900 + i, storedLocation.getAltitude(), 0);
|
|
157
|
+
assertEquals(2 + i, storedLocation.getBearing(), 0);
|
|
158
|
+
assertEquals(40.21 + i, storedLocation.getLatitude(), 0);
|
|
159
|
+
assertEquals(23.45 + i,storedLocation.getLongitude(), 0);
|
|
160
|
+
assertEquals(20 + i, storedLocation.getSpeed(), 0);
|
|
161
|
+
assertEquals("test", storedLocation.getProvider());
|
|
162
|
+
assertEquals(1000 + i, storedLocation.getTime(), 0);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
@Test
|
|
167
|
+
public void testPersistLocationWithRowLimit() {
|
|
168
|
+
LocationDAO dao = new ContentProviderLocationDAO(getContext());
|
|
169
|
+
|
|
170
|
+
int maxRows = 100;
|
|
171
|
+
|
|
172
|
+
for (int i = 0; i < maxRows * 2; i++) {
|
|
173
|
+
dao.persistLocation(BackgroundLocation.fromLocation(new Location("fake")), maxRows);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
Collection<BackgroundLocation> locations = dao.getAllLocations();
|
|
177
|
+
assertEquals(maxRows, locations.size());
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
@Test
|
|
181
|
+
public void testShouldReplaceOldLocation() {
|
|
182
|
+
LocationDAO dao = new ContentProviderLocationDAO(getContext());
|
|
183
|
+
|
|
184
|
+
dao.persistLocation(BackgroundLocation.fromLocation(new Location("old")), 1);
|
|
185
|
+
dao.persistLocation(BackgroundLocation.fromLocation(new Location("new")), 1);
|
|
186
|
+
|
|
187
|
+
Collection<BackgroundLocation> locations = dao.getAllLocations();
|
|
188
|
+
assertEquals(1, locations.size());
|
|
189
|
+
assertEquals("new", locations.iterator().next().getProvider());
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
@Test
|
|
193
|
+
public void testPersistLocationWithRowLimitWhenMaxRowsReduced() {
|
|
194
|
+
LocationDAO dao = new ContentProviderLocationDAO(getContext());
|
|
195
|
+
|
|
196
|
+
int maxRowsRun[] = {100, 10};
|
|
197
|
+
|
|
198
|
+
for (int i = 0; i < maxRowsRun.length; i++) {
|
|
199
|
+
int maxRows = maxRowsRun[i];
|
|
200
|
+
for (int j = 0; j < maxRows * 2; j++) {
|
|
201
|
+
dao.persistLocation(BackgroundLocation.fromLocation(new Location("fake")), maxRows);
|
|
202
|
+
}
|
|
203
|
+
Collection<BackgroundLocation> locations = dao.getAllLocations();
|
|
204
|
+
assertEquals(maxRows, locations.size());
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
Long locationId = dao.persistLocation(BackgroundLocation.fromLocation(new Location("fake")));
|
|
208
|
+
assertEquals(locationId, Long.valueOf(101));
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
@Test
|
|
212
|
+
public void testPersistLocationWithBatchId() {
|
|
213
|
+
LocationDAO dao = new ContentProviderLocationDAO(getContext());
|
|
214
|
+
|
|
215
|
+
BackgroundLocation location = new BackgroundLocation();
|
|
216
|
+
location.setBatchStartMillis(1000L);
|
|
217
|
+
dao.persistLocation(location);
|
|
218
|
+
ArrayList<BackgroundLocation> locations = new ArrayList(dao.getAllLocations());
|
|
219
|
+
assertEquals(Long.valueOf(1000L), locations.get(0).getBatchStartMillis());
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
@Test
|
|
223
|
+
public void testGetLocationsForSyncCount() {
|
|
224
|
+
LocationDAO dao = new ContentProviderLocationDAO(getContext());
|
|
225
|
+
|
|
226
|
+
BackgroundLocation location;
|
|
227
|
+
for (int i = 1; i < 100; i++) {
|
|
228
|
+
location = new BackgroundLocation();
|
|
229
|
+
if ((i % 3) == 0) {
|
|
230
|
+
// exactly 33 locations (out of 99) should be eligible for sync for given batch id 1000
|
|
231
|
+
location.setBatchStartMillis(1000L);
|
|
232
|
+
location.setStatus(BackgroundLocation.SYNC_PENDING);
|
|
233
|
+
} else if ((i % 2) == 0) {
|
|
234
|
+
// exactly 33 locations as deleted
|
|
235
|
+
location.setStatus(BackgroundLocation.DELETED);
|
|
236
|
+
} else {
|
|
237
|
+
location.setStatus(BackgroundLocation.SYNC_PENDING);
|
|
238
|
+
}
|
|
239
|
+
dao.persistLocation(location);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
assertEquals(66, dao.getValidLocations().size());
|
|
243
|
+
assertEquals(99, dao.getAllLocations().size());
|
|
244
|
+
assertEquals(66L, dao.getLocationsForSyncCount(10001L));
|
|
245
|
+
assertEquals(33L, dao.getLocationsForSyncCount(1000L));
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
@Test
|
|
249
|
+
public void testGetLocationById() {
|
|
250
|
+
LocationDAO dao = new ContentProviderLocationDAO(getContext());
|
|
251
|
+
|
|
252
|
+
Location location = null;
|
|
253
|
+
BackgroundLocation bgLocation = null;
|
|
254
|
+
|
|
255
|
+
for (int i = 0; i < 10; i++) {
|
|
256
|
+
location = new Location("fake");
|
|
257
|
+
location.setAccuracy(200 + i);
|
|
258
|
+
location.setAltitude(900 + i);
|
|
259
|
+
location.setBearing(2 + i);
|
|
260
|
+
location.setLatitude(40.21 + i);
|
|
261
|
+
location.setLongitude(23.45 + i);
|
|
262
|
+
location.setSpeed(20 + i);
|
|
263
|
+
location.setProvider("test");
|
|
264
|
+
location.setTime(1000 + i);
|
|
265
|
+
bgLocation = BackgroundLocation.fromLocation(location);
|
|
266
|
+
dao.persistLocation(bgLocation);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
BackgroundLocation pending = dao.getLocationById(2);
|
|
270
|
+
assertEquals(Long.valueOf(2), pending.getLocationId());
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
@Test
|
|
274
|
+
public void testGetFirstPendingLocation() {
|
|
275
|
+
LocationDAO dao = new ContentProviderLocationDAO(getContext());
|
|
276
|
+
|
|
277
|
+
BackgroundLocation location = null;
|
|
278
|
+
|
|
279
|
+
for (int i = 1; i <= 5; i++) {
|
|
280
|
+
location = new BackgroundLocation();
|
|
281
|
+
location.setProvider("fake");
|
|
282
|
+
location.setAccuracy(200 + i);
|
|
283
|
+
location.setAltitude(900 + i);
|
|
284
|
+
location.setBearing(2 + i);
|
|
285
|
+
location.setLatitude(40.21 + i);
|
|
286
|
+
location.setLongitude(23.45 + i);
|
|
287
|
+
location.setSpeed(20 + i);
|
|
288
|
+
location.setProvider("test");
|
|
289
|
+
location.setTime(1000 + i);
|
|
290
|
+
if (i <= 3) {
|
|
291
|
+
location.setStatus(BackgroundLocation.DELETED);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
dao.persistLocation(location);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
BackgroundLocation pending = dao.getFirstUnpostedLocation();
|
|
298
|
+
assertEquals(Long.valueOf(4), pending.getLocationId());
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
@Test
|
|
302
|
+
public void testGetNextPendingLocation() {
|
|
303
|
+
LocationDAO dao = new ContentProviderLocationDAO(getContext());
|
|
304
|
+
|
|
305
|
+
BackgroundLocation location = null;
|
|
306
|
+
|
|
307
|
+
for (int i = 1; i <= 5; i++) {
|
|
308
|
+
location = new BackgroundLocation();
|
|
309
|
+
location.setProvider("fake");
|
|
310
|
+
location.setAccuracy(200 + i);
|
|
311
|
+
location.setAltitude(900 + i);
|
|
312
|
+
location.setBearing(2 + i);
|
|
313
|
+
location.setLatitude(40.21 + i);
|
|
314
|
+
location.setLongitude(23.45 + i);
|
|
315
|
+
location.setSpeed(20 + i);
|
|
316
|
+
location.setProvider("test");
|
|
317
|
+
location.setTime(1000 + i);
|
|
318
|
+
if (i <= 3) {
|
|
319
|
+
location.setStatus(BackgroundLocation.DELETED);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
dao.persistLocation(location);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
BackgroundLocation pending = dao.getNextUnpostedLocation(4);
|
|
326
|
+
assertEquals(Long.valueOf(5), pending.getLocationId());
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
@Test
|
|
330
|
+
public void testGetPendingLocationsCount() {
|
|
331
|
+
LocationDAO dao = new ContentProviderLocationDAO(getContext());
|
|
332
|
+
|
|
333
|
+
BackgroundLocation location = null;
|
|
334
|
+
|
|
335
|
+
for (int i = 0; i < 5; i++) {
|
|
336
|
+
location = new BackgroundLocation();
|
|
337
|
+
location.setProvider("fake");
|
|
338
|
+
location.setAccuracy(200 + i);
|
|
339
|
+
location.setAltitude(900 + i);
|
|
340
|
+
location.setBearing(2 + i);
|
|
341
|
+
location.setLatitude(40.21 + i);
|
|
342
|
+
location.setLongitude(23.45 + i);
|
|
343
|
+
location.setSpeed(20 + i);
|
|
344
|
+
location.setProvider("test");
|
|
345
|
+
location.setTime(1000 + i);
|
|
346
|
+
if (i < 3) {
|
|
347
|
+
location.setStatus(BackgroundLocation.DELETED);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
dao.persistLocation(location);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
assertEquals(2, dao.getUnpostedLocationsCount());
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
@Test
|
|
357
|
+
public void testDeleteFirstPendingLocation() {
|
|
358
|
+
LocationDAO dao = new ContentProviderLocationDAO(getContext());
|
|
359
|
+
|
|
360
|
+
BackgroundLocation location = null;
|
|
361
|
+
|
|
362
|
+
for (int i = 1; i <= 5; i++) {
|
|
363
|
+
location = new BackgroundLocation();
|
|
364
|
+
location.setProvider("fake");
|
|
365
|
+
location.setAccuracy(200 + i);
|
|
366
|
+
location.setAltitude(900 + i);
|
|
367
|
+
location.setBearing(2 + i);
|
|
368
|
+
location.setLatitude(40.21 + i);
|
|
369
|
+
location.setLongitude(23.45 + i);
|
|
370
|
+
location.setSpeed(20 + i);
|
|
371
|
+
location.setProvider("test");
|
|
372
|
+
location.setTime(1000 + i);
|
|
373
|
+
if (i <= 3) {
|
|
374
|
+
location.setStatus(BackgroundLocation.DELETED);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
dao.persistLocation(location);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
BackgroundLocation deleted = dao.deleteFirstUnpostedLocation();
|
|
381
|
+
assertEquals(Long.valueOf(4), deleted.getLocationId());
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
@Test
|
|
385
|
+
public void testDeletePendingLocations() {
|
|
386
|
+
LocationDAO dao = new ContentProviderLocationDAO(getContext());
|
|
387
|
+
|
|
388
|
+
BackgroundLocation location = null;
|
|
389
|
+
|
|
390
|
+
for (int i = 0; i < 5; i++) {
|
|
391
|
+
location = new BackgroundLocation();
|
|
392
|
+
location.setProvider("fake");
|
|
393
|
+
location.setAccuracy(200 + i);
|
|
394
|
+
location.setAltitude(900 + i);
|
|
395
|
+
location.setBearing(2 + i);
|
|
396
|
+
location.setLatitude(40.21 + i);
|
|
397
|
+
location.setLongitude(23.45 + i);
|
|
398
|
+
location.setSpeed(20 + i);
|
|
399
|
+
location.setProvider("test");
|
|
400
|
+
location.setTime(1000 + i);
|
|
401
|
+
if (i < 3) {
|
|
402
|
+
location.setStatus(BackgroundLocation.DELETED);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
dao.persistLocation(location);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
dao.deleteUnpostedLocations();
|
|
409
|
+
assertEquals(0, dao.getUnpostedLocationsCount());
|
|
410
|
+
assertEquals(2, dao.getLocationsForSyncCount(0));
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
@Test
|
|
414
|
+
public void testPersistLocationForSync() {
|
|
415
|
+
LocationDAO dao = new ContentProviderLocationDAO(getContext());
|
|
416
|
+
|
|
417
|
+
BackgroundLocation location = new BackgroundLocation();
|
|
418
|
+
location.setProvider("fake");
|
|
419
|
+
location.setAccuracy(200);
|
|
420
|
+
location.setAltitude(900);
|
|
421
|
+
location.setBearing(2);
|
|
422
|
+
location.setLatitude(40.21);
|
|
423
|
+
location.setLongitude(23.45);
|
|
424
|
+
location.setSpeed(20);
|
|
425
|
+
location.setProvider("test");
|
|
426
|
+
location.setTime(1000);
|
|
427
|
+
|
|
428
|
+
long locationId = dao.persistLocation(location);
|
|
429
|
+
location.setLocationId(locationId);
|
|
430
|
+
assertEquals(1, dao.getUnpostedLocationsCount());
|
|
431
|
+
assertEquals(0, dao.getLocationsForSyncCount(0));
|
|
432
|
+
|
|
433
|
+
dao.persistLocationForSync(location, 100);
|
|
434
|
+
assertEquals(0, dao.getUnpostedLocationsCount());
|
|
435
|
+
assertEquals(1, dao.getLocationsForSyncCount(0));
|
|
436
|
+
}
|
|
437
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
package com.marianhello.bgloc;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import androidx.test.platform.app.InstrumentationRegistry;
|
|
5
|
+
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
|
6
|
+
import androidx.test.filters.SmallTest;
|
|
7
|
+
|
|
8
|
+
import com.marianhello.logging.DBLogReader;
|
|
9
|
+
import com.marianhello.logging.LogEntry;
|
|
10
|
+
import com.marianhello.logging.LoggerManager;
|
|
11
|
+
|
|
12
|
+
import junit.framework.Assert;
|
|
13
|
+
|
|
14
|
+
import org.junit.Before;
|
|
15
|
+
import org.junit.Test;
|
|
16
|
+
import org.junit.runner.RunWith;
|
|
17
|
+
import org.slf4j.Logger;
|
|
18
|
+
import org.slf4j.event.Level;
|
|
19
|
+
|
|
20
|
+
import java.io.File;
|
|
21
|
+
import java.util.ArrayList;
|
|
22
|
+
import java.util.Collection;
|
|
23
|
+
|
|
24
|
+
import ch.qos.logback.classic.LoggerContext;
|
|
25
|
+
import ch.qos.logback.core.CoreConstants;
|
|
26
|
+
import ch.qos.logback.core.android.CommonPathUtil;
|
|
27
|
+
|
|
28
|
+
@RunWith(AndroidJUnit4.class)
|
|
29
|
+
@SmallTest
|
|
30
|
+
public class DBLogReaderTest {
|
|
31
|
+
private static final String TAG = "DBLogReaderTest";
|
|
32
|
+
|
|
33
|
+
@Before
|
|
34
|
+
public void deleteDatabase() {
|
|
35
|
+
LoggerManager.disableDBLogging();
|
|
36
|
+
String packageName = null;
|
|
37
|
+
LoggerContext context = (LoggerContext) org.slf4j.LoggerFactory.getILoggerFactory();
|
|
38
|
+
|
|
39
|
+
if (context != null) {
|
|
40
|
+
packageName = context.getProperty(CoreConstants.PACKAGE_NAME_KEY);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (!(packageName == null || packageName.length() == 0)) {
|
|
44
|
+
File dbfile = new File(CommonPathUtil.getDatabaseDirectoryPath(packageName), DBLogReader.DB_FILENAME);
|
|
45
|
+
Context ctx = InstrumentationRegistry.getTargetContext();
|
|
46
|
+
ctx.deleteDatabase(dbfile.getPath());
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@Test
|
|
51
|
+
public void testReadLogEntriesWithLimit() {
|
|
52
|
+
LoggerManager.enableDBLogging();
|
|
53
|
+
Logger logger = LoggerManager.getLogger(DBLogReaderTest.class);
|
|
54
|
+
|
|
55
|
+
for (int i = 0; i < 100; i++) {
|
|
56
|
+
logger.debug("Message #" + i);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
DBLogReader logReader = new DBLogReader();
|
|
60
|
+
Collection<LogEntry> entries = logReader.getEntries(10, 0, Level.DEBUG);
|
|
61
|
+
Assert.assertEquals(10, entries.size());
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@Test
|
|
65
|
+
public void testReadLogEntriesWithOffset() {
|
|
66
|
+
LoggerManager.enableDBLogging();
|
|
67
|
+
Logger logger = LoggerManager.getLogger(DBLogReaderTest.class);
|
|
68
|
+
|
|
69
|
+
for (int i = 0; i < 100; i++) {
|
|
70
|
+
logger.debug("Message #" + i);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
DBLogReader logReader = new DBLogReader();
|
|
74
|
+
ArrayList<LogEntry> entries = (ArrayList) logReader.getEntries(10, 0, Level.DEBUG);
|
|
75
|
+
LogEntry lastEntry = entries.get(entries.size() - 1);
|
|
76
|
+
entries = (ArrayList) logReader.getEntries(10, lastEntry.getId(), Level.DEBUG);
|
|
77
|
+
Assert.assertEquals(lastEntry.getId() - 1, entries.get(0).getId().intValue());
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
@Test
|
|
81
|
+
public void testReadLogEntriesWithOffsetAsc() {
|
|
82
|
+
LoggerManager.enableDBLogging();
|
|
83
|
+
Logger logger = LoggerManager.getLogger(DBLogReaderTest.class);
|
|
84
|
+
|
|
85
|
+
for (int i = 0; i < 100; i++) {
|
|
86
|
+
logger.debug("Message #" + i);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
DBLogReader logReader = new DBLogReader();
|
|
90
|
+
ArrayList<LogEntry> entries = (ArrayList) logReader.getEntries(10, 0, Level.DEBUG);
|
|
91
|
+
LogEntry lastEntry = entries.get(entries.size() - 1);
|
|
92
|
+
entries = (ArrayList) logReader.getEntries(-10, lastEntry.getId(), Level.DEBUG);
|
|
93
|
+
Assert.assertEquals(lastEntry.getId() + 1, entries.get(0).getId().intValue());
|
|
94
|
+
}
|
|
95
|
+
}
|
package/android/common/src/androidTest/java/com/marianhello/bgloc/LocationContentProviderTest.java
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
package com.marianhello.bgloc;
|
|
2
|
+
|
|
3
|
+
import android.database.Cursor;
|
|
4
|
+
import android.database.sqlite.SQLiteDatabase;
|
|
5
|
+
import android.net.Uri;
|
|
6
|
+
import android.test.RenamingDelegatingContext;
|
|
7
|
+
import android.test.mock.MockContentResolver;
|
|
8
|
+
|
|
9
|
+
import com.marianhello.bgloc.data.BackgroundLocation;
|
|
10
|
+
import com.marianhello.bgloc.data.provider.LocationContentProvider;
|
|
11
|
+
import com.marianhello.bgloc.data.sqlite.SQLiteLocationContract.LocationEntry;
|
|
12
|
+
import com.marianhello.bgloc.data.sqlite.SQLiteOpenHelper;
|
|
13
|
+
import com.marianhello.bgloc.test.LocationProviderTestCase;
|
|
14
|
+
import com.marianhello.bgloc.test.TestConstants;
|
|
15
|
+
|
|
16
|
+
import org.junit.Assert;
|
|
17
|
+
import org.junit.Before;
|
|
18
|
+
import org.junit.Test;
|
|
19
|
+
|
|
20
|
+
import java.util.ArrayList;
|
|
21
|
+
|
|
22
|
+
import static com.marianhello.bgloc.data.sqlite.SQLiteLocationContract.LocationEntry.SQL_DROP_LOCATION_TABLE;
|
|
23
|
+
|
|
24
|
+
public class LocationContentProviderTest extends LocationProviderTestCase {
|
|
25
|
+
|
|
26
|
+
private MockContentResolver mResolver;
|
|
27
|
+
private final Uri mContentUri;
|
|
28
|
+
|
|
29
|
+
public LocationContentProviderTest() {
|
|
30
|
+
super();
|
|
31
|
+
mContentUri = LocationContentProvider.getContentUri(TestConstants.Authority);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public void deleteDatabase() {
|
|
35
|
+
// TODO: investigate why prefix is not automatically used when deleteDatabase
|
|
36
|
+
RenamingDelegatingContext context = ((RenamingDelegatingContext) getMockContext().getBaseContext());
|
|
37
|
+
|
|
38
|
+
SQLiteOpenHelper dbHelper = new SQLiteOpenHelper(context);
|
|
39
|
+
SQLiteDatabase db = dbHelper.getWritableDatabase();
|
|
40
|
+
dbHelper.execAndLogSql(db, SQL_DROP_LOCATION_TABLE);
|
|
41
|
+
dbHelper.onCreate(db);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@Before
|
|
45
|
+
@Override
|
|
46
|
+
public void setUp() throws Exception {
|
|
47
|
+
super.setUp();
|
|
48
|
+
mResolver = getMockContentResolver();
|
|
49
|
+
deleteDatabase();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@Test
|
|
53
|
+
public void testResolveProvider() {
|
|
54
|
+
Cursor cursor = mResolver.query(mContentUri, null, null, null,null);
|
|
55
|
+
Assert.assertNotNull(cursor);
|
|
56
|
+
cursor.close();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@Test
|
|
60
|
+
public void testShouldCreateAndRetrieveLocation() {
|
|
61
|
+
BackgroundLocation location = new BackgroundLocation();
|
|
62
|
+
location.setAccuracy(200);
|
|
63
|
+
location.setAltitude(900);
|
|
64
|
+
location.setBearing(2);
|
|
65
|
+
location.setLatitude(40.21);
|
|
66
|
+
location.setLongitude(23.45);
|
|
67
|
+
location.setSpeed(20);
|
|
68
|
+
location.setProvider("test");
|
|
69
|
+
location.setTime(1000);
|
|
70
|
+
|
|
71
|
+
createLocation(location);
|
|
72
|
+
|
|
73
|
+
Cursor cursor = mResolver.query(mContentUri, null, null, null,null);
|
|
74
|
+
assertEquals(1, cursor.getCount());
|
|
75
|
+
assertTrue(cursor.moveToFirst());
|
|
76
|
+
|
|
77
|
+
assertEquals(200, cursor.getFloat(cursor.getColumnIndex(LocationEntry.COLUMN_NAME_ACCURACY)), 0);
|
|
78
|
+
assertEquals(900, cursor.getDouble(cursor.getColumnIndex(LocationEntry.COLUMN_NAME_ALTITUDE)), 0);
|
|
79
|
+
assertEquals(2, cursor.getFloat(cursor.getColumnIndex(LocationEntry.COLUMN_NAME_BEARING)), 0);
|
|
80
|
+
assertEquals(40.21, cursor.getDouble(cursor.getColumnIndex(LocationEntry.COLUMN_NAME_LATITUDE)), 0);
|
|
81
|
+
assertEquals(23.45, cursor.getDouble(cursor.getColumnIndex(LocationEntry.COLUMN_NAME_LONGITUDE)), 0);
|
|
82
|
+
assertEquals(20, cursor.getFloat(cursor.getColumnIndex(LocationEntry.COLUMN_NAME_SPEED)), 0);
|
|
83
|
+
assertEquals("test", cursor.getString(cursor.getColumnIndex(LocationEntry.COLUMN_NAME_PROVIDER)));
|
|
84
|
+
assertEquals(1000, cursor.getLong(cursor.getColumnIndex(LocationEntry.COLUMN_NAME_TIME)), 0);
|
|
85
|
+
|
|
86
|
+
cursor.close();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
@Test
|
|
90
|
+
public void testShouldDeleteSingleLocation() {
|
|
91
|
+
BackgroundLocation location = new BackgroundLocation();
|
|
92
|
+
location.setAccuracy(200);
|
|
93
|
+
location.setAltitude(900);
|
|
94
|
+
location.setBearing(2);
|
|
95
|
+
location.setLatitude(40.21);
|
|
96
|
+
location.setLongitude(23.45);
|
|
97
|
+
location.setSpeed(20);
|
|
98
|
+
location.setProvider("test");
|
|
99
|
+
location.setTime(1000);
|
|
100
|
+
|
|
101
|
+
Uri locationUri = createLocation(location);
|
|
102
|
+
int rowsDeleted = mResolver.delete(locationUri, null, null);
|
|
103
|
+
|
|
104
|
+
assertEquals(1, rowsDeleted);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
@Test
|
|
108
|
+
public void testShouldDeleteMultipleLocations() {
|
|
109
|
+
ArrayList<Uri> locationUris = new ArrayList<Uri>();
|
|
110
|
+
|
|
111
|
+
for (int i = 1; i <= 2; i++) {
|
|
112
|
+
BackgroundLocation location = new BackgroundLocation();
|
|
113
|
+
location.setAccuracy(200);
|
|
114
|
+
location.setAltitude(900);
|
|
115
|
+
location.setBearing(2);
|
|
116
|
+
location.setLatitude(40.21);
|
|
117
|
+
location.setLongitude(23.45);
|
|
118
|
+
location.setSpeed(20);
|
|
119
|
+
location.setProvider("test");
|
|
120
|
+
location.setTime(1000);
|
|
121
|
+
|
|
122
|
+
Uri locationUri = createLocation(location);
|
|
123
|
+
locationUris.add(locationUri);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
int rowsDeleted = mResolver.delete(mContentUri, null, null);
|
|
127
|
+
assertEquals(2, rowsDeleted);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
@Test
|
|
131
|
+
public void testShouldUpdateSingleLocation() {
|
|
132
|
+
BackgroundLocation location = new BackgroundLocation();
|
|
133
|
+
location.setAccuracy(200);
|
|
134
|
+
location.setAltitude(900);
|
|
135
|
+
location.setBearing(2);
|
|
136
|
+
location.setLatitude(40.21);
|
|
137
|
+
location.setLongitude(23.45);
|
|
138
|
+
location.setSpeed(20);
|
|
139
|
+
location.setProvider("test");
|
|
140
|
+
location.setTime(1000);
|
|
141
|
+
|
|
142
|
+
Uri locationUri = createLocation(location);
|
|
143
|
+
|
|
144
|
+
location.setProvider("new test");
|
|
145
|
+
|
|
146
|
+
int rowsUpdated = mResolver.update(locationUri, location.toContentValues(), null, null);
|
|
147
|
+
assertEquals(1, rowsUpdated);
|
|
148
|
+
|
|
149
|
+
Cursor cursor = mResolver.query(locationUri, null, null, null,null);
|
|
150
|
+
assertEquals(1, cursor.getCount());
|
|
151
|
+
assertTrue(cursor.moveToFirst());
|
|
152
|
+
|
|
153
|
+
assertEquals("new test", cursor.getString(cursor.getColumnIndex(LocationEntry.COLUMN_NAME_PROVIDER)));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
private Uri createLocation(BackgroundLocation location) {
|
|
157
|
+
return mResolver.insert(mContentUri, location.toContentValues());
|
|
158
|
+
}
|
|
159
|
+
}
|