| OLD | NEW |
| 1 // Copyright (c) 2009, Google Inc. | 1 // Copyright (c) 2009, Google Inc. |
| 2 // All rights reserved. | 2 // All rights reserved. |
| 3 // | 3 // |
| 4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
| 6 // met: | 6 // met: |
| 7 // | 7 // |
| 8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
| 9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
| 10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "common/memory.h" | 31 #include "common/memory.h" |
| 32 | 32 |
| 33 using namespace google_breakpad; | 33 using namespace google_breakpad; |
| 34 | 34 |
| 35 namespace { | 35 namespace { |
| 36 typedef testing::Test PageAllocatorTest; | 36 typedef testing::Test PageAllocatorTest; |
| 37 } | 37 } |
| 38 | 38 |
| 39 TEST(PageAllocatorTest, Setup) { | 39 TEST(PageAllocatorTest, Setup) { |
| 40 PageAllocator allocator; | 40 PageAllocator allocator; |
| 41 EXPECT_EQ(0, allocator.pages_allocated()); | 41 EXPECT_EQ(0U, allocator.pages_allocated()); |
| 42 } | 42 } |
| 43 | 43 |
| 44 TEST(PageAllocatorTest, SmallObjects) { | 44 TEST(PageAllocatorTest, SmallObjects) { |
| 45 PageAllocator allocator; | 45 PageAllocator allocator; |
| 46 | 46 |
| 47 EXPECT_EQ(0, allocator.pages_allocated()); | 47 EXPECT_EQ(0U, allocator.pages_allocated()); |
| 48 for (unsigned i = 1; i < 1024; ++i) { | 48 for (unsigned i = 1; i < 1024; ++i) { |
| 49 uint8_t *p = reinterpret_cast<uint8_t*>(allocator.Alloc(i)); | 49 uint8_t *p = reinterpret_cast<uint8_t*>(allocator.Alloc(i)); |
| 50 ASSERT_FALSE(p == NULL); | 50 ASSERT_FALSE(p == NULL); |
| 51 memset(p, 0, i); | 51 memset(p, 0, i); |
| 52 } | 52 } |
| 53 } | 53 } |
| 54 | 54 |
| 55 TEST(PageAllocatorTest, LargeObject) { | 55 TEST(PageAllocatorTest, LargeObject) { |
| 56 PageAllocator allocator; | 56 PageAllocator allocator; |
| 57 | 57 |
| 58 EXPECT_EQ(0, allocator.pages_allocated()); | 58 EXPECT_EQ(0U, allocator.pages_allocated()); |
| 59 uint8_t *p = reinterpret_cast<uint8_t*>(allocator.Alloc(10000)); | 59 uint8_t *p = reinterpret_cast<uint8_t*>(allocator.Alloc(10000)); |
| 60 ASSERT_FALSE(p == NULL); | 60 ASSERT_FALSE(p == NULL); |
| 61 EXPECT_EQ(3, allocator.pages_allocated()); | 61 EXPECT_EQ(3U, allocator.pages_allocated()); |
| 62 for (unsigned i = 1; i < 10; ++i) { | 62 for (unsigned i = 1; i < 10; ++i) { |
| 63 uint8_t *p = reinterpret_cast<uint8_t*>(allocator.Alloc(i)); | 63 uint8_t *p = reinterpret_cast<uint8_t*>(allocator.Alloc(i)); |
| 64 ASSERT_FALSE(p == NULL); | 64 ASSERT_FALSE(p == NULL); |
| 65 memset(p, 0, i); | 65 memset(p, 0, i); |
| 66 } | 66 } |
| 67 } | 67 } |
| 68 | 68 |
| 69 namespace { | 69 namespace { |
| 70 typedef testing::Test WastefulVectorTest; | 70 typedef testing::Test WastefulVectorTest; |
| 71 } | 71 } |
| 72 | 72 |
| 73 TEST(WastefulVectorTest, Setup) { | 73 TEST(WastefulVectorTest, Setup) { |
| 74 PageAllocator allocator_; | 74 PageAllocator allocator_; |
| 75 wasteful_vector<int> v(&allocator_); | 75 wasteful_vector<int> v(&allocator_); |
| 76 ASSERT_TRUE(v.empty()); | 76 ASSERT_TRUE(v.empty()); |
| 77 ASSERT_EQ(v.size(), 0u); | 77 ASSERT_EQ(v.size(), 0u); |
| 78 } | 78 } |
| 79 | 79 |
| 80 TEST(WastefulVectorTest, Simple) { | 80 TEST(WastefulVectorTest, Simple) { |
| 81 PageAllocator allocator_; | 81 PageAllocator allocator_; |
| 82 EXPECT_EQ(0, allocator_.pages_allocated()); | 82 EXPECT_EQ(0U, allocator_.pages_allocated()); |
| 83 wasteful_vector<unsigned> v(&allocator_); | 83 wasteful_vector<unsigned> v(&allocator_); |
| 84 | 84 |
| 85 for (unsigned i = 0; i < 256; ++i) { | 85 for (unsigned i = 0; i < 256; ++i) { |
| 86 v.push_back(i); | 86 v.push_back(i); |
| 87 ASSERT_EQ(i, v.back()); | 87 ASSERT_EQ(i, v.back()); |
| 88 ASSERT_EQ(&v.back(), &v[i]); | 88 ASSERT_EQ(&v.back(), &v[i]); |
| 89 } | 89 } |
| 90 ASSERT_FALSE(v.empty()); | 90 ASSERT_FALSE(v.empty()); |
| 91 ASSERT_EQ(v.size(), 256u); | 91 ASSERT_EQ(v.size(), 256u); |
| 92 EXPECT_EQ(1, allocator_.pages_allocated()); | 92 EXPECT_EQ(1U, allocator_.pages_allocated()); |
| 93 for (unsigned i = 0; i < 256; ++i) | 93 for (unsigned i = 0; i < 256; ++i) |
| 94 ASSERT_EQ(v[i], i); | 94 ASSERT_EQ(v[i], i); |
| 95 } | 95 } |
| 96 | 96 |
| 97 TEST(WastefulVectorTest, UsesPageAllocator) { | 97 TEST(WastefulVectorTest, UsesPageAllocator) { |
| 98 PageAllocator allocator_; | 98 PageAllocator allocator_; |
| 99 wasteful_vector<unsigned> v(&allocator_); | 99 wasteful_vector<unsigned> v(&allocator_); |
| 100 EXPECT_EQ(1, allocator_.pages_allocated()); | 100 EXPECT_EQ(1U, allocator_.pages_allocated()); |
| 101 | 101 |
| 102 v.push_back(1); | 102 v.push_back(1); |
| 103 ASSERT_TRUE(allocator_.OwnsPointer(&v[0])); | 103 ASSERT_TRUE(allocator_.OwnsPointer(&v[0])); |
| 104 } | 104 } |
| 105 | 105 |
| 106 TEST(WastefulVectorTest, AutoWastefulVector) { | 106 TEST(WastefulVectorTest, AutoWastefulVector) { |
| 107 PageAllocator allocator_; | 107 PageAllocator allocator_; |
| 108 EXPECT_EQ(0, allocator_.pages_allocated()); | 108 EXPECT_EQ(0U, allocator_.pages_allocated()); |
| 109 | 109 |
| 110 auto_wasteful_vector<unsigned, 4> v(&allocator_); | 110 auto_wasteful_vector<unsigned, 4> v(&allocator_); |
| 111 EXPECT_EQ(0, allocator_.pages_allocated()); | 111 EXPECT_EQ(0U, allocator_.pages_allocated()); |
| 112 | 112 |
| 113 v.push_back(1); | 113 v.push_back(1); |
| 114 EXPECT_EQ(0, allocator_.pages_allocated()); | 114 EXPECT_EQ(0U, allocator_.pages_allocated()); |
| 115 EXPECT_FALSE(allocator_.OwnsPointer(&v[0])); | 115 EXPECT_FALSE(allocator_.OwnsPointer(&v[0])); |
| 116 | 116 |
| 117 v.resize(4); | 117 v.resize(4); |
| 118 EXPECT_EQ(0, allocator_.pages_allocated()); | 118 EXPECT_EQ(0U, allocator_.pages_allocated()); |
| 119 EXPECT_FALSE(allocator_.OwnsPointer(&v[0])); | 119 EXPECT_FALSE(allocator_.OwnsPointer(&v[0])); |
| 120 | 120 |
| 121 v.resize(10); | 121 v.resize(10); |
| 122 EXPECT_EQ(1, allocator_.pages_allocated()); | 122 EXPECT_EQ(1U, allocator_.pages_allocated()); |
| 123 EXPECT_TRUE(allocator_.OwnsPointer(&v[0])); | 123 EXPECT_TRUE(allocator_.OwnsPointer(&v[0])); |
| 124 } | 124 } |
| OLD | NEW |