Skip to content

Commit

Permalink
Merge pull request #220 from zapcannon87/master
Browse files Browse the repository at this point in the history
release: 16.5.0
  • Loading branch information
zapcannon87 authored Aug 13, 2019
2 parents d00b604 + 4efef54 commit 7038557
Show file tree
Hide file tree
Showing 26 changed files with 1,523 additions and 948 deletions.
2 changes: 1 addition & 1 deletion LeanCloud.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'LeanCloud'
s.version = '16.4.0'
s.version = '16.5.0'
s.license = { :type => 'Apache License, Version 2.0', :file => 'LICENSE' }
s.summary = 'LeanCloud Swift SDK'
s.homepage = 'https://leancloud.cn/'
Expand Down
16 changes: 8 additions & 8 deletions LeanCloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
D363343622CDB0D300995DC1 /* LCEngineTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D363343522CDB0D300995DC1 /* LCEngineTestCase.swift */; };
D3662F9222019B590046A390 /* test.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = D3662F9122019B590046A390 /* test.mp3 */; };
D3665C3721FEAAC1005B44B0 /* IMMessageTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3665C3621FEAAC1005B44B0 /* IMMessageTestCase.swift */; };
D36E6C7022EC56A800CC1989 /* LiveQuery.swift in Sources */ = {isa = PBXBuildFile; fileRef = D36E6C6F22EC56A800CC1989 /* LiveQuery.swift */; };
D3783A1221F453C3006F6635 /* IMConversationTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3783A1121F453C3006F6635 /* IMConversationTestCase.swift */; };
D393EDBE21D38206001CBB2B /* IMMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = D393EDBD21D38206001CBB2B /* IMMessage.swift */; };
D39C50A822D4683C00CFCB43 /* Push.swift in Sources */ = {isa = PBXBuildFile; fileRef = D39C50A722D4683C00CFCB43 /* Push.swift */; };
Expand All @@ -100,13 +101,12 @@
D3B600842281679400F2E556 /* LCApplicationTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3B600832281679400F2E556 /* LCApplicationTestCase.swift */; };
D3BBFB41225D944100B75BA1 /* LCLocalStorageContextTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3BBFB40225D944100B75BA1 /* LCLocalStorageContextTestCase.swift */; };
D3C3782F21E48D3C00EA9AC9 /* IMConversationQuery.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3C3782E21E48D3C00EA9AC9 /* IMConversationQuery.swift */; };
D3D73BEB22EAA4EE00ECAE2B /* LiveQueryClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3D73BEA22EAA4EE00ECAE2B /* LiveQueryClient.swift */; };
D3DAD03C218DA402008BCD37 /* RTMConnectionTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3DAD03B218DA402008BCD37 /* RTMConnectionTestCase.swift */; };
D3E1F48D2193EDF3007B6FFB /* ConnectionTestViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3E1F48C2193EDF3007B6FFB /* ConnectionTestViewController.swift */; };
D3E1F4AE21940E8E007B6FFB /* SwiftProtobuf.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D3872641217726B500DD8FBF /* SwiftProtobuf.framework */; };
D3E1F4AF21940E8E007B6FFB /* SwiftProtobuf.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = D3872641217726B500DD8FBF /* SwiftProtobuf.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
D3E1F4B321940E95007B6FFB /* Alamofire.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 837E04EE1CABA688008CC3FF /* Alamofire.framework */; };
D3E1F4B421940E95007B6FFB /* Alamofire.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 837E04EE1CABA688008CC3FF /* Alamofire.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
D3F030E4222FB31F009F6C67 /* MessagePushTestViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3F030E3222FB31F009F6C67 /* MessagePushTestViewController.swift */; };
D3FE04522277EA6C0008C88A /* IMLocalStorageTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3FE04512277EA6C0008C88A /* IMLocalStorageTestCase.swift */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -418,6 +418,7 @@
D363343522CDB0D300995DC1 /* LCEngineTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LCEngineTestCase.swift; sourceTree = "<group>"; };
D3662F9122019B590046A390 /* test.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = test.mp3; sourceTree = "<group>"; };
D3665C3621FEAAC1005B44B0 /* IMMessageTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IMMessageTestCase.swift; sourceTree = "<group>"; };
D36E6C6F22EC56A800CC1989 /* LiveQuery.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LiveQuery.swift; sourceTree = "<group>"; };
D3783A1121F453C3006F6635 /* IMConversationTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IMConversationTestCase.swift; sourceTree = "<group>"; };
D387262A217726B500DD8FBF /* SwiftProtobuf.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = SwiftProtobuf.xcodeproj; path = SwiftProtobuf/SwiftProtobuf.xcodeproj; sourceTree = "<group>"; };
D393EDBD21D38206001CBB2B /* IMMessage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IMMessage.swift; sourceTree = "<group>"; };
Expand All @@ -429,9 +430,8 @@
D3B600832281679400F2E556 /* LCApplicationTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LCApplicationTestCase.swift; sourceTree = "<group>"; };
D3BBFB40225D944100B75BA1 /* LCLocalStorageContextTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LCLocalStorageContextTestCase.swift; sourceTree = "<group>"; };
D3C3782E21E48D3C00EA9AC9 /* IMConversationQuery.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IMConversationQuery.swift; sourceTree = "<group>"; };
D3D73BEA22EAA4EE00ECAE2B /* LiveQueryClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LiveQueryClient.swift; sourceTree = "<group>"; };
D3DAD03B218DA402008BCD37 /* RTMConnectionTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RTMConnectionTestCase.swift; sourceTree = "<group>"; };
D3E1F48C2193EDF3007B6FFB /* ConnectionTestViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConnectionTestViewController.swift; sourceTree = "<group>"; };
D3F030E3222FB31F009F6C67 /* MessagePushTestViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessagePushTestViewController.swift; sourceTree = "<group>"; };
D3F030F2222FB411009F6C67 /* RuntimeTests-iOS.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "RuntimeTests-iOS.entitlements"; sourceTree = "<group>"; };
D3FE04512277EA6C0008C88A /* IMLocalStorageTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IMLocalStorageTestCase.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -662,8 +662,6 @@
D3F030F2222FB411009F6C67 /* RuntimeTests-iOS.entitlements */,
D317983A2193DC860037DE57 /* AppDelegate.swift */,
D317983C2193DC860037DE57 /* ViewController.swift */,
D3E1F48C2193EDF3007B6FFB /* ConnectionTestViewController.swift */,
D3F030E3222FB31F009F6C67 /* MessagePushTestViewController.swift */,
D317983E2193DC860037DE57 /* Main.storyboard */,
D31798412193DC880037DE57 /* Assets.xcassets */,
D31798432193DC880037DE57 /* LaunchScreen.storyboard */,
Expand Down Expand Up @@ -711,6 +709,8 @@
D393EDBD21D38206001CBB2B /* IMMessage.swift */,
D3C3782E21E48D3C00EA9AC9 /* IMConversationQuery.swift */,
D34F1BB82268263000251BC8 /* IMLocalStorage.swift */,
D3D73BEA22EAA4EE00ECAE2B /* LiveQueryClient.swift */,
D36E6C6F22EC56A800CC1989 /* LiveQuery.swift */,
);
path = IM;
sourceTree = "<group>";
Expand Down Expand Up @@ -1103,6 +1103,7 @@
D3C3782F21E48D3C00EA9AC9 /* IMConversationQuery.swift in Sources */,
835F5D791D7E6808004D1A0E /* Extension.swift in Sources */,
835F5D7D1D7E6808004D1A0E /* ObjectProfiler.swift in Sources */,
D3D73BEB22EAA4EE00ECAE2B /* LiveQueryClient.swift in Sources */,
1113D80421AB963B000677BD /* IMConversation.swift in Sources */,
835F5D821D7E6808004D1A0E /* Response.swift in Sources */,
835F5D861D7E6808004D1A0E /* SMSClient.swift in Sources */,
Expand All @@ -1116,6 +1117,7 @@
11D9C0FB216DF63B00A620B7 /* Application.swift in Sources */,
835F5D6B1D7E6808004D1A0E /* Bool.swift in Sources */,
835F5D751D7E6808004D1A0E /* String.swift in Sources */,
D36E6C7022EC56A800CC1989 /* LiveQuery.swift in Sources */,
835F5D7B1D7E6808004D1A0E /* LeanCloud.swift in Sources */,
835F5D741D7E6808004D1A0E /* Role.swift in Sources */,
D3301279217727870007286A /* Command.pb.swift in Sources */,
Expand Down Expand Up @@ -1157,8 +1159,6 @@
buildActionMask = 2147483647;
files = (
D317983D2193DC860037DE57 /* ViewController.swift in Sources */,
D3E1F48D2193EDF3007B6FFB /* ConnectionTestViewController.swift in Sources */,
D3F030E4222FB31F009F6C67 /* MessagePushTestViewController.swift in Sources */,
D317983B2193DC860037DE57 /* AppDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
204 changes: 114 additions & 90 deletions LeanCloudTests/IMClientTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,7 @@ import XCTest

class IMClientTestCase: RTMBaseTestCase {

func testInitWithUser() {
let user = LCUser()
user.username = UUID().uuidString.lcString
user.password = UUID().uuidString.lcString

XCTAssertTrue(user.signUp().isSuccess)

do {
let client = try IMClient(user: user)
XCTAssertNotNil(client.user)
XCTAssertEqual(client.ID, user.objectId?.stringValue)
} catch {
XCTFail("\(error)")
}
}

func testDeinit() {
func testInit() {
do {
let invalidID: String = Array<String>.init(repeating: "a", count: 65).joined()
let _ = try IMClient(ID: invalidID)
Expand All @@ -45,23 +29,42 @@ class IMClientTestCase: RTMBaseTestCase {
}

do {
var client: IMClient? = try IMClient(ID: "qweasd", tag: "mobile")
XCTAssertNotNil(client?.deviceTokenObservation)
XCTAssertNotNil(client?.fallbackUDID)
client = nil
XCTAssertNil(client)
let _ = try IMClient(ID: uuid)
let _ = try IMClient(ID: uuid, tag: uuid)
} catch {
XCTFail()
XCTFail("\(error)")
}
}

func testInitWithUser() {
let user = LCUser()
user.username = UUID().uuidString.lcString
user.password = UUID().uuidString.lcString

XCTAssertTrue(user.signUp().isSuccess)

do {
let client = try IMClient(user: user)
XCTAssertNotNil(client.user)
XCTAssertEqual(client.ID, user.objectId?.stringValue)
} catch {
XCTFail("\(error)")
}
}

func testDeinit() {
var client: IMClient? = try! IMClient(ID: uuid, tag: uuid)
weak var wClient: IMClient? = client
client = nil
delay()
XCTAssertNil(wClient)
}

func testOpenAndClose() {
let client: IMClient = try! IMClient(ID: uuid)

for _ in 0..<3 {
let exp = expectation(description: "open and close")
exp.expectedFulfillmentCount = 3
client.open { (result) in
expecting { (exp) in
client.open(completion: { (result) in
XCTAssertTrue(Thread.isMainThread)
XCTAssertTrue(result.isSuccess)
XCTAssertNil(result.error)
Expand All @@ -70,24 +73,66 @@ class IMClientTestCase: RTMBaseTestCase {
XCTAssertNil(client.openingOptions)
XCTAssertNil(client.openingCompletion)
XCTAssertEqual(client.sessionState, .opened)
XCTAssertNotNil(client.connectionDelegator.delegate)
exp.fulfill()
})
}

expecting { (exp) in
client.open { (result) in
XCTAssertTrue(result.isFailure)
XCTAssertNotNil(result.error)
exp.fulfill()
}
}

expecting { (exp) in
client.close() { (result) in
XCTAssertTrue(Thread.isMainThread)
XCTAssertTrue(result.isSuccess)
XCTAssertNil(result.error)
XCTAssertNil(client.sessionToken)
XCTAssertNil(client.sessionTokenExpiration)
XCTAssertNil(client.openingOptions)
XCTAssertNil(client.openingCompletion)
XCTAssertEqual(client.sessionState, .closed)
XCTAssertNil(client.connectionDelegator.delegate)
exp.fulfill()
client.open { (result) in
XCTAssertNotNil(result.error)
}
}
}

func testOpenWithSignature() {
let user = LCUser()
user.username = UUID().uuidString.lcString
user.password = UUID().uuidString.lcString

XCTAssertTrue(user.signUp().isSuccess)

if let objectID = user.objectId?.value, let sessionToken = user.sessionToken?.value {

var clientWithUser: IMClient! = try! IMClient(user: user)
expecting { (exp) in
clientWithUser.open(completion: { (result) in
XCTAssertTrue(result.isSuccess)
XCTAssertNil(result.error)
exp.fulfill()
client.close() { (result) in
XCTAssertTrue(Thread.isMainThread)
XCTAssertTrue(result.isSuccess)
XCTAssertNil(result.error)
XCTAssertNil(client.sessionToken)
XCTAssertNil(client.sessionTokenExpiration)
XCTAssertNil(client.openingOptions)
XCTAssertNil(client.openingCompletion)
XCTAssertEqual(client.sessionState, .closed)
exp.fulfill()
}
}
})
}

clientWithUser = nil
delay()

let signatureDelegator = SignatureDelegator()
signatureDelegator.sessionToken = sessionToken
let clientWithID = try! IMClient(ID: objectID, signatureDelegate: signatureDelegator)
expecting { (exp) in
clientWithID.open(completion: { (result) in
XCTAssertTrue(result.isSuccess)
XCTAssertNil(result.error)
exp.fulfill()
})
}
waitForExpectations(timeout: timeout, handler: nil)
}
}

Expand Down Expand Up @@ -166,8 +211,8 @@ class IMClientTestCase: RTMBaseTestCase {
}
wait(for: [exp1], timeout: timeout)

RTMConnectionRefMap_protobuf1.removeAll()
RTMConnectionRefMap_protobuf3.removeAll()
RTMConnectionManager.default.protobuf1Map.removeAll()
RTMConnectionManager.default.protobuf3Map.removeAll()

applicationRegistry.removeAll()
let application2: LCApplication = try! LCApplication(
Expand Down Expand Up @@ -501,30 +546,6 @@ class IMClientTestCase: RTMBaseTestCase {

XCTAssertEqual(client.convCollection.count, 2)
}

func testInitWithUserAndOpenWithSignature() {
let user = LCUser()
user.username = UUID().uuidString.lcString
user.password = UUID().uuidString.lcString

XCTAssertTrue(user.signUp().isSuccess)

if let sessionToken = user.sessionToken?.stringValue {

let signatureDelegator = SignatureDelegator()
signatureDelegator.sessionToken = sessionToken

let client = try! IMClient(user: user, signatureDelegate: signatureDelegator)

expecting { (exp) in
client.open(completion: { (result) in
XCTAssertTrue(result.isSuccess)
XCTAssertNil(result.error)
exp.fulfill()
})
}
}
}

}

Expand Down Expand Up @@ -564,37 +585,40 @@ extension IMClientTestCase {

var sessionToken: String?

func getOpenSignature(client: IMClient, completion: @escaping (IMSignature) -> Void) {
guard let sessionToken = self.sessionToken else {
return
}
let application = client.application
let httpClient: HTTPClient = application.httpClient
let url = application.v2router.route(path: "rtm/clients/sign", module: .api)!
let parameters: [String: Any] = ["session_token": sessionToken]
_ = httpClient.request(url: url, method: .get, parameters: parameters) { (response) in
guard
let value = response.value as? [String: Any],
let client_id = value["client_id"] as? String,
client_id == client.ID,
let signature = value["signature"] as? String,
let timestamp = value["timestamp"] as? Int64,
let nonce = value["nonce"] as? String else
{
return
}
completion(IMSignature(signature: signature, timestamp: timestamp, nonce: nonce))
}
}

func client(_ client: IMClient, action: IMSignature.Action, signatureHandler: @escaping (IMClient, IMSignature?) -> Void) {
XCTAssertTrue(Thread.isMainThread)
switch action {
case .open:
guard let sessionToken = self.sessionToken else {
break
}

let application = client.application
let httpClient: HTTPClient = application.httpClient
let url = application.v2router.route(path: "rtm/clients/sign", module: .api)!
let parameters: [String: Any] = ["session_token": sessionToken]

let _ = httpClient.request(url: url, method: .get, parameters: parameters) { (response) in
guard
let value = response.value as? [String: Any],
let client_id = value["client_id"] as? String,
client_id == client.ID,
let signature = value["signature"] as? String,
let timestamp = value["timestamp"] as? Int64,
let nonce = value["nonce"] as? String else
{
return
}
signatureHandler(client, IMSignature(signature: signature, timestamp: timestamp, nonce: nonce))
self.getOpenSignature(client: client) { (signature) in
signatureHandler(client, signature)
}
default:
break
}
}

}

}
Loading

0 comments on commit 7038557

Please sign in to comment.