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

Unified Diff: sync/api/sync_attachment_unittest.cc

Issue 102193004: Checkpointing some Sync Attachment work. Added SyncAttachment and SyncAttachmentId. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added some DCHECKs and another test case. Created 7 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
Index: sync/api/sync_attachment_unittest.cc
diff --git a/sync/api/sync_attachment_unittest.cc b/sync/api/sync_attachment_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1d0f051a78ada3d8b8ca9c07fc5f05b2488d02b9
--- /dev/null
+++ b/sync/api/sync_attachment_unittest.cc
@@ -0,0 +1,52 @@
+// Copyright 2013 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.
+
+#include "sync/api/sync_attachment.h"
+
+#include <string>
+
+#include "base/memory/ref_counted.h"
+#include "base/memory/ref_counted_memory.h"
+#include "base/memory/scoped_ptr.h"
+#include "sync/protocol/sync.pb.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using sync_pb::SyncAttachmentId;
+
+namespace syncer {
+
+namespace {
+
+typedef testing::Test SyncAttachmentTest;
+
+TEST_F(SyncAttachmentTest, Create_UniqueIdIsUnique) {
+ SyncAttachmentId id;
+ scoped_refptr<base::RefCountedString> bytes(new base::RefCountedString);
+ bytes->data() = "some data";
Nicolas Zea 2013/12/30 19:10:31 nit: make this a anon const variable, and reuse it
maniscalco 2013/12/30 22:17:19 Done.
+ scoped_ptr<SyncAttachment> a1 = SyncAttachment::Create(bytes);
+ scoped_ptr<SyncAttachment> a2 = SyncAttachment::Create(bytes);
+ EXPECT_NE(a1->GetId().unique_id(), a2->GetId().unique_id());
+ EXPECT_EQ(a1->GetBytes(), a2->GetBytes());
+}
+
+TEST_F(SyncAttachmentTest, Create_WithEmptyBytes) {
+ SyncAttachmentId id;
+ scoped_refptr<base::RefCountedString> emptyBytes(new base::RefCountedString);
+ scoped_ptr<SyncAttachment> a = SyncAttachment::Create(emptyBytes);
+ EXPECT_EQ(emptyBytes, a->GetBytes());
+}
+
+TEST_F(SyncAttachmentTest, CreateWithId_HappyCase) {
+ SyncAttachmentId id;
+ id.set_unique_id("3290482049832");
+ scoped_refptr<base::RefCountedString> bytes(new base::RefCountedString);
+ bytes->data() = "some data";
+ scoped_ptr<SyncAttachment> a = SyncAttachment::CreateWithId(id, bytes);
+ EXPECT_EQ(id.unique_id(), a->GetId().unique_id());
+ EXPECT_EQ(bytes, a->GetBytes());
+}
+
+} // namespace
+
+} // namespace syncer

Powered by Google App Engine
This is Rietveld 408576698