-
Notifications
You must be signed in to change notification settings - Fork 10
Rid 列挙型を追加する #295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Rid 列挙型を追加する #295
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,4 +1,4 @@ | ||
| .PHONY: fmt fmt-lint lint | ||
| .PHONY: build fmt fmt-lint lint | ||
|
|
||
| # すべてを実行 | ||
| all: fmt fmt-lint lint | ||
|
|
@@ -7,6 +7,19 @@ all: fmt fmt-lint lint | |
| fmt: | ||
| swift format --in-place --recursive Sora SoraTests | ||
|
|
||
| # build | ||
| build: | ||
| xcodebuild \ | ||
| -scheme 'Sora' \ | ||
| -sdk iphoneos26.1 \ | ||
| -configuration Release \ | ||
| -derivedDataPath build \ | ||
| -destination 'generic/platform=iOS' \ | ||
| clean build \ | ||
| CODE_SIGNING_REQUIRED=NO \ | ||
| CODE_SIGN_IDENTITY= \ | ||
| PROVISIONING_PROFILE= | ||
|
Comment on lines
+10
to
+21
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. あったら使うかなと思い追加しました |
||
|
|
||
| # swift-format lint | ||
| fmt-lint: | ||
| swift format lint --strict --parallel --recursive Sora SoraTests | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,41 @@ | ||
| /// 映像の rid を表します。 | ||
| /// type: offer の simulcastRpcRids や RPC で利用される汎用 rid 型です。 | ||
| public enum Rid: Equatable { | ||
| /// 映像を受信しない | ||
| case none | ||
|
|
||
| /// r0 | ||
| case r0 | ||
|
|
||
| /// r1 | ||
| case r1 | ||
|
|
||
| /// r2 | ||
| case r2 | ||
| } | ||
|
|
||
| private var ridTable: PairTable<String, Rid> = | ||
| PairTable( | ||
| name: "rid", | ||
| pairs: [ | ||
| ("none", .none), | ||
| ("r0", .r0), | ||
| ("r1", .r1), | ||
| ("r2", .r2), | ||
| ]) | ||
|
|
||
| /// :nodoc: | ||
| extension Rid: Codable { | ||
| public init(from decoder: Decoder) throws { | ||
| let container = try decoder.singleValueContainer() | ||
| let string = try container.decode(String.self) | ||
| guard let rid = ridTable.right(other: string) else { | ||
| throw SoraError.invalidSignalingMessage | ||
| } | ||
| self = rid | ||
| } | ||
|
|
||
| public func encode(to encoder: Encoder) throws { | ||
| try ridTable.encode(self, to: encoder) | ||
| } | ||
| } |
This file contains hidden or 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,33 @@ | ||
| import XCTest | ||
|
|
||
| @testable import Sora | ||
|
|
||
| class RidTests: XCTestCase { | ||
| func testRidEncodingAndDecoding() throws { | ||
| let cases: [(Rid, String)] = [ | ||
| (.none, "\"none\""), | ||
| (.r0, "\"r0\""), | ||
| (.r1, "\"r1\""), | ||
| (.r2, "\"r2\""), | ||
| ] | ||
|
|
||
| for (rid, expectedJson) in cases { | ||
| // Encoding | ||
| let encoder = JSONEncoder() | ||
| let encodedData = try encoder.encode(rid) | ||
| let encodedJson = String(data: encodedData, encoding: .utf8) | ||
| XCTAssertEqual(encodedJson, expectedJson, "Failed encoding \(rid)") | ||
|
|
||
| // Decoding | ||
| let decoder = JSONDecoder() | ||
| let decodedRid = try decoder.decode(Rid.self, from: expectedJson.data(using: .utf8)!) | ||
| XCTAssertEqual(decodedRid, rid, "Failed decoding \(expectedJson)") | ||
| } | ||
| } | ||
|
|
||
| func testDecodeInvalidRidThrowsError() throws { | ||
| let decoder = JSONDecoder() | ||
| let data = "\"invalid\"".data(using: .utf8)! | ||
| XCTAssertThrowsError(try decoder.decode(Rid.self, from: data)) | ||
| } | ||
| } |
This file contains hidden or 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,66 @@ | ||
| import XCTest | ||
|
|
||
| @testable import Sora | ||
|
|
||
| class SignalingOfferTests: XCTestCase { | ||
| func testDecodeSimulcastRpcRids() throws { | ||
| let testCases: [(simulcastRpcRids: [String], expectedRids: [Rid]?, shouldThrow: Bool)] = [ | ||
| (["r0", "r1", "r2"], [.r0, .r1, .r2], false), | ||
| (["none"], [.none], false), | ||
| ([], [], false), | ||
| (["invalid"], nil, true), | ||
| ] | ||
|
|
||
| for (simulcastRpcRids, expectedRids, shouldThrow) in testCases { | ||
| let json: String | ||
| if simulcastRpcRids.isEmpty { | ||
| json = """ | ||
| { | ||
| "type": "offer", | ||
| "client_id": "client123", | ||
| "connection_id": "conn123", | ||
| "sdp": "v=0\\r\\no=- 1 1 IN IP4 127.0.0.1\\r\\n", | ||
| "simulcast_rpc_rids": [] | ||
| } | ||
| """ | ||
| } else { | ||
| let ridsJson = simulcastRpcRids.map { "\"\($0)\"" }.joined(separator: ", ") | ||
| json = """ | ||
| { | ||
| "type": "offer", | ||
| "client_id": "client123", | ||
| "connection_id": "conn123", | ||
| "sdp": "v=0\\r\\no=- 1 1 IN IP4 127.0.0.1\\r\\n", | ||
| "simulcast_rpc_rids": [\(ridsJson)] | ||
| } | ||
| """ | ||
| } | ||
|
|
||
| let data = json.data(using: .utf8)! | ||
| let decoder = JSONDecoder() | ||
|
|
||
| if shouldThrow { | ||
| XCTAssertThrowsError(try decoder.decode(SignalingOffer.self, from: data)) | ||
| } else { | ||
| let offer = try decoder.decode(SignalingOffer.self, from: data) | ||
| XCTAssertEqual(offer.simulcastRpcRids, expectedRids) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func testDecodeSimulcastRpcRidsNotPresent() throws { | ||
| let json = """ | ||
| { | ||
| "type": "offer", | ||
| "client_id": "client123", | ||
| "connection_id": "conn123", | ||
| "sdp": "v=0\\r\\no=- 1 1 IN IP4 127.0.0.1\\r\\n" | ||
| } | ||
| """ | ||
| let data = json.data(using: .utf8)! | ||
| let decoder = JSONDecoder() | ||
| let offer = try decoder.decode(SignalingOffer.self, from: data) | ||
|
|
||
| XCTAssertNil(offer.simulcastRpcRids) | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここらの追加分は #291 で書けてなかった内容を追加したものです