Add ICU message format support
[chromium-blink-merge.git] / chromecast / crash / linux / dummy_minidump_generator_unittest.cc
blobd70ea76135225e4b0df6a62c2ee3a8b0524dfb9b
1 // Copyright 2015 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.
5 #include <string>
7 #include "base/files/file_util.h"
8 #include "base/rand_util.h"
9 #include "chromecast/crash/linux/dummy_minidump_generator.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace chromecast {
14 TEST(DummyMinidumpGeneratorTest, GenerateFailsWithInvalidPath) {
15 // Create directory in which to put minidump.
16 base::FilePath minidump_dir;
17 ASSERT_TRUE(base::CreateNewTempDirectory("", &minidump_dir));
19 // Attempt to generate a minidump from an invalid path.
20 DummyMinidumpGenerator generator("/path/does/not/exist/minidump.dmp");
21 ASSERT_FALSE(generator.Generate(minidump_dir.Append("minidump.dmp").value()));
24 TEST(DummyMinidumpGeneratorTest, GenerateSucceedsWithSmallSource) {
25 // Create directory in which to put minidump.
26 base::FilePath minidump_dir;
27 ASSERT_TRUE(base::CreateNewTempDirectory("", &minidump_dir));
29 // Create a fake minidump file.
30 base::FilePath fake_minidump;
31 ASSERT_TRUE(base::CreateTemporaryFile(&fake_minidump));
32 const std::string data("Test contents of the minidump file.\n");
33 ASSERT_EQ(static_cast<int>(data.size()),
34 base::WriteFile(fake_minidump, data.c_str(), data.size()));
36 DummyMinidumpGenerator generator(fake_minidump.value());
37 base::FilePath new_minidump = minidump_dir.Append("minidump.dmp");
38 EXPECT_TRUE(generator.Generate(new_minidump.value()));
40 // Original file should not exist, and new file should contain original
41 // contents.
42 std::string copied_data;
43 EXPECT_FALSE(base::PathExists(fake_minidump));
44 ASSERT_TRUE(base::PathExists(new_minidump));
45 EXPECT_TRUE(base::ReadFileToString(new_minidump, &copied_data));
46 EXPECT_EQ(data, copied_data);
49 TEST(DummyMinidumpGeneratorTest, GenerateSucceedsWithLargeSource) {
50 // Create directory in which to put minidump.
51 base::FilePath minidump_dir;
52 ASSERT_TRUE(base::CreateNewTempDirectory("", &minidump_dir));
54 // Create a large fake minidump file.
55 base::FilePath fake_minidump;
56 ASSERT_TRUE(base::CreateTemporaryFile(&fake_minidump));
57 size_t str_len = 32768 * 10 + 1;
58 const std::string data = base::RandBytesAsString(str_len);
60 // Write the string to the file.
61 ASSERT_EQ(static_cast<int>(data.size()),
62 base::WriteFile(fake_minidump, data.c_str(), data.size()));
64 base::FilePath new_minidump = minidump_dir.Append("minidump.dmp");
65 DummyMinidumpGenerator generator(fake_minidump.value());
66 ASSERT_TRUE(generator.Generate(new_minidump.value()));
68 // Original file should not exist, and new file should contain original
69 // contents.
70 std::string copied_data;
71 EXPECT_FALSE(base::PathExists(fake_minidump));
72 ASSERT_TRUE(base::PathExists(new_minidump));
73 EXPECT_TRUE(base::ReadFileToString(new_minidump, &copied_data));
74 EXPECT_EQ(data, copied_data);
77 } // namespace chromecast