|
| 1 | +/* |
| 2 | + * Cppcheck - A tool for static C/C++ code analysis |
| 3 | + * Copyright (C) 2007-2011 Daniel Marjamäki and Cppcheck team. |
| 4 | + * |
| 5 | + * This program is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU General Public License as published by |
| 7 | + * the Free Software Foundation, either version 3 of the License, or |
| 8 | + * (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License |
| 16 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + */ |
| 18 | + |
| 19 | +#include "testsuite.h" |
| 20 | +#include "filelister.h" |
| 21 | +#include <fstream> |
| 22 | +#include <algorithm> |
| 23 | + |
| 24 | +class TestFileLister: public TestFixture |
| 25 | +{ |
| 26 | +public: |
| 27 | + TestFileLister() |
| 28 | + :TestFixture("TestFileLister") |
| 29 | + {} |
| 30 | + |
| 31 | +private: |
| 32 | + void run() |
| 33 | + { |
| 34 | + // bail out if the tests are not executed from the base folder |
| 35 | + { |
| 36 | + std::ifstream fin("test/testfilelister.cpp"); |
| 37 | + if (!fin.is_open()) |
| 38 | + return; |
| 39 | + } |
| 40 | + |
| 41 | + TEST_CASE(isDirectory); |
| 42 | + TEST_CASE(recursiveAddFiles); |
| 43 | + } |
| 44 | + |
| 45 | + void isDirectory() |
| 46 | + { |
| 47 | + ASSERT_EQUALS(false, FileLister::isDirectory("readme.txt")); |
| 48 | + ASSERT_EQUALS(true, FileLister::isDirectory("lib")); |
| 49 | + } |
| 50 | + |
| 51 | + void recursiveAddFiles() |
| 52 | + { |
| 53 | + // Recursively add add files.. |
| 54 | + std::vector<std::string> filenames; |
| 55 | + FileLister::recursiveAddFiles(filenames, "."); |
| 56 | +/* |
| 57 | + for (unsigned int i = 0; i < filenames.size(); ++i) |
| 58 | + std::cout << filenames[i] << std::endl; |
| 59 | +*/ |
| 60 | + // Make sure source files are added.. |
| 61 | + ASSERT(std::find(filenames.begin(), filenames.end(), "./cli/main.cpp") != filenames.end()); |
| 62 | + ASSERT(std::find(filenames.begin(), filenames.end(), "./lib/token.cpp") != filenames.end()); |
| 63 | + ASSERT(std::find(filenames.begin(), filenames.end(), "./lib/tokenize.cpp") != filenames.end()); |
| 64 | + ASSERT(std::find(filenames.begin(), filenames.end(), "./test/testfilelister.cpp") != filenames.end()); |
| 65 | + |
| 66 | + // Make sure headers are not added.. |
| 67 | + ASSERT(std::find(filenames.begin(), filenames.end(), "./lib/tokenize.h") == filenames.end()); |
| 68 | + } |
| 69 | +}; |
| 70 | + |
| 71 | +REGISTER_TEST(TestFileLister) |
| 72 | + |
0 commit comments