restrict_test.cpp

来自「Boost provides free peer-reviewed portab」· C++ 代码 · 共 687 行 · 第 1/2 页

CPP
687
字号
            "with large padding"        );    }}void write_direct_device() {    {        vector<char>              dest1( data_reps * data_length() +                                          2 * small_padding,                                          '\n' );        restricted_test_sequence  dest2(small_padding);        stream_offset             off = small_padding,                                  len = data_reps * data_length();        array_sink                array(&dest1[0], &dest1[0] + dest1.size());        filtering_ostream         out(BOOST_RESTRICT(array, off, len));        write_data_in_chunks(out);        out.reset();        BOOST_CHECK_MESSAGE(            std::equal(dest1.begin(), dest1.end(), dest2.begin()),            "failed writing to restriction<Direct>"        );    }    {        vector<char>              dest1(            data_reps * data_length() + small_padding, '\n');        restricted_test_sequence  dest2(small_padding, true);        stream_offset             off = small_padding;        array_sink                array(&dest1[0], &dest1[0] + dest1.size());        filtering_ostream         out(BOOST_RESTRICT(array, off));        write_data_in_chunks(out);        out.reset();        BOOST_CHECK_MESSAGE(            std::equal(dest1.begin(), dest1.end(), dest2.begin()),            "failed writing to half-open restriction<Direct>"        );    }}void write_filter() {    {        restricted_test_file       dest1(small_padding);        restricted_lowercase_file  dest2(small_padding);        stream_offset              off = small_padding,                                   len = data_reps * data_length();        filtering_ostream          out;        out.push(BOOST_RESTRICT(tolower_seekable_filter(), off, len));        out.push(file(dest1.name(), BOOST_IOS::binary));        write_data_in_chunks(out);        out.reset();        ifstream               first(dest1.name().c_str(), in_mode);        ifstream               second(dest2.name().c_str(), in_mode);        BOOST_CHECK_MESSAGE(            compare_streams_in_chunks(first, second),            "failed writing to restriction<Filter> with small padding"        );    }    {        restricted_test_file       dest1(large_padding);        restricted_lowercase_file  dest2(large_padding);        stream_offset              off = large_padding,                                   len = data_reps * data_length();        filtering_ostream          out;        out.push(BOOST_RESTRICT(tolower_seekable_filter(), off, len));        out.push(file(dest1.name(), BOOST_IOS::binary));        write_data_in_chunks(out);        out.reset();        ifstream               first(dest1.name().c_str(), in_mode);        ifstream               second(dest2.name().c_str(), in_mode);        BOOST_CHECK_MESSAGE(            compare_streams_in_chunks(first, second),            "failed writing to restriction<Filter> with large padding"        );    }    {        restricted_test_file       dest1(small_padding, true);        restricted_lowercase_file  dest2(small_padding, true);        stream_offset              off = small_padding;        filtering_ostream          out;        out.push(BOOST_RESTRICT(tolower_seekable_filter(), off));        out.push(file(dest1.name(), BOOST_IOS::binary));        write_data_in_chunks(out);        out.reset();        ifstream               first(dest1.name().c_str(), in_mode);        ifstream               second(dest2.name().c_str(), in_mode);        BOOST_CHECK_MESSAGE(            compare_streams_in_chunks(first, second),            "failed writing to restriction<Filter> with small padding"        );    }    {        restricted_test_file       dest1(large_padding, true);        restricted_lowercase_file  dest2(large_padding, true);        stream_offset              off = large_padding;        filtering_ostream          out;        out.push(BOOST_RESTRICT(tolower_seekable_filter(), off));        out.push(file(dest1.name(), BOOST_IOS::binary));        write_data_in_chunks(out);        out.reset();        ifstream                   first(dest1.name().c_str(), in_mode);        ifstream                   second(dest2.name().c_str(), in_mode);        BOOST_CHECK_MESSAGE(            compare_streams_in_chunks(first, second),            "failed writing to restriction<Filter> with large padding"        );    }}void seek_device(){    {        restricted_test_file       src(large_padding);        stream_offset              off = large_padding,                                   len = data_reps * data_length();        filtering_stream<seekable> io(            BOOST_RESTRICT(file(src.name(), BOOST_IOS::binary), off, len));        BOOST_CHECK_MESSAGE(            test_seekable_in_chunks(io),            "failed seeking within restriction<Device>"        );    }    {        restricted_test_file       src(large_padding, true);        stream_offset              off = large_padding;        filtering_stream<seekable> io(            BOOST_RESTRICT(file(src.name(), BOOST_IOS::binary), off));        BOOST_CHECK_MESSAGE(            test_seekable_in_chunks(io),            "failed seeking within half-open restriction<Device>"        );    }}void seek_direct_device(){    {        vector<char>               src(            data_reps * data_length() + 2 * small_padding, '\n');        stream_offset              off = small_padding,                                   len = data_reps * data_length();        array                      ar(&src[0], &src[0] + src.size());        filtering_stream<seekable> io(BOOST_RESTRICT(ar, off, len));        BOOST_CHECK_MESSAGE(            test_seekable_in_chars(io),            "failed seeking within restriction<Direct> with small padding"        );    }    {        vector<char>               src(            data_reps * data_length() + small_padding, '\n');        stream_offset              off = small_padding;        array                      ar(&src[0], &src[0] + src.size());        filtering_stream<seekable> io(BOOST_RESTRICT(ar, off));        BOOST_CHECK_MESSAGE(            test_seekable_in_chars(io),            "failed seeking within half-open restriction<Direct> "            "with small padding"        );    }}void seek_filter(){    {        restricted_test_file       src(small_padding);        stream_offset              off = large_padding,                                   len = data_reps * data_length();        filtering_stream<seekable> io;        io.push(BOOST_RESTRICT(identity_seekable_filter(), off, len));        io.push(file(src.name(), BOOST_IOS::binary));        BOOST_CHECK_MESSAGE(            test_seekable_in_chars(io),            "failed seeking within restriction<Device>"        );    }    {        restricted_test_file       src(small_padding, true);        stream_offset              off = large_padding;        filtering_stream<seekable> io;        io.push(BOOST_RESTRICT(identity_seekable_filter(), off));        io.push(file(src.name(), BOOST_IOS::binary));        BOOST_CHECK_MESSAGE(            test_seekable_in_chars(io),            "failed seeking within half-open restriction<Device>"        );    }}void close_device(){    // Restrict a source    {        operation_sequence  seq;        chain<input>        ch;        ch.push(            io::BOOST_RESTRICT(                closable_device<input>(seq.new_operation(1)),                 0            )        );        BOOST_CHECK_NO_THROW(ch.reset());        BOOST_CHECK_OPERATION_SEQUENCE(seq);    }    // Restrict a seekable device    {        operation_sequence  seq;        chain<seekable>     ch;        ch.push(            io::BOOST_RESTRICT(                closable_device<seekable>(seq.new_operation(1)),                 0            )        );        BOOST_CHECK_NO_THROW(ch.reset());        BOOST_CHECK_OPERATION_SEQUENCE(seq);    }    // Restrict a direct source    {        operation_sequence  seq;        chain<input>        ch;        ch.push(            io::BOOST_RESTRICT(                closable_device<direct_input>(seq.new_operation(1)),                 0            )        );        BOOST_CHECK_NO_THROW(ch.reset());        BOOST_CHECK_OPERATION_SEQUENCE(seq);    }    // Restrict a direct seekable device    {        operation_sequence  seq;        chain<seekable>     ch;        ch.push(            io::BOOST_RESTRICT(                closable_device<direct_seekable>(seq.new_operation(1)),                 0            )        );        BOOST_CHECK_NO_THROW(ch.reset());        BOOST_CHECK_OPERATION_SEQUENCE(seq);    }}void close_filter(){    // Restrict an input filter    {        operation_sequence  seq;        chain<input>        ch;        ch.push(            io::BOOST_RESTRICT(                closable_filter<input>(seq.new_operation(2)),                 0            )        );        ch.push(closable_device<input>(seq.new_operation(1)));        BOOST_CHECK_NO_THROW(ch.reset());        BOOST_CHECK_OPERATION_SEQUENCE(seq);    }    // Restrict a seekable filter    {        operation_sequence  seq;        chain<seekable>     ch;        ch.push(            io::BOOST_RESTRICT(                closable_filter<seekable>(seq.new_operation(1)),                 0            )        );        ch.push(closable_device<seekable>(seq.new_operation(2)));        BOOST_CHECK_NO_THROW(ch.reset());        BOOST_CHECK_OPERATION_SEQUENCE(seq);    }    // Restrict a dual_use filter for input    {        operation_sequence  seq;        chain<input>        ch;        operation           dummy;        ch.push(            io::BOOST_RESTRICT(                closable_filter<dual_use>(                    seq.new_operation(2),                    dummy                ),                0            )        );        ch.push(closable_device<input>(seq.new_operation(1)));        BOOST_CHECK_NO_THROW(ch.reset());        BOOST_CHECK_OPERATION_SEQUENCE(seq);    }    // Restrict a dual_use filter for output    {        operation_sequence  seq;        chain<output>       ch;        operation           dummy;        ch.push(            io::BOOST_RESTRICT(                closable_filter<dual_use>(                    dummy,                    seq.new_operation(1)                ),                0            )        );        ch.push(closable_device<output>(seq.new_operation(2)));        BOOST_CHECK_NO_THROW(ch.reset());        BOOST_CHECK_OPERATION_SEQUENCE(seq);    }}test_suite* init_unit_test_suite(int, char* []) {    test_suite* test =         BOOST_TEST_SUITE(BOOST_STRINGIZE(BOOST_RESTRICT) " test");    test->add(BOOST_TEST_CASE(&read_device));    test->add(BOOST_TEST_CASE(&read_direct_device));    test->add(BOOST_TEST_CASE(&read_filter));    test->add(BOOST_TEST_CASE(&write_device));    test->add(BOOST_TEST_CASE(&write_direct_device));    test->add(BOOST_TEST_CASE(&write_filter));    test->add(BOOST_TEST_CASE(&seek_device));    test->add(BOOST_TEST_CASE(&seek_direct_device));    test->add(BOOST_TEST_CASE(&close_device));    test->add(BOOST_TEST_CASE(&close_filter));    return test;}

⌨️ 快捷键说明

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