| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include <cstdio> | 11 #include <stdio.h> |
| 12 #include <memory> | 12 #include <memory> |
| 13 | 13 |
| 14 #include "webrtc/modules/audio_processing/test/conversational_speech/config.h" | 14 #include "webrtc/modules/audio_processing/test/conversational_speech/config.h" |
| 15 #include "webrtc/modules/audio_processing/test/conversational_speech/mock_wavrea
der_factory.h" |
| 16 #include "webrtc/modules/audio_processing/test/conversational_speech/multiend_ca
ll.h" |
| 15 #include "webrtc/modules/audio_processing/test/conversational_speech/timing.h" | 17 #include "webrtc/modules/audio_processing/test/conversational_speech/timing.h" |
| 18 #include "webrtc/test/gmock.h" |
| 16 #include "webrtc/test/gtest.h" | 19 #include "webrtc/test/gtest.h" |
| 17 #include "webrtc/test/testsupport/fileutils.h" | 20 #include "webrtc/test/testsupport/fileutils.h" |
| 18 | 21 |
| 19 namespace webrtc { | 22 namespace webrtc { |
| 20 namespace test { | 23 namespace test { |
| 21 namespace { | 24 namespace { |
| 22 | 25 |
| 23 using conversational_speech::LoadTiming; | 26 using conversational_speech::LoadTiming; |
| 24 using conversational_speech::SaveTiming; | 27 using conversational_speech::SaveTiming; |
| 28 using conversational_speech::MockWavReaderFactory; |
| 29 using conversational_speech::MultiEndCall; |
| 25 using conversational_speech::Turn; | 30 using conversational_speech::Turn; |
| 31 using conversational_speech::WavReaderAbstractFactory; |
| 26 | 32 |
| 27 const char* const audiotracks_path = "/path/to/audiotracks"; | 33 const char* const audiotracks_path = "/path/to/audiotracks"; |
| 28 const char* const timing_filepath = "/path/to/timing_file.txt"; | 34 const char* const timing_filepath = "/path/to/timing_file.txt"; |
| 29 const char* const output_path = "/path/to/output_dir"; | 35 const char* const output_path = "/path/to/output_dir"; |
| 30 | 36 |
| 31 const std::vector<Turn> expected_timing = { | 37 const std::vector<Turn> expected_timing = { |
| 32 {"A", "a1", 0}, | 38 {"A", "a1", 0}, |
| 33 {"B", "b1", 0}, | 39 {"B", "b1", 0}, |
| 34 {"A", "a2", 100}, | 40 {"A", "a2", 100}, |
| 35 {"B", "b2", -200}, | 41 {"B", "b2", -200}, |
| 36 {"A", "a3", 0}, | 42 {"A", "a3", 0}, |
| 37 {"A", "a4", 0}, | 43 {"A", "a3", 0}, |
| 38 }; | 44 }; |
| 39 const std::size_t kNumberOfTurns = expected_timing.size(); | 45 const std::size_t kNumberOfTurns = expected_timing.size(); |
| 40 | 46 |
| 41 } // namespace | 47 } // namespace |
| 42 | 48 |
| 43 TEST(ConversationalSpeechTest, Settings) { | 49 TEST(ConversationalSpeechTest, Settings) { |
| 44 const conversational_speech::Config config( | 50 const conversational_speech::Config config( |
| 45 audiotracks_path, timing_filepath, output_path); | 51 audiotracks_path, timing_filepath, output_path); |
| 46 | 52 |
| 47 // Test getters. | 53 // Test getters. |
| 48 EXPECT_EQ(audiotracks_path, config.audiotracks_path()); | 54 EXPECT_EQ(audiotracks_path, config.audiotracks_path()); |
| 49 EXPECT_EQ(timing_filepath, config.timing_filepath()); | 55 EXPECT_EQ(timing_filepath, config.timing_filepath()); |
| 50 EXPECT_EQ(output_path, config.output_path()); | 56 EXPECT_EQ(output_path, config.output_path()); |
| 51 } | 57 } |
| 52 | 58 |
| 53 TEST(ConversationalSpeechTest, ExpectedTimingSize) { | |
| 54 // Check the expected timing size. | |
| 55 EXPECT_EQ(kNumberOfTurns, 6u); | |
| 56 } | |
| 57 | |
| 58 TEST(ConversationalSpeechTest, TimingSaveLoad) { | 59 TEST(ConversationalSpeechTest, TimingSaveLoad) { |
| 59 // Save test timing. | 60 // Save test timing. |
| 60 const std::string temporary_filepath = webrtc::test::TempFilename( | 61 const std::string temporary_filepath = webrtc::test::TempFilename( |
| 61 webrtc::test::OutputPath(), "TempTimingTestFile"); | 62 webrtc::test::OutputPath(), "TempTimingTestFile"); |
| 62 SaveTiming(temporary_filepath, expected_timing); | 63 SaveTiming(temporary_filepath, expected_timing); |
| 63 | 64 |
| 64 // Create a std::vector<Turn> instance by loading from file. | 65 // Create a std::vector<Turn> instance by loading from file. |
| 65 std::vector<Turn> actual_timing = LoadTiming(temporary_filepath); | 66 std::vector<Turn> actual_timing = LoadTiming(temporary_filepath); |
| 66 std::remove(temporary_filepath.c_str()); | 67 std::remove(temporary_filepath.c_str()); |
| 67 | 68 |
| 68 // Check size. | 69 // Check size. |
| 69 EXPECT_EQ(expected_timing.size(), actual_timing.size()); | 70 EXPECT_EQ(expected_timing.size(), actual_timing.size()); |
| 70 | 71 |
| 71 // Check Turn instances. | 72 // Check Turn instances. |
| 72 for (size_t index = 0; index < expected_timing.size(); ++index) { | 73 for (size_t index = 0; index < expected_timing.size(); ++index) { |
| 73 EXPECT_EQ(expected_timing[index], actual_timing[index]) | 74 EXPECT_EQ(expected_timing[index], actual_timing[index]) |
| 74 << "turn #" << index << " not matching"; | 75 << "turn #" << index << " not matching"; |
| 75 } | 76 } |
| 76 } | 77 } |
| 77 | 78 |
| 79 TEST(ConversationalSpeechTest, MultiEndCallCreate) { |
| 80 auto mock_wavreader_factory = std::unique_ptr<MockWavReaderFactory>( |
| 81 new MockWavReaderFactory()); |
| 82 |
| 83 // There are 5 unique audio tracks to read. |
| 84 EXPECT_CALL(*mock_wavreader_factory, Create(testing::_)).Times(5); |
| 85 |
| 86 // Inject the mock wav reader factory. |
| 87 conversational_speech::MultiEndCall multiend_call( |
| 88 expected_timing, audiotracks_path, std::move(mock_wavreader_factory)); |
| 89 |
| 90 // Test. |
| 91 EXPECT_EQ(2u, multiend_call.speaker_names().size()); |
| 92 EXPECT_EQ(5u, multiend_call.audiotrack_readers().size()); |
| 93 } |
| 94 |
| 78 } // namespace test | 95 } // namespace test |
| 79 } // namespace webrtc | 96 } // namespace webrtc |
| OLD | NEW |