-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
236 lines (234 loc) · 5.1 KB
/
Copy pathmain.cpp
File metadata and controls
236 lines (234 loc) · 5.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# include "Generator.h"
# include "Invalid.h"
// Main function controls UI and calls Generators as required
signed main()
{
int wrong_count = 0;
string command;
cout << "\033[2J\033[1;1H";
string s1;
cout << "Welcome to the test case generator toolkit." << '\n';
cout << "Use the command 'manual' or open manual.txt to open the manual." << '\n';
cout << "Use the command 'gen' or 'generator' to set test cases. Please refer to the manual if you are unsure about the keywords." << '\n';
cout << "Please enter 'exit' or 'quit' to exit the application." << '\n';
cout << "Please enter 'clear' to clear the screen." << '\n' << '\n';
while(true)
{
cout << '\n' << "> ";
getline(cin, command, '\n');
if(command == "")
continue;
// quit
if(command[0] == 'q')
{
stringstream str(command);
string s;
str >> s;
if(s == "quit")
{
if(str >> s1)
{
wrong_count++;
cout << "Invalid command, extra words detected." << '\n';
}
else
{
cout << "Are you sure you want to quit? (y/n) ";
string choice;
wrong_count = 0;
getline(cin, choice);
if(choice == "y")
{
cout << '\n' << '\n';
break;
}
}
}
else
{
wrong_count++;
cout << "Illegal command \"" << s << "\": did you mean \"quit\"?" << '\n';
}
}
// exit
else if(command[0] == 'e')
{
stringstream str(command);
string s;
str >> s;
if(s == "exit")
{
if(str >> s1)
{
wrong_count++;
cout << "Invalid command, extra words detected." << '\n';
}
else
{
cout << "Are you sure you want to exit? (y/n) ";
string choice;
wrong_count = 0;
getline(cin, choice);
if(choice == "y")
{
cout << '\n' << '\n';
break;
}
}
}
else
{
wrong_count++;
cout << "Illegal command \"" << s << "\": did you mean \"exit\"?" << '\n';
}
}
// generate test case
else if(command[0] == 'g')
{
stringstream str(command);
string s;
str >> s;
if(s != "gen" && s != "generate")
{
wrong_count++;
cout << "Illegal command \"" << s << "\": did you mean: \"gen\"?" << '\n';
}
else
{
wrong_count = 0;
try
{
cout << "Invoked: generation " << '\n' << '\n' << '\n';
Generate g1;
g1.genfunc();
cout << "Generation completed successfully. " << '\n';
}
catch(Invalid &e)
{
int ecode = e.retError();
switch(ecode)
{
case 1 :
cout << "Invalid integer input. Aborted." << '\n';
break;
case 2 :
cout << "Invalid string input. Aborted." << '\n';
break;
case 3 :
cout << "Invalid preset. Aborted." << '\n';
break;
case 11 :
cout << "Invalid constraints. Aborted." << '\n';
break;
case 21 :
cout << "Invalid Distribution key. Aborted." << '\n';
break;
case 101 :
cout << "Invalid characters. Aborted." << '\n';
break;
case 201 :
cout << "Invalid floating point input. Aborted." << '\n';
break;
case 1001 :
cout << "Sizes invalid. Aborted." << '\n';
break;
case 2001 :
cout << "Output generated aborted. Generation completed successfully." << '\n';
break;
case -1 :
cout << "Generation aborted." << '\n';
break;
}
}
catch(int &i)
{
switch(i)
{
case 111:
cout << "Invalid binary input. Aborted." << '\n';
break;
}
}
}
}
// clear screen
else if(command[0] == 'c')
{
stringstream str(command);
string s;
str >> s;
if(s == "clear")
{
if(str >> s)
{
if(str >> s1)
{
wrong_count++;
cout << "Invalid command, extra words detected." << '\n';
}
else if(s == "screen")
{
cout << "\033[2J\033[1;1H";
wrong_count = 0;
}
else
{
wrong_count++;
cout << "Illegal command \"clear " << s <<"\"." << '\n';
}
}
else
{
cout << "\033[2J\033[1;1H";
wrong_count = 0;
}
}
else
{
wrong_count++;
cout << "Illegal command \"" << s << "\": did you mean \"clear\"?" << '\n';
}
}
// open manual
else if(command[0] == 'm')
{
stringstream str(command);
string s;
str >> s;
if(s == "manual")
{
if(str >> s1)
{
wrong_count++;
cout << "Invalid command, extra words detected." << '\n';
}
cout << "Invoked: manual " << '\n' << '\n' << '\n';
fstream f1("manual.txt", ios :: in);
while(true)
{
string s1;
getline(f1, s1, '\n');
if(f1.eof())
break;
cout << s1 << '\n';
this_thread :: sleep_for(microseconds(10000));
}
wrong_count = 0;
}
else
{
wrong_count++;
cout << "Illegal command \"" << command << "\": did you mean \"manual\"?" << '\n';
}
}
else
{
cout << "Invalid command \"" << command << "\"" << '\n';
wrong_count++;
}
if(wrong_count >= 3)
cout << "In case you have trouble with commands, open manual.txt or open it here using the command \"manual\"." << '\n';
}
cout << "Thank you for using the test case generator toolkit." << '\n' << '\n';
return 0;
}