@josuelmm/cordova-background-geolocation 4.2.3 → 4.5.2
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 +11 -0
- package/CHANGELOG.md +261 -0
- package/README.md +306 -115
- package/android/CDVBackgroundGeolocation/src/main/java/com/marianhello/bgloc/cordova/ConfigMapper.java +34 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/tenforwardconsulting/bgloc/cordova/BackgroundGeolocationPlugin.java +61 -1
- package/android/common/src/main/AndroidManifest.xml +1 -1
- package/android/common/src/main/java/com/marianhello/bgloc/BootCompletedReceiver.java +20 -3
- package/android/common/src/main/java/com/marianhello/bgloc/Config.java +87 -1
- package/android/common/src/main/java/com/marianhello/bgloc/data/BackgroundLocation.java +94 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/ConfigJsonMapper.java +211 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/LocationTemplateFactory.java +6 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteConfigurationContract.java +5 -1
- package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteConfigurationDAO.java +32 -1
- package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteLocationContract.java +12 -2
- package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteLocationDAO.java +33 -2
- package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteOpenHelper.java +15 -1
- package/android/common/src/main/java/com/marianhello/bgloc/provider/AbstractLocationProvider.java +48 -1
- package/android/common/src/main/java/com/marianhello/bgloc/provider/ActivityRecognitionLocationProvider.java +105 -6
- package/android/common/src/main/java/com/marianhello/bgloc/provider/DistanceFilterLocationProvider.java +336 -250
- package/android/common/src/main/java/com/marianhello/bgloc/provider/RawLocationProvider.java +69 -19
- package/android/common/src/main/java/com/marianhello/bgloc/service/LocationServiceImpl.java +246 -21
- package/android/common/src/main/java/com/marianhello/bgloc/service/LocationServiceProxy.java +5 -2
- package/android/common/src/main/java/com/marianhello/bgloc/sync/BatchManager.java +46 -13
- package/ios/CDVBackgroundGeolocation/CDVBackgroundGeolocation.m +23 -1
- package/ios/common/BackgroundGeolocation/MAURActivityLocationProvider.m +208 -70
- package/ios/common/BackgroundGeolocation/MAURBackgroundGeolocationFacade.m +132 -5
- package/ios/common/BackgroundGeolocation/MAURBackgroundSync.m +20 -0
- package/ios/common/BackgroundGeolocation/MAURConfig.h +7 -0
- package/ios/common/BackgroundGeolocation/MAURConfig.m +37 -2
- package/ios/common/BackgroundGeolocation/MAURConfigurationContract.h +3 -0
- package/ios/common/BackgroundGeolocation/MAURConfigurationContract.m +3 -1
- package/ios/common/BackgroundGeolocation/MAURDistanceFilterLocationProvider.m +10 -1
- package/ios/common/BackgroundGeolocation/MAURGeolocationOpenHelper.m +15 -1
- package/ios/common/BackgroundGeolocation/MAURLocation.h +12 -0
- package/ios/common/BackgroundGeolocation/MAURLocation.m +33 -4
- package/ios/common/BackgroundGeolocation/MAURLocationContract.h +4 -0
- package/ios/common/BackgroundGeolocation/MAURLocationContract.m +5 -1
- package/ios/common/BackgroundGeolocation/MAURLocationManager.m +19 -1
- package/ios/common/BackgroundGeolocation/MAURPostLocationTask.h +9 -0
- package/ios/common/BackgroundGeolocation/MAURPostLocationTask.m +59 -1
- package/ios/common/BackgroundGeolocation/MAURRawLocationProvider.m +10 -1
- package/ios/common/BackgroundGeolocation/MAURSQLiteConfigurationDAO.m +54 -4
- package/ios/common/BackgroundGeolocation/MAURSQLiteLocationDAO.h +12 -0
- package/ios/common/BackgroundGeolocation/MAURSQLiteLocationDAO.m +125 -5
- package/package.json +31 -1
- package/plugin.xml +3 -10
- package/www/BackgroundGeolocation.d.ts +143 -3
- package/www/BackgroundGeolocation.js +11 -4
- package/CLAUDE.md +0 -56
- package/HISTORY.md +0 -871
- package/android/CDVBackgroundGeolocation/src/test/java/com/marianhello/ConfigMapperTest.java +0 -220
- package/android/common/src/androidTest/java/com/marianhello/bgloc/BackgroundGeolocationFacadeTest.java +0 -45
- package/android/common/src/androidTest/java/com/marianhello/bgloc/BatchManagerTest.java +0 -570
- package/android/common/src/androidTest/java/com/marianhello/bgloc/ConfigTest.java +0 -76
- package/android/common/src/androidTest/java/com/marianhello/bgloc/ContentProviderLocationDAOTest.java +0 -437
- package/android/common/src/androidTest/java/com/marianhello/bgloc/DBLogReaderTest.java +0 -95
- package/android/common/src/androidTest/java/com/marianhello/bgloc/LocationContentProviderTest.java +0 -159
- package/android/common/src/androidTest/java/com/marianhello/bgloc/LocationServiceProxyTest.java +0 -161
- package/android/common/src/androidTest/java/com/marianhello/bgloc/LocationServiceTest.java +0 -247
- package/android/common/src/androidTest/java/com/marianhello/bgloc/SQLiteConfigurationDAOTest.java +0 -200
- package/android/common/src/androidTest/java/com/marianhello/bgloc/SQLiteLocationDAOTest.java +0 -457
- package/android/common/src/androidTest/java/com/marianhello/bgloc/SQLiteLocationDAOThreadTest.java +0 -96
- package/android/common/src/androidTest/java/com/marianhello/bgloc/SQLiteOpenHelperTest.java +0 -225
- package/android/common/src/androidTest/java/com/marianhello/bgloc/TestPluginDelegate.java +0 -46
- package/android/common/src/androidTest/java/com/marianhello/bgloc/TestResourceResolver.java +0 -14
- package/android/common/src/androidTest/java/com/marianhello/bgloc/provider/MockLocationProvider.java +0 -50
- package/android/common/src/androidTest/java/com/marianhello/bgloc/provider/TestLocationProviderFactory.java +0 -17
- package/android/common/src/androidTest/java/com/marianhello/bgloc/sqlite/SQLiteOpenHelper10.java +0 -92
- package/android/common/src/androidTest/java/com/marianhello/bgloc/test/LocationProviderTestCase.java +0 -107
- package/android/common/src/androidTest/java/com/marianhello/bgloc/test/TestConstants.java +0 -5
- package/android/common/src/test/java/com/marianhello/backgroundgeolocation/ArrayListLocationTemplateTest.java +0 -82
- package/android/common/src/test/java/com/marianhello/backgroundgeolocation/BackgroundLocationTest.java +0 -128
- package/android/common/src/test/java/com/marianhello/backgroundgeolocation/ConfigTest.java +0 -191
- package/android/common/src/test/java/com/marianhello/backgroundgeolocation/DBLogReaderTest.java +0 -37
- package/android/common/src/test/java/com/marianhello/backgroundgeolocation/HashMapLocationTemplateTest.java +0 -216
- package/android/common/src/test/java/com/marianhello/backgroundgeolocation/HttpPostServiceTest.java +0 -223
- package/android/common/src/test/java/com/marianhello/backgroundgeolocation/LocationTemplateFactoryTest.java +0 -50
- package/android/common/src/test/java/com/marianhello/backgroundgeolocation/PostLocationTaskTest.java +0 -180
- package/android/common/src/test/java/com/marianhello/backgroundgeolocation/TestHelper.java +0 -16
- package/ios/common/BackgroundGeolocation/SOMotionDetector/CHANGELOG.md +0 -2
- package/ios/common/BackgroundGeolocation/SOMotionDetector/LICENSE +0 -21
- package/ios/common/BackgroundGeolocation/SOMotionDetector/README.md +0 -135
- package/ios/common/BackgroundGeolocation/SOMotionDetector/SOLocationManager.h +0 -80
- package/ios/common/BackgroundGeolocation/SOMotionDetector/SOLocationManager.m +0 -147
- package/ios/common/BackgroundGeolocation/SOMotionDetector/SOMotionActivity.h +0 -30
- package/ios/common/BackgroundGeolocation/SOMotionDetector/SOMotionActivity.m +0 -42
- package/ios/common/BackgroundGeolocation/SOMotionDetector/SOMotionDetector.h +0 -99
- package/ios/common/BackgroundGeolocation/SOMotionDetector/SOMotionDetector.m +0 -327
- package/ios/common/BackgroundGeolocation/SOMotionDetector/SOStepDetector.h +0 -44
- package/ios/common/BackgroundGeolocation/SOMotionDetector/SOStepDetector.m +0 -94
- package/ios/common/BackgroundGeolocationTests/Info.plist +0 -24
- package/ios/common/BackgroundGeolocationTests/MAURBackgroundLocationTest.m +0 -185
- package/ios/common/BackgroundGeolocationTests/MAURConfigTest.m +0 -161
- package/ios/common/BackgroundGeolocationTests/MAURGeolocationOpenHelperTest.m +0 -102
- package/ios/common/BackgroundGeolocationTests/MAURLocationTest.m +0 -216
- package/ios/common/BackgroundGeolocationTests/MAURLocationUploaderTest.m +0 -55
- package/ios/common/BackgroundGeolocationTests/MAURLogReaderTest.m +0 -43
- package/ios/common/BackgroundGeolocationTests/MAURSQLiteConfigurationDAOTest.m +0 -102
- package/ios/common/BackgroundGeolocationTests/MAURSQLiteHelperTest.m +0 -41
- package/ios/common/BackgroundGeolocationTests/MAURSQLiteLocationDAOTests.m +0 -240
- package/ios/common/BackgroundGeolocationTests/MAURSQLiteLocationDAOThreadTest.m +0 -84
- package/ios/common/BackgroundGeolocationTests/MAURSQLiteOpenHelperTest.m +0 -144
- package/ios/common/scripts/xcode-refactor.js +0 -184
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// MAURSQLiteHelperTest.m
|
|
3
|
-
// BackgroundGeolocationTests
|
|
4
|
-
//
|
|
5
|
-
// Created by Marian Hello on 27/06/16.
|
|
6
|
-
// Copyright © 2016 mauron85. All rights reserved.
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
#import <XCTest/XCTest.h>
|
|
10
|
-
#import "MAURSQLiteHelper.h"
|
|
11
|
-
|
|
12
|
-
@interface MAURSQLiteHelperTest : XCTestCase
|
|
13
|
-
|
|
14
|
-
@end
|
|
15
|
-
|
|
16
|
-
@implementation MAURSQLiteHelperTest
|
|
17
|
-
|
|
18
|
-
- (void)setUp {
|
|
19
|
-
[super setUp];
|
|
20
|
-
// Put setup code here. This method is called before the invocation of each test method in the class.
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
- (void)tearDown {
|
|
24
|
-
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
|
25
|
-
[super tearDown];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
- (void)testCreateTableSQLStatement {
|
|
29
|
-
NSString *tableName = @"TEST_TABLE";
|
|
30
|
-
NSArray *columns = @[
|
|
31
|
-
@{ @"name": @"pk_col", @"type": [SQLPrimaryKeyAutoIncColumnType sqlColumnWithType: kInteger]},
|
|
32
|
-
@{ @"name": @"text_col", @"type": [SQLColumnType sqlColumnWithType: kText]},
|
|
33
|
-
@{ @"name": @"real_col", @"type": [SQLColumnType sqlColumnWithType: kReal]},
|
|
34
|
-
@{ @"name": @"int_col", @"type": [SQLColumnType sqlColumnWithType: kInteger]}
|
|
35
|
-
];
|
|
36
|
-
NSString *sql = [MAURSQLiteHelper createTableSqlStatement:tableName columns:columns];
|
|
37
|
-
XCTAssertEqualObjects(sql, @"CREATE TABLE IF NOT EXISTS TEST_TABLE ( pk_col INTEGER PRIMARY KEY AUTOINCREMENT , text_col TEXT , real_col REAL , int_col INTEGER );");
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
@end
|
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// SQLiteLocationDAOTest.m
|
|
3
|
-
// BackgroundGeolocationTests
|
|
4
|
-
//
|
|
5
|
-
// Created by Marian Hello on 10/06/16.
|
|
6
|
-
// Copyright © 2016 mauron85. All rights reserved.
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
#import <XCTest/XCTest.h>
|
|
10
|
-
#import "MAURSQLiteLocationDAO.h"
|
|
11
|
-
|
|
12
|
-
@interface SQLiteLocationDAOTest : XCTestCase
|
|
13
|
-
|
|
14
|
-
@end
|
|
15
|
-
|
|
16
|
-
@implementation SQLiteLocationDAOTest
|
|
17
|
-
|
|
18
|
-
- (void)setUp {
|
|
19
|
-
[super setUp];
|
|
20
|
-
MAURSQLiteLocationDAO *locationDAO = [MAURSQLiteLocationDAO sharedInstance];
|
|
21
|
-
[locationDAO clearDatabase];
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
- (void)tearDown {
|
|
25
|
-
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
|
26
|
-
[super tearDown];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
- (void)testPersistLocation {
|
|
30
|
-
// This is an example of a functional test case.
|
|
31
|
-
// Use XCTAssert and related functions to verify your tests produce the correct results.
|
|
32
|
-
|
|
33
|
-
MAURSQLiteLocationDAO *locationDAO = [MAURSQLiteLocationDAO sharedInstance];
|
|
34
|
-
MAURLocation *location = [[MAURLocation alloc] init];
|
|
35
|
-
|
|
36
|
-
location.time = [NSDate dateWithTimeIntervalSince1970:1465511097774.577];
|
|
37
|
-
location.accuracy = [NSNumber numberWithDouble:5];
|
|
38
|
-
location.speed = [NSNumber numberWithDouble:31.67];
|
|
39
|
-
location.heading = [NSNumber numberWithDouble:298.83];
|
|
40
|
-
location.altitude = [NSNumber numberWithDouble:940];
|
|
41
|
-
location.latitude = [NSNumber numberWithDouble:37.35439853];
|
|
42
|
-
location.longitude = [NSNumber numberWithDouble:-122.1100721];
|
|
43
|
-
location.provider = @"TEST";
|
|
44
|
-
location.locationProvider = [NSNumber numberWithInt:-1];
|
|
45
|
-
|
|
46
|
-
NSNumber *locationId = [locationDAO persistLocation:location];
|
|
47
|
-
|
|
48
|
-
NSArray<MAURLocation*> *locations = [locationDAO getAllLocations];
|
|
49
|
-
MAURLocation *result = [locations firstObject];
|
|
50
|
-
|
|
51
|
-
XCTAssertTrue([locationId isEqualToNumber:[NSNumber numberWithInt:1]], @"LocationId is %lu expecting 1",(unsigned long)locationId);
|
|
52
|
-
XCTAssertEqual([locations count], 1, @"Number of stored location is %lu expecting 1", (unsigned long)[locations count]);
|
|
53
|
-
XCTAssertTrue([result.locationId isEqualToNumber:[NSNumber numberWithInt:1]], @"LocationId is %lu expecting 1",(unsigned long)result.locationId);
|
|
54
|
-
XCTAssertTrue([result.time isEqualToDate:[NSDate dateWithTimeIntervalSince1970:1465511097774.577]], "Location time is %@ expecting %@", result.time, [NSDate dateWithTimeIntervalSince1970:1465511097774.577]);
|
|
55
|
-
XCTAssertTrue([result.accuracy isEqualToNumber:[NSNumber numberWithDouble:5]], "Location accuracy is %@ expecting %@", result.accuracy, [NSNumber numberWithDouble:5]);
|
|
56
|
-
XCTAssertTrue([result.speed isEqualToNumber:[NSNumber numberWithDouble:31.67]], "Location speed is %@ expecting %@", result.speed, [NSNumber numberWithDouble:31.67]);
|
|
57
|
-
XCTAssertTrue([result.heading isEqualToNumber:[NSNumber numberWithDouble:298.83]], "Location heading is %@ expecting %@", result.heading, [NSNumber numberWithDouble:298.83]);
|
|
58
|
-
XCTAssertTrue([result.altitude isEqualToNumber:[NSNumber numberWithDouble:940]], "Location altitude is %@ expecting %@", result.altitude, [NSNumber numberWithDouble:940]);
|
|
59
|
-
XCTAssertTrue([result.latitude isEqualToNumber:[NSNumber numberWithDouble:37.35439853]], "Location latitude is %@ expecting %@", result.latitude, [NSNumber numberWithDouble:37.35439853]);
|
|
60
|
-
XCTAssertTrue([result.longitude isEqualToNumber:[NSNumber numberWithDouble:-122.1100721]], "Location longitude is %@ expecting %@", result.longitude, [NSNumber numberWithDouble:-122.1100721]);
|
|
61
|
-
XCTAssertTrue([result.provider isEqualToString:@"TEST"], @"Location provider is expected to be TEST");
|
|
62
|
-
XCTAssertTrue([result.locationProvider isEqualToNumber:[NSNumber numberWithInt:-1]], "Location service_provider is %@ expecting %@", result.locationProvider, [NSNumber numberWithInt:-1]);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
- (void)testDeleteLocation {
|
|
66
|
-
MAURSQLiteLocationDAO *locationDAO = [MAURSQLiteLocationDAO sharedInstance];
|
|
67
|
-
MAURLocation *location = [[MAURLocation alloc] init];
|
|
68
|
-
|
|
69
|
-
location.time = [NSDate dateWithTimeIntervalSince1970:1465511097774.577];
|
|
70
|
-
location.accuracy = [NSNumber numberWithDouble:5];
|
|
71
|
-
location.speed = [NSNumber numberWithDouble:31.67];
|
|
72
|
-
location.heading = [NSNumber numberWithDouble:298.83];
|
|
73
|
-
location.altitude = [NSNumber numberWithDouble:940];
|
|
74
|
-
location.latitude = [NSNumber numberWithDouble:37.35439853];
|
|
75
|
-
location.longitude = [NSNumber numberWithDouble:-122.1100721];
|
|
76
|
-
location.provider = @"TEST";
|
|
77
|
-
location.locationProvider = [NSNumber numberWithInt:-1];
|
|
78
|
-
|
|
79
|
-
NSNumber *locationId1 = [locationDAO persistLocation:location];
|
|
80
|
-
NSNumber *locationId2 = [locationDAO persistLocation:location];
|
|
81
|
-
|
|
82
|
-
NSArray<MAURLocation*> *locations = [locationDAO getAllLocations];
|
|
83
|
-
XCTAssertEqual([locations count], 2, @"Number of stored location is %lu expecting 2", (unsigned long)[locations count]);
|
|
84
|
-
|
|
85
|
-
[locationDAO deleteLocation:locationId1 error:nil];
|
|
86
|
-
locations = [locationDAO getValidLocations];
|
|
87
|
-
MAURLocation *result = [locations firstObject];
|
|
88
|
-
|
|
89
|
-
XCTAssertEqual([locations count], 1, @"Number of stored location is %lu expecting 1", (unsigned long)[locations count]);
|
|
90
|
-
XCTAssertTrue([result.locationId isEqualToNumber:locationId2], "LocationId is %@ expecting %@", result.locationId, locationId2);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
- (void)testDeleteAllLocations {
|
|
94
|
-
MAURSQLiteLocationDAO *locationDAO = [MAURSQLiteLocationDAO sharedInstance];
|
|
95
|
-
MAURLocation *location = [[MAURLocation alloc] init];
|
|
96
|
-
|
|
97
|
-
location.time = [NSDate dateWithTimeIntervalSince1970:1465511097774.577];
|
|
98
|
-
location.accuracy = [NSNumber numberWithDouble:5];
|
|
99
|
-
location.speed = [NSNumber numberWithDouble:31.67];
|
|
100
|
-
location.heading = [NSNumber numberWithDouble:298.83];
|
|
101
|
-
location.altitude = [NSNumber numberWithDouble:940];
|
|
102
|
-
location.latitude = [NSNumber numberWithDouble:37.35439853];
|
|
103
|
-
location.longitude = [NSNumber numberWithDouble:-122.1100721];
|
|
104
|
-
location.provider = @"TEST";
|
|
105
|
-
location.locationProvider = [NSNumber numberWithInt:-1];
|
|
106
|
-
|
|
107
|
-
[locationDAO persistLocation:location];
|
|
108
|
-
[locationDAO persistLocation:location];
|
|
109
|
-
[locationDAO persistLocation:location];
|
|
110
|
-
[locationDAO persistLocation:location];
|
|
111
|
-
[locationDAO persistLocation:location];
|
|
112
|
-
[locationDAO persistLocation:location];
|
|
113
|
-
[locationDAO persistLocation:location];
|
|
114
|
-
|
|
115
|
-
NSArray<MAURLocation*> *locations = [locationDAO getAllLocations];
|
|
116
|
-
XCTAssertEqual([locations count], 7, @"Number of stored location is %lu expecting 7", (unsigned long)[locations count]);
|
|
117
|
-
|
|
118
|
-
[locationDAO deleteAllLocations:nil];
|
|
119
|
-
locations = [locationDAO getValidLocations];
|
|
120
|
-
|
|
121
|
-
XCTAssertEqual([locations count], 0, @"Number of stored location is %lu expecting 0", (unsigned long)[locations count]);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
- (void)testGetAllLocations {
|
|
125
|
-
MAURSQLiteLocationDAO *locationDAO = [MAURSQLiteLocationDAO sharedInstance];
|
|
126
|
-
MAURLocation *location;
|
|
127
|
-
|
|
128
|
-
for (int i = 0; i < 10; i++) {
|
|
129
|
-
location = [[MAURLocation alloc] init];
|
|
130
|
-
location.time = [NSDate dateWithTimeIntervalSince1970:1465511097774.577+i];
|
|
131
|
-
location.accuracy = [NSNumber numberWithDouble:5+i];
|
|
132
|
-
location.speed = [NSNumber numberWithDouble:31.67+i];
|
|
133
|
-
location.heading = [NSNumber numberWithDouble:298.83+i];
|
|
134
|
-
location.altitude = [NSNumber numberWithDouble:940+i];
|
|
135
|
-
location.latitude = [NSNumber numberWithDouble:37.35439853+i];
|
|
136
|
-
location.longitude = [NSNumber numberWithDouble:-122.1100721+i];
|
|
137
|
-
location.provider = @"TEST";
|
|
138
|
-
location.locationProvider = [NSNumber numberWithInt:-1];
|
|
139
|
-
|
|
140
|
-
[locationDAO persistLocation:location];
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
NSArray<MAURLocation*> *locations = [locationDAO getAllLocations];
|
|
144
|
-
XCTAssertEqual([locations count], 10, @"Number of stored location is %lu expecting 10", (unsigned long)[locations count]);
|
|
145
|
-
|
|
146
|
-
for (int i = 0; i < 10; i++) {
|
|
147
|
-
MAURLocation *result = [locations objectAtIndex:i];
|
|
148
|
-
XCTAssertEqual([result.locationId intValue], i+1, "LocationId is %d expecting %d", [result.locationId intValue], i+1);
|
|
149
|
-
XCTAssertTrue([result.time isEqualToDate:[NSDate dateWithTimeIntervalSince1970:1465511097774.577+i]], "Location time is %@ expecting %@", result.time, [NSDate dateWithTimeIntervalSince1970:1465511097774.577+i]);
|
|
150
|
-
XCTAssertTrue([result.accuracy isEqualToNumber:[NSNumber numberWithDouble:5+i]], "Location accuracy is %@ expecting %@", result.accuracy, [NSNumber numberWithDouble:5+i]);
|
|
151
|
-
XCTAssertTrue([result.speed isEqualToNumber:[NSNumber numberWithDouble:31.67+i]], "Location speed is %@ expecting %@", result.speed, [NSNumber numberWithDouble:31.67+i]);
|
|
152
|
-
XCTAssertTrue([result.heading isEqualToNumber:[NSNumber numberWithDouble:298.83+i]], "Location heading is %@ expecting %@", result.heading, [NSNumber numberWithDouble:298.83+i]);
|
|
153
|
-
XCTAssertTrue([result.altitude isEqualToNumber:[NSNumber numberWithDouble:940+i]], "Location altitude is %@ expecting %@", result.altitude, [NSNumber numberWithDouble:940+i]);
|
|
154
|
-
XCTAssertTrue([result.latitude isEqualToNumber:[NSNumber numberWithDouble:37.35439853+i]], "Location latitude is %@ expecting %@", result.latitude, [NSNumber numberWithDouble:37.35439853+i]);
|
|
155
|
-
XCTAssertTrue([result.longitude isEqualToNumber:[NSNumber numberWithDouble:-122.1100721+i]], "Location longitude is %@ expecting %@", result.longitude, [NSNumber numberWithDouble:-122.1100721+i]);
|
|
156
|
-
XCTAssertTrue([result.provider isEqualToString:@"TEST"], @"Location provider is expected to be TEST");
|
|
157
|
-
XCTAssertTrue([result.locationProvider isEqualToNumber:[NSNumber numberWithInt:-1]], "Location service_provider is %@ expecting %@", result.locationProvider, [NSNumber numberWithInt:-1]);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
- (void)testGetValidLocations {
|
|
162
|
-
MAURSQLiteLocationDAO *locationDAO = [MAURSQLiteLocationDAO sharedInstance];
|
|
163
|
-
MAURLocation *location;
|
|
164
|
-
|
|
165
|
-
for (int i = 0; i < 10; i++) {
|
|
166
|
-
location = [[MAURLocation alloc] init];
|
|
167
|
-
location.time = [NSDate dateWithTimeIntervalSince1970:1465511097774.577+i];
|
|
168
|
-
location.accuracy = [NSNumber numberWithDouble:5+i];
|
|
169
|
-
location.speed = [NSNumber numberWithDouble:31.67+i];
|
|
170
|
-
location.heading = [NSNumber numberWithDouble:298.83+i];
|
|
171
|
-
location.altitude = [NSNumber numberWithDouble:940+i];
|
|
172
|
-
location.latitude = [NSNumber numberWithDouble:37.35439853+i];
|
|
173
|
-
location.longitude = [NSNumber numberWithDouble:-122.1100721+i];
|
|
174
|
-
location.provider = @"TEST";
|
|
175
|
-
location.locationProvider = [NSNumber numberWithInt:-1];
|
|
176
|
-
location.isValid = (i % 2) == 0;
|
|
177
|
-
|
|
178
|
-
[locationDAO persistLocation:location];
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
NSArray<MAURLocation*> *validLocations = [locationDAO getValidLocations];
|
|
182
|
-
XCTAssertEqual([validLocations count], 5, @"Number of valid location is %lu expecting 5", (unsigned long)[validLocations count]);
|
|
183
|
-
|
|
184
|
-
NSArray<MAURLocation*> *locations = [locationDAO getAllLocations];
|
|
185
|
-
XCTAssertEqual([locations count], 10, @"Number of stored location is %lu expecting 10", (unsigned long)[locations count]);
|
|
186
|
-
|
|
187
|
-
for (int i = 0; i < 10; i++) {
|
|
188
|
-
MAURLocation *result = [locations objectAtIndex:i];
|
|
189
|
-
if ((i % 2) == 0) {
|
|
190
|
-
XCTAssertTrue(result.isValid);
|
|
191
|
-
} else {
|
|
192
|
-
XCTAssertFalse(result.isValid);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
- (void)testPersistLocationWithZeroRowLimit {
|
|
198
|
-
int maxRows = 0;
|
|
199
|
-
MAURSQLiteLocationDAO *locationDAO = [MAURSQLiteLocationDAO sharedInstance];
|
|
200
|
-
|
|
201
|
-
for (int i = 0; i < maxRows * 2; i++) {
|
|
202
|
-
[locationDAO persistLocation:nil limitRows:maxRows];
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
NSArray<MAURLocation*> *locations = [locationDAO getAllLocations];
|
|
206
|
-
XCTAssertEqual([locations count], maxRows, @"Number of stored location is %lu expecting 0", (unsigned long)[locations count]);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
- (void)testPersistLocationWithRowLimit {
|
|
210
|
-
int maxRows = 100;
|
|
211
|
-
MAURSQLiteLocationDAO *locationDAO = [MAURSQLiteLocationDAO sharedInstance];
|
|
212
|
-
|
|
213
|
-
NSNumber *locationId = nil;
|
|
214
|
-
for (int i = 1; i <= maxRows * 2; i++) {
|
|
215
|
-
locationId = [locationDAO persistLocation:nil limitRows:maxRows];
|
|
216
|
-
XCTAssertTrue([locationId isEqualToNumber:[NSNumber numberWithInt:i > 100 ? i - 100 : i]], @"LocationId is %@ expecting %i", locationId, i);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
NSArray<MAURLocation*> *locations = [locationDAO getAllLocations];
|
|
220
|
-
XCTAssertEqual([locations count], maxRows, @"Number of stored location is %lu expecting 100", (unsigned long)[locations count]);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
- (void)testPersistLocationWithRowLimitWhenMaxRowsReduced {
|
|
224
|
-
NSInteger maxRowsRun[2] = {100, 10};
|
|
225
|
-
MAURSQLiteLocationDAO *locationDAO = [MAURSQLiteLocationDAO sharedInstance];
|
|
226
|
-
|
|
227
|
-
for (int i = 0; i < sizeof(maxRowsRun) / sizeof(NSInteger); i++) {
|
|
228
|
-
NSInteger maxRows = maxRowsRun[i];
|
|
229
|
-
for (int i = 0; i < maxRows * 2; i++) {
|
|
230
|
-
[locationDAO persistLocation:nil limitRows:maxRows];
|
|
231
|
-
}
|
|
232
|
-
NSArray<MAURLocation*> *locations = [locationDAO getAllLocations];
|
|
233
|
-
XCTAssertEqual([locations count], maxRows, @"Number of stored location is %lu expecting %ld", (unsigned long)[locations count], (long)maxRows);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
NSNumber *locationId = [locationDAO persistLocation:nil];
|
|
237
|
-
XCTAssertTrue([locationId isEqualToNumber:[NSNumber numberWithInt:101]], @"Expecting primary key id to be 101 actual %@", locationId);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
@end
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// BackgroundGeolocationTest.m
|
|
3
|
-
// BackgroundGeolocationTests
|
|
4
|
-
//
|
|
5
|
-
// Created by Marian Hello on 10/06/16.
|
|
6
|
-
// Copyright © 2016 mauron85. All rights reserved.
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
#import <XCTest/XCTest.h>
|
|
10
|
-
#import "MAURSQLiteLocationDAO.h"
|
|
11
|
-
|
|
12
|
-
@interface PersistLocationInThread : NSObject
|
|
13
|
-
{
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
// class methods go here
|
|
17
|
-
- (void) noop;
|
|
18
|
-
- (void) persistLocation:(NSNumber *)value;
|
|
19
|
-
@end
|
|
20
|
-
|
|
21
|
-
@interface MAURSQLiteLocationDAOThreadTest : XCTestCase
|
|
22
|
-
|
|
23
|
-
@end
|
|
24
|
-
|
|
25
|
-
@implementation MAURSQLiteLocationDAOThreadTest
|
|
26
|
-
|
|
27
|
-
- (void)setUp {
|
|
28
|
-
[super setUp];
|
|
29
|
-
MAURSQLiteLocationDAO *locationDAO = [MAURSQLiteLocationDAO sharedInstance];
|
|
30
|
-
[locationDAO clearDatabase];
|
|
31
|
-
// Put setup code here. This method is called before the invocation of each test method in the class.
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
- (void)tearDown {
|
|
35
|
-
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
|
36
|
-
[super tearDown];
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
- (void)testGetAllLocationsMultiThread {
|
|
40
|
-
MAURSQLiteLocationDAO *locationDAO = [MAURSQLiteLocationDAO sharedInstance];
|
|
41
|
-
long unsigned threadsCount = 100;
|
|
42
|
-
|
|
43
|
-
dispatch_queue_t queue = dispatch_queue_create("com.marianhello.SQLiteLocationDAOThreadTests", DISPATCH_QUEUE_CONCURRENT);
|
|
44
|
-
dispatch_group_t group = dispatch_group_create();
|
|
45
|
-
|
|
46
|
-
for (int i = 0; i < threadsCount; i++) {
|
|
47
|
-
dispatch_group_async(group, queue, ^{
|
|
48
|
-
MAURLocation *location = [[MAURLocation alloc] init];
|
|
49
|
-
location.time = [NSDate dateWithTimeIntervalSince1970:100+i];
|
|
50
|
-
location.accuracy = [NSNumber numberWithDouble:i];
|
|
51
|
-
location.speed = [NSNumber numberWithDouble:32+i];
|
|
52
|
-
location.heading = [NSNumber numberWithDouble:200+i];
|
|
53
|
-
location.altitude = [NSNumber numberWithDouble:940+i];
|
|
54
|
-
location.latitude = [NSNumber numberWithDouble:37+i];
|
|
55
|
-
location.longitude = [NSNumber numberWithDouble:-22+i];
|
|
56
|
-
location.provider = @"TEST";
|
|
57
|
-
location.locationProvider = [NSNumber numberWithInt:-1];
|
|
58
|
-
|
|
59
|
-
[locationDAO persistLocation:location];
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
|
|
64
|
-
|
|
65
|
-
NSMutableArray *locations = [NSMutableArray arrayWithArray:[locationDAO getAllLocations]];
|
|
66
|
-
[locations sortUsingDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@"time" ascending:YES]]];
|
|
67
|
-
|
|
68
|
-
XCTAssertEqual([locations count], threadsCount, @"Number of stored location is %lu expecting %lu", (unsigned long)[locations count], threadsCount);
|
|
69
|
-
|
|
70
|
-
for (int i = 0; i < threadsCount; i++) {
|
|
71
|
-
MAURLocation *result = [locations objectAtIndex:i];
|
|
72
|
-
XCTAssertTrue([result.time isEqualToDate:[NSDate dateWithTimeIntervalSince1970:100+i]], "time is %@ expecting %@", result.time, [NSDate dateWithTimeIntervalSince1970:100+i]);
|
|
73
|
-
XCTAssertTrue([result.accuracy isEqualToNumber:[NSNumber numberWithDouble:i]], "accuracy is %@ expecting %@", result.accuracy, [NSNumber numberWithDouble:i]);
|
|
74
|
-
XCTAssertTrue([result.speed isEqualToNumber:[NSNumber numberWithDouble:32+i]], "speed is %@ expecting %@", result.speed, [NSNumber numberWithDouble:32+i]);
|
|
75
|
-
XCTAssertTrue([result.heading isEqualToNumber:[NSNumber numberWithDouble:200+i]], "heading is %@ expecting %@", result.heading, [NSNumber numberWithDouble:200+i]);
|
|
76
|
-
XCTAssertTrue([result.altitude isEqualToNumber:[NSNumber numberWithDouble:940+i]], "altitude is %@ expecting %@", result.altitude, [NSNumber numberWithDouble:940+i]);
|
|
77
|
-
XCTAssertTrue([result.latitude isEqualToNumber:[NSNumber numberWithDouble:37+i]], "latitude is %@ expecting %@", result.latitude, [NSNumber numberWithDouble:37+i]);
|
|
78
|
-
XCTAssertTrue([result.longitude isEqualToNumber:[NSNumber numberWithDouble:-22+i]], "longitude is %@ expecting %@", result.longitude, [NSNumber numberWithDouble:-22+i]);
|
|
79
|
-
XCTAssertTrue([result.provider isEqualToString:@"TEST"], @"provider is expected to be TEST");
|
|
80
|
-
XCTAssertTrue([result.locationProvider isEqualToNumber:[NSNumber numberWithInt:-1]], "service_provider is %@ expecting %@", result.locationProvider, [NSNumber numberWithInt:-1]);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
@end
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// MAURSQLiteOpenHelperTest.m
|
|
3
|
-
// BackgroundGeolocationTests
|
|
4
|
-
//
|
|
5
|
-
// Created by Marian Hello on 01/07/16.
|
|
6
|
-
// Copyright © 2016 mauron85. All rights reserved.
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
#import <XCTest/XCTest.h>
|
|
10
|
-
#import "MAURSQLiteHelper.h"
|
|
11
|
-
#import "MAURSQLiteOpenHelper.h"
|
|
12
|
-
|
|
13
|
-
@interface MockCreateOpenHelper : MAURSQLiteOpenHelper
|
|
14
|
-
@property (readwrite, nonatomic) BOOL wasCreated;
|
|
15
|
-
- (void) onCreate:(FMDatabase*)database;
|
|
16
|
-
@end
|
|
17
|
-
|
|
18
|
-
@implementation MockCreateOpenHelper : MAURSQLiteOpenHelper
|
|
19
|
-
- (instancetype)init
|
|
20
|
-
{
|
|
21
|
-
self = [super init:@"geolocationtest.db" version:1];
|
|
22
|
-
self.wasCreated = NO;
|
|
23
|
-
return self;
|
|
24
|
-
}
|
|
25
|
-
- (void) onCreate:(FMDatabase*)database
|
|
26
|
-
{
|
|
27
|
-
self.wasCreated = YES;
|
|
28
|
-
}
|
|
29
|
-
@end
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
@interface MockUpgradeOpenHelper : MAURSQLiteOpenHelper
|
|
33
|
-
@property (readwrite, nonatomic) BOOL wasUpgraded;
|
|
34
|
-
- (void) onUpgrade:(FMDatabase*)database fromVersion:(NSInteger)oldVersion toVersion:(NSInteger)newVersion;
|
|
35
|
-
@end
|
|
36
|
-
|
|
37
|
-
@implementation MockUpgradeOpenHelper : MAURSQLiteOpenHelper
|
|
38
|
-
- (instancetype)init
|
|
39
|
-
{
|
|
40
|
-
self = [super init:@"geolocationtest.db" version:2];
|
|
41
|
-
self.wasUpgraded = NO;
|
|
42
|
-
return self;
|
|
43
|
-
}
|
|
44
|
-
- (void) onUpgrade:(FMDatabase*)database fromVersion:(NSInteger)oldVersion toVersion:(NSInteger)newVersion
|
|
45
|
-
{
|
|
46
|
-
self.wasUpgraded = YES;
|
|
47
|
-
}
|
|
48
|
-
@end
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
@interface MockDowngradeOpenHelper : MAURSQLiteOpenHelper
|
|
52
|
-
@property (readwrite, nonatomic) BOOL wasDowngraded;
|
|
53
|
-
- (void) onDowngrade:(FMDatabase*)database fromVersion:(NSInteger)oldVersion toVersion:(NSInteger)newVersion;
|
|
54
|
-
@end
|
|
55
|
-
|
|
56
|
-
@implementation MockDowngradeOpenHelper : MAURSQLiteOpenHelper
|
|
57
|
-
- (instancetype)init
|
|
58
|
-
{
|
|
59
|
-
self = [super init:@"geolocationtest.db" version:1];
|
|
60
|
-
self.wasDowngraded = NO;
|
|
61
|
-
return self;
|
|
62
|
-
}
|
|
63
|
-
- (void) onDowngrade:(FMDatabase*)database fromVersion:(NSInteger)oldVersion toVersion:(NSInteger)newVersion
|
|
64
|
-
{
|
|
65
|
-
self.wasDowngraded = YES;
|
|
66
|
-
}
|
|
67
|
-
@end
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
@interface MAURSQLiteOpenHelperTest : XCTestCase
|
|
71
|
-
|
|
72
|
-
@end
|
|
73
|
-
|
|
74
|
-
@implementation MAURSQLiteOpenHelperTest
|
|
75
|
-
|
|
76
|
-
- (void)setUp {
|
|
77
|
-
[super setUp];
|
|
78
|
-
MockCreateOpenHelper *helper = [[MockCreateOpenHelper alloc] init];
|
|
79
|
-
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
80
|
-
NSString *dbPath = [helper getDatabasePath];
|
|
81
|
-
[fileManager removeItemAtPath:dbPath error:nil];
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
- (void)tearDown {
|
|
85
|
-
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
|
86
|
-
[super tearDown];
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
- (void)testIfDbIsCreated {
|
|
90
|
-
MockCreateOpenHelper *helper = [[MockCreateOpenHelper alloc] init];
|
|
91
|
-
[helper getWritableDatabase];
|
|
92
|
-
[helper close];
|
|
93
|
-
NSDictionary *meta = [helper getDatabaseMetadata];
|
|
94
|
-
NSLog(@"meta %@ %@ %@", meta[@"dbVersion"], meta[@"created"], meta[@"last_updated"]);
|
|
95
|
-
XCTAssertEqual([[meta valueForKey:@"dbVersion"] integerValue], 1);
|
|
96
|
-
XCTAssertTrue(helper.wasCreated);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
- (void)testIfDbIsUpgraded {
|
|
100
|
-
MAURSQLiteOpenHelper *helper;
|
|
101
|
-
|
|
102
|
-
// first create empty db version 1
|
|
103
|
-
helper = [[MockCreateOpenHelper alloc] init];
|
|
104
|
-
[helper getWritableDatabase];
|
|
105
|
-
[helper close];
|
|
106
|
-
|
|
107
|
-
// now upgrade to version 2
|
|
108
|
-
helper = [[MockUpgradeOpenHelper alloc] init];
|
|
109
|
-
[helper getWritableDatabase];
|
|
110
|
-
[helper close];
|
|
111
|
-
NSDictionary *meta = [helper getDatabaseMetadata];
|
|
112
|
-
NSLog(@"meta %@ %@ %@", meta[@"dbVersion"], meta[@"created"], meta[@"last_updated"]);
|
|
113
|
-
XCTAssertEqual([[meta valueForKey:@"dbVersion"] integerValue], 2);
|
|
114
|
-
XCTAssertTrue(((MockUpgradeOpenHelper*)helper).wasUpgraded);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
- (void)testIfDbIsDowngraded {
|
|
118
|
-
MAURSQLiteOpenHelper *helper;
|
|
119
|
-
NSDictionary *meta;
|
|
120
|
-
|
|
121
|
-
// first create empty db version 1
|
|
122
|
-
helper = [[MockCreateOpenHelper alloc] init];
|
|
123
|
-
[helper getWritableDatabase];
|
|
124
|
-
[helper close];
|
|
125
|
-
|
|
126
|
-
// now upgrade to version 2
|
|
127
|
-
helper = [[MockUpgradeOpenHelper alloc] init];
|
|
128
|
-
[helper getWritableDatabase];
|
|
129
|
-
[helper close];
|
|
130
|
-
meta = [helper getDatabaseMetadata];
|
|
131
|
-
XCTAssertEqual([[meta valueForKey:@"dbVersion"] integerValue], 2);
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
helper = [[MockDowngradeOpenHelper alloc] init];
|
|
135
|
-
[helper getWritableDatabase];
|
|
136
|
-
[helper close];
|
|
137
|
-
meta = [helper getDatabaseMetadata];
|
|
138
|
-
NSLog(@"meta %@ %@ %@", meta[@"dbVersion"], meta[@"created"], meta[@"last_updated"]);
|
|
139
|
-
XCTAssertEqual([[meta valueForKey:@"dbVersion"] integerValue], 1);
|
|
140
|
-
XCTAssertTrue(((MockDowngradeOpenHelper*)helper).wasDowngraded);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
@end
|