summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'libunwindstack/tests/MemoryRangeTest.cpp')
-rw-r--r--libunwindstack/tests/MemoryRangeTest.cpp34
1 files changed, 7 insertions, 27 deletions
diff --git a/libunwindstack/tests/MemoryRangeTest.cpp b/libunwindstack/tests/MemoryRangeTest.cpp
index d636ec497..ee5ba018b 100644
--- a/libunwindstack/tests/MemoryRangeTest.cpp
+++ b/libunwindstack/tests/MemoryRangeTest.cpp
@@ -17,6 +17,7 @@
17#include <stdint.h> 17#include <stdint.h>
18#include <string.h> 18#include <string.h>
19 19
20#include <memory>
20#include <vector> 21#include <vector>
21 22
22#include <gtest/gtest.h> 23#include <gtest/gtest.h>
@@ -65,35 +66,14 @@ TEST_F(MemoryRangeTest, read_near_limit) {
65 ASSERT_FALSE(range.Read(1020, dst.data(), 5)); 66 ASSERT_FALSE(range.Read(1020, dst.data(), 5));
66 ASSERT_FALSE(range.Read(1024, dst.data(), 1)); 67 ASSERT_FALSE(range.Read(1024, dst.data(), 1));
67 ASSERT_FALSE(range.Read(1024, dst.data(), 1024)); 68 ASSERT_FALSE(range.Read(1024, dst.data(), 1024));
68}
69
70TEST_F(MemoryRangeTest, read_string_past_end) {
71 std::string name("0123456789");
72 memory_->SetMemory(0, name);
73
74 // Verify a read past the range fails.
75 MemoryRange range(memory_, 0, 5);
76 std::string dst_name;
77 ASSERT_FALSE(range.ReadString(0, &dst_name));
78}
79
80TEST_F(MemoryRangeTest, read_string_to_end) {
81 std::string name("0123456789");
82 memory_->SetMemory(30, name);
83 69
84 // Verify the range going to the end of the string works. 70 // Verify that reading up to the end works.
85 MemoryRange range(memory_, 30, 30 + name.size() + 1); 71 ASSERT_TRUE(range.Read(1020, dst.data(), 4));
86 std::string dst_name;
87 ASSERT_TRUE(range.ReadString(0, &dst_name));
88 ASSERT_EQ("0123456789", dst_name);
89} 72}
90 73
91TEST_F(MemoryRangeTest, read_string_fencepost) { 74TEST_F(MemoryRangeTest, read_overflow) {
92 std::string name("0123456789"); 75 std::vector<uint8_t> buffer(100);
93 memory_->SetMemory(10, name);
94 76
95 // Verify the range set to one byte less than the end of the string fails. 77 std::unique_ptr<MemoryRange> overflow(new MemoryRange(new MemoryFakeAlwaysReadZero, 100, 200));
96 MemoryRange range(memory_, 10, 10 + name.size()); 78 ASSERT_FALSE(overflow->Read(UINT64_MAX - 10, buffer.data(), 100));
97 std::string dst_name;
98 ASSERT_FALSE(range.ReadString(0, &dst_name));
99} 79}