| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/media_galleries/fileapi/picasa/pmp_column_reader.h" | 10 #include "chrome/browser/media_galleries/fileapi/picasa/pmp_column_reader.h" |
| 11 #include "chrome/browser/media_galleries/fileapi/picasa/pmp_constants.h" | 11 #include "chrome/browser/media_galleries/fileapi/picasa/pmp_constants.h" |
| 12 #include "chrome/browser/media_galleries/fileapi/picasa/pmp_table_reader.h" | 12 #include "chrome/browser/media_galleries/fileapi/picasa/pmp_table_reader.h" |
| 13 #include "chrome/browser/media_galleries/fileapi/picasa/pmp_test_helper.h" | 13 #include "chrome/browser/media_galleries/fileapi/picasa/pmp_test_helper.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 using picasaimport::PmpTestHelper; | 18 using picasaimport::PmpTestHelper; |
| 19 | 19 |
| 20 TEST(PmpTableReaderTest, RowCountAndFieldType) { | 20 TEST(PmpTableReaderTest, RowCountAndFieldType) { |
| 21 PmpTestHelper test_helper; | 21 std::string table_name("tabletest"); |
| 22 PmpTestHelper test_helper(table_name); |
| 22 ASSERT_TRUE(test_helper.Init()); | 23 ASSERT_TRUE(test_helper.Init()); |
| 23 | 24 |
| 24 std::string table_name = "testtable"; | |
| 25 | |
| 26 std::vector<std::string> column_names; | 25 std::vector<std::string> column_names; |
| 27 column_names.push_back("strings"); | 26 column_names.push_back("strings"); |
| 28 column_names.push_back("uint32s"); | 27 column_names.push_back("uint32s"); |
| 29 column_names.push_back("doubles"); | 28 column_names.push_back("doubles"); |
| 30 | 29 |
| 31 const std::vector<std::string> strings_vector(10, "Hello"); | 30 const std::vector<std::string> strings_vector(10, "Hello"); |
| 32 const std::vector<uint32> uint32s_vector(30, 42); | 31 const std::vector<uint32> uint32s_vector(30, 42); |
| 33 const std::vector<double> doubles_vector(20, 0.5); | 32 const std::vector<double> doubles_vector(20, 0.5); |
| 34 | 33 |
| 35 picasaimport::PmpFieldType column_field_types[] = { | 34 picasaimport::PmpFieldType column_field_types[] = { |
| 36 picasaimport::PMP_TYPE_STRING, | 35 picasaimport::PMP_TYPE_STRING, |
| 37 picasaimport::PMP_TYPE_UINT32, | 36 picasaimport::PMP_TYPE_UINT32, |
| 38 picasaimport::PMP_TYPE_DOUBLE64 | 37 picasaimport::PMP_TYPE_DOUBLE64 |
| 39 }; | 38 }; |
| 40 | 39 |
| 41 const uint32 max_rows = uint32s_vector.size(); | 40 const uint32 max_rows = uint32s_vector.size(); |
| 42 | 41 |
| 43 base::FilePath indicator_path = test_helper.GetTempDirPath().Append( | |
| 44 base::FilePath::FromUTF8Unsafe(table_name + "_0")); | |
| 45 | |
| 46 ASSERT_EQ(0, file_util::WriteFile(indicator_path, NULL, 0)); | |
| 47 // Write three column files, one each for strings, uint32s, and doubles. | 42 // Write three column files, one each for strings, uint32s, and doubles. |
| 48 | 43 |
| 49 ASSERT_TRUE(test_helper.WriteColumnFileFromVector( | 44 ASSERT_TRUE(test_helper.WriteColumnFileFromVector( |
| 50 table_name, column_names[0], column_field_types[0], strings_vector)); | 45 column_names[0], column_field_types[0], strings_vector)); |
| 46 ASSERT_TRUE(test_helper.WriteColumnFileFromVector( |
| 47 column_names[1], column_field_types[1], uint32s_vector)); |
| 48 ASSERT_TRUE(test_helper.WriteColumnFileFromVector( |
| 49 column_names[2], column_field_types[2], doubles_vector)); |
| 51 | 50 |
| 52 ASSERT_TRUE(test_helper.WriteColumnFileFromVector( | 51 picasaimport::PmpTableReader table_reader(table_name, |
| 53 table_name, column_names[1], column_field_types[1], uint32s_vector)); | 52 test_helper.GetTempDirPath()); |
| 54 | 53 |
| 55 ASSERT_TRUE(test_helper.WriteColumnFileFromVector( | 54 for (unsigned int i = 0; i < column_names.size(); i++) { |
| 56 table_name, column_names[2], column_field_types[2], doubles_vector)); | 55 ASSERT_TRUE( |
| 57 | 56 table_reader.AddColumn(column_names[i], column_field_types[i]) != NULL); |
| 58 picasaimport::PmpTableReader table_reader; | 57 } |
| 59 ASSERT_TRUE(table_reader.Init( | |
| 60 table_name, test_helper.GetTempDirPath(), column_names)); | |
| 61 | 58 |
| 62 EXPECT_EQ(max_rows, table_reader.RowCount()); | 59 EXPECT_EQ(max_rows, table_reader.RowCount()); |
| 63 | |
| 64 const std::vector<const picasaimport::PmpColumnReader*> column_readers = | |
| 65 table_reader.GetColumns(); | |
| 66 | |
| 67 for (int i = 0; i < 3; i++) { | |
| 68 EXPECT_EQ(column_field_types[i], column_readers[i]->field_type()); | |
| 69 } | |
| 70 } | 60 } |
| 71 | 61 |
| 72 } // namespace | 62 } // namespace |
| OLD | NEW |