chromium/base/i18n/streaming_utf8_validator_unittest.cc

// Copyright 2014 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.
//
// Note: U8_NEXT couldn't be rewritten using the spanification_tool, because it
// is a macro.
#pragma allow_unsafe_buffers
#endif

#include "base/i18n/streaming_utf8_validator.h"

#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>

#include <string>
#include <string_view>

#include "base/containers/span.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/memory/ref_counted.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversion_utils.h"
#include "base/synchronization/lock.h"
#include "base/task/thread_pool.h"
#include "base/test/task_environment.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/icu/source/common/unicode/utf8.h"

namespace base {
namespace {

// Avoid having to qualify the enum values in the tests.
const StreamingUtf8Validator::State VALID_ENDPOINT =;
const StreamingUtf8Validator::State VALID_MIDPOINT =;
const StreamingUtf8Validator::State INVALID =;

const uint32_t kThoroughTestChunkSize =;

class StreamingUtf8ValidatorThoroughTest : public ::testing::Test {};

// Enable locally to verify that this class accepts exactly the same set of
// 4-byte strings as ICU-based validation. This tests every possible 4-byte
// string, so it is too slow to run routinely on low-powered machines.
TEST_F(StreamingUtf8ValidatorThoroughTest, DISABLED_TestEverything) {}

// These valid and invalid UTF-8 sequences are based on the tests from
// base/strings/string_util_unittest.cc

// All of the strings in |valid| must represent a single codepoint, because
// partial sequences are constructed by taking non-empty prefixes of these
// strings.
const char* const valid[] =;

const char* const* const valid_end =;

const char* const invalid[] =;

const char* const* const invalid_end =;

// A ForwardIterator which returns all the non-empty prefixes of the elements of
// "valid".
class PartialIterator {};

// A test fixture for tests which test one UTF-8 sequence (or invalid
// byte sequence) at a time.
class StreamingUtf8ValidatorSingleSequenceTest : public ::testing::Test {};

// A test fixture for tests which test the concatenation of byte sequences.
class StreamingUtf8ValidatorDoubleSequenceTest : public ::testing::Test {};

TEST(StreamingUtf8ValidatorTest, NothingIsValid) {}

// Because the members of the |valid| array need to be non-zero length
// sequences and are measured with strlen(), |valid| cannot be used it
// to test the NUL character '\0', so the NUL character gets its own
// test.
TEST(StreamingUtf8ValidatorTest, NulIsValid) {}

// Just a basic sanity test before we start getting fancy.
TEST(StreamingUtf8ValidatorTest, HelloWorld) {}

// Check that the Reset() method works.
TEST(StreamingUtf8ValidatorTest, ResetWorks) {}

TEST_F(StreamingUtf8ValidatorSingleSequenceTest, Valid) {}

TEST_F(StreamingUtf8ValidatorSingleSequenceTest, Partial) {}

TEST_F(StreamingUtf8ValidatorSingleSequenceTest, Invalid) {}

TEST_F(StreamingUtf8ValidatorSingleSequenceTest, ValidByByte) {}

TEST_F(StreamingUtf8ValidatorSingleSequenceTest, PartialByByte) {}

TEST_F(StreamingUtf8ValidatorSingleSequenceTest, InvalidByByte) {}

TEST_F(StreamingUtf8ValidatorDoubleSequenceTest, ValidPlusValidIsValid) {}

TEST_F(StreamingUtf8ValidatorDoubleSequenceTest, ValidPlusPartialIsPartial) {}

TEST_F(StreamingUtf8ValidatorDoubleSequenceTest, PartialPlusValidIsInvalid) {}

TEST_F(StreamingUtf8ValidatorDoubleSequenceTest, PartialPlusPartialIsInvalid) {}

TEST_F(StreamingUtf8ValidatorDoubleSequenceTest, ValidPlusInvalidIsInvalid) {}

TEST_F(StreamingUtf8ValidatorDoubleSequenceTest, InvalidPlusValidIsInvalid) {}

TEST_F(StreamingUtf8ValidatorDoubleSequenceTest, InvalidPlusInvalidIsInvalid) {}

TEST_F(StreamingUtf8ValidatorDoubleSequenceTest, InvalidPlusPartialIsInvalid) {}

TEST_F(StreamingUtf8ValidatorDoubleSequenceTest, PartialPlusInvalidIsInvalid) {}

TEST(StreamingUtf8ValidatorValidateTest, EmptyIsValid) {}

TEST(StreamingUtf8ValidatorValidateTest, SimpleValidCase) {}

TEST(StreamingUtf8ValidatorValidateTest, SimpleInvalidCase) {}

TEST(StreamingUtf8ValidatorValidateTest, TruncatedIsInvalid) {}

}  // namespace
}  // namespace base