summaryrefslogtreecommitdiff
path: root/libs/context/test/test_context.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libs/context/test/test_context.cpp')
-rw-r--r--libs/context/test/test_context.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/libs/context/test/test_context.cpp b/libs/context/test/test_context.cpp
index 27dae776a..85797b24d 100644
--- a/libs/context/test/test_context.cpp
+++ b/libs/context/test/test_context.cpp
@@ -16,6 +16,7 @@
#include <boost/utility.hpp>
#include <boost/context/all.hpp>
+#include <boost/context/detail/config.hpp>
#include "../example/simple_stack_allocator.hpp"
@@ -221,6 +222,53 @@ void test_stacked()
BOOST_CHECK_EQUAL( 3, value1);
}
+#if ! defined(BOOST_CONTEXT_NO_EXECUTION_CONTEXT)
+ctx::execution_context * mctx = nullptr;
+
+void f11() {
+ value1 = 3;
+ mctx->resume();
+}
+
+void f12( int i) {
+ value1 = i;
+ mctx->resume();
+}
+
+void test_ectx() {
+ boost::context::execution_context ctx( boost::context::execution_context::current() );
+ mctx = & ctx;
+ value1 = 0;
+ ctx::fixedsize_stack alloc;
+ ctx::execution_context ectx( alloc, f11);
+ ectx.resume();
+ BOOST_CHECK_EQUAL( 3, value1);
+}
+
+void test_variadric() {
+ boost::context::execution_context ctx( boost::context::execution_context::current() );
+ mctx = & ctx;
+ value1 = 0;
+ ctx::fixedsize_stack alloc;
+ ctx::execution_context ectx( alloc, f12, 5);
+ ectx.resume();
+ BOOST_CHECK_EQUAL( 5, value1);
+}
+
+void test_prealloc() {
+ boost::context::execution_context ctx( boost::context::execution_context::current() );
+ mctx = & ctx;
+ value1 = 0;
+ ctx::fixedsize_stack alloc;
+ ctx::stack_context sctx( alloc.allocate() );
+ void * sp = static_cast< char * >( sctx.sp) - 10;
+ std::size_t size = sctx.size - 10;
+ ctx::execution_context ectx( ctx::preallocated( sp, size, sctx), alloc, f12, 7);
+ ectx.resume();
+ BOOST_CHECK_EQUAL( 7, value1);
+}
+#endif
+
boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
{
boost::unit_test::test_suite * test =
@@ -236,5 +284,11 @@ boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
test->add( BOOST_TEST_CASE( & test_fp) );
test->add( BOOST_TEST_CASE( & test_stacked) );
+#if ! defined(BOOST_CONTEXT_NO_EXECUTION_CONTEXT)
+ test->add( BOOST_TEST_CASE( & test_ectx) );
+ test->add( BOOST_TEST_CASE( & test_variadric) );
+ test->add( BOOST_TEST_CASE( & test_prealloc) );
+#endif
+
return test;
}