~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to unittests/utf8_test.cc

  • Committer: Andrew Hutchings
  • Date: 2011-01-23 21:32:31 UTC
  • mto: (2108.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 2109.
  • Revision ID: andrew@linuxjedi.co.uk-20110123213231-dp2r4enepa9k4g36
Convert all unit tests to boost::test
Add pandora support for boost::test
Remove pandora support for gtest

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
#define BOOST_TEST_DYN_LINK
 
26
#include <boost/test/unit_test.hpp>
 
27
 
 
28
#include <drizzled/utf8/utf8.h>
 
29
 
 
30
using namespace drizzled;
 
31
 
 
32
BOOST_AUTO_TEST_SUITE(UTF8)
 
33
BOOST_AUTO_TEST_CASE(is_single)
 
34
{
 
35
  BOOST_REQUIRE(utf8::is_single('a'));
 
36
  const char *multi_byte= "ç";
 
37
  BOOST_REQUIRE(not utf8::is_single(*multi_byte));
 
38
  BOOST_REQUIRE(not utf8::is_single(*(multi_byte + 1)));
 
39
}
 
40
 
 
41
BOOST_AUTO_TEST_CASE(codepoint_length)
 
42
{
 
43
  uint32_t one_byte= 0x0024;
 
44
  uint32_t two_bytes= 0x00A2;
 
45
  uint32_t three_bytes= 0x20AC;
 
46
  uint32_t four_bytes= 0x024B62;
 
47
  BOOST_REQUIRE_EQUAL(1, utf8::codepoint_length(one_byte));
 
48
  BOOST_REQUIRE_EQUAL(2, utf8::codepoint_length(two_bytes));
 
49
  BOOST_REQUIRE_EQUAL(3, utf8::codepoint_length(three_bytes));
 
50
  BOOST_REQUIRE_EQUAL(4, utf8::codepoint_length(four_bytes));
 
51
}
 
52
 
 
53
BOOST_AUTO_TEST_CASE(sequence_length)
 
54
{
 
55
  const char *one_byte= "$";
 
56
  const char *two_bytes= "¢";
 
57
  const char *three_bytes= "€";
 
58
  const char *four_bytes= "𤭢";
 
59
  BOOST_REQUIRE_EQUAL(1, utf8::sequence_length(*one_byte));
 
60
  BOOST_REQUIRE_EQUAL(2, utf8::sequence_length(*two_bytes));
 
61
  BOOST_REQUIRE_EQUAL(3, utf8::sequence_length(*three_bytes));
 
62
  BOOST_REQUIRE_EQUAL(4, utf8::sequence_length(*four_bytes));
 
63
}
 
64
 
 
65
BOOST_AUTO_TEST_CASE(char_length)
 
66
{
 
67
  const char *one_byte= "$";
 
68
  const char *two_bytes= "¢";
 
69
  const char *three_bytes= "€";
 
70
  const char *four_bytes= "𤭢";
 
71
  const char *test_string= "__tañgè Ñãmé";
 
72
  BOOST_REQUIRE_EQUAL(1, utf8::char_length(one_byte));
 
73
  BOOST_REQUIRE_EQUAL(1, utf8::char_length(two_bytes));
 
74
  BOOST_REQUIRE_EQUAL(1, utf8::char_length(three_bytes));
 
75
  BOOST_REQUIRE_EQUAL(1, utf8::char_length(four_bytes));
 
76
  BOOST_REQUIRE_EQUAL(12, utf8::char_length(test_string));
 
77
}
 
78
 
 
79
BOOST_AUTO_TEST_CASE(char_length_string)
 
80
{
 
81
  std::string one_byte= "$";
 
82
  std::string two_bytes= "¢";
 
83
  std::string three_bytes= "€";
 
84
  std::string four_bytes= "𤭢";
 
85
  std::string test_string= "__tañgè Ñãmé";
 
86
  BOOST_REQUIRE_EQUAL(1, utf8::char_length(one_byte));
 
87
  BOOST_REQUIRE_EQUAL(1, utf8::char_length(two_bytes));
 
88
  BOOST_REQUIRE_EQUAL(1, utf8::char_length(three_bytes));
 
89
  BOOST_REQUIRE_EQUAL(1, utf8::char_length(four_bytes));
 
90
  BOOST_REQUIRE_EQUAL(12, utf8::char_length(test_string));
 
91
}
 
92
BOOST_AUTO_TEST_SUITE_END()