-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli_test.cpp
More file actions
84 lines (81 loc) · 2.94 KB
/
cli_test.cpp
File metadata and controls
84 lines (81 loc) · 2.94 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
#include "file_system.h"
#include <iostream>
#include <string>
#include <vector>
using namespace std;
// Simulate user input and test eshaanOS CLI commands
void testEshaanOSCLI() {
FileSystem eshaanOSfs;
vector<string> commands = {
"help",
"create test.txt",
"write test.txt Hello, World!",
"read test.txt",
"ls",
"delete test.txt",
"read test.txt",
"create ", // Invalid
"delete non_existent.txt", // Invalid
"write test.txt", // Invalid
"invalid_command"
};
string content;
for (const auto& command : commands) {
cout << "\n--- Executing: " << command << " ---" << endl;
if (command == "help") {
cout << "Available commands:\nhelp\ncreate <file>\ndelete <file>\nread <file>\nwrite <file> <text>\nls\nexit\n";
} else if (command.find("create ") == 0) {
string fileName = command.substr(7);
if (fileName.empty()) {
cout << "Error: No file name provided." << endl;
} else {
eshaanOSfs.createFile(fileName);
}
} else if (command.find("delete ") == 0) {
string fileName = command.substr(7);
if (fileName.empty()) {
cout << "Error: No file name provided." << endl;
} else {
eshaanOSfs.deleteFile(fileName);
}
} else if (command.find("read ") == 0) {
string fileName = command.substr(5);
if (fileName.empty()) {
cout << "Error: No file name provided." << endl;
} else {
eshaanOSfs.readFile(fileName, content);
}
} else if (command.find("write ") == 0) {
size_t firstSpace = command.find(' ');
size_t secondSpace = command.find(' ', firstSpace + 1);
if (secondSpace == string::npos) {
cout << "Usage: write <file> <text>" << endl;
continue;
}
string fileName = command.substr(firstSpace + 1, secondSpace - firstSpace - 1);
string text = command.substr(secondSpace + 1);
if (fileName.empty() || text.empty()) {
cout << "Usage: write <file> <text>" << endl;
} else {
eshaanOSfs.writeFile(fileName, text);
}
} else if (command == "ls") {
vector<string> directory = eshaanOSfs.listDirectory();
if (directory.empty()) {
cout << "Directory is empty." << endl;
} else {
cout << "Files in directory:" << endl;
for (const string& file : directory) {
cout << file << endl;
}
}
} else {
cout << "Unknown command. Type 'help' for available commands." << endl;
}
}
}
int main() {
cout << "--- eshaanOS CLI Automated Test ---" << endl;
testEshaanOSCLI();
return 0;
}