Chromium Code Reviews| Index: content/browser/media_gallery/media_gallery_database_unittest.cc |
| diff --git a/content/browser/media_gallery/media_gallery_database_unittest.cc b/content/browser/media_gallery/media_gallery_database_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2c30d698c40d5c603469e1a2d2f27920bcd69ff5 |
| --- /dev/null |
| +++ b/content/browser/media_gallery/media_gallery_database_unittest.cc |
| @@ -0,0 +1,62 @@ |
| +// Copyright (c) 2012 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 "base/file_util.h" |
|
Lei Zhang
2012/03/07 01:41:42
nit: you only need file_path.h.
tpayne
2012/03/07 18:04:03
Done.
|
| +#include "base/scoped_temp_dir.h" |
| +#include "content/browser/media_gallery/media_gallery_database.h" |
| +#include "content/browser/media_gallery/media_gallery_types.h" |
| +#include "sql/connection.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace media_gallery { |
| + |
| +class MediaGalleryDatabaseTest : public testing::Test, |
| + public MediaGalleryDatabase { |
| + public: |
| + MediaGalleryDatabaseTest() { } |
| + |
| + protected: |
| + virtual sql::Connection& GetDB() { |
| + return db_; |
| + } |
| + |
| + private: |
| + // Test setup. |
| + void SetUp() { |
| + ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| + FilePath db_file = temp_dir_.path().AppendASCII("MediaGalleryTest.db"); |
| + |
| + ASSERT_TRUE(db_.Open(db_file)); |
| + |
| + // Initialize the tables for this test. |
| + ASSERT_EQ(sql::INIT_OK, InitInternal(&db_)); |
| + } |
| + |
| + void TearDown() { |
| + db_.Close(); |
| + } |
| + |
| + ScopedTempDir temp_dir_; |
| + sql::Connection db_; |
| +}; |
| + |
| +TEST_F(MediaGalleryDatabaseTest, Init) { |
| + EXPECT_TRUE(DoesCollectionsTableExist(&GetDB())); |
| +} |
| + |
| +TEST_F(MediaGalleryDatabaseTest, AddCollection) { |
| + CollectionRow row1(FilePath(FILE_PATH_LITERAL("path1")), |
| + base::Time::FromDoubleT(12345), |
| + 123, |
| + false); |
| + CollectionId rowid = CreateCollectionRow(&row1); |
| + EXPECT_TRUE(rowid); |
|
Lei Zhang
2012/03/07 01:41:42
Do you need this when you have the test on the nex
tpayne
2012/03/07 18:04:03
Done.
Lei Zhang
2012/03/07 21:24:37
You didn't do anything here.
tpayne
2012/03/07 21:34:54
Done.
|
| + EXPECT_EQ(rowid, row1.id); |
| + |
| + CollectionRow row2; |
| + EXPECT_TRUE(GetCollectionRow(rowid, &row2)); |
| + EXPECT_TRUE(row1 == row2); |
|
Lei Zhang
2012/03/07 01:41:42
EXPECT_EQ(row1, row2);
tpayne
2012/03/07 18:04:03
This requires defining operator<< for CollectionRo
|
| +} |
| + |
| +} // namespace media_gallery |