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

Side by Side Diff: chromeos/dbus/cras_audio_client_unittest.cc

Issue 1883343002: Finishing cras audio client unittest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chromeos/dbus/cras_audio_client.h" 5 #include "chromeos/dbus/cras_audio_client.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 const double* doubles = nullptr; 87 const double* doubles = nullptr;
88 size_t size = 0; 88 size_t size = 0;
89 ASSERT_TRUE(reader->PopArrayOfDoubles(&doubles, &size)); 89 ASSERT_TRUE(reader->PopArrayOfDoubles(&doubles, &size));
90 EXPECT_EQ(expected_doubles.size(), size); 90 EXPECT_EQ(expected_doubles.size(), size);
91 for (size_t i = 0; i < size; ++i) { 91 for (size_t i = 0; i < size; ++i) {
92 EXPECT_EQ(expected_doubles[i], doubles[i]); 92 EXPECT_EQ(expected_doubles[i], doubles[i]);
93 } 93 }
94 EXPECT_FALSE(reader->HasMoreData()); 94 EXPECT_FALSE(reader->HasMoreData());
95 } 95 }
96 96
97 // Expect the reader to have an uint64_t and an int32_t.
98 void ExpectUint64AndInt32Arguments(uint64_t expected_uint64,
99 int32_t expected_int32,
100 dbus::MessageReader* reader) {
101 uint64_t value1;
102 ASSERT_TRUE(reader->PopUint64(&value1));
103 EXPECT_EQ(expected_uint64, value1);
104 int32_t value2;
105 ASSERT_TRUE(reader->PopInt32(&value2));
106 EXPECT_EQ(expected_int32, value2);
107 EXPECT_FALSE(reader->HasMoreData());
108 }
109
110 // Expect the reader to have an uint64_t.
111 void ExpectUint64Argument(uint64_t expected_value,
112 dbus::MessageReader* reader) {
113 uint64_t value;
114 ASSERT_TRUE(reader->PopUint64(&value));
115 EXPECT_EQ(expected_value, value);
116 EXPECT_FALSE(reader->HasMoreData());
117 }
118
119 // Expect the reader to have a bool.
120 void ExpectBoolArgument(bool expected_bool, dbus::MessageReader* reader) {
121 bool value;
122 ASSERT_TRUE(reader->PopBool(&value));
123 EXPECT_EQ(expected_bool, value);
124 EXPECT_FALSE(reader->HasMoreData());
125 }
126
127 // Expect the reader to have an uint64_t and a bool.
128 void ExpectUint64AndBoolArguments(uint64_t expected_uint64,
129 bool expected_bool,
130 dbus::MessageReader* reader) {
131 uint64_t value1;
132 ASSERT_TRUE(reader->PopUint64(&value1));
133 EXPECT_EQ(expected_uint64, value1);
134 bool value2;
135 ASSERT_TRUE(reader->PopBool(&value2));
136 EXPECT_EQ(expected_bool, value2);
137 EXPECT_FALSE(reader->HasMoreData());
138 }
139
97 void WriteNodesToResponse(dbus::MessageWriter& writer, 140 void WriteNodesToResponse(dbus::MessageWriter& writer,
98 const AudioNodeList& node_list) { 141 const AudioNodeList& node_list) {
99 dbus::MessageWriter sub_writer(nullptr); 142 dbus::MessageWriter sub_writer(nullptr);
100 dbus::MessageWriter entry_writer(nullptr); 143 dbus::MessageWriter entry_writer(nullptr);
101 for (size_t i = 0; i < node_list.size(); ++i) { 144 for (size_t i = 0; i < node_list.size(); ++i) {
102 writer.OpenArray("{sv}", &sub_writer); 145 writer.OpenArray("{sv}", &sub_writer);
103 sub_writer.OpenDictEntry(&entry_writer); 146 sub_writer.OpenDictEntry(&entry_writer);
104 entry_writer.AppendString(cras::kIsInputProperty); 147 entry_writer.AppendString(cras::kIsInputProperty);
105 entry_writer.AppendVariantOfBool(node_list[i].is_input); 148 entry_writer.AppendVariantOfBool(node_list[i].is_input);
106 sub_writer.CloseContainer(&entry_writer); 149 sub_writer.CloseContainer(&entry_writer);
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 // Call method. 635 // Call method.
593 MockErrorCallback error_callback; 636 MockErrorCallback error_callback;
594 client_->GetNodes(base::Bind(&ExpectAudioNodeListResult, 637 client_->GetNodes(base::Bind(&ExpectAudioNodeListResult,
595 &expected_node_list), 638 &expected_node_list),
596 error_callback.GetCallback()); 639 error_callback.GetCallback());
597 EXPECT_CALL(error_callback, Run(_, _)).Times(0); 640 EXPECT_CALL(error_callback, Run(_, _)).Times(0);
598 // Run the message loop. 641 // Run the message loop.
599 message_loop_.RunUntilIdle(); 642 message_loop_.RunUntilIdle();
600 } 643 }
601 644
645 TEST_F(CrasAudioClientTest, SetOutputNodeVolume) {
646 const uint64_t kNodeId = 10003;
647 const int32_t kVolume = 80;
648 // Create response.
649 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
650
651 // Set expectations.
652 PrepareForMethodCall(cras::kSetOutputNodeVolume,
653 base::Bind(&ExpectUint64AndInt32Arguments,
654 kNodeId,
655 kVolume),
656 response.get());
657 // Call method.
658 client_->SetOutputNodeVolume(kNodeId, kVolume);
659 // Run the message loop.
660 message_loop_.RunUntilIdle();
661 }
662
663 TEST_F(CrasAudioClientTest, SetOutputUserMute) {
664 const bool kUserMuteOn = true;
665 // Create response.
666 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
667
668 // Set expectations.
669 PrepareForMethodCall(cras::kSetOutputUserMute,
670 base::Bind(&ExpectBoolArgument, kUserMuteOn),
671 response.get());
672 // Call method.
673 client_->SetOutputUserMute(kUserMuteOn);
674 // Run the message loop.
675 message_loop_.RunUntilIdle();
676 }
677
678 TEST_F(CrasAudioClientTest, SetInputNodeGain) {
679 const uint64_t kNodeId = 20003;
680 const int32_t kInputGain = 2;
681 // Create response.
682 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
683
684 // Set expectations.
685 PrepareForMethodCall(cras::kSetInputNodeGain,
686 base::Bind(&ExpectUint64AndInt32Arguments,
687 kNodeId,
688 kInputGain),
689 response.get());
690 // Call method.
691 client_->SetInputNodeGain(kNodeId, kInputGain);
692 // Run the message loop.
693 message_loop_.RunUntilIdle();
694 }
695
696 TEST_F(CrasAudioClientTest, SetInputMute) {
697 const bool kInputMuteOn = true;
698 // Create response.
699 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
700
701 // Set expectations.
702 PrepareForMethodCall(cras::kSetInputMute,
703 base::Bind(&ExpectBoolArgument, kInputMuteOn),
704 response.get());
705 // Call method.
706 client_->SetInputMute(kInputMuteOn);
707 // Run the message loop.
708 message_loop_.RunUntilIdle();
709 }
710
711 TEST_F(CrasAudioClientTest, SetActiveOutputNode) {
712 const uint64_t kNodeId = 10004;
713 // Create response.
714 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
715
716 // Set expectations.
717 PrepareForMethodCall(cras::kSetActiveOutputNode,
718 base::Bind(&ExpectUint64Argument, kNodeId),
719 response.get());
720 // Call method.
721 client_->SetActiveOutputNode(kNodeId);
722 // Run the message loop.
723 message_loop_.RunUntilIdle();
724 }
725
726 TEST_F(CrasAudioClientTest, SetActiveInputNode) {
727 const uint64_t kNodeId = 20004;
728 // Create response.
729 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
730
731 // Set expectations.
732 PrepareForMethodCall(cras::kSetActiveInputNode,
733 base::Bind(&ExpectUint64Argument, kNodeId),
734 response.get());
735 // Call method.
736 client_->SetActiveInputNode(kNodeId);
737 // Run the message loop.
738 message_loop_.RunUntilIdle();
739 }
740
741 TEST_F(CrasAudioClientTest, AddActiveInputNode) {
742 const uint64_t kNodeId = 20005;
743 // Create response.
744 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
745
746 // Set expectations.
747 PrepareForMethodCall(cras::kAddActiveInputNode,
748 base::Bind(&ExpectUint64Argument, kNodeId),
749 response.get());
750 // Call method.
751 client_->AddActiveInputNode(kNodeId);
752 // Run the message loop.
753 message_loop_.RunUntilIdle();
754 }
755
756 TEST_F(CrasAudioClientTest, RemoveActiveInputNode) {
757 const uint64_t kNodeId = 20006;
758 // Create response.
759 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
760
761 // Set expectations.
762 PrepareForMethodCall(cras::kRemoveActiveInputNode,
763 base::Bind(&ExpectUint64Argument, kNodeId),
764 response.get());
765 // Call method.
766 client_->RemoveActiveInputNode(kNodeId);
767 // Run the message loop.
768 message_loop_.RunUntilIdle();
769 }
770
771 TEST_F(CrasAudioClientTest, AddActiveOutputNode) {
772 const uint64_t kNodeId = 10005;
773 // Create response.
774 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
775
776 // Set expectations.
777 PrepareForMethodCall(cras::kAddActiveOutputNode,
778 base::Bind(&ExpectUint64Argument, kNodeId),
779 response.get());
780 // Call method.
781 client_->AddActiveOutputNode(kNodeId);
782 // Run the message loop.
783 message_loop_.RunUntilIdle();
784 }
785
786 TEST_F(CrasAudioClientTest, RemoveActiveOutputNode) {
787 const uint64_t kNodeId = 10006;
788 // Create response.
789 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
790
791 // Set expectations.
792 PrepareForMethodCall(cras::kRemoveActiveOutputNode,
793 base::Bind(&ExpectUint64Argument, kNodeId),
794 response.get());
795 // Call method.
796 client_->RemoveActiveOutputNode(kNodeId);
797 // Run the message loop.
798 message_loop_.RunUntilIdle();
799 }
800
801 TEST_F(CrasAudioClientTest, SwapLeftRight) {
802 const uint64_t kNodeId = 10007;
803 const bool kSwap = true;
804 // Create response.
805 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
806
807 // Set expectations.
808 PrepareForMethodCall(cras::kSwapLeftRight,
809 base::Bind(&ExpectUint64AndBoolArguments,
810 kNodeId,
811 kSwap),
812 response.get());
813 // Call method.
814 client_->SwapLeftRight(kNodeId, kSwap);
815 // Run the message loop.
816 message_loop_.RunUntilIdle();
817 }
818
602 TEST_F(CrasAudioClientTest, SetGlobalOutputChannelRemix) { 819 TEST_F(CrasAudioClientTest, SetGlobalOutputChannelRemix) {
603 const int32_t kChannels = 2; 820 const int32_t kChannels = 2;
604 const std::vector<double> kMixer = {0, 0.1, 0.5, 1}; 821 const std::vector<double> kMixer = {0, 0.1, 0.5, 1};
605 // Create response. 822 // Create response.
606 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 823 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
607 824
608 // Set expectations. 825 // Set expectations.
609 PrepareForMethodCall(cras::kSetGlobalOutputChannelRemix, 826 PrepareForMethodCall(cras::kSetGlobalOutputChannelRemix,
610 base::Bind(&ExpectInt32AndArrayOfDoublesArguments, 827 base::Bind(&ExpectInt32AndArrayOfDoublesArguments,
611 kChannels, 828 kChannels,
612 kMixer), 829 kMixer),
613 response.get()); 830 response.get());
614 831
615 // Call method. 832 // Call method.
616 client_->SetGlobalOutputChannelRemix(kChannels, kMixer); 833 client_->SetGlobalOutputChannelRemix(kChannels, kMixer);
617 // Run the message loop. 834 // Run the message loop.
618 message_loop_.RunUntilIdle(); 835 message_loop_.RunUntilIdle();
619 } 836 }
620 837
621 } // namespace chromeos 838 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698