Skip to content

Commit 1552392

Browse files
authored
iOS fix appcenter tests (#448)
1 parent 53f029a commit 1552392

File tree

10 files changed

+165
-291
lines changed

10 files changed

+165
-291
lines changed

.github/workflows/ios-appcenter.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ jobs:
3838
- name: Make build dir
3939
run: mkdir ddp
4040

41+
- name: Install resource script dependency
42+
run: |
43+
brew update
44+
brew install convmv
45+
46+
- name: Copy test_resources
47+
run: ./copy_test_resources.sh
48+
4149
- name: Run Cocoapods
4250
run: pod install
4351

.github/workflows/ios-perf.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,9 @@ jobs:
2828

2929
strategy:
3030
matrix:
31-
device: [iOS-14.5, iOS-32bit]
31+
device: [ios-perf]
3232
include:
33-
- device: iOS-14.5
34-
performanceThresholdSec: 0.2
35-
- device: iOS-32bit
33+
- device: ios-perf
3634
performanceThresholdSec: 0.2
3735

3836
steps:
@@ -51,6 +49,14 @@ jobs:
5149
- name: Make build dir
5250
run: mkdir ddp
5351

52+
- name: Install resource script dependency
53+
run: |
54+
brew update
55+
brew install convmv
56+
57+
- name: Copy test_resources
58+
run: ./copy_test_resources.sh
59+
5460
- name: Run Cocoapods
5561
run: pod install
5662

binding/ios/RhinoAppTest/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@ build/*
1818
xcuserdata
1919
Pods
2020
ddp
21+
22+
RhinoAppTestUITests/test_resources/*
23+
!RhinoAppTestUITests/test_resources/.gitkeep

binding/ios/RhinoAppTest/RhinoAppTest.xcodeproj/project.pbxproj

Lines changed: 4 additions & 164 deletions
Large diffs are not rendered by default.

binding/ios/RhinoAppTest/RhinoAppTestUITests/BaseTest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ class BaseTest: XCTestCase {
4646

4747
return try rhino.getInference()
4848
}
49-
}
49+
}

binding/ios/RhinoAppTest/RhinoAppTestUITests/RhinoAppTestUITests.swift

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class RhinoAppTestUITests: BaseTest {
1616

1717
func testInitSuccessSimple() throws {
1818
let bundle = Bundle(for: type(of: self))
19-
let contextPath = bundle.path(forResource: "coffee_maker_ios", ofType: "rhn")!
19+
let contextPath = bundle.path(forResource: "coffee_maker_ios", ofType: "rhn", inDirectory: "test_resources/context_files/en")!
2020
let r = try Rhino.init(
2121
accessKey: accessKey,
2222
contextPath: contextPath)
@@ -30,8 +30,8 @@ class RhinoAppTestUITests: BaseTest {
3030

3131
func testInitSuccessWithCustomModelPath() throws {
3232
let bundle = Bundle(for: type(of: self))
33-
let contextPath = bundle.path(forResource: "coffee_maker_ios", ofType: "rhn")!
34-
let modelPath = bundle.path(forResource: "rhino_params", ofType: "pv")!
33+
let contextPath = bundle.path(forResource: "coffee_maker_ios", ofType: "rhn", inDirectory: "test_resources/context_files/en")!
34+
let modelPath = bundle.path(forResource: "rhino_params", ofType: "pv", inDirectory: "test_resources/model_files")!
3535

3636
let r = try Rhino.init(
3737
accessKey: accessKey,
@@ -43,7 +43,7 @@ class RhinoAppTestUITests: BaseTest {
4343

4444
func testInitSuccessWithCustomSensitivity() throws {
4545
let bundle = Bundle(for: type(of: self))
46-
let contextPath = bundle.path(forResource: "coffee_maker_ios", ofType: "rhn")!
46+
let contextPath = bundle.path(forResource: "coffee_maker_ios", ofType: "rhn", inDirectory: "test_resources/context_files/en")!
4747

4848
let r = try Rhino.init(
4949
accessKey: accessKey,
@@ -55,7 +55,7 @@ class RhinoAppTestUITests: BaseTest {
5555

5656
func testInitSuccessWithCustomEndpointDuration() throws {
5757
let bundle = Bundle(for: type(of: self))
58-
let contextPath = bundle.path(forResource: "coffee_maker_ios", ofType: "rhn")!
58+
let contextPath = bundle.path(forResource: "coffee_maker_ios", ofType: "rhn", inDirectory: "test_resources/context_files/en")!
5959

6060
let r = try Rhino.init(
6161
accessKey: accessKey,
@@ -67,7 +67,7 @@ class RhinoAppTestUITests: BaseTest {
6767

6868
func testInitSuccessWithRequireEndpointOff() throws {
6969
let bundle = Bundle(for: type(of: self))
70-
let contextPath = bundle.path(forResource: "coffee_maker_ios", ofType: "rhn")!
70+
let contextPath = bundle.path(forResource: "coffee_maker_ios", ofType: "rhn", inDirectory: "test_resources/context_files/en")!
7171

7272
let r = try Rhino.init(
7373
accessKey: accessKey,
@@ -79,8 +79,8 @@ class RhinoAppTestUITests: BaseTest {
7979

8080
func testInitFailWithMismatchedLanguage() throws {
8181
let bundle = Bundle(for: type(of: self))
82-
let contextPath = bundle.path(forResource: "beleuchtung_ios", ofType: "rhn")!
83-
let modelPath = bundle.path(forResource: "rhino_params", ofType: "pv")!
82+
let contextPath = bundle.path(forResource: "beleuchtung_ios", ofType: "rhn", inDirectory: "test_resources/context_files/de")!
83+
let modelPath = bundle.path(forResource: "rhino_params", ofType: "pv", inDirectory: "test_resources/model_files")!
8484

8585
var didFail = false
8686
do {
@@ -112,7 +112,7 @@ class RhinoAppTestUITests: BaseTest {
112112

113113
func testInitFailWithInvalidModelPath() throws {
114114
let bundle = Bundle(for: type(of: self))
115-
let contextPath = bundle.path(forResource: "coffee_maker_ios", ofType: "rhn")!
115+
let contextPath = bundle.path(forResource: "coffee_maker_ios", ofType: "rhn", inDirectory: "test_resources/context_files/en")!
116116
let modelPath = "/bad_path/bad_path.pv"
117117

118118
var didFail = false
@@ -130,7 +130,7 @@ class RhinoAppTestUITests: BaseTest {
130130

131131
func testInitFailWithInvalidSensitivity() throws {
132132
let bundle = Bundle(for: type(of: self))
133-
let contextPath = bundle.path(forResource: "coffee_maker_ios", ofType: "rhn")!
133+
let contextPath = bundle.path(forResource: "coffee_maker_ios", ofType: "rhn", inDirectory: "test_resources/context_files/en")!
134134

135135
var didFail = false
136136
do {
@@ -147,7 +147,7 @@ class RhinoAppTestUITests: BaseTest {
147147

148148
func testInitFailWithInvalidEndpointDuration() throws {
149149
let bundle = Bundle(for: type(of: self))
150-
let contextPath = bundle.path(forResource: "coffee_maker_ios", ofType: "rhn")!
150+
let contextPath = bundle.path(forResource: "coffee_maker_ios", ofType: "rhn", inDirectory: "test_resources/context_files/en")!
151151

152152
var didFail = false
153153
do {
@@ -164,7 +164,7 @@ class RhinoAppTestUITests: BaseTest {
164164

165165
func testInitFailWithWrongPlatform() throws {
166166
let bundle = Bundle(for: type(of: self))
167-
let contextPath = bundle.path(forResource: "coffee_maker_linux", ofType: "rhn")!
167+
let contextPath = bundle.path(forResource: "coffee_maker_linux", ofType: "rhn", inDirectory: "test_resources/context_files/en")!
168168

169169
var didFail = false
170170
do {
@@ -180,8 +180,8 @@ class RhinoAppTestUITests: BaseTest {
180180

181181
func testInitWithNonAsciiModelName() throws {
182182
let bundle = Bundle(for: type(of: self))
183-
let contextPath = bundle.path(forResource: "iluminación_inteligente_ios", ofType: "rhn")!
184-
let modelPath = bundle.path(forResource: "rhino_params_es", ofType: "pv")!
183+
let contextPath = bundle.path(forResource: "iluminación_inteligente_ios", ofType: "rhn", inDirectory: "test_resources/context_files/es")!
184+
let modelPath = bundle.path(forResource: "rhino_params_es", ofType: "pv", inDirectory: "test_resources/model_files")!
185185

186186
let r = try Rhino.init(
187187
accessKey: accessKey,
@@ -193,12 +193,12 @@ class RhinoAppTestUITests: BaseTest {
193193

194194
func testProcWithinContext() throws {
195195
let bundle = Bundle(for: type(of: self))
196-
let contextPath = bundle.path(forResource: "coffee_maker_ios", ofType: "rhn")!
196+
let contextPath = bundle.path(forResource: "coffee_maker_ios", ofType: "rhn", inDirectory: "test_resources/context_files/en")!
197197
let r = try Rhino.init(
198198
accessKey: accessKey,
199199
contextPath: contextPath)
200200

201-
let fileURL: URL = bundle.url(forResource: "test_within_context", withExtension: "wav")!
201+
let fileURL: URL = bundle.url(forResource: "test_within_context", withExtension: "wav", subdirectory: "test_resources/audio_samples")!
202202
let inference = try processFile(rhino: r, testAudioURL: fileURL)
203203

204204
XCTAssert(inference.isUnderstood)
@@ -217,12 +217,12 @@ class RhinoAppTestUITests: BaseTest {
217217

218218
func testProcOutOfContext() throws {
219219
let bundle = Bundle(for: type(of: self))
220-
let contextPath = bundle.path(forResource: "coffee_maker_ios", ofType: "rhn")!
220+
let contextPath = bundle.path(forResource: "coffee_maker_ios", ofType: "rhn", inDirectory: "test_resources/context_files/en")!
221221
let r = try Rhino.init(
222222
accessKey: accessKey,
223223
contextPath: contextPath)
224224

225-
let fileURL: URL = bundle.url(forResource: "test_out_of_context", withExtension: "wav")!
225+
let fileURL: URL = bundle.url(forResource: "test_out_of_context", withExtension: "wav", subdirectory: "test_resources/audio_samples")!
226226
let inference = try processFile(rhino: r, testAudioURL: fileURL)
227227
XCTAssert(!inference.isUnderstood)
228228

binding/ios/RhinoAppTest/RhinoAppTestUITests/RhinoLanguageTests.swift

Lines changed: 83 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -12,121 +12,100 @@ import XCTest
1212

1313
import Rhino
1414

15-
class RhinoWithinContextTests: BaseTest {
16-
static var testData: [[Any]] = [
17-
["en", "coffee_maker", "orderBeverage", ["beverage": "americano", "numberOfShots": "double shot", "size": "medium"]],
18-
["es", "iluminación_inteligente", "changeColor", ["location": "habitación", "color": "rosado"]],
19-
["de", "beleuchtung", "changeState", ["state": "aus"]],
20-
["fr", "éclairage_intelligent", "changeColor", ["color": "violet"]],
21-
["it", "illuminazione", "spegnereLuce", ["luogo": "bagno"]],
22-
["ja", "sumāto_shōmei", "色変更", ["": ""]],
23-
["ko", "seumateu_jomyeong", "changeColor", ["color": "파란색"]],
24-
["pt", "luz_inteligente", "ligueLuz", ["lugar": "cozinha"]]]
15+
struct TestData : Decodable {
16+
var tests: TestDataTests
17+
}
2518

26-
var language: String = ""
27-
var modelPath: String = ""
28-
var contextPath: String = ""
29-
var testAudioPath: URL? = URL(string: "")
30-
var expectedIntent: String = ""
31-
var expectedSlots: [String: String] = [:]
19+
struct TestDataTests : Decodable {
20+
var within_context: [TestDataWithinContextTest]
21+
var out_of_context: [TestDataOutOfContextTest]
22+
}
3223

33-
override class var defaultTestSuite: XCTestSuite {
34-
get {
35-
let xcTestSuite = XCTestSuite(name: NSStringFromClass(self))
36-
let bundle = Bundle(for: self)
24+
struct TestDataWithinContextTest : Decodable {
25+
var language: String
26+
var context_name: String
27+
var inference: TestDataInference
28+
}
3729

38-
for testCase in testData {
39-
let suffix = (testCase[0]) as! String == "en" ? "" : "_\(testCase[0])"
40-
for invocation in testInvocations {
41-
let newTestCase = RhinoWithinContextTests(invocation: invocation)
42-
newTestCase.language = testCase[0] as! String
43-
newTestCase.modelPath = bundle.path(forResource: "rhino_params\(suffix)", ofType: "pv")!
44-
newTestCase.contextPath = bundle.path(forResource: "\(testCase[1])_ios", ofType: "rhn")!
45-
newTestCase.testAudioPath = bundle.url(forResource: "test_within_context\(suffix)", withExtension: "wav")!
46-
newTestCase.expectedIntent = testCase[2] as! String
47-
newTestCase.expectedSlots = testCase[3] as! [String: String]
48-
xcTestSuite.addTest(newTestCase)
49-
}
50-
}
30+
struct TestDataInference : Decodable {
31+
var intent: String
32+
var slots: [String : String]
33+
}
5134

52-
return xcTestSuite
53-
}
54-
}
35+
struct TestDataOutOfContextTest : Decodable {
36+
var language: String
37+
var context_name: String
38+
}
5539

40+
class RhinoWithinContextTests: BaseTest {
5641
func testWrapper() throws {
57-
let inference = try XCTContext.runActivity(named: "(\(language))") { _ -> Inference in
58-
let r = try Rhino.init(
59-
accessKey: accessKey,
60-
contextPath: contextPath,
61-
modelPath: modelPath)
62-
XCTAssert(Rhino.version != "")
63-
XCTAssert(Rhino.frameLength > 0)
64-
XCTAssert(Rhino.sampleRate > 0)
65-
XCTAssert(r.contextInfo != "")
66-
67-
let ret = try processFile(rhino: r, testAudioURL: testAudioPath!)
68-
r.delete()
69-
return ret
42+
let bundle = Bundle(for: type(of: self))
43+
let testDataJsonUrl = bundle.url(forResource: "test_data", withExtension: "json", subdirectory: "test_resources")!
44+
45+
let testDataJsonData = try Data(contentsOf: testDataJsonUrl)
46+
let testData = try JSONDecoder().decode(TestData.self, from: testDataJsonData)
47+
48+
for testCase in testData.tests.within_context {
49+
let suffix = testCase.language == "en" ? "" : "_\(testCase.language)"
50+
51+
let language: String = testCase.language
52+
let modelPath: String = bundle.path(forResource: "rhino_params\(suffix)", ofType: "pv", inDirectory: "test_resources/model_files")!
53+
let contextPath: String = bundle.path(forResource: "\(testCase.context_name)_ios", ofType: "rhn", inDirectory: "test_resources/context_files/\(testCase.language)")!
54+
let testAudioPath: URL = bundle.url(forResource: "test_within_context\(suffix)", withExtension: "wav", subdirectory: "test_resources/audio_samples")!
55+
let expectedIntent: String = testCase.inference.intent
56+
let expectedSlots: [String: String] = testCase.inference.slots
57+
58+
try XCTContext.runActivity(named: "(\(language))") { _ in
59+
let r = try Rhino.init(
60+
accessKey: accessKey,
61+
contextPath: contextPath,
62+
modelPath: modelPath)
63+
XCTAssert(Rhino.version != "")
64+
XCTAssert(Rhino.frameLength > 0)
65+
XCTAssert(Rhino.sampleRate > 0)
66+
XCTAssert(r.contextInfo != "")
67+
68+
let inference = try processFile(rhino: r, testAudioURL: testAudioPath)
69+
r.delete()
70+
71+
XCTAssert(inference.isUnderstood)
72+
XCTAssert(inference.intent == expectedIntent)
73+
XCTAssert(inference.slots == expectedSlots)
74+
}
7075
}
71-
72-
XCTAssert(inference.isUnderstood)
73-
XCTAssert(inference.intent == expectedIntent)
74-
XCTAssert(inference.slots == expectedSlots)
7576
}
7677
}
7778

7879
class RhinoOutOfContextTests: BaseTest {
79-
static var testData: [[Any]] = [
80-
["en", "coffee_maker"],
81-
["es", "iluminación_inteligente"],
82-
["de", "beleuchtung"],
83-
["fr", "éclairage_intelligent"],
84-
["it", "illuminazione"],
85-
["ja", "sumāto_shōmei"],
86-
["ko", "seumateu_jomyeong"],
87-
["pt", "luz_inteligente"]]
88-
89-
var language: String = ""
90-
var modelPath: String = ""
91-
var contextPath: String = ""
92-
var testAudioPath: URL? = URL(string: "")
93-
94-
override class var defaultTestSuite: XCTestSuite {
95-
get {
96-
let xcTestSuite = XCTestSuite(name: NSStringFromClass(self))
97-
let bundle = Bundle(for: self)
98-
99-
for testCase in testData {
100-
let suffix = (testCase[0]) as! String == "en" ? "" : "_\(testCase[0])"
101-
for invocation in testInvocations {
102-
let newTestCase = RhinoOutOfContextTests(invocation: invocation)
103-
newTestCase.language = testCase[0] as! String
104-
newTestCase.modelPath = bundle.path(forResource: "rhino_params\(suffix)", ofType: "pv")!
105-
newTestCase.contextPath = bundle.path(forResource: "\(testCase[1])_ios", ofType: "rhn")!
106-
newTestCase.testAudioPath = bundle.url(forResource: "test_out_of_context\(suffix)", withExtension: "wav")!
107-
xcTestSuite.addTest(newTestCase)
108-
}
109-
}
110-
111-
return xcTestSuite
112-
}
113-
}
114-
11580
func testWrapper() throws {
116-
let inference = try XCTContext.runActivity(named: "(\(language))") { _ -> Inference in
117-
let r = try Rhino.init(
118-
accessKey: accessKey,
119-
contextPath: contextPath,
120-
modelPath: modelPath)
121-
XCTAssert(Rhino.version != "")
122-
XCTAssert(Rhino.frameLength > 0)
123-
XCTAssert(Rhino.sampleRate > 0)
124-
XCTAssert(r.contextInfo != "")
125-
let ret = try processFile(rhino: r, testAudioURL: testAudioPath!)
126-
r.delete()
127-
return ret
81+
let bundle = Bundle(for: type(of: self))
82+
83+
let testDataJsonUrl = bundle.url(forResource: "test_data", withExtension: "json", subdirectory: "test_resources")!
84+
let testDataJsonData = try Data(contentsOf: testDataJsonUrl)
85+
let testData = try JSONDecoder().decode(TestData.self, from: testDataJsonData)
86+
87+
for testCase in testData.tests.out_of_context {
88+
let suffix = testCase.language == "en" ? "" : "_\(testCase.language)"
89+
90+
let language: String = testCase.language
91+
let modelPath: String = bundle.path(forResource: "rhino_params\(suffix)", ofType: "pv", inDirectory: "test_resources/model_files")!
92+
let contextPath: String = bundle.path(forResource: "\(testCase.context_name)_ios", ofType: "rhn", inDirectory: "test_resources/context_files/\(testCase.language)")!
93+
let testAudioPath: URL = bundle.url(forResource: "test_out_of_context\(suffix)", withExtension: "wav", subdirectory: "test_resources/audio_samples")!
94+
95+
try XCTContext.runActivity(named: "(\(language))") { _ in
96+
let r = try Rhino.init(
97+
accessKey: accessKey,
98+
contextPath: contextPath,
99+
modelPath: modelPath)
100+
XCTAssert(Rhino.version != "")
101+
XCTAssert(Rhino.frameLength > 0)
102+
XCTAssert(Rhino.sampleRate > 0)
103+
XCTAssert(r.contextInfo != "")
104+
let inference = try processFile(rhino: r, testAudioURL: testAudioPath)
105+
r.delete()
106+
107+
XCTAssert(!inference.isUnderstood)
108+
}
128109
}
129-
130-
XCTAssert(!inference.isUnderstood)
131110
}
132-
}
111+
}

binding/ios/RhinoAppTest/RhinoAppTestUITests/test_resources/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)