summaryrefslogtreecommitdiffstats
path: root/media/libcubeb/tests/test_utils.cpp
blob: f52cd3196348d15110170f20cf4366d1ae67a92a (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
73
74
75
76
77
78
79
80
#include <cassert>
#include "cubeb_utils.h"

int test_auto_array()
{
  auto_array<uint32_t> array;
  auto_array<uint32_t> array2(10);
  uint32_t a[10];

  assert(array2.length() == 0);
  assert(array2.capacity() == 10);


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

  assert(array.capacity() == 0);
  assert(array.length() == 0);

  array.push(a, 10);

  assert(!array.reserve(9));

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

  assert(array.capacity() == 10);
  assert(array.length() == 10);

  uint32_t b[10];

  array.pop(b, 5);

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

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

  assert(!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(array.data()[10 * j + i] == i);
    }
  }
  assert(array.length() == 20);
  assert(array.capacity() == 20);
  array.pop(nullptr, 5);

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

  assert(array.length() == 15);
  assert(array.capacity() == 20);

  return 0;
}


int main()
{
  test_auto_array();
  return 0;
}