-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed ReactContext copy/move semantic (#4870)
* Fixed ReactContext copy/move semantic * Change files * Fixed formatting * Test to show how to use a delegate in ReactPropertyBag
- Loading branch information
1 parent
c6c71f7
commit aa96215
Showing
7 changed files
with
173 additions
and
4 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
change/react-native-windows-2020-05-11-11-06-42-FixReactContext.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"type": "prerelease", | ||
"comment": "Fixed ReactContext copy/move semantic", | ||
"packageName": "react-native-windows", | ||
"email": "vmorozov@microsoft.com", | ||
"dependentChangeType": "patch", | ||
"date": "2020-05-11T18:06:42.425Z" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
vnext/Microsoft.ReactNative.Cxx.UnitTests/ReactContextTest.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
#include "pch.h" | ||
#include <ReactContext.h> | ||
#include "ReactModuleBuilderMock.h" | ||
|
||
using namespace winrt::Microsoft::ReactNative; | ||
|
||
struct ReactContextStub : implements<ReactContextStub, IReactContext> { | ||
IReactPropertyBag Properties() noexcept { | ||
VerifyElseCrashSz(false, "Not implemented"); | ||
} | ||
|
||
void DispatchEvent( | ||
Windows::UI::Xaml::FrameworkElement const & /*view*/, | ||
hstring const & /*eventName*/, | ||
JSValueArgWriter const & /*eventDataArgWriter*/) noexcept { | ||
VerifyElseCrashSz(false, "Not implemented"); | ||
} | ||
|
||
void CallJSFunction( | ||
hstring const & /*moduleName*/, | ||
hstring const & /*functionName*/, | ||
JSValueArgWriter const & /*paramsArgWriter*/) noexcept { | ||
VerifyElseCrashSz(false, "Not implemented"); | ||
} | ||
|
||
void EmitJSEvent( | ||
hstring const & /*eventEmitterName*/, | ||
hstring const & /*eventName*/, | ||
JSValueArgWriter const & /*paramsArgWriter*/) noexcept { | ||
VerifyElseCrashSz(false, "Not implemented"); | ||
} | ||
}; | ||
|
||
namespace ReactNativeTests { | ||
|
||
TEST_CLASS (ReactContextTest) { | ||
TEST_METHOD(Test_ctor_Default) { | ||
ReactContext context; | ||
TestCheck(!context); | ||
} | ||
|
||
TEST_METHOD(Test_ctor_IReactContext) { | ||
auto reactContextMock = winrt::make<ReactContextStub>(); | ||
ReactContext context{reactContextMock}; | ||
TestCheck(context); | ||
} | ||
|
||
TEST_METHOD(Test_ctor_copy) { | ||
auto reactContextMock = winrt::make<ReactContextStub>(); | ||
ReactContext context1{reactContextMock}; | ||
ReactContext context2{context1}; | ||
TestCheck(context1); | ||
TestCheck(context2); | ||
TestCheckEqual(context1, context2); | ||
} | ||
|
||
TEST_METHOD(Test_ctor_move) { | ||
auto reactContextMock = winrt::make<ReactContextStub>(); | ||
ReactContext context1{reactContextMock}; | ||
ReactContext context2{std::move(context1)}; | ||
TestCheck(!context1); | ||
TestCheck(context2); | ||
} | ||
|
||
TEST_METHOD(Test_assign_nullptr) { | ||
ReactContext context; | ||
context = nullptr; | ||
TestCheck(!context); | ||
} | ||
|
||
TEST_METHOD(Test_assign_copy) { | ||
auto reactContextMock = winrt::make<ReactContextStub>(); | ||
ReactContext context1{reactContextMock}; | ||
ReactContext context2; | ||
context2 = context1; | ||
TestCheck(context1); | ||
TestCheck(context2); | ||
TestCheckEqual(context1, context2); | ||
} | ||
|
||
TEST_METHOD(Test_assign_move) { | ||
auto reactContextMock = winrt::make<ReactContextStub>(); | ||
ReactContext context1{reactContextMock}; | ||
ReactContext context2; | ||
context2 = std::move(context1); | ||
TestCheck(!context1); | ||
TestCheck(context2); | ||
} | ||
|
||
TEST_METHOD(Test_compare) { | ||
auto reactContextMock1 = winrt::make<ReactContextStub>(); | ||
auto reactContextMock2 = winrt::make<ReactContextStub>(); | ||
ReactContext context11{reactContextMock1}; | ||
ReactContext context12{context11}; | ||
ReactContext context2{reactContextMock2}; | ||
ReactContext context3; | ||
TestCheck(context11 == context12); | ||
TestCheck(context12 == context11); | ||
TestCheck(context11 != context2); | ||
TestCheck(context11 != context3); | ||
TestCheck(context2 != context11); | ||
TestCheck(context3 != context11); | ||
TestCheck(context3 == nullptr); | ||
TestCheck(nullptr == context3); | ||
TestCheck(context11 != nullptr); | ||
TestCheck(nullptr != context11); | ||
} | ||
}; | ||
|
||
} // namespace ReactNativeTests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
vnext/Microsoft.ReactNative.IntegrationTests/ReactNativeHostTests.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters