Skip to content

Commit 5deff77

Browse files
committed
Add basic JsDiagApiTests for breakpoints
1 parent e1ca7cb commit 5deff77

File tree

2 files changed

+91
-1
lines changed

2 files changed

+91
-1
lines changed

bin/NativeTests/JsDiagApiTest.cpp

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
//-------------------------------------------------------------------------------------------------------
2+
// Copyright (C) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
4+
//-------------------------------------------------------------------------------------------------------
5+
6+
#include "stdafx.h"
7+
#include "catch.hpp"
8+
#include <process.h>
9+
10+
#pragma warning(disable:4100) // unreferenced formal parameter
11+
#pragma warning(disable:6387) // suppressing preFAST which raises warning for passing null to the JsRT APIs
12+
#pragma warning(disable:6262) // CATCH is using stack variables to report errors, suppressing the preFAST warning.
13+
14+
namespace JsDiagApiTest
15+
{
16+
static void CALLBACK DebugEventCallback(JsDiagDebugEvent debugEvent, JsValueRef eventData, void* callbackState)
17+
{
18+
}
19+
20+
bool TestSetup(JsRuntimeHandle *runtime)
21+
{
22+
JsValueRef context = JS_INVALID_REFERENCE;
23+
JsValueRef setContext = JS_INVALID_REFERENCE;
24+
25+
// Create runtime, context and set current context
26+
REQUIRE(JsCreateRuntime(JsRuntimeAttributeNone, nullptr, runtime) == JsNoError);
27+
REQUIRE(JsCreateContext(*runtime, &context) == JsNoError);
28+
REQUIRE(JsSetCurrentContext(context) == JsNoError);
29+
REQUIRE(((JsGetCurrentContext(&setContext) == JsNoError) || setContext == context));
30+
31+
// Enable debugging
32+
REQUIRE(JsDiagStartDebugging(*runtime, JsDiagApiTest::DebugEventCallback, nullptr) == JsNoError);
33+
34+
return true;
35+
}
36+
37+
bool TestCleanup(JsRuntimeHandle runtime)
38+
{
39+
if (runtime != nullptr)
40+
{
41+
// Disable debugging
42+
JsDiagStopDebugging(runtime, nullptr);
43+
44+
JsSetCurrentContext(nullptr);
45+
JsDisposeRuntime(runtime);
46+
}
47+
return true;
48+
}
49+
50+
template <class Handler>
51+
void WithSetup(Handler handler)
52+
{
53+
JsRuntimeHandle runtime = JS_INVALID_RUNTIME_HANDLE;
54+
if (!TestSetup(&runtime))
55+
{
56+
REQUIRE(false);
57+
return;
58+
}
59+
60+
handler(runtime);
61+
62+
TestCleanup(runtime);
63+
}
64+
65+
#ifndef BUILD_WITHOUT_SCRIPT_DEBUG
66+
void BreakpointsContextTest(JsRuntimeHandle runtime)
67+
{
68+
JsContextRef context = JS_INVALID_REFERENCE;
69+
REQUIRE(JsGetCurrentContext(&context) == JsNoError);
70+
71+
// Verify no errors with a context set
72+
JsValueRef scriptsArray = JS_INVALID_REFERENCE;
73+
REQUIRE(JsDiagGetScripts(&scriptsArray) == JsNoError);
74+
75+
// Verify the APIs return an error when no current context set
76+
JsSetCurrentContext(nullptr);
77+
CHECK(JsDiagGetScripts(&scriptsArray) == JsErrorNoCurrentContext);
78+
79+
JsValueRef breakpoint = JS_INVALID_REFERENCE;
80+
CHECK(JsDiagSetBreakpoint(0, 0, 0, &breakpoint) == JsErrorNoCurrentContext);
81+
82+
CHECK(JsDiagRemoveBreakpoint(0) == JsErrorNoCurrentContext);
83+
}
84+
85+
TEST_CASE("JsDiagApiTest_BreakpointsContextTest", "[JsDiagApiTest]")
86+
{
87+
JsDiagApiTest::WithSetup(JsDiagApiTest::BreakpointsContextTest);
88+
}
89+
#endif // BUILD_WITHOUT_SCRIPT_DEBUG
90+
}

bin/NativeTests/NativeTests.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
$(ChakraCoreRootDirectory)bin\External;
2828
%(AdditionalIncludeDirectories)
2929
</AdditionalIncludeDirectories>
30-
3130
<MultiProcessorCompilation>true</MultiProcessorCompilation>
3231
<SmallerTypeCheck>false</SmallerTypeCheck>
3332
<MinimalRebuild>false</MinimalRebuild>
@@ -47,6 +46,7 @@
4746
<ClCompile Include="CodexTests.cpp" />
4847
<ClCompile Include="FileLoadHelpers.cpp" />
4948
<ClCompile Include="FunctionExecutionTest.cpp" />
49+
<ClCompile Include="JsDiagApiTest.cpp" />
5050
<ClCompile Include="JsRTApiTest.cpp" />
5151
<ClCompile Include="MemoryPolicyTest.cpp" />
5252
<ClCompile Include="NativeTests.cpp" />

0 commit comments

Comments
 (0)