base_test_unittest.cc 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright (c) 2011 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. #include "courgette/base_test_unittest.h"
  5. #include "base/files/file_util.h"
  6. #include "base/path_service.h"
  7. void BaseTest::SetUp() {
  8. ASSERT_TRUE(base::PathService::Get(base::DIR_SOURCE_ROOT, &test_dir_));
  9. test_dir_ = test_dir_.AppendASCII("courgette");
  10. test_dir_ = test_dir_.AppendASCII("testdata");
  11. }
  12. void BaseTest::TearDown() {
  13. }
  14. // Reads a test file into a string.
  15. std::string BaseTest::FileContents(const char* file_name) const {
  16. base::FilePath file_path = test_dir_;
  17. file_path = file_path.AppendASCII(file_name);
  18. std::string file_bytes;
  19. EXPECT_TRUE(base::ReadFileToString(file_path, &file_bytes));
  20. return file_bytes;
  21. }
  22. std::string BaseTest::FilesContents(std::list<std::string> file_names) const {
  23. std::string result;
  24. std::list<std::string>::iterator file_name = file_names.begin();
  25. while (file_name != file_names.end()) {
  26. result += FileContents(file_name->c_str());
  27. file_name++;
  28. }
  29. return result;
  30. }