-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NEW] Will option on SessionManager closes #44 [NEW] Change SessionManager subscriptions while connected [FIX] Correct SessionManager subscriptions according to server session present
- Loading branch information
Christoph Krey
committed
Aug 22, 2015
1 parent
4897a23
commit 38cc064
Showing
67 changed files
with
766 additions
and
423 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
Pod::Spec.new do |s| | ||
s.name = "MQTTClient" | ||
s.version = "0.2.4" | ||
s.version = "0.2.5" | ||
s.summary = "IOS native ObjectiveC MQTT Framework" | ||
s.homepage = "https://github.com/ckrey/MQTT-Client-Framework" | ||
s.license = { :type => "MIT", :file => "LICENSE" } | ||
s.author = { "Christoph Krey" => "[email protected]" } | ||
s.source = { :git => "https://github.com/ckrey/MQTT-Client-Framework.git", :tag => "0.2.4" } | ||
s.source = { :git => "https://github.com/ckrey/MQTT-Client-Framework.git", :tag => "0.2.5" } | ||
|
||
s.source_files = "MQTTClient/MQTTClient", "MQTTClient/MQTTClient/**/*.{h,m}" | ||
s.requires_arc = true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
// | ||
// MQTTSessionManagerTests.m | ||
// MQTTClient | ||
// | ||
// Created by Christoph Krey on 21.08.15. | ||
// Copyright (c) 2015 Christoph Krey. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
#import <XCTest/XCTest.h> | ||
#import "MQTTSessionManager.h" | ||
#import "MQTTClientTests.h" | ||
|
||
@interface MQTTSessionManagerTests : XCTestCase <MQTTSessionManagerDelegate> | ||
@property (nonatomic) int received; | ||
@property (nonatomic) int sent; | ||
@property (nonatomic) BOOL timeout; | ||
@property (nonatomic) int step; | ||
@end | ||
|
||
@implementation MQTTSessionManagerTests | ||
|
||
- (void)setUp { | ||
[super setUp]; | ||
} | ||
|
||
- (void)tearDown { | ||
[super tearDown]; | ||
} | ||
|
||
- (void)testMQTTSessionManagerClean { | ||
[self testMQTTSessionManager:true]; | ||
} | ||
|
||
- (void)testMQTTSessionManagerNoClean { | ||
[self testMQTTSessionManager:false]; | ||
} | ||
|
||
- (void)testMQTTSessionManager:(BOOL)clean { | ||
for (NSString *broker in BROKERLIST) { | ||
NSLog(@"testing broker %@", broker); | ||
NSDictionary *parameters = BROKERS[broker]; | ||
|
||
|
||
self.step = -1; | ||
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:[parameters[@"timeout"] intValue] | ||
target:self | ||
selector:@selector(timeout:) | ||
userInfo:nil | ||
repeats:true]; | ||
|
||
self.received = 0; | ||
MQTTSessionManager *manager = [[MQTTSessionManager alloc] init]; | ||
manager.delegate = self; | ||
manager.subscriptions = [@{@"#": @(0)} mutableCopy]; | ||
[manager connectTo:parameters[@"host"] | ||
port:[parameters[@"port"] intValue] | ||
tls:[parameters[@"tls"] boolValue] | ||
keepalive:60 | ||
clean:clean | ||
auth:NO | ||
user:nil | ||
pass:nil | ||
will:NO | ||
willTopic:nil | ||
willMsg:nil | ||
willQos:MQTTQosLevelAtMostOnce | ||
willRetainFlag:FALSE | ||
withClientId:@"MQTTSessionManager"]; | ||
while (self.step == -1 && manager.state != MQTTSessionManagerStateConnected) { | ||
NSLog(@"waiting for connect %d", manager.state); | ||
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; | ||
} | ||
XCTAssertEqual(manager.state, MQTTSessionManagerStateConnected); | ||
|
||
while (self.step <= 0) { | ||
NSLog(@"received %d on #", self.received); | ||
[manager sendData:[@"data" dataUsingEncoding:NSUTF8StringEncoding] topic:@"MQTTSessionManager" qos:MQTTQosLevelAtMostOnce retain:FALSE]; | ||
self.sent++; | ||
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; | ||
} | ||
XCTAssertEqual(self.received, self.sent); | ||
|
||
manager.subscriptions = [@{@"#": @(0),@"$SYS/#": @(0)} mutableCopy]; | ||
while (self.step == 1) { | ||
NSLog(@"received %d on # or $SYS/#", self.received); | ||
[manager sendData:[@"data" dataUsingEncoding:NSUTF8StringEncoding] topic:@"MQTTSessionManager" qos:MQTTQosLevelAtMostOnce retain:FALSE]; | ||
self.sent++; | ||
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; | ||
} | ||
XCTAssertEqual(self.received, self.sent); | ||
|
||
manager.subscriptions = [@{@"$SYS/#": @(0)} mutableCopy]; | ||
while (self.step <= 2) { | ||
NSLog(@"received %d on $SYS/#", self.received); | ||
[manager sendData:[@"data" dataUsingEncoding:NSUTF8StringEncoding] topic:@"MQTTSessionManager" qos:MQTTQosLevelAtMostOnce retain:FALSE]; | ||
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; | ||
} | ||
XCTAssertEqual(self.received, self.sent); | ||
|
||
manager.subscriptions = [@{} mutableCopy]; | ||
while (self.step <= 3) { | ||
NSLog(@"received %d on nothing", self.received); | ||
[manager sendData:[@"data" dataUsingEncoding:NSUTF8StringEncoding] topic:@"MQTTSessionManager" qos:MQTTQosLevelAtMostOnce retain:FALSE]; | ||
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; | ||
} | ||
XCTAssertEqual(self.received, self.sent); | ||
|
||
[manager disconnect]; | ||
while (self.step <= 4) { | ||
NSLog(@"received %d after disconnect", self.received); | ||
[manager sendData:[@"data" dataUsingEncoding:NSUTF8StringEncoding] topic:@"MQTTSessionManager" qos:MQTTQosLevelAtMostOnce retain:FALSE]; | ||
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; | ||
} | ||
XCTAssertEqual(self.received, self.sent); | ||
[timer invalidate]; | ||
} | ||
} | ||
|
||
- (void)handleMessage:(NSData *)data onTopic:(NSString *)topic retained:(BOOL)retained { | ||
NSLog(@"handleMessage t:%@", topic); | ||
if ([topic isEqualToString:@"MQTTSessionManager"]) { | ||
self.received++; | ||
} | ||
} | ||
|
||
- (void)timeout:(NSTimer *)timer { | ||
NSLog(@"timeout s:%d", self.step); | ||
self.step++; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.