| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import <Foundation/Foundation.h> | 5 #import <Foundation/Foundation.h> |
| 6 #include <stddef.h> | 6 #include <stddef.h> |
| 7 | 7 |
| 8 #import "base/mac/scoped_nsobject.h" | |
| 9 #include "base/macros.h" | 8 #include "base/macros.h" |
| 10 #import "ios/web/navigation/nscoder_util.h" | 9 #import "ios/web/navigation/nscoder_util.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "testing/platform_test.h" | 11 #include "testing/platform_test.h" |
| 13 | 12 |
| 13 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 14 #error "This file requires ARC support." |
| 15 #endif |
| 16 |
| 14 namespace web { | 17 namespace web { |
| 15 namespace { | 18 namespace { |
| 16 | 19 |
| 17 typedef PlatformTest NSCoderStdStringTest; | 20 typedef PlatformTest NSCoderStdStringTest; |
| 18 | 21 |
| 19 const char* testStrings[] = { | 22 const char* testStrings[] = { |
| 20 "Arf", | 23 "Arf", |
| 21 "", | 24 "", |
| 22 "This is working™", | 25 "This is working™", |
| 23 "古池や蛙飛込む水の音\nふるいけやかわずとびこむみずのおと", | 26 "古池や蛙飛込む水の音\nふるいけやかわずとびこむみずのおと", |
| 24 "ἀγεωμέτρητος μηδεὶς εἰσίτω", | 27 "ἀγεωμέτρητος μηδεὶς εἰσίτω", |
| 25 "Bang!\t\n" | 28 "Bang!\t\n" |
| 26 }; | 29 }; |
| 27 | 30 |
| 28 TEST_F(NSCoderStdStringTest, encodeDecode) { | 31 TEST_F(NSCoderStdStringTest, encodeDecode) { |
| 29 for (size_t i = 0; i < arraysize(testStrings); ++i) { | 32 for (size_t i = 0; i < arraysize(testStrings); ++i) { |
| 30 NSMutableData* data = [NSMutableData data]; | 33 NSMutableData* data = [NSMutableData data]; |
| 31 | 34 |
| 32 base::scoped_nsobject<NSKeyedArchiver> archiver( | 35 NSKeyedArchiver* archiver = |
| 33 [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]); | 36 [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]; |
| 34 nscoder_util::EncodeString(archiver, @"test", testStrings[i]); | 37 nscoder_util::EncodeString(archiver, @"test", testStrings[i]); |
| 35 [archiver finishEncoding]; | 38 [archiver finishEncoding]; |
| 36 | 39 |
| 37 base::scoped_nsobject<NSKeyedUnarchiver> unarchiver( | 40 NSKeyedUnarchiver* unarchiver = |
| 38 [[NSKeyedUnarchiver alloc] initForReadingWithData:data]); | 41 [[NSKeyedUnarchiver alloc] initForReadingWithData:data]; |
| 39 const std::string decoded = nscoder_util::DecodeString(unarchiver, @"test"); | 42 const std::string decoded = nscoder_util::DecodeString(unarchiver, @"test"); |
| 40 | 43 |
| 41 EXPECT_EQ(decoded, testStrings[i]); | 44 EXPECT_EQ(decoded, testStrings[i]); |
| 42 } | 45 } |
| 43 } | 46 } |
| 44 | 47 |
| 45 TEST_F(NSCoderStdStringTest, decodeEmpty) { | 48 TEST_F(NSCoderStdStringTest, decodeEmpty) { |
| 46 NSMutableData* data = [NSMutableData data]; | 49 NSMutableData* data = [NSMutableData data]; |
| 47 | 50 |
| 48 base::scoped_nsobject<NSKeyedArchiver> archiver( | 51 NSKeyedArchiver* archiver = |
| 49 [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]); | 52 [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]; |
| 50 [archiver finishEncoding]; | 53 [archiver finishEncoding]; |
| 51 | 54 |
| 52 base::scoped_nsobject<NSKeyedUnarchiver> unarchiver( | 55 NSKeyedUnarchiver* unarchiver = |
| 53 [[NSKeyedUnarchiver alloc] initForReadingWithData:data]); | 56 [[NSKeyedUnarchiver alloc] initForReadingWithData:data]; |
| 54 const std::string decoded = nscoder_util::DecodeString(unarchiver, @"test"); | 57 const std::string decoded = nscoder_util::DecodeString(unarchiver, @"test"); |
| 55 | 58 |
| 56 EXPECT_EQ(decoded, ""); | 59 EXPECT_EQ(decoded, ""); |
| 57 } | 60 } |
| 58 | 61 |
| 59 } // namespace | 62 } // namespace |
| 60 } // namespace web | 63 } // namespace web |
| OLD | NEW |