chromium/third_party/crashpad/crashpad/client/length_delimited_ring_buffer_test.cc

// Copyright 2023 The Crashpad Authors
//
// 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/length_delimited_ring_buffer.h"

#include <stdint.h>

#include <array>
#include <string>
#include <vector>

#include "gmock/gmock.h"
#include "gtest/gtest.h"

namespace crashpad {
namespace test {
namespace {

Eq;
IsFalse;
IsTrue;

// Buffer with magic 0xcab00d1e, version 1, read_pos 0, length 3, and 3 bytes of
// data (1 varint length, 2 bytes data)
constexpr char kValidBufferSize3[] =;
constexpr size_t kValidBufferSize3Len =;  // Remove trailing NUL.

// Buffer with magic 0xcab00d1e, version 8, read_pos 0, length 3, and 3 bytes of
// data (1 varint length, 2 bytes data).
constexpr char kInvalidVersionBuffer[] =;
constexpr size_t kInvalidVersionBufferLen =;  // Remove trailing NUL.

// Buffer representing process which crashed while in the middle of a Push()
// operation, with a previously-Push()ed buffer whose length was zeroed out at
// the start.
constexpr char kMidCrashBuffer[] =;
constexpr size_t kMidCrashBufferLen =;  // Remove trailing NUL.

constexpr uint8_t kHello[] =;

// Invalid buffer containing malformed varint in data payload (Base 128 varint
// with length 6, which would represent a data length > 32 bits).
constexpr char kInvalidBase128VarintBuffer[] =;
constexpr size_t kInvalidBase128VarintBufferLen =;  // Remove trailing NUL.

// Invalid buffer containing malformed varint in data payload (Base 128 varint
// with length 5 but bits 33 and 34 set, which would represent a data length >
// 32 bits).
constexpr char kInvalidBase128VarintBits33And34SetBuffer[] =;
constexpr size_t kInvalidBase128VarintBits33And34SetBufferLen =;  // Remove trailing NUL.

// Invalid buffer containing too-short data payload (varint length indicates
// payload length is 4 but payload only contains 3 bytes).
constexpr char kInvalidPayloadBufferTooShort[] =;
constexpr size_t kInvalidPayloadBufferTooShortLen =;  // Remove trailing NUL.

TEST(LengthDelimitedRingBufferTest,
     RingBufferDataShouldStartWithMagicAndVersion) {}

TEST(LengthDelimitedRingBufferTest,
     EmptyBufferSizeShouldIncludeHeaderInRingBufferLength) {}

TEST(LengthDelimitedRingBufferTest,
     NonEmptyBufferSizeShouldIncludeHeaderAndData) {}

TEST(LengthDelimitedRingBufferTest, PopOnEmptyBufferShouldFail) {}

TEST(LengthDelimitedRingBufferTest, PushZeroLengthShouldFail) {}

TEST(LengthDelimitedRingBufferTest, PushExactlyBufferSizeThenPopShouldSucceed) {}

TEST(LengthDelimitedRingBufferTest, PushLargerThanBufferSizeShouldFail) {}

TEST(LengthDelimitedRingBufferTest,
     PushUntilFullThenPopUntilEmptyShouldReturnInFIFOOrder) {}

TEST(LengthDelimitedRingBufferTest,
     PushThenPopBuffersOfDifferingLengthsShouldReturnBuffers) {}

TEST(LengthDelimitedRingBufferDataTest, PushOnFullBufferShouldOverwriteOldest) {}

TEST(LengthDelimitedRingBufferDataTest,
     PushOnFullBufferShouldOverwriteMultipleOldest) {}

TEST(LengthDelimitedRingBufferDataTest, PushThenPopWithLengthVarintTwoBytes) {}

TEST(LengthDelimitedRingBufferDataTest, DeserializeFromTooShortShouldFail) {}

TEST(LengthDelimitedRingBufferDataTest, DeserializeFromTooLongShouldFail) {}

TEST(LengthDelimitedRingBufferDataTest,
     DeserializeFromInvalidVersionShouldFail) {}

TEST(LengthDelimitedRingBufferDataTest,
     DeserializeFromInvalidVarintLengthShouldSucceedButPopShouldFail) {}

TEST(LengthDelimitedRingBufferDataTest,
     DeserializeFromInvalidVarintBitsShouldSucceedButPopShouldFail) {}

TEST(LengthDelimitedRingBufferDataTest,
     DeserializeFromInvalidPayloadBufferTooShortShouldSucceedButPopShouldFail) {}

TEST(LengthDelimitedRingBufferDataTest,
     DeserializeFromFullBufferShouldSucceed) {}

TEST(LengthDelimitedRingBufferDataTest,
     DeserializeFromMidCrashBufferShouldSucceedButSubsequentPopShouldFail) {}

}  // namespace
}  // namespace test
}  // namespace crashpad