File: mm_text_io.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 (58 lines) | stat: -rw-r--r-- 2,097 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
#include "common/common_pch.h"

#include "common/mm_io_x.h"
#include "common/mm_mem_io.h"
#include "common/mm_proxy_io.h"
#include "common/mm_text_io.h"

#include "tests/unit/init.h"
#include "tests/unit/util.h"

namespace {

TEST(MmTextIo, BomUtf8) {
  unsigned char const text[14] = { 0xef, 0xbb, 0xbf, 'h', 'e', 'l', 'l', 'o', '\n', 'w', 'o', 'r', 'l', 'd' };
  mm_text_io_c in{std::make_shared<mm_mem_io_c>(text, 14)};

  ASSERT_EQ("UTF-8"s, in.get_encoding());
  EXPECT_EQ("hello"s, in.getline());
  EXPECT_EQ("world"s, in.getline());
}

TEST(MmTextIo, BomUtf16Le) {
  unsigned char const text[24] = { 0xff, 0xfe, 'h', 0, 'e', 0, 'l', 0, 'l', 0, 'o', 0, '\n', 0, 'w', 0, 'o', 0, 'r', 0, 'l', 0, 'd', 0, };
  mm_text_io_c in{std::make_shared<mm_mem_io_c>(text, 24)};

  ASSERT_EQ("UTF-16LE"s, in.get_encoding());
  EXPECT_EQ("hello"s, in.getline());
  EXPECT_EQ("world"s, in.getline());
}

TEST(MmTextIo, BomUtf16Be) {
  unsigned char const text[24] = { 0xfe, 0xff, 0, 'h', 0, 'e', 0, 'l', 0, 'l', 0, 'o', 0, '\n', 0, 'w', 0, 'o', 0, 'r', 0, 'l', 0, 'd' };
  mm_text_io_c in{std::make_shared<mm_mem_io_c>(text, 24)};

  ASSERT_EQ("UTF-16BE"s, in.get_encoding());
  EXPECT_EQ("hello"s, in.getline());
  EXPECT_EQ("world"s, in.getline());
}

TEST(MmTextIo, BomUtf32Le) {
  unsigned char const text[48] = { 0xff, 0xfe, 0, 0, 'h', 0, 0, 0, 'e', 0, 0, 0, 'l', 0, 0, 0, 'l', 0, 0, 0, 'o', 0, 0, 0, '\n', 0, 0, 0, 'w', 0, 0, 0, 'o', 0, 0, 0, 'r', 0, 0, 0, 'l', 0, 0, 0, 'd', 0, 0, 0, };
  mm_text_io_c in{std::make_shared<mm_mem_io_c>(text, 48)};

  ASSERT_EQ("UTF-32LE"s, in.get_encoding());
  EXPECT_EQ("hello"s, in.getline());
  EXPECT_EQ("world"s, in.getline());
}

TEST(MmTextIo, BomUtf32Be) {
  unsigned char const text[48] = { 0x00, 0x00, 0xfe, 0xff, 0, 0, 0, 'h', 0, 0, 0, 'e', 0, 0, 0, 'l', 0, 0, 0, 'l', 0, 0, 0, 'o', 0, 0, 0, '\n', 0, 0, 0, 'w', 0, 0, 0, 'o', 0, 0, 0, 'r', 0, 0, 0, 'l', 0, 0, 0, 'd' };
  mm_text_io_c in{std::make_shared<mm_mem_io_c>(text, 48)};

  ASSERT_EQ("UTF-32BE"s, in.get_encoding());
  EXPECT_EQ("hello"s, in.getline());
  EXPECT_EQ("world"s, in.getline());
}

}