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
];
40 - (NSMutableArray
<StackFrame
*>*)mutableStack
{
41 return (NSMutableArray
<StackFrame
*>*)_model.stack
;
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
;
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]
60 initialStack
[0].loaded
= YES
;
61 initialStack
[1].loaded
= YES
;
62 initialStack
[2].loaded
= YES
;
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
);
74 - (void)testReplaceTopFrame
{
75 NSArray
<StackFrame
*>* initialStack
= [self initialStack
];
76 [[self mutableStack
] addObjectsFromArray
:initialStack
];
77 XCTAssertEqual(3u, _model.stackDepth
);
79 NSArray
<StackFrame
*>* replacementStack
= @
[
80 [self makeStackFrameForFile
:@
"/top/frame" atLine
:999 stackIndex
:0],
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
);
94 - (void)testAddNewTopFrame
{
95 [_model updateStack
:[self initialStack
]];
96 XCTAssertEqual(3u, _model.stackDepth
);
98 NSMutableArray
<StackFrame
*>* replacementStack
= [NSMutableArray arrayWithArray
:[self initialStack
]];
99 [replacementStack insertObject
:[self makeStackFrameForFile
:@
"/top/new" atLine
:44 stackIndex
:0]
101 replacementStack
[1].index
= 1;
102 replacementStack
[2].index
= 2;
103 replacementStack
[3].index
= 3;
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
);
116 - (void)testRemoveTopFrame
{
117 NSArray
* initialStack
= [self initialStack
];
118 [_model updateStack
:initialStack
];
119 XCTAssertEqual(3u, _model.stackDepth
);
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
);
129 - (void)testClearStack
{
130 [_model updateStack
:[self initialStack
]];
131 XCTAssertEqual(3u, _model.stackDepth
);
132 [_model updateStack
:@
[]];
133 XCTAssertEqual(0u, _model.stackDepth
);