Ejemplo n.º 1
0
#include <lab14a.h>
#include <doctest.h>

#include <iostream>
#include <sstream>
#include <string>
#include <vector>

SCENARIO( "treat animals") {
  GIVEN( "an vector of unique_ptr<Animal>" ) {
    auto zoo = make_animals();
    WHEN( "n is 1" ) {
      THEN( "each animal should complain about a shot" ) {
        std::ostringstream actual;
        auto cout_buff = std::cout.rdbuf(); // save pointer to std::cout buffer
        std::cout.rdbuf(actual.rdbuf());     // sub local for cout
        treat_animals(zoo);
        std::cout.rdbuf(cout_buff);          // restore cout

        std::string expected = "meow.\n";
        auto pos = actual.str().find_first_of(expected); 
        REQUIRE_MESSAGE(pos != std::string::npos, "Did not give a Cat a shot");
        
        expected = "arf, arf!\n";
        pos = actual.str().find_first_of(expected); 
        REQUIRE_MESSAGE(pos != std::string::npos, "Did not give a Dog a shot");
        
        expected = "Hoot!\n";
        pos = actual.str().find_first_of(expected); 
        REQUIRE_MESSAGE(pos != std::string::npos, "Did not give a Owl a shot");
        
Ejemplo n.º 2
0
#include <unordered_map>
#include <unordered_set>
#include <iostream>

#if defined(_MSC_VER)
    #pragma warning (push)
    #pragma warning (disable : 4189) // local variable is initialized but not referenced
#endif

TEST_CASE("README", "[hide]")
{
    {
        // redirect std::cout for the README file
        auto old_cout_buffer = std::cout.rdbuf();
        std::ostringstream new_stream;
        std::cout.rdbuf(new_stream.rdbuf());
        {
            // create an empty structure (null)
            json j;

            // add a number that is stored as double (note the implicit conversion of j to an object)
            j["pi"] = 3.141;

            // add a Boolean that is stored as bool
            j["happy"] = true;

            // add a string that is stored as std::string
            j["name"] = "Niels";

            // add another null object by passing nullptr
            j["nothing"] = nullptr;
Ejemplo n.º 3
0
// Copyright (C) 2016 Jonathan Müller <*****@*****.**>
// This file is subject to the license terms in the LICENSE file
// found in the top-level directory of this distribution.

#include <standardese/output.hpp>

#include <catch.hpp>

using namespace standardese;

TEST_CASE("output_stream_base")
{
    std::ostringstream str;
    streambuf_output out(*str.rdbuf());

    SECTION("newline test")
    {
        out.write_char('a');
        out.write_new_line();

        out.write_str("b\n", 2);
        out.write_new_line();

        out.write_str("c ignore me", 1);
        out.write_blank_line();

        out.write_str("d\n", 2);
        out.write_blank_line();

        REQUIRE(str.str() == "a\nb\nc\n\nd\n\n");
    }
Ejemplo n.º 4
0
 Serialize(const void* Buffer, std::size_t BufferSize) : Data()
 {
     Data.rdbuf()->pubsetbuf(const_cast<char*>(reinterpret_cast<const char*>(Buffer)), BufferSize);
 }
 ExpectedStreamOutput(std::ostream &stream,const char *expected_)
     : expected(expected_), original_stream(stream), original_streambuf(*(stream.rdbuf(substituted_stream.rdbuf())))
 {
 }
 * Sources     :
 */
#define CATCH_CONFIG_MAIN
#include "catch.hpp"

#include <sstream>
#include <iostream>
#include <string>
#include "lab_5.h"
using std::string;

TEST_CASE("Hello Function") {
  string cout_output;
  std::streambuf* oldCout = cout.rdbuf();
  std::ostringstream captureCout;
  cout.rdbuf(captureCout.rdbuf());
  Hello();
  cout.rdbuf(oldCout);
  cout_output = captureCout.str();
  SECTION("Hello()") {
    CHECK(cout_output == "Hello world!");
  }
  captureCout.str("");
}

TEST_CASE("Print Message Function") {
  string cout_output;
  std::streambuf* oldCout = cout.rdbuf();
  std::ostringstream captureCout;
  cout.rdbuf(captureCout.rdbuf());
  PrintMessage("Hello again!");