1 // Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <gtest/gtest.h>
6 #include <stdio.h>
7
8 extern "C" {
9 #include "cras_volume_curve.h"
10 }
11
12 namespace {
13
TEST(VolumeCurve,DefaultCurve)14 TEST(VolumeCurve, DefaultCurve) {
15 struct cras_volume_curve* curve;
16 curve = cras_volume_curve_create_default();
17 ASSERT_NE(static_cast<struct cras_volume_curve*>(NULL), curve);
18 EXPECT_EQ(0 - 50 * 50, curve->get_dBFS(curve, 50));
19 EXPECT_EQ(0, curve->get_dBFS(curve, 100));
20 EXPECT_EQ(0 - 100 * 50, curve->get_dBFS(curve, 0));
21 EXPECT_EQ(0 - 25 * 50, curve->get_dBFS(curve, 75));
22 cras_volume_curve_destroy(curve);
23 }
24
TEST(VolumeCurve,SteppedCurve)25 TEST(VolumeCurve, SteppedCurve) {
26 struct cras_volume_curve* curve;
27 curve = cras_volume_curve_create_simple_step(-600, 75);
28 ASSERT_NE(static_cast<struct cras_volume_curve*>(NULL), curve);
29 EXPECT_EQ(-600 - 50 * 75, curve->get_dBFS(curve, 50));
30 EXPECT_EQ(-600, curve->get_dBFS(curve, 100));
31 EXPECT_EQ(-600 - 100 * 75, curve->get_dBFS(curve, 0));
32 EXPECT_EQ(-600 - 25 * 75, curve->get_dBFS(curve, 75));
33 cras_volume_curve_destroy(curve);
34 }
35
TEST(VolumeCurve,ExplicitCurve)36 TEST(VolumeCurve, ExplicitCurve) {
37 struct cras_volume_curve* curve;
38 long dB_vals[101];
39
40 for (unsigned int i = 0; i < 101; i++)
41 dB_vals[i] = i * 2 + -400;
42 curve = cras_volume_curve_create_explicit(dB_vals);
43 ASSERT_NE(static_cast<struct cras_volume_curve*>(NULL), curve);
44 for (unsigned int i = 0; i < 101; i++)
45 EXPECT_EQ(i * 2 - 400, curve->get_dBFS(curve, i));
46 cras_volume_curve_destroy(curve);
47 }
48
49 } // namespace
50
main(int argc,char ** argv)51 int main(int argc, char** argv) {
52 ::testing::InitGoogleTest(&argc, argv);
53 return RUN_ALL_TESTS();
54 }
55