summaryrefslogtreecommitdiff
path: root/cras/src/tests/volume_curve_unittest.cc
blob: 267452aa48571411995d230d12d831a1f810d073 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <gtest/gtest.h>
#include <stdio.h>

extern "C" {
#include "cras_volume_curve.h"
}

namespace {

TEST(VolumeCurve, DefaultCurve) {
  struct cras_volume_curve* curve;
  curve = cras_volume_curve_create_default();
  ASSERT_NE(static_cast<struct cras_volume_curve*>(NULL), curve);
  EXPECT_EQ(0 - 50 * 50, curve->get_dBFS(curve, 50));
  EXPECT_EQ(0, curve->get_dBFS(curve, 100));
  EXPECT_EQ(0 - 100 * 50, curve->get_dBFS(curve, 0));
  EXPECT_EQ(0 - 25 * 50, curve->get_dBFS(curve, 75));
  cras_volume_curve_destroy(curve);
}

TEST(VolumeCurve, SteppedCurve) {
  struct cras_volume_curve* curve;
  curve = cras_volume_curve_create_simple_step(-600, 75);
  ASSERT_NE(static_cast<struct cras_volume_curve*>(NULL), curve);
  EXPECT_EQ(-600 - 50 * 75, curve->get_dBFS(curve, 50));
  EXPECT_EQ(-600, curve->get_dBFS(curve, 100));
  EXPECT_EQ(-600 - 100 * 75, curve->get_dBFS(curve, 0));
  EXPECT_EQ(-600 - 25 * 75, curve->get_dBFS(curve, 75));
  cras_volume_curve_destroy(curve);
}

TEST(VolumeCurve, ExplicitCurve) {
  struct cras_volume_curve* curve;
  long dB_vals[101];

  for (unsigned int i = 0; i < 101; i++)
    dB_vals[i] = i * 2 + -400;
  curve = cras_volume_curve_create_explicit(dB_vals);
  ASSERT_NE(static_cast<struct cras_volume_curve*>(NULL), curve);
  for (unsigned int i = 0; i < 101; i++)
    EXPECT_EQ(i * 2 - 400, curve->get_dBFS(curve, i));
  cras_volume_curve_destroy(curve);
}

}  //  namespace

int main(int argc, char** argv) {
  ::testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}