Commit 5fd37a6f authored by Bart van der Velden's avatar Bart van der Velden

First gmock test attempt (#54)

parent 834f489a
......@@ -88,10 +88,12 @@ if (test)
include_directories(
${gtest_SOURCE_DIR}/include
${gtest_SOURCE_DIR})
${gtest_SOURCE_DIR}
${gmock_SOURCE_DIR}/include
${gmock_SOURCE_DIR})
# Where Google Test's libraries can be found.
link_directories(${gtest_BINARY_DIR})
link_directories(${gtest_BINARY_DIR} ${gmock_BINARY_DIR})
endif()
#--------------------------------------------------------------------
......@@ -187,11 +189,13 @@ set(EXTRA_LIBS ${EXTRA_LIBS} ${Boost_LIBRARIES})
set(COMMON_SOURCES
HandleCommandLine.cpp
CommandLine.cpp
${PROJECT_BINARY_DIR}/src/version.cpp
)
set(COMMON_INCLUDES
version.h
CommandLine.h
HandleCommandLine.h
)
......
/*****************************************************************************
* Copyright 2014 Bart van der Velden <bart@muckingabout.eu> *
* *
* 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/>. *
*****************************************************************************/
#include "CommandLine.h"
#include <fstream>
#include <boost/program_options.hpp>
#include <boost/exception/all.hpp>
#include <boost/exception/get_error_info.hpp>
#include "version.h"
CommandLine::CommandLine()
{
}
CommandLine::~CommandLine()
{
}
bool CommandLine::ParseCommandLine()
{
return false;
}
std::vector<boost::filesystem::path> CommandLine::GetDirectories() const
{
std::vector<boost::filesystem::path> directories;
return directories;
}
boost::filesystem::path CommandLine::GetLogFile() const
{
boost::filesystem::path logFile;
return logFile;
}
std::string CommandLine::GetErrorMessage() const
{
std::string retVal;
return retVal;
}
std::string CommandLine::GetLogMessage() const
{
std::string retVal;
return retVal;
}
/*****************************************************************************
* Copyright 2014 Bart van der Velden <bart@muckingabout.eu> *
* *
* 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/>. *
*****************************************************************************/
#ifndef MUSICCOLLECTION_COMMANDLINE_H_INCLUDED
#define MUSICCOLLECTION_COMMANDLINE_H_INCLUDED
#include <vector>
#include <boost/filesystem.hpp>
class CommandLine
{
public:
explicit CommandLine();
virtual ~CommandLine();
virtual bool ParseCommandLine();
virtual std::vector<boost::filesystem::path> GetDirectories() const;
virtual boost::filesystem::path GetLogFile() const;
virtual std::string GetErrorMessage() const;
virtual std::string GetLogMessage() const;
private:
};
#endif // MUSICCOLLECTION_COMMANDLINE_H_INCLUDED
if(test)
# Where Google Test's libraries can be found.
# Where Google Test and Mock libraries can be found.
set(gtest_link_dir ${gtest_BINARY_DIR}/../lib/Debug)
set(gmock_link_dir ${gmock_BINARY_DIR}/../lib/Debug)
link_directories(${gtest_link_dir})
link_directories(${gtest_link_dir} ${gmock_link_dir})
if(CMAKE_DEBUG)
message(STATUS "include directories:")
......@@ -32,12 +33,15 @@ if(test)
add_definitions(${QtWidgets_DEFINITIONS})
set(INCLUDES
../HandleCommandLine.h
CommandLine-mock.h
../CommandLine.h
#../HandleCommandLine.h
../version.h
)
set(SOURCES
HandleCommandLine_test.cpp ../HandleCommandLine.cpp
CommandLine_test.cpp ../CommandLine.cpp
#HandleCommandLine_test.cpp ../HandleCommandLine.cpp
${PROJECT_BINARY_DIR}/src/version.cpp
)
......@@ -45,9 +49,9 @@ if(test)
runMusicCollectionTest
${SOURCES}
${INCLUDES}
${gtest_SOURCE_DIR}/src/gtest_main.cc)
${gmock_SOURCE_DIR}/src/gmock_main.cc)
target_link_libraries(runMusicCollectionTest gtest
target_link_libraries(runMusicCollectionTest gtest gmock
${TAGLIB_LIBRARIES}
${Boost_LIBRARIES})
......
/*****************************************************************************
* Copyright 2014 Bart van der Velden <bart@muckingabout.eu> *
* *
* 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/>. *
*****************************************************************************/
#ifndef MUSICCOLLECTION_TEST_COMMANDLINE_MOCK_H_INCLUDED
#define MUSICCOLLECTION_TEST_COMMANDLINE_MOCK_H_INCLUDED
#include "../CommandLine.h"
#include "gmock/gmock.h"
class MockCommandLine : public CommandLine
{
public:
MOCK_METHOD0(ParseCommandLine, bool());
};
#endif // MUSICCOLLECTION_TEST_COMMANDLINE_MOCK_H_INCLUDED
#include "CommandLine-mock.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
using namespace std;
using ::testing::AtLeast;
namespace fs = boost::filesystem;
TEST(CommandLineTest, EmptyPath)
{
MockCommandLine mockCmdLine;
EXPECT_CALL(mockCmdLine, ParseCommandLine()).Times(AtLeast(1));
EXPECT_FALSE(mockCmdLine.ParseCommandLine());
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment