<commit_before>// Copyright (c) 2006-2008 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"
#include "base/logging.h"
#include "base/path_service.h"
#include "chrome/browser/search_engines/template_url.h"
#include "chrome/browser/search_engines/template_url_parser.h"
#include "chrome/common/chrome_paths.h"
#include "testing/gtest/include/gtest/gtest.h"

class TemplateURLParserTest : public testing::Test {
 public:
  TemplateURLParserTest() : parse_result_(true) {
  }

  virtual void SetUp() {
    ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &full_path_));
    full_path_ = full_path_.AppendASCII("osdd");
    if (!file_util::PathExists(full_path_)) {
      LOG(ERROR) <<
          L"This test can't be run without some non-redistributable data";
      full_path_ = FilePath();
    }
  }

  bool IsDisabled() {
    return full_path_.empty();
  }

  // Parses the OpenSearch description document at file_name (relative to
  // the data dir). The TemplateURL is placed in template_url_.
  // The result of Parse is stored in the field parse_result_ (this doesn't
  // use a return value due to internally using ASSERT_).
  void ParseFile(const std::string& file_name,
                 TemplateURLParser::ParameterFilter* filter) {
    FilePath full_path;
    parse_result_ = false;
    ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &full_path));
    full_path = full_path.AppendASCII("osdd");
    full_path = full_path.AppendASCII(file_name);
    ASSERT_TRUE(file_util::PathExists(full_path));

    std::string contents;
    file_util::ReadFileToString(full_path, &contents);
    parse_result_ = TemplateURLParser::Parse(
        reinterpret_cast<const unsigned char*>(contents.c_str()),
        contents.length(), filter, &template_url_);
  }

  // ParseFile parses the results into this template_url.
  TemplateURL template_url_;

  FilePath full_path_;

  // Result of the parse.
  bool parse_result_;<commit_msg>Coverity: check file_util::ReadFileToString return.<commit_after>// Copyright (c) 2006-2008 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"
#include "base/logging.h"
#include "base/path_service.h"
#include "chrome/browser/search_engines/template_url.h"
#include "chrome/browser/search_engines/template_url_parser.h"
#include "chrome/common/chrome_paths.h"
#include "testing/gtest/include/gtest/gtest.h"

class TemplateURLParserTest : public testing::Test {
 public:
  TemplateURLParserTest() : parse_result_(true) {
  }

  virtual void SetUp() {
    ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &full_path_));
    full_path_ = full_path_.AppendASCII("osdd");
    if (!file_util::PathExists(full_path_)) {
      LOG(ERROR) <<
          L"This test can't be run without some non-redistributable data";
      full_path_ = FilePath();
    }
  }

  bool IsDisabled() {
    return full_path_.empty();
  }

  // Parses the OpenSearch description document at file_name (relative to
  // the data dir). The TemplateURL is placed in template_url_.
  // The result of Parse is stored in the field parse_result_ (this doesn't
  // use a return value due to internally using ASSERT_).
  void ParseFile(const std::string& file_name,
                 TemplateURLParser::ParameterFilter* filter) {
    FilePath full_path;
    parse_result_ = false;
    ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &full_path));
    full_path = full_path.AppendASCII("osdd");
    full_path = full_path.AppendASCII(file_name);
    ASSERT_TRUE(file_util::PathExists(full_path));

    std::string contents;
    ASSERT_TRUE(file_util::ReadFileToString(full_path, &contents));
    parse_result_ = TemplateURLParser::Parse(
        reinterpret_cast<const unsigned char*>(contents.c_str()),
        contents.length(), filter, &template_url_);
  }

  // ParseFile parses the results into this template_url.
  TemplateURL template_url_;

  FilePath full_path_;

  // Result of the parse.
  bool parse_result_;
{'fraction_non_alphanumeric': 0.10847132229421647, 'fraction_numerical': 0.003839692824574034, 'mean_word_length': 4.190535491905355, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '979565', 'n_tokens_mistral': 1305, 'n_tokens_neox': 1265, 'n_words': 322}