]> src.bluestatic.org Git - macgdbp.git/blob - Source/Tests/DebuggerModelTest.m
Some final header nits.
[macgdbp.git] / Source / Tests / DebuggerModelTest.m
1 /*
2 * MacGDBp
3 * Copyright (c) 2015, Blue Static <https://www.bluestatic.org>
4 *
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6 * General Public License as published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
10 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along with this program; if not,
14 * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
15 */
16
17 #import <XCTest/XCTest.h>
18
19 #import "DebuggerModel.h"
20 #import "StackFrame.h"
21
22 @interface DebuggerModelTest : XCTestCase
23
24 @end
25
26 @implementation DebuggerModelTest {
27 DebuggerModel* _model;
28 }
29
30 - (void)setUp {
31 [super setUp];
32 _model = [[DebuggerModel alloc] init];
33 }
34
35 - (void)tearDown {
36 [_model release];
37 [super tearDown];
38 }
39
40 - (NSMutableArray<StackFrame*>*)mutableStack {
41 return (NSMutableArray<StackFrame*>*)_model.stack;
42 }
43
44 - (StackFrame*)makeStackFrameForFile:(NSString*)file
45 atLine:(NSUInteger)line
46 stackIndex:(NSUInteger)index {
47 StackFrame* frame = [[[StackFrame alloc] init] autorelease];
48 frame.filename = file;
49 frame.lineNumber = line;
50 frame.index = index;
51 return frame;
52 }
53
54 - (NSArray<StackFrame*>*)initialStack {
55 NSArray<StackFrame*>* initialStack = @[
56 [self makeStackFrameForFile:@"/top/frame" atLine:12 stackIndex:0],
57 [self makeStackFrameForFile:@"/middle/frame" atLine:44 stackIndex:1],
58 [self makeStackFrameForFile:@"/bottom/frame" atLine:1 stackIndex:2]
59 ];
60 initialStack[0].loaded = YES;
61 initialStack[1].loaded = YES;
62 initialStack[2].loaded = YES;
63 return initialStack;
64 }
65
66 - (void)testEmptyStackReplace {
67 XCTAssertEqual(0u, _model.stackDepth);
68 NSArray* stack = [self initialStack];
69 [_model updateStack:stack];
70 XCTAssertEqual(3u, _model.stackDepth);
71 XCTAssertEqualObjects(stack, _model.stack);
72 }
73
74 - (void)testReplaceTopFrame {
75 NSArray<StackFrame*>* initialStack = [self initialStack];
76 [[self mutableStack] addObjectsFromArray:initialStack];
77 XCTAssertEqual(3u, _model.stackDepth);
78
79 NSArray<StackFrame*>* replacementStack = @[
80 [self makeStackFrameForFile:@"/top/frame" atLine:999 stackIndex:0],
81 initialStack[1],
82 initialStack[2]
83 ];
84 [_model updateStack:replacementStack];
85 XCTAssertEqualObjects(replacementStack, _model.stack);
86 XCTAssertFalse(_model.stack[0].loaded);
87 XCTAssertEqual(0u, _model.stack[0].index);
88 XCTAssertTrue(_model.stack[1].loaded);
89 XCTAssertEqual(1u, _model.stack[1].index);
90 XCTAssertTrue(_model.stack[2].loaded);
91 XCTAssertEqual(2u, _model.stack[2].index);
92 }
93
94 - (void)testAddNewTopFrame {
95 [_model updateStack:[self initialStack]];
96 XCTAssertEqual(3u, _model.stackDepth);
97
98 NSMutableArray<StackFrame*>* replacementStack = [NSMutableArray arrayWithArray:[self initialStack]];
99 [replacementStack insertObject:[self makeStackFrameForFile:@"/top/new" atLine:44 stackIndex:0]
100 atIndex:0];
101 replacementStack[1].index = 1;
102 replacementStack[2].index = 2;
103 replacementStack[3].index = 3;
104
105 [_model updateStack:replacementStack];
106 XCTAssertEqual(4u, _model.stackDepth);
107 XCTAssertEqualObjects(replacementStack, _model.stack);
108 XCTAssertFalse(_model.stack[0].loaded);
109 XCTAssertEqual(0u, _model.stack[0].index);
110 XCTAssertTrue(_model.stack[1].loaded);
111 XCTAssertEqual(1u, _model.stack[1].index);
112 XCTAssertTrue(_model.stack[2].loaded);
113 XCTAssertEqual(2u, _model.stack[2].index);
114 }
115
116 - (void)testRemoveTopFrame {
117 NSArray* initialStack = [self initialStack];
118 [_model updateStack:initialStack];
119 XCTAssertEqual(3u, _model.stackDepth);
120
121 [_model updateStack:[initialStack subarrayWithRange:NSMakeRange(1, 2)]];
122 XCTAssertEqual(2u, _model.stackDepth);
123 XCTAssertTrue(_model.stack[0].loaded);
124 XCTAssertEqual(0u, _model.stack[0].index);
125 XCTAssertTrue(_model.stack[1].loaded);
126 XCTAssertEqual(1u, _model.stack[1].index);
127 }
128
129 - (void)testClearStack {
130 [_model updateStack:[self initialStack]];
131 XCTAssertEqual(3u, _model.stackDepth);
132 [_model updateStack:@[]];
133 XCTAssertEqual(0u, _model.stackDepth);
134 }
135
136 @end