Skip to content

Commit

Permalink
Merge pull request #1313 from Microsoft/develop
Browse files Browse the repository at this point in the history
Apple SDK release 1.13.2
  • Loading branch information
jaeklim authored Feb 20, 2019
2 parents b7b3154 + f423c0e commit ba06375
Show file tree
Hide file tree
Showing 23 changed files with 245 additions and 50 deletions.
2 changes: 1 addition & 1 deletion AppCenter.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'AppCenter'
s.version = '1.13.1'
s.version = '1.13.2'

s.summary = 'Visual Studio App Center is your continuous integration, delivery and learning solution for iOS and macOS apps.'
s.description = <<-DESC
Expand Down
8 changes: 8 additions & 0 deletions AppCenter/AppCenter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,9 @@
38641B051EB0F40800B2CE73 /* MSAppDelegateForwarderTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 38641B041EB0F40800B2CE73 /* MSAppDelegateForwarderTests.m */; };
386A69ED1FD8843D0057B316 /* MSKeychainUtilPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 386A69EC1FD8843D0057B316 /* MSKeychainUtilPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
386E8D931E25932100EECF0F /* MSHttpTestUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 386E8D911E25932100EECF0F /* MSHttpTestUtil.m */; };
387A7FCB22178E92008A5587 /* MSReachabilityTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 387A7FCA22178E91008A5587 /* MSReachabilityTests.m */; };
387A7FCC22178E92008A5587 /* MSReachabilityTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 387A7FCA22178E91008A5587 /* MSReachabilityTests.m */; };
387A7FCD22178E92008A5587 /* MSReachabilityTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 387A7FCA22178E91008A5587 /* MSReachabilityTests.m */; };
387C75811D6270A300D68CC1 /* MSServiceAbstractInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 387C757F1D6270A300D68CC1 /* MSServiceAbstractInternal.h */; };
387C758F1D64E50800D68CC1 /* MSServiceCommon.h in Headers */ = {isa = PBXBuildFile; fileRef = 387C758D1D64DF2500D68CC1 /* MSServiceCommon.h */; };
387C75961D64EE1900D68CC1 /* MSServiceAbstractTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 387C75951D64EE1900D68CC1 /* MSServiceAbstractTests.m */; };
Expand Down Expand Up @@ -1009,6 +1012,7 @@
386A69EC1FD8843D0057B316 /* MSKeychainUtilPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MSKeychainUtilPrivate.h; sourceTree = "<group>"; };
386E8D911E25932100EECF0F /* MSHttpTestUtil.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MSHttpTestUtil.m; sourceTree = "<group>"; };
386E8D921E25932100EECF0F /* MSHttpTestUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MSHttpTestUtil.h; sourceTree = "<group>"; };
387A7FCA22178E91008A5587 /* MSReachabilityTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MSReachabilityTests.m; sourceTree = "<group>"; };
387C757F1D6270A300D68CC1 /* MSServiceAbstractInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = MSServiceAbstractInternal.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
387C758D1D64DF2500D68CC1 /* MSServiceCommon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = MSServiceCommon.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
387C75951D64EE1900D68CC1 /* MSServiceAbstractTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = MSServiceAbstractTests.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
Expand Down Expand Up @@ -1615,6 +1619,7 @@
04A79A4720C6F635006D0072 /* MSOneCollectorIngestionTests.m */,
B29D884621E9286100EAF084 /* MSOrderedDictionaryTest.m */,
04B7BBEE1E5FAD4D001A0CE1 /* MSIngestionUtilTests.m */,
387A7FCA22178E91008A5587 /* MSReachabilityTests.m */,
387C75951D64EE1900D68CC1 /* MSServiceAbstractTests.m */,
0493783F1FE4913C000ADBAF /* MSSessionContextTests.m */,
D36136821E7BB338004AE043 /* MSStoragePerformanceTests.m */,
Expand Down Expand Up @@ -2616,6 +2621,7 @@
0446DF0D1F3B864600C8E338 /* MSLogDBStorageTests.m in Sources */,
9CE97B2D21A4C0BC00A1B160 /* MSUserIdContextTests.m in Sources */,
35DFC2302170044A00455589 /* MSBooleanTypedPropertyTests.m in Sources */,
387A7FCD22178E92008A5587 /* MSReachabilityTests.m in Sources */,
04A79A4B20C6F63F006D0072 /* MSOneCollectorIngestionTests.m in Sources */,
384A92632188BE400099BE70 /* MSDelegateForwarderTestUtil.m in Sources */,
04B45C5321E90F2400FE6746 /* MSStorageTestUtil.m in Sources */,
Expand Down Expand Up @@ -2674,6 +2680,7 @@
35DFC2322170051000455589 /* MSDateTimeTypedPropertyTests.m in Sources */,
046AEADD1ECA562A00CBE511 /* MSHttpTestUtil.m in Sources */,
046AEADE1ECA562A00CBE511 /* MSDeviceHistoryInfoTests.m in Sources */,
387A7FCC22178E92008A5587 /* MSReachabilityTests.m in Sources */,
04A140881ECE63BF001CEE94 /* MSAppCenterTests.m in Sources */,
35DFC23C2170052900455589 /* MSStringTypedPropertyTests.m in Sources */,
04B45C5221E90F2200FE6746 /* MSStorageTestUtil.m in Sources */,
Expand Down Expand Up @@ -2882,6 +2889,7 @@
386E8D931E25932100EECF0F /* MSHttpTestUtil.m in Sources */,
B2FD53651E567BCF0050F909 /* MSDeviceHistoryInfoTests.m in Sources */,
35DFC2382170051F00455589 /* MSLongTypedPropertyTests.m in Sources */,
387A7FCB22178E92008A5587 /* MSReachabilityTests.m in Sources */,
380A4DCB1DD6908A00E99219 /* MSUtilityTests.m in Sources */,
04A79A4920C6F63C006D0072 /* MSOneCollectorIngestionTests.m in Sources */,
04B45C5121E90F2000FE6746 /* MSStorageTestUtil.m in Sources */,
Expand Down
23 changes: 14 additions & 9 deletions AppCenter/AppCenter/Internals/Storage/MSDBStorage.m
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ + (BOOL)tableExists:(NSString *)tableName inOpenedDatabase:(void *)db {
NSString *query =
[NSString stringWithFormat:@"SELECT COUNT(*) FROM \"sqlite_master\" WHERE \"type\"='table' AND \"name\"='%@';", tableName];
NSArray<NSArray *> *result = [MSDBStorage executeSelectionQuery:query inOpenedDatabase:db];
return (result.count > 0) ? [(NSNumber *)result[0][0] boolValue] : NO;
return result.count > 0 && result[0].count > 0 ? [(NSNumber *)result[0][0] boolValue] : NO;
}

+ (NSUInteger)versionInOpenedDatabase:(void *)db {
NSArray<NSArray *> *result = [MSDBStorage executeSelectionQuery:@"PRAGMA user_version" inOpenedDatabase:db];
return (result.count > 0) ? [(NSNumber *)result[0][0] unsignedIntegerValue] : 0;
return result.count > 0 && result[0].count > 0 ? [(NSNumber *)result[0][0] unsignedIntegerValue] : 0;
}

+ (void)setVersion:(NSUInteger)version inOpenedDatabase:(void *)db {
Expand All @@ -126,7 +126,10 @@ + (void)setVersion:(NSUInteger)version inOpenedDatabase:(void *)db {

+ (void)enableAutoVacuumInOpenedDatabase:(void *)db {
NSArray<NSArray *> *result = [MSDBStorage executeSelectionQuery:@"PRAGMA auto_vacuum" inOpenedDatabase:db];
int vacuumMode = [(NSNumber *)result[0][0] intValue];
int vacuumMode = 0;
if (result.count > 0 && result[0].count > 0){
vacuumMode = [(NSNumber *)result[0][0] intValue];
}
BOOL autoVacuumDisabled = vacuumMode != 1;

/*
Expand Down Expand Up @@ -288,18 +291,20 @@ + (sqlite3 *)openDatabaseAtFileURL:(NSURL *)fileURL withResult:(int *)result {
}

+ (long)getPageSizeInOpenedDatabase:(void *)db {
NSArray<NSArray *> *rows = [MSDBStorage executeSelectionQuery:@"PRAGMA page_size;" inOpenedDatabase:db];
return [(NSNumber *)rows[0][0] longValue];
return [MSDBStorage querySingleValue:@"PRAGMA page_size;" inOpenedDatabase:db];
}

+ (long)getPageCountInOpenedDatabase:(void *)db {
NSArray<NSArray *> *rows = [MSDBStorage executeSelectionQuery:@"PRAGMA page_count;" inOpenedDatabase:db];
return [(NSNumber *)rows[0][0] longValue];
return [MSDBStorage querySingleValue:@"PRAGMA page_count;" inOpenedDatabase:db];
}

+ (long)getMaxPageCountInOpenedDatabase:(void *)db {
NSArray<NSArray *> *rows = [MSDBStorage executeSelectionQuery:@"PRAGMA max_page_count;" inOpenedDatabase:db];
return [(NSNumber *)rows[0][0] longValue];
return [MSDBStorage querySingleValue:@"PRAGMA max_page_count;" inOpenedDatabase:db];
}

+ (long)querySingleValue:(NSString *)query inOpenedDatabase:(void *)db {
NSArray<NSArray *> *rows = [MSDBStorage executeSelectionQuery:query inOpenedDatabase:db];
return rows.count > 0 && rows[0].count > 0 ? [(NSNumber *)rows[0][0] longValue] : 0;
}

+ (int)setMaxPageCount:(long)maxPageCount inOpenedDatabase:(void *)db {
Expand Down
25 changes: 25 additions & 0 deletions AppCenter/AppCenter/Internals/Storage/MSDBStoragePrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,31 @@ static const long kMSDefaultDatabaseSizeInBytes = 10 * 1024 * 1024;
*/
- (int)executeQueryUsingBlock:(MSDBStorageQueryBlock)block;

/**
* Query the number of pages (i.e.: SQLite "page_count") of the database.
*
* @param db Database handle.
*
* @return The number of pages.
*/
+ (long)getPageCountInOpenedDatabase:(void *)db;

/**
* Query the size of pages (i.e.: SQLite "page_size") of the database.
*
* @param db Database handle.
*
* @return The size of pages.
*/
+ (long)getPageSizeInOpenedDatabase:(void *)db;

/**
* Set the auto vacuum (i.e.: SQLite "auto_vacuum") of the database.
*
* @param db Database handle.
*/
+ (void)enableAutoVacuumInOpenedDatabase:(void *)db;

/**
* Check if a table exists in this database.
*
Expand Down
41 changes: 20 additions & 21 deletions AppCenter/AppCenter/Internals/Vendor/Reachability/MS_Reachability.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@

#define kShouldPrintReachabilityFlags 0

static void PrintReachabilityFlags(__attribute__((unused))
SCNetworkReachabilityFlags flags,
__attribute__((unused))
const char *comment) {
static void PrintReachabilityFlags(__unused SCNetworkReachabilityFlags flags,
__unused const char *comment) {
#if kShouldPrintReachabilityFlags

NSLog(@"Reachability Flag Status: %c%c %c%c%c%c%c%c%c %s\n",
Expand Down Expand Up @@ -54,6 +52,14 @@ static void ReachabilityCallback(SCNetworkReachabilityRef target,
object:noteObject];
}

static void RunOnMainThread(dispatch_block_t block) {
if ([NSThread isMainThread]) {
block();
} else {
dispatch_async(dispatch_get_main_queue(), block);
}
}

#pragma mark - Reachability extension

@interface MS_Reachability ()
Expand Down Expand Up @@ -124,7 +130,7 @@ + (instancetype)reachabilityForInternetConnection {
#pragma mark - Start and stop notifier

- (void)startNotifier {
dispatch_block_t block = ^{
RunOnMainThread(^{
SCNetworkReachabilityContext context = {0, (__bridge void *)(self), NULL,
NULL, NULL};
if (SCNetworkReachabilitySetCallback(self.reachabilityRef,
Expand All @@ -136,32 +142,25 @@ - (void)startNotifier {
object:self];
}
}
};
if ([NSThread isMainThread]) {
block();
} else {
dispatch_async(dispatch_get_main_queue(), block);
}
});
}

- (void)stopNotifier {
dispatch_block_t block = ^{
RunOnMainThread(^{
if (self.reachabilityRef != NULL) {
SCNetworkReachabilityUnscheduleFromRunLoop(
self.reachabilityRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
}
};
if ([NSThread isMainThread]) {
block();
} else {
dispatch_async(dispatch_get_main_queue(), block);
}
});
}

- (void)dealloc {
[self stopNotifier];
if (self.reachabilityRef != NULL) {
CFRelease(self.reachabilityRef);
__block SCNetworkReachabilityRef reachabilityRef = self.reachabilityRef;
if (reachabilityRef != NULL) {
RunOnMainThread(^{
SCNetworkReachabilityUnscheduleFromRunLoop(reachabilityRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
CFRelease(reachabilityRef);
});
}
}

Expand Down
1 change: 1 addition & 0 deletions AppCenter/AppCenter/MSAppCenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@

/**
* Enable or disable the SDK as a whole. In addition to AppCenter resources, it will also enable or disable all registered services.
* The state is persisted in the device's storage across application launches.
*
* @param isEnabled YES to enable, NO to disable.
*
Expand Down
13 changes: 7 additions & 6 deletions AppCenter/AppCenter/MSService.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@
@protocol MSService <NSObject>

/**
* Enable/disable this service.
* Enable or disable this service.
* The state is persisted in the device's storage across application launches.
*
* @param isEnabled whether this service is enabled or not.
* @param isEnabled Whether this service is enabled or not.
*
* @see isEnabled
* @see isEnabled
*/
+ (void)setEnabled:(BOOL)isEnabled;

/**
* Is this service enabled.
* Indicates whether this service is enabled.
*
* @return a boolean whether this service is enabled or not.
* @return `YES` if this service is enabled, `NO` if it is not.
*
* @see setEnabled:
* @see setEnabled:
*/
+ (BOOL)isEnabled;

Expand Down
109 changes: 109 additions & 0 deletions AppCenter/AppCenterTests/MSDBStorageTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,115 @@ - (void)testMigration {
OCMVerifyAll(dbStorage);
}

- (void)testGetMaxPageCountInOpenedDatabaseReturnsZeroWhenQueryFails {

// If
// Query returns empty array.
id dbStorageMock = OCMClassMock([MSDBStorage class]);
sqlite3 *db = [self.storageTestUtil openDatabase];
NSMutableArray<NSMutableArray *> *entries = [NSMutableArray<NSMutableArray *> new];
OCMStub([dbStorageMock executeSelectionQuery:[OCMArg any] inOpenedDatabase:db]).andReturn(entries);

// When
long counter = [MSDBStorage getMaxPageCountInOpenedDatabase:db];

// Then
assertThatLong(counter, equalToLong(0));

// If
// Query returns an array with empty array.
[entries addObject:[NSMutableArray new]];
OCMStub([dbStorageMock executeSelectionQuery:[OCMArg any] inOpenedDatabase:db]).andReturn(entries);

// When
counter = [MSDBStorage getMaxPageCountInOpenedDatabase:db];

// Then
assertThatLong(counter, equalToLong(0));
}

- (void)testGetPageCountInOpenedDatabaseReturnsZeroWhenQueryFails {

// If
// Query returns empty array.
id dbStorageMock = OCMClassMock([MSDBStorage class]);
sqlite3 *db = [self.storageTestUtil openDatabase];
NSMutableArray<NSMutableArray *> *entries = [NSMutableArray<NSMutableArray *> new];
OCMStub([dbStorageMock executeSelectionQuery:[OCMArg any] inOpenedDatabase:db]).andReturn(entries);

// When
long counter = [MSDBStorage getPageCountInOpenedDatabase:db];

// Then
assertThatLong(counter, equalToLong(0));

// If
// Query returns an array with empty array.
[entries addObject:[NSMutableArray new]];
OCMStub([dbStorageMock executeSelectionQuery:[OCMArg any] inOpenedDatabase:db]).andReturn(entries);

// When
counter = [MSDBStorage getPageCountInOpenedDatabase:db];

// Then
assertThatLong(counter, equalToLong(0));
}

- (void)testGetPageSizeInOpenedDatabaseReturnsZeroWhenQueryFails {

// If
// Query returns empty array.
id dbStorageMock = OCMClassMock([MSDBStorage class]);
sqlite3 *db = [self.storageTestUtil openDatabase];
NSMutableArray<NSMutableArray *> *entries = [NSMutableArray<NSMutableArray *> new];
OCMStub([dbStorageMock executeSelectionQuery:[OCMArg any] inOpenedDatabase:db]).andReturn(entries);

// When
long counter = [MSDBStorage getPageSizeInOpenedDatabase:db];

// Then
assertThatLong(counter, equalToLong(0));

// If
// Query returns an array with empty array.
[entries addObject:[NSMutableArray new]];
OCMStub([dbStorageMock executeSelectionQuery:[OCMArg any] inOpenedDatabase:db]).andReturn(entries);

// When
counter = [MSDBStorage getPageSizeInOpenedDatabase:db];

// Then
assertThatLong(counter, equalToLong(0));
}

- (void)testEnableAutoVacuumInOpenedDatabaseWhenQueryFails {

// If
// Query returns empty array.
id dbStorageMock = OCMClassMock([MSDBStorage class]);
sqlite3 *db = [self.storageTestUtil openDatabase];
NSMutableArray<NSMutableArray *> *entries = [NSMutableArray<NSMutableArray *> new];
OCMStub([dbStorageMock executeSelectionQuery:[OCMArg any] inOpenedDatabase:db]).andReturn(entries);
OCMStub([dbStorageMock executeNonSelectionQuery:[OCMArg any] inOpenedDatabase:db]);

// When
[MSDBStorage enableAutoVacuumInOpenedDatabase:db];

// Then
OCMVerify([dbStorageMock executeNonSelectionQuery:[OCMArg any] inOpenedDatabase:db]);

// If
// Query returns an array with empty array.
[entries addObject:[NSMutableArray new]];
OCMStub([dbStorageMock executeSelectionQuery:[OCMArg any] inOpenedDatabase:db]).andReturn(entries);

// When
[MSDBStorage enableAutoVacuumInOpenedDatabase:db];

// Then
OCMVerify([dbStorageMock executeNonSelectionQuery:[OCMArg any] inOpenedDatabase:db]);
}

- (void)testExecuteQuery {

// If
Expand Down
Loading

0 comments on commit ba06375

Please sign in to comment.