]> git.tdb.fi Git - libs/core.git/blob - tests/codec.cpp
Use string::size_type rather than unsigned to store string offsets
[libs/core.git] / tests / codec.cpp
1 #include <msp/stringcodec/ascii.h>
2 #include <msp/stringcodec/utf8.h>
3 #include <msp/test/test.h>
4
5 using namespace std;
6 using namespace Msp;
7
8 class CodecTests: public Test::RegisteredTest<CodecTests>
9 {
10 public:
11         CodecTests();
12
13         static const char *get_name() { return "Codec"; }
14
15 private:
16         void invalid_character();
17         void invalid_sequence();
18 };
19
20
21 CodecTests::CodecTests()
22 {
23         add(&CodecTests::invalid_character, "invalid_character").expect_throw<StringCodec::invalid_character>();
24         add(&CodecTests::invalid_sequence, "invalid_sequence").expect_throw<StringCodec::invalid_sequence>();
25 }
26
27 void CodecTests::invalid_character()
28 {
29         StringCodec::unichar ch = 0xE4;
30         StringCodec::Ascii::Encoder enc;
31         string buf;
32         enc.encode_char(ch, buf);
33 }
34
35 void CodecTests::invalid_sequence()
36 {
37         string str = "\343\201";
38         string::const_iterator iter = str.begin();
39         StringCodec::Utf8::Decoder dec;
40         dec.decode_char(str, iter);
41 }