toolkit/crashreporter/google-breakpad/src/common/memory_unittest.cc

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 // Copyright (c) 2009, Google Inc.
     2 // All rights reserved.
     3 //
     4 // Redistribution and use in source and binary forms, with or without
     5 // modification, are permitted provided that the following conditions are
     6 // met:
     7 //
     8 //     * Redistributions of source code must retain the above copyright
     9 // notice, this list of conditions and the following disclaimer.
    10 //     * Redistributions in binary form must reproduce the above
    11 // copyright notice, this list of conditions and the following disclaimer
    12 // in the documentation and/or other materials provided with the
    13 // distribution.
    14 //     * Neither the name of Google Inc. nor the names of its
    15 // contributors may be used to endorse or promote products derived from
    16 // this software without specific prior written permission.
    17 //
    18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    30 #include "breakpad_googletest_includes.h"
    31 #include "common/memory.h"
    33 using namespace google_breakpad;
    35 namespace {
    36 typedef testing::Test PageAllocatorTest;
    37 }
    39 TEST(PageAllocatorTest, Setup) {
    40   PageAllocator allocator;
    41 }
    43 TEST(PageAllocatorTest, SmallObjects) {
    44   PageAllocator allocator;
    46   for (unsigned i = 1; i < 1024; ++i) {
    47     uint8_t *p = reinterpret_cast<uint8_t*>(allocator.Alloc(i));
    48     ASSERT_FALSE(p == NULL);
    49     memset(p, 0, i);
    50   }
    51 }
    53 TEST(PageAllocatorTest, LargeObject) {
    54   PageAllocator allocator;
    56   uint8_t *p = reinterpret_cast<uint8_t*>(allocator.Alloc(10000));
    57   ASSERT_FALSE(p == NULL);
    58   for (unsigned i = 1; i < 10; ++i) {
    59     uint8_t *p = reinterpret_cast<uint8_t*>(allocator.Alloc(i));
    60     ASSERT_FALSE(p == NULL);
    61     memset(p, 0, i);
    62   }
    63 }
    65 namespace {
    66 typedef testing::Test WastefulVectorTest;
    67 }
    69 TEST(WastefulVectorTest, Setup) {
    70   PageAllocator allocator_;
    71   wasteful_vector<int> v(&allocator_);
    72   ASSERT_TRUE(v.empty());
    73   ASSERT_EQ(v.size(), 0u);
    74 }
    76 TEST(WastefulVectorTest, Simple) {
    77   PageAllocator allocator_;
    78   wasteful_vector<unsigned> v(&allocator_);
    80   for (unsigned i = 0; i < 256; ++i) {
    81     v.push_back(i);
    82     ASSERT_EQ(i, v.back());
    83     ASSERT_EQ(&v.back(), &v[i]);
    84   }
    85   ASSERT_FALSE(v.empty());
    86   ASSERT_EQ(v.size(), 256u);
    87   for (unsigned i = 0; i < 256; ++i)
    88     ASSERT_EQ(v[i], i);
    89 }

mercurial