Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(479)

Side by Side Diff: experimental/windows_debugger/debugger/core/debug_breakpoint_test.cc

Issue 10928195: First round of dead file removal (Closed) Base URL: https://github.com/samclegg/nativeclient-sdk.git@master
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Native Client Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 #include "debugger/core/debug_breakpoint.h"
5 #include "debugger/core/debuggee_process_mock.h"
6 #include "gtest/gtest.h"
7
8 namespace {
9 const unsigned char kBreakpointCode = 0xCC;
10 void* kBigAddr = reinterpret_cast<void*>(0xAAFFEE88);
11 void* kSmallAddr = reinterpret_cast<void*>(2);
12
13
14 // Breakpoint test fixture.
15 class BreakpointTest : public ::testing::Test {
16 protected:
17 BreakpointTest()
18 : big_addr_(kBigAddr),
19 addr_(kSmallAddr),
20 proc_(NULL),
21 orig_code_(0) {
22 bp_ = new debug::Breakpoint(kSmallAddr, &proc_);
23 }
24 ~BreakpointTest() { delete bp_; }
25
26 void* big_addr_;
27 void* addr_;
28 debug::DebuggeeProcessMock proc_;
29 debug::Breakpoint* bp_;
30 unsigned char orig_code_;
31 };
32
33 // Unit tests start here.
34 TEST_F(BreakpointTest, EmptyBreakpoint) {
35 debug::Breakpoint bp;
36 EXPECT_EQ(NULL, bp.address());
37 EXPECT_EQ(0, bp.original_code_byte());
38 EXPECT_FALSE(bp.is_valid());
39 }
40
41 TEST_F(BreakpointTest, UninitializedBreakpoints) {
42 void* addr = kBigAddr;
43 debug::Breakpoint bp(addr, &proc_);
44 EXPECT_EQ(addr, bp.address());
45 EXPECT_EQ(0, bp.original_code_byte());
46 EXPECT_FALSE(bp.is_valid());
47 }
48
49 TEST_F(BreakpointTest, MockProcessReadOk) {
50 // Make sure original code byte is correct.
51 EXPECT_TRUE(proc_.ReadMemory(addr_, sizeof(orig_code_), &orig_code_));
52 EXPECT_EQ(debug::DebuggeeProcessMock::kFillChar, orig_code_);
53 }
54
55 TEST_F(BreakpointTest, MockProcessReadErr) {
56 // Make sure ReadMemory fails when called with big address.
57 EXPECT_FALSE(proc_.ReadMemory(big_addr_, sizeof(orig_code_), &orig_code_));
58 EXPECT_EQ(0, orig_code_);
59 }
60
61 TEST_F(BreakpointTest, BreakpointInitialization) {
62 // Tests breakpoint initialization.
63 EXPECT_TRUE(bp_->Init());
64 EXPECT_EQ(debug::DebuggeeProcessMock::kFillChar, bp_->original_code_byte());
65 EXPECT_TRUE(bp_->is_valid());
66 unsigned char code = 0;
67 EXPECT_TRUE(proc_.ReadMemory(addr_, sizeof(code), &code));
68 EXPECT_EQ(kBreakpointCode, code);
69 }
70
71 TEST_F(BreakpointTest, BreakpointRemoval) {
72 EXPECT_TRUE(bp_->Init());
73 EXPECT_TRUE(bp_->RecoverCodeAtBreakpoint());
74 unsigned char code = 0;
75 EXPECT_TRUE(proc_.ReadMemory(addr_, sizeof(code), &code));
76 EXPECT_EQ(debug::DebuggeeProcessMock::kFillChar, code);
77 }
78
79 TEST_F(BreakpointTest, BreakpointRecovery) {
80 EXPECT_TRUE(bp_->Init());
81 EXPECT_TRUE(bp_->WriteBreakpointCode());
82 unsigned char code = 0;
83 EXPECT_TRUE(proc_.ReadMemory(addr_, sizeof(code), &code));
84 EXPECT_EQ(kBreakpointCode, code);
85 }
86
87 TEST_F(BreakpointTest, OpsOnInvalidMemory) {
88 debug::Breakpoint bp(kBigAddr, &proc_);
89 EXPECT_FALSE(bp.Init());
90 EXPECT_FALSE(bp.RecoverCodeAtBreakpoint());
91 EXPECT_FALSE(bp.WriteBreakpointCode());
92 EXPECT_FALSE(bp.is_valid());
93 }
94 } // namespace
95
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698