Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
pdfium_span_unittest.cpp
Go to the documentation of this file.
1// Copyright 2018 The PDFium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <vector>
6
7#include "core/fxcrt/unowned_ptr.h"
8#include "testing/gtest/include/gtest/gtest.h"
9#include "third_party/base/containers/span.h"
10
11// Tests PDFium-modifications to base::span. The name of this file is
12// chosen to avoid collisions with base's span_unittest.cc
13
15 int stuff[] = {1, 2, 3};
16 pdfium::span<int> null_span;
17 pdfium::span<int> stuff_span(stuff);
18 pdfium::span<int> empty_first_span = stuff_span.first(0);
19 pdfium::span<int> empty_last_span = stuff_span.last(0);
20 pdfium::span<int> empty_sub_span1 = stuff_span.subspan(0, 0);
21 pdfium::span<int> empty_sub_span2 = stuff_span.subspan(3, 0);
22 EXPECT_TRUE(null_span.empty());
23 EXPECT_TRUE(empty_first_span.empty());
24 EXPECT_TRUE(empty_last_span.empty());
25 EXPECT_TRUE(empty_sub_span1.empty());
26 EXPECT_TRUE(empty_sub_span2.empty());
27}
28
29// Custom implementation of first()/last().
31 int one[] = {1};
32 int stuff[] = {1, 2, 3};
33 pdfium::span<int> one_span(one);
34 pdfium::span<int> stuff_span(stuff);
35 EXPECT_EQ(one_span.front(), 1);
36 EXPECT_EQ(one_span.back(), 1);
37 EXPECT_EQ(stuff_span.front(), 1);
38 EXPECT_EQ(stuff_span.back(), 3);
39}
40
42 pdfium::span<int> empty_span;
43 EXPECT_DEATH(empty_span[0] += 1, "");
44}
45
47 pdfium::span<int> empty_span;
48 EXPECT_DEATH(empty_span.front() += 1, "");
49}
50
52 pdfium::span<int> empty_span;
53 EXPECT_DEATH(empty_span.back() += 1, "");
54}
55
56#if defined(UNOWNED_PTR_DANGLING_CHECKS)
57namespace {
58
59void CreateDanglingSpan() {
60 pdfium::span<int> data_span;
61 {
62 std::vector<int> data(4);
63 data_span = pdfium::make_span(data);
64 }
65}
66
67} // namespace
68
69TEST(PdfiumSpanDeathTest, DanglingReference) {
70 EXPECT_DEATH(CreateDanglingSpan(), "");
71}
72#endif // defined(UNOWNED_PTR_DANGLING_CHECKS)
TEST(FXCRYPT, MD5GenerateEmtpyData)