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
|
cout << "================= Test 17 =================" << endl;
delete system;
cout << "System deleted. I shall make sure there is no memory leak." << endl;
cout << "==========================================" << endl;
cout << endl;
cout << endl;
}
{
cout << "Testing LLDirectory below..." << endl << endl;
cout << "================= Test 1 =================" << endl;
Directory* r = new LLDirectory("\\", NULL);
cout << r->addChild(true, "a") << endl;
cout << r->addChild(true, "b") << endl;
cout << r->addChild(false, "f1") << endl;
cout << r->addChild(false, "f2") << endl;
cout << r->addChild(false, "f3") << endl;
cout << r->addChild(true, "c") << endl;
cout << r->addChild(true, "c") << endl;
cout << r->addChild(true, "z") << endl;
string s = r->list();
cout << r->list() << endl;
if(s != "[a] [b] [c] f1 f2 f3 [z]")
cout << "Format/output is incorrect! Please check carefully. \nYour output= <" << s << "> \nExpected= <" << "[a] [b] [c] f1 f2 f3 [z]" << ">" << endl;
cout << "================= Test 2 =================" << endl;
cout << r->removeChild("b") << endl;
cout << r->removeChild("nope") << endl;
cout << r->list() << endl;
cout << "================= Test 3 =================" << endl;
cout << r->getPath() << endl;
cout << "================= Test 4 =================" << endl;
cout << (r->getChild("nope")==NULL?"NULL":r->getChild("nope")->getName()) << endl;
cout << (r->getChild("c")==NULL?"NULL":r->getChild("c")->getName()) << endl;
cout << "================= Test 5 =================" << endl;
Directory* c = dynamic_cast<Directory*>(r->getChild("c"));
cout << c->addChild(true, "ca") << endl;
cout << c->addChild(true, "cn") << endl;
cout << c->addChild(false, "cf1") << endl;
cout << c->list() << endl;
cout << "================= Test 6 =================" << endl;
cout << c->getPath() << endl;
cout << c->getChild("cn")->getPath() << endl;
cout << c->getChild("cf1")->getPath() << endl;
cout << "================= Test 7 =================" << endl;
delete r;
cout << "LLDirectory deleted. I shall make sure there is no memory leak." << endl;
cout << "================= Test 8 =================" << endl;
System<LLDirectory>* system = new System<LLDirectory>;
cout << system->isValidPath("") << endl;
cout << system->isValidPath("c") << endl;
cout << system->isValidPath("\\") << endl;
cout << system->isValidPath("\\c") << endl;
cout << system->isValidPath("\\c\\cn") << endl;
cout << system->isValidPath("\\c\\nope") << endl;
cout << "================= Test 9 =================" << endl;
cout << system->addDir("\\", "a") << endl;
cout << system->addDir("\\", "b") << endl;
cout << system->addFile("\\", "f1", "hi") << endl;
cout << system->addFile("\\", "f2", "hello") << endl;
cout << system->addFile("\\", "f3", "howdy") << endl;
cout << system->addDir("\\", "c") << endl;
cout << system->addDir("\\", "c") << endl;
cout << "In \\ : " << system->list("\\") << endl;
cout << "================= Test 10 =================" << endl;
cout << system->del("\\", "b") << endl;
cout << system->del("\\", "nope") << endl;
cout << "In \\ : " << system->list("\\") << endl;
cout << "================= Test 11 =================" << endl;
cout << (system->getDirectory("\\")==NULL?"NULL":"\\") << endl;
cout << (system->getDirectory("\\c")==NULL?"NULL":"c") << endl;
cout << (system->getDirectory("\\nope")==NULL?"NULL":"nope") << endl;
cout << "================= Test 12 =================" << endl;
cout << system->getDirectory("\\")->getPath() << endl;
cout << system->getDirectory("\\c")->getPath() << endl;
cout << "================= Test 13 =================" << endl;
cout << system->addDir("\\c", "ca") << endl;
cout << system->addDir("\\c", "cn") << endl;
cout << system->addFile("\\c", "cf1", "yo") << endl;
cout << "In \\c : " << system->list("\\c") << endl;
cout << (system->getFile("\\c", "cfnope")?"nope":"NULL") << endl;
cout << system->getFile("\\c", "cf1")->getContent() << endl;
system->getFile("\\c", "cf1")->setContent("yoooooooo");
cout << system->getFile("\\c", "cf1")->getContent() << endl;
cout << "================= Test 14 =================" << endl;
cout << system->getDirectory("\\c\\cn")->getPath() << endl;
cout << system->getFile("\\c", "cf1")->getPath() << endl;
cout << "================= Test 15 =================" << endl;
cout << "In \\ : " << system->list("\\") << endl;
cout << "In \\a : " << system->list("\\a") << endl;
cout << "In \\b : " << system->list("\\b") << endl;
cout << "In \\c : " << system->list("\\c") << endl;
cout << "In \\c\\cn : " << system->list("\\c\\cn") << endl;
cout << "Move result = " << system->move("\\","f2","\\c","f2") << endl;
cout << "In \\ : " << system->list("\\") << endl;
cout << "In \\a : " << system->list("\\a") << endl;
cout << "In \\b : " << system->list("\\b") << endl;
cout << "In \\c : " << system->list("\\c") << endl;
cout << "In \\c\\cn : " << system->list("\\c\\cn") << endl;
cout << "================= Test 16 =================" << endl;
cout << system->addFile("\\c\\cn","cnf","so deep!") << endl;
cout << "In \\ : " << system->list("\\") << endl;
cout << "In \\a : " << system->list("\\a") << endl;
cout << "In \\b : " << system->list("\\b") << endl;
cout << "In \\c : " << system->list("\\c") << endl;
cout << "In \\c\\cn : " << system->list("\\c\\cn") << endl;
cout << "In \\a\\c : " << system->list("\\a\\c") << endl;
cout << "In \\a\\c\\cn : " << system->list("\\a\\c\\cn") << endl;
cout << system->getFile("\\c\\cn", "cnf")->getPath() << endl;
cout << "Move result = " << system->move("\\","c","\\a","c") << endl;
cout << "In \\ : " << system->list("\\") << endl;
cout << "In \\a : " << system->list("\\a") << endl;
cout << "In \\b : " << system->list("\\b") << endl;
cout << "In \\c : " << system->list("\\c") << endl;
cout << "In \\c\\cn : " << system->list("\\c\\cn") << endl;
cout << "In \\a\\c : " << system->list("\\a\\c") << endl;
cout << "In \\a\\c\\cn : " << system->list("\\a\\c\\cn") << endl;
cout << system->getFile("\\a\\c\\cn", "cnf")->getPath() << endl;
cout << "================= Test 17 =================" << endl;
delete system;
cout << "System deleted. I shall make sure there is no memory leak." << endl;
cout << "===========================================" << endl;
cout << endl;
cout << endl;
}
return 0;
}
| |