Skip to content

Commit 11efc63

Browse files
committed
ExecutionContext: Add engine getter
1 parent 4fb010b commit 11efc63

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

include/scratchcpp/dev/executioncontext.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace libscratchcpp
99
{
1010

1111
class Thread;
12-
class Target;
12+
class IEngine;
1313
class Promise;
1414
class ExecutionContextPrivate;
1515

@@ -22,6 +22,7 @@ class LIBSCRATCHCPP_EXPORT ExecutionContext
2222
virtual ~ExecutionContext() { }
2323

2424
Thread *thread() const;
25+
IEngine *engine() const;
2526

2627
std::shared_ptr<Promise> promise() const;
2728
void setPromise(std::shared_ptr<Promise> promise);

src/dev/engine/executioncontext.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ Thread *ExecutionContext::thread() const
1919
return impl->thread;
2020
}
2121

22+
/*! Returns the engine of the project. */
23+
IEngine *ExecutionContext::engine() const
24+
{
25+
return impl->thread->engine();
26+
}
27+
2228
/*! Returns the script promise. */
2329
std::shared_ptr<Promise> ExecutionContext::promise() const
2430
{

test/dev/executioncontext/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ add_executable(
66
target_link_libraries(
77
executioncontext_test
88
GTest::gtest_main
9+
GTest::gmock_main
910
scratchcpp
11+
scratchcpp_mocks
1012
)
1113

1214
gtest_discover_tests(executioncontext_test)

test/dev/executioncontext/executioncontext_test.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@
22
#include <scratchcpp/thread.h>
33
#include <scratchcpp/dev/promise.h>
44

5+
#include <enginemock.h>
6+
57
#include "../../common.h"
68

79
using namespace libscratchcpp;
810

911
TEST(ExecutionContextTest, Constructor)
1012
{
11-
Thread thread(nullptr, nullptr, nullptr);
13+
EngineMock engine;
14+
Thread thread(nullptr, &engine, nullptr);
1215
ExecutionContext ctx(&thread);
1316
ASSERT_EQ(ctx.thread(), &thread);
17+
ASSERT_EQ(ctx.engine(), &engine);
1418
}
1519

1620
TEST(ExecutionContextTest, Promise)

0 commit comments

Comments
 (0)