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

Side by Side Diff: chrome/browser/sync/syncable/syncable_unittest.cc

Issue 193103: Build sync engine as part of the browser build (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "chrome/browser/sync/syncable/syncable.h" 5 #include "chrome/browser/sync/syncable/syncable.h"
6 6
7 #include "build/build_config.h"
8
7 #include <sys/types.h> 9 #include <sys/types.h>
8 10
9 #include <iostream> 11 #include <iostream>
10 #include <limits> 12 #include <limits>
11 #include <string> 13 #include <string>
12 14
13 // TODO(ncarter): Winnow down the OS-specific includes from the test 15 // TODO(ncarter): Winnow down the OS-specific includes from the test
14 // file. 16 // file.
15 #if defined(OS_WINDOWS) 17 #if defined(OS_WIN)
16 #include <tchar.h> 18 #include <tchar.h>
17 #include <atlbase.h> 19 #include <atlbase.h>
18 #include <process.h> 20 #include <process.h>
19 #endif // defined(OS_WINDOWS) 21 #endif // defined(OS_WIN)
20 22
21 #if !defined(OS_WINDOWS) 23 #if !defined(OS_WIN)
22 #define MAX_PATH PATH_MAX 24 #define MAX_PATH PATH_MAX
23 #include <strstream> 25 #include <strstream>
24 #include <ostream> 26 #include <ostream>
25 #include <stdio.h> 27 #include <stdio.h>
26 #include <sys/ipc.h> 28 #include <sys/ipc.h>
27 #include <sys/sem.h> 29 #include <sys/sem.h>
28 #include <sys/times.h> 30 #include <sys/times.h>
29 #endif // !defined(OS_WINDOWS) 31 #endif // !defined(OS_WIN)
30 32
31 #include "base/at_exit.h" 33 #include "base/at_exit.h"
32 #include "base/logging.h" 34 #include "base/logging.h"
33 #include "base/scoped_ptr.h" 35 #include "base/scoped_ptr.h"
34 #include "chrome/browser/sync/syncable/directory_backing_store.h" 36 #include "chrome/browser/sync/syncable/directory_backing_store.h"
35 #include "chrome/browser/sync/syncable/directory_manager.h" 37 #include "chrome/browser/sync/syncable/directory_manager.h"
36 #include "chrome/browser/sync/util/character_set_converters.h" 38 #include "chrome/browser/sync/util/character_set_converters.h"
37 #include "chrome/browser/sync/util/closure.h" 39 #include "chrome/browser/sync/util/closure.h"
38 #include "chrome/browser/sync/util/compat-file.h" 40 #include "chrome/browser/sync/util/compat_file.h"
39 #include "chrome/browser/sync/util/event_sys-inl.h" 41 #include "chrome/browser/sync/util/event_sys-inl.h"
40 #include "chrome/browser/sync/util/path_helpers.h" 42 #include "chrome/browser/sync/util/path_helpers.h"
41 #include "chrome/browser/sync/util/pthread_helpers.h" 43 #include "chrome/browser/sync/util/pthread_helpers.h"
42 #include "chrome/browser/sync/util/query_helpers.h" 44 #include "chrome/browser/sync/util/query_helpers.h"
43 #include "chrome/test/sync/engine/test_id_factory.h" 45 #include "chrome/test/sync/engine/test_id_factory.h"
44 #include "testing/gtest/include/gtest/gtest.h" 46 #include "testing/gtest/include/gtest/gtest.h"
45 #include "third_party/sqlite/preprocessed/sqlite3.h" 47 #include "third_party/sqlite/preprocessed/sqlite3.h"
46 48
47 using browser_sync::TestIdFactory; 49 using browser_sync::TestIdFactory;
48 using std::cout; 50 using std::cout;
(...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 976
975 timespec operator + (const timespec& a, const timespec& b) { 977 timespec operator + (const timespec& a, const timespec& b) {
976 const long nanos = a.tv_nsec + b.tv_nsec; 978 const long nanos = a.tv_nsec + b.tv_nsec;
977 static const long nanos_per_second = 1000000000; 979 static const long nanos_per_second = 1000000000;
978 timespec r = { a.tv_sec + b.tv_sec + (nanos / nanos_per_second), 980 timespec r = { a.tv_sec + b.tv_sec + (nanos / nanos_per_second),
979 nanos % nanos_per_second }; 981 nanos % nanos_per_second };
980 return r; 982 return r;
981 } 983 }
982 984
983 void SleepMs(int milliseconds) { 985 void SleepMs(int milliseconds) {
984 #ifdef OS_WINDOWS 986 #ifdef OS_WIN
985 Sleep(milliseconds); 987 Sleep(milliseconds);
986 #else 988 #else
987 usleep(milliseconds * 1000); 989 usleep(milliseconds * 1000);
988 #endif 990 #endif
989 } 991 }
990 992
991 namespace StressTransaction { 993 namespace StressTransaction {
992 struct Globals { 994 struct Globals {
993 DirectoryManager* dirman; 995 DirectoryManager* dirman;
994 PathString dirname; 996 PathString dirname;
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1127 PathString a(1, tests[i].a); 1129 PathString a(1, tests[i].a);
1128 PathString b(1, tests[i].b); 1130 PathString b(1, tests[i].b);
1129 const int result = ComparePathNames(a, b); 1131 const int result = ComparePathNames(a, b);
1130 if (result != tests[i].expected_result) { 1132 if (result != tests[i].expected_result) {
1131 ADD_FAILURE() << "ComparePathNames(" << tests[i].a << ", " << tests[i].b 1133 ADD_FAILURE() << "ComparePathNames(" << tests[i].a << ", " << tests[i].b
1132 << ") returned " << result << "; expected " 1134 << ") returned " << result << "; expected "
1133 << tests[i].expected_result; 1135 << tests[i].expected_result;
1134 } 1136 }
1135 } 1137 }
1136 1138
1137 #ifndef OS_WINDOWS 1139 #ifndef OS_WIN
1138 // This table lists (to the best of my knowledge) every pair of characters 1140 // This table lists (to the best of my knowledge) every pair of characters
1139 // in unicode such that: 1141 // in unicode such that:
1140 // for all i: tolower(kUpperToLowerMap[i].upper) = kUpperToLowerMap[i].lower 1142 // for all i: tolower(kUpperToLowerMap[i].upper) = kUpperToLowerMap[i].lower
1141 // This is then used to test that case-insensitive comparison of each pair 1143 // This is then used to test that case-insensitive comparison of each pair
1142 // returns 0 (that, that they are equal). After running the test on Mac OS X 1144 // returns 0 (that, that they are equal). After running the test on Mac OS X
1143 // with the CFString API for comparision, the failing cases were commented 1145 // with the CFString API for comparision, the failing cases were commented
1144 // out. 1146 // out.
1145 // 1147 //
1146 // Map of upper to lower case characters taken from 1148 // Map of upper to lower case characters taken from
1147 // ftp://ftp.unicode.org/Public/UNIDATA/UnicodeData.txt 1149 // ftp://ftp.unicode.org/Public/UNIDATA/UnicodeData.txt
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
1467 if (0 != result) { 1469 if (0 != result) {
1468 // This ugly strstream works around an issue where using << hex on the 1470 // This ugly strstream works around an issue where using << hex on the
1469 // stream for ADD_FAILURE produces "true" and "false" in the output. 1471 // stream for ADD_FAILURE produces "true" and "false" in the output.
1470 strstream msg; 1472 strstream msg;
1471 msg << "ComparePathNames(0x" << hex << kUpperToLowerMap[i].upper 1473 msg << "ComparePathNames(0x" << hex << kUpperToLowerMap[i].upper
1472 << ", 0x" << hex << kUpperToLowerMap[i].lower 1474 << ", 0x" << hex << kUpperToLowerMap[i].lower
1473 << ") returned " << dec << result << "; expected 0" << '\0'; 1475 << ") returned " << dec << result << "; expected 0" << '\0';
1474 ADD_FAILURE() << msg.str(); 1476 ADD_FAILURE() << msg.str();
1475 } 1477 }
1476 } 1478 }
1477 #endif // not defined OS_WINDOWS 1479 #endif // not defined OS_WIN
1478 } 1480 }
1479 1481
1480 #ifdef OS_WINDOWS 1482 #ifdef OS_WIN
1481 TEST(Syncable, PathNameMatch) { 1483 TEST(Syncable, PathNameMatch) {
1482 // basic stuff, not too many otherwise we're testing the os. 1484 // basic stuff, not too many otherwise we're testing the os.
1483 EXPECT_TRUE(PathNameMatch(PSTR("bob"), PSTR("bob"))); 1485 EXPECT_TRUE(PathNameMatch(PSTR("bob"), PSTR("bob")));
1484 EXPECT_FALSE(PathNameMatch(PSTR("bob"), PSTR("fred"))); 1486 EXPECT_FALSE(PathNameMatch(PSTR("bob"), PSTR("fred")));
1485 // Test our ; extension. 1487 // Test our ; extension.
1486 EXPECT_TRUE(PathNameMatch(PSTR("bo;b"), PSTR("bo;b"))); 1488 EXPECT_TRUE(PathNameMatch(PSTR("bo;b"), PSTR("bo;b")));
1487 EXPECT_TRUE(PathNameMatch(PSTR("bo;b"), PSTR("bo*"))); 1489 EXPECT_TRUE(PathNameMatch(PSTR("bo;b"), PSTR("bo*")));
1488 EXPECT_FALSE(PathNameMatch(PSTR("bo;b"), PSTR("co;b"))); 1490 EXPECT_FALSE(PathNameMatch(PSTR("bo;b"), PSTR("co;b")));
1489 EXPECT_FALSE(PathNameMatch(PSTR("bo;b"), PSTR("co*"))); 1491 EXPECT_FALSE(PathNameMatch(PSTR("bo;b"), PSTR("co*")));
1490 // Test our fixes for prepended spaces. 1492 // Test our fixes for prepended spaces.
1491 EXPECT_TRUE(PathNameMatch(PSTR(" bob"), PSTR(" bo*"))); 1493 EXPECT_TRUE(PathNameMatch(PSTR(" bob"), PSTR(" bo*")));
1492 EXPECT_TRUE(PathNameMatch(PSTR(" bob"), PSTR(" bob"))); 1494 EXPECT_TRUE(PathNameMatch(PSTR(" bob"), PSTR(" bob")));
1493 EXPECT_FALSE(PathNameMatch(PSTR("bob"), PSTR(" bob"))); 1495 EXPECT_FALSE(PathNameMatch(PSTR("bob"), PSTR(" bob")));
1494 EXPECT_FALSE(PathNameMatch(PSTR(" bob"), PSTR("bob"))); 1496 EXPECT_FALSE(PathNameMatch(PSTR(" bob"), PSTR("bob")));
1495 // Combo test. 1497 // Combo test.
1496 EXPECT_TRUE(PathNameMatch(PSTR(" b;ob"), PSTR(" b;o*"))); 1498 EXPECT_TRUE(PathNameMatch(PSTR(" b;ob"), PSTR(" b;o*")));
1497 EXPECT_TRUE(PathNameMatch(PSTR(" b;ob"), PSTR(" b;ob"))); 1499 EXPECT_TRUE(PathNameMatch(PSTR(" b;ob"), PSTR(" b;ob")));
1498 EXPECT_FALSE(PathNameMatch(PSTR("b;ob"), PSTR(" b;ob"))); 1500 EXPECT_FALSE(PathNameMatch(PSTR("b;ob"), PSTR(" b;ob")));
1499 EXPECT_FALSE(PathNameMatch(PSTR(" b;ob"), PSTR("b;ob"))); 1501 EXPECT_FALSE(PathNameMatch(PSTR(" b;ob"), PSTR("b;ob")));
1500 // other whitespace should give no matches. 1502 // other whitespace should give no matches.
1501 EXPECT_FALSE(PathNameMatch(PSTR("bob"), PSTR("\tbob"))); 1503 EXPECT_FALSE(PathNameMatch(PSTR("bob"), PSTR("\tbob")));
1502 } 1504 }
1503 #endif // OS_WINDOWS 1505 #endif // OS_WIN
1504 1506
1505 } // namespace 1507 } // namespace
1506 1508
1507 void FakeSync(MutableEntry* e, const char* fake_id) { 1509 void FakeSync(MutableEntry* e, const char* fake_id) {
1508 e->Put(IS_UNSYNCED, false); 1510 e->Put(IS_UNSYNCED, false);
1509 e->Put(BASE_VERSION, 2); 1511 e->Put(BASE_VERSION, 2);
1510 e->Put(ID, Id::CreateFromServerId(fake_id)); 1512 e->Put(ID, Id::CreateFromServerId(fake_id));
1511 } 1513 }
1512 1514
1513 TEST_F(SyncableDirectoryTest, Bug1509232) { 1515 TEST_F(SyncableDirectoryTest, Bug1509232) {
(...skipping 11 matching lines...) Expand all
1525 Blob value_blob(value, value + ARRAYSIZE(value)); 1527 Blob value_blob(value, value + ARRAYSIZE(value));
1526 ext.mutable_value()->swap(value_blob); 1528 ext.mutable_value()->swap(value_blob);
1527 ext.delete_attribute(); 1529 ext.delete_attribute();
1528 } 1530 }
1529 // This call to SaveChanges used to CHECK fail. 1531 // This call to SaveChanges used to CHECK fail.
1530 dir_.get()->SaveChanges(); 1532 dir_.get()->SaveChanges();
1531 } 1533 }
1532 1534
1533 } // namespace syncable 1535 } // namespace syncable
1534 1536
1535 #ifdef OS_WINDOWS 1537 #ifdef OS_WIN
1536 class LocalModule : public CAtlExeModuleT<LocalModule> { }; 1538 class LocalModule : public CAtlExeModuleT<LocalModule> { };
1537 LocalModule module_; 1539 LocalModule module_;
1538 1540
1539 int main(int argc, char* argv[]) { 1541 int main(int argc, char* argv[]) {
1540 testing::InitGoogleTest(&argc, argv); 1542 testing::InitGoogleTest(&argc, argv);
1541 1543
1542 // TODO(chron) Add method to change random seed. 1544 // TODO(chron) Add method to change random seed.
1543 const int32 test_random_seed = time(NULL); 1545 const int32 test_random_seed = time(NULL);
1544 cout << "Random seed: " << test_random_seed << endl; 1546 cout << "Random seed: " << test_random_seed << endl;
1545 LOG(INFO) << "Random seed: " << test_random_seed << endl; 1547 LOG(INFO) << "Random seed: " << test_random_seed << endl;
1546 srand(test_random_seed); 1548 srand(test_random_seed);
1547 1549
1548 // Necessary for NewCallback, scoped to main 1550 // Necessary for NewCallback, scoped to main
1549 base::AtExitManager at_exit_manager; 1551 base::AtExitManager at_exit_manager;
1550 1552
1551 int result = RUN_ALL_TESTS(); 1553 int result = RUN_ALL_TESTS();
1552 return result; 1554 return result;
1553 } 1555 }
1554 #endif 1556 #endif
OLDNEW
« no previous file with comments | « chrome/browser/sync/syncable/syncable.cc ('k') | chrome/browser/sync/util/character_set_converters-linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698