2
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License as
6
* published by the Free Software Foundation; version 2 of the
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20
#include "tut_stdafx.h"
22
#include "grt/grt_shell.h"
23
#include "grt/grt_dispatcher.h"
24
#include "grt/grt_manager.h"
31
BEGIN_TEST_DATA_CLASS(be_shell)
35
GRTDispatcher dispatcher;
37
TEST_DATA_CONSTRUCTOR(be_shell)
38
: dispatcher(&grt, false, true), shell(&manager, &dispatcher)
40
shell.set_saves_history(10);
47
TEST_MODULE(be_shell, "grt shell backend");
52
{ // test history navigation
56
shell.set_saves_history(10);
57
shell.save_history_line("line1");
58
flag= shell.previous_history_line("newline", line);
59
ensure("previous line", flag);
60
ensure_equals("previous line value", line, "line1");
62
flag= shell.next_history_line(line);
63
ensure("next line", flag);
64
ensure_equals("next line value", line, "newline");
67
shell.save_history_line("line2");
68
shell.save_history_line("line3");
70
flag= shell.next_history_line(line);
71
ensure("next", !flag);
73
flag= shell.previous_history_line("newline", line);
74
ensure("previous line", flag);
75
ensure_equals("previous line value", line, "line3");
77
flag= shell.previous_history_line("line3", line);
78
ensure("previous line", flag);
79
ensure_equals("previous line value", line, "line2");
81
flag= shell.previous_history_line("line2", line);
82
ensure("previous line", flag);
83
ensure_equals("previous line value", line, "line1");
85
flag= shell.previous_history_line("line1", line);
86
ensure("previous line", !flag);
88
flag= shell.next_history_line(line);
89
ensure("next line", flag);
90
ensure_equals("next line value", line, "line2");
92
flag= shell.next_history_line(line);
93
ensure("next line", flag);
94
ensure_equals("next line value", line, "line3");
96
flag= shell.next_history_line(line);
97
ensure("next line", flag);
98
ensure_equals("next line value", line, "newline");
100
flag= shell.next_history_line(line);
101
ensure("previous line", !flag);
103
flag= shell.previous_history_line("newline", line);
104
ensure("previous line", flag);
105
ensure_equals("previous line value", line, "line3");
112
ShellBE *tmpshell= new ShellBE(&manager, &dispatcher);
114
tmpshell->set_saves_history(10);
115
tmpshell->set_save_directory(".");
117
tmpshell->save_history_line("line1");
118
tmpshell->save_history_line("line2");
119
tmpshell->save_history_line("line3.1\nline3.2\n\nline3.3");
120
tmpshell->save_history_line("line4");
121
tmpshell->save_history_line("line5");
123
tmpshell->set_snippet_data("hello world\nsnippet line this");
124
tmpshell->store_state();
128
tmpshell= new ShellBE(&manager, &dispatcher);
129
tmpshell->set_saves_history(10);
130
tmpshell->set_save_directory(".");
131
tmpshell->restore_state();
135
flag= tmpshell->previous_history_line("newline", line);
136
ensure("get restored line", flag);
138
ensure_equals("last line ", line, "line5");
140
flag= tmpshell->previous_history_line(line, line);
141
ensure("prev after save", flag);
142
ensure_equals("last line ", line, "line4");
144
flag= tmpshell->previous_history_line(line, line);
145
ensure("prev after save", flag);
146
ensure_equals("last line ", line, "line3.1\nline3.2\n\nline3.3");
149
line= tmpshell->get_snippet_data();
150
ensure_equals("snippet", line, "hello world\nsnippet line this");