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

Side by Side Diff: sync/syncable/directory_backing_store_unittest.cc

Issue 10989063: Changed DB to store node positions as Ordinals. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Ordinal default ctor now creates invalid Ordinals Created 8 years, 2 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 unified diff | Download patch
OLDNEW
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 #include "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/scoped_temp_dir.h" 12 #include "base/scoped_temp_dir.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "base/string_number_conversions.h" 14 #include "base/string_number_conversions.h"
15 #include "sql/connection.h" 15 #include "sql/connection.h"
16 #include "sql/statement.h" 16 #include "sql/statement.h"
17 #include "sync/internal_api/public/base/node_ordinal.h"
17 #include "sync/protocol/bookmark_specifics.pb.h" 18 #include "sync/protocol/bookmark_specifics.pb.h"
18 #include "sync/protocol/sync.pb.h" 19 #include "sync/protocol/sync.pb.h"
19 #include "sync/syncable/directory_backing_store.h" 20 #include "sync/syncable/directory_backing_store.h"
20 #include "sync/syncable/on_disk_directory_backing_store.h" 21 #include "sync/syncable/on_disk_directory_backing_store.h"
21 #include "sync/syncable/syncable-inl.h" 22 #include "sync/syncable/syncable-inl.h"
22 #include "sync/test/test_directory_backing_store.h" 23 #include "sync/test/test_directory_backing_store.h"
23 #include "sync/util/time.h" 24 #include "sync/util/time.h"
24 #include "testing/gtest/include/gtest/gtest-param-test.h" 25 #include "testing/gtest/include/gtest/gtest-param-test.h"
25 26
26 namespace syncer { 27 namespace syncer {
(...skipping 29 matching lines...) Expand all
56 void SetUpVersion70Database(sql::Connection* connection); 57 void SetUpVersion70Database(sql::Connection* connection);
57 void SetUpVersion71Database(sql::Connection* connection); 58 void SetUpVersion71Database(sql::Connection* connection);
58 void SetUpVersion72Database(sql::Connection* connection); 59 void SetUpVersion72Database(sql::Connection* connection);
59 void SetUpVersion73Database(sql::Connection* connection); 60 void SetUpVersion73Database(sql::Connection* connection);
60 void SetUpVersion74Database(sql::Connection* connection); 61 void SetUpVersion74Database(sql::Connection* connection);
61 void SetUpVersion75Database(sql::Connection* connection); 62 void SetUpVersion75Database(sql::Connection* connection);
62 void SetUpVersion76Database(sql::Connection* connection); 63 void SetUpVersion76Database(sql::Connection* connection);
63 void SetUpVersion77Database(sql::Connection* connection); 64 void SetUpVersion77Database(sql::Connection* connection);
64 void SetUpVersion78Database(sql::Connection* connection); 65 void SetUpVersion78Database(sql::Connection* connection);
65 void SetUpVersion79Database(sql::Connection* connection); 66 void SetUpVersion79Database(sql::Connection* connection);
67 void SetUpVersion80Database(sql::Connection* connection);
66 68
67 void SetUpCurrentDatabaseAndCheckVersion(sql::Connection* connection) { 69 void SetUpCurrentDatabaseAndCheckVersion(sql::Connection* connection) {
68 SetUpVersion77Database(connection); // Prepopulates data. 70 SetUpVersion77Database(connection); // Prepopulates data.
69 scoped_ptr<TestDirectoryBackingStore> dbs( 71 scoped_ptr<TestDirectoryBackingStore> dbs(
70 new TestDirectoryBackingStore(GetUsername(), connection)); 72 new TestDirectoryBackingStore(GetUsername(), connection));
71 73
72 ASSERT_TRUE(LoadAndIgnoreReturnedData(dbs.get())); 74 ASSERT_TRUE(LoadAndIgnoreReturnedData(dbs.get()));
73 ASSERT_FALSE(dbs->needs_column_refresh_); 75 ASSERT_FALSE(dbs->needs_column_refresh_);
74 ASSERT_EQ(kCurrentDBVersion, dbs->GetVersion()); 76 ASSERT_EQ(kCurrentDBVersion, dbs->GetVersion());
75 } 77 }
(...skipping 1552 matching lines...) Expand 10 before | Expand all | Expand 10 after
1628 "9010788312004066376x-6609234393368420856x',NULL);" 1630 "9010788312004066376x-6609234393368420856x',NULL);"
1629 )); 1631 ));
1630 ASSERT_TRUE(connection->CommitTransaction()); 1632 ASSERT_TRUE(connection->CommitTransaction());
1631 } 1633 }
1632 1634
1633 void MigrationTest::SetUpVersion79Database(sql::Connection* connection) { 1635 void MigrationTest::SetUpVersion79Database(sql::Connection* connection) {
1634 ASSERT_TRUE(connection->is_open()); 1636 ASSERT_TRUE(connection->is_open());
1635 ASSERT_TRUE(connection->BeginTransaction()); 1637 ASSERT_TRUE(connection->BeginTransaction());
1636 ASSERT_TRUE(connection->Execute( 1638 ASSERT_TRUE(connection->Execute(
1637 "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);" 1639 "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
1638 "INSERT INTO 'share_version' VALUES('nick@chromium.org',78);" 1640 "INSERT INTO 'share_version' VALUES('nick@chromium.org',79);"
akalin 2012/10/05 22:40:27 nice catch
1639 "CREATE TABLE models (model_id BLOB primary key, progress_marker BLOB, in" 1641 "CREATE TABLE models (model_id BLOB primary key, progress_marker BLOB, in"
1640 "itial_sync_ended BOOLEAN default 0);" 1642 "itial_sync_ended BOOLEAN default 0);"
1641 "INSERT INTO 'models' VALUES(X'C2881000',X'0888810218B605',1);" 1643 "INSERT INTO 'models' VALUES(X'C2881000',X'0888810218B605',1);"
1642 "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,base" 1644 "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,base"
1643 "_version bigint default -1,server_version bigint default 0,server_po" 1645 "_version bigint default -1,server_version bigint default 0,server_po"
1644 "sition_in_parent bigint default 0,local_external_id bigint default 0" 1646 "sition_in_parent bigint default 0,local_external_id bigint default 0"
1645 ",mtime bigint default 0,server_mtime bigint default 0,ctime bigint d" 1647 ",mtime bigint default 0,server_mtime bigint default 0,ctime bigint d"
1646 "efault 0,server_ctime bigint default 0,id varchar(255) default 'r',p" 1648 "efault 0,server_ctime bigint default 0,id varchar(255) default 'r',p"
1647 "arent_id varchar(255) default 'r',server_parent_id varchar(255) defa" 1649 "arent_id varchar(255) default 'r',server_parent_id varchar(255) defa"
1648 "ult 'r',prev_id varchar(255) default 'r',next_id varchar(255) defaul" 1650 "ult 'r',prev_id varchar(255) default 'r',next_id varchar(255) defaul"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1718 "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthda" 1720 "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthda"
1719 "y TEXT, db_create_version TEXT, db_create_time INT, next_id INT defa" 1721 "y TEXT, db_create_version TEXT, db_create_time INT, next_id INT defa"
1720 "ult -2, cache_guid TEXT , notification_state BLOB);" 1722 "ult -2, cache_guid TEXT , notification_state BLOB);"
1721 "INSERT INTO 'share_info' VALUES('nick@chromium.org','nick@chromium.org'," 1723 "INSERT INTO 'share_info' VALUES('nick@chromium.org','nick@chromium.org',"
1722 "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064," 1724 "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,"
1723 "-131078,'9010788312004066376x-6609234393368420856x',NULL);" 1725 "-131078,'9010788312004066376x-6609234393368420856x',NULL);"
1724 )); 1726 ));
1725 ASSERT_TRUE(connection->CommitTransaction()); 1727 ASSERT_TRUE(connection->CommitTransaction());
1726 } 1728 }
1727 1729
1730 void MigrationTest::SetUpVersion80Database(sql::Connection* connection) {
1731 ASSERT_TRUE(connection->is_open());
1732 ASSERT_TRUE(connection->BeginTransaction());
1733 ASSERT_TRUE(connection->Execute(
1734 "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);"
1735 "INSERT INTO 'share_version' VALUES('nick@chromium.org',80);"
1736 "CREATE TABLE models (model_id BLOB primary key, progress_marker BLOB, in"
1737 "itial_sync_ended BOOLEAN default 0);"
1738 "INSERT INTO 'models' VALUES(X'C2881000',X'0888810218B605',1);"
1739 "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,base"
1740 "_version bigint default -1,server_version bigint default 0,server_po"
1741 "sition_in_parent bigint default 0,local_external_id bigint default 0"
1742 ",mtime bigint default 0,server_mtime bigint default 0,ctime bigint d"
1743 "efault 0,server_ctime bigint default 0,id varchar(255) default 'r',p"
1744 "arent_id varchar(255) default 'r',server_parent_id varchar(255) defa"
1745 "ult 'r',prev_id varchar(255) default 'r',next_id varchar(255) defaul"
1746 "t 'r',is_unsynced bit default 0,is_unapplied_update bit default 0,is"
1747 "_del bit default 0,is_dir bit default 0,server_is_dir bit default 0,"
1748 "server_is_del bit default 0,non_unique_name varchar,server_non_uniqu"
1749 "e_name varchar(255),unique_server_tag varchar,unique_client_tag varc"
1750 "har,specifics blob,server_specifics blob, base_server_specifics BLOB"
1751 ");"
1752 "INSERT INTO 'metas' VALUES(1,-1,0,0,0," META_PROTO_TIMES_VALS(1) ",'r','"
1753 "r','r','r','r',0,0,0,1,0,0,NULL,NULL,NULL,NULL,X'',X'',NULL);"
1754 "INSERT INTO 'metas' VALUES(2,669,669,-2097152,4,"
1755 META_PROTO_TIMES_VALS(2) ",'s_ID_2','s_ID_9','s_ID_9','s_ID_2','s_ID_"
1756 "2',0,0,1,0,0,1,'Deleted Item','Deleted Item',NULL,NULL,X'C28810220A1"
1757 "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084141534741534741',X"
1758 "'C28810260A17687474703A2F2F7777772E676F6F676C652E636F6D2F32120B41534"
1759 "14447414447414447',NULL);"
1760 "INSERT INTO 'metas' VALUES(4,681,681,-3145728,3,"
1761 META_PROTO_TIMES_VALS(4) ",'s_ID_4','s_ID_9','s_ID_9','s_ID_4','s_ID_"
1762 "4',0,0,1,0,0,1,'Welcome to Chromium','Welcome to Chromium',NULL,NULL"
1763 ",X'C28810350A31687474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6"
1764 "D652F696E746C2F656E2F77656C636F6D652E68746D6C1200',X'C28810350A31687"
1765 "474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F656"
1766 "E2F77656C636F6D652E68746D6C1200',NULL);"
1767 "INSERT INTO 'metas' VALUES(5,677,677,1048576,7,"
1768 META_PROTO_TIMES_VALS(5) ",'s_ID_5','s_ID_9','s_ID_9','s_ID_5','s_ID_"
1769 "5',0,0,1,0,0,1,'Google','Google',NULL,NULL,X'C28810220A16687474703A2"
1770 "F2F7777772E676F6F676C652E636F6D2F12084147415347415347',X'C28810220A1"
1771 "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084147464447415347',N"
1772 "ULL);"
1773 "INSERT INTO 'metas' VALUES(6,694,694,-4194304,6,"
1774 META_PROTO_TIMES_VALS(6) ",'s_ID_6','s_ID_9','s_ID_9','r','r',0,0,0,1"
1775 ",1,0,'The Internet','The Internet',NULL,NULL,X'C2881000',X'C2881000'"
1776 ",NULL);"
1777 "INSERT INTO 'metas' VALUES(7,663,663,1048576,0,"
1778 META_PROTO_TIMES_VALS(7) ",'s_ID_7','r','r','r','r',0,0,0,1,1,0,'Goog"
1779 "le Chrome','Google Chrome','google_chrome',NULL,NULL,NULL,NULL);"
1780 "INSERT INTO 'metas' VALUES(8,664,664,1048576,0,"
1781 META_PROTO_TIMES_VALS(8) ",'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1"
1782 ",1,0,'Bookmarks','Bookmarks','google_chrome_bookmarks',NULL,X'C28810"
1783 "00',X'C2881000',NULL);"
1784 "INSERT INTO 'metas' VALUES(9,665,665,1048576,1,"
1785 META_PROTO_TIMES_VALS(9) ",'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0"
1786 ",0,0,1,1,0,'Bookmark Bar','Bookmark Bar','bookmark_bar',NULL,X'C2881"
1787 "000',X'C2881000',NULL);"
1788 "INSERT INTO 'metas' VALUES(10,666,666,2097152,2,"
1789 META_PROTO_TIMES_VALS(10) ",'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r',"
1790 "0,0,0,1,1,0,'Other Bookmarks','Other Bookmarks','other_bookmarks',NU"
1791 "LL,X'C2881000',X'C2881000',NULL);"
1792 "INSERT INTO 'metas' VALUES(11,683,683,-1048576,8,"
1793 META_PROTO_TIMES_VALS(11) ",'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13'"
1794 ",0,0,0,0,0,0,'Home (The Chromium Projects)','Home (The Chromium Proj"
1795 "ects)',NULL,NULL,X'C28810220A18687474703A2F2F6465762E6368726F6D69756"
1796 "D2E6F72672F1206414741545741',X'C28810290A1D687474703A2F2F6465762E636"
1797 "8726F6D69756D2E6F72672F6F7468657212084146414756415346',NULL);"
1798 "INSERT INTO 'metas' VALUES(12,685,685,0,9,"
1799 META_PROTO_TIMES_VALS(12) ",'s_ID_12','s_ID_6','s_ID_6','s_ID_13','s_"
1800 "ID_14',0,0,0,1,1,0,'Extra Bookmarks','Extra Bookmarks',NULL,NULL,X'C"
1801 "2881000',X'C2881000',NULL);"
1802 "INSERT INTO 'metas' VALUES(13,687,687,-917504,10,"
1803 META_PROTO_TIMES_VALS(13) ",'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_"
1804 "ID_12',0,0,0,0,0,0,'ICANN | Internet Corporation for Assigned Names "
1805 "and Numbers','ICANN | Internet Corporation for Assigned Names and Nu"
1806 "mbers',NULL,NULL,X'C28810240A15687474703A2F2F7777772E6963616E6E2E636"
1807 "F6D2F120B504E474158463041414646',X'C28810200A15687474703A2F2F7777772"
1808 "E6963616E6E2E636F6D2F120744414146415346',NULL);"
1809 "INSERT INTO 'metas' VALUES(14,692,692,1048576,11,"
1810 META_PROTO_TIMES_VALS(14) ",'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r'"
1811 ",0,0,0,0,0,0,'The WebKit Open Source Project','The WebKit Open Sourc"
1812 "e Project',NULL,NULL,X'C288101A0A12687474703A2F2F7765626B69742E6F726"
1813 "72F1204504E4758',X'C288101C0A13687474703A2F2F7765626B69742E6F72672F7"
1814 "81205504E473259',NULL);"
1815 "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthda"
1816 "y TEXT, db_create_version TEXT, db_create_time INT, next_id INT defa"
1817 "ult -2, cache_guid TEXT , notification_state BLOB, bag_of_chips "
1818 "blob);"
1819 "INSERT INTO 'share_info' VALUES('nick@chromium.org','nick@chromium.org',"
1820 "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,"
1821 "-131078,'9010788312004066376x-6609234393368420856x',NULL, NULL);"
1822 ));
1823 ASSERT_TRUE(connection->CommitTransaction());
1824 }
1825
1728 TEST_F(DirectoryBackingStoreTest, MigrateVersion67To68) { 1826 TEST_F(DirectoryBackingStoreTest, MigrateVersion67To68) {
1729 sql::Connection connection; 1827 sql::Connection connection;
1730 ASSERT_TRUE(connection.OpenInMemory()); 1828 ASSERT_TRUE(connection.OpenInMemory());
1731 1829
1732 SetUpVersion67Database(&connection); 1830 SetUpVersion67Database(&connection);
1733 1831
1734 // Columns existing before version 67. 1832 // Columns existing before version 67.
1735 ASSERT_TRUE(connection.DoesColumnExist("metas", "name")); 1833 ASSERT_TRUE(connection.DoesColumnExist("metas", "name"));
1736 ASSERT_TRUE(connection.DoesColumnExist("metas", "unsanitized_name")); 1834 ASSERT_TRUE(connection.DoesColumnExist("metas", "unsanitized_name"));
1737 ASSERT_TRUE(connection.DoesColumnExist("metas", "server_name")); 1835 ASSERT_TRUE(connection.DoesColumnExist("metas", "server_name"));
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
2043 ASSERT_FALSE(dbs->needs_column_refresh_); 2141 ASSERT_FALSE(dbs->needs_column_refresh_);
2044 ASSERT_TRUE(dbs->MigrateVersion78To79()); 2142 ASSERT_TRUE(dbs->MigrateVersion78To79());
2045 ASSERT_EQ(79, dbs->GetVersion()); 2143 ASSERT_EQ(79, dbs->GetVersion());
2046 ASSERT_FALSE(dbs->needs_column_refresh_); 2144 ASSERT_FALSE(dbs->needs_column_refresh_);
2047 2145
2048 // Ensure the next_id has been incremented. 2146 // Ensure the next_id has been incremented.
2049 MetahandlesIndex entry_bucket; 2147 MetahandlesIndex entry_bucket;
2050 STLElementDeleter<MetahandlesIndex> deleter(&entry_bucket); 2148 STLElementDeleter<MetahandlesIndex> deleter(&entry_bucket);
2051 Directory::KernelLoadInfo load_info; 2149 Directory::KernelLoadInfo load_info;
2052 2150
2151 s.Clear();
2053 ASSERT_TRUE(dbs->Load(&entry_bucket, &load_info)); 2152 ASSERT_TRUE(dbs->Load(&entry_bucket, &load_info));
2054 EXPECT_LE(load_info.kernel_info.next_id, kInitialNextId - 65536); 2153 EXPECT_LE(load_info.kernel_info.next_id, kInitialNextId - 65536);
2055 } 2154 }
2056 2155
2057 TEST_F(DirectoryBackingStoreTest, MigrateVersion79To80) { 2156 TEST_F(DirectoryBackingStoreTest, MigrateVersion79To80) {
2058 sql::Connection connection; 2157 sql::Connection connection;
2059 ASSERT_TRUE(connection.OpenInMemory()); 2158 ASSERT_TRUE(connection.OpenInMemory());
2060 SetUpVersion79Database(&connection); 2159 SetUpVersion79Database(&connection);
2061 2160
2062 scoped_ptr<TestDirectoryBackingStore> dbs( 2161 scoped_ptr<TestDirectoryBackingStore> dbs(
2063 new TestDirectoryBackingStore(GetUsername(), &connection)); 2162 new TestDirectoryBackingStore(GetUsername(), &connection));
2064 ASSERT_FALSE(dbs->needs_column_refresh_); 2163 ASSERT_FALSE(dbs->needs_column_refresh_);
2065 ASSERT_TRUE(dbs->MigrateVersion79To80()); 2164 ASSERT_TRUE(dbs->MigrateVersion79To80());
2066 ASSERT_EQ(80, dbs->GetVersion()); 2165 ASSERT_EQ(80, dbs->GetVersion());
2067 ASSERT_FALSE(dbs->needs_column_refresh_); 2166 ASSERT_FALSE(dbs->needs_column_refresh_);
2068 2167
2069 // Ensure the bag_of_chips has been set. 2168 // Ensure the bag_of_chips has been set.
2070 MetahandlesIndex entry_bucket; 2169 MetahandlesIndex entry_bucket;
2071 STLElementDeleter<MetahandlesIndex> deleter(&entry_bucket); 2170 STLElementDeleter<MetahandlesIndex> deleter(&entry_bucket);
2072 Directory::KernelLoadInfo load_info; 2171 Directory::KernelLoadInfo load_info;
2073 2172
akalin 2012/10/05 22:40:27 remove this extra line?
vishwath 2012/10/08 20:17:49 Done.
2173
2074 ASSERT_TRUE(dbs->Load(&entry_bucket, &load_info)); 2174 ASSERT_TRUE(dbs->Load(&entry_bucket, &load_info));
2075 // Check that the initial value is the serialization of an empty ChipBag. 2175 // Check that the initial value is the serialization of an empty ChipBag.
2076 sync_pb::ChipBag chip_bag; 2176 sync_pb::ChipBag chip_bag;
2077 std::string serialized_chip_bag; 2177 std::string serialized_chip_bag;
2078 ASSERT_TRUE(chip_bag.SerializeToString(&serialized_chip_bag)); 2178 ASSERT_TRUE(chip_bag.SerializeToString(&serialized_chip_bag));
2079 EXPECT_EQ(serialized_chip_bag, load_info.kernel_info.bag_of_chips); 2179 EXPECT_EQ(serialized_chip_bag, load_info.kernel_info.bag_of_chips);
2080 } 2180 }
2081 2181
2182 TEST_F(DirectoryBackingStoreTest, MigrateVersion80To81) {
2183 sql::Connection connection;
2184 ASSERT_TRUE(connection.OpenInMemory());
2185 SetUpVersion80Database(&connection);
2186
2187 sql::Statement s(connection.GetUniqueStatement(
2188 "SELECT metahandle, server_position_in_parent "
2189 "FROM metas WHERE unique_server_tag = 'google_chrome'"));
2190 ASSERT_TRUE(s.Step());
2191 ASSERT_EQ(sql::COLUMN_TYPE_INTEGER, s.ColumnType(1));
2192
2193 scoped_ptr<TestDirectoryBackingStore> dbs(
2194 new TestDirectoryBackingStore(GetUsername(), &connection));
2195 ASSERT_TRUE(dbs->MigrateVersion80To81());
2196 ASSERT_EQ(81, dbs->GetVersion());
2197
2198 // Test that ordinal values are preserved correctly.
2199 sql::Statement new_s(connection.GetUniqueStatement(
2200 "SELECT metahandle, server_ordinal_in_parent "
2201 "FROM metas WHERE unique_server_tag = 'google_chrome'"));
2202 ASSERT_TRUE(new_s.Step());
2203 ASSERT_EQ(sql::COLUMN_TYPE_BLOB, new_s.ColumnType(1));
2204
2205 std::string expected_ordinal = Int64ToNodeOrdinal(1048576).ToInternalValue();
2206 std::string actual_ordinal;
2207 new_s.ColumnBlobAsString(1, &actual_ordinal);
2208 ASSERT_EQ(expected_ordinal, actual_ordinal);
2209 }
2210
2211
2212 TEST_F(DirectoryBackingStoreTest, InvalidOrdinalTriggersRedownload) {
2213 sql::Connection connection;
2214 ASSERT_TRUE(connection.OpenInMemory());
2215 SetUpVersion80Database(&connection);
2216
2217 scoped_ptr<TestDirectoryBackingStore> dbs(
akalin 2012/10/05 22:40:27 actually, can you make a SetUpVersion81Database?
vishwath 2012/10/08 20:17:49 Done.
2218 new TestDirectoryBackingStore(GetUsername(), &connection));
2219 ASSERT_TRUE(dbs->MigrateVersion80To81());
2220 ASSERT_EQ(81, dbs->GetVersion());
2221
2222 //Insert row with bad ordinal.
akalin 2012/10/05 22:40:27 space after //
vishwath 2012/10/08 20:17:49 Done.
2223 const int64 now = TimeToProtoTime(base::Time::Now());
2224 sql::Statement s(connection.GetUniqueStatement(
2225 "INSERT INTO metas "
2226 "( id, metahandle, is_dir, ctime, mtime, server_ordinal_in_parent) "
2227 "VALUES( \"c-invalid\", 9999, 1, ?, ?, \" \")"));
2228 s.BindInt64(0, now);
2229 s.BindInt64(1, now);
2230 ASSERT_TRUE(s.Run());
2231
2232 //Trying to unpack this entry should signal that the DB is corrupted.
akalin 2012/10/05 22:40:27 space after //
vishwath 2012/10/08 20:17:49 Done.
2233 MetahandlesIndex entry_bucket;
2234 Directory::KernelLoadInfo kernel_load_info;
2235 ASSERT_EQ(FAILED_DATABASE_CORRUPT,
2236 dbs->Load(&entry_bucket, &kernel_load_info));
2237
2238 }
2239
2082 TEST_P(MigrationTest, ToCurrentVersion) { 2240 TEST_P(MigrationTest, ToCurrentVersion) {
2083 sql::Connection connection; 2241 sql::Connection connection;
2084 ASSERT_TRUE(connection.OpenInMemory()); 2242 ASSERT_TRUE(connection.OpenInMemory());
2085 switch (GetParam()) { 2243 switch (GetParam()) {
2086 case 67: 2244 case 67:
2087 SetUpVersion67Database(&connection); 2245 SetUpVersion67Database(&connection);
2088 break; 2246 break;
2089 case 68: 2247 case 68:
2090 SetUpVersion68Database(&connection); 2248 SetUpVersion68Database(&connection);
2091 break; 2249 break;
(...skipping 23 matching lines...) Expand all
2115 break; 2273 break;
2116 case 77: 2274 case 77:
2117 SetUpVersion77Database(&connection); 2275 SetUpVersion77Database(&connection);
2118 break; 2276 break;
2119 case 78: 2277 case 78:
2120 SetUpVersion78Database(&connection); 2278 SetUpVersion78Database(&connection);
2121 break; 2279 break;
2122 case 79: 2280 case 79:
2123 SetUpVersion79Database(&connection); 2281 SetUpVersion79Database(&connection);
2124 break; 2282 break;
2283 case 80:
2284 SetUpVersion80Database(&connection);
2285 break;
2125 default: 2286 default:
2126 // If you see this error, it may mean that you've increased the 2287 // If you see this error, it may mean that you've increased the
2127 // database version number but you haven't finished adding unit tests 2288 // database version number but you haven't finished adding unit tests
2128 // for the database migration code. You need to need to supply a 2289 // for the database migration code. You need to need to supply a
2129 // SetUpVersionXXDatabase function with a dump of the test database 2290 // SetUpVersionXXDatabase function with a dump of the test database
2130 // at the old schema. Here's one way to do that: 2291 // at the old schema. Here's one way to do that:
2131 // 1. Start on a clean tree (with none of your pending schema changes). 2292 // 1. Start on a clean tree (with none of your pending schema changes).
2132 // 2. Set a breakpoint in this function and run the unit test. 2293 // 2. Set a breakpoint in this function and run the unit test.
2133 // 3. Allow this test to run to completion (step out of the call), 2294 // 3. Allow this test to run to completion (step out of the call),
2134 // without allowing ~MigrationTest to execute. 2295 // without allowing ~MigrationTest to execute.
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
2452 const std::string& guid2 = TestDirectoryBackingStore::GenerateCacheGUID(); 2613 const std::string& guid2 = TestDirectoryBackingStore::GenerateCacheGUID();
2453 EXPECT_EQ(24U, guid1.size()); 2614 EXPECT_EQ(24U, guid1.size());
2454 EXPECT_EQ(24U, guid2.size()); 2615 EXPECT_EQ(24U, guid2.size());
2455 // In theory this test can fail, but it won't before the universe 2616 // In theory this test can fail, but it won't before the universe
2456 // dies of heat death. 2617 // dies of heat death.
2457 EXPECT_NE(guid1, guid2); 2618 EXPECT_NE(guid1, guid2);
2458 } 2619 }
2459 2620
2460 } // namespace syncable 2621 } // namespace syncable
2461 } // namespace syncer 2622 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698