Authored by 周蓉君

更新YH_Analytics测试样例。Review by 阿瑟。

... ... @@ -102,7 +102,21 @@ static dispatch_queue_t persisitingQueue;
return _locationManager;
}
#pragma mark - Functions
- (void)setLogStrategy:(YHLogStrategy)strategyNumber
{
NSUserDefaults *strategy = [NSUserDefaults standardUserDefaults];
[strategy setObject: [NSNumber numberWithInteger:strategyNumber] forKey:@"LOGSTRATEGY"];
[strategy synchronize];
}
- (YHLogStrategy)logStrategy
{
NSUserDefaults *strategy = [NSUserDefaults standardUserDefaults];
NSNumber * strategyObj = [strategy objectForKey:@"LOGSTRATEGY"];
return [strategyObj intValue];
}
#pragma mark - Private Method
// 添加网络监测回调block
- (void)startObserverNetworkReachabilityStatus
... ... @@ -185,6 +199,36 @@ static dispatch_queue_t persisitingQueue;
self.session = nil;
}
- (NSString *)timestamp
{
long long now = [[NSDate date] timeIntervalSince1970];
long long int date = (long long int)now;
return [NSString stringWithFormat:@"%lld", date];
}
// 发送本地持久化数据
- (void)uploadDiskData
{
[[YHAssemblyAssistant sharedInstance] uploadDiskData];
}
// 发送本地持久化数据
- (void)tryUploadDiskData
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *lastUploadTime = [defaults objectForKey:kKeyUserDefaultsLastUploadTimestamp];
NSString *timeStamp = [self timestamp];
NSInteger uploadTimeInterval = [timeStamp integerValue] - [lastUploadTime integerValue];
if (uploadTimeInterval > self.currentInterval) {
[self uploadDiskData];
[defaults setObject:timeStamp forKey:kKeyUserDefaultsLastUploadTimestamp];
[defaults synchronize];
}
}
#pragma mark - Public Method
- (void)startWithAppId:(NSString *)appId
{
[self startObserverNetworkReachabilityStatus];
... ... @@ -281,35 +325,6 @@ static dispatch_queue_t persisitingQueue;
}
- (NSString *)timestamp
{
long long now = [[NSDate date] timeIntervalSince1970];
long long int date = (long long int)now;
return [NSString stringWithFormat:@"%lld", date];
}
// 发送本地持久化数据
- (void)uploadDiskData
{
[[YHAssemblyAssistant sharedInstance] uploadDiskData];
}
// 发送本地持久化数据
- (void)tryUploadDiskData
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *lastUploadTime = [defaults objectForKey:kKeyUserDefaultsLastUploadTimestamp];
NSString *timeStamp = [self timestamp];
NSInteger uploadTimeInterval = [timeStamp integerValue] - [lastUploadTime integerValue];
if (uploadTimeInterval > self.currentInterval) {
[self uploadDiskData];
[defaults setObject:timeStamp forKey:kKeyUserDefaultsLastUploadTimestamp];
[defaults synchronize];
}
}
#pragma mark - Location
#pragma mark - CLLocationManagerDelegate
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
... ... @@ -345,18 +360,4 @@ static dispatch_queue_t persisitingQueue;
NSLog(@"%@", errorMsg);
}
- (void)setLogStrategy:(YHLogStrategy)strategyNumber
{
NSUserDefaults *strategy = [NSUserDefaults standardUserDefaults];
[strategy setObject: [NSNumber numberWithInteger:strategyNumber] forKey:@"LOGSTRATEGY"];
[strategy synchronize];
}
- (YHLogStrategy)logStrategy
{
NSUserDefaults *strategy = [NSUserDefaults standardUserDefaults];
NSNumber * strategyObj = [strategy objectForKey:@"LOGSTRATEGY"];
return [strategyObj intValue];
}
@end
... ...
... ... @@ -47,6 +47,10 @@
- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
assemblyAssistantMock = nil;
crashReporterMock = nil;
networkAssistantMock = nil;
analytics = nil;
[super tearDown];
}
... ...
... ... @@ -39,8 +39,8 @@
- (void)testStartWithAppIdMethodWithConstraint {
NSLog(@"%@ start", self.name); // self.name is the name of the test-case method.
[[mock stub] startWithAppId:[OCMArg any]];
[mock startWithAppId:[OCMArg any]];
[[mock stub] startWithAppId:[OCMArg isKindOfClass:[NSString class]]];
[mock startWithAppId:@"appId"];
NSLog(@"%@ end", self.name);
}
... ... @@ -48,7 +48,7 @@
- (void)testLogEventMethodWithConstraint {
NSLog(@"%@ start", self.name);
[[mock stub] logEvent:[OCMArg any] parameters:[OCMArg any]];
[[mock stub] logEvent:[OCMArg isKindOfClass:[NSString class]] parameters:[OCMArg isKindOfClass:[NSDictionary class]]];
[mock logEvent:@"event" parameters:nil];
NSLog(@"%@ end", self.name);
... ... @@ -57,7 +57,7 @@
- (void)testLogErrorMethodWithConstraint {
NSLog(@"%@ start", self.name);
[[mock stub] logError:[OCMArg any] parameters:[OCMArg any]];
[[mock stub] logError:[OCMArg isKindOfClass:[NSString class]] parameters:[OCMArg isKindOfClass:[NSDictionary class]]];
[mock logError:@"error" parameters:nil];
NSLog(@"%@ end", self.name);
... ...