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 3 // found in the LICENSE file. 4 5 #include "chrome/browser/chromeos/drive/file_change.h" 6 7 #include "testing/gtest/include/gtest/gtest.h" 8 9 namespace drive { 10 11 TEST(FileChangeTest, Getters) { 12 base::FilePath change_path(FILE_PATH_LITERAL("test")); 13 FileChange::Type change_type = FileChange::ADDED; 14 15 FileChange file_change(change_path, change_type); 16 17 EXPECT_EQ(change_path, file_change.path()); 18 EXPECT_EQ(change_type, file_change.type()); 19 } 20 21 TEST(FileChangeTest, FactoryMethod) { 22 base::FilePath change_path(FILE_PATH_LITERAL("a/b/c/d")); 23 FileChange::Type change_type = FileChange::CHANGED; 24 25 FileChangeSet changed_files = 26 FileChange::CreateSingleSet(change_path, change_type); 27 28 ASSERT_EQ(1u, changed_files.size()); 29 FileChangeSet::iterator it = changed_files.begin(); 30 31 EXPECT_EQ(change_path, it->path()); 32 EXPECT_EQ(change_type, it->type()); 33 } 34 35 TEST(FileChangeTest, Equals) { 36 // Change is equal if and only if both path and type are equal. 37 // Paths differ, types are equal. 38 FileChange file_change1(base::FilePath(FILE_PATH_LITERAL("a")), 39 FileChange::ADDED); 40 FileChange file_change2(base::FilePath(FILE_PATH_LITERAL("b")), 41 FileChange::ADDED); 42 EXPECT_EQ(file_change1, file_change1); 43 EXPECT_FALSE(file_change1 == file_change2); 44 45 // Paths are equal, types differ. 46 FileChange file_change3(base::FilePath(FILE_PATH_LITERAL("a")), 47 FileChange::DELETED); 48 FileChange file_change4(base::FilePath(FILE_PATH_LITERAL("a")), 49 FileChange::CHANGED); 50 EXPECT_FALSE(file_change3 == file_change4); 51 52 // Paths and types are equal. 53 FileChange file_change5(base::FilePath(FILE_PATH_LITERAL("c")), 54 FileChange::ADDED); 55 FileChange file_change6(base::FilePath(FILE_PATH_LITERAL("c")), 56 FileChange::ADDED); 57 EXPECT_EQ(file_change5, file_change6); 58 } 59 60 TEST(FileChangeTest, Compare) { 61 FileChange file_change1(base::FilePath(FILE_PATH_LITERAL("a")), 62 FileChange::DELETED); 63 FileChange file_change2(base::FilePath(FILE_PATH_LITERAL("a")), 64 FileChange::ADDED); 65 FileChange file_change3(base::FilePath(FILE_PATH_LITERAL("a")), 66 FileChange::CHANGED); 67 FileChange file_change4(base::FilePath(FILE_PATH_LITERAL("b")), 68 FileChange::ADDED); 69 FileChange file_change5(base::FilePath(FILE_PATH_LITERAL("c")), 70 FileChange::DELETED); 71 72 // Comparison operator should not return true for equal values. 73 EXPECT_FALSE(file_change1 < file_change1); 74 EXPECT_FALSE(file_change2 < file_change2); 75 EXPECT_FALSE(file_change3 < file_change3); 76 EXPECT_FALSE(file_change4 < file_change4); 77 EXPECT_FALSE(file_change5 < file_change5); 78 79 EXPECT_LT(file_change1, file_change2); 80 EXPECT_LT(file_change1, file_change3); 81 EXPECT_LT(file_change1, file_change4); 82 EXPECT_LT(file_change1, file_change5); 83 84 EXPECT_FALSE(file_change2 < file_change1); 85 EXPECT_LT(file_change2, file_change3); 86 EXPECT_LT(file_change2, file_change4); 87 EXPECT_LT(file_change2, file_change5); 88 89 EXPECT_FALSE(file_change3 < file_change1); 90 EXPECT_FALSE(file_change3 < file_change2); 91 EXPECT_LT(file_change3, file_change4); 92 EXPECT_LT(file_change3, file_change5); 93 94 EXPECT_FALSE(file_change4 < file_change1); 95 EXPECT_FALSE(file_change4 < file_change2); 96 EXPECT_FALSE(file_change4 < file_change3); 97 EXPECT_LT(file_change4, file_change5); 98 } 99 100 } // namespace drive 101