mirror of
https://github.com/chromium/crashpad.git
synced 2025-01-14 09:17:57 +08:00
Provide a non-explicit constructor for StringAnnotation.
This allows brace initializing a C array of StringAnnotation objects. Bug: crashpad:192 Change-Id: Id1b187b67b24bb57251957e9d9c18c16579f1dd4 Reviewed-on: https://chromium-review.googlesource.com/807645 Reviewed-by: Mark Mentovai <mark@chromium.org> Commit-Queue: Robert Sesek <rsesek@chromium.org>
This commit is contained in:
parent
00e6bd0887
commit
ac3cc1b884
@ -196,12 +196,36 @@ class Annotation {
|
||||
template <Annotation::ValueSizeType MaxSize>
|
||||
class StringAnnotation : public Annotation {
|
||||
public:
|
||||
//! \brief A constructor tag that enables braced initialization in C arrays.
|
||||
//!
|
||||
//! \sa StringAnnotation()
|
||||
enum class Tag { kArray };
|
||||
|
||||
//! \brief Constructs a new StringAnnotation with the given \a name.
|
||||
//!
|
||||
//! \param[in] name The Annotation name.
|
||||
constexpr explicit StringAnnotation(const char name[])
|
||||
: Annotation(Type::kString, name, value_), value_() {}
|
||||
|
||||
//! \brief Constructs a new StringAnnotation with the given \a name.
|
||||
//!
|
||||
//! This constructor takes the ArrayInitializerTag for use when
|
||||
//! initializing a C array of annotations. The main constructor is
|
||||
//! explicit and cannot be brace-initialized. As an example:
|
||||
//!
|
||||
//! \code
|
||||
//! static crashpad::StringAnnotation<32> annotations[] = {
|
||||
//! {"name-1", crashpad::StringAnnotation<32>::Tag::kArray},
|
||||
//! {"name-2", crashpad::StringAnnotation<32>::Tag::kArray},
|
||||
//! {"name-3", crashpad::StringAnnotation<32>::Tag::kArray},
|
||||
//! };
|
||||
//! \endcode
|
||||
//!
|
||||
//! \param[in] name The Annotation name.
|
||||
//! \param[in] tag A constructor tag.
|
||||
constexpr StringAnnotation(const char name[], Tag tag)
|
||||
: StringAnnotation(name) {}
|
||||
|
||||
//! \brief Sets the Annotation's string value.
|
||||
//!
|
||||
//! \param[in] value The `NUL`-terminated C-string value.
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
#include "client/annotation.h"
|
||||
|
||||
#include <array>
|
||||
#include <string>
|
||||
|
||||
#include "client/annotation_list.h"
|
||||
@ -107,6 +108,19 @@ TEST_F(Annotation, StringType) {
|
||||
EXPECT_EQ("loooo", annotation.value());
|
||||
}
|
||||
|
||||
TEST(StringAnnotation, ArrayOfString) {
|
||||
static crashpad::StringAnnotation<4> annotations[] = {
|
||||
{"test-1", crashpad::StringAnnotation<4>::Tag::kArray},
|
||||
{"test-2", crashpad::StringAnnotation<4>::Tag::kArray},
|
||||
{"test-3", crashpad::StringAnnotation<4>::Tag::kArray},
|
||||
{"test-4", crashpad::StringAnnotation<4>::Tag::kArray},
|
||||
};
|
||||
|
||||
for (auto& annotation : annotations) {
|
||||
EXPECT_FALSE(annotation.is_set());
|
||||
}
|
||||
}
|
||||
|
||||
#if DCHECK_IS_ON()
|
||||
|
||||
TEST(AnnotationDeathTest, EmbeddedNUL) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user