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

Unified 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, 9 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 side-by-side diff with in-line comments
Download patch
Index: webkit/fileapi/media/picasa/pmp_table_reader_unittest.cc
diff --git a/webkit/fileapi/media/picasa/pmp_table_reader_unittest.cc b/webkit/fileapi/media/picasa/pmp_table_reader_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d213595563b521ae0941fc3fa02c69eddcd82450
--- /dev/null
+++ b/webkit/fileapi/media/picasa/pmp_table_reader_unittest.cc
@@ -0,0 +1,84 @@
+// Copyright 2013 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 <algorithm>
+#include <vector>
+
+#include "base/file_util.h"
+#include "base/files/scoped_temp_dir.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "webkit/fileapi/media/picasa/pmp_column_reader.h"
+#include "webkit/fileapi/media/picasa/pmp_constants.h"
+#include "webkit/fileapi/media/picasa/pmp_table_reader.h"
+#include "webkit/fileapi/media/picasa/pmp_test_helper.h"
+
+namespace {
+
+using fileapi::PmpTestHelper;
+
+template<class T>
+bool WriteColumnFile(base::FilePath directory, std::string table_name,
+ std::string column_name, const uint16 field_type,
+ std::vector<T> elements_vector) {
+ base::FilePath path = directory.Append(table_name + "_" + column_name + "." +
+ fileapi::kPmpExtension);
+ std::vector<uint8> data = PmpTestHelper::MakeHeaderAndBody(
+ field_type, elements_vector.size(), elements_vector);
+
+ return PmpTestHelper::WriteToFile(path, data);
+}
+
+TEST(PmpTableReaderTest, RowCountAndFieldType) {
+ base::ScopedTempDir tempdir;
+
+ std::string table_name = "testtable";
+
+ std::vector<std::string> column_names;
+ column_names.push_back("strings");
+ column_names.push_back("uint32s");
+ column_names.push_back("doubles");
+
+ const std::vector<std::string> strings_vector(10, "Hello");
+ const std::vector<uint32> uint32s_vector(30, 42);
+ const std::vector<double> doubles_vector(20, 0.5);
+
+ uint16 column_field_types[] = {
+ fileapi::kPmpFieldTypeString,
+ fileapi::kPmpFieldTypeUInt32,
+ fileapi::kPmpFieldTypeDouble64
+ };
+
+ const uint32 max_rows = uint32s_vector.size();
+
+ ASSERT_TRUE(tempdir.CreateUniqueTempDir());
+
+ base::FilePath temppath = tempdir.path();
+
+ ASSERT_EQ(
+ 0, file_util::WriteFile(temppath.Append(table_name + "_0"), NULL, 0));
+ // Write three column files, one each for strings, uint32s, and doubles.
+
+ ASSERT_TRUE(WriteColumnFile(temppath, table_name, column_names[0],
+ column_field_types[0], strings_vector));
+
+ ASSERT_TRUE(WriteColumnFile(temppath, table_name, column_names[1],
+ column_field_types[1], uint32s_vector));
+
+ ASSERT_TRUE(WriteColumnFile(temppath, table_name, column_names[2],
+ column_field_types[2], doubles_vector));
+
+ fileapi::PmpTableReader table_reader;
+ ASSERT_TRUE(table_reader.InitFromDisk(table_name, temppath, column_names));
+
+ EXPECT_EQ(max_rows, table_reader.RowCount());
+
+ const std::vector<const fileapi::PmpColumnReader*> column_readers =
+ table_reader.GetColumns();
+
+ for(int i = 0; i < 3; i++) {
+ EXPECT_EQ(column_field_types[i], column_readers[i]->field_type());
+ }
+}
+
+} // namespace

Powered by Google App Engine
This is Rietveld 408576698