@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,457 @@
|
|
|
1
|
+
package com.marianhello.bgloc;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import android.database.sqlite.SQLiteDatabase;
|
|
5
|
+
import android.location.Location;
|
|
6
|
+
import androidx.test.platform.app.InstrumentationRegistry;
|
|
7
|
+
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
|
8
|
+
import androidx.test.filters.SmallTest;
|
|
9
|
+
|
|
10
|
+
import com.marianhello.bgloc.data.BackgroundLocation;
|
|
11
|
+
import com.marianhello.bgloc.data.sqlite.SQLiteLocationDAO;
|
|
12
|
+
import com.marianhello.bgloc.data.sqlite.SQLiteOpenHelper;
|
|
13
|
+
|
|
14
|
+
import junit.framework.Assert;
|
|
15
|
+
|
|
16
|
+
import org.junit.Before;
|
|
17
|
+
import org.junit.Ignore;
|
|
18
|
+
import org.junit.Test;
|
|
19
|
+
import org.junit.runner.RunWith;
|
|
20
|
+
|
|
21
|
+
import java.util.ArrayList;
|
|
22
|
+
import java.util.Collection;
|
|
23
|
+
import java.util.Iterator;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Created by finch on 12/07/16.
|
|
27
|
+
*/
|
|
28
|
+
@Ignore
|
|
29
|
+
@RunWith(AndroidJUnit4.class)
|
|
30
|
+
@SmallTest
|
|
31
|
+
public class SQLiteLocationDAOTest {
|
|
32
|
+
|
|
33
|
+
@Before
|
|
34
|
+
public void deleteDatabase() {
|
|
35
|
+
Context ctx = InstrumentationRegistry.getTargetContext();
|
|
36
|
+
ctx.deleteDatabase(SQLiteOpenHelper.SQLITE_DATABASE_NAME);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@Test
|
|
40
|
+
public void persistLocation() {
|
|
41
|
+
Context ctx = InstrumentationRegistry.getTargetContext();
|
|
42
|
+
SQLiteDatabase db = new SQLiteOpenHelper(ctx).getWritableDatabase();
|
|
43
|
+
SQLiteLocationDAO dao = new SQLiteLocationDAO(db);
|
|
44
|
+
|
|
45
|
+
Location location = new Location("fake");
|
|
46
|
+
location.setAccuracy(200);
|
|
47
|
+
location.setAltitude(900);
|
|
48
|
+
location.setBearing(2);
|
|
49
|
+
location.setLatitude(40.21);
|
|
50
|
+
location.setLongitude(23.45);
|
|
51
|
+
location.setSpeed(20);
|
|
52
|
+
location.setProvider("test");
|
|
53
|
+
location.setTime(1000);
|
|
54
|
+
BackgroundLocation bgLocation = new BackgroundLocation(location);
|
|
55
|
+
|
|
56
|
+
dao.persistLocation(bgLocation);
|
|
57
|
+
|
|
58
|
+
ArrayList<BackgroundLocation> locations = new ArrayList(dao.getAllLocations());
|
|
59
|
+
Assert.assertEquals(1, locations.size());
|
|
60
|
+
|
|
61
|
+
BackgroundLocation storedLocation = locations.get(0);
|
|
62
|
+
Assert.assertEquals(200, storedLocation.getAccuracy(), 0);
|
|
63
|
+
Assert.assertEquals(900, storedLocation.getAltitude(), 0);
|
|
64
|
+
Assert.assertEquals(2, storedLocation.getBearing(), 0);
|
|
65
|
+
Assert.assertEquals(40.21, storedLocation.getLatitude(), 0);
|
|
66
|
+
Assert.assertEquals(23.45, storedLocation.getLongitude(), 0);
|
|
67
|
+
Assert.assertEquals(20, storedLocation.getSpeed(), 0);
|
|
68
|
+
Assert.assertEquals("test", storedLocation.getProvider(), "test");
|
|
69
|
+
Assert.assertEquals(1000, storedLocation.getTime(), 0);
|
|
70
|
+
Assert.assertFalse(storedLocation.hasMockLocationsEnabled());
|
|
71
|
+
Assert.assertFalse(storedLocation.areMockLocationsEnabled());
|
|
72
|
+
Assert.assertTrue(storedLocation.hasIsFromMockProvider()); // because setIsFromMockProvider is called in constructor
|
|
73
|
+
Assert.assertFalse(storedLocation.isFromMockProvider());
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
@Test
|
|
77
|
+
public void persistLocationIsMock() {
|
|
78
|
+
Context ctx = InstrumentationRegistry.getTargetContext();
|
|
79
|
+
SQLiteDatabase db = new SQLiteOpenHelper(ctx).getWritableDatabase();
|
|
80
|
+
SQLiteLocationDAO dao = new SQLiteLocationDAO(db);
|
|
81
|
+
|
|
82
|
+
BackgroundLocation bgLocation = new BackgroundLocation();
|
|
83
|
+
bgLocation.setMockLocationsEnabled(true);
|
|
84
|
+
bgLocation.setIsFromMockProvider(true);
|
|
85
|
+
|
|
86
|
+
dao.persistLocation(bgLocation);
|
|
87
|
+
|
|
88
|
+
ArrayList<BackgroundLocation> locations = new ArrayList(dao.getAllLocations());
|
|
89
|
+
Assert.assertEquals(1, locations.size());
|
|
90
|
+
|
|
91
|
+
BackgroundLocation storedLocation = locations.get(0);
|
|
92
|
+
Assert.assertTrue(storedLocation.hasMockLocationsEnabled());
|
|
93
|
+
Assert.assertTrue(storedLocation.areMockLocationsEnabled());
|
|
94
|
+
Assert.assertTrue(storedLocation.hasIsFromMockProvider());
|
|
95
|
+
Assert.assertTrue(storedLocation.isFromMockProvider());
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
@Test
|
|
99
|
+
public void deleteLocationById() {
|
|
100
|
+
Context ctx = InstrumentationRegistry.getTargetContext();
|
|
101
|
+
SQLiteDatabase db = new SQLiteOpenHelper(ctx).getWritableDatabase();
|
|
102
|
+
SQLiteLocationDAO dao = new SQLiteLocationDAO(db);
|
|
103
|
+
|
|
104
|
+
BackgroundLocation bgLocation = new BackgroundLocation(new Location("fake"));
|
|
105
|
+
Collection<BackgroundLocation> locations = null;
|
|
106
|
+
|
|
107
|
+
Long locationId = dao.persistLocation(bgLocation);
|
|
108
|
+
|
|
109
|
+
locations = dao.getAllLocations();
|
|
110
|
+
Assert.assertEquals(1, locations.size());
|
|
111
|
+
|
|
112
|
+
dao.deleteLocationById(locationId);
|
|
113
|
+
|
|
114
|
+
locations = dao.getValidLocations();
|
|
115
|
+
Assert.assertEquals(0, locations.size());
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
@Test
|
|
119
|
+
public void deleteAllLocations() {
|
|
120
|
+
Context ctx = InstrumentationRegistry.getTargetContext();
|
|
121
|
+
SQLiteDatabase db = new SQLiteOpenHelper(ctx).getWritableDatabase();
|
|
122
|
+
SQLiteLocationDAO dao = new SQLiteLocationDAO(db);
|
|
123
|
+
|
|
124
|
+
Collection<BackgroundLocation> locations = null;
|
|
125
|
+
|
|
126
|
+
for (int i = 0; i < 10; i++) {
|
|
127
|
+
dao.persistLocation(new BackgroundLocation(new Location("fake")));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
locations = dao.getValidLocations();
|
|
131
|
+
Assert.assertEquals(10, locations.size());
|
|
132
|
+
|
|
133
|
+
dao.deleteAllLocations();
|
|
134
|
+
|
|
135
|
+
locations = dao.getValidLocations();
|
|
136
|
+
Assert.assertEquals(0, locations.size());
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
@Test
|
|
140
|
+
public void getAllLocations() {
|
|
141
|
+
Context ctx = InstrumentationRegistry.getTargetContext();
|
|
142
|
+
SQLiteDatabase db = new SQLiteOpenHelper(ctx).getWritableDatabase();
|
|
143
|
+
SQLiteLocationDAO dao = new SQLiteLocationDAO(db);
|
|
144
|
+
|
|
145
|
+
Location location = null;
|
|
146
|
+
BackgroundLocation bgLocation = null;
|
|
147
|
+
|
|
148
|
+
for (int i = 0; i < 10; i++) {
|
|
149
|
+
location = new Location("fake");
|
|
150
|
+
location.setAccuracy(200 + i);
|
|
151
|
+
location.setAltitude(900 + i);
|
|
152
|
+
location.setBearing(2 + i);
|
|
153
|
+
location.setLatitude(40.21 + i);
|
|
154
|
+
location.setLongitude(23.45 + i);
|
|
155
|
+
location.setSpeed(20 + i);
|
|
156
|
+
location.setProvider("test");
|
|
157
|
+
location.setTime(1000 + i);
|
|
158
|
+
bgLocation = new BackgroundLocation(location);
|
|
159
|
+
dao.persistLocation(bgLocation);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
Collection<BackgroundLocation> locations = dao.getAllLocations();
|
|
163
|
+
Iterator<BackgroundLocation> it = locations.iterator();
|
|
164
|
+
BackgroundLocation storedLocation = null;
|
|
165
|
+
for (int i = 0; i < 10; i++) {
|
|
166
|
+
storedLocation = it.next();
|
|
167
|
+
Assert.assertEquals(200 + i, storedLocation.getAccuracy(), 0);
|
|
168
|
+
Assert.assertEquals(900 + i, storedLocation.getAltitude(), 0);
|
|
169
|
+
Assert.assertEquals(2 + i, storedLocation.getBearing(), 0);
|
|
170
|
+
Assert.assertEquals(40.21 + i, storedLocation.getLatitude(), 0);
|
|
171
|
+
Assert.assertEquals(23.45 + i,storedLocation.getLongitude(), 0);
|
|
172
|
+
Assert.assertEquals(20 + i, storedLocation.getSpeed(), 0);
|
|
173
|
+
Assert.assertEquals("test", storedLocation.getProvider());
|
|
174
|
+
Assert.assertEquals(1000 + i, storedLocation.getTime(), 0);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
@Test
|
|
179
|
+
public void persistLocationWithRowLimit() {
|
|
180
|
+
int maxRows = 100;
|
|
181
|
+
Context ctx = InstrumentationRegistry.getTargetContext();
|
|
182
|
+
SQLiteDatabase db = new SQLiteOpenHelper(ctx).getWritableDatabase();
|
|
183
|
+
SQLiteLocationDAO dao = new SQLiteLocationDAO(db);
|
|
184
|
+
|
|
185
|
+
for (int i = 0; i < maxRows * 2; i++) {
|
|
186
|
+
dao.persistLocation(new BackgroundLocation(new Location("fake")), maxRows);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
Collection<BackgroundLocation> locations = dao.getAllLocations();
|
|
190
|
+
Assert.assertEquals(maxRows, locations.size());
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
@Test
|
|
194
|
+
public void persistLocationWithRowLimitWhenMaxRowsReduced() {
|
|
195
|
+
int maxRowsRun[] = {100, 10};
|
|
196
|
+
Context ctx = InstrumentationRegistry.getTargetContext();
|
|
197
|
+
SQLiteDatabase db = new SQLiteOpenHelper(ctx).getWritableDatabase();
|
|
198
|
+
SQLiteLocationDAO dao = new SQLiteLocationDAO(db);
|
|
199
|
+
|
|
200
|
+
for (int i = 0; i < maxRowsRun.length; i++) {
|
|
201
|
+
int maxRows = maxRowsRun[i];
|
|
202
|
+
for (int j = 0; j < maxRows * 2; j++) {
|
|
203
|
+
dao.persistLocation(new BackgroundLocation(new Location("fake")), maxRows);
|
|
204
|
+
}
|
|
205
|
+
Collection<BackgroundLocation> locations = dao.getAllLocations();
|
|
206
|
+
Assert.assertEquals(maxRows, locations.size());
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
Long locationId = dao.persistLocation(new BackgroundLocation(new Location("fake")));
|
|
210
|
+
Assert.assertEquals(locationId, Long.valueOf(101));
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
@Test
|
|
214
|
+
public void persistLocationWithBatchId() {
|
|
215
|
+
Context ctx = InstrumentationRegistry.getTargetContext();
|
|
216
|
+
SQLiteDatabase db = new SQLiteOpenHelper(ctx).getWritableDatabase();
|
|
217
|
+
SQLiteLocationDAO dao = new SQLiteLocationDAO(db);
|
|
218
|
+
|
|
219
|
+
BackgroundLocation location = new BackgroundLocation();
|
|
220
|
+
location.setBatchStartMillis(1000L);
|
|
221
|
+
dao.persistLocation(location);
|
|
222
|
+
ArrayList<BackgroundLocation> locations = new ArrayList(dao.getAllLocations());
|
|
223
|
+
Assert.assertEquals(Long.valueOf(1000L), locations.get(0).getBatchStartMillis());
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
@Test
|
|
227
|
+
public void getLocationsForSyncCount() {
|
|
228
|
+
Context ctx = InstrumentationRegistry.getTargetContext();
|
|
229
|
+
SQLiteDatabase db = new SQLiteOpenHelper(ctx).getWritableDatabase();
|
|
230
|
+
SQLiteLocationDAO dao = new SQLiteLocationDAO(db);
|
|
231
|
+
|
|
232
|
+
BackgroundLocation location;
|
|
233
|
+
for (int i = 1; i < 100; i++) {
|
|
234
|
+
location = new BackgroundLocation();
|
|
235
|
+
if ((i % 3) == 0) {
|
|
236
|
+
// exactly 33 locations (out of 99) should be eligible for sync for given batch id 1000
|
|
237
|
+
location.setBatchStartMillis(1000L);
|
|
238
|
+
location.setStatus(BackgroundLocation.SYNC_PENDING);
|
|
239
|
+
} else if ((i % 2) == 0) {
|
|
240
|
+
// exactly 33 locations as deleted
|
|
241
|
+
location.setStatus(BackgroundLocation.DELETED);
|
|
242
|
+
} else {
|
|
243
|
+
location.setStatus(BackgroundLocation.SYNC_PENDING);
|
|
244
|
+
}
|
|
245
|
+
dao.persistLocation(location);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
Assert.assertEquals(66, dao.getValidLocations().size());
|
|
249
|
+
Assert.assertEquals(99, dao.getAllLocations().size());
|
|
250
|
+
Assert.assertEquals(66L, dao.getLocationsForSyncCount(10001L));
|
|
251
|
+
Assert.assertEquals(33L, dao.getLocationsForSyncCount(1000L));
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
@Test
|
|
255
|
+
public void getLocationById() {
|
|
256
|
+
Context ctx = InstrumentationRegistry.getTargetContext();
|
|
257
|
+
SQLiteDatabase db = new SQLiteOpenHelper(ctx).getWritableDatabase();
|
|
258
|
+
SQLiteLocationDAO dao = new SQLiteLocationDAO(db);
|
|
259
|
+
|
|
260
|
+
Location location = null;
|
|
261
|
+
BackgroundLocation bgLocation = null;
|
|
262
|
+
|
|
263
|
+
for (int i = 0; i < 10; i++) {
|
|
264
|
+
location = new Location("fake");
|
|
265
|
+
location.setAccuracy(200 + i);
|
|
266
|
+
location.setAltitude(900 + i);
|
|
267
|
+
location.setBearing(2 + i);
|
|
268
|
+
location.setLatitude(40.21 + i);
|
|
269
|
+
location.setLongitude(23.45 + i);
|
|
270
|
+
location.setSpeed(20 + i);
|
|
271
|
+
location.setProvider("test");
|
|
272
|
+
location.setTime(1000 + i);
|
|
273
|
+
bgLocation = new BackgroundLocation(location);
|
|
274
|
+
dao.persistLocation(bgLocation);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
BackgroundLocation pending = dao.getLocationById(2);
|
|
278
|
+
Assert.assertEquals(Long.valueOf(2), pending.getLocationId());
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
@Test
|
|
282
|
+
public void getFirstPendingLocation() {
|
|
283
|
+
Context ctx = InstrumentationRegistry.getTargetContext();
|
|
284
|
+
SQLiteDatabase db = new SQLiteOpenHelper(ctx).getWritableDatabase();
|
|
285
|
+
SQLiteLocationDAO dao = new SQLiteLocationDAO(db);
|
|
286
|
+
|
|
287
|
+
BackgroundLocation location = null;
|
|
288
|
+
|
|
289
|
+
for (int i = 1; i <= 5; i++) {
|
|
290
|
+
location = new BackgroundLocation();
|
|
291
|
+
location.setProvider("fake");
|
|
292
|
+
location.setAccuracy(200 + i);
|
|
293
|
+
location.setAltitude(900 + i);
|
|
294
|
+
location.setBearing(2 + i);
|
|
295
|
+
location.setLatitude(40.21 + i);
|
|
296
|
+
location.setLongitude(23.45 + i);
|
|
297
|
+
location.setSpeed(20 + i);
|
|
298
|
+
location.setProvider("test");
|
|
299
|
+
location.setTime(1000 + i);
|
|
300
|
+
if (i <= 3) {
|
|
301
|
+
location.setStatus(BackgroundLocation.DELETED);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
dao.persistLocation(location);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
BackgroundLocation pending = dao.getFirstUnpostedLocation();
|
|
308
|
+
Assert.assertEquals(Long.valueOf(4), pending.getLocationId());
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
@Test
|
|
312
|
+
public void getNextPendingLocation() {
|
|
313
|
+
Context ctx = InstrumentationRegistry.getTargetContext();
|
|
314
|
+
SQLiteDatabase db = new SQLiteOpenHelper(ctx).getWritableDatabase();
|
|
315
|
+
SQLiteLocationDAO dao = new SQLiteLocationDAO(db);
|
|
316
|
+
|
|
317
|
+
BackgroundLocation location = null;
|
|
318
|
+
|
|
319
|
+
for (int i = 1; i <= 5; i++) {
|
|
320
|
+
location = new BackgroundLocation();
|
|
321
|
+
location.setProvider("fake");
|
|
322
|
+
location.setAccuracy(200 + i);
|
|
323
|
+
location.setAltitude(900 + i);
|
|
324
|
+
location.setBearing(2 + i);
|
|
325
|
+
location.setLatitude(40.21 + i);
|
|
326
|
+
location.setLongitude(23.45 + i);
|
|
327
|
+
location.setSpeed(20 + i);
|
|
328
|
+
location.setProvider("test");
|
|
329
|
+
location.setTime(1000 + i);
|
|
330
|
+
if (i <= 3) {
|
|
331
|
+
location.setStatus(BackgroundLocation.DELETED);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
dao.persistLocation(location);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
BackgroundLocation pending = dao.getNextUnpostedLocation(4);
|
|
338
|
+
Assert.assertEquals(Long.valueOf(5), pending.getLocationId());
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
@Test
|
|
342
|
+
public void getPendingLocationsCount() {
|
|
343
|
+
Context ctx = InstrumentationRegistry.getTargetContext();
|
|
344
|
+
SQLiteDatabase db = new SQLiteOpenHelper(ctx).getWritableDatabase();
|
|
345
|
+
SQLiteLocationDAO dao = new SQLiteLocationDAO(db);
|
|
346
|
+
|
|
347
|
+
BackgroundLocation location = null;
|
|
348
|
+
|
|
349
|
+
for (int i = 0; i < 5; i++) {
|
|
350
|
+
location = new BackgroundLocation();
|
|
351
|
+
location.setProvider("fake");
|
|
352
|
+
location.setAccuracy(200 + i);
|
|
353
|
+
location.setAltitude(900 + i);
|
|
354
|
+
location.setBearing(2 + i);
|
|
355
|
+
location.setLatitude(40.21 + i);
|
|
356
|
+
location.setLongitude(23.45 + i);
|
|
357
|
+
location.setSpeed(20 + i);
|
|
358
|
+
location.setProvider("test");
|
|
359
|
+
location.setTime(1000 + i);
|
|
360
|
+
if (i < 3) {
|
|
361
|
+
location.setStatus(BackgroundLocation.DELETED);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
dao.persistLocation(location);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
Assert.assertEquals(2, dao.getUnpostedLocationsCount());
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
@Test
|
|
371
|
+
public void deleteFirstPendingLocation() {
|
|
372
|
+
Context ctx = InstrumentationRegistry.getTargetContext();
|
|
373
|
+
SQLiteDatabase db = new SQLiteOpenHelper(ctx).getWritableDatabase();
|
|
374
|
+
SQLiteLocationDAO dao = new SQLiteLocationDAO(db);
|
|
375
|
+
|
|
376
|
+
BackgroundLocation location = null;
|
|
377
|
+
|
|
378
|
+
for (int i = 1; i <= 5; i++) {
|
|
379
|
+
location = new BackgroundLocation();
|
|
380
|
+
location.setProvider("fake");
|
|
381
|
+
location.setAccuracy(200 + i);
|
|
382
|
+
location.setAltitude(900 + i);
|
|
383
|
+
location.setBearing(2 + i);
|
|
384
|
+
location.setLatitude(40.21 + i);
|
|
385
|
+
location.setLongitude(23.45 + i);
|
|
386
|
+
location.setSpeed(20 + i);
|
|
387
|
+
location.setProvider("test");
|
|
388
|
+
location.setTime(1000 + i);
|
|
389
|
+
if (i <= 3) {
|
|
390
|
+
location.setStatus(BackgroundLocation.DELETED);
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
dao.persistLocation(location);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
BackgroundLocation deleted = dao.deleteFirstUnpostedLocation();
|
|
397
|
+
Assert.assertEquals(Long.valueOf(4), deleted.getLocationId());
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
@Test
|
|
401
|
+
public void deletePendingLocations() {
|
|
402
|
+
Context ctx = InstrumentationRegistry.getTargetContext();
|
|
403
|
+
SQLiteDatabase db = new SQLiteOpenHelper(ctx).getWritableDatabase();
|
|
404
|
+
SQLiteLocationDAO dao = new SQLiteLocationDAO(db);
|
|
405
|
+
|
|
406
|
+
BackgroundLocation location = null;
|
|
407
|
+
|
|
408
|
+
for (int i = 0; i < 5; i++) {
|
|
409
|
+
location = new BackgroundLocation();
|
|
410
|
+
location.setProvider("fake");
|
|
411
|
+
location.setAccuracy(200 + i);
|
|
412
|
+
location.setAltitude(900 + i);
|
|
413
|
+
location.setBearing(2 + i);
|
|
414
|
+
location.setLatitude(40.21 + i);
|
|
415
|
+
location.setLongitude(23.45 + i);
|
|
416
|
+
location.setSpeed(20 + i);
|
|
417
|
+
location.setProvider("test");
|
|
418
|
+
location.setTime(1000 + i);
|
|
419
|
+
if (i < 3) {
|
|
420
|
+
location.setStatus(BackgroundLocation.DELETED);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
dao.persistLocation(location);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
dao.deleteUnpostedLocations();
|
|
427
|
+
Assert.assertEquals(0, dao.getUnpostedLocationsCount());
|
|
428
|
+
Assert.assertEquals(2, dao.getLocationsForSyncCount(0));
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
@Test
|
|
432
|
+
public void persistLocationForSync() {
|
|
433
|
+
Context ctx = InstrumentationRegistry.getTargetContext();
|
|
434
|
+
SQLiteDatabase db = new SQLiteOpenHelper(ctx).getWritableDatabase();
|
|
435
|
+
SQLiteLocationDAO dao = new SQLiteLocationDAO(db);
|
|
436
|
+
|
|
437
|
+
BackgroundLocation location = new BackgroundLocation();
|
|
438
|
+
location.setProvider("fake");
|
|
439
|
+
location.setAccuracy(200);
|
|
440
|
+
location.setAltitude(900);
|
|
441
|
+
location.setBearing(2);
|
|
442
|
+
location.setLatitude(40.21);
|
|
443
|
+
location.setLongitude(23.45);
|
|
444
|
+
location.setSpeed(20);
|
|
445
|
+
location.setProvider("test");
|
|
446
|
+
location.setTime(1000);
|
|
447
|
+
|
|
448
|
+
long locationId = dao.persistLocation(location);
|
|
449
|
+
location.setLocationId(locationId);
|
|
450
|
+
Assert.assertEquals(1, dao.getUnpostedLocationsCount());
|
|
451
|
+
Assert.assertEquals(0, dao.getLocationsForSyncCount(0));
|
|
452
|
+
|
|
453
|
+
dao.persistLocationForSync(location, 100);
|
|
454
|
+
Assert.assertEquals(0, dao.getUnpostedLocationsCount());
|
|
455
|
+
Assert.assertEquals(1, dao.getLocationsForSyncCount(0));
|
|
456
|
+
}
|
|
457
|
+
}
|
package/android/common/src/androidTest/java/com/marianhello/bgloc/SQLiteLocationDAOThreadTest.java
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
package com.marianhello.bgloc;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import android.database.sqlite.SQLiteDatabase;
|
|
5
|
+
import android.location.Location;
|
|
6
|
+
import androidx.test.platform.app.InstrumentationRegistry;
|
|
7
|
+
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
|
8
|
+
import androidx.test.filters.SmallTest;
|
|
9
|
+
|
|
10
|
+
import com.marianhello.bgloc.data.BackgroundLocation;
|
|
11
|
+
import com.marianhello.bgloc.data.sqlite.SQLiteLocationDAO;
|
|
12
|
+
import com.marianhello.bgloc.data.sqlite.SQLiteOpenHelper;
|
|
13
|
+
|
|
14
|
+
import junit.framework.Assert;
|
|
15
|
+
|
|
16
|
+
import org.junit.Before;
|
|
17
|
+
import org.junit.Ignore;
|
|
18
|
+
import org.junit.Test;
|
|
19
|
+
import org.junit.runner.RunWith;
|
|
20
|
+
|
|
21
|
+
import java.util.Collection;
|
|
22
|
+
import java.util.Iterator;
|
|
23
|
+
import java.util.concurrent.ExecutorService;
|
|
24
|
+
import java.util.concurrent.Executors;
|
|
25
|
+
import java.util.concurrent.TimeUnit;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Created by finch on 13/07/16.
|
|
29
|
+
*/
|
|
30
|
+
@Ignore
|
|
31
|
+
@RunWith(AndroidJUnit4.class)
|
|
32
|
+
@SmallTest
|
|
33
|
+
public class SQLiteLocationDAOThreadTest {
|
|
34
|
+
|
|
35
|
+
@Before
|
|
36
|
+
public void deleteDatabase() {
|
|
37
|
+
Context ctx = InstrumentationRegistry.getTargetContext();
|
|
38
|
+
ctx.deleteDatabase(SQLiteOpenHelper.SQLITE_DATABASE_NAME);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@Test
|
|
42
|
+
public void persistLocationFromMultipleThreads() {
|
|
43
|
+
int threadsCount = 100;
|
|
44
|
+
|
|
45
|
+
Context ctx = InstrumentationRegistry.getTargetContext();
|
|
46
|
+
SQLiteDatabase db = new SQLiteOpenHelper(ctx).getWritableDatabase();
|
|
47
|
+
final SQLiteLocationDAO dao = new SQLiteLocationDAO(db);
|
|
48
|
+
|
|
49
|
+
ExecutorService es = Executors.newCachedThreadPool();
|
|
50
|
+
for (int j = 0; j < threadsCount; j++) {
|
|
51
|
+
final int i = j;
|
|
52
|
+
es.execute(new Runnable() {
|
|
53
|
+
public void run() {
|
|
54
|
+
Location location = new Location("fake");
|
|
55
|
+
location.setAccuracy(200 + i);
|
|
56
|
+
location.setAltitude(900 + i);
|
|
57
|
+
location.setBearing(2 + i);
|
|
58
|
+
location.setLatitude(40.21 + i);
|
|
59
|
+
location.setLongitude(23.45 + i);
|
|
60
|
+
location.setSpeed(20 + i);
|
|
61
|
+
location.setProvider("test");
|
|
62
|
+
location.setTime(1000 + i);
|
|
63
|
+
BackgroundLocation bgLocation = new BackgroundLocation(location);
|
|
64
|
+
|
|
65
|
+
dao.persistLocation(bgLocation);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
es.shutdown();
|
|
70
|
+
try {
|
|
71
|
+
boolean finished = es.awaitTermination(1, TimeUnit.MINUTES);
|
|
72
|
+
} catch (InterruptedException e) {
|
|
73
|
+
e.printStackTrace();
|
|
74
|
+
Assert.fail("Test terminated. Operation toked too long.");
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
Collection<BackgroundLocation> locations = dao.getValidLocations();
|
|
78
|
+
Assert.assertEquals(threadsCount, locations.size());
|
|
79
|
+
|
|
80
|
+
int i = 0;
|
|
81
|
+
BackgroundLocation storedLocation = null;
|
|
82
|
+
Iterator<BackgroundLocation> it = locations.iterator();
|
|
83
|
+
while(it.hasNext()) {
|
|
84
|
+
storedLocation = it.next();
|
|
85
|
+
Assert.assertEquals(200 + i, storedLocation.getAccuracy(), 0);
|
|
86
|
+
Assert.assertEquals(900 + i, storedLocation.getAltitude(), 0);
|
|
87
|
+
Assert.assertEquals(2 + i, storedLocation.getBearing(), 0);
|
|
88
|
+
Assert.assertEquals(40.21 + i, storedLocation.getLatitude(), 0);
|
|
89
|
+
Assert.assertEquals(23.45 + i,storedLocation.getLongitude(), 0);
|
|
90
|
+
Assert.assertEquals(20 + i, storedLocation.getSpeed(), 0);
|
|
91
|
+
Assert.assertEquals("test", storedLocation.getProvider());
|
|
92
|
+
Assert.assertEquals(1000 + i, storedLocation.getTime(), 0);
|
|
93
|
+
i++;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|