Chromium Code Reviews| 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> | |
| 12 #include <memory> | |
| 13 | |
| 11 #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/timing.h" | |
| 12 #include "webrtc/test/gtest.h" | 16 #include "webrtc/test/gtest.h" |
| 17 #include "webrtc/test/testsupport/fileutils.h" | |
| 13 | 18 |
| 14 namespace webrtc { | 19 namespace webrtc { |
| 15 namespace test { | 20 namespace test { |
| 16 namespace { | 21 namespace { |
| 17 | 22 |
| 23 typedef conversational_speech::Timing Timing; | |
| 24 typedef conversational_speech::Timing::Turn Turn; | |
|
kwiberg-webrtc
2017/03/16 14:10:08
I don't think there's ever a reason to use typedef
AleBzk
2017/03/20 14:25:27
Just wanted to make an alias.
Should I remove both
kwiberg-webrtc
2017/03/21 22:35:14
Sorry, I should probably have put quotes around "u
| |
| 25 | |
| 18 const char* const audiotracks_path = "/path/to/audiotracks"; | 26 const char* const audiotracks_path = "/path/to/audiotracks"; |
| 19 const char* const timing_filepath = "/path/to/timing_file.txt"; | 27 const char* const timing_filepath = "/path/to/timing_file.txt"; |
| 20 const char* const output_path = "/path/to/output_dir"; | 28 const char* const output_path = "/path/to/output_dir"; |
| 21 | 29 |
| 30 const std::size_t kNumberOfTurns = 6; | |
| 31 Turn const turns[kNumberOfTurns] = { | |
|
kwiberg-webrtc
2017/03/16 14:10:08
Don't put a number between the []. That way, it ca
AleBzk
2017/03/20 14:25:28
This was intentional even if it may look strange.
kwiberg-webrtc
2017/03/21 22:35:14
Third option. Use [] without a number, and use arr
| |
| 32 {"A", "a1", 0}, | |
| 33 {"B", "b1", 0}, | |
| 34 {"A", "a2", 100}, | |
| 35 {"B", "b2", -200}, | |
| 36 {"A", "a3", 0}, | |
| 37 {"A", "a4", 0}, | |
| 38 }; | |
| 39 | |
| 40 // Create a Timing instance populated with turns. | |
| 41 std::unique_ptr<Timing> CreateTiming() { | |
| 42 std::unique_ptr<Timing> timing = std::unique_ptr<Timing>(new Timing()); | |
| 43 | |
| 44 // Add turns. | |
| 45 for (Turn turn_ : turns) { | |
|
kwiberg-webrtc
2017/03/16 14:10:08
Please don't use trailing _ in anything except mem
AleBzk
2017/03/20 14:25:27
Done.
| |
| 46 auto turn = std::unique_ptr<Turn>( | |
| 47 new Turn(turn_.speaker_name, turn_.audiotrack_file_name, turn_.offset)); | |
| 48 timing->AppendTurn(std::move(turn)); | |
|
kwiberg-webrtc
2017/03/16 14:10:08
You don't need to bind the std::unique_ptr<Turn> t
AleBzk
2017/03/20 14:25:27
Done.
| |
| 49 } | |
| 50 | |
| 51 return timing; | |
| 52 } | |
| 53 | |
| 22 } // namespace | 54 } // namespace |
| 23 | 55 |
| 24 TEST(ConversationalSpeechTest, Settings) { | 56 TEST(ConversationalSpeechTest, Settings) { |
| 25 conversational_speech::Config config( | 57 conversational_speech::Config config( |
| 26 audiotracks_path, timing_filepath, output_path); | 58 audiotracks_path, timing_filepath, output_path); |
| 27 | 59 |
| 28 // Test getters. | 60 // Test getters. |
| 29 EXPECT_EQ(config.audiotracks_path(), audiotracks_path); | 61 EXPECT_EQ(config.audiotracks_path(), audiotracks_path); |
| 30 EXPECT_EQ(config.timing_filepath(), timing_filepath); | 62 EXPECT_EQ(config.timing_filepath(), timing_filepath); |
| 31 EXPECT_EQ(config.output_path(), output_path); | 63 EXPECT_EQ(config.output_path(), output_path); |
| 32 } | 64 } |
| 33 | 65 |
| 66 TEST(ConversationalSpeechTest, TimingInstanceRead) { | |
| 67 std::unique_ptr<Timing> timing = CreateTiming(); | |
| 68 | |
| 69 // Check size. | |
| 70 EXPECT_EQ(timing->Size(), kNumberOfTurns); | |
| 71 | |
| 72 // Test move semantic while iterating over turns. | |
| 73 std::size_t index = 0; | |
| 74 for (const auto& turn : timing->turns()) { | |
| 75 Turn expected_turn = turns[index++]; | |
| 76 EXPECT_EQ(expected_turn.speaker_name, turn->speaker_name); | |
| 77 EXPECT_EQ(expected_turn.audiotrack_file_name, turn->audiotrack_file_name); | |
| 78 EXPECT_EQ(expected_turn.offset, turn->offset); | |
| 79 } | |
|
kwiberg-webrtc
2017/03/16 14:10:08
To minimize the risk of human error, consider incr
AleBzk
2017/03/20 14:25:28
Done.
| |
| 80 } | |
| 81 | |
| 82 TEST(ConversationalSpeechTest, SaveLoadSettings) { | |
| 83 std::string temporary_filepath = webrtc::test::TempFilename( | |
|
kwiberg-webrtc
2017/03/16 14:10:08
const std::string. It's a good habit to use const
AleBzk
2017/03/20 14:25:27
Done.
| |
| 84 webrtc::test::OutputPath(), "TempTimingTestFile"); | |
| 85 | |
| 86 // Create a populated Timing instance and save it to a temporary file. | |
| 87 std::unique_ptr<Timing> expected_timing = CreateTiming(); | |
| 88 expected_timing->Save(temporary_filepath); | |
| 89 | |
| 90 // New Timing instance populated by loading the temporary file. | |
| 91 Timing timing; | |
| 92 timing.Load(temporary_filepath); | |
| 93 std::remove(temporary_filepath.c_str()); | |
| 94 | |
| 95 // Check size. | |
| 96 EXPECT_EQ(expected_timing->Size(), timing.Size()); | |
| 97 | |
| 98 // Check turns. | |
| 99 const std::vector<std::unique_ptr<Turn>>& expected_turns = | |
| 100 expected_timing->turns(); | |
| 101 const std::vector<std::unique_ptr<Turn>>& turns = timing.turns(); | |
| 102 for (std::size_t index = 0; index < timing.Size(); index++) { | |
| 103 // TODO(alessiob): is this a good practice? I need that the client code | |
| 104 // iterates the turns without owning the pointers. | |
| 105 Turn* expected_turn = expected_turns[index].get(); | |
| 106 Turn* turn = turns[index].get(); | |
|
kwiberg-webrtc
2017/03/16 14:10:08
You don't need to bind these to local variables. A
AleBzk
2017/03/20 14:25:27
Done.
| |
| 107 EXPECT_TRUE(*expected_turn == *turn) | |
| 108 << "turn #" << index << " not matching"; | |
| 109 } | |
| 110 } | |
| 111 | |
| 34 } // namespace test | 112 } // namespace test |
| 35 } // namespace webrtc | 113 } // namespace webrtc |
| OLD | NEW |