summaryrefslogtreecommitdiffstats
path: root/chrome/browser/parsers
diff options
context:
space:
mode:
authorjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-22 20:39:53 +0000
committerjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-22 20:39:53 +0000
commit635b5cacd941af08cc616c4644fa4f7ee8bc3eec (patch)
treecd31a6c68e217ac6fb39abfae0dcdcbe5b34d679 /chrome/browser/parsers
parent5b00039b06fc2c80ac3e72e8d708d3a6df1e6ab9 (diff)
downloadchromium_src-635b5cacd941af08cc616c4644fa4f7ee8bc3eec.zip
chromium_src-635b5cacd941af08cc616c4644fa4f7ee8bc3eec.tar.gz
chromium_src-635b5cacd941af08cc616c4644fa4f7ee8bc3eec.tar.bz2
TTF: Add tests for FileMetaDataParser.
BUG=none TEST=FileMetaDataParserTest.* Review URL: http://codereview.chromium.org/2814022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50518 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/parsers')
-rw-r--r--chrome/browser/parsers/metadata_parser_filebase.h4
-rw-r--r--chrome/browser/parsers/metadata_parser_filebase_unittest.cc98
2 files changed, 100 insertions, 2 deletions
diff --git a/chrome/browser/parsers/metadata_parser_filebase.h b/chrome/browser/parsers/metadata_parser_filebase.h
index b49ebfe..c0ecfe4 100644
--- a/chrome/browser/parsers/metadata_parser_filebase.h
+++ b/chrome/browser/parsers/metadata_parser_filebase.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 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.
@@ -10,7 +10,7 @@
typedef base::hash_map<std::string, std::string> PropertyMap;
// Parser for the file type. Allows for parsing of files, and gets
-// properties assiciated with files.
+// properties associated with files.
class FileMetadataParser : public MetadataParser {
public:
explicit FileMetadataParser(const FilePath& path);
diff --git a/chrome/browser/parsers/metadata_parser_filebase_unittest.cc b/chrome/browser/parsers/metadata_parser_filebase_unittest.cc
new file mode 100644
index 0000000..0e954e6
--- /dev/null
+++ b/chrome/browser/parsers/metadata_parser_filebase_unittest.cc
@@ -0,0 +1,98 @@
+// Copyright (c) 2010 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 <map>
+#include <string>
+
+#include "base/file_path.h"
+#include "base/file_util.h"
+#include "base/scoped_temp_dir.h"
+#include "base/string_util.h"
+#include "chrome/browser/parsers/metadata_parser_filebase.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+class FileMetaDataParserTest : public testing::Test {
+ protected:
+ virtual void SetUp() {
+ // Create a temporary directory for testing and fill it with a file.
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+
+ test_file_ = temp_dir_.path().AppendASCII("FileMetaDataParserTest");
+
+ // Create the test file.
+ std::string content = "content";
+ int write_size = file_util::WriteFile(test_file_, content.c_str(),
+ content.length());
+ ASSERT_EQ(static_cast<int>(content.length()), write_size);
+ }
+
+ std::string test_file_str() {
+#if defined(OS_POSIX)
+ return test_file_.BaseName().value();
+#elif defined(OS_WIN)
+ return WideToASCII(test_file_.BaseName().value());
+#endif // defined(OS_POSIX)
+ }
+
+ std::string test_file_size() {
+ int64 size;
+ EXPECT_TRUE(file_util::GetFileSize(test_file_, &size));
+
+ return Int64ToString(size);
+ }
+
+ ScopedTempDir temp_dir_;
+ FilePath test_file_;
+};
+
+TEST_F(FileMetaDataParserTest, Parse) {
+ FileMetadataParser parser(test_file_);
+
+ EXPECT_TRUE(parser.Parse());
+
+ std::string value;
+ EXPECT_TRUE(parser.GetProperty(MetadataParser::kPropertyTitle, &value));
+ EXPECT_EQ(test_file_str(), value);
+
+ // Verify the file size property.
+ EXPECT_TRUE(parser.GetProperty(MetadataParser::kPropertyFilesize, &value));
+ EXPECT_EQ(test_file_size(), value);
+
+ // FileMetadataParser does not set kPropertyType.
+ EXPECT_FALSE(parser.GetProperty(MetadataParser::kPropertyType, &value));
+}
+
+TEST_F(FileMetaDataParserTest, PropertyIterator) {
+ FileMetadataParser parser(test_file_);
+
+ EXPECT_TRUE(parser.Parse());
+
+ scoped_ptr<MetadataPropertyIterator> iter(parser.GetPropertyIterator());
+ ASSERT_NE(static_cast<MetadataPropertyIterator*>(NULL), iter.get());
+ ASSERT_EQ(2, iter->Length());
+
+ std::map<std::string, std::string> expectations;
+ expectations[MetadataParser::kPropertyFilesize] = test_file_size();
+ expectations[MetadataParser::kPropertyTitle] = test_file_str();
+
+ std::string key, value;
+ for (int i = 0; i < iter->Length(); ++i) {
+ EXPECT_FALSE(iter->IsEnd());
+ EXPECT_TRUE(iter->GetNext(&key, &value));
+ // No ostream operator<< implementation for map iterator, so can't use
+ // ASSERT_NE.
+ ASSERT_TRUE(expectations.find(key) != expectations.end());
+ EXPECT_EQ(expectations[key], value);
+
+ expectations.erase(key);
+ }
+
+ EXPECT_TRUE(iter->IsEnd());
+ EXPECT_FALSE(iter->GetNext(&key, &value));
+ EXPECT_TRUE(expectations.empty());
+}
+
+} // namespace