@@ -30,71 +30,71 @@ static const char* ALLOC_TAG = "TextToSpeechManagerTests";
30
30
31
31
class MockPCMDriver : public PCMOutputDriver
32
32
{
33
- public:
34
- MockPCMDriver () : m_primeCalledCount(0 ), m_flushCalledCount(0 ), m_mockWriteResponse(false ) {}
35
-
36
- bool WriteBufferToDevice (const unsigned char * buffer, size_t size) override
37
- {
38
- m_buffersWritten.push_back (ByteBuffer (buffer, size));
39
- return m_mockWriteResponse;
40
- }
41
-
42
- void MockWriteResponse (bool response)
43
- {
44
- m_mockWriteResponse = response;
45
- }
46
-
47
- const Aws::Vector<ByteBuffer>& GetWrittenBuffers () const
48
- {
49
- return m_buffersWritten;
50
- }
51
-
52
- Aws::Vector<DeviceInfo> EnumerateDevices () const override
53
- {
54
- return m_devices;
55
- }
56
-
57
- void AddDevice (const DeviceInfo& device)
58
- {
59
- m_devices.push_back (device);
60
- }
61
-
62
- void SetActiveDevice (const DeviceInfo& device, const CapabilityInfo& caps) override
63
- {
64
- m_activeDevice = device;
65
- m_selectedCaps = caps;
66
- }
67
-
68
- const DeviceInfo& GetActiveDevice () const
69
- {
70
- return m_activeDevice;
71
- }
72
-
73
- const CapabilityInfo& GetActiveCaps () const
74
- {
75
- return m_selectedCaps;
76
- }
77
-
78
- const char * GetName () const override
79
- {
80
- return MOCK_DRIVER_NAME;
81
- }
82
-
83
- size_t GetPrimeCalledCount () const
84
- {
85
- return m_primeCalledCount;
86
- }
87
-
88
- void Prime () override
89
- {
90
- m_primeCalledCount++;
91
- }
92
-
93
- size_t GetFlushCalledCount () const
94
- {
95
- return m_primeCalledCount;
96
- }
97
-
33
+ public:
34
+ MockPCMDriver () : m_primeCalledCount(0 ), m_flushCalledCount(0 ), m_mockWriteResponse(false ) {}
35
+
36
+ bool WriteBufferToDevice (const unsigned char * buffer, size_t size) override
37
+ {
38
+ m_buffersWritten.push_back (ByteBuffer (buffer, size));
39
+ return m_mockWriteResponse;
40
+ }
41
+
42
+ void MockWriteResponse (bool response)
43
+ {
44
+ m_mockWriteResponse = response;
45
+ }
46
+
47
+ const Aws::Vector<ByteBuffer>& GetWrittenBuffers () const
48
+ {
49
+ return m_buffersWritten;
50
+ }
51
+
52
+ Aws::Vector<DeviceInfo> EnumerateDevices () const override
53
+ {
54
+ return m_devices;
55
+ }
56
+
57
+ void AddDevice (const DeviceInfo& device)
58
+ {
59
+ m_devices.push_back (device);
60
+ }
61
+
62
+ void SetActiveDevice (const DeviceInfo& device, const CapabilityInfo& caps) override
63
+ {
64
+ m_activeDevice = device;
65
+ m_selectedCaps = caps;
66
+ }
67
+
68
+ const DeviceInfo& GetActiveDevice () const
69
+ {
70
+ return m_activeDevice;
71
+ }
72
+
73
+ const CapabilityInfo& GetActiveCaps () const
74
+ {
75
+ return m_selectedCaps;
76
+ }
77
+
78
+ const char * GetName () const override
79
+ {
80
+ return MOCK_DRIVER_NAME;
81
+ }
82
+
83
+ size_t GetPrimeCalledCount () const
84
+ {
85
+ return m_primeCalledCount;
86
+ }
87
+
88
+ void Prime () override
89
+ {
90
+ m_primeCalledCount++;
91
+ }
92
+
93
+ size_t GetFlushCalledCount () const
94
+ {
95
+ return m_primeCalledCount;
96
+ }
97
+
98
98
void Flush () override
99
99
{
100
100
m_flushCalledCount++;
@@ -320,14 +320,15 @@ TEST(TextToSpeechManagerTests, TestSynthResponseAndOutput)
320
320
const char * REQUEST_TEXT = " Blah blah blah" ;
321
321
322
322
SendTextCompletedHandler handler = [&](const char * text, const SynthesizeSpeechOutcome&, bool sent)
323
- {
324
- EXPECT_STREQ (REQUEST_TEXT, text);
325
- EXPECT_TRUE (sent);
326
- semaphore.notify_all ();
323
+ {
324
+ std::lock_guard<std::mutex> lockGuard (lock);
325
+ EXPECT_STREQ (REQUEST_TEXT, text);
326
+ EXPECT_TRUE (sent);
327
+ semaphore.notify_all ();
327
328
};
328
329
329
- manager.SendTextToOutputDevice (REQUEST_TEXT, handler);
330
330
std::unique_lock<std::mutex> locker (lock);
331
+ manager.SendTextToOutputDevice (REQUEST_TEXT, handler);
331
332
semaphore.wait (locker);
332
333
333
334
auto capturedRequest = pollyClient->GetCapturedSynthesizeSpeech ();
@@ -381,13 +382,14 @@ TEST(TextToSpeechManagerTests, TestSynthRequestFailedAndNoOutput)
381
382
382
383
SendTextCompletedHandler handler = [&](const char * text, const SynthesizeSpeechOutcome&, bool sent)
383
384
{
385
+ std::lock_guard<std::mutex> lockGuard (lock);
384
386
EXPECT_STREQ (REQUEST_TEXT, text);
385
387
EXPECT_FALSE (sent);
386
388
semaphore.notify_all ();
387
389
};
388
390
389
- manager.SendTextToOutputDevice (REQUEST_TEXT, handler);
390
391
std::unique_lock<std::mutex> locker (lock);
392
+ manager.SendTextToOutputDevice (REQUEST_TEXT, handler);
391
393
semaphore.wait (locker);
392
394
393
395
auto capturedRequest = pollyClient->GetCapturedSynthesizeSpeech ();
0 commit comments