Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: src/trusted/plugin/srpc/string_encoding_test.cc

Issue 2981011: Move plugin/srpc contents to the more appropriately named plugin/common.... (Closed) Base URL: http://nativeclient.googlecode.com/svn/trunk/src/native_client/
Patch Set: '' Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/trusted/plugin/srpc/string_encoding.cc ('k') | src/trusted/plugin/srpc/utility.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2010 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can
4 * be found in the LICENSE file.
5 */
6
7 #include <string.h>
8
9 #include "native_client/src/shared/platform/nacl_check.h"
10 #include "native_client/src/trusted/plugin/srpc/string_encoding.h"
11
12
13 int main() {
14 const char* input;
15 char* output;
16 size_t output_size;
17
18 // Valid input.
19
20 input = "Hello world, \x80 and \xff";
21 CHECK(plugin::ByteStringAsUTF8(input, strlen(input), &output, &output_size));
22 CHECK(strcmp(output, "Hello world, \xc2\x80 and \xc3\xbf") == 0);
23 CHECK(plugin::ByteStringFromUTF8(output, output_size, &output, &output_size));
24 CHECK(strcmp(output, "Hello world, \x80 and \xff") == 0);
25
26 // Valid UTF-8, but chars too big.
27
28 // Three-byte sequence
29 // This encodes \u1000
30 input = "\xe1\x80\x80";
31 CHECK(!plugin::ByteStringFromUTF8(input, strlen(input),
32 &output, &output_size));
33 // This encodes \u0100
34 input = "\xc4\x80";
35 CHECK(!plugin::ByteStringFromUTF8(input, strlen(input),
36 &output, &output_size));
37
38 // Invalid UTF-8.
39
40 // Incomplete sequence
41 input = "\xc2";
42 CHECK(!plugin::ByteStringFromUTF8(input, strlen(input),
43 &output, &output_size));
44 // Subsequent byte is wrong
45 input = "\xc2 ";
46 CHECK(!plugin::ByteStringFromUTF8(input, strlen(input),
47 &output, &output_size));
48 // Over long encoding
49 // This is a non-canonical encoding for \x00
50 input = "\xc0\x80";
51 CHECK(!plugin::ByteStringFromUTF8(input, strlen(input),
52 &output, &output_size));
53
54 return 0;
55 }
OLDNEW
« no previous file with comments | « src/trusted/plugin/srpc/string_encoding.cc ('k') | src/trusted/plugin/srpc/utility.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698