| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2008, Google Inc. |
| 2 // |
| 3 // Redistribution and use in source and binary forms, with or without |
| 4 // modification, are permitted provided that the following conditions are met: |
| 5 // |
| 6 // 1. Redistributions of source code must retain the above copyright notice, |
| 7 // this list of conditions and the following disclaimer. |
| 8 // 2. Redistributions in binary form must reproduce the above copyright notice, |
| 9 // this list of conditions and the following disclaimer in the documentation |
| 10 // and/or other materials provided with the distribution. |
| 11 // 3. Neither the name of Google Inc. nor the names of its contributors may be |
| 12 // used to endorse or promote products derived from this software without |
| 13 // specific prior written permission. |
| 14 // |
| 15 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 16 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 17 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 18 // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 19 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 20 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 21 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 22 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 23 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 24 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 |
| 26 #include "gears/base/common/database2_metadata.h" |
| 27 #include "gears/base/common/sqlite_wrapper.h" |
| 28 |
| 29 static const std::string16 kTestOrigin(STRING16(L"unittest.foo.example.com")); |
| 30 static const std::string16 kTestName(STRING16(L"unittest")); |
| 31 |
| 32 bool TestDatabase2Metadata() { |
| 33 #undef TEST_ASSERT |
| 34 #define TEST_ASSERT(b) \ |
| 35 { \ |
| 36 if (!(b)) { \ |
| 37 LOG(("TestDatabase2Metadata - failed (%d)\n", __LINE__)); \ |
| 38 return false; \ |
| 39 } \ |
| 40 } |
| 41 SQLDatabase db; |
| 42 |
| 43 // create test database |
| 44 TEST_ASSERT(db.Open(STRING16(L"TestDatabase2Metadata.db"))); |
| 45 TEST_ASSERT(db.DropAllObjects()); |
| 46 |
| 47 // create table |
| 48 Database2Metadata table(&db); |
| 49 TEST_ASSERT(table.CreateTableVersion8()); |
| 50 |
| 51 // set version |
| 52 std::string16 versionIn(L"1.0"); |
| 53 TEST_ASSERT(table.SetVersion(kTestOrigin, kTestName, versionIn)); |
| 54 |
| 55 std::string16 versionOut; |
| 56 bool found; |
| 57 |
| 58 // read version |
| 59 TEST_ASSERT(table.GetVersion(kTestOrigin, kTestName, &versionOut, &found)); |
| 60 TEST_ASSERT(found); |
| 61 TEST_ASSERT(versionOut == versionIn); |
| 62 |
| 63 // update version |
| 64 std::string16 newVersionIn(L"2.0"); |
| 65 TEST_ASSERT(table.SetVersion(kTestOrigin, kTestName, newVersionIn)); |
| 66 |
| 67 TEST_ASSERT(table.GetVersion(kTestOrigin, kTestName, &versionOut, &found)); |
| 68 TEST_ASSERT(found); |
| 69 TEST_ASSERT(versionOut == newVersionIn); |
| 70 |
| 71 // read unknown origin/name |
| 72 TEST_ASSERT(table.GetVersion(std::string16(L"http://unknown.example.com"), |
| 73 std::string16(L"unknown"), &versionOut, &found)); |
| 74 |
| 75 TEST_ASSERT(!found); |
| 76 |
| 77 LOG(("TestDatabase2Metadata - passed\n")); |
| 78 |
| 79 return true; |
| 80 } |
| OLD | NEW |