Home | History | Annotate | Download | only in tests
      1 // Copyright 2015 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 <stdio.h>
      6 #include <gtest/gtest.h>
      7 
      8 extern "C" {
      9 #include "cras_rstream.h"
     10 #include "stream_list.h"
     11 }
     12 
     13 namespace {
     14 
     15 static unsigned int add_called;
     16 static int added_cb(struct cras_rstream *rstream) {
     17   add_called++;
     18   return 0;
     19 }
     20 
     21 static unsigned int rm_called;
     22 static struct cras_rstream *rmed_stream;
     23 static int removed_cb(struct cras_rstream *rstream) {
     24   rm_called++;
     25   rmed_stream = rstream;
     26   return 0;
     27 }
     28 
     29 static unsigned int create_called;
     30 static struct cras_rstream_config *create_config;
     31 static struct cras_rstream dummy_rstream;
     32 static int create_rstream_cb(struct cras_rstream_config *stream_config,
     33                              struct cras_rstream **stream) {
     34   create_called++;
     35   create_config = stream_config;
     36   *stream = &dummy_rstream;
     37   dummy_rstream.stream_id = 0x3003;
     38   return 0;
     39 }
     40 
     41 static unsigned int destroy_called;
     42 static struct cras_rstream *destroyed_stream;
     43 static void destroy_rstream_cb(struct cras_rstream *rstream) {
     44   destroy_called++;
     45   destroyed_stream = rstream;
     46 }
     47 
     48 static void reset_test_data() {
     49   add_called = 0;
     50   rm_called = 0;
     51   create_called = 0;
     52   destroy_called = 0;
     53 }
     54 
     55 TEST(StreamList, AddRemove) {
     56   struct stream_list *l;
     57   struct cras_rstream *s1;
     58   struct cras_rstream_config s1_config;
     59 
     60   reset_test_data();
     61   l = stream_list_create(added_cb, removed_cb, create_rstream_cb,
     62                          destroy_rstream_cb, NULL);
     63   stream_list_add(l, &s1_config, &s1);
     64   EXPECT_EQ(1, add_called);
     65   EXPECT_EQ(1, create_called);
     66   EXPECT_EQ(&s1_config, create_config);
     67   EXPECT_EQ(0, stream_list_rm(l, 0x3003));
     68   EXPECT_EQ(1, rm_called);
     69   EXPECT_EQ(s1, rmed_stream);
     70   EXPECT_EQ(1, destroy_called);
     71   EXPECT_EQ(s1, destroyed_stream);
     72   stream_list_destroy(l);
     73 }
     74 
     75 extern "C" {
     76 
     77 struct cras_timer *cras_tm_create_timer(
     78                 struct cras_tm *tm,
     79                 unsigned int ms,
     80                 void (*cb)(struct cras_timer *t, void *data),
     81                 void *cb_data) {
     82   return reinterpret_cast<struct cras_timer *>(0x404);
     83 }
     84 
     85 void cras_tm_cancel_timer(struct cras_tm *tm, struct cras_timer *t) {
     86 }
     87 
     88 }
     89 
     90 } // namespace
     91 
     92 int main(int argc, char **argv) {
     93   ::testing::InitGoogleTest(&argc, argv);
     94   return RUN_ALL_TESTS();
     95 }
     96