File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -56,6 +56,7 @@ TESTOBJ = test/testautovariables.o \
5656 test/testsimplifytokens.o \
5757 test/teststl.o \
5858 test/testsuite.o \
59+ test/testthreadexecutor.o \
5960 test/testtoken.o \
6061 test/testtokenize.o \
6162 test/testunusedfunctions.o \
@@ -225,6 +226,9 @@ test/teststl.o: test/teststl.cpp lib/tokenize.h lib/classinfo.h lib/token.h lib/
225226test/testsuite.o : test/testsuite.cpp test/testsuite.h lib/errorlogger.h lib/settings.h
226227 $(CXX ) $(CXXFLAGS ) -Ilib -c -o test/testsuite.o test/testsuite.cpp
227228
229+ test/testthreadexecutor.o : test/testthreadexecutor.cpp lib/cppcheck.h lib/settings.h lib/errorlogger.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h lib/classinfo.h test/testsuite.h
230+ $(CXX ) $(CXXFLAGS ) -Ilib -c -o test/testthreadexecutor.o test/testthreadexecutor.cpp
231+
228232test/testtoken.o : test/testtoken.cpp test/testsuite.h lib/errorlogger.h lib/settings.h lib/tokenize.h lib/classinfo.h lib/token.h
229233 $(CXX ) $(CXXFLAGS ) -Ilib -c -o test/testtoken.o test/testtoken.cpp
230234
Original file line number Diff line number Diff line change @@ -40,6 +40,11 @@ ThreadExecutor::~ThreadExecutor()
4040 // dtor
4141}
4242
43+ void ThreadExecutor::addFileContent (const std::string &path, const std::string &content)
44+ {
45+ _fileContents[ path ] = content;
46+ }
47+
4348// /////////////////////////////////////////////////////////////////////////////
4449// //// This code is for __GNUC__ and __sun only ///////////////////////////////
4550// /////////////////////////////////////////////////////////////////////////////
@@ -155,7 +160,18 @@ unsigned int ThreadExecutor::check()
155160 {
156161 CppCheck fileChecker (*this );
157162 fileChecker.settings (_settings);
158- fileChecker.addFile (_filenames[i]);
163+
164+ if (_fileContents.size () > 0 && _fileContents.find (_filenames[i]) != _fileContents.end ())
165+ {
166+ // File content was given as a string
167+ fileChecker.addFile (_filenames[i], _fileContents[ _filenames[i] ]);
168+ }
169+ else
170+ {
171+ // Read file from a file
172+ fileChecker.addFile (_filenames[i]);
173+ }
174+
159175 unsigned int resultOfCheck = fileChecker.check ();
160176 std::ostringstream oss;
161177 oss << resultOfCheck;
Original file line number Diff line number Diff line change @@ -38,13 +38,24 @@ class ThreadExecutor : public ErrorLogger
3838 virtual void reportOut (const std::string &outmsg);
3939 virtual void reportErr (const ErrorLogger::ErrorMessage &msg);
4040 virtual void reportStatus (unsigned int index, unsigned int max);
41+ /* *
42+ * @brief Add content to a file, to be used in unit testing.
43+ *
44+ * @param path File name (used as a key to link with real file).
45+ * @param content If the file would be a real file, this should be
46+ * the content of the file.
47+ */
48+ void addFileContent (const std::string &path, const std::string &content);
4149
4250private:
4351 const std::vector<std::string> &_filenames;
4452 const Settings &_settings;
4553 ErrorLogger &_errorLogger;
4654 unsigned int _fileCount;
4755
56+ /* * @brief Key is file name, and value is the content of the file */
57+ std::map<std::string, std::string> _fileContents;
58+
4859#if (defined(__GNUC__) || defined(__sun)) && !defined(__MINGW32__)
4960private:
5061 bool handleRead (unsigned int &result);
Original file line number Diff line number Diff line change 137137 <Unit filename =" test/teststl.cpp" />
138138 <Unit filename =" test/testsuite.cpp" />
139139 <Unit filename =" test/testsuite.h" />
140+ <Unit filename =" test/testthreadexecutor.cpp" />
140141 <Unit filename =" test/testtoken.cpp" />
141142 <Unit filename =" test/testtokenize.cpp" />
142143 <Unit filename =" test/testunusedfunctions.cpp" />
Original file line number Diff line number Diff line change 1+ /*
2+ * Cppcheck - A tool for static C/C++ code analysis
3+ * Copyright (C) 2007-2010 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+
20+ // The preprocessor that Cppcheck uses is a bit special. Instead of generating
21+ // the code for a known configuration, it generates the code for each configuration.
22+
23+
24+ #include " cppcheck.h"
25+ #include " testsuite.h"
26+
27+ #include < algorithm>
28+ #include < map>
29+ #include < string>
30+ #include < stdexcept>
31+
32+ extern std::ostringstream errout;
33+ extern std::ostringstream output;
34+
35+ class TestThreadExecutor : public TestFixture
36+ {
37+ public:
38+ TestThreadExecutor () : TestFixture(" TestThreadExecutor" )
39+ { }
40+
41+ private:
42+
43+ void check (const std::string &data)
44+ {
45+ errout.str (" " );
46+ output.str (" " );
47+ }
48+
49+ void run ()
50+ {
51+ TEST_CASE (jobs);
52+ }
53+
54+ void jobs ()
55+ {
56+ errout.str (" " );
57+ output.str (" " );
58+ }
59+ };
60+
61+ REGISTER_TEST (TestThreadExecutor)
You can’t perform that action at this time.
0 commit comments