]> src.bluestatic.org Git - macgdbp.git/blob - Source/Tests/DebuggerModelTest.m
Add a tool to wrap a raw ED25519 key in PKCS8.
[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 [super tearDown];
37 }
38
39 - (NSMutableArray<StackFrame*>*)mutableStack {
40 return (NSMutableArray<StackFrame*>*)_model.stack;
41 }
42
43 - (StackFrame*)makeStackFrameForFile:(NSString*)file
44 atLine:(NSUInteger)line
45 stackIndex:(NSUInteger)index {
46 StackFrame* frame = [[StackFrame alloc] init];
47 frame.filename = file;
48 frame.lineNumber = line;
49 frame.index = index;
50 return frame;
51 }
52
53 - (NSArray<StackFrame*>*)initialStack {
54 NSArray<StackFrame*>* initialStack = @[
55 [self makeStackFrameForFile:@"/top/frame" atLine:12 stackIndex:0],
56 [self makeStackFrameForFile:@"/middle/frame" atLine:44 stackIndex:1],
57 [self makeStackFrameForFile:@"/bottom/frame" atLine:1 stackIndex:2]
58 ];
59 initialStack[0].loaded = YES;
60 initialStack[1].loaded = YES;
61 initialStack[2].loaded = YES;
62 return initialStack;
63 }
64
65 - (void)testEmptyStackReplace {
66 XCTAssertEqual(0u, _model.stackDepth);
67 NSArray* stack = [self initialStack];
68 [_model updateStack:stack];
69 XCTAssertEqual(3u, _model.stackDepth);
70 XCTAssertEqualObjects(stack, _model.stack);
71 }
72
73 - (void)testReplaceTopFrame {
74 NSArray<StackFrame*>* initialStack = [self initialStack];
75 [[self mutableStack] addObjectsFromArray:initialStack];
76 XCTAssertEqual(3u, _model.stackDepth);
77
78 NSArray<StackFrame*>* replacementStack = @[
79 [self makeStackFrameForFile:@"/top/frame" atLine:999 stackIndex:0],
80 initialStack[1],
81 initialStack[2]
82 ];
83 [_model updateStack:replacementStack];
84 XCTAssertEqualObjects(replacementStack, _model.stack);
85 XCTAssertFalse(_model.stack[0].loaded);
86 XCTAssertEqual(0u, _model.stack[0].index);
87 XCTAssertTrue(_model.stack[1].loaded);
88 XCTAssertEqual(1u, _model.stack[1].index);
89 XCTAssertTrue(_model.stack[2].loaded);
90 XCTAssertEqual(2u, _model.stack[2].index);
91 }
92
93 - (void)testAddNewTopFrame {
94 [_model updateStack:[self initialStack]];
95 XCTAssertEqual(3u, _model.stackDepth);
96
97 NSMutableArray<StackFrame*>* replacementStack = [NSMutableArray arrayWithArray:[self initialStack]];
98 [replacementStack insertObject:[self makeStackFrameForFile:@"/top/new" atLine:44 stackIndex:0]
99 atIndex:0];
100 replacementStack[1].index = 1;
101 replacementStack[2].index = 2;
102 replacementStack[3].index = 3;
103
104 [_model updateStack:replacementStack];
105 XCTAssertEqual(4u, _model.stackDepth);
106 XCTAssertEqualObjects(replacementStack, _model.stack);
107 XCTAssertFalse(_model.stack[0].loaded);
108 XCTAssertEqual(0u, _model.stack[0].index);
109 XCTAssertTrue(_model.stack[1].loaded);
110 XCTAssertEqual(1u, _model.stack[1].index);
111 XCTAssertTrue(_model.stack[2].loaded);
112 XCTAssertEqual(2u, _model.stack[2].index);
113 }
114
115 - (void)testRemoveTopFrame {
116 NSArray* initialStack = [self initialStack];
117 [_model updateStack:initialStack];
118 XCTAssertEqual(3u, _model.stackDepth);
119
120 [_model updateStack:[initialStack subarrayWithRange:NSMakeRange(1, 2)]];
121 XCTAssertEqual(2u, _model.stackDepth);
122 XCTAssertTrue(_model.stack[0].loaded);
123 XCTAssertEqual(0u, _model.stack[0].index);
124 XCTAssertTrue(_model.stack[1].loaded);
125 XCTAssertEqual(1u, _model.stack[1].index);
126 }
127
128 - (void)testClearStack {
129 [_model updateStack:[self initialStack]];
130 XCTAssertEqual(3u, _model.stackDepth);
131 [_model updateStack:@[]];
132 XCTAssertEqual(0u, _model.stackDepth);
133 }
134
135 @end