Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Side by Side Diff: webrtc/modules/audio_processing/test/conversational_speech/generator_unittest.cc

Issue 2750353002: Conversational speech tool: timing model with data access. (Closed)
Patch Set: comments from Karl addressed Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
14 #include "webrtc/base/array_view.h"
11 #include "webrtc/modules/audio_processing/test/conversational_speech/config.h" 15 #include "webrtc/modules/audio_processing/test/conversational_speech/config.h"
16 #include "webrtc/modules/audio_processing/test/conversational_speech/timing.h"
12 #include "webrtc/test/gtest.h" 17 #include "webrtc/test/gtest.h"
18 #include "webrtc/test/testsupport/fileutils.h"
13 19
14 namespace webrtc { 20 namespace webrtc {
15 namespace test { 21 namespace test {
16 namespace { 22 namespace {
17 23
24 typedef conversational_speech::Timing Timing;
25 typedef conversational_speech::Timing::Turn Turn;
26
18 const char* const audiotracks_path = "/path/to/audiotracks"; 27 const char* const audiotracks_path = "/path/to/audiotracks";
19 const char* const timing_filepath = "/path/to/timing_file.txt"; 28 const char* const timing_filepath = "/path/to/timing_file.txt";
20 const char* const output_path = "/path/to/output_dir"; 29 const char* const output_path = "/path/to/output_dir";
21 30
31 const std::size_t kNumberOfTurns = 6;
32 const Turn turns[kNumberOfTurns] = {
33 {"A", "a1", 0},
34 {"B", "b1", 0},
35 {"A", "a2", 100},
36 {"B", "b2", -200},
37 {"A", "a3", 0},
38 {"A", "a4", 0},
39 };
40
41 // Create a Timing instance populated with turns.
42 std::unique_ptr<Timing> CreateTiming() {
43 std::unique_ptr<Timing> timing = std::unique_ptr<Timing>(new Timing());
44
45 // Add turns.
46 for (Turn source_turn : turns) {
kwiberg-webrtc 2017/03/21 22:35:15 Almost always use const& (or just &, if you need m
AleBzk 2017/03/22 10:07:22 Done.
47 timing->AppendTurn(Turn(
48 source_turn.speaker_name,
49 source_turn.audiotrack_file_name,
50 source_turn.offset));
kwiberg-webrtc 2017/03/21 22:35:15 Why not just timing->AppendTurn(source_turn);
AleBzk 2017/03/22 10:07:21 Not applying anymore.
51 }
kwiberg-webrtc 2017/03/21 22:35:15 Hmm. Use the new initializer_list constructor here
AleBzk 2017/03/22 10:07:22 Not applying anymore.
52
53 return timing;
54 }
55
22 } // namespace 56 } // namespace
23 57
24 TEST(ConversationalSpeechTest, Settings) { 58 TEST(ConversationalSpeechTest, Settings) {
25 conversational_speech::Config config( 59 const conversational_speech::Config config(
26 audiotracks_path, timing_filepath, output_path); 60 audiotracks_path, timing_filepath, output_path);
27 61
28 // Test getters. 62 // Test getters.
29 EXPECT_EQ(config.audiotracks_path(), audiotracks_path); 63 EXPECT_EQ(config.audiotracks_path(), audiotracks_path);
30 EXPECT_EQ(config.timing_filepath(), timing_filepath); 64 EXPECT_EQ(config.timing_filepath(), timing_filepath);
31 EXPECT_EQ(config.output_path(), output_path); 65 EXPECT_EQ(config.output_path(), output_path);
32 } 66 }
33 67
68 TEST(ConversationalSpeechTest, TimingInitializerList) {
69 // Test initializer list for the Timing class.
70 const std::size_t kNumberOfTurns = 6;
71 Timing actual_timing = {
72 Turn("A", "a1", 0),
73 Turn("B", "b1", 0),
74 Turn("A", "a2", 100),
75 Turn("B", "b2", -200),
76 Turn("A", "a3", 0),
77 Turn("A", "a4", 0),
78 };
79 EXPECT_EQ(actual_timing.turns().size(), kNumberOfTurns);
kwiberg-webrtc 2017/03/21 22:35:15 "kNumberOfTurns" isn't much use here. Just use a l
AleBzk 2017/03/22 10:07:21 Done.
80 }
81
AleBzk 2017/03/20 14:25:28 I added a new constructor for Timing to familiariz
kwiberg-webrtc 2017/03/21 22:35:15 Hmm. Is it useful enough to pay for the extra comp
AleBzk 2017/03/22 10:07:21 I don't need it anymore due to the refactoring.
82 TEST(ConversationalSpeechTest, TimingInstanceRead) {
83 const std::unique_ptr<Timing> actual_timing = CreateTiming();
84 rtc::ArrayView<const Timing::Turn> actual_turns = actual_timing->turns();
85
86 // Check size.
87 EXPECT_EQ(actual_turns.size(), kNumberOfTurns);
88
89 // Check members for each turn.
90 for (size_t index = 0; index < actual_turns.size(); ++index) {
91 const auto& actual_turn = actual_turns[index];
92 const auto& expected_turn = turns[index];
93 EXPECT_EQ(actual_turn.speaker_name, expected_turn.speaker_name);
94 EXPECT_EQ(actual_turn.audiotrack_file_name,
95 expected_turn.audiotrack_file_name);
96 EXPECT_EQ(actual_turn.offset, expected_turn.offset);
kwiberg-webrtc 2017/03/21 22:35:15 Should Turn have an operator==? Or does it already
AleBzk 2017/03/22 10:07:22 Right, however I removed this test due to the refa
97 }
98 }
99
100 TEST(ConversationalSpeechTest, SaveLoadSettings) {
101 const std::string temporary_filepath = webrtc::test::TempFilename(
102 webrtc::test::OutputPath(), "TempTimingTestFile");
103
104 // Create a populated Timing instance and save it to a temporary file.
105 const std::unique_ptr<Timing> expected_timing = CreateTiming();
106 expected_timing->Save(temporary_filepath);
107
108 // New Timing instance populated by loading the temporary file.
109 Timing actual_timing;
110 actual_timing.Load(temporary_filepath);
111 std::remove(temporary_filepath.c_str());
112
113 // Check size.
114 rtc::ArrayView<const Timing::Turn> expected_turns = expected_timing->turns();
115 rtc::ArrayView<const Timing::Turn> actual_turns = actual_timing.turns();
116 EXPECT_EQ(expected_turns.size(), actual_turns.size());
117
118 // Check Turn instances.
119 for (size_t index = 0; index < actual_turns.size(); ++index) {
120 EXPECT_TRUE(expected_turns[index] == actual_turns[index])
kwiberg-webrtc 2017/03/21 22:35:15 EXPECT_EQ?
AleBzk 2017/03/22 10:07:21 Done.
121 << "turn #" << index << " not matching";
122 }
123 }
124
34 } // namespace test 125 } // namespace test
35 } // namespace webrtc 126 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698