]>
git.proxmox.com Git - ceph.git/blob - ceph/src/test/utf8.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2011 New Dream Network
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
14 #include "common/utf8.h"
15 #include "gtest/gtest.h"
18 TEST(IsValidUtf8
, SimpleAscii
) {
19 ASSERT_EQ(0, check_utf8_cstr("Ascii ftw."));
20 ASSERT_EQ(0, check_utf8_cstr(""));
21 ASSERT_EQ(0, check_utf8_cstr("B"));
22 ASSERT_EQ(0, check_utf8_cstr("Badgers badgers badgers badgers "
23 "mushroom mushroom"));
24 ASSERT_EQ(0, check_utf8("foo", strlen("foo")));
27 TEST(IsValidUtf8
, ControlChars
) {
28 // Sadly, control characters are valid utf8...
29 uint8_t control_chars
[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
30 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d };
31 ASSERT_EQ(0, check_utf8((char*)control_chars
, sizeof(control_chars
)));
34 TEST(IsValidUtf8
, SimpleUtf8
) {
35 uint8_t funkystr
[] = { 0x66, 0xd1, 0x86, 0xd1, 0x9d, 0xd2, 0xa0, 0xd3,
36 0xad, 0xd3, 0xae, 0x0a };
37 ASSERT_EQ(0, check_utf8((char*)funkystr
, sizeof(funkystr
)));
39 uint8_t valid2
[] = { 0xc3, 0xb1 };
40 ASSERT_EQ(0, check_utf8((char*)valid2
, sizeof(valid2
)));
43 TEST(IsValidUtf8
, InvalidUtf8
) {
44 uint8_t inval
[] = { 0xe2, 0x28, 0xa1 };
45 ASSERT_NE(0, check_utf8((char*)inval
, sizeof(inval
)));
47 uint8_t invalid2
[] = { 0xc3, 0x28 };
48 ASSERT_NE(0, check_utf8((char*)invalid2
, sizeof(invalid2
)));
51 TEST(HasControlChars
, HasControlChars1
) {
52 uint8_t has_control_chars
[] = { 0x41, 0x01, 0x00 };
53 ASSERT_NE(0, check_for_control_characters_cstr((const char*)has_control_chars
));
54 uint8_t has_control_chars2
[] = { 0x7f, 0x41, 0x00 };
55 ASSERT_NE(0, check_for_control_characters_cstr((const char*)has_control_chars2
));
57 char has_newline
[] = "blah blah\n";
58 ASSERT_NE(0, check_for_control_characters_cstr(has_newline
));
60 char no_control_chars
[] = "blah blah";
61 ASSERT_EQ(0, check_for_control_characters_cstr(no_control_chars
));
63 uint8_t validutf
[] = { 0x66, 0xd1, 0x86, 0xd1, 0x9d, 0xd2, 0xa0, 0xd3,
64 0xad, 0xd3, 0xae, 0x0 };
65 ASSERT_EQ(0, check_for_control_characters_cstr((const char*)validutf
));