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"
16 typedef PlatformTest NSCoderStdStringTest;
18 const char* testStrings[] = {
22 "古池や蛙飛込む水の音\nふるいけやかわずとびこむみずのおと",
23 "ἀγεωμέτρητος μηδεὶς εἰσίτω",
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]);
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, "");