-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add NSCopying support to ART*ChannelOptions
Will use in an upcoming commit, but it's also handy for users of the SDK (e.g. I had already found myself wanting it in Chat, when wishing to create a modified version of an options object recevied as an argument).
- Loading branch information
1 parent
35805d0
commit a3b3217
Showing
5 changed files
with
86 additions
and
1 deletion.
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
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,56 @@ | ||
import Ably | ||
import XCTest | ||
|
||
class ChannelOptionsTests: XCTestCase { | ||
// MARK: - ARTChannelOptions | ||
|
||
func test_copyChannelOptions() throws { | ||
let options = ARTChannelOptions() | ||
options.cipher = ARTCrypto.getDefaultParams(["key": ARTCrypto.generateRandomKey()]) | ||
|
||
let copied = try XCTUnwrap(options.copy() as? ARTChannelOptions) | ||
|
||
// Check it creates a new object | ||
XCTAssertFalse(options === copied) | ||
|
||
// Check properties | ||
XCTAssertIdentical(options.cipher, copied.cipher) | ||
} | ||
|
||
func test_copyingFrozenChannelOptions_createsUnfrozenCopy() throws { | ||
let options = ARTChannelOptions() | ||
options.isFrozen = true | ||
|
||
let copied = try XCTUnwrap(options.copy() as? ARTChannelOptions) | ||
XCTAssertFalse(copied.isFrozen) | ||
} | ||
|
||
// MARK: - ARTRealtimeChannelOptions | ||
|
||
func test_copyRealtimeChannelOptions() throws { | ||
let options = ARTRealtimeChannelOptions() | ||
options.cipher = ARTCrypto.getDefaultParams(["key": ARTCrypto.generateRandomKey()]) | ||
options.params = ["foo": "bar"] | ||
options.modes = [.subscribe] | ||
options.attachOnSubscribe = false | ||
|
||
let copied = try XCTUnwrap(options.copy() as? ARTRealtimeChannelOptions) | ||
|
||
// Check it creates a new object | ||
XCTAssertFalse(options === copied) | ||
|
||
// Check properties | ||
XCTAssertIdentical(options.cipher, copied.cipher) | ||
XCTAssertIdentical(options.params as NSDictionary?, copied.params as NSDictionary?) | ||
XCTAssertEqual(options.modes, copied.modes) | ||
XCTAssertEqual(options.attachOnSubscribe, copied.attachOnSubscribe) | ||
} | ||
|
||
func test_copyingFrozenRealtimeChannelOptions_createsUnfrozenCopy() throws { | ||
let options = ARTRealtimeChannelOptions() | ||
options.isFrozen = true | ||
|
||
let copied = try XCTUnwrap(options.copy() as? ARTRealtimeChannelOptions) | ||
XCTAssertFalse(copied.isFrozen) | ||
} | ||
} |