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

Unified Diff: ios/web/navigation/nscoder_util_unittest.mm

Issue 988383002: Upstream various ios/web utilities and helpers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@web-public-upstreaming
Patch Set: Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: ios/web/navigation/nscoder_util_unittest.mm
diff --git a/ios/web/navigation/nscoder_util_unittest.mm b/ios/web/navigation/nscoder_util_unittest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..8d3b667e618759ec36e7f9f92191ade94a7cf7d5
--- /dev/null
+++ b/ios/web/navigation/nscoder_util_unittest.mm
@@ -0,0 +1,59 @@
+// Copyright 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import <Foundation/Foundation.h>
+
+#include "base/basictypes.h"
+#include "base/mac/scoped_nsobject.h"
+#include "ios/web/navigation/nscoder_util.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/platform_test.h"
+
+namespace web {
+namespace {
+
+typedef PlatformTest NSCoderStdStringTest;
+
+const char* testStrings[] = {
+ "Arf",
+ "",
+ "This is working™",
+ "古池や蛙飛込む水の音\nふるいけやかわずとびこむみずのおと",
+ "ἀγεωμέτρητος μηδεὶς εἰσίτω",
+ "Bang!\t\n"
+};
+
+TEST_F(NSCoderStdStringTest, encodeDecode) {
+ for (size_t i = 0; i < arraysize(testStrings); ++i) {
+ NSMutableData* data = [NSMutableData data];
+
+ base::scoped_nsobject<NSKeyedArchiver> archiver(
+ [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]);
+ nscoder_util::EncodeString(archiver, @"test", testStrings[i]);
+ [archiver finishEncoding];
+
+ base::scoped_nsobject<NSKeyedUnarchiver> unarchiver(
+ [[NSKeyedUnarchiver alloc] initForReadingWithData:data]);
+ const std::string decoded = nscoder_util::DecodeString(unarchiver, @"test");
+
+ EXPECT_EQ(decoded, testStrings[i]);
+ }
+}
+
+TEST_F(NSCoderStdStringTest, decodeEmpty) {
+ NSMutableData* data = [NSMutableData data];
+
+ base::scoped_nsobject<NSKeyedArchiver> archiver(
+ [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]);
+ [archiver finishEncoding];
+
+ base::scoped_nsobject<NSKeyedUnarchiver> unarchiver(
+ [[NSKeyedUnarchiver alloc] initForReadingWithData:data]);
+ const std::string decoded = nscoder_util::DecodeString(unarchiver, @"test");
+
+ EXPECT_EQ(decoded, "");
+}
+
+} // namespace
+} // namespace web

Powered by Google App Engine
This is Rietveld 408576698