Add ICU message format support
[chromium-blink-merge.git] / ios / web / navigation / nscoder_util_unittest.mm
blob8d3b667e618759ec36e7f9f92191ade94a7cf7d5
1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #import <Foundation/Foundation.h>
7 #include "base/basictypes.h"
8 #include "base/mac/scoped_nsobject.h"
9 #include "ios/web/navigation/nscoder_util.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "testing/platform_test.h"
13 namespace web {
14 namespace {
16 typedef PlatformTest NSCoderStdStringTest;
18 const char* testStrings[] = {
19     "Arf",
20     "",
21     "This is working™",
22     "古池や蛙飛込む水の音\nふるいけやかわずとびこむみずのおと",
23     "ἀγεωμέτρητος μηδεὶς εἰσίτω",
24     "Bang!\t\n"
27 TEST_F(NSCoderStdStringTest, encodeDecode) {
28   for (size_t i = 0; i < arraysize(testStrings); ++i) {
29     NSMutableData* data = [NSMutableData data];
31     base::scoped_nsobject<NSKeyedArchiver> archiver(
32         [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]);
33     nscoder_util::EncodeString(archiver, @"test", testStrings[i]);
34     [archiver finishEncoding];
36     base::scoped_nsobject<NSKeyedUnarchiver> unarchiver(
37         [[NSKeyedUnarchiver alloc] initForReadingWithData:data]);
38     const std::string decoded = nscoder_util::DecodeString(unarchiver, @"test");
40     EXPECT_EQ(decoded, testStrings[i]);
41   }
44 TEST_F(NSCoderStdStringTest, decodeEmpty) {
45   NSMutableData* data = [NSMutableData data];
47   base::scoped_nsobject<NSKeyedArchiver> archiver(
48       [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]);
49   [archiver finishEncoding];
51   base::scoped_nsobject<NSKeyedUnarchiver> unarchiver(
52       [[NSKeyedUnarchiver alloc] initForReadingWithData:data]);
53   const std::string decoded = nscoder_util::DecodeString(unarchiver, @"test");
55   EXPECT_EQ(decoded, "");
58 }  // namespace
59 }  // namespace web