chromium/base/values_unittest.cc

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40284755): Remove this and spanify to fix the errors.
#pragma allow_unsafe_buffers
#endif

#include "base/values.h"

#include <stddef.h>

#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <memory>
#include <string>
#include <string_view>
#include <type_traits>
#include <utility>
#include <vector>

#include "base/bits.h"
#include "base/containers/adapters.h"
#include "base/containers/contains.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/gtest_util.h"
#include "build/build_config.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

#if BUILDFLAG(ENABLE_BASE_TRACING)
#include <optional>

#include "third_party/perfetto/include/perfetto/test/traced_value_test_support.h"  // no-presubmit-check nogncheck
#endif  // BUILDFLAG(ENABLE_BASE_TRACING)

namespace base {

#ifdef NDEBUG
// `Value` should have a (relatively) small size to avoid creating excess
// overhead, e.g. for lists of values that are all ints.
//
// This test is limited to NDEBUG builds, since some containers may require
// extra storage for supporting debug checks for things like iterators.
TEST(ValuesTest, SizeOfValue) {
#if defined(__GLIBCXX__)
  // libstdc++ std::string takes already 4 machine words, so the absl::variant
  // takes 5
  constexpr size_t kExpectedSize = 5 * sizeof(void*);
#else   // !defined(__GLIBCXX__)
  // libc++'s std::string and std::vector both take 3 machine words. An
  // additional word is used by absl::variant for the type index.
  constexpr size_t kExpectedSize = 4 * sizeof(void*);
#endif  // defined(__GLIBCXX__)

  // Use std::integral_constant so the compiler error message includes the
  // evaluated size. In future versions of clang, it should be possible to
  // simplify this to an equality comparison (i.e. newer clangs print out
  // "comparison reduces to '(1 == 2)'").
  static_assert(std::is_same_v<std::integral_constant<size_t, sizeof(Value)>,
                               std::integral_constant<size_t, kExpectedSize>>,
                "base::Value has an unexpected size!");
}
#endif

TEST(ValuesTest, TestNothrow) {}

TEST(ValuesTest, EmptyValue) {}

// Group of tests for the value constructors.
TEST(ValuesTest, ConstructBool) {}

TEST(ValuesTest, ConstructFromPtrs) {}

TEST(ValuesTest, ConstructInt) {}

TEST(ValuesTest, ConstructDouble) {}

TEST(ValuesTest, ConstructStringFromConstCharPtr) {}

TEST(ValuesTest, ConstructStringFromStringPiece) {}

TEST(ValuesTest, ConstructStringFromStdStringRRef) {}

TEST(ValuesTest, ConstructStringFromConstChar16Ptr) {}

TEST(ValuesTest, ConstructStringFromStringPiece16) {}

TEST(ValuesTest, ConstructBinary) {}

TEST(ValuesTest, ConstructDict) {}

TEST(ValuesTest, ConstructDictFromValueDict) {}

TEST(ValuesTest, ConstructList) {}

TEST(ValuesTest, UseTestingEachOnValueList) {}

TEST(ValuesTest, ConstructListFromValueList) {}

TEST(ValuesTest, HardenTests) {}

// Group of tests for the copy constructors and copy-assigmnent. For equality
// checks comparisons of the interesting fields are done instead of relying on
// Equals being correct.
TEST(ValuesTest, CopyBool) {}

TEST(ValuesTest, CopyInt) {}

TEST(ValuesTest, CopyDouble) {}

TEST(ValuesTest, CopyString) {}

TEST(ValuesTest, CopyBinary) {}

TEST(ValuesTest, CopyDictionary) {}

TEST(ValuesTest, CopyList) {}

// Group of tests for the move constructors and move-assigmnent.
TEST(ValuesTest, MoveBool) {}

TEST(ValuesTest, MoveInt) {}

TEST(ValuesTest, MoveDouble) {}

TEST(ValuesTest, MoveString) {}

TEST(ValuesTest, MoveBinary) {}

TEST(ValuesTest, MoveConstructDictionary) {}

TEST(ValuesTest, MoveAssignDictionary) {}

TEST(ValuesTest, ConstructDictWithIterators) {}

TEST(ValuesTest, MoveList) {}

TEST(ValuesTest, Append) {}

TEST(ValuesTest, ListInsert) {}

TEST(ValuesTest, ListResize) {}

TEST(ValuesTest, ReverseIter) {}

// Test all three behaviors of EnsureDict() (Create a new dict where no
// matchining values exist, return an existing dict, create a dict overwriting
// a value of another type).
TEST(ValuesTest, DictEnsureDict) {}

// Test all three behaviors of EnsureList() (Create a new list where no
// matchining value exists, return an existing list, create a list overwriting
// a value of another type).
TEST(ValuesTest, DictEnsureList) {}

// TODO(dcheng): Add more tests directly exercising the updated dictionary and
// list APIs. For now, most of the updated APIs are tested indirectly via the
// legacy APIs that are largely backed by the updated APIs.
TEST(ValuesTest, DictFindByDottedPath) {}

TEST(ValuesTest, DictSetByDottedPath) {}

TEST(ValuesTest, RvalueDictSetByDottedPath) {}

TEST(ValuesTest, DictSetWithDottedKey) {}

TEST(ValuesTest, ListFront) {}

TEST(ValuesTest, ListFrontWhenEmpty) {}

TEST(ValuesTest, ListBack) {}

TEST(ValuesTest, ListBackWhenEmpty) {}

TEST(ValuesTest, ListErase) {}

TEST(ValuesTest, ListEraseRange) {}

TEST(ValuesTest, ListEraseValue) {}

TEST(ValuesTest, ListEraseIf) {}

TEST(ValuesTest, ClearList) {}

TEST(ValuesTest, FindKey) {}

TEST(ValuesTest, FindKeyChangeValue) {}

TEST(ValuesTest, FindKeyConst) {}

TEST(ValuesTest, FindBoolKey) {}

TEST(ValuesTest, FindIntKey) {}

TEST(ValuesTest, FindStringKey) {}

TEST(ValuesTest, MutableFindStringKey) {}

TEST(ValuesTest, FindDictKey) {}

TEST(ValuesTest, FindListKey) {}

TEST(ValuesTest, FindBlob) {}

TEST(ValuesTest, SetKey) {}

TEST(ValuesTest, SetBoolKey) {}

TEST(ValuesTest, SetIntKey) {}

TEST(ValuesTest, SetDoubleKey) {}

TEST(ValuesTest, SetStringKey) {}

TEST(ValuesTest, RvalueSet) {}

TEST(ValuesTest, FindPath) {}

TEST(ValuesTest, SetByDottedPath) {}

TEST(ValuesTest, SetBoolPath) {}

TEST(ValuesTest, SetIntPath) {}

TEST(ValuesTest, SetDoublePath) {}

TEST(ValuesTest, SetStringPath) {}

TEST(ValuesTest, Remove) {}

TEST(ValuesTest, Extract) {}

TEST(ValuesTest, RemoveByDottedPath) {}

TEST(ValuesTest, ExtractByDottedPath) {}

TEST(ValuesTest, Basic) {}

TEST(ValuesTest, List) {}

TEST(ValuesTest, RvalueAppend) {}

TEST(ValuesTest, ListWithCapacity) {}

TEST(ValuesTest, BinaryValue) {}

TEST(ValuesTest, StringValue) {}

TEST(ValuesTest, DictionaryDeletion) {}

TEST(ValuesTest, DictionarySetReturnsPointer) {}

TEST(ValuesTest, Clone) {}

TEST(ValuesTest, TakeString) {}

// Check that the value can still be used after `TakeString()` was called, as
// long as a new value was assigned to it.
TEST(ValuesTest, PopulateAfterTakeString) {}

TEST(ValuesTest, TakeDict) {}

// Check that the value can still be used after `TakeDict()` was called, as long
// as a new value was assigned to it.
TEST(ValuesTest, PopulateAfterTakeDict) {}

TEST(ValuesTest, TakeList) {}

// Check that the value can still be used after `TakeList()` was called, as long
// as a new value was assigned to it.
TEST(ValuesTest, PopulateAfterTakeList) {}

TEST(ValuesTest, SpecializedEquals) {}

// Test that a literal string comparison does not end up using the bool (!!)
// overload.
TEST(ValuesTest, LiteralStringEquals) {}

TEST(ValuesTest, Equals) {}

TEST(ValuesTest, Comparisons) {}

TEST(ValuesTest, Merge) {}

TEST(ValuesTest, DictionaryIterator) {}

TEST(ValuesTest, MutatingCopiedPairsInDictMutatesUnderlyingValues) {}

TEST(ValuesTest, StdDictionaryIterator) {}

TEST(ValuesTest, SelfSwap) {}

TEST(ValuesTest, FromToUniquePtrValue) {}

TEST(ValuesTest, MutableFindStringPath) {}

TEST(ValuesTest, MutableGetString) {}

#if BUILDFLAG(ENABLE_BASE_TRACING)
TEST(ValuesTest, TracingSupport) {}
#endif  // BUILDFLAG(ENABLE_BASE_TRACING)

TEST(ValueViewTest, BasicConstruction) {}

TEST(ValueViewTest, ValueConstruction) {}

TEST(ValueViewTest, ToValue) {}

}  // namespace base