• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2019 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 
6 #include <gtest/gtest.h>
7 
8 extern "C" {
9 #include "cras_audio_area.h"
10 #include "cras_empty_iodev.h"
11 #include "cras_iodev.h"
12 }
13 
14 static struct timespec clock_gettime_retspec;
15 static struct cras_audio_format fake_format;
16 static cras_audio_area mock_audio_area;
17 
18 namespace {
19 
TEST(EmptyIodev,GetInputBuffer)20 TEST(EmptyIodev, GetInputBuffer) {
21   struct cras_iodev* iodev;
22   struct timespec ts;
23   cras_audio_area* area;
24   unsigned nframes;
25 
26   iodev = empty_iodev_create(CRAS_STREAM_INPUT, CRAS_NODE_TYPE_FALLBACK_NORMAL);
27 
28   clock_gettime_retspec.tv_sec = 0;
29   clock_gettime_retspec.tv_nsec = 10000000;
30   fake_format.frame_rate = 48000;
31   iodev->format = &fake_format;
32   iodev->configure_dev(iodev);
33 
34   clock_gettime_retspec.tv_nsec = 20000000;
35   nframes = iodev->frames_queued(iodev, &ts);
36   ASSERT_EQ(480, nframes);
37 
38   /* If client takes too long to get input data, number of frames
39    * returned shouldn't exceeds device's own buffer size. */
40   nframes = 5000;
41   clock_gettime_retspec.tv_sec = 1;
42   iodev->get_buffer(iodev, &area, &nframes);
43   ASSERT_EQ(4096, nframes);
44 
45   iodev->close_dev(iodev);
46   empty_iodev_destroy(iodev);
47 }
48 
49 }  // namespace
50 
51 extern "C" {
52 
cras_iodev_free_format(struct cras_iodev * iodev)53 void cras_iodev_free_format(struct cras_iodev* iodev) {}
54 
cras_iodev_default_no_stream_playback(struct cras_iodev * odev,int enable)55 int cras_iodev_default_no_stream_playback(struct cras_iodev* odev, int enable) {
56   return 0;
57 }
58 
cras_iodev_init_audio_area(struct cras_iodev * iodev,int num_channels)59 void cras_iodev_init_audio_area(struct cras_iodev* iodev, int num_channels) {
60   iodev->area = &mock_audio_area;
61 }
62 
cras_iodev_free_audio_area(struct cras_iodev * iodev)63 void cras_iodev_free_audio_area(struct cras_iodev* iodev) {}
64 
cras_audio_area_config_buf_pointers(struct cras_audio_area * area,const struct cras_audio_format * fmt,uint8_t * base_buffer)65 void cras_audio_area_config_buf_pointers(struct cras_audio_area* area,
66                                          const struct cras_audio_format* fmt,
67                                          uint8_t* base_buffer) {}
68 
cras_iodev_list_rm_input(struct cras_iodev * input)69 int cras_iodev_list_rm_input(struct cras_iodev* input) {
70   return 0;
71 }
72 
cras_iodev_list_rm_output(struct cras_iodev * output)73 int cras_iodev_list_rm_output(struct cras_iodev* output) {
74   return 0;
75 }
76 
cras_iodev_free_resources(struct cras_iodev * iodev)77 void cras_iodev_free_resources(struct cras_iodev* iodev) {}
78 
cras_iodev_add_node(struct cras_iodev * iodev,struct cras_ionode * node)79 void cras_iodev_add_node(struct cras_iodev* iodev, struct cras_ionode* node) {
80   iodev->nodes = node;
81 }
82 
cras_iodev_set_active_node(struct cras_iodev * iodev,struct cras_ionode * node)83 void cras_iodev_set_active_node(struct cras_iodev* iodev,
84                                 struct cras_ionode* node) {
85   iodev->active_node = node;
86 }
87 
88 //  From librt.
clock_gettime(clockid_t clk_id,struct timespec * tp)89 int clock_gettime(clockid_t clk_id, struct timespec* tp) {
90   tp->tv_sec = clock_gettime_retspec.tv_sec;
91   tp->tv_nsec = clock_gettime_retspec.tv_nsec;
92   return 0;
93 }
94 
95 }  // extern "C"
96 
main(int argc,char ** argv)97 int main(int argc, char** argv) {
98   ::testing::InitGoogleTest(&argc, argv);
99   return RUN_ALL_TESTS();
100 }
101