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

Side by Side Diff: webkit/fileapi/media/picasa/pmp_table_reader_unittest.cc

Issue 12704024: Simple PMP reader to parse Picasa's metadata (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unused constant. Created 7 years, 8 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <algorithm>
6 #include <vector>
7
8 #include "base/file_util.h"
9 #include "base/files/scoped_temp_dir.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "webkit/fileapi/media/picasa/pmp_column_reader.h"
12 #include "webkit/fileapi/media/picasa/pmp_constants.h"
13 #include "webkit/fileapi/media/picasa/pmp_table_reader.h"
14 #include "webkit/fileapi/media/picasa/pmp_test_helper.h"
15
16 namespace {
17
18 using fileapi::PmpTestHelper;
19
20 template<class T>
21 bool WriteColumnFile(base::FilePath directory, std::string table_name,
22 std::string column_name, const uint16 field_type,
23 std::vector<T> elements_vector) {
24 base::FilePath path = directory.Append(table_name + "_" + column_name + "." +
25 fileapi::kPmpExtension);
26 std::vector<uint8> data = PmpTestHelper::MakeHeaderAndBody(
27 field_type, elements_vector.size(), elements_vector);
28
29 return PmpTestHelper::WriteToFile(path, data);
30 }
31
32 TEST(PmpTableReaderTest, RowCountAndFieldType) {
33 base::ScopedTempDir tempdir;
34
35 std::string table_name = "testtable";
36
37 std::vector<std::string> column_names;
38 column_names.push_back("strings");
39 column_names.push_back("uint32s");
40 column_names.push_back("doubles");
41
42 const std::vector<std::string> strings_vector(10, "Hello");
43 const std::vector<uint32> uint32s_vector(30, 42);
44 const std::vector<double> doubles_vector(20, 0.5);
45
46 uint16 column_field_types[] = {
47 fileapi::kPmpFieldTypeString,
48 fileapi::kPmpFieldTypeUInt32,
49 fileapi::kPmpFieldTypeDouble64
50 };
51
52 const uint32 max_rows = uint32s_vector.size();
53
54 ASSERT_TRUE(tempdir.CreateUniqueTempDir());
55
56 base::FilePath temppath = tempdir.path();
57
58 ASSERT_EQ(
59 0, file_util::WriteFile(temppath.Append(table_name + "_0"), NULL, 0));
60 // Write three column files, one each for strings, uint32s, and doubles.
61
62 ASSERT_TRUE(WriteColumnFile(temppath, table_name, column_names[0],
63 column_field_types[0], strings_vector));
64
65 ASSERT_TRUE(WriteColumnFile(temppath, table_name, column_names[1],
66 column_field_types[1], uint32s_vector));
67
68 ASSERT_TRUE(WriteColumnFile(temppath, table_name, column_names[2],
69 column_field_types[2], doubles_vector));
70
71 fileapi::PmpTableReader table_reader;
72 ASSERT_TRUE(table_reader.InitFromDisk(table_name, temppath, column_names));
73
74 EXPECT_EQ(max_rows, table_reader.RowCount());
75
76 const std::vector<const fileapi::PmpColumnReader*> column_readers =
77 table_reader.GetColumns();
78
79 for(int i = 0; i < 3; i++) {
80 EXPECT_EQ(column_field_types[i], column_readers[i]->field_type());
81 }
82 }
83
84 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698