Home | History | Annotate | Download | only in tests
      1 // Copyright (c) 2013 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 
      7 extern "C" {
      8 // Test static functions
      9 #include "cras_audio_format.c"
     10 }
     11 
     12 namespace {
     13 
     14 class ChannelConvMtxTestSuite : public testing::Test {
     15   protected:
     16     virtual void SetUp() {
     17       int i;
     18       in_fmt = cras_audio_format_create(SND_PCM_FORMAT_S16_LE, 44100, 6);
     19       out_fmt = cras_audio_format_create(SND_PCM_FORMAT_S16_LE, 44100, 6);
     20       for (i = 0; i < CRAS_CH_MAX; i++) {
     21         in_fmt->channel_layout[i] = -1;
     22         out_fmt->channel_layout[i] = -1;
     23       }
     24     }
     25 
     26     virtual void TearDown() {
     27       cras_audio_format_destroy(in_fmt);
     28       cras_audio_format_destroy(out_fmt);
     29       if (conv_mtx)
     30         cras_channel_conv_matrix_destroy(conv_mtx, 6);
     31     }
     32 
     33     struct cras_audio_format *in_fmt;
     34     struct cras_audio_format *out_fmt;
     35     float **conv_mtx;
     36 };
     37 
     38 TEST_F(ChannelConvMtxTestSuite, MatrixCreateSuccess) {
     39   in_fmt->channel_layout[0] = 5;
     40   in_fmt->channel_layout[1] = 4;
     41   in_fmt->channel_layout[2] = 3;
     42   in_fmt->channel_layout[3] = 2;
     43   in_fmt->channel_layout[4] = 1;
     44   in_fmt->channel_layout[5] = 0;
     45 
     46   out_fmt->channel_layout[0] = 0;
     47   out_fmt->channel_layout[1] = 1;
     48   out_fmt->channel_layout[2] = 2;
     49   out_fmt->channel_layout[3] = 3;
     50   out_fmt->channel_layout[4] = 4;
     51   out_fmt->channel_layout[5] = 5;
     52 
     53   conv_mtx = cras_channel_conv_matrix_create(in_fmt, out_fmt);
     54   ASSERT_NE(conv_mtx, (void *)NULL);
     55 }
     56 
     57 TEST_F(ChannelConvMtxTestSuite, MatrixCreateFail) {
     58   in_fmt->channel_layout[0] = 5;
     59   in_fmt->channel_layout[1] = 4;
     60   in_fmt->channel_layout[2] = 3;
     61   in_fmt->channel_layout[3] = 2;
     62   in_fmt->channel_layout[4] = 1;
     63   in_fmt->channel_layout[5] = 0;
     64 
     65   out_fmt->channel_layout[0] = 0;
     66   out_fmt->channel_layout[1] = 1;
     67   out_fmt->channel_layout[2] = 2;
     68   out_fmt->channel_layout[3] = 3;
     69   out_fmt->channel_layout[4] = 4;
     70   out_fmt->channel_layout[7] = 5;
     71 
     72   conv_mtx = cras_channel_conv_matrix_create(in_fmt, out_fmt);
     73   ASSERT_EQ(conv_mtx, (void *)NULL);
     74 }
     75 
     76 TEST_F(ChannelConvMtxTestSuite, SLSRToRRRL) {
     77   in_fmt->channel_layout[0] = 0;
     78   in_fmt->channel_layout[1] = 1;
     79   in_fmt->channel_layout[4] = 2;
     80   in_fmt->channel_layout[5] = 3;
     81   /* Input format uses SL and SR*/
     82   in_fmt->channel_layout[6] = 4;
     83   in_fmt->channel_layout[7] = 5;
     84 
     85   out_fmt->channel_layout[0] = 0;
     86   out_fmt->channel_layout[1] = 1;
     87   /* Output format uses RR and RR */
     88   out_fmt->channel_layout[2] = 4;
     89   out_fmt->channel_layout[3] = 5;
     90   out_fmt->channel_layout[4] = 2;
     91   out_fmt->channel_layout[5] = 3;
     92 
     93   conv_mtx = cras_channel_conv_matrix_create(in_fmt, out_fmt);
     94   ASSERT_NE(conv_mtx, (void *)NULL);
     95 }
     96 
     97 } // namespace
     98 
     99 int main(int argc, char **argv) {
    100   ::testing::InitGoogleTest(&argc, argv);
    101   return RUN_ALL_TESTS();
    102 }
    103