Speeding up test case for user input function

I have a function that accepts user input via std :: cin:

std::getline(std::cin, in);

and creates an appropriate data structure by matching it with a regular expression. The function then returns this data structure.

I am using boost.test, and I want to create a unit test to verify that the output type is correct, given some inputs. However, I do not know how to do this, since the input is not passed as an argument to the function.

EDIT: Is there an easy way to create a test boost script that passes a function string through standard input?

+5
source share
1 answer

, std::getline, , , std::istream&, std::cin. , :

my_struct my_func()
{
    //...

    std::getline(std::cin, in);

    //...
}

:

my_struct my_func(std::istream& is);

inline my_struct my_func()
{
    return my_func(std::cin);
}

my_struct my_func(std::istream& is)
{
    //...

    std::getline(is, in);

    //...
}

, my_func , std::istringstream my_func(std::istream&).

, std::getline, , , - . . , .

+7

All Articles