File: byte_buffer.cpp

package info (click to toggle)
mkvtoolnix 97.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 60,284 kB
  • sloc: cpp: 217,034; ruby: 11,453; xml: 8,125; ansic: 6,885; sh: 5,274; python: 1,041; perl: 191; makefile: 113; awk: 16; javascript: 4
file content (77 lines) | stat: -rw-r--r-- 1,590 bytes parent folder | download | duplicates (3)
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
#include "common/common_pch.h"

#include "common/byte_buffer.h"

#include "tests/unit/init.h"

namespace {

TEST(ByteBuffer, Add) {
  mtx::bytes::buffer_c b;

  b.add(reinterpret_cast<unsigned char const *>("Hello"), 5);

  ASSERT_EQ(5, b.get_size());

  b.add(reinterpret_cast<unsigned char const *>("world!"), 6);

  ASSERT_EQ(11, b.get_size());

  auto s = std::string{reinterpret_cast<char *>(b.get_buffer()), b.get_size()};

  ASSERT_EQ("Helloworld!"s, s);
}

TEST(ByteBuffer, Remove) {
  mtx::bytes::buffer_c b;

  b.add(reinterpret_cast<unsigned char const *>("Hello world"), 11);

  ASSERT_EQ(11, b.get_size());

  b.remove(3);

  ASSERT_EQ(8, b.get_size());

  auto s = std::string{reinterpret_cast<char *>(b.get_buffer()), b.get_size()};

  ASSERT_EQ("lo world"s, s);

  b.remove(2, mtx::bytes::buffer_c::at_back);

  ASSERT_EQ(6, b.get_size());

  s = std::string{reinterpret_cast<char *>(b.get_buffer()), b.get_size()};

  ASSERT_EQ("lo wor"s, s);

  b.add(reinterpret_cast<unsigned char const *>("meow"), 4);

  ASSERT_EQ(10, b.get_size());

  s = std::string{reinterpret_cast<char *>(b.get_buffer()), b.get_size()};

  ASSERT_EQ("lo wormeow"s, s);
}

TEST(ByteBuffer, Prepend) {
  mtx::bytes::buffer_c b;

  b.add(reinterpret_cast<unsigned char const *>("You cruel world"), 15);

  ASSERT_EQ(15, b.get_size());

  b.remove(9);

  ASSERT_EQ(6, b.get_size());

  b.prepend(reinterpret_cast<unsigned char const *>("Hello"), 5);

  ASSERT_EQ(11, b.get_size());

  auto s = std::string{reinterpret_cast<char *>(b.get_buffer()), b.get_size()};

  ASSERT_EQ("Hello world"s, s);
}

}