FreeYourSoul / FSeam

Cpp header only library to manage compile time mock class generated via Python script
MIT License
86 stars 8 forks source link

Compile error with constructor #4

Closed allspark closed 5 years ago

allspark commented 5 years ago

Describe the bug

FSeam_Tutorial/cmake-build-debug/ClassesToMock.fseam.cc:17:51: error: return type specification for constructor invalid

To Reproduce Steps to reproduce the behavior:

in the file: https://github.com/FreeYourSoul/FSeam_Tutorial/blob/master/ClassMock_Example/ClassesToMock.hh

add a constructor GameOfThronesDatabase();

Desktop (please complete the following information):

FreeYourSoul commented 5 years ago

Hello, Could you send me the generated ClassesToMock.fseam.cc you have? Normally the compiler provided constructor should be enough (no need to explicitly make one). This error is intriguing

allspark commented 5 years ago

sure, here:

this line: void GameOfThronesDatabase::GameOfThronesDatabase()

/**
 * FSeam generated class for ClassesToMock.hh
 * Please do not modify
 */

// includes
#include <vector>
#include <string>
#include <functional>
#include <FSeamMockData.hpp>
#include <FSeam/FSeam.hpp>
#include <ClassesToMock.hh>

// GameOfThronesDatabase public
// Methods Mocked Implementation for class GameOfThronesDatabase

void GameOfThronesDatabase::GameOfThronesDatabase() {
    auto mockVerifier = (FSeam::MockVerifier::instance().isMockRegistered(this)) ?
        FSeam::MockVerifier::instance().getMock(this, "GameOfThronesDatabase") :
        FSeam::MockVerifier::instance().getDefaultMock("GameOfThronesDatabase");
    FSeam::GameOfThronesDatabaseData data {};

    mockVerifier->invokeDupedMethod(__func__, &data);
    mockVerifier->methodCall(__func__, &data);

}

bool GameOfThronesDatabase::isPlayerWinnerOfGameOfThrones(const std::string & name) {
    auto mockVerifier = (FSeam::MockVerifier::instance().isMockRegistered(this)) ?
        FSeam::MockVerifier::instance().getMock(this, "GameOfThronesDatabase") :
        FSeam::MockVerifier::instance().getDefaultMock("GameOfThronesDatabase");
    FSeam::GameOfThronesDatabaseData data {};

    if (std::is_copy_constructible<std::decay<const std::string &>>())
        data.isPlayerWinnerOfGameOfThrones_name_ParamValue = name;
    mockVerifier->invokeDupedMethod(__func__, &data);
    mockVerifier->methodCall(__func__, &data);
    return data.isPlayerWinnerOfGameOfThrones_ReturnValue;
}

std::vector<int> GameOfThronesDatabase::getGoodSeasons(int season) {
    auto mockVerifier = (FSeam::MockVerifier::instance().isMockRegistered(this)) ?
        FSeam::MockVerifier::instance().getMock(this, "GameOfThronesDatabase") :
        FSeam::MockVerifier::instance().getDefaultMock("GameOfThronesDatabase");
    FSeam::GameOfThronesDatabaseData data {};

    if (std::is_copy_constructible<std::decay<int>>())
        data.getGoodSeasons_season_ParamValue = season;
    mockVerifier->invokeDupedMethod(__func__, &data);
    mockVerifier->methodCall(__func__, &data);
    return data.getGoodSeasons_ReturnValue;
}

std::vector<int> GameOfThronesDatabase::getNotSoGoodSeasons(int season) {
    auto mockVerifier = (FSeam::MockVerifier::instance().isMockRegistered(this)) ?
        FSeam::MockVerifier::instance().getMock(this, "GameOfThronesDatabase") :
        FSeam::MockVerifier::instance().getDefaultMock("GameOfThronesDatabase");
    FSeam::GameOfThronesDatabaseData data {};

    if (std::is_copy_constructible<std::decay<int>>())
        data.getNotSoGoodSeasons_season_ParamValue = season;
    mockVerifier->invokeDupedMethod(__func__, &data);
    mockVerifier->methodCall(__func__, &data);
    return data.getNotSoGoodSeasons_ReturnValue;
}

// GameOfThronesDatabase protected
// Methods Mocked Implementation for class GameOfThronesDatabase

// GameOfThronesDatabase private
// Methods Mocked Implementation for class GameOfThronesDatabase
FreeYourSoul commented 5 years ago

That is strange, the python code analyzer is only creating implementation of element it can read in the class. Either your ClassesToMock.hh has a constructor. Either your FSeam installation has an issue, did you try reinstalling FSeam? My generated file look like that:

/**
 * FSeam generated class for ClassesToMock.hh
 * Please do not modify
 */

// includes
#include <vector>
#include <string>
#include <functional>
#include <FSeamMockData.hpp>
#include <FSeam/FSeam.hpp>
#include <ClassesToMock.hh>

// GameOfThronesDatabase protected
// Methods Mocked Implementation for class GameOfThronesDatabase

// GameOfThronesDatabase public
// Methods Mocked Implementation for class GameOfThronesDatabase

bool GameOfThronesDatabase::isPlayerWinnerOfGameOfThrones(const std::string & name) {
    auto mockVerifier = (FSeam::MockVerifier::instance().isMockRegistered(this)) ?
        FSeam::MockVerifier::instance().getMock(this, "GameOfThronesDatabase") :
        FSeam::MockVerifier::instance().getDefaultMock("GameOfThronesDatabase");
    FSeam::GameOfThronesDatabaseData data {};

    if (std::is_copy_constructible<std::decay<const std::string &>>())
        data.isPlayerWinnerOfGameOfThrones_name_ParamValue = name;
    mockVerifier->invokeDupedMethod(__func__, &data);
    mockVerifier->methodCall(__func__, &data);
    return data.isPlayerWinnerOfGameOfThrones_ReturnValue;
}

std::vector<int> GameOfThronesDatabase::getGoodSeasons(int season) {
    auto mockVerifier = (FSeam::MockVerifier::instance().isMockRegistered(this)) ?
        FSeam::MockVerifier::instance().getMock(this, "GameOfThronesDatabase") :
        FSeam::MockVerifier::instance().getDefaultMock("GameOfThronesDatabase");
    FSeam::GameOfThronesDatabaseData data {};

    if (std::is_copy_constructible<std::decay<int>>())
        data.getGoodSeasons_season_ParamValue = season;
    mockVerifier->invokeDupedMethod(__func__, &data);
    mockVerifier->methodCall(__func__, &data);
    return data.getGoodSeasons_ReturnValue;
}

std::vector<int> GameOfThronesDatabase::getNotSoGoodSeasons(int season) {
    auto mockVerifier = (FSeam::MockVerifier::instance().isMockRegistered(this)) ?
        FSeam::MockVerifier::instance().getMock(this, "GameOfThronesDatabase") :
        FSeam::MockVerifier::instance().getDefaultMock("GameOfThronesDatabase");
    FSeam::GameOfThronesDatabaseData data {};

    if (std::is_copy_constructible<std::decay<int>>())
        data.getNotSoGoodSeasons_season_ParamValue = season;
    mockVerifier->invokeDupedMethod(__func__, &data);
    mockVerifier->methodCall(__func__, &data);
    return data.getNotSoGoodSeasons_ReturnValue;
}

// GameOfThronesDatabase private
// Methods Mocked Implementation for class GameOfThronesDatabase
allspark commented 5 years ago

Hi

yes my ClassesToMock.hh has a constructor, i added it there to test it.

so FSeam can't be used on classes with constructors?

FreeYourSoul commented 5 years ago

I need to test it, I only did tests with a constructor that has the body in the header file (as usually my constructor just use the initializer parameters to setup the class) or with compiler generated one. I come back to you when I tested / fix in case of issue.

FreeYourSoul commented 5 years ago

The Generator is not taking into account constructor or destructor for the generation, and thus add a return value to it. My bad. I will fix it right away.

FreeYourSoul commented 5 years ago

A fix has been provided: It fix the issue with constructor and destructor (as it had the same issue). The destructor took a little bit more time as the syntax with ~ doesn't fit perfectly with automated generation.

Please, update your FSeam and you can retry.

allspark commented 5 years ago

thx works now