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

Unified Diff: src/platform/update_engine/gzip_unittest.cc

Issue 465067: Missed new files in last commit
Patch Set: Created 11 years 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
« no previous file with comments | « src/platform/update_engine/gzip.cc ('k') | src/platform/update_engine/install_action.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/platform/update_engine/gzip_unittest.cc
diff --git a/src/platform/update_engine/gzip_unittest.cc b/src/platform/update_engine/gzip_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..298ca9d4f360522082ffdd08c51c2f90fc5805d9
--- /dev/null
+++ b/src/platform/update_engine/gzip_unittest.cc
@@ -0,0 +1,68 @@
+// Copyright (c) 2009 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <string.h>
+#include <unistd.h>
+#include <string>
+#include <vector>
+#include <gtest/gtest.h>
+#include "update_engine/gzip.h"
+#include "update_engine/test_utils.h"
+#include "update_engine/utils.h"
+
+using std::string;
+using std::vector;
+
+namespace chromeos_update_engine {
+
+class GzipTest : public ::testing::Test { };
+
+TEST(GzipTest, SimpleTest) {
+ string in("this should compress well xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
+ "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
+ "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
+ "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
+ "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
+ "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
+ vector<char> out;
+ EXPECT_TRUE(GzipCompressString(in, &out));
+ EXPECT_LT(out.size(), in.size());
+ EXPECT_GT(out.size(), 0);
+ vector<char> decompressed;
+ EXPECT_TRUE(GzipDecompress(out, &decompressed));
+ EXPECT_EQ(in.size(), decompressed.size());
+ EXPECT_TRUE(!memcmp(in.data(), &decompressed[0], in.size()));
+}
+
+TEST(GzipTest, PoorCompressionTest) {
+ string in(reinterpret_cast<const char*>(kRandomString),
+ sizeof(kRandomString));
+ vector<char> out;
+ EXPECT_TRUE(GzipCompressString(in, &out));
+ EXPECT_GT(out.size(), in.size());
+ string out_string(&out[0], out.size());
+ vector<char> decompressed;
+ EXPECT_TRUE(GzipDecompressString(out_string, &decompressed));
+ EXPECT_EQ(in.size(), decompressed.size());
+ EXPECT_TRUE(!memcmp(in.data(), &decompressed[0], in.size()));
+}
+
+TEST(GzipTest, MalformedGzipTest) {
+ string in(reinterpret_cast<const char*>(kRandomString),
+ sizeof(kRandomString));
+ vector<char> out;
+ EXPECT_FALSE(GzipDecompressString(in, &out));
+}
+
+TEST(GzipTest, EmptyInputsTest) {
+ string in;
+ vector<char> out;
+ EXPECT_TRUE(GzipDecompressString(in, &out));
+ EXPECT_EQ(0, out.size());
+
+ EXPECT_TRUE(GzipCompressString(in, &out));
+ EXPECT_EQ(0, out.size());
+}
+
+} // namespace chromeos_update_engine
« no previous file with comments | « src/platform/update_engine/gzip.cc ('k') | src/platform/update_engine/install_action.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698