@@ -57,12 +57,12 @@ class TestStreamWaitState : public ::testing::Test {
57
57
return (r == Result::OK || r == Result::ErrorClosed);
58
58
}
59
59
60
- void checkWaitZeroTimeout () {
60
+ // if zero then don't wait for a state change
61
+ void checkWaitForStateChangeTimeout (int64_t timeout = kTimeoutInNanos ) {
61
62
StreamState next = StreamState::Unknown;
62
- int64_t timeout = 0 ; // don't wait for a state change
63
- Result result = mStream ->waitForStateChange (mStream ->getState (), &next, timeout);
64
- EXPECT_EQ (Result::ErrorTimeout, result);
65
- }
63
+ Result result = mStream ->waitForStateChange (mStream ->getState (), &next, timeout);
64
+ EXPECT_EQ (Result::ErrorTimeout, result);
65
+ }
66
66
67
67
void checkStopWhileWaiting () {
68
68
StreamState next = StreamState::Unknown;
@@ -120,15 +120,16 @@ class TestStreamWaitState : public ::testing::Test {
120
120
121
121
};
122
122
123
+ // Test return of error timeout when zero passed as the timeoutNanos.
123
124
TEST_F (TestStreamWaitState, OutputLowWaitZero) {
124
125
ASSERT_TRUE (openStream (Direction::Output, PerformanceMode::LowLatency));
125
- checkWaitZeroTimeout ( );
126
+ checkWaitForStateChangeTimeout ( 0 );
126
127
ASSERT_TRUE (closeStream ());
127
128
}
128
129
129
130
TEST_F (TestStreamWaitState, OutputNoneWaitZero) {
130
131
ASSERT_TRUE (openStream (Direction::Output, PerformanceMode::None));
131
- checkWaitZeroTimeout ( );
132
+ checkWaitForStateChangeTimeout ( 0 );
132
133
ASSERT_TRUE (closeStream ());
133
134
}
134
135
@@ -137,7 +138,7 @@ TEST_F(TestStreamWaitState, OutputLowWaitZeroSLES) {
137
138
builder.setPerformanceMode (PerformanceMode::LowLatency);
138
139
builder.setAudioApi (AudioApi::OpenSLES);
139
140
ASSERT_TRUE (openStream (builder));
140
- checkWaitZeroTimeout ( );
141
+ checkWaitForStateChangeTimeout ( 0 );
141
142
ASSERT_TRUE (closeStream ());
142
143
}
143
144
@@ -146,10 +147,40 @@ TEST_F(TestStreamWaitState, OutputNoneWaitZeroSLES) {
146
147
builder.setPerformanceMode (PerformanceMode::None);
147
148
builder.setAudioApi (AudioApi::OpenSLES);
148
149
ASSERT_TRUE (openStream (builder));
149
- checkWaitZeroTimeout ();
150
+ checkWaitForStateChangeTimeout (0 );
151
+ ASSERT_TRUE (closeStream ());
152
+ }
153
+
154
+ // Test actual timeout.
155
+ TEST_F (TestStreamWaitState, OutputLowWaitNonZero) {
156
+ ASSERT_TRUE (openStream (Direction::Output, PerformanceMode::LowLatency));
157
+ checkWaitForStateChangeTimeout ();
150
158
ASSERT_TRUE (closeStream ());
151
159
}
152
160
161
+ TEST_F (TestStreamWaitState, OutputNoneWaitNonZero) {
162
+ ASSERT_TRUE (openStream (Direction::Output, PerformanceMode::None));
163
+ checkWaitForStateChangeTimeout ();
164
+ ASSERT_TRUE (closeStream ());
165
+ }
166
+
167
+ TEST_F (TestStreamWaitState, OutputLowWaitNonZeroSLES) {
168
+ AudioStreamBuilder builder;
169
+ builder.setPerformanceMode (PerformanceMode::LowLatency);
170
+ builder.setAudioApi (AudioApi::OpenSLES);
171
+ ASSERT_TRUE (openStream (builder));
172
+ checkWaitForStateChangeTimeout ();
173
+ ASSERT_TRUE (closeStream ());
174
+ }
175
+
176
+ TEST_F (TestStreamWaitState, OutputNoneWaitNonZeroSLES) {
177
+ AudioStreamBuilder builder;
178
+ builder.setPerformanceMode (PerformanceMode::None);
179
+ builder.setAudioApi (AudioApi::OpenSLES);
180
+ ASSERT_TRUE (openStream (builder));
181
+ checkWaitForStateChangeTimeout ();
182
+ ASSERT_TRUE (closeStream ());
183
+ }
153
184
154
185
TEST_F (TestStreamWaitState, OutputLowStopWhileWaiting) {
155
186
ASSERT_TRUE (openStream (Direction::Output, PerformanceMode::LowLatency));
@@ -215,4 +246,4 @@ TEST_F(TestStreamWaitState, OutputLowCloseWhileWaitingSLES) {
215
246
ASSERT_TRUE (openStream (builder));
216
247
checkCloseWhileWaiting ();
217
248
ASSERT_TRUE (closeStream ());
218
- }
249
+ }
0 commit comments