Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9205099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:52:21+00:00 2026-06-17T23:52:21+00:00

I need to write tests(using google testing framework) for small study program that was

  • 0

I need to write tests(using google testing framework) for small study program that was written not by me. (it’s just small console game which can get modes from command line or just get it in runtime)
There is a problem: I can’t change the souce code but there is in almost all methods used cout and cin. and my question is “how to answer on requests (cin) of programm while testing (something like get data for cin from string )?“.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T23:52:22+00:00Added an answer on June 17, 2026 at 11:52 pm

    Assuming you can control main() (or some other function called before the functions to be tested) you can change where std::cin reads from and where std::cout writes to:

    int main(int ac, char* av[]) {
        std::streambuf* orig = std::cin.rdbuf();
        std::istringstream input("whatever");
        std::cin.rdbuf(input.rdbuf());
        // tests go here
        std::cin.rdbuf(orig);
    }
    

    (likewise for std::cout)

    This example saves the original stream buffer of std::cin so it can be replaced before leaving main(). It then sets up std::cin to read from a string stream. It can be any other stream buffer as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the Google App Engine testbed framework to write test cases with
I'm working in a framework that uses commons-fileupload. Now I need to write unit
I am trying to write integration tests. Therefore I need the start methods of
I'd like to write some tests for delete() in Grails. These need to be
If you need to choose the language to write your integration tests, what language
Problem I have a UDPlistener application that I need to write a unit test
I'm just starting to play around with Google Guice as a dependency injection framework
I'm trying to write my first Perl program. If you think that Perl is
I need to write a simple WinForms apps that can be fired to test
I need to add GPS functionality to an existing Blackberry Application that I've written.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.