summaryrefslogtreecommitdiffstats
path: root/media/libcubeb/test/test_utils.cpp
blob: cbdb960984d9372edefaff4e54f2dd001f801343 (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
#include "gtest/gtest.h"
#include "cubeb_utils.h"

TEST(cubeb, auto_array)
{
  auto_array<uint32_t> array;
  auto_array<uint32_t> array2(10);
  uint32_t a[10];

  ASSERT_EQ(array2.length(), 0u);
  ASSERT_EQ(array2.capacity(), 10u);


  for (uint32_t i = 0; i < 10; i++) {
    a[i] = i;
  }

  ASSERT_EQ(array.capacity(), 0u);
  ASSERT_EQ(array.length(), 0u);

  array.push(a, 10);

  ASSERT_TRUE(!array.reserve(9));

  for (uint32_t i = 0; i < 10; i++) {
    ASSERT_EQ(array.data()[i], i);
  }

  ASSERT_EQ(array.capacity(), 10u);
  ASSERT_EQ(array.length(), 10u);

  uint32_t b[10];

  array.pop(b, 5);

  ASSERT_EQ(array.capacity(), 10u);
  ASSERT_EQ(array.length(), 5u);
  for (uint32_t i = 0; i < 5; i++) {
    ASSERT_EQ(b[i], i);
    ASSERT_EQ(array.data()[i], 5 + i);
  }
  uint32_t* bb = b + 5;
  array.pop(bb, 5);

  ASSERT_EQ(array.capacity(), 10u);
  ASSERT_EQ(array.length(), 0u);
  for (uint32_t i = 0; i < 5; i++) {
    ASSERT_EQ(bb[i], 5 + i);
  }

  ASSERT_TRUE(!array.pop(nullptr, 1));

  array.push(a, 10);
  array.push(a, 10);

  for (uint32_t j = 0; j < 2; j++) {
    for (uint32_t i = 0; i < 10; i++) {
      ASSERT_EQ(array.data()[10 * j + i], i);
    }
  }
  ASSERT_EQ(array.length(), 20u);
  ASSERT_EQ(array.capacity(), 20u);
  array.pop(nullptr, 5);

  for (uint32_t i = 0; i < 5; i++) {
    ASSERT_EQ(array.data()[i], 5 + i);
  }

  ASSERT_EQ(array.length(), 15u);
  ASSERT_EQ(array.capacity(), 20u);
}