2022-09-06 19:14:07 -04:00
|
|
|
// Copyright 2014 The Crashpad Authors
|
2014-08-01 14:44:57 -04:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
#include "minidump/minidump_string_writer.h"
|
|
|
|
|
2022-02-28 20:57:19 -08:00
|
|
|
#include <iterator>
|
2014-08-01 14:44:57 -04:00
|
|
|
#include <string>
|
2022-06-02 12:27:37 -06:00
|
|
|
#include <type_traits>
|
2014-08-01 14:44:57 -04:00
|
|
|
|
2015-02-05 15:04:49 -08:00
|
|
|
#include "base/format_macros.h"
|
2022-06-02 12:27:37 -06:00
|
|
|
#include "base/notreached.h"
|
2014-08-01 14:44:57 -04:00
|
|
|
#include "base/strings/stringprintf.h"
|
2014-11-07 09:57:07 -05:00
|
|
|
#include "base/strings/utf_string_conversions.h"
|
2014-08-01 14:44:57 -04:00
|
|
|
#include "gtest/gtest.h"
|
2014-11-07 09:57:07 -05:00
|
|
|
#include "minidump/test/minidump_rva_list_test_util.h"
|
2014-10-21 14:15:07 -04:00
|
|
|
#include "minidump/test/minidump_string_writer_test_util.h"
|
2014-11-07 09:57:07 -05:00
|
|
|
#include "minidump/test/minidump_writable_test_util.h"
|
2015-02-18 14:15:38 -05:00
|
|
|
#include "util/file/string_file.h"
|
2014-08-01 14:44:57 -04:00
|
|
|
|
2014-10-07 17:28:50 -04:00
|
|
|
namespace crashpad {
|
|
|
|
namespace test {
|
2014-08-01 14:44:57 -04:00
|
|
|
namespace {
|
|
|
|
|
2022-06-02 12:27:37 -06:00
|
|
|
class TestTypeNames {
|
|
|
|
public:
|
|
|
|
template <typename T>
|
|
|
|
static std::string GetName(int) {
|
2024-08-14 13:09:43 +10:00
|
|
|
static_assert(std::is_same<T, RVA>() || std::is_same<T, RVA64>());
|
|
|
|
return std::is_same<T, RVA>() ? "RVA" : "RVA64";
|
2022-06-02 12:27:37 -06:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename RVAType>
|
|
|
|
class MinidumpStringWriter : public ::testing::Test {};
|
|
|
|
|
|
|
|
using RVATypes = ::testing::Types<RVA, RVA64>;
|
|
|
|
TYPED_TEST_SUITE(MinidumpStringWriter, RVATypes, TestTypeNames);
|
|
|
|
|
|
|
|
TYPED_TEST(MinidumpStringWriter, MinidumpUTF16StringWriter) {
|
2015-02-18 14:15:38 -05:00
|
|
|
StringFile string_file;
|
2014-08-01 14:44:57 -04:00
|
|
|
|
|
|
|
{
|
|
|
|
SCOPED_TRACE("unset");
|
2015-02-18 14:15:38 -05:00
|
|
|
string_file.Reset();
|
2014-08-01 14:44:57 -04:00
|
|
|
crashpad::internal::MinidumpUTF16StringWriter string_writer;
|
2015-02-18 14:15:38 -05:00
|
|
|
EXPECT_TRUE(string_writer.WriteEverything(&string_file));
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
ASSERT_EQ(string_file.string().size(), 6u);
|
2014-10-21 14:15:07 -04:00
|
|
|
|
|
|
|
const MINIDUMP_STRING* minidump_string =
|
2022-06-02 12:27:37 -06:00
|
|
|
MinidumpStringAtRVA(string_file.string(), TypeParam(0));
|
2014-10-21 14:15:07 -04:00
|
|
|
EXPECT_TRUE(minidump_string);
|
2022-06-02 12:27:37 -06:00
|
|
|
EXPECT_EQ(MinidumpStringAtRVAAsString(string_file.string(), TypeParam(0)),
|
2021-03-08 17:31:04 +01:00
|
|
|
std::u16string());
|
2014-08-01 14:44:57 -04:00
|
|
|
}
|
|
|
|
|
2017-07-25 13:34:04 -04:00
|
|
|
static constexpr struct {
|
2014-08-01 14:44:57 -04:00
|
|
|
size_t input_length;
|
|
|
|
const char* input_string;
|
|
|
|
size_t output_length;
|
2021-03-08 17:31:04 +01:00
|
|
|
char16_t output_string[10];
|
2014-08-01 14:44:57 -04:00
|
|
|
} kTestData[] = {
|
|
|
|
{0, "", 0, {}},
|
|
|
|
{1, "a", 1, {'a'}},
|
|
|
|
{2, "\0b", 2, {0, 'b'}},
|
|
|
|
{3, "cde", 3, {'c', 'd', 'e'}},
|
|
|
|
{9, "Hi world!", 9, {'H', 'i', ' ', 'w', 'o', 'r', 'l', 'd', '!'}},
|
|
|
|
{7, "ret\nurn", 7, {'r', 'e', 't', '\n', 'u', 'r', 'n'}},
|
|
|
|
{2, "\303\251", 1, {0x00e9}}, // é
|
|
|
|
|
|
|
|
// oóöőo
|
|
|
|
{8, "o\303\263\303\266\305\221o", 5, {'o', 0x00f3, 0x00f6, 0x151, 'o'}},
|
|
|
|
{4, "\360\220\204\202", 2, {0xd800, 0xdd02}}, // 𐄂 (non-BMP)
|
|
|
|
};
|
|
|
|
|
2022-02-28 20:57:19 -08:00
|
|
|
for (size_t index = 0; index < std::size(kTestData); ++index) {
|
2014-08-01 14:44:57 -04:00
|
|
|
SCOPED_TRACE(base::StringPrintf(
|
2015-02-05 15:04:49 -08:00
|
|
|
"index %" PRIuS ", input %s", index, kTestData[index].input_string));
|
2014-08-01 14:44:57 -04:00
|
|
|
|
|
|
|
// Make sure that the expected output string with its NUL terminator fits in
|
|
|
|
// the space provided.
|
2022-02-28 20:57:19 -08:00
|
|
|
ASSERT_EQ(kTestData[index]
|
|
|
|
.output_string[std::size(kTestData[index].output_string) - 1],
|
|
|
|
0);
|
2014-08-01 14:44:57 -04:00
|
|
|
|
2015-02-18 14:15:38 -05:00
|
|
|
string_file.Reset();
|
2014-08-01 14:44:57 -04:00
|
|
|
crashpad::internal::MinidumpUTF16StringWriter string_writer;
|
|
|
|
string_writer.SetUTF8(std::string(kTestData[index].input_string,
|
|
|
|
kTestData[index].input_length));
|
2015-02-18 14:15:38 -05:00
|
|
|
EXPECT_TRUE(string_writer.WriteEverything(&string_file));
|
2014-08-01 14:44:57 -04:00
|
|
|
|
|
|
|
const size_t expected_utf16_units_with_nul =
|
|
|
|
kTestData[index].output_length + 1;
|
2022-01-14 17:51:32 -05:00
|
|
|
[[maybe_unused]] MINIDUMP_STRING* tmp;
|
2014-08-01 14:44:57 -04:00
|
|
|
const size_t expected_utf16_bytes =
|
2018-01-10 14:16:31 -08:00
|
|
|
expected_utf16_units_with_nul * sizeof(tmp->Buffer[0]);
|
|
|
|
ASSERT_EQ(string_file.string().size(), sizeof(*tmp) + expected_utf16_bytes);
|
2014-10-21 14:15:07 -04:00
|
|
|
|
|
|
|
const MINIDUMP_STRING* minidump_string =
|
2022-06-02 12:27:37 -06:00
|
|
|
MinidumpStringAtRVA(string_file.string(), TypeParam(0));
|
2014-10-21 14:15:07 -04:00
|
|
|
EXPECT_TRUE(minidump_string);
|
2021-03-08 17:31:04 +01:00
|
|
|
std::u16string expect_string = std::u16string(
|
2014-12-12 11:06:09 -08:00
|
|
|
kTestData[index].output_string, kTestData[index].output_length);
|
2022-06-02 12:27:37 -06:00
|
|
|
EXPECT_EQ(MinidumpStringAtRVAAsString(string_file.string(), TypeParam(0)),
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
expect_string);
|
2014-08-01 14:44:57 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-02 12:27:37 -06:00
|
|
|
TYPED_TEST(MinidumpStringWriter, ConvertInvalidUTF8ToUTF16) {
|
2015-02-18 14:15:38 -05:00
|
|
|
StringFile string_file;
|
2014-08-01 14:44:57 -04:00
|
|
|
|
2017-07-25 13:34:04 -04:00
|
|
|
static constexpr const char* kTestData[] = {
|
2014-08-01 14:44:57 -04:00
|
|
|
"\200", // continuation byte
|
|
|
|
"\300", // start byte followed by EOF
|
|
|
|
"\310\177", // start byte without continuation
|
|
|
|
"\340\200", // EOF in middle of 3-byte sequence
|
|
|
|
"\340\200\115", // invalid 3-byte sequence
|
|
|
|
"\303\0\251", // NUL in middle of valid sequence
|
|
|
|
};
|
|
|
|
|
2022-02-28 20:57:19 -08:00
|
|
|
for (size_t index = 0; index < std::size(kTestData); ++index) {
|
2015-02-05 15:04:49 -08:00
|
|
|
SCOPED_TRACE(base::StringPrintf(
|
|
|
|
"index %" PRIuS ", input %s", index, kTestData[index]));
|
2015-02-18 14:15:38 -05:00
|
|
|
string_file.Reset();
|
2014-08-01 14:44:57 -04:00
|
|
|
crashpad::internal::MinidumpUTF16StringWriter string_writer;
|
|
|
|
string_writer.SetUTF8(kTestData[index]);
|
2015-02-18 14:15:38 -05:00
|
|
|
EXPECT_TRUE(string_writer.WriteEverything(&string_file));
|
2014-08-01 14:44:57 -04:00
|
|
|
|
|
|
|
// The requirements for conversion of invalid UTF-8 input are lax. Make sure
|
|
|
|
// that at least enough data was written for a string that has one unit and
|
|
|
|
// a NUL terminator, make sure that the length field matches the length of
|
2014-10-21 14:15:07 -04:00
|
|
|
// data written, and make sure that at least one U+FFFD replacement
|
|
|
|
// character was written.
|
|
|
|
const MINIDUMP_STRING* minidump_string =
|
2022-06-02 12:27:37 -06:00
|
|
|
MinidumpStringAtRVA(string_file.string(), TypeParam(0));
|
2014-10-21 14:15:07 -04:00
|
|
|
EXPECT_TRUE(minidump_string);
|
2022-01-14 17:51:32 -05:00
|
|
|
[[maybe_unused]] MINIDUMP_STRING* tmp;
|
2018-01-10 14:16:31 -08:00
|
|
|
EXPECT_EQ(
|
|
|
|
minidump_string->Length,
|
|
|
|
string_file.string().size() - sizeof(*tmp) - sizeof(tmp->Buffer[0]));
|
2021-03-08 17:31:04 +01:00
|
|
|
std::u16string output_string =
|
2022-06-02 12:27:37 -06:00
|
|
|
MinidumpStringAtRVAAsString(string_file.string(), TypeParam(0));
|
2014-10-21 14:15:07 -04:00
|
|
|
EXPECT_FALSE(output_string.empty());
|
2021-03-08 17:31:04 +01:00
|
|
|
EXPECT_NE(output_string.find(0xfffd), std::u16string::npos);
|
2014-08-01 14:44:57 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-02 12:27:37 -06:00
|
|
|
TYPED_TEST(MinidumpStringWriter, MinidumpUTF8StringWriter) {
|
2015-02-18 14:15:38 -05:00
|
|
|
StringFile string_file;
|
2014-08-01 14:44:57 -04:00
|
|
|
|
|
|
|
{
|
|
|
|
SCOPED_TRACE("unset");
|
2015-02-18 14:15:38 -05:00
|
|
|
string_file.Reset();
|
2014-08-01 14:44:57 -04:00
|
|
|
crashpad::internal::MinidumpUTF8StringWriter string_writer;
|
2015-02-18 14:15:38 -05:00
|
|
|
EXPECT_TRUE(string_writer.WriteEverything(&string_file));
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
ASSERT_EQ(string_file.string().size(), 5u);
|
2014-10-21 14:15:07 -04:00
|
|
|
|
2014-08-01 14:44:57 -04:00
|
|
|
const MinidumpUTF8String* minidump_string =
|
2022-06-02 12:27:37 -06:00
|
|
|
MinidumpUTF8StringAtRVA(string_file.string(), TypeParam(0));
|
2014-10-21 14:15:07 -04:00
|
|
|
EXPECT_TRUE(minidump_string);
|
2022-06-02 12:27:37 -06:00
|
|
|
EXPECT_EQ(
|
|
|
|
MinidumpUTF8StringAtRVAAsString(string_file.string(), TypeParam(0)),
|
|
|
|
std::string());
|
2014-08-01 14:44:57 -04:00
|
|
|
}
|
|
|
|
|
2017-07-25 13:34:04 -04:00
|
|
|
static constexpr struct {
|
2014-08-01 14:44:57 -04:00
|
|
|
size_t length;
|
|
|
|
const char* string;
|
|
|
|
} kTestData[] = {
|
|
|
|
{0, ""},
|
|
|
|
{1, "a"},
|
|
|
|
{2, "\0b"},
|
|
|
|
{3, "cde"},
|
|
|
|
{9, "Hi world!"},
|
|
|
|
{7, "ret\nurn"},
|
|
|
|
{2, "\303\251"}, // é
|
|
|
|
|
|
|
|
// oóöőo
|
|
|
|
{8, "o\303\263\303\266\305\221o"},
|
|
|
|
{4, "\360\220\204\202"}, // 𐄂 (non-BMP)
|
|
|
|
};
|
|
|
|
|
2022-02-28 20:57:19 -08:00
|
|
|
for (size_t index = 0; index < std::size(kTestData); ++index) {
|
2014-08-01 14:44:57 -04:00
|
|
|
SCOPED_TRACE(base::StringPrintf(
|
2015-02-05 15:04:49 -08:00
|
|
|
"index %" PRIuS ", input %s", index, kTestData[index].string));
|
2014-08-01 14:44:57 -04:00
|
|
|
|
2015-02-18 14:15:38 -05:00
|
|
|
string_file.Reset();
|
2014-08-01 14:44:57 -04:00
|
|
|
crashpad::internal::MinidumpUTF8StringWriter string_writer;
|
2014-10-16 18:09:18 -04:00
|
|
|
std::string test_string(kTestData[index].string, kTestData[index].length);
|
|
|
|
string_writer.SetUTF8(test_string);
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
EXPECT_EQ(string_writer.UTF8(), test_string);
|
2015-02-18 14:15:38 -05:00
|
|
|
EXPECT_TRUE(string_writer.WriteEverything(&string_file));
|
2014-08-01 14:44:57 -04:00
|
|
|
|
|
|
|
const size_t expected_utf8_bytes_with_nul = kTestData[index].length + 1;
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
ASSERT_EQ(string_file.string().size(),
|
|
|
|
sizeof(MinidumpUTF8String) + expected_utf8_bytes_with_nul);
|
2014-10-21 14:15:07 -04:00
|
|
|
|
2014-08-01 14:44:57 -04:00
|
|
|
const MinidumpUTF8String* minidump_string =
|
2022-06-02 12:27:37 -06:00
|
|
|
MinidumpUTF8StringAtRVA(string_file.string(), TypeParam(0));
|
2014-10-21 14:15:07 -04:00
|
|
|
EXPECT_TRUE(minidump_string);
|
2022-06-02 12:27:37 -06:00
|
|
|
EXPECT_EQ(
|
|
|
|
MinidumpUTF8StringAtRVAAsString(string_file.string(), TypeParam(0)),
|
|
|
|
test_string);
|
2014-08-01 14:44:57 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-07 09:57:07 -05:00
|
|
|
struct MinidumpUTF16StringListWriterTraits {
|
2014-11-07 11:45:44 -05:00
|
|
|
using MinidumpStringListWriterType = MinidumpUTF16StringListWriter;
|
2021-03-08 17:31:04 +01:00
|
|
|
static std::u16string ExpectationForUTF8(const std::string& utf8) {
|
2014-11-07 09:57:07 -05:00
|
|
|
return base::UTF8ToUTF16(utf8);
|
|
|
|
}
|
2021-03-08 17:31:04 +01:00
|
|
|
static std::u16string ObservationAtRVA(const std::string& file_contents,
|
2014-12-12 11:06:09 -08:00
|
|
|
RVA rva) {
|
2014-11-07 09:57:07 -05:00
|
|
|
return MinidumpStringAtRVAAsString(file_contents, rva);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MinidumpUTF8StringListWriterTraits {
|
2014-11-07 11:45:44 -05:00
|
|
|
using MinidumpStringListWriterType = MinidumpUTF8StringListWriter;
|
2014-11-07 09:57:07 -05:00
|
|
|
static std::string ExpectationForUTF8(const std::string& utf8) {
|
|
|
|
return utf8;
|
|
|
|
}
|
|
|
|
static std::string ObservationAtRVA(const std::string& file_contents,
|
|
|
|
RVA rva) {
|
|
|
|
return MinidumpUTF8StringAtRVAAsString(file_contents, rva);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Traits>
|
|
|
|
void MinidumpStringListTest() {
|
|
|
|
std::vector<std::string> strings;
|
|
|
|
strings.push_back(std::string("One"));
|
|
|
|
strings.push_back(std::string());
|
|
|
|
strings.push_back(std::string("3"));
|
|
|
|
strings.push_back(std::string("\360\237\222\251"));
|
|
|
|
|
|
|
|
typename Traits::MinidumpStringListWriterType string_list_writer;
|
|
|
|
EXPECT_FALSE(string_list_writer.IsUseful());
|
|
|
|
string_list_writer.InitializeFromVector(strings);
|
|
|
|
EXPECT_TRUE(string_list_writer.IsUseful());
|
|
|
|
|
2015-02-18 14:15:38 -05:00
|
|
|
StringFile string_file;
|
2014-11-07 09:57:07 -05:00
|
|
|
|
2015-02-18 14:15:38 -05:00
|
|
|
ASSERT_TRUE(string_list_writer.WriteEverything(&string_file));
|
2014-11-07 09:57:07 -05:00
|
|
|
|
|
|
|
const MinidumpRVAList* list =
|
2015-02-18 14:15:38 -05:00
|
|
|
MinidumpRVAListAtStart(string_file.string(), strings.size());
|
2014-11-07 09:57:07 -05:00
|
|
|
ASSERT_TRUE(list);
|
|
|
|
|
|
|
|
for (size_t index = 0; index < strings.size(); ++index) {
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
EXPECT_EQ(
|
|
|
|
Traits::ObservationAtRVA(string_file.string(), list->children[index]),
|
|
|
|
Traits::ExpectationForUTF8(strings[index]));
|
2014-11-07 09:57:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-02 12:27:37 -06:00
|
|
|
TYPED_TEST(MinidumpStringWriter, MinidumpUTF16StringList) {
|
2014-11-07 09:57:07 -05:00
|
|
|
MinidumpStringListTest<MinidumpUTF16StringListWriterTraits>();
|
|
|
|
}
|
|
|
|
|
2022-06-02 12:27:37 -06:00
|
|
|
TYPED_TEST(MinidumpStringWriter, MinidumpUTF8StringList) {
|
2014-11-07 09:57:07 -05:00
|
|
|
MinidumpStringListTest<MinidumpUTF8StringListWriterTraits>();
|
|
|
|
}
|
|
|
|
|
2014-08-01 14:44:57 -04:00
|
|
|
} // namespace
|
2014-10-07 17:28:50 -04:00
|
|
|
} // namespace test
|
|
|
|
} // namespace crashpad
|