~ubuntu-branches/ubuntu/quantal/mysql-workbench/quantal

« back to all changes in this revision

Viewing changes to backend/wbpublic/grt/unit-tests/shell_test.cpp

  • Committer: Package Import Robot
  • Author(s): Dmitry Smirnov
  • Date: 2012-03-01 21:57:30 UTC
  • Revision ID: package-import@ubuntu.com-20120301215730-o7y8av8y38n162ro
Tags: upstream-5.2.38+dfsg
ImportĀ upstreamĀ versionĀ 5.2.38+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
 
3
 *
 
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
 
7
 * License.
 
8
 * 
 
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.
 
13
 * 
 
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
 
17
 * 02110-1301  USA
 
18
 */
 
19
 
 
20
#include "tut_stdafx.h"
 
21
 
 
22
#include "grt/grt_shell.h"
 
23
#include "grt/grt_dispatcher.h"
 
24
#include "grt/grt_manager.h"
 
25
 
 
26
 
 
27
using namespace grt;
 
28
using namespace bec;
 
29
 
 
30
 
 
31
BEGIN_TEST_DATA_CLASS(be_shell)
 
32
public:
 
33
  GRT grt;
 
34
  GRTManager manager;
 
35
  GRTDispatcher dispatcher;
 
36
  ShellBE shell;
 
37
TEST_DATA_CONSTRUCTOR(be_shell)
 
38
  : dispatcher(&grt, false, true), shell(&manager, &dispatcher)
 
39
{
 
40
  shell.set_saves_history(10);
 
41
}
 
42
 
 
43
END_TEST_DATA_CLASS;
 
44
 
 
45
 
 
46
 
 
47
TEST_MODULE(be_shell, "grt shell backend");
 
48
 
 
49
 
 
50
 
 
51
TEST_FUNCTION(1)
 
52
{ // test history navigation
 
53
  bool flag;
 
54
  std::string line;
 
55
  
 
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");
 
61
 
 
62
  flag= shell.next_history_line(line);
 
63
  ensure("next line", flag);
 
64
  ensure_equals("next line value", line, "newline");
 
65
 
 
66
 
 
67
  shell.save_history_line("line2");
 
68
  shell.save_history_line("line3");
 
69
 
 
70
  flag= shell.next_history_line(line);
 
71
  ensure("next", !flag);
 
72
 
 
73
  flag= shell.previous_history_line("newline", line);
 
74
  ensure("previous line", flag);
 
75
  ensure_equals("previous line value", line, "line3");
 
76
 
 
77
  flag= shell.previous_history_line("line3", line);
 
78
  ensure("previous line", flag);
 
79
  ensure_equals("previous line value", line, "line2");
 
80
  
 
81
  flag= shell.previous_history_line("line2", line);
 
82
  ensure("previous line", flag);
 
83
  ensure_equals("previous line value", line, "line1");
 
84
  
 
85
  flag= shell.previous_history_line("line1", line);
 
86
  ensure("previous line", !flag);
 
87
 
 
88
  flag= shell.next_history_line(line);
 
89
  ensure("next line", flag);
 
90
  ensure_equals("next line value", line, "line2");
 
91
 
 
92
  flag= shell.next_history_line(line);
 
93
  ensure("next line", flag);
 
94
  ensure_equals("next line value", line, "line3");
 
95
  
 
96
  flag= shell.next_history_line(line);
 
97
  ensure("next line", flag);
 
98
  ensure_equals("next line value", line, "newline");
 
99
  
 
100
  flag= shell.next_history_line(line);
 
101
  ensure("previous line", !flag);
 
102
 
 
103
  flag= shell.previous_history_line("newline", line);
 
104
  ensure("previous line", flag);
 
105
  ensure_equals("previous line value", line, "line3");
 
106
}
 
107
 
 
108
 
 
109
TEST_FUNCTION(2)
 
110
{
 
111
  bool flag;
 
112
  ShellBE *tmpshell= new ShellBE(&manager, &dispatcher);
 
113
 
 
114
  tmpshell->set_saves_history(10);
 
115
  tmpshell->set_save_directory(".");
 
116
 
 
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");
 
122
 
 
123
  tmpshell->set_snippet_data("hello world\nsnippet line this");
 
124
  tmpshell->store_state();
 
125
  
 
126
  delete tmpshell;
 
127
 
 
128
  tmpshell= new ShellBE(&manager, &dispatcher);
 
129
  tmpshell->set_saves_history(10);
 
130
  tmpshell->set_save_directory(".");
 
131
  tmpshell->restore_state();
 
132
 
 
133
  std::string line;
 
134
 
 
135
  flag= tmpshell->previous_history_line("newline", line);
 
136
  ensure("get restored line", flag);
 
137
 
 
138
  ensure_equals("last line ", line, "line5");
 
139
 
 
140
  flag= tmpshell->previous_history_line(line, line);
 
141
  ensure("prev after save", flag);
 
142
  ensure_equals("last line ", line, "line4");
 
143
 
 
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");
 
147
 
 
148
 
 
149
  line= tmpshell->get_snippet_data();
 
150
  ensure_equals("snippet", line, "hello world\nsnippet line this");
 
151
 
 
152
  delete tmpshell;
 
153
}
 
154
 
 
155
 
 
156
 
 
157
END_TESTS