3 * Copyright (c) 2015, Blue Static <https://www.bluestatic.org>
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.
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.
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
17 #import <XCTest/XCTest.h>
19 #import "DebuggerModel.h"
20 #import "StackFrame.h"
22 @interface DebuggerModelTest
: XCTestCase
26 @implementation DebuggerModelTest
{
27 DebuggerModel
* _model
;
32 _model
= [[DebuggerModel alloc
] init
];
39 - (NSMutableArray
<StackFrame
*>*)mutableStack
{
40 return (NSMutableArray
<StackFrame
*>*)_model.stack
;
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
;
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]
59 initialStack
[0].loaded
= YES
;
60 initialStack
[1].loaded
= YES
;
61 initialStack
[2].loaded
= YES
;
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
);
73 - (void)testReplaceTopFrame
{
74 NSArray
<StackFrame
*>* initialStack
= [self initialStack
];
75 [[self mutableStack
] addObjectsFromArray
:initialStack
];
76 XCTAssertEqual(3u, _model.stackDepth
);
78 NSArray
<StackFrame
*>* replacementStack
= @
[
79 [self makeStackFrameForFile
:@
"/top/frame" atLine
:999 stackIndex
:0],
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
);
93 - (void)testAddNewTopFrame
{
94 [_model updateStack
:[self initialStack
]];
95 XCTAssertEqual(3u, _model.stackDepth
);
97 NSMutableArray
<StackFrame
*>* replacementStack
= [NSMutableArray arrayWithArray
:[self initialStack
]];
98 [replacementStack insertObject
:[self makeStackFrameForFile
:@
"/top/new" atLine
:44 stackIndex
:0]
100 replacementStack
[1].index
= 1;
101 replacementStack
[2].index
= 2;
102 replacementStack
[3].index
= 3;
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
);
115 - (void)testRemoveTopFrame
{
116 NSArray
* initialStack
= [self initialStack
];
117 [_model updateStack
:initialStack
];
118 XCTAssertEqual(3u, _model.stackDepth
);
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
);
128 - (void)testClearStack
{
129 [_model updateStack
:[self initialStack
]];
130 XCTAssertEqual(3u, _model.stackDepth
);
131 [_model updateStack
:@
[]];
132 XCTAssertEqual(0u, _model.stackDepth
);