Add testthreadexecutor.cpp
This commit is contained in:
parent
98ae660260
commit
c27e631aa2
4
Makefile
4
Makefile
|
@ -56,6 +56,7 @@ TESTOBJ = test/testautovariables.o \
|
||||||
test/testsimplifytokens.o \
|
test/testsimplifytokens.o \
|
||||||
test/teststl.o \
|
test/teststl.o \
|
||||||
test/testsuite.o \
|
test/testsuite.o \
|
||||||
|
test/testthreadexecutor.o \
|
||||||
test/testtoken.o \
|
test/testtoken.o \
|
||||||
test/testtokenize.o \
|
test/testtokenize.o \
|
||||||
test/testunusedfunctions.o \
|
test/testunusedfunctions.o \
|
||||||
|
@ -225,6 +226,9 @@ test/teststl.o: test/teststl.cpp lib/tokenize.h lib/classinfo.h lib/token.h lib/
|
||||||
test/testsuite.o: test/testsuite.cpp test/testsuite.h lib/errorlogger.h lib/settings.h
|
test/testsuite.o: test/testsuite.cpp test/testsuite.h lib/errorlogger.h lib/settings.h
|
||||||
$(CXX) $(CXXFLAGS) -Ilib -c -o test/testsuite.o test/testsuite.cpp
|
$(CXX) $(CXXFLAGS) -Ilib -c -o test/testsuite.o test/testsuite.cpp
|
||||||
|
|
||||||
|
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
|
||||||
|
$(CXX) $(CXXFLAGS) -Ilib -c -o test/testthreadexecutor.o test/testthreadexecutor.cpp
|
||||||
|
|
||||||
test/testtoken.o: test/testtoken.cpp test/testsuite.h lib/errorlogger.h lib/settings.h lib/tokenize.h lib/classinfo.h lib/token.h
|
test/testtoken.o: test/testtoken.cpp test/testsuite.h lib/errorlogger.h lib/settings.h lib/tokenize.h lib/classinfo.h lib/token.h
|
||||||
$(CXX) $(CXXFLAGS) -Ilib -c -o test/testtoken.o test/testtoken.cpp
|
$(CXX) $(CXXFLAGS) -Ilib -c -o test/testtoken.o test/testtoken.cpp
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,11 @@ ThreadExecutor::~ThreadExecutor()
|
||||||
//dtor
|
//dtor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ThreadExecutor::addFileContent(const std::string &path, const std::string &content)
|
||||||
|
{
|
||||||
|
_fileContents[ path ] = content;
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
////// This code is for __GNUC__ and __sun only ///////////////////////////////
|
////// This code is for __GNUC__ and __sun only ///////////////////////////////
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -155,7 +160,18 @@ unsigned int ThreadExecutor::check()
|
||||||
{
|
{
|
||||||
CppCheck fileChecker(*this);
|
CppCheck fileChecker(*this);
|
||||||
fileChecker.settings(_settings);
|
fileChecker.settings(_settings);
|
||||||
fileChecker.addFile(_filenames[i]);
|
|
||||||
|
if (_fileContents.size() > 0 && _fileContents.find(_filenames[i]) != _fileContents.end())
|
||||||
|
{
|
||||||
|
// File content was given as a string
|
||||||
|
fileChecker.addFile(_filenames[i], _fileContents[ _filenames[i] ]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Read file from a file
|
||||||
|
fileChecker.addFile(_filenames[i]);
|
||||||
|
}
|
||||||
|
|
||||||
unsigned int resultOfCheck = fileChecker.check();
|
unsigned int resultOfCheck = fileChecker.check();
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << resultOfCheck;
|
oss << resultOfCheck;
|
||||||
|
|
|
@ -38,6 +38,14 @@ public:
|
||||||
virtual void reportOut(const std::string &outmsg);
|
virtual void reportOut(const std::string &outmsg);
|
||||||
virtual void reportErr(const ErrorLogger::ErrorMessage &msg);
|
virtual void reportErr(const ErrorLogger::ErrorMessage &msg);
|
||||||
virtual void reportStatus(unsigned int index, unsigned int max);
|
virtual void reportStatus(unsigned int index, unsigned int max);
|
||||||
|
/**
|
||||||
|
* @brief Add content to a file, to be used in unit testing.
|
||||||
|
*
|
||||||
|
* @param path File name (used as a key to link with real file).
|
||||||
|
* @param content If the file would be a real file, this should be
|
||||||
|
* the content of the file.
|
||||||
|
*/
|
||||||
|
void addFileContent(const std::string &path, const std::string &content);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::vector<std::string> &_filenames;
|
const std::vector<std::string> &_filenames;
|
||||||
|
@ -45,6 +53,9 @@ private:
|
||||||
ErrorLogger &_errorLogger;
|
ErrorLogger &_errorLogger;
|
||||||
unsigned int _fileCount;
|
unsigned int _fileCount;
|
||||||
|
|
||||||
|
/** @brief Key is file name, and value is the content of the file */
|
||||||
|
std::map<std::string, std::string> _fileContents;
|
||||||
|
|
||||||
#if (defined(__GNUC__) || defined(__sun)) && !defined(__MINGW32__)
|
#if (defined(__GNUC__) || defined(__sun)) && !defined(__MINGW32__)
|
||||||
private:
|
private:
|
||||||
bool handleRead(unsigned int &result);
|
bool handleRead(unsigned int &result);
|
||||||
|
|
|
@ -137,6 +137,7 @@
|
||||||
<Unit filename="test/teststl.cpp" />
|
<Unit filename="test/teststl.cpp" />
|
||||||
<Unit filename="test/testsuite.cpp" />
|
<Unit filename="test/testsuite.cpp" />
|
||||||
<Unit filename="test/testsuite.h" />
|
<Unit filename="test/testsuite.h" />
|
||||||
|
<Unit filename="test/testthreadexecutor.cpp" />
|
||||||
<Unit filename="test/testtoken.cpp" />
|
<Unit filename="test/testtoken.cpp" />
|
||||||
<Unit filename="test/testtokenize.cpp" />
|
<Unit filename="test/testtokenize.cpp" />
|
||||||
<Unit filename="test/testunusedfunctions.cpp" />
|
<Unit filename="test/testunusedfunctions.cpp" />
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
/*
|
||||||
|
* Cppcheck - A tool for static C/C++ code analysis
|
||||||
|
* Copyright (C) 2007-2010 Daniel Marjamäki and Cppcheck team.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
// The preprocessor that Cppcheck uses is a bit special. Instead of generating
|
||||||
|
// the code for a known configuration, it generates the code for each configuration.
|
||||||
|
|
||||||
|
|
||||||
|
#include "cppcheck.h"
|
||||||
|
#include "testsuite.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
extern std::ostringstream errout;
|
||||||
|
extern std::ostringstream output;
|
||||||
|
|
||||||
|
class TestThreadExecutor : public TestFixture
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TestThreadExecutor() : TestFixture("TestThreadExecutor")
|
||||||
|
{ }
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void check(const std::string &data)
|
||||||
|
{
|
||||||
|
errout.str("");
|
||||||
|
output.str("");
|
||||||
|
}
|
||||||
|
|
||||||
|
void run()
|
||||||
|
{
|
||||||
|
TEST_CASE(jobs);
|
||||||
|
}
|
||||||
|
|
||||||
|
void jobs()
|
||||||
|
{
|
||||||
|
errout.str("");
|
||||||
|
output.str("");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
REGISTER_TEST(TestThreadExecutor)
|
Loading…
Reference in New Issue