⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example_test.cpp

📁 C++的一个好库。。。现在很流行
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// (C) Copyright Jonathan Turkanis 2005.
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)

// See http://www.boost.org/libs/iostreams for documentation.

#include <map>
#include <boost/iostreams/detail/ios.hpp>  // failure.
#include <boost/iostreams/device/file.hpp>
#include <boost/iostreams/filter/test.hpp>
#include <boost/iostreams/stream.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/test/test_tools.hpp>
#include <boost/test/unit_test.hpp>
#include "../example/container_device.hpp"
#include "../example/dictionary_filter.hpp"
#include "../example/line_wrapping_filter.hpp"
#include "../example/shell_comments_filter.hpp"
#include "../example/tab_expanding_filter.hpp"
#include "../example/unix2dos_filter.hpp"
#include "./detail/verification.hpp"
#include "./detail/sequence.hpp"
#include "./detail/temp_file.hpp"

using boost::unit_test::test_suite;
namespace io = boost::iostreams;
namespace ex = boost::iostreams::example;

//------------------container_device test-------------------------------------//

void container_device_test()
{
    using namespace std;
    using namespace boost::iostreams::test;

    typedef vector<char>                       vector_type;
    typedef ex::container_source<vector_type>  vector_source;
    typedef ex::container_sink<vector_type>    vector_sink;
    typedef ex::container_device<vector_type>  vector_device;

    {
        test_sequence<>                     seq;
        test_file                           file;
        io::stream<vector_source>    first(seq);
        io::stream<io::file_source>  second(file.name(), in_mode);
        BOOST_CHECK(compare_streams_in_chunks(first, second));
    }

    {
        std::vector<char>              first;
        test_sequence<>                second;
        io::stream<vector_sink> out(first);
        write_data_in_chunks(out);
        BOOST_CHECK(first == second);
    }

    {
        vector<char>                     v;
        io::stream<vector_device> io(v);
        BOOST_CHECK(test_seekable_in_chunks(io));
    }
}

//------------------dictionary_filter test------------------------------------//

void dictionary_filter_test()
{
    using namespace std;

    io::example::dictionary d;

    // See http://english2american.com.
    d.add("answerphone",  "answering machine");
    d.add("bloke",        "guy");
    d.add("gearbox",      "transmission");
    d.add("ironmonger",   "hardware shop");
    d.add("loo",          "restroom");
    d.add("lorry",        "truck");
    d.add("rubber",       "eraser");
    d.add("spanner",      "monkey wrench");
    d.add("telly",        "TV");
    d.add("tyre",         "tire");
    d.add("waistcoat",    "vest");
    d.add("windscreen",   "windshield");

    const std::string input = // Note: last character is non-alphabetic.
        "I had a message on my answerphone from the bloke at the car "
        "dealership that the windscreen and tyre on my lorry were replaced. "
        "However, the gearbox would not be ready until tomorrow since the "
        "spanner that they needed was broken and they had to go to the "
        "ironmonger to buy a replacement. Since my lorry was not ready, "
        "I decided to take the bus downtown and buy a new waistcoat. I "
        "also stopped at the liquor store to buy some wine. I came home "
        "and watched the telly and drank my wine. I also worked on a "
        "crossword puzzle. Fortunately I had a pencil with a new rubber. "
        "During that evening I made frequent trips to the loo due to my "
        "excessive drinking";

    const std::string output = // Note: last character is non-alphabetic.
        "I had a message on my answering machine from the guy at the car "
        "dealership that the windshield and tire on my truck were replaced. "
        "However, the transmission would not be ready until tomorrow since "
        "the monkey wrench that they needed was broken and they had to go to "
        "the hardware shop to buy a replacement. Since my truck was not ready, "
        "I decided to take the bus downtown and buy a new vest. I also stopped "
        "at the liquor store to buy some wine. I came home and watched the TV "
        "and drank my wine. I also worked on a crossword puzzle. Fortunately I "
        "had a pencil with a new eraser. During that evening I made frequent "
        "trips to the restroom due to my excessive drinking";

    BOOST_CHECK(
        io::test_input_filter( io::example::dictionary_stdio_filter(d),
                               input, output )
    );

    BOOST_CHECK(
        io::test_output_filter( io::example::dictionary_stdio_filter(d),
                                input, output )
    );

    BOOST_CHECK(
        io::test_input_filter( io::example::dictionary_input_filter(d),
                               input, output )
    );

    BOOST_CHECK(
        io::test_output_filter( io::example::dictionary_output_filter(d),
                                input, output )
    );
}

//------------------line_wrapping_filter test---------------------------------//

void line_wrapping_filter_test()
{
    using namespace std;

    const std::string input =
        "I had a message on my answerphone from the bloke at the car \n"
        "dealership that the windscreen and tyre on my lorry were replaced. \n"
        "However, the gearbox would not be ready until tomorrow since the \n"
        "spanner that they needed was broken and they had to go to the \n"
        "ironmonger to buy a replacement. Since my lorry was not ready, \n"
        "I decided to take the bus downtown and buy a new waistcoat. I \n"
        "also stopped at the liquor store to buy some wine. I came home \n"
        "and watched the telly and drank my wine. I also worked on a \n"
        "crossword puzzle. Fortunately I had a pencil with a new rubber. \n"
        "During that evening I made frequent trips to the loo due to my \n"
        "excessive drinking.";

    const std::string output =
        "I had a message on my answerphone from t\n"
        "he bloke at the car \n"
        "dealership that the windscreen and tyre \n"
        "on my lorry were replaced. \n"
        "However, the gearbox would not be ready \n"
        "until tomorrow since the \n"
        "spanner that they needed was broken and \n"
        "they had to go to the \n"
        "ironmonger to buy a replacement. Since m\n"
        "y lorry was not ready, \n"
        "I decided to take the bus downtown and b\n"
        "uy a new waistcoat. I \n"
        "also stopped at the liquor store to buy \n"
        "some wine. I came home \n"
        "and watched the telly and drank my wine.\n"
        " I also worked on a \n"
        "crossword puzzle. Fortunately I had a pe\n"
        "ncil with a new rubber. \n"
        "During that evening I made frequent trip\n"
        "s to the loo due to my \n"
        "excessive drinking.";

    BOOST_CHECK(
        io::test_input_filter( io::example::line_wrapping_stdio_filter(40),
                               input, output )
    );

    BOOST_CHECK(
        io::test_output_filter( io::example::line_wrapping_stdio_filter(40),
                                input, output )
    );

    BOOST_CHECK(
        io::test_input_filter( io::example::line_wrapping_input_filter(40),
                               input, output )
    );

    BOOST_CHECK(
        io::test_output_filter( io::example::line_wrapping_output_filter(40),
                                input, output )
    );
}

//------------------shell_comments_filter test--------------------------------//

void shell_comments_filter_test()
{
    using namespace std;

    const std::string input = // From <libs/filesystem/build/Jamfile>.
        "lib boost_filesystem\n"
        "     : ../src/$(SOURCES).cpp\n"
        "     : # build requirements\n"
        "       [ common-names ] # magic for install and auto-link features\n"
        "       <include>$(BOOST_ROOT) <sysinclude>$(BOOST_ROOT)\n"
        "       <no-warn>exception.cpp <no-warn>operations_posix_windows.cpp\n"
        "     : debug release  # build variants\n"
        "     ;\n"
        "\n"
        "dll boost_filesystem\n"
        "     : ../src/$(SOURCES).cpp\n"
        "     : # build requirements\n"
        "       [ common-names ]  # magic for install and auto-link features\n"
        "       <define>BOOST_FILESYSTEM_DYN_LINK=1  # tell source we're building dll's\n"
        "       <runtime-link>dynamic  # build only for dynamic runtimes\n"
        "       <include>$(BOOST_ROOT) <sysinclude>$(BOOST_ROOT)\n"
        "       <no-warn>exception.cpp <no-warn>operations_posix_windows.cpp\n"
        "     : debug release  # build variants\n"
        "     ;";

    const std::string output =
        "lib boost_filesystem\n"
        "     : ../src/$(SOURCES).cpp\n"
        "     : \n"
        "       [ common-names ] \n"
        "       <include>$(BOOST_ROOT) <sysinclude>$(BOOST_ROOT)\n"
        "       <no-warn>exception.cpp <no-warn>operations_posix_windows.cpp\n"
        "     : debug release  \n"
        "     ;\n"
        "\n"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -