TEST(FileSystemIterator, multipleFiles) { TestDirectory rootDir(File("foobarfolder")); rootDir.addFile("foobar1.txt"); rootDir.addFile("foobar2.txt"); rootDir.addFile("foobar3.txt"); rootDir.addFile("foobar4.txt"); rootDir.addFile("foobar5.txt"); HashSet<String> filenames; filenames.put("foobar1.txt"); filenames.put("foobar2.txt"); filenames.put("foobar3.txt"); filenames.put("foobar4.txt"); filenames.put("foobar5.txt"); FileSystemIterator iter(rootDir.getFile()); while (iter.isValid()) { EXPECT_TRUE(filenames.hasElement(iter->getFileName())); filenames.remove(iter->getFileName()); iter.next(); } EXPECT_EQ(0u, filenames.count()); }
TEST(FileSystemIterator, defaultAcceptTest) { // setup TestDirectory rootDir(File("foobarfolder")); rootDir.addFile("foobar1.txt"); rootDir.addDirectory("foobar")->addFile("foobar2.txt"); HashSet<String> filenames; filenames.put("foobar1.txt"); filenames.put("foobar"); filenames.put("foobar2.txt"); FileSystemIterator iter(rootDir.getFile()); EXPECT_TRUE(iter.isValid()); EXPECT_TRUE(filenames.hasElement(iter->getFileName())); filenames.remove(iter->getFileName()); EXPECT_TRUE(iter.next()); EXPECT_TRUE(filenames.hasElement(iter->getFileName())); filenames.remove(iter->getFileName()); EXPECT_TRUE(iter.next()); EXPECT_TRUE(filenames.hasElement(iter->getFileName())); filenames.remove(iter->getFileName()); EXPECT_EQ(0u, filenames.count()); EXPECT_FALSE(iter.next()); EXPECT_FALSE(iter.isValid()); // iterate again, but don't finish FileSystemIterator iter2(rootDir.getFile()); }
TEST(FileSystemIterator, subSubDirs) { TestDirectory rootDir(File("foobarfolder")); TestDirectoryPtr subDir1 = rootDir.addDirectory("subdir1"); TestDirectoryPtr subDir2 = rootDir.addDirectory("subdir2"); TestDirectoryPtr subDir3 = rootDir.addDirectory("subdir3"); subDir1->addDirectory("sub1subdir1")->addFile("sub1subdir1file1")->addFile("sub1subdir1file2"); subDir1->addDirectory("sub1subdir2")->addFile("sub1subdir2file1")->addFile("sub1subdir2file2"); subDir1->addDirectory("sub1subdir3")->addFile("sub1subdir3file1")->addFile("sub1subdir3file2"); subDir2->addDirectory("sub2subdir1")->addFile("sub2subdir1file1")->addFile("sub2subdir1file2"); subDir2->addDirectory("sub2subdir2")->addFile("sub2subdir2file1")->addFile("sub2subdir2file2"); subDir2->addDirectory("sub2subdir3")->addFile("sub2subdir3file1")->addFile("sub2subdir3file2"); subDir3->addDirectory("sub3subdir1")->addFile("sub3subdir1file1")->addFile("sub3subdir1file2"); subDir3->addDirectory("sub3subdir2")->addFile("sub3subdir2file1")->addFile("sub3subdir2file2"); subDir3->addDirectory("sub3subdir3")->addFile("sub3subdir3file1")->addFile("sub3subdir3file2"); HashSet<String> filenames; filenames.put("subdir1"); filenames.put("subdir2"); filenames.put("subdir3"); filenames.put("sub1subdir1"); filenames.put("sub1subdir2"); filenames.put("sub1subdir3"); filenames.put("sub2subdir1"); filenames.put("sub2subdir2"); filenames.put("sub2subdir3"); filenames.put("sub3subdir1"); filenames.put("sub3subdir2"); filenames.put("sub3subdir3"); filenames.put("sub1subdir1file1"); filenames.put("sub1subdir2file1"); filenames.put("sub1subdir3file1"); filenames.put("sub2subdir1file1"); filenames.put("sub2subdir2file1"); filenames.put("sub2subdir3file1"); filenames.put("sub3subdir1file1"); filenames.put("sub3subdir2file1"); filenames.put("sub3subdir3file1"); filenames.put("sub1subdir1file2"); filenames.put("sub1subdir2file2"); filenames.put("sub1subdir3file2"); filenames.put("sub2subdir1file2"); filenames.put("sub2subdir2file2"); filenames.put("sub2subdir3file2"); filenames.put("sub3subdir1file2"); filenames.put("sub3subdir2file2"); filenames.put("sub3subdir3file2"); FileSystemIterator iter(rootDir.getFile()); while (iter.isValid()) { EXPECT_TRUE(filenames.hasElement(iter->getFileName())); EXPECT_EQ(CAPU_OK, filenames.remove(iter->getFileName())); iter.next(); } EXPECT_EQ(0u, filenames.count()); }