| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/memory/scoped_nsobject.h" | 8 #include "base/mac/scoped_nsobject.h" |
| 9 #include "chrome/common/mac/nscoder_util.h" | 9 #include "chrome/common/mac/nscoder_util.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "testing/platform_test.h" | 11 #include "testing/platform_test.h" |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 typedef PlatformTest NSCoderStdStringTest; | 15 typedef PlatformTest NSCoderStdStringTest; |
| 16 | 16 |
| 17 const char* testStrings[] = { | 17 const char* testStrings[] = { |
| 18 "Arf", | 18 "Arf", |
| 19 "", | 19 "", |
| 20 "This is working™", | 20 "This is working™", |
| 21 "古池や蛙飛込む水の音\nふるいけやかわずとびこむみずのおと", | 21 "古池や蛙飛込む水の音\nふるいけやかわずとびこむみずのおと", |
| 22 "ἀγεωμέτρητος μηδεὶς εἰσίτω", | 22 "ἀγεωμέτρητος μηδεὶς εἰσίτω", |
| 23 "Bang!\t\n" | 23 "Bang!\t\n" |
| 24 }; | 24 }; |
| 25 | 25 |
| 26 TEST_F(NSCoderStdStringTest, encodeDecode) { | 26 TEST_F(NSCoderStdStringTest, encodeDecode) { |
| 27 for (size_t i = 0; i < arraysize(testStrings); ++i) { | 27 for (size_t i = 0; i < arraysize(testStrings); ++i) { |
| 28 NSMutableData *data = [NSMutableData data]; | 28 NSMutableData *data = [NSMutableData data]; |
| 29 | 29 |
| 30 scoped_nsobject<NSKeyedArchiver> archiver( | 30 base::scoped_nsobject<NSKeyedArchiver> archiver( |
| 31 [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]); | 31 [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]); |
| 32 nscoder_util::EncodeString(archiver, @"test", testStrings[i]); | 32 nscoder_util::EncodeString(archiver, @"test", testStrings[i]); |
| 33 [archiver finishEncoding]; | 33 [archiver finishEncoding]; |
| 34 | 34 |
| 35 scoped_nsobject<NSKeyedUnarchiver> unarchiver( | 35 base::scoped_nsobject<NSKeyedUnarchiver> unarchiver( |
| 36 [[NSKeyedUnarchiver alloc] initForReadingWithData:data]); | 36 [[NSKeyedUnarchiver alloc] initForReadingWithData:data]); |
| 37 const std::string decoded = nscoder_util::DecodeString(unarchiver, @"test"); | 37 const std::string decoded = nscoder_util::DecodeString(unarchiver, @"test"); |
| 38 | 38 |
| 39 EXPECT_EQ(decoded, testStrings[i]); | 39 EXPECT_EQ(decoded, testStrings[i]); |
| 40 } | 40 } |
| 41 } | 41 } |
| 42 | 42 |
| 43 TEST_F(NSCoderStdStringTest, decodeEmpty) { | 43 TEST_F(NSCoderStdStringTest, decodeEmpty) { |
| 44 NSMutableData *data = [NSMutableData data]; | 44 NSMutableData *data = [NSMutableData data]; |
| 45 | 45 |
| 46 scoped_nsobject<NSKeyedArchiver> archiver( | 46 base::scoped_nsobject<NSKeyedArchiver> archiver( |
| 47 [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]); | 47 [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]); |
| 48 [archiver finishEncoding]; | 48 [archiver finishEncoding]; |
| 49 | 49 |
| 50 scoped_nsobject<NSKeyedUnarchiver> unarchiver( | 50 base::scoped_nsobject<NSKeyedUnarchiver> unarchiver( |
| 51 [[NSKeyedUnarchiver alloc] initForReadingWithData:data]); | 51 [[NSKeyedUnarchiver alloc] initForReadingWithData:data]); |
| 52 const std::string decoded = nscoder_util::DecodeString(unarchiver, @"test"); | 52 const std::string decoded = nscoder_util::DecodeString(unarchiver, @"test"); |
| 53 | 53 |
| 54 EXPECT_EQ(decoded, ""); | 54 EXPECT_EQ(decoded, ""); |
| 55 } | 55 } |
| 56 | 56 |
| 57 } // namespace | 57 } // namespace |
| OLD | NEW |