mirror of
https://github.com/chromium/crashpad.git
synced 2025-01-15 10:07:56 +08:00
34699d378b
This introduces the Annotation object, used to declare typed annotations, and the AnnotationList object, used to reference these. The AnnotationList is referenced by the CrashpadInfo structure. Currently nothing reads these. The AnnotationList implements a lock-free linked list, into which Annotation objects are added exactly once, when they are first set. Clearing an Annotation merely marks it internally as such, rather than removing it from the list. Bug: crashpad:192 Change-Id: I72414b1f83d624c4ae323e09ecea8cfb69a68c5e Reviewed-on: https://chromium-review.googlesource.com/547135 Reviewed-by: Mark Mentovai <mark@chromium.org> Commit-Queue: Robert Sesek <rsesek@chromium.org>
113 lines
2.9 KiB
C++
113 lines
2.9 KiB
C++
// Copyright 2017 The Crashpad Authors. All rights reserved.
|
|
//
|
|
// 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 "client/annotation.h"
|
|
|
|
#include <string>
|
|
|
|
#include "client/annotation_list.h"
|
|
#include "client/crashpad_info.h"
|
|
#include "gtest/gtest.h"
|
|
|
|
namespace crashpad {
|
|
namespace test {
|
|
namespace {
|
|
|
|
class Annotation : public testing::Test {
|
|
public:
|
|
void SetUp() override {
|
|
CrashpadInfo::GetCrashpadInfo()->set_annotations_list(&annotations_);
|
|
}
|
|
|
|
void TearDown() override {
|
|
CrashpadInfo::GetCrashpadInfo()->set_annotations_list(nullptr);
|
|
}
|
|
|
|
size_t AnnotationsCount() {
|
|
size_t result = 0;
|
|
for (auto* annotation : annotations_) {
|
|
if (annotation->is_set())
|
|
++result;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
protected:
|
|
crashpad::AnnotationList annotations_;
|
|
};
|
|
|
|
TEST_F(Annotation, Basics) {
|
|
constexpr crashpad::Annotation::Type kType =
|
|
crashpad::Annotation::UserDefinedType(1);
|
|
|
|
const char kName[] = "annotation 1";
|
|
char buffer[1024];
|
|
crashpad::Annotation annotation(kType, kName, buffer);
|
|
|
|
EXPECT_FALSE(annotation.is_set());
|
|
EXPECT_EQ(0u, AnnotationsCount());
|
|
|
|
EXPECT_EQ(kType, annotation.type());
|
|
EXPECT_EQ(0u, annotation.size());
|
|
EXPECT_EQ(std::string(kName), annotation.name());
|
|
EXPECT_EQ(buffer, annotation.value());
|
|
|
|
annotation.SetSize(10);
|
|
|
|
EXPECT_TRUE(annotation.is_set());
|
|
EXPECT_EQ(1u, AnnotationsCount());
|
|
|
|
EXPECT_EQ(10u, annotation.size());
|
|
EXPECT_EQ(&annotation, *annotations_.begin());
|
|
|
|
annotation.Clear();
|
|
|
|
EXPECT_FALSE(annotation.is_set());
|
|
EXPECT_EQ(0u, AnnotationsCount());
|
|
|
|
EXPECT_EQ(0u, annotation.size());
|
|
}
|
|
|
|
TEST_F(Annotation, StringType) {
|
|
crashpad::StringAnnotation<5> annotation("name");
|
|
const char* value_ptr = static_cast<const char*>(annotation.value());
|
|
|
|
EXPECT_FALSE(annotation.is_set());
|
|
|
|
EXPECT_EQ(crashpad::Annotation::Type::kString, annotation.type());
|
|
EXPECT_EQ(0u, annotation.size());
|
|
EXPECT_EQ(std::string("name"), annotation.name());
|
|
EXPECT_EQ(0u, strlen(value_ptr));
|
|
|
|
annotation.Set("test");
|
|
|
|
EXPECT_TRUE(annotation.is_set());
|
|
EXPECT_EQ(1u, AnnotationsCount());
|
|
|
|
EXPECT_EQ(4u, annotation.size());
|
|
EXPECT_EQ(std::string("test"), value_ptr);
|
|
|
|
annotation.Set("loooooooooooong");
|
|
|
|
EXPECT_TRUE(annotation.is_set());
|
|
EXPECT_EQ(1u, AnnotationsCount());
|
|
|
|
EXPECT_EQ(5u, annotation.size());
|
|
EXPECT_EQ(std::string("loooo"), std::string(value_ptr, annotation.size()));
|
|
}
|
|
|
|
} // namespace
|
|
} // namespace test
|
|
} // namespace crashpad
|