I have the below original file that has class and structure.
windowsdata.h
struct windows_data
{
std::wstring computer_model;
std::wstring computer_name;
std::wstring computer_manufacturer;
};
class windows_interface
{
public:
virtual void read_windows_data() = 0;
virtual ~windows_interface();
};
std::wstring get_wmi_interface();
To use gtest and gmock, i followed the below approach:
test_all_modules.cpp
#include "stdafx.h"
#include <Windows.h>
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "test_all_modules.h"
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
::testing::InitGoogleMock(&argc, argv);
int result = RUN_ALL_TESTS();
getchar();
return result;
}
test_all_modules.h
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include <string>
#include <system_error>
using namespace ::testing;
class test_windows_data : public ::testing::Test
{
protected:
test_windows_data() {};
~test_windows_data() {};
void SetUp() override {};
};
In the below file I am using the gtest to call the original function and to test the structure variables. Is it the correct way to test the structure variables using gtest?
And also I am using gmock by creating the mock class.
But when I am usig MOCK_METHOD0, it is showing Function definition for "MOCK_METHOD0" not found. Do I need to define the "MOCK_METHOD0"? If so, please help me how to define?
Could anyone please help me how to resolve? I am using gtest and gmock version 1.8.1. And properly pointing to correct lib and include files.
test_windows_data.cpp
#include "stdafx.h"
#include "test_all_modules.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
using namespace MyTest;
TEST_F(test_windows_data, test_windows_data_default)
{
windows_data windows_data_obj; // original structure
std::wstring ptr_windows_interface = get_windows_interface();
windows_data_obj = ptr_windows_interface->read_windows_data();
EXPECT_GT( windows_data_obj->computer_name.length(), 0);
EXPECT_GT( windows_data_obj->computer_manufacturer.length(), 0);
EXPECT_GT( windows_data_obj->computer_model.length(), 0);
}
class mock_windows_interface : public windows_interface {
public:
MOCK_METHOD0(read_windows_data, void());
};
mock_windows_interface mock_windows;
TEST(mock_windows, test_windows_data_default) {
EXPECT_CALL(mock_windows, read_windows_data());
}
Aucun commentaire:
Enregistrer un commentaire