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

📄 execute_test.cpp

📁 Boost provides free peer-reviewed portable C++ source libraries. We emphasize libraries that work
💻 CPP
📖 第 1 页 / 共 2 页
字号:
             cleaned_up2 = false, cleaned_up3 = false;        BOOST_CHECK_THROW(            execute_all(                operation<void>(executed),                operation<void>(cleaned_up1),                operation<void>(cleaned_up2),                thrower<3>(cleaned_up3)            ),             error<3>        );        BOOST_CHECK(executed && cleaned_up1 && cleaned_up2 && cleaned_up3);    }}void multiple_exceptions_test(){    // Test primary operation and cleanup operation throwing    {        bool executed = false, cleaned_up = false;        BOOST_CHECK_THROW(            execute_all(                thrower<0>(executed),                thrower<1>(cleaned_up)            ),            error<0>        );        BOOST_CHECK(executed && cleaned_up);    }    // Test primary operation and first of two cleanup operations throwing    {        bool executed = false, cleaned_up1 = false, cleaned_up2 = false;        BOOST_CHECK_THROW(            execute_all(                thrower<0>(executed),                thrower<1>(cleaned_up1),                operation<void>(cleaned_up2)            ),            error<0>        );        BOOST_CHECK(executed && cleaned_up1 && cleaned_up2);    }    // Test primary operation and second of two cleanup operations throwing    {        bool executed = false, cleaned_up1 = false, cleaned_up2 = false;        BOOST_CHECK_THROW(            execute_all(                thrower<0>(executed),                operation<void>(cleaned_up1),                thrower<2>(cleaned_up2)            ),            error<0>        );        BOOST_CHECK(executed && cleaned_up1 && cleaned_up2);    }    // Test two cleanup operations throwing    {        bool executed = false, cleaned_up1 = false, cleaned_up2 = false;        BOOST_CHECK_THROW(            execute_all(                operation<void>(executed),                thrower<1>(cleaned_up1),                thrower<2>(cleaned_up2)            ),            error<1>        );        BOOST_CHECK(executed && cleaned_up1 && cleaned_up2);    }    // Test primary operation and first of three cleanup operations throwing    {        bool executed = false, cleaned_up1 = false,              cleaned_up2 = false, cleaned_up3 = false;        BOOST_CHECK_THROW(            execute_all(                thrower<0>(executed),                thrower<1>(cleaned_up1),                operation<void>(cleaned_up2),                operation<void>(cleaned_up3)            ),            error<0>        );        BOOST_CHECK(executed && cleaned_up1 && cleaned_up2 && cleaned_up3);    }    // Test primary operation and second of three cleanup operations throwing    {        bool executed = false, cleaned_up1 = false,              cleaned_up2 = false, cleaned_up3 = false;        BOOST_CHECK_THROW(            execute_all(                thrower<0>(executed),                operation<void>(cleaned_up1),                thrower<2>(cleaned_up2),                operation<void>(cleaned_up3)            ),            error<0>        );        BOOST_CHECK(executed && cleaned_up1 && cleaned_up2 && cleaned_up3);    }    // Test primary operation and third of three cleanup operations throwing    {        bool executed = false, cleaned_up1 = false,              cleaned_up2 = false, cleaned_up3 = false;        BOOST_CHECK_THROW(            execute_all(                thrower<0>(executed),                operation<void>(cleaned_up1),                operation<void>(cleaned_up2),                thrower<3>(cleaned_up3)            ),            error<0>        );        BOOST_CHECK(executed && cleaned_up1 && cleaned_up2 && cleaned_up3);    }    // Test first and second of three cleanup operations throwing    {        bool executed = false, cleaned_up1 = false,              cleaned_up2 = false, cleaned_up3 = false;        BOOST_CHECK_THROW(            execute_all(                operation<void>(executed),                thrower<1>(cleaned_up1),                thrower<2>(cleaned_up2),                operation<void>(cleaned_up3)            ),            error<1>        );        BOOST_CHECK(executed && cleaned_up1 && cleaned_up2 && cleaned_up3);    }    // Test first and third of three cleanup operations throwing    {        bool executed = false, cleaned_up1 = false,              cleaned_up2 = false, cleaned_up3 = false;        BOOST_CHECK_THROW(            execute_all(                operation<void>(executed),                thrower<1>(cleaned_up1),                operation<void>(cleaned_up2),                thrower<3>(cleaned_up3)            ),            error<1>        );        BOOST_CHECK(executed && cleaned_up1 && cleaned_up2 && cleaned_up3);    }    // Test second and third of three cleanup operations throwing    {        bool executed = false, cleaned_up1 = false,              cleaned_up2 = false, cleaned_up3 = false;        BOOST_CHECK_THROW(            execute_all(                operation<void>(executed),                operation<void>(cleaned_up1),                thrower<2>(cleaned_up2),                thrower<3>(cleaned_up3)            ),            error<2>        );        BOOST_CHECK(executed && cleaned_up1 && cleaned_up2 && cleaned_up3);    }    // Test three cleanup operations throwing    {        bool executed = false, cleaned_up1 = false,              cleaned_up2 = false, cleaned_up3 = false;        BOOST_CHECK_THROW(            execute_all(                operation<void>(executed),                thrower<1>(cleaned_up1),                thrower<2>(cleaned_up2),                thrower<3>(cleaned_up3)            ),            error<1>        );        BOOST_CHECK(executed && cleaned_up1 && cleaned_up2 && cleaned_up3);    }}#define ARRAY_SIZE(ar) (sizeof(ar) / sizeof(ar[0]))void foreach_test(){    // Test case where neither of two operations throws    {        int count = 0;        int seq[] = {-1, -1};        BOOST_CHECK_NO_THROW(            execute_foreach(seq, seq + ARRAY_SIZE(seq), foreach_func(count))        );        BOOST_CHECK(count == ARRAY_SIZE(seq));    }    // Test case where first of two operations throws    {        int count = 0;        int seq[] = {0, -1};        BOOST_CHECK_THROW(            execute_foreach(seq, seq + ARRAY_SIZE(seq), foreach_func(count)),            error<0>        );        BOOST_CHECK(count == ARRAY_SIZE(seq));    }    // Test case where second of two operations throws    {        int count = 0;        int seq[] = {-1, 1};        BOOST_CHECK_THROW(            execute_foreach(seq, seq + ARRAY_SIZE(seq), foreach_func(count)),            error<1>        );        BOOST_CHECK(count == ARRAY_SIZE(seq));    }    // Test case where both of two operations throw    {        int count = 0;        int seq[] = {0, 1};        BOOST_CHECK_THROW(            execute_foreach(seq, seq + ARRAY_SIZE(seq), foreach_func(count)),            error<0>        );        BOOST_CHECK(count == ARRAY_SIZE(seq));    }    // Test case where none of three operations throws    {        int count = 0;        int seq[] = {-1, -1, -1};        BOOST_CHECK_NO_THROW(            execute_foreach(seq, seq + ARRAY_SIZE(seq), foreach_func(count))        );        BOOST_CHECK(count == ARRAY_SIZE(seq));    }    // Test case where first of three operations throw    {        int count = 0;        int seq[] = {0, -1, -1};        BOOST_CHECK_THROW(            execute_foreach(seq, seq + ARRAY_SIZE(seq), foreach_func(count)),            error<0>        );        BOOST_CHECK(count == ARRAY_SIZE(seq));    }    // Test case where second of three operations throw    {        int count = 0;        int seq[] = {-1, 1, -1};        BOOST_CHECK_THROW(            execute_foreach(seq, seq + ARRAY_SIZE(seq), foreach_func(count)),            error<1>        );        BOOST_CHECK(count == ARRAY_SIZE(seq));    }    // Test case where third of three operations throw    {        int count = 0;        int seq[] = {-1, -1, 2};        BOOST_CHECK_THROW(            execute_foreach(seq, seq + ARRAY_SIZE(seq), foreach_func(count)),            error<2>        );        BOOST_CHECK(count == ARRAY_SIZE(seq));    }    // Test case where first and second of three operations throw    {        int count = 0;        int seq[] = {0, 1, -1};        BOOST_CHECK_THROW(            execute_foreach(seq, seq + ARRAY_SIZE(seq), foreach_func(count)),            error<0>        );        BOOST_CHECK(count == ARRAY_SIZE(seq));    }    // Test case where first and third of three operations throw    {        int count = 0;        int seq[] = {0, -1, 2};        BOOST_CHECK_THROW(            execute_foreach(seq, seq + ARRAY_SIZE(seq), foreach_func(count)),            error<0>        );        BOOST_CHECK(count == ARRAY_SIZE(seq));    }    // Test case where second and third of three operations throw    {        int count = 0;        int seq[] = {-1, 1, 2};        BOOST_CHECK_THROW(            execute_foreach(seq, seq + ARRAY_SIZE(seq), foreach_func(count)),            error<1>        );        BOOST_CHECK(count == ARRAY_SIZE(seq));    }    // Test case where three of three operations throw    {        int count = 0;        int seq[] = {0, 1, 2};        BOOST_CHECK_THROW(            execute_foreach(seq, seq + ARRAY_SIZE(seq), foreach_func(count)),            error<0>        );        BOOST_CHECK(count == ARRAY_SIZE(seq));    }}test_suite* init_unit_test_suite(int, char* []) {    test_suite* test = BOOST_TEST_SUITE("execute test");    test->add(BOOST_TEST_CASE(&success_test));    test->add(BOOST_TEST_CASE(&operation_throws_test));    test->add(BOOST_TEST_CASE(&cleanup_throws_test));    test->add(BOOST_TEST_CASE(&multiple_exceptions_test));    test->add(BOOST_TEST_CASE(&foreach_test));    return test;}

⌨️ 快捷键说明

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