Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/xpcom/tests/gtest/TestTArray2.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim:set ts=2 sw=2 sts=2 et cindent: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#include "mozilla/ArrayUtils.h"
8
#include "mozilla/Unused.h"
9
10
#include <stdlib.h>
11
#include <stdio.h>
12
#include <iostream>
13
#include "nsTArray.h"
14
#include "nsAutoPtr.h"
15
#include "nsString.h"
16
#include "nsDirectoryServiceDefs.h"
17
#include "nsDirectoryServiceUtils.h"
18
#include "nsComponentManagerUtils.h"
19
#include "nsXPCOM.h"
20
#include "nsIFile.h"
21
22
#include "gtest/gtest.h"
23
24
using namespace mozilla;
25
26
namespace TestTArray {
27
28
// Define this so we can use test_basic_array in test_comptr_array
29
template <class T>
30
0
inline bool operator<(const nsCOMPtr<T>& lhs, const nsCOMPtr<T>& rhs) {
31
0
  return lhs.get() < rhs.get();
32
0
}
33
34
//----
35
36
template <class ElementType>
37
static bool test_basic_array(ElementType *data,
38
                             size_t dataLen,
39
0
                             const ElementType& extra) {
40
0
  nsTArray<ElementType> ary;
41
0
  const nsTArray<ElementType>& cary = ary;
42
0
43
0
  ary.AppendElements(data, dataLen);
44
0
  if (ary.Length() != dataLen) {
45
0
    return false;
46
0
  }
47
0
  if (!(ary == ary)) {
48
0
    return false;
49
0
  }
50
0
  size_t i;
51
0
  for (i = 0; i < ary.Length(); ++i) {
52
0
    if (ary[i] != data[i])
53
0
      return false;
54
0
  }
55
0
  for (i = 0; i < ary.Length(); ++i) {
56
0
    if (ary.SafeElementAt(i, extra) != data[i])
57
0
      return false;
58
0
  }
59
0
  if (ary.SafeElementAt(ary.Length(), extra) != extra ||
60
0
      ary.SafeElementAt(ary.Length() * 10, extra) != extra)
61
0
    return false;
62
0
  // ensure sort results in ascending order
63
0
  ary.Sort();
64
0
  size_t j = 0, k = ary.IndexOfFirstElementGt(extra);
65
0
  if (k != 0 && ary[k-1] == extra)
66
0
    return false;
67
0
  for (i = 0; i < ary.Length(); ++i) {
68
0
    k = ary.IndexOfFirstElementGt(ary[i]);
69
0
    if (k == 0 || ary[k-1] != ary[i])
70
0
      return false;
71
0
    if (k < j)
72
0
      return false;
73
0
    j = k;
74
0
  }
75
0
  for (i = ary.Length(); --i; ) {
76
0
    if (ary[i] < ary[i - 1])
77
0
      return false;
78
0
    if (ary[i] == ary[i - 1])
79
0
      ary.RemoveElementAt(i);
80
0
  }
81
0
  if (!(ary == ary)) {
82
0
    return false;
83
0
  }
84
0
  for (i = 0; i < ary.Length(); ++i) {
85
0
    if (ary.BinaryIndexOf(ary[i]) != i)
86
0
      return false;
87
0
  }
88
0
  if (ary.BinaryIndexOf(extra) != ary.NoIndex)
89
0
    return false;
90
0
  size_t oldLen = ary.Length();
91
0
  ary.RemoveElement(data[dataLen / 2]);
92
0
  if (ary.Length() != (oldLen - 1))
93
0
    return false;
94
0
  if (!(ary == ary))
95
0
    return false;
96
0
97
0
  if (ary.ApplyIf(extra,
98
0
                  []() { return true; },
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<int>(int*, unsigned long, int const&)::{lambda()#1}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<long>(long*, unsigned long, long const&)::{lambda()#1}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<char>(char*, unsigned long, char const&)::{lambda()#1}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<unsigned int>(unsigned int*, unsigned long, unsigned int const&)::{lambda()#1}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsTString<char> >(nsTString<char>*, unsigned long, nsTString<char> const&)::{lambda()#1}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsCOMPtr<nsIFile> >(nsCOMPtr<nsIFile>*, unsigned long, nsCOMPtr<nsIFile> const&)::{lambda()#1}::operator()() const
99
0
                  []() { return false; }))
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<int>(int*, unsigned long, int const&)::{lambda()#2}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<long>(long*, unsigned long, long const&)::{lambda()#2}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<char>(char*, unsigned long, char const&)::{lambda()#2}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<unsigned int>(unsigned int*, unsigned long, unsigned int const&)::{lambda()#2}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsTString<char> >(nsTString<char>*, unsigned long, nsTString<char> const&)::{lambda()#2}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsCOMPtr<nsIFile> >(nsCOMPtr<nsIFile>*, unsigned long, nsCOMPtr<nsIFile> const&)::{lambda()#2}::operator()() const
100
0
    return false;
101
0
  if (ary.ApplyIf(extra,
102
0
                  [](size_t) { return true; },
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<int>(int*, unsigned long, int const&)::{lambda(unsigned long)#1}::operator()(unsigned long) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<long>(long*, unsigned long, long const&)::{lambda(unsigned long)#1}::operator()(unsigned long) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<char>(char*, unsigned long, char const&)::{lambda(unsigned long)#1}::operator()(unsigned long) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<unsigned int>(unsigned int*, unsigned long, unsigned int const&)::{lambda(unsigned long)#1}::operator()(unsigned long) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsTString<char> >(nsTString<char>*, unsigned long, nsTString<char> const&)::{lambda(unsigned long)#1}::operator()(unsigned long) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsCOMPtr<nsIFile> >(nsCOMPtr<nsIFile>*, unsigned long, nsCOMPtr<nsIFile> const&)::{lambda(unsigned long)#1}::operator()(unsigned long) const
103
0
                  []() { return false; }))
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<int>(int*, unsigned long, int const&)::{lambda()#3}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<long>(long*, unsigned long, long const&)::{lambda()#3}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<char>(char*, unsigned long, char const&)::{lambda()#3}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<unsigned int>(unsigned int*, unsigned long, unsigned int const&)::{lambda()#3}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsTString<char> >(nsTString<char>*, unsigned long, nsTString<char> const&)::{lambda()#3}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsCOMPtr<nsIFile> >(nsCOMPtr<nsIFile>*, unsigned long, nsCOMPtr<nsIFile> const&)::{lambda()#3}::operator()() const
104
0
    return false;
105
0
  // On a non-const array, ApplyIf's first lambda may use either const or non-
106
0
  // const element types.
107
0
  if (ary.ApplyIf(extra,
108
0
                  [](ElementType&) { return true; },
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<int>(int*, unsigned long, int const&)::{lambda(int&)#1}::operator()(int&) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<long>(long*, unsigned long, long const&)::{lambda(long&)#1}::operator()(long&) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<char>(char*, unsigned long, char const&)::{lambda(char&)#1}::operator()(char&) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<unsigned int>(unsigned int*, unsigned long, unsigned int const&)::{lambda(unsigned int&)#1}::operator()(unsigned int&) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsTString<char> >(nsTString<char>*, unsigned long, nsTString<char> const&)::{lambda(nsTString<char>&)#1}::operator()(nsTString<char>&) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsCOMPtr<nsIFile> >(nsCOMPtr<nsIFile>*, unsigned long, nsCOMPtr<nsIFile> const&)::{lambda(nsCOMPtr<nsIFile>&)#1}::operator()(nsCOMPtr<nsIFile>&) const
109
0
                  []() { return false; }))
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<int>(int*, unsigned long, int const&)::{lambda()#4}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<long>(long*, unsigned long, long const&)::{lambda()#4}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<char>(char*, unsigned long, char const&)::{lambda()#4}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<unsigned int>(unsigned int*, unsigned long, unsigned int const&)::{lambda()#4}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsTString<char> >(nsTString<char>*, unsigned long, nsTString<char> const&)::{lambda()#4}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsCOMPtr<nsIFile> >(nsCOMPtr<nsIFile>*, unsigned long, nsCOMPtr<nsIFile> const&)::{lambda()#4}::operator()() const
110
0
    return false;
111
0
  if (ary.ApplyIf(extra,
112
0
                  [](const ElementType&) { return true; },
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<int>(int*, unsigned long, int const&)::{lambda(int const&)#1}::operator()(int const&) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<long>(long*, unsigned long, long const&)::{lambda(long const&)#1}::operator()(long const&) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<char>(char*, unsigned long, char const&)::{lambda(char const&)#1}::operator()(char const&) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<unsigned int>(unsigned int*, unsigned long, unsigned int const&)::{lambda(unsigned int const&)#1}::operator()(unsigned int const&) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsTString<char> >(nsTString<char>*, unsigned long, nsTString<char> const&)::{lambda(nsTString<char> const&)#1}::operator()(nsTString<char> const&) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsCOMPtr<nsIFile> >(nsCOMPtr<nsIFile>*, unsigned long, nsCOMPtr<nsIFile> const&)::{lambda(nsCOMPtr<nsIFile> const&)#1}::operator()(nsCOMPtr<nsIFile> const&) const
113
0
                  []() { return false; }))
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<int>(int*, unsigned long, int const&)::{lambda()#5}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<long>(long*, unsigned long, long const&)::{lambda()#5}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<char>(char*, unsigned long, char const&)::{lambda()#5}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<unsigned int>(unsigned int*, unsigned long, unsigned int const&)::{lambda()#5}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsTString<char> >(nsTString<char>*, unsigned long, nsTString<char> const&)::{lambda()#5}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsCOMPtr<nsIFile> >(nsCOMPtr<nsIFile>*, unsigned long, nsCOMPtr<nsIFile> const&)::{lambda()#5}::operator()() const
114
0
    return false;
115
0
  if (ary.ApplyIf(extra,
116
0
                  [](size_t, ElementType&) { return true; },
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<int>(int*, unsigned long, int const&)::{lambda(unsigned long, int&)#1}::operator()(unsigned long, int&) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<long>(long*, unsigned long, long const&)::{lambda(unsigned long, long&)#1}::operator()(unsigned long, long&) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<char>(char*, unsigned long, char const&)::{lambda(unsigned long, char&)#1}::operator()(unsigned long, char&) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<unsigned int>(unsigned int*, unsigned long, unsigned int const&)::{lambda(unsigned long, unsigned int&)#1}::operator()(unsigned long, unsigned int&) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsTString<char> >(nsTString<char>*, unsigned long, nsTString<char> const&)::{lambda(unsigned long, nsTString<char>&)#1}::operator()(unsigned long, nsTString<char>&) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsCOMPtr<nsIFile> >(nsCOMPtr<nsIFile>*, unsigned long, nsCOMPtr<nsIFile> const&)::{lambda(unsigned long, nsCOMPtr<nsIFile>&)#1}::operator()(unsigned long, nsCOMPtr<nsIFile>&) const
117
0
                  []() { return false; }))
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<int>(int*, unsigned long, int const&)::{lambda()#6}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<long>(long*, unsigned long, long const&)::{lambda()#6}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<char>(char*, unsigned long, char const&)::{lambda()#6}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<unsigned int>(unsigned int*, unsigned long, unsigned int const&)::{lambda()#6}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsTString<char> >(nsTString<char>*, unsigned long, nsTString<char> const&)::{lambda()#6}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsCOMPtr<nsIFile> >(nsCOMPtr<nsIFile>*, unsigned long, nsCOMPtr<nsIFile> const&)::{lambda()#6}::operator()() const
118
0
    return false;
119
0
  if (ary.ApplyIf(extra,
120
0
                  [](size_t, const ElementType&) { return true; },
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<int>(int*, unsigned long, int const&)::{lambda(unsigned long, int const&)#1}::operator()(unsigned long, int const&) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<long>(long*, unsigned long, long const&)::{lambda(unsigned long, long const&)#1}::operator()(unsigned long, long const&) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<char>(char*, unsigned long, char const&)::{lambda(unsigned long, char const&)#1}::operator()(unsigned long, char const&) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<unsigned int>(unsigned int*, unsigned long, unsigned int const&)::{lambda(unsigned long, unsigned int const&)#1}::operator()(unsigned long, unsigned int const&) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsTString<char> >(nsTString<char>*, unsigned long, nsTString<char> const&)::{lambda(unsigned long, nsTString<char> const&)#1}::operator()(unsigned long, nsTString<char> const&) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsCOMPtr<nsIFile> >(nsCOMPtr<nsIFile>*, unsigned long, nsCOMPtr<nsIFile> const&)::{lambda(unsigned long, nsCOMPtr<nsIFile> const&)#1}::operator()(unsigned long, nsCOMPtr<nsIFile> const&) const
121
0
                  []() { return false; }))
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<int>(int*, unsigned long, int const&)::{lambda()#7}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<long>(long*, unsigned long, long const&)::{lambda()#7}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<char>(char*, unsigned long, char const&)::{lambda()#7}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<unsigned int>(unsigned int*, unsigned long, unsigned int const&)::{lambda()#7}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsTString<char> >(nsTString<char>*, unsigned long, nsTString<char> const&)::{lambda()#7}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsCOMPtr<nsIFile> >(nsCOMPtr<nsIFile>*, unsigned long, nsCOMPtr<nsIFile> const&)::{lambda()#7}::operator()() const
122
0
    return false;
123
0
124
0
  if (cary.ApplyIf(extra,
125
0
                   []() { return true; },
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<int>(int*, unsigned long, int const&)::{lambda()#8}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<long>(long*, unsigned long, long const&)::{lambda()#8}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<char>(char*, unsigned long, char const&)::{lambda()#8}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<unsigned int>(unsigned int*, unsigned long, unsigned int const&)::{lambda()#8}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsTString<char> >(nsTString<char>*, unsigned long, nsTString<char> const&)::{lambda()#8}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsCOMPtr<nsIFile> >(nsCOMPtr<nsIFile>*, unsigned long, nsCOMPtr<nsIFile> const&)::{lambda()#8}::operator()() const
126
0
                   []() { return false; }))
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<int>(int*, unsigned long, int const&)::{lambda()#9}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<long>(long*, unsigned long, long const&)::{lambda()#9}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<char>(char*, unsigned long, char const&)::{lambda()#9}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<unsigned int>(unsigned int*, unsigned long, unsigned int const&)::{lambda()#9}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsTString<char> >(nsTString<char>*, unsigned long, nsTString<char> const&)::{lambda()#9}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsCOMPtr<nsIFile> >(nsCOMPtr<nsIFile>*, unsigned long, nsCOMPtr<nsIFile> const&)::{lambda()#9}::operator()() const
127
0
  if (cary.ApplyIf(extra,
128
0
                   [](size_t) { return true; },
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<int>(int*, unsigned long, int const&)::{lambda(unsigned long)#2}::operator()(unsigned long) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<long>(long*, unsigned long, long const&)::{lambda(unsigned long)#2}::operator()(unsigned long) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<char>(char*, unsigned long, char const&)::{lambda(unsigned long)#2}::operator()(unsigned long) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<unsigned int>(unsigned int*, unsigned long, unsigned int const&)::{lambda(unsigned long)#2}::operator()(unsigned long) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsTString<char> >(nsTString<char>*, unsigned long, nsTString<char> const&)::{lambda(unsigned long)#2}::operator()(unsigned long) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsCOMPtr<nsIFile> >(nsCOMPtr<nsIFile>*, unsigned long, nsCOMPtr<nsIFile> const&)::{lambda(unsigned long)#2}::operator()(unsigned long) const
129
0
                   []() { return false; }))
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<int>(int*, unsigned long, int const&)::{lambda()#10}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<long>(long*, unsigned long, long const&)::{lambda()#10}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<char>(char*, unsigned long, char const&)::{lambda()#10}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<unsigned int>(unsigned int*, unsigned long, unsigned int const&)::{lambda()#10}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsTString<char> >(nsTString<char>*, unsigned long, nsTString<char> const&)::{lambda()#10}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsCOMPtr<nsIFile> >(nsCOMPtr<nsIFile>*, unsigned long, nsCOMPtr<nsIFile> const&)::{lambda()#10}::operator()() const
130
0
  // On a const array, ApplyIf's first lambda must only use const element types.
131
0
  if (cary.ApplyIf(extra,
132
0
                   [](const ElementType&) { return true; },
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<int>(int*, unsigned long, int const&)::{lambda(int const&)#2}::operator()(int const&) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<long>(long*, unsigned long, long const&)::{lambda(long const&)#2}::operator()(long const&) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<char>(char*, unsigned long, char const&)::{lambda(char const&)#2}::operator()(char const&) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<unsigned int>(unsigned int*, unsigned long, unsigned int const&)::{lambda(unsigned int const&)#2}::operator()(unsigned int const&) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsTString<char> >(nsTString<char>*, unsigned long, nsTString<char> const&)::{lambda(nsTString<char> const&)#2}::operator()(nsTString<char> const&) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsCOMPtr<nsIFile> >(nsCOMPtr<nsIFile>*, unsigned long, nsCOMPtr<nsIFile> const&)::{lambda(nsCOMPtr<nsIFile> const&)#2}::operator()(nsCOMPtr<nsIFile> const&) const
133
0
                   []() { return false; }))
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<int>(int*, unsigned long, int const&)::{lambda()#11}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<long>(long*, unsigned long, long const&)::{lambda()#11}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<char>(char*, unsigned long, char const&)::{lambda()#11}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<unsigned int>(unsigned int*, unsigned long, unsigned int const&)::{lambda()#11}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsTString<char> >(nsTString<char>*, unsigned long, nsTString<char> const&)::{lambda()#11}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsCOMPtr<nsIFile> >(nsCOMPtr<nsIFile>*, unsigned long, nsCOMPtr<nsIFile> const&)::{lambda()#11}::operator()() const
134
0
  if (cary.ApplyIf(extra,
135
0
                   [](size_t, const ElementType&) { return true; },
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<int>(int*, unsigned long, int const&)::{lambda(unsigned long, int const&)#2}::operator()(unsigned long, int const&) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<long>(long*, unsigned long, long const&)::{lambda(unsigned long, long const&)#2}::operator()(unsigned long, long const&) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<char>(char*, unsigned long, char const&)::{lambda(unsigned long, char const&)#2}::operator()(unsigned long, char const&) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<unsigned int>(unsigned int*, unsigned long, unsigned int const&)::{lambda(unsigned long, unsigned int const&)#2}::operator()(unsigned long, unsigned int const&) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsTString<char> >(nsTString<char>*, unsigned long, nsTString<char> const&)::{lambda(unsigned long, nsTString<char> const&)#2}::operator()(unsigned long, nsTString<char> const&) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsCOMPtr<nsIFile> >(nsCOMPtr<nsIFile>*, unsigned long, nsCOMPtr<nsIFile> const&)::{lambda(unsigned long, nsCOMPtr<nsIFile> const&)#2}::operator()(unsigned long, nsCOMPtr<nsIFile> const&) const
136
0
                   []() { return false; }))
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<int>(int*, unsigned long, int const&)::{lambda()#12}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<long>(long*, unsigned long, long const&)::{lambda()#12}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<char>(char*, unsigned long, char const&)::{lambda()#12}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<unsigned int>(unsigned int*, unsigned long, unsigned int const&)::{lambda()#12}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsTString<char> >(nsTString<char>*, unsigned long, nsTString<char> const&)::{lambda()#12}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsCOMPtr<nsIFile> >(nsCOMPtr<nsIFile>*, unsigned long, nsCOMPtr<nsIFile> const&)::{lambda()#12}::operator()() const
137
0
    return false;
138
0
139
0
  size_t index = ary.Length() / 2;
140
0
  if (!ary.InsertElementAt(index, extra))
141
0
    return false;
142
0
  if (!(ary == ary))
143
0
    return false;
144
0
  if (ary[index] != extra)
145
0
    return false;
146
0
  if (ary.IndexOf(extra) == ary.NoIndex)
147
0
    return false;
148
0
  if (ary.LastIndexOf(extra) == ary.NoIndex)
149
0
    return false;
150
0
  // ensure proper searching
151
0
  if (ary.IndexOf(extra) > ary.LastIndexOf(extra))
152
0
    return false;
153
0
  if (ary.IndexOf(extra, index) != ary.LastIndexOf(extra, index))
154
0
    return false;
155
0
  if (!ary.ApplyIf(extra,
156
0
                   [&](size_t i, const ElementType& e) {
157
0
                     return i == index && e == extra;
158
0
                   },
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<int>(int*, unsigned long, int const&)::{lambda(unsigned long, int const&)#3}::operator()(unsigned long, int const&) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<long>(long*, unsigned long, long const&)::{lambda(unsigned long, long const&)#3}::operator()(unsigned long, long const&) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<char>(char*, unsigned long, char const&)::{lambda(unsigned long, char const&)#3}::operator()(unsigned long, char const&) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<unsigned int>(unsigned int*, unsigned long, unsigned int const&)::{lambda(unsigned long, unsigned int const&)#3}::operator()(unsigned long, unsigned int const&) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsTString<char> >(nsTString<char>*, unsigned long, nsTString<char> const&)::{lambda(unsigned long, nsTString<char> const&)#3}::operator()(unsigned long, nsTString<char> const&) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsCOMPtr<nsIFile> >(nsCOMPtr<nsIFile>*, unsigned long, nsCOMPtr<nsIFile> const&)::{lambda(unsigned long, nsCOMPtr<nsIFile> const&)#3}::operator()(unsigned long, nsCOMPtr<nsIFile> const&) const
159
0
                   []() { return false; }))
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<int>(int*, unsigned long, int const&)::{lambda()#13}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<long>(long*, unsigned long, long const&)::{lambda()#13}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<char>(char*, unsigned long, char const&)::{lambda()#13}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<unsigned int>(unsigned int*, unsigned long, unsigned int const&)::{lambda()#13}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsTString<char> >(nsTString<char>*, unsigned long, nsTString<char> const&)::{lambda()#13}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsCOMPtr<nsIFile> >(nsCOMPtr<nsIFile>*, unsigned long, nsCOMPtr<nsIFile> const&)::{lambda()#13}::operator()() const
160
0
    return false;
161
0
  if (!cary.ApplyIf(extra,
162
0
                    [&](size_t i, const ElementType& e) {
163
0
                      return i == index && e == extra;
164
0
                    },
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<int>(int*, unsigned long, int const&)::{lambda(unsigned long, int const&)#4}::operator()(unsigned long, int const&) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<long>(long*, unsigned long, long const&)::{lambda(unsigned long, long const&)#4}::operator()(unsigned long, long const&) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<char>(char*, unsigned long, char const&)::{lambda(unsigned long, char const&)#4}::operator()(unsigned long, char const&) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<unsigned int>(unsigned int*, unsigned long, unsigned int const&)::{lambda(unsigned long, unsigned int const&)#4}::operator()(unsigned long, unsigned int const&) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsTString<char> >(nsTString<char>*, unsigned long, nsTString<char> const&)::{lambda(unsigned long, nsTString<char> const&)#4}::operator()(unsigned long, nsTString<char> const&) const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsCOMPtr<nsIFile> >(nsCOMPtr<nsIFile>*, unsigned long, nsCOMPtr<nsIFile> const&)::{lambda(unsigned long, nsCOMPtr<nsIFile> const&)#4}::operator()(unsigned long, nsCOMPtr<nsIFile> const&) const
165
0
                    []() { return false; }))
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<int>(int*, unsigned long, int const&)::{lambda()#14}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<long>(long*, unsigned long, long const&)::{lambda()#14}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<char>(char*, unsigned long, char const&)::{lambda()#14}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<unsigned int>(unsigned int*, unsigned long, unsigned int const&)::{lambda()#14}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsTString<char> >(nsTString<char>*, unsigned long, nsTString<char> const&)::{lambda()#14}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsCOMPtr<nsIFile> >(nsCOMPtr<nsIFile>*, unsigned long, nsCOMPtr<nsIFile> const&)::{lambda()#14}::operator()() const
166
0
    return false;
167
0
168
0
  nsTArray<ElementType> copy(ary);
169
0
  if (!(ary == copy))
170
0
    return false;
171
0
  for (i = 0; i < copy.Length(); ++i) {
172
0
    if (ary[i] != copy[i])
173
0
      return false;
174
0
  }
175
0
  if (!ary.AppendElements(copy))
176
0
    return false;
177
0
  size_t cap = ary.Capacity();
178
0
  ary.RemoveElementsAt(copy.Length(), copy.Length());
179
0
  ary.Compact();
180
0
  if (ary.Capacity() == cap)
181
0
    return false;
182
0
183
0
  ary.Clear();
184
0
  if (ary.IndexOf(extra) != ary.NoIndex)
185
0
    return false;
186
0
  if (ary.LastIndexOf(extra) != ary.NoIndex)
187
0
    return false;
188
0
  if (ary.ApplyIf(extra,
189
0
                  []() { return true; },
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<int>(int*, unsigned long, int const&)::{lambda()#15}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<long>(long*, unsigned long, long const&)::{lambda()#15}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<char>(char*, unsigned long, char const&)::{lambda()#15}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<unsigned int>(unsigned int*, unsigned long, unsigned int const&)::{lambda()#15}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsTString<char> >(nsTString<char>*, unsigned long, nsTString<char> const&)::{lambda()#15}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsCOMPtr<nsIFile> >(nsCOMPtr<nsIFile>*, unsigned long, nsCOMPtr<nsIFile> const&)::{lambda()#15}::operator()() const
190
0
                  []() { return false; }))
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<int>(int*, unsigned long, int const&)::{lambda()#16}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<long>(long*, unsigned long, long const&)::{lambda()#16}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<char>(char*, unsigned long, char const&)::{lambda()#16}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<unsigned int>(unsigned int*, unsigned long, unsigned int const&)::{lambda()#16}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsTString<char> >(nsTString<char>*, unsigned long, nsTString<char> const&)::{lambda()#16}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsCOMPtr<nsIFile> >(nsCOMPtr<nsIFile>*, unsigned long, nsCOMPtr<nsIFile> const&)::{lambda()#16}::operator()() const
191
0
    return false;
192
0
  if (cary.ApplyIf(extra,
193
0
                   []() { return true; },
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<int>(int*, unsigned long, int const&)::{lambda()#17}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<long>(long*, unsigned long, long const&)::{lambda()#17}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<char>(char*, unsigned long, char const&)::{lambda()#17}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<unsigned int>(unsigned int*, unsigned long, unsigned int const&)::{lambda()#17}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsTString<char> >(nsTString<char>*, unsigned long, nsTString<char> const&)::{lambda()#17}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsCOMPtr<nsIFile> >(nsCOMPtr<nsIFile>*, unsigned long, nsCOMPtr<nsIFile> const&)::{lambda()#17}::operator()() const
194
0
                   []() { return false; }))
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<int>(int*, unsigned long, int const&)::{lambda()#18}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<long>(long*, unsigned long, long const&)::{lambda()#18}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<char>(char*, unsigned long, char const&)::{lambda()#18}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<unsigned int>(unsigned int*, unsigned long, unsigned int const&)::{lambda()#18}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsTString<char> >(nsTString<char>*, unsigned long, nsTString<char> const&)::{lambda()#18}::operator()() const
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsCOMPtr<nsIFile> >(nsCOMPtr<nsIFile>*, unsigned long, nsCOMPtr<nsIFile> const&)::{lambda()#18}::operator()() const
195
0
    return false;
196
0
197
0
  ary.Clear();
198
0
  if (!ary.IsEmpty() || ary.Elements() == nullptr)
199
0
    return false;
200
0
  if (!(ary == nsTArray<ElementType>()))
201
0
    return false;
202
0
  if (ary == copy)
203
0
    return false;
204
0
  if (ary.SafeElementAt(0, extra) != extra ||
205
0
      ary.SafeElementAt(10, extra) != extra)
206
0
    return false;
207
0
208
0
  ary = copy;
209
0
  if (!(ary == copy))
210
0
    return false;
211
0
  for (i = 0; i < copy.Length(); ++i) {
212
0
    if (ary[i] != copy[i])
213
0
      return false;
214
0
  }
215
0
216
0
  if (!ary.InsertElementsAt(0, copy))
217
0
    return false;
218
0
  if (ary == copy)
219
0
    return false;
220
0
  ary.RemoveElementsAt(0, copy.Length());
221
0
  for (i = 0; i < copy.Length(); ++i) {
222
0
    if (ary[i] != copy[i])
223
0
      return false;
224
0
  }
225
0
226
0
  // These shouldn't crash!
227
0
  nsTArray<ElementType> empty;
228
0
  ary.AppendElements(reinterpret_cast<ElementType *>(0), 0);
229
0
  ary.AppendElements(empty);
230
0
231
0
  // See bug 324981
232
0
  ary.RemoveElement(extra);
233
0
  ary.RemoveElement(extra);
234
0
235
0
  return true;
236
0
}
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<int>(int*, unsigned long, int const&)
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<long>(long*, unsigned long, long const&)
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<char>(char*, unsigned long, char const&)
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<unsigned int>(unsigned int*, unsigned long, unsigned int const&)
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsTString<char> >(nsTString<char>*, unsigned long, nsTString<char> const&)
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::test_basic_array<nsCOMPtr<nsIFile> >(nsCOMPtr<nsIFile>*, unsigned long, nsCOMPtr<nsIFile> const&)
237
238
0
TEST(TArray, test_int_array) {
239
0
  int data[] = {4,6,8,2,4,1,5,7,3};
240
0
  ASSERT_TRUE(test_basic_array(data, ArrayLength(data), int(14)));
241
0
}
242
243
0
TEST(TArray, test_int64_array) {
244
0
  int64_t data[] = {4,6,8,2,4,1,5,7,3};
245
0
  ASSERT_TRUE(test_basic_array(data, ArrayLength(data), int64_t(14)));
246
0
}
247
248
0
TEST(TArray, test_char_array) {
249
0
  char data[] = {4,6,8,2,4,1,5,7,3};
250
0
  ASSERT_TRUE(test_basic_array(data, ArrayLength(data), char(14)));
251
0
}
252
253
0
TEST(TArray, test_uint32_array) {
254
0
  uint32_t data[] = {4,6,8,2,4,1,5,7,3};
255
0
  ASSERT_TRUE(test_basic_array(data, ArrayLength(data), uint32_t(14)));
256
0
}
257
258
//----
259
260
class Object {
261
  public:
262
0
    Object() : mNum(0) {
263
0
    }
264
0
    Object(const char *str, uint32_t num) : mStr(str), mNum(num) {
265
0
    }
266
0
    Object(const Object& other) : mStr(other.mStr), mNum(other.mNum) {
267
0
    }
268
0
    ~Object() {}
269
270
0
    Object& operator=(const Object& other) {
271
0
      mStr = other.mStr;
272
0
      mNum = other.mNum;
273
0
      return *this;
274
0
    }
275
276
0
    bool operator==(const Object& other) const {
277
0
      return mStr == other.mStr && mNum == other.mNum;
278
0
    }
279
280
0
    bool operator<(const Object& other) const {
281
0
      // sort based on mStr only
282
0
      return mStr.Compare(other.mStr.get()) < 0;
283
0
    }
284
285
0
    const char *Str() const { return mStr.get(); }
286
0
    uint32_t Num() const { return mNum; }
287
288
  private:
289
    nsCString mStr;
290
    uint32_t  mNum;
291
};
292
293
0
TEST(TArray, test_object_array) {
294
0
  nsTArray<Object> objArray;
295
0
  const char kdata[] = "hello world";
296
0
  size_t i;
297
0
  for (i = 0; i < ArrayLength(kdata); ++i) {
298
0
    char x[] = {kdata[i],'\0'};
299
0
    ASSERT_TRUE(objArray.AppendElement(Object(x, i)));
300
0
  }
301
0
  for (i = 0; i < ArrayLength(kdata); ++i) {
302
0
    ASSERT_EQ(objArray[i].Str()[0], kdata[i]);
303
0
    ASSERT_EQ(objArray[i].Num(), i);
304
0
  }
305
0
  objArray.Sort();
306
0
  const char ksorted[] = "\0 dehllloorw";
307
0
  for (i = 0; i < ArrayLength(kdata)-1; ++i) {
308
0
    ASSERT_EQ(objArray[i].Str()[0], ksorted[i]);
309
0
  }
310
0
}
311
312
class Countable {
313
  static int sCount;
314
315
  public:
316
    Countable()
317
0
    {
318
0
      sCount++;
319
0
    }
320
321
    Countable(const Countable& aOther)
322
0
    {
323
0
      sCount++;
324
0
    }
325
326
0
    static int Count() { return sCount; }
327
};
328
329
class Moveable {
330
  static int sCount;
331
332
  public:
333
    Moveable()
334
0
    {
335
0
      sCount++;
336
0
    }
337
338
    Moveable(const Moveable& aOther)
339
0
    {
340
0
      sCount++;
341
0
    }
342
343
    Moveable(Moveable&& aOther)
344
0
    {
345
0
      // Do not increment sCount
346
0
    }
347
348
0
    static int Count() { return sCount; }
349
};
350
351
/* static */ int Countable::sCount = 0;
352
/* static */ int Moveable::sCount = 0;
353
354
0
static nsTArray<int> returns_by_value() {
355
0
  nsTArray<int> result;
356
0
  return result;
357
0
}
358
359
0
TEST(TArray, test_return_by_value) {
360
0
  nsTArray<int> result = returns_by_value();
361
0
  ASSERT_TRUE(true); // This is just a compilation test.
362
0
}
363
364
0
TEST(TArray, test_move_array) {
365
0
  nsTArray<Countable> countableArray;
366
0
  uint32_t i;
367
0
  for (i = 0; i < 4; ++i) {
368
0
    ASSERT_TRUE(countableArray.AppendElement(Countable()));
369
0
  }
370
0
371
0
  ASSERT_EQ(Countable::Count(), 8);
372
0
373
0
  const nsTArray<Countable>& constRefCountableArray = countableArray;
374
0
375
0
  ASSERT_EQ(Countable::Count(), 8);
376
0
377
0
  nsTArray<Countable> copyCountableArray(constRefCountableArray);
378
0
379
0
  ASSERT_EQ(Countable::Count(), 12);
380
0
381
0
  nsTArray<Countable>&& moveRefCountableArray = std::move(countableArray);
382
0
  moveRefCountableArray.Length(); // Make compilers happy.
383
0
384
0
  ASSERT_EQ(Countable::Count(), 12);
385
0
386
0
  nsTArray<Countable> movedCountableArray(std::move(countableArray));
387
0
388
0
  ASSERT_EQ(Countable::Count(), 12);
389
0
390
0
  // Test ctor
391
0
  FallibleTArray<Countable> differentAllocatorCountableArray(std::move(copyCountableArray));
392
0
  // operator=
393
0
  copyCountableArray = std::move(differentAllocatorCountableArray);
394
0
  differentAllocatorCountableArray = std::move(copyCountableArray);
395
0
  // And the other ctor
396
0
  nsTArray<Countable> copyCountableArray2(std::move(differentAllocatorCountableArray));
397
0
  // with auto
398
0
  AutoTArray<Countable, 3> autoCountableArray(std::move(copyCountableArray2));
399
0
  // operator=
400
0
  copyCountableArray2 = std::move(autoCountableArray);
401
0
  // Mix with FallibleTArray
402
0
  FallibleTArray<Countable> differentAllocatorCountableArray2(std::move(copyCountableArray2));
403
0
  AutoTArray<Countable, 4> autoCountableArray2(std::move(differentAllocatorCountableArray2));
404
0
  differentAllocatorCountableArray2 = std::move(autoCountableArray2);
405
0
406
0
  ASSERT_EQ(Countable::Count(), 12);
407
0
408
0
  nsTArray<Moveable> moveableArray;
409
0
  for (i = 0; i < 4; ++i) {
410
0
    ASSERT_TRUE(moveableArray.AppendElement(Moveable()));
411
0
  }
412
0
413
0
  ASSERT_EQ(Moveable::Count(), 4);
414
0
415
0
  const nsTArray<Moveable>& constRefMoveableArray = moveableArray;
416
0
417
0
  ASSERT_EQ(Moveable::Count(), 4);
418
0
419
0
  nsTArray<Moveable> copyMoveableArray(constRefMoveableArray);
420
0
421
0
  ASSERT_EQ(Moveable::Count(), 8);
422
0
423
0
  nsTArray<Moveable>&& moveRefMoveableArray = std::move(moveableArray);
424
0
  moveRefMoveableArray.Length(); // Make compilers happy.
425
0
426
0
  ASSERT_EQ(Moveable::Count(), 8);
427
0
428
0
  nsTArray<Moveable> movedMoveableArray(std::move(moveableArray));
429
0
430
0
  ASSERT_EQ(Moveable::Count(), 8);
431
0
432
0
  // Test ctor
433
0
  FallibleTArray<Moveable> differentAllocatorMoveableArray(std::move(copyMoveableArray));
434
0
  // operator=
435
0
  copyMoveableArray = std::move(differentAllocatorMoveableArray);
436
0
  differentAllocatorMoveableArray = std::move(copyMoveableArray);
437
0
  // And the other ctor
438
0
  nsTArray<Moveable> copyMoveableArray2(std::move(differentAllocatorMoveableArray));
439
0
  // with auto
440
0
  AutoTArray<Moveable, 3> autoMoveableArray(std::move(copyMoveableArray2));
441
0
  // operator=
442
0
  copyMoveableArray2 = std::move(autoMoveableArray);
443
0
  // Mix with FallibleTArray
444
0
  FallibleTArray<Moveable> differentAllocatorMoveableArray2(std::move(copyMoveableArray2));
445
0
  AutoTArray<Moveable, 4> autoMoveableArray2(std::move(differentAllocatorMoveableArray2));
446
0
  differentAllocatorMoveableArray2 = std::move(autoMoveableArray2);
447
0
448
0
  ASSERT_EQ(Moveable::Count(), 8);
449
0
450
0
  AutoTArray<Moveable, 8> moveableAutoArray;
451
0
  for (uint32_t i = 0; i < 4; ++i) {
452
0
    ASSERT_TRUE(moveableAutoArray.AppendElement(Moveable()));
453
0
  }
454
0
455
0
  ASSERT_EQ(Moveable::Count(), 12);
456
0
457
0
  const AutoTArray<Moveable, 8>& constRefMoveableAutoArray = moveableAutoArray;
458
0
459
0
  ASSERT_EQ(Moveable::Count(), 12);
460
0
461
0
  AutoTArray<Moveable, 8> copyMoveableAutoArray(constRefMoveableAutoArray);
462
0
463
0
  ASSERT_EQ(Moveable::Count(), 16);
464
0
465
0
  AutoTArray<Moveable, 8> movedMoveableAutoArray(std::move(moveableAutoArray));
466
0
467
0
  ASSERT_EQ(Moveable::Count(), 16);
468
0
}
469
470
//----
471
472
0
TEST(TArray, test_string_array) {
473
0
  nsTArray<nsCString> strArray;
474
0
  const char kdata[] = "hello world";
475
0
  size_t i;
476
0
  for (i = 0; i < ArrayLength(kdata); ++i) {
477
0
    nsCString str;
478
0
    str.Assign(kdata[i]);
479
0
    ASSERT_TRUE(strArray.AppendElement(str));
480
0
  }
481
0
  for (i = 0; i < ArrayLength(kdata); ++i) {
482
0
    ASSERT_EQ(strArray[i].CharAt(0), kdata[i]);
483
0
  }
484
0
485
0
  const char kextra[] = "foo bar";
486
0
  size_t oldLen = strArray.Length();
487
0
  ASSERT_TRUE(strArray.AppendElement(kextra));
488
0
  strArray.RemoveElement(kextra);
489
0
  ASSERT_EQ(oldLen, strArray.Length());
490
0
491
0
  ASSERT_EQ(strArray.IndexOf("e"), size_t(1));
492
0
  ASSERT_TRUE(strArray.ApplyIf("e",
493
0
                               [](size_t i, nsCString& s) {
494
0
                                 return i == 1 && s == "e";
495
0
                               },
496
0
                               []() { return false; }));
497
0
498
0
  strArray.Sort();
499
0
  const char ksorted[] = "\0 dehllloorw";
500
0
  for (i = ArrayLength(kdata); i--; ) {
501
0
    ASSERT_EQ(strArray[i].CharAt(0), ksorted[i]);
502
0
    if (i > 0 && strArray[i] == strArray[i - 1])
503
0
      strArray.RemoveElementAt(i);
504
0
  }
505
0
  for (i = 0; i < strArray.Length(); ++i) {
506
0
    ASSERT_EQ(strArray.BinaryIndexOf(strArray[i]), i);
507
0
  }
508
0
  auto no_index = strArray.NoIndex; // Fixes gtest compilation error
509
0
  ASSERT_EQ(strArray.BinaryIndexOf(EmptyCString()), no_index);
510
0
511
0
  nsCString rawArray[MOZ_ARRAY_LENGTH(kdata) - 1];
512
0
  for (i = 0; i < ArrayLength(rawArray); ++i)
513
0
    rawArray[i].Assign(kdata + i);  // substrings of kdata
514
0
515
0
  ASSERT_TRUE(test_basic_array(rawArray, ArrayLength(rawArray),
516
0
                               nsCString("foopy")));
517
0
}
518
519
//----
520
521
typedef nsCOMPtr<nsIFile> FilePointer;
522
523
class nsFileNameComparator {
524
  public:
525
0
    bool Equals(const FilePointer &a, const char *b) const {
526
0
      nsAutoCString name;
527
0
      a->GetNativeLeafName(name);
528
0
      return name.Equals(b);
529
0
    }
530
};
531
532
0
TEST(TArray, test_comptr_array) {
533
0
  FilePointer tmpDir;
534
0
  NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(tmpDir));
535
0
  ASSERT_TRUE(tmpDir);
536
0
  const char *kNames[] = {
537
0
    "foo.txt", "bar.html", "baz.gif"
538
0
  };
539
0
  nsTArray<FilePointer> fileArray;
540
0
  size_t i;
541
0
  for (i = 0; i < ArrayLength(kNames); ++i) {
542
0
    FilePointer f;
543
0
    tmpDir->Clone(getter_AddRefs(f));
544
0
    ASSERT_TRUE(f);
545
0
    ASSERT_FALSE(NS_FAILED(f->AppendNative(nsDependentCString(kNames[i]))));
546
0
    fileArray.AppendElement(f);
547
0
  }
548
0
549
0
  ASSERT_EQ(fileArray.IndexOf(kNames[1], 0, nsFileNameComparator()), size_t(1));
550
0
  ASSERT_TRUE(fileArray.ApplyIf(kNames[1], 0, nsFileNameComparator(),
551
0
                                [](size_t i) { return i == 1; },
552
0
                                []() { return false; }));
553
0
554
0
  // It's unclear what 'operator<' means for nsCOMPtr, but whatever...
555
0
  ASSERT_TRUE(test_basic_array(fileArray.Elements(), fileArray.Length(),
556
0
                               tmpDir));
557
0
}
558
559
//----
560
561
class RefcountedObject {
562
  public:
563
0
    RefcountedObject() : rc(0) {}
564
0
    void AddRef() {
565
0
      ++rc;
566
0
    }
567
0
    void Release() {
568
0
      if (--rc == 0)
569
0
        delete this;
570
0
    }
571
0
    ~RefcountedObject() {}
572
  private:
573
    int32_t rc;
574
};
575
576
0
TEST(TArray, test_refptr_array) {
577
0
  nsTArray< RefPtr<RefcountedObject> > objArray;
578
0
579
0
  RefcountedObject *a = new RefcountedObject(); a->AddRef();
580
0
  RefcountedObject *b = new RefcountedObject(); b->AddRef();
581
0
  RefcountedObject *c = new RefcountedObject(); c->AddRef();
582
0
583
0
  objArray.AppendElement(a);
584
0
  objArray.AppendElement(b);
585
0
  objArray.AppendElement(c);
586
0
587
0
  ASSERT_EQ(objArray.IndexOf(b), size_t(1));
588
0
  ASSERT_TRUE(objArray.ApplyIf(b,
589
0
                               [&](size_t i, RefPtr<RefcountedObject>& r) {
590
0
                                 return i == 1 && r == b;
591
0
                               },
592
0
                               []() { return false; }));
593
0
594
0
  a->Release();
595
0
  b->Release();
596
0
  c->Release();
597
0
}
598
599
//----
600
601
0
TEST(TArray, test_ptrarray) {
602
0
  nsTArray<uint32_t*> ary;
603
0
  ASSERT_EQ(ary.SafeElementAt(0), nullptr);
604
0
  ASSERT_EQ(ary.SafeElementAt(1000), nullptr);
605
0
606
0
  uint32_t a = 10;
607
0
  ary.AppendElement(&a);
608
0
  ASSERT_EQ(*ary[0], a);
609
0
  ASSERT_EQ(*ary.SafeElementAt(0), a);
610
0
611
0
  nsTArray<const uint32_t*> cary;
612
0
  ASSERT_EQ(cary.SafeElementAt(0), nullptr);
613
0
  ASSERT_EQ(cary.SafeElementAt(1000), nullptr);
614
0
615
0
  const uint32_t b = 14;
616
0
  cary.AppendElement(&a);
617
0
  cary.AppendElement(&b);
618
0
  ASSERT_EQ(*cary[0], a);
619
0
  ASSERT_EQ(*cary[1], b);
620
0
  ASSERT_EQ(*cary.SafeElementAt(0), a);
621
0
  ASSERT_EQ(*cary.SafeElementAt(1), b);
622
0
}
623
624
//----
625
626
// This test relies too heavily on the existence of DebugGetHeader to be
627
// useful in non-debug builds.
628
#ifdef DEBUG
629
TEST(TArray, test_autoarray) {
630
  uint32_t data[] = {4,6,8,2,4,1,5,7,3};
631
  AutoTArray<uint32_t, MOZ_ARRAY_LENGTH(data)> array;
632
633
  void* hdr = array.DebugGetHeader();
634
  ASSERT_NE(hdr, nsTArray<uint32_t>().DebugGetHeader());
635
  ASSERT_NE(hdr, (AutoTArray<uint32_t, MOZ_ARRAY_LENGTH(data)>().DebugGetHeader()));
636
637
  array.AppendElement(1u);
638
  ASSERT_EQ(hdr, array.DebugGetHeader());
639
640
  array.RemoveElement(1u);
641
  array.AppendElements(data, ArrayLength(data));
642
  ASSERT_EQ(hdr, array.DebugGetHeader());
643
644
  array.AppendElement(2u);
645
  ASSERT_NE(hdr, array.DebugGetHeader());
646
647
  array.Clear();
648
  array.Compact();
649
  ASSERT_EQ(hdr, array.DebugGetHeader());
650
  array.AppendElements(data, ArrayLength(data));
651
  ASSERT_EQ(hdr, array.DebugGetHeader());
652
653
  nsTArray<uint32_t> array2;
654
  void* emptyHdr = array2.DebugGetHeader();
655
  array.SwapElements(array2);
656
  ASSERT_NE(emptyHdr, array.DebugGetHeader());
657
  ASSERT_NE(hdr, array2.DebugGetHeader());
658
  size_t i;
659
  for (i = 0; i < ArrayLength(data); ++i) {
660
    ASSERT_EQ(array2[i], data[i]);
661
  }
662
  ASSERT_TRUE(array.IsEmpty());
663
664
  array.Compact();
665
  array.AppendElements(data, ArrayLength(data));
666
  uint32_t data3[] = {5, 7, 11};
667
  AutoTArray<uint32_t, MOZ_ARRAY_LENGTH(data3)> array3;
668
  array3.AppendElements(data3, ArrayLength(data3));
669
  array.SwapElements(array3);
670
  for (i = 0; i < ArrayLength(data); ++i) {
671
    ASSERT_EQ(array3[i], data[i]);
672
  }
673
  for (i = 0; i < ArrayLength(data3); ++i) {
674
    ASSERT_EQ(array[i], data3[i]);
675
  }
676
}
677
#endif
678
679
//----
680
681
// IndexOf used to potentially scan beyond the end of the array.  Test for
682
// this incorrect behavior by adding a value (5), removing it, then seeing
683
// if IndexOf finds it.
684
0
TEST(TArray, test_indexof) {
685
0
  nsTArray<int> array;
686
0
  array.AppendElement(0);
687
0
  // add and remove the 5
688
0
  array.AppendElement(5);
689
0
  array.RemoveElementAt(1);
690
0
  // we should not find the 5!
691
0
  auto no_index = array.NoIndex; // Fixes gtest compilation error.
692
0
  ASSERT_EQ(array.IndexOf(5, 1), no_index);
693
0
  ASSERT_FALSE(array.ApplyIf(5, 1,
694
0
                             []() { return true; },
695
0
                             []() { return false; }));
696
0
}
697
698
//----
699
700
template <class Array>
701
static bool is_heap(const Array& ary, size_t len) {
702
  size_t index = 1;
703
  while (index < len) {
704
    if (ary[index] > ary[(index - 1) >> 1])
705
      return false;
706
    index++;
707
  }
708
  return true;
709
}
710
711
//----
712
713
// An array |arr| is using its auto buffer if |&arr < arr.Elements()| and
714
// |arr.Elements() - &arr| is small.
715
716
#define IS_USING_AUTO(arr) \
717
  ((uintptr_t) &(arr) < (uintptr_t) arr.Elements() && \
718
   ((ptrdiff_t)arr.Elements() - (ptrdiff_t)&arr) <= 16)
719
720
#define CHECK_IS_USING_AUTO(arr) \
721
0
  do {                                                    \
722
0
    ASSERT_TRUE(IS_USING_AUTO(arr));                      \
723
0
  } while(0)
724
725
#define CHECK_NOT_USING_AUTO(arr) \
726
0
  do {                                                    \
727
0
    ASSERT_FALSE(IS_USING_AUTO(arr));                     \
728
0
  } while(0)
729
730
#define CHECK_USES_SHARED_EMPTY_HDR(arr) \
731
0
  do {                                                    \
732
0
    nsTArray<int> _empty;                                 \
733
0
    ASSERT_EQ(_empty.Elements(), arr.Elements());         \
734
0
  } while(0)
735
736
#define CHECK_EQ_INT(actual, expected) \
737
0
  do {                                                                       \
738
0
    ASSERT_EQ((actual), (expected));                                         \
739
0
  } while(0)
740
741
#define CHECK_ARRAY(arr, data) \
742
0
  do {                                                          \
743
0
    CHECK_EQ_INT((arr).Length(), (size_t)ArrayLength(data));  \
744
0
    for (size_t _i = 0; _i < ArrayLength(data); _i++) {       \
745
0
      CHECK_EQ_INT((arr)[_i], (data)[_i]);                      \
746
0
    }                                                           \
747
0
  } while(0)
748
749
0
TEST(TArray, test_swap) {
750
0
  // Test nsTArray::SwapElements.  Unfortunately there are many cases.
751
0
  int data1[] = {8, 6, 7, 5};
752
0
  int data2[] = {3, 0, 9};
753
0
754
0
  // Swap two auto arrays.
755
0
  {
756
0
    AutoTArray<int, 8> a;
757
0
    AutoTArray<int, 6> b;
758
0
759
0
    a.AppendElements(data1, ArrayLength(data1));
760
0
    b.AppendElements(data2, ArrayLength(data2));
761
0
    CHECK_IS_USING_AUTO(a);
762
0
    CHECK_IS_USING_AUTO(b);
763
0
764
0
    a.SwapElements(b);
765
0
766
0
    CHECK_IS_USING_AUTO(a);
767
0
    CHECK_IS_USING_AUTO(b);
768
0
    CHECK_ARRAY(a, data2);
769
0
    CHECK_ARRAY(b, data1);
770
0
  }
771
0
772
0
  // Swap two auto arrays -- one whose data lives on the heap, the other whose
773
0
  // data lives on the stack -- which each fits into the other's auto storage.
774
0
  {
775
0
    AutoTArray<int, 3> a;
776
0
    AutoTArray<int, 3> b;
777
0
778
0
    a.AppendElements(data1, ArrayLength(data1));
779
0
    a.RemoveElementAt(3);
780
0
    b.AppendElements(data2, ArrayLength(data2));
781
0
782
0
    // Here and elsewhere, we assert that if we start with an auto array
783
0
    // capable of storing N elements, we store N+1 elements into the array, and
784
0
    // then we remove one element, that array is still not using its auto
785
0
    // buffer.
786
0
    //
787
0
    // This isn't at all required by the TArray API. It would be fine if, when
788
0
    // we shrink back to N elements, the TArray frees its heap storage and goes
789
0
    // back to using its stack storage.  But we assert here as a check that the
790
0
    // test does what we expect.  If the TArray implementation changes, just
791
0
    // change the failing assertions.
792
0
    CHECK_NOT_USING_AUTO(a);
793
0
794
0
    // This check had better not change, though.
795
0
    CHECK_IS_USING_AUTO(b);
796
0
797
0
    a.SwapElements(b);
798
0
799
0
    CHECK_IS_USING_AUTO(b);
800
0
    CHECK_ARRAY(a, data2);
801
0
    int expectedB[] = {8, 6, 7};
802
0
    CHECK_ARRAY(b, expectedB);
803
0
  }
804
0
805
0
  // Swap two auto arrays which are using heap storage such that one fits into
806
0
  // the other's auto storage, but the other needs to stay on the heap.
807
0
  {
808
0
    AutoTArray<int, 3> a;
809
0
    AutoTArray<int, 2> b;
810
0
    a.AppendElements(data1, ArrayLength(data1));
811
0
    a.RemoveElementAt(3);
812
0
813
0
    b.AppendElements(data2, ArrayLength(data2));
814
0
    b.RemoveElementAt(2);
815
0
816
0
    CHECK_NOT_USING_AUTO(a);
817
0
    CHECK_NOT_USING_AUTO(b);
818
0
819
0
    a.SwapElements(b);
820
0
821
0
    CHECK_NOT_USING_AUTO(b);
822
0
823
0
    int expected1[] = {3, 0};
824
0
    int expected2[] = {8, 6, 7};
825
0
826
0
    CHECK_ARRAY(a, expected1);
827
0
    CHECK_ARRAY(b, expected2);
828
0
  }
829
0
830
0
  // Swap two arrays, neither of which fits into the other's auto-storage.
831
0
  {
832
0
    AutoTArray<int, 1> a;
833
0
    AutoTArray<int, 3> b;
834
0
835
0
    a.AppendElements(data1, ArrayLength(data1));
836
0
    b.AppendElements(data2, ArrayLength(data2));
837
0
838
0
    a.SwapElements(b);
839
0
840
0
    CHECK_ARRAY(a, data2);
841
0
    CHECK_ARRAY(b, data1);
842
0
  }
843
0
844
0
  // Swap an empty nsTArray with a non-empty AutoTArray.
845
0
  {
846
0
    nsTArray<int> a;
847
0
    AutoTArray<int, 3> b;
848
0
849
0
    b.AppendElements(data2, ArrayLength(data2));
850
0
    CHECK_IS_USING_AUTO(b);
851
0
852
0
    a.SwapElements(b);
853
0
854
0
    CHECK_ARRAY(a, data2);
855
0
    CHECK_EQ_INT(b.Length(), size_t(0));
856
0
    CHECK_IS_USING_AUTO(b);
857
0
  }
858
0
859
0
  // Swap two big auto arrays.
860
0
  {
861
0
    const unsigned size = 8192;
862
0
    AutoTArray<unsigned, size> a;
863
0
    AutoTArray<unsigned, size> b;
864
0
865
0
    for (unsigned i = 0; i < size; i++) {
866
0
      a.AppendElement(i);
867
0
      b.AppendElement(i + 1);
868
0
    }
869
0
870
0
    CHECK_IS_USING_AUTO(a);
871
0
    CHECK_IS_USING_AUTO(b);
872
0
873
0
    a.SwapElements(b);
874
0
875
0
    CHECK_IS_USING_AUTO(a);
876
0
    CHECK_IS_USING_AUTO(b);
877
0
878
0
    CHECK_EQ_INT(a.Length(), size_t(size));
879
0
    CHECK_EQ_INT(b.Length(), size_t(size));
880
0
881
0
    for (unsigned i = 0; i < size; i++) {
882
0
      CHECK_EQ_INT(a[i], i + 1);
883
0
      CHECK_EQ_INT(b[i], i);
884
0
    }
885
0
  }
886
0
887
0
  // Swap two arrays and make sure that their capacities don't increase
888
0
  // unnecessarily.
889
0
  {
890
0
    nsTArray<int> a;
891
0
    nsTArray<int> b;
892
0
    b.AppendElements(data2, ArrayLength(data2));
893
0
894
0
    CHECK_EQ_INT(a.Capacity(), size_t(0));
895
0
    size_t bCapacity = b.Capacity();
896
0
897
0
    a.SwapElements(b);
898
0
899
0
    // Make sure that we didn't increase the capacity of either array.
900
0
    CHECK_ARRAY(a, data2);
901
0
    CHECK_EQ_INT(b.Length(), size_t(0));
902
0
    CHECK_EQ_INT(b.Capacity(), size_t(0));
903
0
    CHECK_EQ_INT(a.Capacity(), bCapacity);
904
0
  }
905
0
906
0
  // Swap an auto array with a TArray, then clear the auto array and make sure
907
0
  // it doesn't forget the fact that it has an auto buffer.
908
0
  {
909
0
    nsTArray<int> a;
910
0
    AutoTArray<int, 3> b;
911
0
912
0
    a.AppendElements(data1, ArrayLength(data1));
913
0
914
0
    a.SwapElements(b);
915
0
916
0
    CHECK_EQ_INT(a.Length(), size_t(0));
917
0
    CHECK_ARRAY(b, data1);
918
0
919
0
    b.Clear();
920
0
921
0
    CHECK_USES_SHARED_EMPTY_HDR(a);
922
0
    CHECK_IS_USING_AUTO(b);
923
0
  }
924
0
925
0
  // Same thing as the previous test, but with more auto arrays.
926
0
  {
927
0
    AutoTArray<int, 16> a;
928
0
    AutoTArray<int, 3> b;
929
0
930
0
    a.AppendElements(data1, ArrayLength(data1));
931
0
932
0
    a.SwapElements(b);
933
0
934
0
    CHECK_EQ_INT(a.Length(), size_t(0));
935
0
    CHECK_ARRAY(b, data1);
936
0
937
0
    b.Clear();
938
0
939
0
    CHECK_IS_USING_AUTO(a);
940
0
    CHECK_IS_USING_AUTO(b);
941
0
  }
942
0
943
0
  // Swap an empty nsTArray and an empty AutoTArray.
944
0
  {
945
0
    AutoTArray<int, 8> a;
946
0
    nsTArray<int> b;
947
0
948
0
    a.SwapElements(b);
949
0
950
0
    CHECK_IS_USING_AUTO(a);
951
0
    CHECK_NOT_USING_AUTO(b);
952
0
    CHECK_EQ_INT(a.Length(), size_t(0));
953
0
    CHECK_EQ_INT(b.Length(), size_t(0));
954
0
  }
955
0
956
0
  // Swap empty auto array with non-empty AutoTArray using malloc'ed storage.
957
0
  // I promise, all these tests have a point.
958
0
  {
959
0
    AutoTArray<int, 2> a;
960
0
    AutoTArray<int, 1> b;
961
0
962
0
    a.AppendElements(data1, ArrayLength(data1));
963
0
964
0
    a.SwapElements(b);
965
0
966
0
    CHECK_IS_USING_AUTO(a);
967
0
    CHECK_NOT_USING_AUTO(b);
968
0
    CHECK_ARRAY(b, data1);
969
0
    CHECK_EQ_INT(a.Length(), size_t(0));
970
0
  }
971
0
}
972
973
// Bug 1171296: Disabled on andoid due to crashes.
974
#if !defined(ANDROID)
975
TEST(TArray, test_fallible)
976
0
{
977
0
  // Test that FallibleTArray works properly; that is, it never OOMs, but
978
0
  // instead eventually returns false.
979
0
  //
980
0
  // This test is only meaningful on 32-bit systems.  On a 64-bit system, we
981
0
  // might never OOM.
982
0
  if (sizeof(void*) > 4) {
983
0
    ASSERT_TRUE(true);
984
0
    return;
985
0
  }
986
0
987
0
  // Allocate a bunch of 128MB arrays.  Larger allocations will fail on some
988
0
  // platforms without actually hitting OOM.
989
0
  //
990
0
  // 36 * 128MB > 4GB, so we should definitely OOM by the 36th array.
991
0
  const unsigned numArrays = 36;
992
0
  FallibleTArray<char> arrays[numArrays];
993
0
  bool oomed = false;
994
0
  for (size_t i = 0; i < numArrays; i++) {
995
0
    // SetCapacity allocates the requested capacity + a header, and we want to
996
0
    // avoid allocating more than 128MB overall because of the size padding it
997
0
    // will cause, which depends on allocator behavior, so use 128MB - an
998
0
    // arbitrary size larger than the array header, so that chances are good
999
0
    // that allocations will always be 128MB.
1000
0
    bool success = arrays[i].SetCapacity(128 * 1024 * 1024 - 1024, fallible);
1001
0
    if (!success) {
1002
0
      // We got our OOM.  Check that it didn't come too early.
1003
0
      oomed = true;
1004
#ifdef XP_WIN
1005
      // 32-bit Windows sometimes OOMs on the 7th, sometimes on the 8th.  To
1006
      // keep the test green, choose the lower of those: the important thing
1007
      // here is that some allocations fail and some succeed.  We're not too
1008
      // concerned about how many iterations it takes.
1009
      const size_t kOOMIterations = 7;
1010
#else
1011
      const size_t kOOMIterations = 8;
1012
0
#endif
1013
0
      ASSERT_GE(i, kOOMIterations) << "Got OOM on iteration " << i << ". Too early!";
1014
0
    }
1015
0
  }
1016
0
1017
0
  ASSERT_TRUE(oomed) << "Didn't OOM or crash?  nsTArray::SetCapacity"
1018
0
                        "must be lying.";
1019
0
}
1020
#endif
1021
1022
0
TEST(TArray, test_conversion_operator) {
1023
0
  FallibleTArray<int> f;
1024
0
  const FallibleTArray<int> fconst;
1025
0
1026
0
  InfallibleTArray<int> i;
1027
0
  const InfallibleTArray<int> iconst;
1028
0
1029
0
  nsTArray<int> t;
1030
0
  const nsTArray<int> tconst;
1031
0
  AutoTArray<int, 8> tauto;
1032
0
  const AutoTArray<int, 8> tautoconst;
1033
0
1034
0
#define CHECK_ARRAY_CAST(type)                        \
1035
0
  do {                                                \
1036
0
    const type<int>& z1 = f;                          \
1037
0
    ASSERT_EQ((void*)&z1, (void*)&f);                 \
1038
0
    const type<int>& z2 = fconst;                     \
1039
0
    ASSERT_EQ((void*)&z2, (void*)&fconst);            \
1040
0
    const type<int>& z5 = i;                          \
1041
0
    ASSERT_EQ((void*)&z5, (void*)&i);                 \
1042
0
    const type<int>& z6 = iconst;                     \
1043
0
    ASSERT_EQ((void*)&z6, (void*)&iconst);            \
1044
0
    const type<int>& z9 = t;                          \
1045
0
    ASSERT_EQ((void*)&z9, (void*)&t);                 \
1046
0
    const type<int>& z10 = tconst;                    \
1047
0
    ASSERT_EQ((void*)&z10, (void*)&tconst);           \
1048
0
    const type<int>& z11 = tauto;                     \
1049
0
    ASSERT_EQ((void*)&z11, (void*)&tauto);            \
1050
0
    const type<int>& z12 = tautoconst;                \
1051
0
    ASSERT_EQ((void*)&z12, (void*)&tautoconst);       \
1052
0
  } while (0)
1053
0
1054
0
  CHECK_ARRAY_CAST(FallibleTArray);
1055
0
  CHECK_ARRAY_CAST(InfallibleTArray);
1056
0
  CHECK_ARRAY_CAST(nsTArray);
1057
0
1058
0
#undef CHECK_ARRAY_CAST
1059
0
}
1060
1061
template<class T>
1062
struct BufAccessor : public T
1063
{
1064
0
  void* GetHdr() { return T::mHdr; }
Unexecuted instantiation: TestTArray::BufAccessor<FallibleTArray<int> >::GetHdr()
Unexecuted instantiation: TestTArray::BufAccessor<nsTArray<int> >::GetHdr()
Unexecuted instantiation: TestTArray::BufAccessor<AutoTArray<int, 1050ul> >::GetHdr()
1065
};
1066
1067
0
TEST(TArray, test_SetLengthAndRetainStorage_no_ctor) {
1068
0
  // 1050 because sizeof(int)*1050 is more than a page typically.
1069
0
  const int N = 1050;
1070
0
  FallibleTArray<int> f;
1071
0
1072
0
  InfallibleTArray<int> i;
1073
0
1074
0
  nsTArray<int> t;
1075
0
  AutoTArray<int, N> tauto;
1076
0
1077
0
#define LPAREN (
1078
0
#define RPAREN )
1079
0
#define FOR_EACH(pre, post)                                    \
1080
0
  do {                                                         \
1081
0
    pre f post;                                                \
1082
0
    pre i post;                                                \
1083
0
    pre t post;                                                \
1084
0
    pre tauto post;                                            \
1085
0
  } while (0)
1086
0
1087
0
  // Setup test arrays.
1088
0
  FOR_EACH(; Unused << , .SetLength(N, fallible));
1089
0
  for (int n = 0; n < N; ++n) {
1090
0
    FOR_EACH(;, [n] = n);
1091
0
  }
1092
0
1093
0
  void* initial_Hdrs[] = {
1094
0
    static_cast<BufAccessor<FallibleTArray<int> >&>(f).GetHdr(),
1095
0
    static_cast<BufAccessor<InfallibleTArray<int> >&>(i).GetHdr(),
1096
0
    static_cast<BufAccessor<nsTArray<int> >&>(t).GetHdr(),
1097
0
    static_cast<BufAccessor<AutoTArray<int, N> >&>(tauto).GetHdr(),
1098
0
    nullptr
1099
0
  };
1100
0
1101
0
  // SetLengthAndRetainStorage(n), should NOT overwrite memory when T hasn't
1102
0
  // a default constructor.
1103
0
  FOR_EACH(;, .SetLengthAndRetainStorage(8));
1104
0
  FOR_EACH(;, .SetLengthAndRetainStorage(12));
1105
0
  for (int n = 0; n < 12; ++n) {
1106
0
    ASSERT_EQ(f[n], n);
1107
0
    ASSERT_EQ(i[n], n);
1108
0
    ASSERT_EQ(t[n], n);
1109
0
    ASSERT_EQ(tauto[n], n);
1110
0
  }
1111
0
  FOR_EACH(;, .SetLengthAndRetainStorage(0));
1112
0
  FOR_EACH(;, .SetLengthAndRetainStorage(N));
1113
0
  for (int n = 0; n < N; ++n) {
1114
0
    ASSERT_EQ(f[n], n);
1115
0
    ASSERT_EQ(i[n], n);
1116
0
    ASSERT_EQ(t[n], n);
1117
0
    ASSERT_EQ(tauto[n], n);
1118
0
  }
1119
0
1120
0
  void* current_Hdrs[] = {
1121
0
    static_cast<BufAccessor<FallibleTArray<int> >&>(f).GetHdr(),
1122
0
    static_cast<BufAccessor<InfallibleTArray<int> >&>(i).GetHdr(),
1123
0
    static_cast<BufAccessor<nsTArray<int> >&>(t).GetHdr(),
1124
0
    static_cast<BufAccessor<AutoTArray<int, N> >&>(tauto).GetHdr(),
1125
0
    nullptr
1126
0
  };
1127
0
1128
0
  // SetLengthAndRetainStorage(n) should NOT have reallocated the internal
1129
0
  // memory.
1130
0
  ASSERT_EQ(sizeof(initial_Hdrs), sizeof(current_Hdrs));
1131
0
  for (size_t n = 0; n < sizeof(current_Hdrs) / sizeof(current_Hdrs[0]); ++n) {
1132
0
    ASSERT_EQ(current_Hdrs[n], initial_Hdrs[n]);
1133
0
  }
1134
0
1135
0
1136
0
#undef FOR_EACH
1137
0
#undef LPAREN
1138
0
#undef RPAREN
1139
0
}
1140
1141
template <typename Comparator>
1142
bool
1143
TestCompareMethods(const Comparator& aComp)
1144
0
{
1145
0
  nsTArray<int> ary({57, 4, 16, 17, 3, 5, 96, 12});
1146
0
1147
0
  ary.Sort(aComp);
1148
0
1149
0
  const int sorted[] = {3, 4, 5, 12, 16, 17, 57, 96 };
1150
0
  for (size_t i = 0; i < MOZ_ARRAY_LENGTH(sorted); i++) {
1151
0
    if (sorted[i] != ary[i]) {
1152
0
      return false;
1153
0
    }
1154
0
  }
1155
0
1156
0
  if (!ary.ContainsSorted(5, aComp)) {
1157
0
    return false;
1158
0
  }
1159
0
  if (ary.ContainsSorted(42, aComp)) {
1160
0
    return false;
1161
0
  }
1162
0
1163
0
  if (ary.BinaryIndexOf(16, aComp) != 4) {
1164
0
    return false;
1165
0
  }
1166
0
1167
0
  return true;
1168
0
}
Unexecuted instantiation: bool TestTArray::TestCompareMethods<TestTArray::IntComparator>(TestTArray::IntComparator const&)
Unexecuted instantiation: Unified_cpp_xpcom_tests_gtest2.cpp:bool TestTArray::TestCompareMethods<TestTArray::TArray_test_comparator_objects_Test::TestBody()::$_140>(TestTArray::TArray_test_comparator_objects_Test::TestBody()::$_140 const&)
1169
1170
struct IntComparator
1171
{
1172
  bool Equals(int aLeft, int aRight) const
1173
0
  {
1174
0
    return aLeft == aRight;
1175
0
  }
1176
1177
  bool LessThan(int aLeft, int aRight) const
1178
0
  {
1179
0
    return aLeft < aRight;
1180
0
  }
1181
};
1182
1183
0
TEST(TArray, test_comparator_objects) {
1184
0
  ASSERT_TRUE(TestCompareMethods(IntComparator()));
1185
0
  ASSERT_TRUE(TestCompareMethods([] (int aLeft, int aRight) { return aLeft - aRight; }));
1186
0
}
1187
1188
struct Big
1189
{
1190
  uint64_t size[40] = {};
1191
};
1192
1193
0
TEST(TArray, test_AutoTArray_SwapElements) {
1194
0
  AutoTArray<Big, 40> oneArray;
1195
0
  AutoTArray<Big, 40> another;
1196
0
1197
0
  for (size_t i = 0; i < 8; ++i) {
1198
0
    oneArray.AppendElement(Big());
1199
0
  }
1200
0
  oneArray[0].size[10] = 1;
1201
0
  for (size_t i = 0; i < 9; ++i) {
1202
0
    another.AppendElement(Big());
1203
0
  }
1204
0
  oneArray.SwapElements(another);
1205
0
1206
0
  ASSERT_EQ(oneArray.Length(), 9u);
1207
0
  ASSERT_EQ(another.Length(), 8u);
1208
0
1209
0
  ASSERT_EQ(oneArray[0].size[10], 0u);
1210
0
  ASSERT_EQ(another[0].size[10], 1u);
1211
0
}
1212
1213
} // namespace TestTArray