1 // Copyright 2018 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 #include "float_buffer.h"
8 
9 namespace {
TEST(FloatBuffer,ReadWrite)10 TEST(FloatBuffer, ReadWrite) {
11   unsigned int readable = 10;
12   struct float_buffer *b = float_buffer_create(10, 2);
13   EXPECT_EQ(10, float_buffer_writable(b));
14 
15   // (w, r)=(8, 0)
16   float_buffer_written(b, 8);
17   EXPECT_EQ(8, float_buffer_level(b));
18 
19   float_buffer_read_pointer(b, 0, &readable);
20   EXPECT_EQ(8, readable);
21   EXPECT_EQ(2, float_buffer_writable(b));
22 
23   readable = 10;
24   float_buffer_read_pointer(b, 3, &readable);
25   EXPECT_EQ(5, readable);
26 
27   // (w, r)=(8, 6)
28   float_buffer_read(b, 6);
29   EXPECT_EQ(2, float_buffer_writable(b));
30 
31   // (w, r)=(0, 6)
32   float_buffer_written(b, 2);
33   EXPECT_EQ(6, float_buffer_writable(b));
34 
35   // (w, r)=(3, 6)
36   readable = 10;
37   float_buffer_written(b, 3);
38   float_buffer_read_pointer(b, 0, &readable);
39   EXPECT_EQ(4, readable);
40 
41   readable = 10;
42   float_buffer_read_pointer(b, 1, &readable);
43   EXPECT_EQ(3, readable);
44 
45   float_buffer_destroy(&b);
46 }
47 
48 } // namespace
49 
main(int argc,char ** argv)50 int main(int argc, char **argv) {
51   ::testing::InitGoogleTest(&argc, argv);
52   return RUN_ALL_TESTS();
53 }
54