~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to unittests/utf8_test.cc

trunk merge plus more pbms updates for drizzle.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2010 Monty Taylor
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; either version 2 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  This program is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with this program; if not, write to the Free Software
 
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
19
 */
 
20
 
 
21
#include "config.h"
 
22
 
 
23
#include <string>
 
24
 
 
25
#include <gtest/gtest.h>
 
26
#include <drizzled/utf8/utf8.h>
 
27
 
 
28
using namespace drizzled;
 
29
 
 
30
TEST(utf8, is_single)
 
31
{
 
32
  EXPECT_EQ(true, utf8::is_single('a'));
 
33
  const char *multi_byte= "ç";
 
34
  EXPECT_EQ(false, utf8::is_single(*multi_byte));
 
35
  EXPECT_EQ(false, utf8::is_single(*(multi_byte + 1)));
 
36
}
 
37
 
 
38
TEST(utf8, codepoint_length)
 
39
{
 
40
  uint32_t one_byte= 0x0024;
 
41
  uint32_t two_bytes= 0x00A2;
 
42
  uint32_t three_bytes= 0x20AC;
 
43
  uint32_t four_bytes= 0x024B62;
 
44
  EXPECT_EQ(1, utf8::codepoint_length(one_byte));
 
45
  EXPECT_EQ(2, utf8::codepoint_length(two_bytes));
 
46
  EXPECT_EQ(3, utf8::codepoint_length(three_bytes));
 
47
  EXPECT_EQ(4, utf8::codepoint_length(four_bytes));
 
48
}
 
49
 
 
50
TEST(utf8, sequence_length)
 
51
{
 
52
  const char *one_byte= "$";
 
53
  const char *two_bytes= "¢";
 
54
  const char *three_bytes= "€";
 
55
  const char *four_bytes= "𤭢";
 
56
  EXPECT_EQ(1, utf8::sequence_length(*one_byte));
 
57
  EXPECT_EQ(2, utf8::sequence_length(*two_bytes));
 
58
  EXPECT_EQ(3, utf8::sequence_length(*three_bytes));
 
59
  EXPECT_EQ(4, utf8::sequence_length(*four_bytes));
 
60
}
 
61
 
 
62
TEST(utf8, char_length)
 
63
{
 
64
  const char *one_byte= "$";
 
65
  const char *two_bytes= "¢";
 
66
  const char *three_bytes= "€";
 
67
  const char *four_bytes= "𤭢";
 
68
  const char *test_string= "__tañgè Ñãmé";
 
69
  EXPECT_EQ(1, utf8::char_length(one_byte));
 
70
  EXPECT_EQ(1, utf8::char_length(two_bytes));
 
71
  EXPECT_EQ(1, utf8::char_length(three_bytes));
 
72
  EXPECT_EQ(1, utf8::char_length(four_bytes));
 
73
  EXPECT_EQ(12, utf8::char_length(test_string));
 
74
}
 
75
 
 
76
TEST(utf8, char_length_string)
 
77
{
 
78
  std::string one_byte= "$";
 
79
  std::string two_bytes= "¢";
 
80
  std::string three_bytes= "€";
 
81
  std::string four_bytes= "𤭢";
 
82
  std::string test_string= "__tañgè Ñãmé";
 
83
  EXPECT_EQ(1, utf8::char_length(one_byte));
 
84
  EXPECT_EQ(1, utf8::char_length(two_bytes));
 
85
  EXPECT_EQ(1, utf8::char_length(three_bytes));
 
86
  EXPECT_EQ(1, utf8::char_length(four_bytes));
 
87
  EXPECT_EQ(12, utf8::char_length(test_string));
 
88
}