summaryrefslogtreecommitdiff
path: root/cras/src/tests/audio_format_unittest.cc
blob: f03f6878639a0cd77d0fc72a37fb2b8970296ac5 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright (c) 2013 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>

extern "C" {
// Test static functions
#include "cras_audio_format.c"
}

namespace {

class ChannelConvMtxTestSuite : public testing::Test {
 protected:
  virtual void SetUp() {
    int i;
    in_fmt = cras_audio_format_create(SND_PCM_FORMAT_S16_LE, 44100, 6);
    out_fmt = cras_audio_format_create(SND_PCM_FORMAT_S16_LE, 44100, 6);
    for (i = 0; i < CRAS_CH_MAX; i++) {
      in_fmt->channel_layout[i] = -1;
      out_fmt->channel_layout[i] = -1;
    }
  }

  virtual void TearDown() {
    cras_audio_format_destroy(in_fmt);
    cras_audio_format_destroy(out_fmt);
    if (conv_mtx)
      cras_channel_conv_matrix_destroy(conv_mtx, 6);
  }

  struct cras_audio_format* in_fmt;
  struct cras_audio_format* out_fmt;
  float** conv_mtx;
};

TEST_F(ChannelConvMtxTestSuite, MatrixCreateSuccess) {
  in_fmt->channel_layout[0] = 5;
  in_fmt->channel_layout[1] = 4;
  in_fmt->channel_layout[2] = 3;
  in_fmt->channel_layout[3] = 2;
  in_fmt->channel_layout[4] = 1;
  in_fmt->channel_layout[5] = 0;

  out_fmt->channel_layout[0] = 0;
  out_fmt->channel_layout[1] = 1;
  out_fmt->channel_layout[2] = 2;
  out_fmt->channel_layout[3] = 3;
  out_fmt->channel_layout[4] = 4;
  out_fmt->channel_layout[5] = 5;

  conv_mtx = cras_channel_conv_matrix_create(in_fmt, out_fmt);
  ASSERT_NE(conv_mtx, (void*)NULL);
}

TEST_F(ChannelConvMtxTestSuite, MatrixCreateFail) {
  in_fmt->channel_layout[0] = 5;
  in_fmt->channel_layout[1] = 4;
  in_fmt->channel_layout[2] = 3;
  in_fmt->channel_layout[3] = 2;
  in_fmt->channel_layout[4] = 1;
  in_fmt->channel_layout[5] = 0;

  out_fmt->channel_layout[0] = 0;
  out_fmt->channel_layout[1] = 1;
  out_fmt->channel_layout[2] = 2;
  out_fmt->channel_layout[3] = 3;
  out_fmt->channel_layout[4] = 4;
  out_fmt->channel_layout[7] = 5;

  conv_mtx = cras_channel_conv_matrix_create(in_fmt, out_fmt);
  ASSERT_EQ(conv_mtx, (void*)NULL);
}

TEST_F(ChannelConvMtxTestSuite, SLSRToRRRL) {
  in_fmt->channel_layout[0] = 0;
  in_fmt->channel_layout[1] = 1;
  in_fmt->channel_layout[4] = 2;
  in_fmt->channel_layout[5] = 3;
  /* Input format uses SL and SR*/
  in_fmt->channel_layout[6] = 4;
  in_fmt->channel_layout[7] = 5;

  out_fmt->channel_layout[0] = 0;
  out_fmt->channel_layout[1] = 1;
  /* Output format uses RR and RR */
  out_fmt->channel_layout[2] = 4;
  out_fmt->channel_layout[3] = 5;
  out_fmt->channel_layout[4] = 2;
  out_fmt->channel_layout[5] = 3;

  conv_mtx = cras_channel_conv_matrix_create(in_fmt, out_fmt);
  ASSERT_NE(conv_mtx, (void*)NULL);
}

}  // namespace

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