diff --git a/change/react-native-windows-2020-04-21-06-23-19-MS_CppTurboModules.json b/change/react-native-windows-2020-04-21-06-23-19-MS_CppTurboModules.json new file mode 100644 index 00000000000..80fe2a4b0ef --- /dev/null +++ b/change/react-native-windows-2020-04-21-06-23-19-MS_CppTurboModules.json @@ -0,0 +1,8 @@ +{ + "type": "prerelease", + "comment": "Implemented C++ TurboModule compile time spec validation", + "packageName": "react-native-windows", + "email": "vmorozov@microsoft.com", + "dependentChangeType": "patch", + "date": "2020-04-21T13:23:19.348Z" +} \ No newline at end of file diff --git a/vnext/Microsoft.ReactNative.Cxx.UnitTests/Microsoft.ReactNative.Cxx.UnitTests.vcxproj b/vnext/Microsoft.ReactNative.Cxx.UnitTests/Microsoft.ReactNative.Cxx.UnitTests.vcxproj index 7959860f16f..352c770761e 100644 --- a/vnext/Microsoft.ReactNative.Cxx.UnitTests/Microsoft.ReactNative.Cxx.UnitTests.vcxproj +++ b/vnext/Microsoft.ReactNative.Cxx.UnitTests/Microsoft.ReactNative.Cxx.UnitTests.vcxproj @@ -112,6 +112,7 @@ + @@ -126,6 +127,7 @@ Create + @@ -157,4 +159,4 @@ - + \ No newline at end of file diff --git a/vnext/Microsoft.ReactNative.Cxx.UnitTests/NativeModuleTest.cpp b/vnext/Microsoft.ReactNative.Cxx.UnitTests/NativeModuleTest.cpp index 8edd3933795..84eb534ceda 100644 --- a/vnext/Microsoft.ReactNative.Cxx.UnitTests/NativeModuleTest.cpp +++ b/vnext/Microsoft.ReactNative.Cxx.UnitTests/NativeModuleTest.cpp @@ -5,24 +5,15 @@ #include "ReactModuleBuilderMock.h" #include -#include "NativeModules.h" +#include "Point.h" #include "future/futureWait.h" -namespace winrt::Microsoft::ReactNative { - -REACT_STRUCT(Point) -struct Point { - REACT_FIELD(X) - int X; - - REACT_FIELD(Y) - int Y; -}; +namespace ReactNativeTests { REACT_MODULE(SimpleNativeModule) struct SimpleNativeModule { REACT_INIT(Initialize) - void Initialize(IReactContext const &context) noexcept { + void Initialize(React::IReactContext const &context) noexcept { IsInitialized = true; TestCheck(context != nullptr); @@ -322,46 +313,46 @@ struct SimpleNativeModule { } REACT_METHOD(DividePromise) - void DividePromise(int x, int y, ReactPromise const &result) noexcept { + void DividePromise(int x, int y, React::ReactPromise const &result) noexcept { if (y != 0) { result.Resolve(x / y); } else { - ReactError error{}; + React::ReactError error{}; error.Message = "Division by 0"; result.Reject(std::move(error)); } } REACT_METHOD(NegatePromise) - void NegatePromise(int x, ReactPromise const &result) noexcept { + void NegatePromise(int x, React::ReactPromise const &result) noexcept { if (x >= 0) { result.Resolve(-x); } else { - ReactError error{}; + React::ReactError error{}; error.Message = "Already negative"; result.Reject(std::move(error)); } } REACT_METHOD(NegateAsyncPromise) - fire_and_forget NegateAsyncPromise(int x, ReactPromise result) noexcept { + fire_and_forget NegateAsyncPromise(int x, React::ReactPromise result) noexcept { co_await winrt::resume_background(); if (x >= 0) { result.Resolve(-x); } else { - ReactError error{}; + React::ReactError error{}; error.Message = "Already negative"; result.Reject(std::move(error)); } } REACT_METHOD(NegateDispatchQueuePromise) - void NegateDispatchQueuePromise(int x, ReactPromise const &result) noexcept { + void NegateDispatchQueuePromise(int x, React::ReactPromise const &result) noexcept { Mso::DispatchQueue::ConcurrentQueue().Post([ x, result ]() noexcept { if (x >= 0) { result.Resolve(-x); } else { - ReactError error{}; + React::ReactError error{}; error.Message = "Already negative"; result.Reject(std::move(error)); } @@ -369,12 +360,12 @@ struct SimpleNativeModule { } REACT_METHOD(NegateFuturePromise) - void NegateFuturePromise(int x, ReactPromise const &result) noexcept { + void NegateFuturePromise(int x, React::ReactPromise const &result) noexcept { Mso::PostFuture([ x, result ]() noexcept { if (x >= 0) { result.Resolve(-x); } else { - ReactError error{}; + React::ReactError error{}; error.Message = "Already negative"; result.Reject(std::move(error)); } @@ -383,7 +374,7 @@ struct SimpleNativeModule { // Each macro has second optional parameter: JS name. REACT_METHOD(VoidPromise, L"voidPromise") - void VoidPromise(int x, ReactPromise const &result) noexcept { + void VoidPromise(int x, React::ReactPromise const &result) noexcept { if (x % 2 == 0) { result.Resolve(); } else { @@ -392,58 +383,58 @@ struct SimpleNativeModule { } REACT_METHOD(ResolveSayHelloPromise) - void ResolveSayHelloPromise(ReactPromise const &result) noexcept { + void ResolveSayHelloPromise(React::ReactPromise const &result) noexcept { result.Resolve("Hello_4"); } REACT_METHOD(RejectSayHelloPromise) - void RejectSayHelloPromise(ReactPromise const &result) noexcept { - ReactError error{}; + void RejectSayHelloPromise(React::ReactPromise const &result) noexcept { + React::ReactError error{}; error.Message = "Promise rejected"; result.Reject(std::move(error)); } REACT_METHOD(StaticDividePromise) - static void StaticDividePromise(int x, int y, ReactPromise const &result) noexcept { + static void StaticDividePromise(int x, int y, React::ReactPromise const &result) noexcept { if (y != 0) { result.Resolve(x / y); } else { - ReactError error{}; + React::ReactError error{}; error.Message = "Division by 0"; result.Reject(std::move(error)); } } REACT_METHOD(StaticNegatePromise) - static void StaticNegatePromise(int x, ReactPromise const &result) noexcept { + static void StaticNegatePromise(int x, React::ReactPromise const &result) noexcept { if (x >= 0) { result.Resolve(-x); } else { - ReactError error{}; + React::ReactError error{}; error.Message = "Already negative"; result.Reject(std::move(error)); } } REACT_METHOD(StaticNegateAsyncPromise) - static fire_and_forget StaticNegateAsyncPromise(int x, ReactPromise result) noexcept { + static fire_and_forget StaticNegateAsyncPromise(int x, React::ReactPromise result) noexcept { co_await winrt::resume_background(); if (x >= 0) { result.Resolve(-x); } else { - ReactError error{}; + React::ReactError error{}; error.Message = "Already negative"; result.Reject(std::move(error)); } } REACT_METHOD(StaticNegateDispatchQueuePromise) - static void StaticNegateDispatchQueuePromise(int x, ReactPromise const &result) noexcept { + static void StaticNegateDispatchQueuePromise(int x, React::ReactPromise const &result) noexcept { Mso::DispatchQueue::ConcurrentQueue().Post([ x, result ]() noexcept { if (x >= 0) { result.Resolve(-x); } else { - ReactError error{}; + React::ReactError error{}; error.Message = "Already negative"; result.Reject(std::move(error)); } @@ -451,12 +442,12 @@ struct SimpleNativeModule { } REACT_METHOD(StaticNegateFuturePromise) - static void StaticNegateFuturePromise(int x, ReactPromise const &result) noexcept { + static void StaticNegateFuturePromise(int x, React::ReactPromise const &result) noexcept { Mso::PostFuture([ x, result ]() noexcept { if (x >= 0) { result.Resolve(-x); } else { - ReactError error{}; + React::ReactError error{}; error.Message = "Already negative"; result.Reject(std::move(error)); } @@ -465,7 +456,7 @@ struct SimpleNativeModule { // Each macro has second optional parameter: JS name. REACT_METHOD(StaticVoidPromise, L"staticVoidPromise") - void StaticVoidPromise(int x, ReactPromise const &result) noexcept { + void StaticVoidPromise(int x, React::ReactPromise const &result) noexcept { if (x % 2 == 0) { result.Resolve(); } else { @@ -474,13 +465,13 @@ struct SimpleNativeModule { } REACT_METHOD(StaticResolveSayHelloPromise) - static void StaticResolveSayHelloPromise(ReactPromise const &result) noexcept { + static void StaticResolveSayHelloPromise(React::ReactPromise const &result) noexcept { result.Resolve("Hello_4"); } REACT_METHOD(StaticRejectSayHelloPromise) - static void StaticRejectSayHelloPromise(ReactPromise const &result) noexcept { - ReactError error{}; + static void StaticRejectSayHelloPromise(React::ReactPromise const &result) noexcept { + React::ReactError error{}; error.Message = "Promise rejected"; result.Reject(std::move(error)); } @@ -528,13 +519,13 @@ struct SimpleNativeModule { static constexpr Point Constant4{/*X =*/3, /*Y =*/4}; REACT_CONSTANT_PROVIDER(Constant5) - void Constant5(ReactConstantProvider &provider) noexcept { + void Constant5(React::ReactConstantProvider &provider) noexcept { provider.Add(L"const51", Point{/*X =*/12, /*Y =*/14}); provider.Add(L"const52", "MyConstant52"); } REACT_CONSTANT_PROVIDER(Constant6) - static void Constant6(ReactConstantProvider &provider) noexcept { + static void Constant6(React::ReactConstantProvider &provider) noexcept { provider.Add(L"const61", Point{/*X =*/15, /*Y =*/17}); provider.Add(L"const62", "MyConstant62"); } @@ -560,9 +551,9 @@ struct SimpleNativeModule { REACT_EVENT(OnStringEvent, L"onStringEvent", L"MyEventEmitter") std::function OnStringEvent; - // Use JSValue which is an immutable JSON-like data representation. + // Use React::JSValue which is an immutable JSON-like data representation. REACT_EVENT(OnJSValueEvent) - std::function OnJSValueEvent; + std::function OnJSValueEvent; // Allows to call JS functions. REACT_FUNCTION(JSIntFunction) @@ -585,9 +576,9 @@ struct SimpleNativeModule { REACT_FUNCTION(JSStringFunction, L"stringFunc", L"MyModule") std::function JSStringFunction; - // Use JSValue which is an immutable JSON-like data representation. + // Use React::JSValue which is an immutable JSON-like data representation. REACT_FUNCTION(JSValueFunction) - std::function JSValueFunction; + std::function JSValueFunction; public: // Used to report some test messages bool IsInitialized{false}; @@ -598,17 +589,17 @@ struct SimpleNativeModule { /*static*/ std::string SimpleNativeModule::StaticMessage; TEST_CLASS (NativeModuleTest) { - ReactModuleBuilderMock m_builderMock{}; - IReactModuleBuilder m_moduleBuilder; + React::ReactModuleBuilderMock m_builderMock{}; + React::IReactModuleBuilder m_moduleBuilder; Windows::Foundation::IInspectable m_moduleObject{nullptr}; SimpleNativeModule *m_module; NativeModuleTest() { - m_moduleBuilder = make(m_builderMock); - auto provider = MakeModuleProvider(); + m_moduleBuilder = winrt::make(m_builderMock); + auto provider = React::MakeModuleProvider(); m_moduleObject = m_builderMock.CreateModule(provider, m_moduleBuilder); - auto reactModule = m_moduleObject.as(); - m_module = &BoxedValue::GetImpl(reactModule); + auto reactModule = m_moduleObject.as(); + m_module = &React::BoxedValue::GetImpl(reactModule); } TEST_METHOD(TestMethodCall_Add) { @@ -644,7 +635,6 @@ TEST_CLASS (NativeModuleTest) { m_builderMock.Call1(L"StaticSayHello", std::function([ ](const std::string &result) noexcept { TestCheck(result == "Hello"); })); TestCheck(m_builderMock.IsResolveCallbackCalled()); - TestCheck(m_builderMock.IsResolveCallbackCalled()); } TEST_METHOD(TestMethodCall_SayHello0) { @@ -1005,8 +995,8 @@ TEST_CLASS (NativeModuleTest) { m_builderMock.Call2( L"DividePromise", std::function([](int result) noexcept { TestCheck(result == 3); }), - std::function( - [](JSValue const &error) noexcept { TestCheck(error["message"] == "Division by 0"); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Division by 0"); }), 6, 2); TestCheck(m_builderMock.IsResolveCallbackCalled()); @@ -1016,8 +1006,8 @@ TEST_CLASS (NativeModuleTest) { m_builderMock.Call2( L"DividePromise", std::function([](int result) noexcept { TestCheck(result == 3); }), - std::function( - [](JSValue const &error) noexcept { TestCheck(error["message"] == "Division by 0"); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Division by 0"); }), 6, 0); TestCheck(m_builderMock.IsRejectCallbackCalled()); @@ -1027,8 +1017,8 @@ TEST_CLASS (NativeModuleTest) { m_builderMock.Call2( L"NegatePromise", std::function([](int result) noexcept { TestCheck(result == -5); }), - std::function( - [](JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), 5); TestCheck(m_builderMock.IsResolveCallbackCalled()); } @@ -1037,8 +1027,8 @@ TEST_CLASS (NativeModuleTest) { m_builderMock.Call2( L"NegatePromise", std::function([](int result) noexcept { TestCheck(result == -5); }), - std::function( - [](JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), -5); TestCheck(m_builderMock.IsRejectCallbackCalled()); } @@ -1047,8 +1037,8 @@ TEST_CLASS (NativeModuleTest) { Mso::FutureWait(m_builderMock.Call2( L"NegateAsyncPromise", std::function([](int result) noexcept { TestCheck(result == -5); }), - std::function( - [](JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), 5)); TestCheck(m_builderMock.IsResolveCallbackCalled()); } @@ -1057,8 +1047,8 @@ TEST_CLASS (NativeModuleTest) { Mso::FutureWait(m_builderMock.Call2( L"NegateAsyncPromise", std::function([](int result) noexcept { TestCheck(result == -5); }), - std::function( - [](JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), -5)); TestCheck(m_builderMock.IsRejectCallbackCalled()); } @@ -1067,8 +1057,8 @@ TEST_CLASS (NativeModuleTest) { Mso::FutureWait(m_builderMock.Call2( L"NegateDispatchQueuePromise", std::function([](int result) noexcept { TestCheck(result == -5); }), - std::function( - [](JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), 5)); TestCheck(m_builderMock.IsResolveCallbackCalled()); } @@ -1077,8 +1067,8 @@ TEST_CLASS (NativeModuleTest) { Mso::FutureWait(m_builderMock.Call2( L"NegateDispatchQueuePromise", std::function([](int result) noexcept { TestCheck(result == -5); }), - std::function( - [](JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), -5)); TestCheck(m_builderMock.IsRejectCallbackCalled()); } @@ -1087,8 +1077,8 @@ TEST_CLASS (NativeModuleTest) { Mso::FutureWait(m_builderMock.Call2( L"NegateFuturePromise", std::function([](int result) noexcept { TestCheck(result == -5); }), - std::function( - [](JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), 5)); TestCheck(m_builderMock.IsResolveCallbackCalled()); } @@ -1097,8 +1087,8 @@ TEST_CLASS (NativeModuleTest) { Mso::FutureWait(m_builderMock.Call2( L"NegateFuturePromise", std::function([](int result) noexcept { TestCheck(result == -5); }), - std::function( - [](JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), -5)); TestCheck(m_builderMock.IsRejectCallbackCalled()); } @@ -1107,8 +1097,8 @@ TEST_CLASS (NativeModuleTest) { m_builderMock.Call2( L"voidPromise", std::function([]() noexcept {}), - std::function( - [](JSValue const &error) noexcept { TestCheck(error["message"] == "Odd unexpected"); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Odd unexpected"); }), 2); TestCheck(m_builderMock.IsResolveCallbackCalled()); } @@ -1117,8 +1107,8 @@ TEST_CLASS (NativeModuleTest) { m_builderMock.Call2( L"voidPromise", std::function([]() noexcept {}), - std::function( - [](JSValue const &error) noexcept { TestCheck(error["message"] == "Odd unexpected"); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Odd unexpected"); }), 3); TestCheck(m_builderMock.IsRejectCallbackCalled()); } @@ -1128,8 +1118,8 @@ TEST_CLASS (NativeModuleTest) { L"ResolveSayHelloPromise", std::function( [](const std::string &result) noexcept { TestCheck(result == "Hello_4"); }), - std::function( - [](JSValue const &error) noexcept { TestCheck(error["message"] == "Promise rejected"); })); + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Promise rejected"); })); TestCheck(m_builderMock.IsResolveCallbackCalled()); } @@ -1138,8 +1128,8 @@ TEST_CLASS (NativeModuleTest) { L"RejectSayHelloPromise", std::function( [](const std::string &result) noexcept { TestCheck(result == "Hello_4"); }), - std::function( - [](JSValue const &error) noexcept { TestCheck(error["message"] == "Promise rejected"); })); + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Promise rejected"); })); TestCheck(m_builderMock.IsRejectCallbackCalled()); } @@ -1147,8 +1137,8 @@ TEST_CLASS (NativeModuleTest) { m_builderMock.Call2( L"StaticDividePromise", std::function([](int result) noexcept { TestCheck(result == 3); }), - std::function( - [](JSValue const &error) noexcept { TestCheck(error["message"] == "Division by 0"); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Division by 0"); }), 6, 2); TestCheck(m_builderMock.IsResolveCallbackCalled()); @@ -1158,8 +1148,8 @@ TEST_CLASS (NativeModuleTest) { m_builderMock.Call2( L"StaticDividePromise", std::function([](int result) noexcept { TestCheck(result == 3); }), - std::function( - [](JSValue const &error) noexcept { TestCheck(error["message"] == "Division by 0"); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Division by 0"); }), 6, 0); TestCheck(m_builderMock.IsRejectCallbackCalled()); @@ -1169,8 +1159,8 @@ TEST_CLASS (NativeModuleTest) { m_builderMock.Call2( L"StaticNegatePromise", std::function([](int result) noexcept { TestCheck(result == -5); }), - std::function( - [](JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), 5); TestCheck(m_builderMock.IsResolveCallbackCalled()); } @@ -1179,8 +1169,8 @@ TEST_CLASS (NativeModuleTest) { Mso::FutureWait(m_builderMock.Call2( L"StaticNegateAsyncPromise", std::function([](int result) noexcept { TestCheck(result == -5); }), - std::function( - [](JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), -5)); TestCheck(m_builderMock.IsRejectCallbackCalled()); } @@ -1189,8 +1179,8 @@ TEST_CLASS (NativeModuleTest) { Mso::FutureWait(m_builderMock.Call2( L"StaticNegateAsyncPromise", std::function([](int result) noexcept { TestCheck(result == -5); }), - std::function( - [](JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), 5)); TestCheck(m_builderMock.IsResolveCallbackCalled()); } @@ -1199,8 +1189,8 @@ TEST_CLASS (NativeModuleTest) { m_builderMock.Call2( L"StaticNegatePromise", std::function([](int result) noexcept { TestCheck(result == -5); }), - std::function( - [](JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), -5); TestCheck(m_builderMock.IsRejectCallbackCalled()); } @@ -1209,8 +1199,8 @@ TEST_CLASS (NativeModuleTest) { Mso::FutureWait(m_builderMock.Call2( L"StaticNegateDispatchQueuePromise", std::function([](int result) noexcept { TestCheck(result == -5); }), - std::function( - [](JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), 5)); TestCheck(m_builderMock.IsResolveCallbackCalled()); } @@ -1219,8 +1209,8 @@ TEST_CLASS (NativeModuleTest) { Mso::FutureWait(m_builderMock.Call2( L"StaticNegateDispatchQueuePromise", std::function([](int result) noexcept { TestCheck(result == -5); }), - std::function( - [](JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), -5)); TestCheck(m_builderMock.IsRejectCallbackCalled()); } @@ -1229,8 +1219,8 @@ TEST_CLASS (NativeModuleTest) { Mso::FutureWait(m_builderMock.Call2( L"StaticNegateFuturePromise", std::function([](int result) noexcept { TestCheck(result == -5); }), - std::function( - [](JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), 5)); TestCheck(m_builderMock.IsResolveCallbackCalled()); } @@ -1239,8 +1229,8 @@ TEST_CLASS (NativeModuleTest) { Mso::FutureWait(m_builderMock.Call2( L"StaticNegateFuturePromise", std::function([](int result) noexcept { TestCheck(result == -5); }), - std::function( - [](JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), -5)); TestCheck(m_builderMock.IsRejectCallbackCalled()); } @@ -1249,8 +1239,8 @@ TEST_CLASS (NativeModuleTest) { m_builderMock.Call2( L"staticVoidPromise", std::function([]() noexcept {}), - std::function( - [](JSValue const &error) noexcept { TestCheck(error["message"] == "Odd unexpected"); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Odd unexpected"); }), 2); TestCheck(m_builderMock.IsResolveCallbackCalled()); } @@ -1259,8 +1249,8 @@ TEST_CLASS (NativeModuleTest) { m_builderMock.Call2( L"staticVoidPromise", std::function([]() noexcept {}), - std::function( - [](JSValue const &error) noexcept { TestCheck(error["message"] == "Odd unexpected"); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Odd unexpected"); }), 3); TestCheck(m_builderMock.IsRejectCallbackCalled()); } @@ -1270,8 +1260,8 @@ TEST_CLASS (NativeModuleTest) { L"StaticResolveSayHelloPromise", std::function( [](const std::string &result) noexcept { TestCheck(result == "Hello_4"); }), - std::function( - [](JSValue const &error) noexcept { TestCheck(error["message"] == "Promise rejected"); })); + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Promise rejected"); })); TestCheck(m_builderMock.IsResolveCallbackCalled()); } @@ -1280,8 +1270,8 @@ TEST_CLASS (NativeModuleTest) { L"StaticRejectSayHelloPromise", std::function( [](const std::string &result) noexcept { TestCheck(result == "Hello_4"); }), - std::function( - [](JSValue const &error) noexcept { TestCheck(error["message"] == "Promise rejected"); })); + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Promise rejected"); })); TestCheck(m_builderMock.IsRejectCallbackCalled()); } @@ -1340,7 +1330,7 @@ TEST_CLASS (NativeModuleTest) { TEST_METHOD(TestEvent_IntEventField) { bool eventRaised = false; m_builderMock.ExpectEvent( - L"RCTDeviceEventEmitter", L"OnIntEvent", [&eventRaised](JSValueArray const &args) noexcept { + L"RCTDeviceEventEmitter", L"OnIntEvent", [&eventRaised](React::JSValueArray const &args) noexcept { TestCheck(args[0] == 42); eventRaised = true; }); @@ -1352,7 +1342,7 @@ TEST_CLASS (NativeModuleTest) { TEST_METHOD(TestEvent_OnNoArgEventField) { bool eventRaised = false; m_builderMock.ExpectEvent( - L"RCTDeviceEventEmitter", L"OnNoArgEvent", [&eventRaised](JSValueArray const &args) noexcept { + L"RCTDeviceEventEmitter", L"OnNoArgEvent", [&eventRaised](React::JSValueArray const &args) noexcept { TestCheckEqual(0, args.size()); eventRaised = true; }); @@ -1364,7 +1354,7 @@ TEST_CLASS (NativeModuleTest) { TEST_METHOD(TestEvent_TwoArgsEventField) { bool eventRaised = false; m_builderMock.ExpectEvent( - L"RCTDeviceEventEmitter", L"OnTwoArgsEvent", [&eventRaised](JSValueArray const &args) noexcept { + L"RCTDeviceEventEmitter", L"OnTwoArgsEvent", [&eventRaised](React::JSValueArray const &args) noexcept { TestCheckEqual(4, args[0]["X"]); TestCheckEqual(2, args[0]["Y"]); TestCheckEqual(12, args[1]["X"]); @@ -1379,7 +1369,7 @@ TEST_CLASS (NativeModuleTest) { TEST_METHOD(TestEvent_JSNameEventField) { bool eventRaised = false; m_builderMock.ExpectEvent( - L"RCTDeviceEventEmitter", L"onPointEvent", [&eventRaised](JSValueArray const &args) noexcept { + L"RCTDeviceEventEmitter", L"onPointEvent", [&eventRaised](React::JSValueArray const &args) noexcept { TestCheck(args[0]["X"] == 4); TestCheck(args[0]["Y"] == 2); eventRaised = true; @@ -1391,10 +1381,11 @@ TEST_CLASS (NativeModuleTest) { TEST_METHOD(TestEvent_JSEventEmitterEventField) { bool eventRaised = false; - m_builderMock.ExpectEvent(L"MyEventEmitter", L"onStringEvent", [&eventRaised](JSValueArray const &args) noexcept { - TestCheckEqual("Hello World!", args[0]); - eventRaised = true; - }); + m_builderMock.ExpectEvent( + L"MyEventEmitter", L"onStringEvent", [&eventRaised](React::JSValueArray const &args) noexcept { + TestCheckEqual("Hello World!", args[0]); + eventRaised = true; + }); m_module->OnStringEvent("Hello World!"); TestCheck(eventRaised == true); @@ -1403,20 +1394,20 @@ TEST_CLASS (NativeModuleTest) { TEST_METHOD(TestEvent_JSValueObjectEventField) { bool eventRaised = false; m_builderMock.ExpectEvent( - L"RCTDeviceEventEmitter", L"OnJSValueEvent", ([&eventRaised](JSValueArray const &args) noexcept { + L"RCTDeviceEventEmitter", L"OnJSValueEvent", ([&eventRaised](React::JSValueArray const &args) noexcept { TestCheck(args[0]["X"] == 4); TestCheck(args[0]["Y"] == 2); eventRaised = true; })); - m_module->OnJSValueEvent(JSValueObject{{"X", 4}, {"Y", 2}}); + m_module->OnJSValueEvent(React::JSValueObject{{"X", 4}, {"Y", 2}}); TestCheck(eventRaised == true); } TEST_METHOD(TestEvent_JSValueArrayEventField) { bool eventRaised = false; m_builderMock.ExpectEvent( - L"RCTDeviceEventEmitter", L"OnJSValueEvent", ([&eventRaised](JSValueArray const &args) noexcept { + L"RCTDeviceEventEmitter", L"OnJSValueEvent", ([&eventRaised](React::JSValueArray const &args) noexcept { TestCheck(args[0][0] == "X"); TestCheck(args[0][1] == 4); TestCheck(args[0][2] == true); @@ -1424,26 +1415,26 @@ TEST_CLASS (NativeModuleTest) { eventRaised = true; })); - m_module->OnJSValueEvent(JSValueArray{"X", 4, true, JSValueObject{{"Id", 42}}}); + m_module->OnJSValueEvent(React::JSValueArray{"X", 4, true, React::JSValueObject{{"Id", 42}}}); TestCheck(eventRaised == true); } TEST_METHOD(TestEvent_JSValueArray1EventField) { bool eventRaised = false; m_builderMock.ExpectEvent( - L"RCTDeviceEventEmitter", L"OnJSValueEvent", ([&eventRaised](JSValueArray const &args) noexcept { + L"RCTDeviceEventEmitter", L"OnJSValueEvent", ([&eventRaised](React::JSValueArray const &args) noexcept { TestCheck(args[0][0] == 4); eventRaised = true; })); - m_module->OnJSValueEvent(JSValueArray{4}); + m_module->OnJSValueEvent(React::JSValueArray{4}); TestCheck(eventRaised == true); } TEST_METHOD(TestFunction_JSIntFunctionField) { bool functionCalled = false; m_builderMock.ExpectFunction( - L"SimpleNativeModule", L"JSIntFunction", [&functionCalled](JSValueArray const &args) noexcept { + L"SimpleNativeModule", L"JSIntFunction", [&functionCalled](React::JSValueArray const &args) noexcept { TestCheck(args[0] == 42); functionCalled = true; }); @@ -1455,7 +1446,7 @@ TEST_CLASS (NativeModuleTest) { TEST_METHOD(TestFunction_JSNameFunctionField) { bool functionCalled = false; m_builderMock.ExpectFunction( - L"SimpleNativeModule", L"pointFunc", [&functionCalled](JSValueArray const &args) noexcept { + L"SimpleNativeModule", L"pointFunc", [&functionCalled](React::JSValueArray const &args) noexcept { TestCheck(args[0]["X"] == 4); TestCheck(args[0]["Y"] == 2); functionCalled = true; @@ -1468,7 +1459,7 @@ TEST_CLASS (NativeModuleTest) { TEST_METHOD(TestFunction_TwoArgFunctionField) { bool functionCalled = false; m_builderMock.ExpectFunction( - L"SimpleNativeModule", L"lineFunc", [&functionCalled](JSValueArray const &args) noexcept { + L"SimpleNativeModule", L"lineFunc", [&functionCalled](React::JSValueArray const &args) noexcept { TestCheck(args[0]["X"] == 4); TestCheck(args[0]["Y"] == 2); TestCheck(args[1]["X"] == 12); @@ -1483,7 +1474,7 @@ TEST_CLASS (NativeModuleTest) { TEST_METHOD(TestFunction_NoArgFunctionField) { bool functionCalled = false; m_builderMock.ExpectFunction( - L"SimpleNativeModule", L"JSNoArgFunction", [&functionCalled](JSValueArray const &args) noexcept { + L"SimpleNativeModule", L"JSNoArgFunction", [&functionCalled](React::JSValueArray const &args) noexcept { TestCheckEqual(0, args.size()); functionCalled = true; }); @@ -1494,10 +1485,11 @@ TEST_CLASS (NativeModuleTest) { TEST_METHOD(TestFunction_JSModuleNameFunctionField) { bool functionCalled = false; - m_builderMock.ExpectFunction(L"MyModule", L"stringFunc", [&functionCalled](JSValueArray const &args) noexcept { - TestCheck(args[0] == "Hello World!"); - functionCalled = true; - }); + m_builderMock.ExpectFunction( + L"MyModule", L"stringFunc", [&functionCalled](React::JSValueArray const &args) noexcept { + TestCheck(args[0] == "Hello World!"); + functionCalled = true; + }); m_module->JSStringFunction("Hello World!"); TestCheck(functionCalled == true); @@ -1506,20 +1498,20 @@ TEST_CLASS (NativeModuleTest) { TEST_METHOD(TestFunction_JSValueObjectFunctionField) { bool functionCalled = false; m_builderMock.ExpectFunction( - L"SimpleNativeModule", L"JSValueFunction", ([&functionCalled](JSValueArray const &args) noexcept { + L"SimpleNativeModule", L"JSValueFunction", ([&functionCalled](React::JSValueArray const &args) noexcept { TestCheck(args[0]["X"] == 4); TestCheck(args[0]["Y"] == 2); functionCalled = true; })); - m_module->JSValueFunction(JSValueObject{{"X", 4}, {"Y", 2}}); + m_module->JSValueFunction(React::JSValueObject{{"X", 4}, {"Y", 2}}); TestCheck(functionCalled == true); } TEST_METHOD(TestFunction_JSValueArrayFunctionField) { bool functionCalled = false; m_builderMock.ExpectFunction( - L"SimpleNativeModule", L"JSValueFunction", ([&functionCalled](JSValueArray const &args) noexcept { + L"SimpleNativeModule", L"JSValueFunction", ([&functionCalled](React::JSValueArray const &args) noexcept { TestCheck(args[0][0] == "X"); TestCheck(args[0][1] == 4); TestCheck(args[0][2] == true); @@ -1527,7 +1519,7 @@ TEST_CLASS (NativeModuleTest) { functionCalled = true; })); - m_module->JSValueFunction(JSValueArray{"X", 4, true, JSValueObject{{"Id", 42}}}); + m_module->JSValueFunction(React::JSValueArray{"X", 4, true, React::JSValueObject{{"Id", 42}}}); TestCheck(functionCalled == true); } @@ -1536,4 +1528,4 @@ TEST_CLASS (NativeModuleTest) { } }; -} // namespace winrt::Microsoft::ReactNative +} // namespace ReactNativeTests diff --git a/vnext/Microsoft.ReactNative.Cxx.UnitTests/NoAttributeNativeModuleTest.cpp b/vnext/Microsoft.ReactNative.Cxx.UnitTests/NoAttributeNativeModuleTest.cpp index 149e39eec87..35c2af283aa 100644 --- a/vnext/Microsoft.ReactNative.Cxx.UnitTests/NoAttributeNativeModuleTest.cpp +++ b/vnext/Microsoft.ReactNative.Cxx.UnitTests/NoAttributeNativeModuleTest.cpp @@ -507,7 +507,7 @@ struct SimpleNativeModule2 { /*static*/ std::string SimpleNativeModule2::StaticMessage; -void RegisterModule(ReactModuleBuilder &moduleBuilder) noexcept { +void GetReactModuleInfo(SimpleNativeModule2 *, ReactModuleBuilder &moduleBuilder) noexcept { moduleBuilder.RegisterModuleName(L"SimpleNativeModule2"); moduleBuilder.RegisterInitMethod(&SimpleNativeModule2::Initialize); moduleBuilder.RegisterMethod(&SimpleNativeModule2::Add, L"Add"); @@ -577,8 +577,8 @@ void RegisterModule(ReactModuleBuilder &moduleBuilder) noex moduleBuilder.RegisterConstantField(&SimpleNativeModule2::Constant2, L"const2"); moduleBuilder.RegisterConstantField(&SimpleNativeModule2::Constant3, L"const3"); moduleBuilder.RegisterConstantField(&SimpleNativeModule2::Constant4, L"Constant4"); - moduleBuilder.RegisterConstantMethod(&SimpleNativeModule2::Constant5, L"Constant5"); - moduleBuilder.RegisterConstantMethod(&SimpleNativeModule2::Constant6, L"Constant6"); + moduleBuilder.RegisterConstantMethod(&SimpleNativeModule2::Constant5); + moduleBuilder.RegisterConstantMethod(&SimpleNativeModule2::Constant6); moduleBuilder.RegisterEventField(&SimpleNativeModule2::OnIntEvent, L"OnIntEvent"); moduleBuilder.RegisterEventField(&SimpleNativeModule2::OnNoArgEvent, L"OnNoArgEvent"); moduleBuilder.RegisterEventField(&SimpleNativeModule2::OnTwoArgsEvent, L"OnTwoArgsEvent"); diff --git a/vnext/Microsoft.ReactNative.Cxx.UnitTests/Point.h b/vnext/Microsoft.ReactNative.Cxx.UnitTests/Point.h new file mode 100644 index 00000000000..d711b247c33 --- /dev/null +++ b/vnext/Microsoft.ReactNative.Cxx.UnitTests/Point.h @@ -0,0 +1,15 @@ +#pragma once +#include "NativeModules.h" + +namespace ReactNativeTests { + +REACT_STRUCT(Point) +struct Point { + REACT_FIELD(X) + int X; + + REACT_FIELD(Y) + int Y; +}; + +} // namespace ReactNativeTests diff --git a/vnext/Microsoft.ReactNative.Cxx.UnitTests/ReactModuleBuilderMock.h b/vnext/Microsoft.ReactNative.Cxx.UnitTests/ReactModuleBuilderMock.h index ded81090484..88ec6935f02 100644 --- a/vnext/Microsoft.ReactNative.Cxx.UnitTests/ReactModuleBuilderMock.h +++ b/vnext/Microsoft.ReactNative.Cxx.UnitTests/ReactModuleBuilderMock.h @@ -112,8 +112,8 @@ struct ReactModuleBuilderMock { std::vector m_constantProviders; std::map> m_methods; std::map m_syncMethods; - bool m_isResolveCallbackCalled; - bool m_isRejectCallbackCalled; + bool m_isResolveCallbackCalled{false}; + bool m_isRejectCallbackCalled{false}; Mso::Functor m_jsFunctionHandler; Mso::Functor m_jsEventHandler; }; diff --git a/vnext/Microsoft.ReactNative.Cxx.UnitTests/TurboModuleTest.cpp b/vnext/Microsoft.ReactNative.Cxx.UnitTests/TurboModuleTest.cpp new file mode 100644 index 00000000000..7564168c4dd --- /dev/null +++ b/vnext/Microsoft.ReactNative.Cxx.UnitTests/TurboModuleTest.cpp @@ -0,0 +1,2050 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#include "pch.h" +#include "ReactModuleBuilderMock.h" + +#include +#include "Point.h" +#include "future/futureWait.h" + +namespace ReactNativeTests { +REACT_MODULE(MyTurboModule) +struct MyTurboModule { + REACT_INIT(Initialize) + void Initialize(React::IReactContext const &context) noexcept { + IsInitialized = true; + TestCheck(context != nullptr); + + // Event and Function fields are initialized before REACT_INIT method call. + TestCheck(this->OnIntEvent != nullptr); + TestCheck(this->JSIntFunction != nullptr); + } + + REACT_METHOD(Add) + int Add(int x, int y) noexcept { + return x + y; + } + + REACT_METHOD(Negate) + int Negate(int x) noexcept { + return -x; + } + + REACT_METHOD(SayHello) + std::string SayHello() noexcept { + return "Hello"; + } + + REACT_METHOD(StaticAdd) + static int StaticAdd(int x, int y) noexcept { + return x + y; + } + + REACT_METHOD(StaticNegate) + static int StaticNegate(int x) noexcept { + return -x; + } + + REACT_METHOD(StaticSayHello) + static std::string StaticSayHello() noexcept { + return "Hello"; + } + + REACT_METHOD(SayHello0) + void SayHello0() noexcept { + Message = "Hello_0"; + } + + REACT_METHOD(PrintPoint) + void PrintPoint(Point pt) noexcept { + std::stringstream ss; + ss << "Point: (" << pt.X << ", " << pt.Y << ")"; + Message = ss.str(); + } + + REACT_METHOD(PrintLine) + void PrintLine(Point start, Point end) noexcept { + std::stringstream ss; + ss << "Line: (" << start.X << ", " << start.Y << ")-(" << end.X << ", " << end.Y << ")"; + Message = ss.str(); + } + + REACT_METHOD(StaticSayHello0) + static void StaticSayHello0() noexcept { + StaticMessage = "Hello_0"; + } + + REACT_METHOD(StaticPrintPoint) + static void StaticPrintPoint(Point pt) noexcept { + std::stringstream ss; + ss << "Static Point: (" << pt.X << ", " << pt.Y << ")"; + StaticMessage = ss.str(); + } + + REACT_METHOD(StaticPrintLine) + static void StaticPrintLine(Point start, Point end) noexcept { + std::stringstream ss; + ss << "Static Line: (" << start.X << ", " << start.Y << ")-(" << end.X << ", " << end.Y << ")"; + StaticMessage = ss.str(); + } + + REACT_METHOD(AddCallback) + void AddCallback(int x, int y, std::function const &resolve) noexcept { + resolve(x + y); + } + + REACT_METHOD(NegateCallback) + void NegateCallback(int x, std::function const &resolve) noexcept { + resolve(-x); + } + + REACT_METHOD(NegateAsyncCallback) + fire_and_forget NegateAsyncCallback(int x, std::function resolve) noexcept { + co_await winrt::resume_background(); + resolve(-x); + } + + REACT_METHOD(NegateDispatchQueueCallback) + void NegateDispatchQueueCallback(int x, std::function const &resolve) noexcept { + Mso::DispatchQueue::ConcurrentQueue().Post([ x, resolve ]() noexcept { resolve(-x); }); + } + + REACT_METHOD(NegateFutureCallback) + void NegateFutureCallback(int x, std::function const &resolve) noexcept { + Mso::PostFuture([ x, resolve ]() noexcept { resolve(-x); }); + } + + REACT_METHOD(SayHelloCallback) + void SayHelloCallback(std::function const &resolve) noexcept { + resolve("Hello_2"); + } + + REACT_METHOD(StaticAddCallback) + static void StaticAddCallback(int x, int y, std::function const &resolve) noexcept { + resolve(x + y); + } + + REACT_METHOD(StaticNegateCallback) + static void StaticNegateCallback(int x, std::function const &resolve) noexcept { + resolve(-x); + } + + REACT_METHOD(StaticNegateAsyncCallback) + static fire_and_forget StaticNegateAsyncCallback(int x, std::function resolve) noexcept { + co_await winrt::resume_background(); + resolve(-x); + } + + REACT_METHOD(StaticNegateDispatchQueueCallback) + static void StaticNegateDispatchQueueCallback(int x, std::function const &resolve) noexcept { + Mso::DispatchQueue::ConcurrentQueue().Post([ x, resolve ]() noexcept { resolve(-x); }); + } + + REACT_METHOD(StaticNegateFutureCallback) + static void StaticNegateFutureCallback(int x, std::function const &resolve) noexcept { + Mso::PostFuture([ x, resolve ]() noexcept { resolve(-x); }); + } + + REACT_METHOD(StaticSayHelloCallback) + static void StaticSayHelloCallback(std::function const &resolve) noexcept { + resolve("Static Hello_2"); + } + + REACT_METHOD(DivideCallbacks) + void DivideCallbacks( + int x, + int y, + std::function const &resolve, + std::function const &reject) noexcept { + if (y != 0) { + resolve(x / y); + } else { + reject("Division by 0"); + } + } + + REACT_METHOD(NegateCallbacks) + void NegateCallbacks( + int x, + std::function const &resolve, + std::function const &reject) noexcept { + if (x >= 0) { + resolve(-x); + } else { + reject("Already negative"); + } + } + + REACT_METHOD(NegateAsyncCallbacks) + fire_and_forget NegateAsyncCallbacks( + int x, + std::function resolve, + std::function reject) noexcept { + co_await winrt::resume_background(); + if (x >= 0) { + resolve(-x); + } else { + reject("Already negative"); + } + } + + REACT_METHOD(NegateDispatchQueueCallbacks) + void NegateDispatchQueueCallbacks( + int x, + std::function const &resolve, + std::function const &reject) noexcept { + Mso::DispatchQueue::ConcurrentQueue().Post([ x, resolve, reject ]() noexcept { + if (x >= 0) { + resolve(-x); + } else { + reject("Already negative"); + } + }); + } + + REACT_METHOD(NegateFutureCallbacks) + void NegateFutureCallbacks( + int x, + std::function const &resolve, + std::function const &reject) noexcept { + Mso::PostFuture([ x, resolve, reject ]() noexcept { + if (x >= 0) { + resolve(-x); + } else { + reject("Already negative"); + } + }); + } + + REACT_METHOD(ResolveSayHelloCallbacks) + void ResolveSayHelloCallbacks( + std::function const &resolve, + std::function const & /*reject*/) noexcept { + resolve("Hello_3"); + } + + REACT_METHOD(RejectSayHelloCallbacks) + void RejectSayHelloCallbacks( + std::function const & /*resolve*/, + std::function const &reject) noexcept { + reject("Goodbye"); + } + + REACT_METHOD(StaticDivideCallbacks) + static void StaticDivideCallbacks( + int x, + int y, + std::function const &resolve, + std::function const &reject) noexcept { + if (y != 0) { + resolve(x / y); + } else { + reject("Division by 0"); + } + } + + REACT_METHOD(StaticNegateCallbacks) + static void StaticNegateCallbacks( + int x, + std::function const &resolve, + std::function const &reject) noexcept { + if (x >= 0) { + resolve(-x); + } else { + reject("Already negative"); + } + } + + REACT_METHOD(StaticNegateAsyncCallbacks) + static fire_and_forget StaticNegateAsyncCallbacks( + int x, + std::function resolve, + std::function reject) noexcept { + co_await winrt::resume_background(); + if (x >= 0) { + resolve(-x); + } else { + reject("Already negative"); + } + } + + REACT_METHOD(StaticNegateDispatchQueueCallbacks) + static void StaticNegateDispatchQueueCallbacks( + int x, + std::function const &resolve, + std::function const &reject) noexcept { + Mso::DispatchQueue::ConcurrentQueue().Post([ x, resolve, reject ]() noexcept { + if (x >= 0) { + resolve(-x); + } else { + reject("Already negative"); + } + }); + } + + REACT_METHOD(StaticNegateFutureCallbacks) + static void StaticNegateFutureCallbacks( + int x, + std::function const &resolve, + std::function const &reject) noexcept { + Mso::PostFuture([ x, resolve, reject ]() noexcept { + if (x >= 0) { + resolve(-x); + } else { + reject("Already negative"); + } + }); + } + + REACT_METHOD(StaticResolveSayHelloCallbacks) + static void StaticResolveSayHelloCallbacks( + std::function const &resolve, + std::function const & /*reject*/) noexcept { + resolve("Hello_3"); + } + + REACT_METHOD(StaticRejectSayHelloCallbacks) + static void StaticRejectSayHelloCallbacks( + std::function const & /*resolve*/, + std::function const &reject) noexcept { + reject("Goodbye"); + } + + REACT_METHOD(DividePromise) + void DividePromise(int x, int y, React::ReactPromise const &result) noexcept { + if (y != 0) { + result.Resolve(x / y); + } else { + React::ReactError error{}; + error.Message = "Division by 0"; + result.Reject(std::move(error)); + } + } + + REACT_METHOD(NegatePromise) + void NegatePromise(int x, React::ReactPromise const &result) noexcept { + if (x >= 0) { + result.Resolve(-x); + } else { + React::ReactError error{}; + error.Message = "Already negative"; + result.Reject(std::move(error)); + } + } + + REACT_METHOD(NegateAsyncPromise) + fire_and_forget NegateAsyncPromise(int x, React::ReactPromise result) noexcept { + co_await winrt::resume_background(); + if (x >= 0) { + result.Resolve(-x); + } else { + React::ReactError error{}; + error.Message = "Already negative"; + result.Reject(std::move(error)); + } + } + + REACT_METHOD(NegateDispatchQueuePromise) + void NegateDispatchQueuePromise(int x, React::ReactPromise const &result) noexcept { + Mso::DispatchQueue::ConcurrentQueue().Post([ x, result ]() noexcept { + if (x >= 0) { + result.Resolve(-x); + } else { + React::ReactError error{}; + error.Message = "Already negative"; + result.Reject(std::move(error)); + } + }); + } + + REACT_METHOD(NegateFuturePromise) + void NegateFuturePromise(int x, React::ReactPromise const &result) noexcept { + Mso::PostFuture([ x, result ]() noexcept { + if (x >= 0) { + result.Resolve(-x); + } else { + React::ReactError error{}; + error.Message = "Already negative"; + result.Reject(std::move(error)); + } + }); + } + + // Each macro has second optional parameter: JS name. + REACT_METHOD(VoidPromise, L"voidPromise") + void VoidPromise(int x, React::ReactPromise const &result) noexcept { + if (x % 2 == 0) { + result.Resolve(); + } else { + result.Reject("Odd unexpected"); + } + } + + REACT_METHOD(ResolveSayHelloPromise) + void ResolveSayHelloPromise(React::ReactPromise const &result) noexcept { + result.Resolve("Hello_4"); + } + + REACT_METHOD(RejectSayHelloPromise) + void RejectSayHelloPromise(React::ReactPromise const &result) noexcept { + React::ReactError error{}; + error.Message = "Promise rejected"; + result.Reject(std::move(error)); + } + + REACT_METHOD(StaticDividePromise) + static void StaticDividePromise(int x, int y, React::ReactPromise const &result) noexcept { + if (y != 0) { + result.Resolve(x / y); + } else { + React::ReactError error{}; + error.Message = "Division by 0"; + result.Reject(std::move(error)); + } + } + + REACT_METHOD(StaticNegatePromise) + static void StaticNegatePromise(int x, React::ReactPromise const &result) noexcept { + if (x >= 0) { + result.Resolve(-x); + } else { + React::ReactError error{}; + error.Message = "Already negative"; + result.Reject(std::move(error)); + } + } + + REACT_METHOD(StaticNegateAsyncPromise) + static fire_and_forget StaticNegateAsyncPromise(int x, React::ReactPromise result) noexcept { + co_await winrt::resume_background(); + if (x >= 0) { + result.Resolve(-x); + } else { + React::ReactError error{}; + error.Message = "Already negative"; + result.Reject(std::move(error)); + } + } + + REACT_METHOD(StaticNegateDispatchQueuePromise) + static void StaticNegateDispatchQueuePromise(int x, React::ReactPromise const &result) noexcept { + Mso::DispatchQueue::ConcurrentQueue().Post([ x, result ]() noexcept { + if (x >= 0) { + result.Resolve(-x); + } else { + React::ReactError error{}; + error.Message = "Already negative"; + result.Reject(std::move(error)); + } + }); + } + + REACT_METHOD(StaticNegateFuturePromise) + static void StaticNegateFuturePromise(int x, React::ReactPromise const &result) noexcept { + Mso::PostFuture([ x, result ]() noexcept { + if (x >= 0) { + result.Resolve(-x); + } else { + React::ReactError error{}; + error.Message = "Already negative"; + result.Reject(std::move(error)); + } + }); + } + + // Each macro has second optional parameter: JS name. + REACT_METHOD(StaticVoidPromise, L"staticVoidPromise") + void StaticVoidPromise(int x, React::ReactPromise const &result) noexcept { + if (x % 2 == 0) { + result.Resolve(); + } else { + result.Reject("Odd unexpected"); + } + } + + REACT_METHOD(StaticResolveSayHelloPromise) + static void StaticResolveSayHelloPromise(React::ReactPromise const &result) noexcept { + result.Resolve("Hello_4"); + } + + REACT_METHOD(StaticRejectSayHelloPromise) + static void StaticRejectSayHelloPromise(React::ReactPromise const &result) noexcept { + React::ReactError error{}; + error.Message = "Promise rejected"; + result.Reject(std::move(error)); + } + + REACT_SYNC_METHOD(AddSync) + int AddSync(int x, int y) noexcept { + return x + y; + } + + REACT_SYNC_METHOD(NegateSync) + int NegateSync(int x) noexcept { + return -x; + } + + REACT_SYNC_METHOD(SayHelloSync) + std::string SayHelloSync() noexcept { + return "Hello"; + } + + REACT_SYNC_METHOD(StaticAddSync) + static int StaticAddSync(int x, int y) noexcept { + return x + y; + } + + REACT_SYNC_METHOD(StaticNegateSync) + static int StaticNegateSync(int x) noexcept { + return -x; + } + + REACT_SYNC_METHOD(StaticSayHelloSync) + static std::string StaticSayHelloSync() noexcept { + return "Hello"; + } + + REACT_CONSTANT(Constant1) + const std::string Constant1{"MyConstant1"}; + + REACT_CONSTANT(Constant2, L"const2") + const std::string Constant2{"MyConstant2"}; + + REACT_CONSTANT(Constant3, L"const3") + static constexpr Point Constant3{/*X =*/2, /*Y =*/3}; + + REACT_CONSTANT(Constant4) + static constexpr Point Constant4{/*X =*/3, /*Y =*/4}; + + REACT_CONSTANT_PROVIDER(Constant5) + void Constant5(React::ReactConstantProvider &provider) noexcept { + provider.Add(L"const51", Point{/*X =*/12, /*Y =*/14}); + provider.Add(L"const52", "MyConstant52"); + } + + REACT_CONSTANT_PROVIDER(Constant6) + static void Constant6(React::ReactConstantProvider &provider) noexcept { + provider.Add(L"const61", Point{/*X =*/15, /*Y =*/17}); + provider.Add(L"const62", "MyConstant62"); + } + + // Allows to emit native module events + REACT_EVENT(OnIntEvent) + std::function OnIntEvent; + + // An event without arguments + REACT_EVENT(OnNoArgEvent) + std::function OnNoArgEvent; + + // An event with two arguments + REACT_EVENT(OnTwoArgsEvent) + std::function OnTwoArgsEvent; + + // Specify event name different from the field name. + REACT_EVENT(OnPointEvent, L"onPointEvent") + std::function OnPointEvent; + + // By default we use the event emitter name from REACT_MODULE which is by default 'RCTDeviceEventEmitter'. + // Here we specify event emitter name local for this event. + REACT_EVENT(OnStringEvent, L"onStringEvent", L"MyEventEmitter") + std::function OnStringEvent; + + // Use React::JSValue which is an immutable JSON-like data representation. + REACT_EVENT(OnJSValueEvent) + std::function OnJSValueEvent; + + // Allows to call JS functions. + REACT_FUNCTION(JSIntFunction) + std::function JSIntFunction; + + // Specify JS function name different from the field name. + REACT_FUNCTION(JSPointFunction, L"pointFunc") + std::function JSPointFunction; + + // Use two arguments. Specify JS function name different from the field name. + REACT_FUNCTION(JSLineFunction, L"lineFunc") + std::function JSLineFunction; + + // Use no arguments. + REACT_FUNCTION(JSNoArgFunction) + std::function JSNoArgFunction; + + // By default we use the module name from REACT_MODULE which is by default the struct name. + // Here we specify module name local for this function. + REACT_FUNCTION(JSStringFunction, L"stringFunc", L"MyModule") + std::function JSStringFunction; + + // Use React::JSValue which is an immutable JSON-like data representation. + REACT_FUNCTION(JSValueFunction) + std::function JSValueFunction; + + public: // Used to report some test messages + bool IsInitialized{false}; + std::string Message; + static std::string StaticMessage; +}; + +/*static*/ std::string MyTurboModule::StaticMessage; + +// The TurboModule spec is going to be generated from the Flow spec file. +// It verifies that: +// - module methods names are unique; +// - method names are matching to the module spec method names; +// - method signatures match the spec method signatures. +struct MyTurboModuleSpec : winrt::Microsoft::ReactNative::TurboModuleSpec { + static constexpr auto methods = std::tuple{ + Method) noexcept>{0, L"Add"}, + Method) noexcept>{1, L"Negate"}, + Method) noexcept>{2, L"SayHello"}, + Method) noexcept>{3, L"StaticAdd"}, + Method) noexcept>{4, L"StaticNegate"}, + Method) noexcept>{5, L"StaticSayHello"}, + Method{6, L"SayHello0"}, + Method{7, L"PrintPoint"}, + Method{8, L"PrintLine"}, + Method{9, L"StaticSayHello0"}, + Method{10, L"StaticPrintPoint"}, + Method{11, L"StaticPrintLine"}, + Method) noexcept>{12, L"AddCallback"}, + Method) noexcept>{13, L"NegateCallback"}, + Method) noexcept>{14, L"NegateAsyncCallback"}, + Method) noexcept>{15, L"NegateDispatchQueueCallback"}, + Method) noexcept>{16, L"NegateFutureCallback"}, + Method) noexcept>{17, L"SayHelloCallback"}, + Method) noexcept>{18, L"StaticAddCallback"}, + Method) noexcept>{19, L"StaticNegateCallback"}, + Method) noexcept>{20, L"StaticNegateAsyncCallback"}, + Method) noexcept>{21, L"StaticNegateDispatchQueueCallback"}, + Method) noexcept>{22, L"StaticNegateFutureCallback"}, + Method) noexcept>{23, L"StaticSayHelloCallback"}, + Method, Callback) noexcept>{24, L"DivideCallbacks"}, + Method, Callback) noexcept>{25, L"NegateCallbacks"}, + Method, Callback) noexcept>{26, L"NegateAsyncCallbacks"}, + Method, Callback) noexcept>{27, L"NegateDispatchQueueCallbacks"}, + Method, Callback) noexcept>{28, L"NegateFutureCallbacks"}, + Method, Callback) noexcept>{29, L"ResolveSayHelloCallbacks"}, + Method, Callback) noexcept>{30, L"RejectSayHelloCallbacks"}, + Method, Callback) noexcept>{31, L"StaticDivideCallbacks"}, + Method, Callback) noexcept>{32, L"StaticNegateCallbacks"}, + Method, Callback) noexcept>{33, L"StaticNegateAsyncCallbacks"}, + Method, Callback) noexcept>{34, L"StaticNegateDispatchQueueCallbacks"}, + Method, Callback) noexcept>{35, L"StaticNegateFutureCallbacks"}, + Method, Callback) noexcept>{36, L"StaticResolveSayHelloCallbacks"}, + Method, Callback) noexcept>{37, L"StaticRejectSayHelloCallbacks"}, + Method) noexcept>{38, L"DividePromise"}, + Method) noexcept>{39, L"NegatePromise"}, + Method) noexcept>{40, L"NegateAsyncPromise"}, + Method) noexcept>{41, L"NegateDispatchQueuePromise"}, + Method) noexcept>{42, L"NegateFuturePromise"}, + Method) noexcept>{43, L"voidPromise"}, + Method) noexcept>{44, L"ResolveSayHelloPromise"}, + Method) noexcept>{45, L"RejectSayHelloPromise"}, + Method) noexcept>{46, L"StaticDividePromise"}, + Method) noexcept>{47, L"StaticNegatePromise"}, + Method) noexcept>{48, L"StaticNegateAsyncPromise"}, + Method) noexcept>{49, L"StaticNegateDispatchQueuePromise"}, + Method) noexcept>{50, L"StaticNegateFuturePromise"}, + Method) noexcept>{51, L"staticVoidPromise"}, + Method) noexcept>{52, L"StaticResolveSayHelloPromise"}, + Method) noexcept>{53, L"StaticRejectSayHelloPromise"}, + SyncMethod{54, L"AddSync"}, + SyncMethod{55, L"NegateSync"}, + SyncMethod{56, L"SayHelloSync"}, + SyncMethod{57, L"StaticAddSync"}, + SyncMethod{58, L"StaticNegateSync"}, + SyncMethod{59, L"StaticSayHelloSync"}, + }; + + template + static constexpr void ValidateModule() noexcept { + constexpr auto methodCheckResults = CheckMethods(); + + REACT_SHOW_METHOD_SPEC_ERRORS( + 0, + "Add", + " REACT_METHOD(Add) int Add(int, int) noexcept {/*implementation*/}\n" + " REACT_METHOD(Add) void Add(int, int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(Add) winrt::fire_and_forget Add(int, int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(Add) static int Add(int, int) noexcept {/*implementation*/}\n" + " REACT_METHOD(Add) static void Add(int, int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(Add) static React::Coroutine Add(int, int, ReactCallback) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 1, + "Negate", + " REACT_METHOD(Negate) int Negate(int) noexcept {/*implementation*/}\n" + " REACT_METHOD(Negate) void Negate(int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(Negate) winrt::fire_and_forget Negate(int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(Negate) static int Negate(int) noexcept {/*implementation*/}\n" + " REACT_METHOD(Negate) static void Negate(int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(Negate) static winrt::fire_and_forget Negate(int, ReactCallback) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 2, + "SayHello", + " REACT_METHOD(SayHello) std::string SayHello() noexcept {/*implementation*/}\n" + " REACT_METHOD(SayHello) void SayHello(ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(SayHello) winrt::fire_and_forget SayHello(ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(SayHello) static std::string SayHello() noexcept {/*implementation*/}\n" + " REACT_METHOD(SayHello) static void SayHello(ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(SayHello) static winrt::fire_and_forget SayHello(ReactCallback) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 3, + "StaticAdd", + " REACT_METHOD(StaticAdd) int StaticAdd(int, int) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticAdd) void StaticAdd(int, int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticAdd) winrt::fire_and_forget StaticAdd(int, int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticAdd) static int StaticAdd(int, int) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticAdd) static void StaticAdd(int, int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticAdd) static winrt::fire_and_forget StaticAdd(int, int, ReactCallback) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 4, + "StaticNegate", + " REACT_METHOD(StaticNegate) int StaticNegate(int) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegate) void StaticNegate(int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegate) winrt::fire_and_forget StaticNegate(int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegate) static int StaticNegate(int) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegate) static void StaticNegate(int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegate) static winrt::fire_and_forget StaticNegate(int, ReactCallback) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 5, + "StaticSayHello", + " REACT_METHOD(StaticSayHello) std::string StaticSayHello() noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticSayHello) void StaticSayHello(ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticSayHello) winrt::fire_and_forget StaticSayHello(ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticSayHello) static std::string StaticSayHello() noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticSayHello) static void StaticSayHello(ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticSayHello) static winrt::fire_and_forget StaticSayHello(ReactCallback) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 6, + "SayHello0", + " REACT_METHOD(SayHello0) void SayHello0() noexcept {/*implementation*/}\n" + " REACT_METHOD(SayHello0) winrt::fire_and_forget SayHello0() noexcept {/*implementation*/}\n" + " REACT_METHOD(SayHello0) static void SayHello0() noexcept {/*implementation*/}\n" + " REACT_METHOD(SayHello0) static winrt::fire_and_forget SayHello0() noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 7, + "PrintPoint", + " REACT_METHOD(PrintPoint) void PrintPoint(Point) noexcept {/*implementation*/}\n" + " REACT_METHOD(PrintPoint) winrt::fire_and_forget PrintPoint(Point) noexcept {/*implementation*/}\n" + " REACT_METHOD(PrintPoint) static void PrintPoint(Point) noexcept {/*implementation*/}\n" + " REACT_METHOD(PrintPoint) static winrt::fire_and_forget PrintPoint(Point) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 8, + "PrintLine", + " REACT_METHOD(PrintPoint) void PrintLine(Point, Point) noexcept {/*implementation*/}\n" + " REACT_METHOD(PrintPoint) winrt::fire_and_forget PrintLine(Point, Point) noexcept {/*implementation*/}\n" + " REACT_METHOD(PrintPoint) static void PrintLine(Point, Point) noexcept {/*implementation*/}\n" + " REACT_METHOD(PrintPoint) static winrt::fire_and_forget PrintLine(Point, Point) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 9, + "StaticSayHello0", + " REACT_METHOD(StaticSayHello0) void StaticSayHello0() noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticSayHello0) winrt::fire_and_forget StaticSayHello0() noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticSayHello0) static void StaticSayHello0() noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticSayHello0) static winrt::fire_and_forget StaticSayHello0() noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 10, + "StaticPrintPoint", + " REACT_METHOD(StaticPrintPoint) void StaticPrintPoint(Point) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticPrintPoint) winrt::fire_and_forget StaticPrintPoint(Point) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticPrintPoint) static void StaticPrintPoint(Point) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticPrintPoint) static winrt::fire_and_forget StaticPrintPoint(Point) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 11, + "StaticPrintLine", + " REACT_METHOD(StaticPrintPoint) void StaticPrintLine(Point, Point) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticPrintPoint) winrt::fire_and_forget StaticPrintLine(Point, Point) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticPrintPoint) static void StaticPrintLine(Point, Point) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticPrintPoint) static winrt::fire_and_forget StaticPrintLine(Point, Point) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 12, + "AddCallback", + " REACT_METHOD(AddCallback) int AddCallback(int, int) noexcept {/*implementation*/}\n" + " REACT_METHOD(AddCallback) void AddCallback(int, int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(AddCallback) winrt::fire_and_forget AddCallback(int, int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(AddCallback) static int AddCallback(int, int) noexcept {/*implementation*/}\n" + " REACT_METHOD(AddCallback) static void AddCallback(int, int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(AddCallback) static winrt::fire_and_forget AddCallback(int, int, ReactCallback) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 13, + "NegateCallback", + " REACT_METHOD(NegateCallback) int NegateCallback(int) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateCallback) void NegateCallback(int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateCallback) winrt::fire_and_forget NegateCallback(int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateCallback) static int NegateCallback(int) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateCallback) static void NegateCallback(int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateCallback) static winrt::fire_and_forget NegateCallback(int, ReactCallback) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 14, + "NegateAsyncCallback", + " REACT_METHOD(NegateAsyncCallback) int NegateAsyncCallback(int) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateAsyncCallback) void NegateAsyncCallback(int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateAsyncCallback) winrt::fire_and_forget NegateAsyncCallback(int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateAsyncCallback) static int NegateAsyncCallback(int) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateAsyncCallback) static void NegateAsyncCallback(int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateAsyncCallback) static winrt::fire_and_forget NegateAsyncCallback(int, ReactCallback) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 15, + "NegateDispatchQueueCallback", + " REACT_METHOD(NegateDispatchQueueCallback) int NegateDispatchQueueCallback(int) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateDispatchQueueCallback) void NegateDispatchQueueCallback(int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateDispatchQueueCallback) winrt::fire_and_forget NegateDispatchQueueCallback(int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateDispatchQueueCallback) static int NegateDispatchQueueCallback(int) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateDispatchQueueCallback) static void NegateDispatchQueueCallback(int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateDispatchQueueCallback) static winrt::fire_and_forget NegateDispatchQueueCallback(int, ReactCallback) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 16, + "NegateFutureCallback", + " REACT_METHOD(NegateFutureCallback) int NegateFutureCallback(int) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateFutureCallback) void NegateFutureCallback(int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateFutureCallback) winrt::fire_and_forget NegateFutureCallback(int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateFutureCallback) static int NegateFutureCallback(int) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateFutureCallback) static void NegateFutureCallback(int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateFutureCallback) static winrt::fire_and_forget NegateFutureCallback(int, ReactCallback) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 17, + "SayHelloCallback", + " REACT_METHOD(SayHelloCallback) std::string SayHelloCallback() noexcept {/*implementation*/}\n" + " REACT_METHOD(SayHelloCallback) void SayHelloCallback(ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(SayHelloCallback) winrt::fire_and_forget SayHelloCallback(ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(SayHelloCallback) static std::string SayHelloCallback() noexcept {/*implementation*/}\n" + " REACT_METHOD(SayHelloCallback) static void SayHelloCallback(ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(SayHelloCallback) static winrt::fire_and_forget SayHelloCallback(ReactCallback) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 18, + "StaticAddCallback", + " REACT_METHOD(StaticAddCallback) int StaticAddCallback(int, int) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticAddCallback) void StaticAddCallback(int, int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticAddCallback) winrt::fire_and_forget StaticAddCallback(int, int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticAddCallback) static int StaticAddCallback(int, int) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticAddCallback) static void StaticAddCallback(int, int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticAddCallback) static winrt::fire_and_forget StaticAddCallback(int, int, ReactCallback) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 19, + "StaticNegateCallback", + " REACT_METHOD(StaticNegateCallback) int StaticNegateCallback(int) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateCallback) void StaticNegateCallback(int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateCallback) winrt::fire_and_forget StaticNegateCallback(int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateCallback) static int StaticNegateCallback(int) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateCallback) static void StaticNegateCallback(int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateCallback) static winrt::fire_and_forget StaticNegateCallback(int, ReactCallback) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 20, + "StaticNegateAsyncCallback", + " REACT_METHOD(StaticNegateAsyncCallback) int StaticNegateAsyncCallback(int) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateAsyncCallback) void StaticNegateAsyncCallback(int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateAsyncCallback) winrt::fire_and_forget StaticNegateAsyncCallback(int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateAsyncCallback) static int StaticNegateAsyncCallback(int) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateAsyncCallback) static void StaticNegateAsyncCallback(int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateAsyncCallback) static winrt::fire_and_forget StaticNegateAsyncCallback(int, ReactCallback) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 21, + "StaticNegateDispatchQueueCallback", + " REACT_METHOD(StaticNegateDispatchQueueCallback) int StaticNegateDispatchQueueCallback(int) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateDispatchQueueCallback) void StaticNegateDispatchQueueCallback(int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateDispatchQueueCallback) winrt::fire_and_forget StaticNegateDispatchQueueCallback(int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateDispatchQueueCallback) static int StaticNegateDispatchQueueCallback(int) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateDispatchQueueCallback) static void StaticNegateDispatchQueueCallback(int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateDispatchQueueCallback) static winrt::fire_and_forget StaticNegateDispatchQueueCallback(int, ReactCallback) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 22, + "StaticNegateFutureCallback", + " REACT_METHOD(StaticNegateFutureCallback) int StaticNegateFutureCallback(int) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateFutureCallback) void StaticNegateFutureCallback(int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateFutureCallback) winrt::fire_and_forget StaticNegateFutureCallback(int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateFutureCallback) static int StaticNegateFutureCallback(int) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateFutureCallback) static void StaticNegateFutureCallback(int, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateFutureCallback) static winrt::fire_and_forget StaticNegateFutureCallback(int, ReactCallback) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 23, + "StaticSayHelloCallback", + " REACT_METHOD(StaticSayHelloCallback) std::string StaticSayHelloCallback() noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticSayHelloCallback) void StaticSayHelloCallback(ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticSayHelloCallback) winrt::fire_and_forget StaticSayHelloCallback(ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticSayHelloCallback) static std::string StaticSayHelloCallback() noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticSayHelloCallback) static void StaticSayHelloCallback(ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticSayHelloCallback) static winrt::fire_and_forget StaticSayHelloCallback(ReactCallback) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 24, + "DivideCallbacks", + " REACT_METHOD(DivideCallbacks) void DivideCallbacks(int, int, ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(DivideCallbacks) winrt::fire_and_forget DivideCallbacks(int, int, ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(DivideCallbacks) static void DivideCallbacks(int, int, ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(DivideCallbacks) static winrt::fire_and_forget DivideCallbacks(int, int, ReactCallback, ReactCallback) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 25, + "NegateCallbacks", + " REACT_METHOD(NegateCallbacks) void NegateCallbacks(int, ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateCallbacks) winrt::fire_and_forget NegateCallbacks(int, ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateCallbacks) static void NegateCallbacks(int, ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateCallbacks) static winrt::fire_and_forget NegateCallbacks(int, ReactCallback, ReactCallback) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 26, + "NegateAsyncCallbacks", + " REACT_METHOD(NegateAsyncCallbacks) void NegateAsyncCallbacks(int, ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateAsyncCallbacks) winrt::fire_and_forget NegateAsyncCallbacks(int, ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateAsyncCallbacks) static void NegateAsyncCallbacks(int, ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateAsyncCallbacks) static winrt::fire_and_forget NegateAsyncCallbacks(int, ReactCallback, ReactCallback) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 27, + "NegateDispatchQueueCallbacks", + " REACT_METHOD(NegateDispatchQueueCallbacks) void NegateDispatchQueueCallbacks(int, ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateDispatchQueueCallbacks) winrt::fire_and_forget NegateDispatchQueueCallbacks(int, ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateDispatchQueueCallbacks) static void NegateDispatchQueueCallbacks(int, ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateDispatchQueueCallbacks) static winrt::fire_and_forget NegateDispatchQueueCallbacks(int, ReactCallback, ReactCallback) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 28, + "NegateFutureCallbacks", + " REACT_METHOD(NegateFutureCallbacks) void NegateFutureCallbacks(int, ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateFutureCallbacks) winrt::fire_and_forget NegateFutureCallbacks(int, ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateFutureCallbacks) static void NegateFutureCallbacks(int, ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateFutureCallbacks) static winrt::fire_and_forget NegateFutureCallbacks(int, ReactCallback, ReactCallback) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 29, + "ResolveSayHelloCallbacks", + " REACT_METHOD(ResolveSayHelloCallbacks) void ResolveSayHelloCallbacks(ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(ResolveSayHelloCallbacks) winrt::fire_and_forget ResolveSayHelloCallbacks(ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(ResolveSayHelloCallbacks) static void ResolveSayHelloCallbacks(ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(ResolveSayHelloCallbacks) static winrt::fire_and_forget ResolveSayHelloCallbacks(ReactCallback, ReactCallback) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 30, + "RejectSayHelloCallbacks", + " REACT_METHOD(RejectSayHelloCallbacks) void RejectSayHelloCallbacks(ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(RejectSayHelloCallbacks) winrt::fire_and_forget RejectSayHelloCallbacks(ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(RejectSayHelloCallbacks) static void RejectSayHelloCallbacks(ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(RejectSayHelloCallbacks) static winrt::fire_and_forget RejectSayHelloCallbacks(ReactCallback, ReactCallback) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 31, + "StaticDivideCallbacks", + " REACT_METHOD(StaticDivideCallbacks) void StaticDivideCallbacks(int, int, ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticDivideCallbacks) winrt::fire_and_forget StaticDivideCallbacks(int, int, ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticDivideCallbacks) static void StaticDivideCallbacks(int, int, ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticDivideCallbacks) static winrt::fire_and_forget StaticDivideCallbacks(int, int, ReactCallback, ReactCallback) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 32, + "StaticNegateCallbacks", + " REACT_METHOD(StaticNegateCallbacks) void StaticNegateCallbacks(int, ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateCallbacks) winrt::fire_and_forget StaticNegateCallbacks(int, ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateCallbacks) static void StaticNegateCallbacks(int, ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateCallbacks) static winrt::fire_and_forget StaticNegateCallbacks(int, ReactCallback, ReactCallback) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 33, + "StaticNegateAsyncCallbacks", + " REACT_METHOD(StaticNegateAsyncCallbacks) void StaticNegateAsyncCallbacks(int, ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateAsyncCallbacks) winrt::fire_and_forget StaticNegateAsyncCallbacks(int, ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateAsyncCallbacks) static void StaticNegateAsyncCallbacks(int, ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateAsyncCallbacks) static winrt::fire_and_forget StaticNegateAsyncCallbacks(int, ReactCallback, ReactCallback) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 34, + "StaticNegateDispatchQueueCallbacks", + " REACT_METHOD(StaticNegateDispatchQueueCallbacks) void StaticNegateDispatchQueueCallbacks(int, ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateDispatchQueueCallbacks) winrt::fire_and_forget StaticNegateDispatchQueueCallbacks(int, ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateDispatchQueueCallbacks) static void StaticNegateDispatchQueueCallbacks(int, ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateDispatchQueueCallbacks) static winrt::fire_and_forget StaticNegateDispatchQueueCallbacks(int, ReactCallback, ReactCallback) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 35, + "StaticNegateFutureCallbacks", + " REACT_METHOD(StaticNegateFutureCallbacks) void StaticNegateFutureCallbacks(int, ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateFutureCallbacks) winrt::fire_and_forget StaticNegateFutureCallbacks(int, ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateFutureCallbacks) static void StaticNegateFutureCallbacks(int, ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateFutureCallbacks) static winrt::fire_and_forget StaticNegateFutureCallbacks(int, ReactCallback, ReactCallback) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 36, + "StaticResolveSayHelloCallbacks", + " REACT_METHOD(StaticResolveSayHelloCallbacks) void StaticResolveSayHelloCallbacks(ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticResolveSayHelloCallbacks) winrt::fire_and_forget StaticResolveSayHelloCallbacks(ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticResolveSayHelloCallbacks) static void StaticResolveSayHelloCallbacks(ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticResolveSayHelloCallbacks) static winrt::fire_and_forget StaticResolveSayHelloCallbacks(ReactCallback, ReactCallback) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 37, + "StaticRejectSayHelloCallbacks", + " REACT_METHOD(StaticRejectSayHelloCallbacks) void StaticRejectSayHelloCallbacks(ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticRejectSayHelloCallbacks) winrt::fire_and_forget StaticRejectSayHelloCallbacks(ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticRejectSayHelloCallbacks) static void StaticRejectSayHelloCallbacks(ReactCallback, ReactCallback) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticRejectSayHelloCallbacks) static winrt::fire_and_forget StaticRejectSayHelloCallbacks(ReactCallback, ReactCallback) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 38, + "DividePromise", + " REACT_METHOD(DividePromise) void DividePromise(int, int, ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(DividePromise) winrt::fire_and_forget DividePromise(int, int, ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(DividePromise) static void DividePromise(int, int, ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(DividePromise) static winrt::fire_and_forget DividePromise(int, int, ReactPromise) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 39, + "NegatePromise", + " REACT_METHOD(NegatePromise) void NegatePromise(int, ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegatePromise) winrt::fire_and_forget NegatePromise(int, ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegatePromise) static void NegatePromise(int, ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegatePromise) static winrt::fire_and_forget NegatePromise(int, ReactPromise) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 40, + "NegateAsyncPromise", + " REACT_METHOD(NegateAsyncPromise) void NegateAsyncPromise(int, ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateAsyncPromise) winrt::fire_and_forget NegateAsyncPromise(int, ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateAsyncPromise) static void NegateAsyncPromise(int, ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateAsyncPromise) static winrt::fire_and_forget NegateAsyncPromise(int, ReactPromise) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 41, + "NegateDispatchQueuePromise", + " REACT_METHOD(NegateDispatchQueuePromise) void NegateDispatchQueuePromise(int, ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateDispatchQueuePromise) winrt::fire_and_forget NegateDispatchQueuePromise(int, ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateDispatchQueuePromise) static void NegateDispatchQueuePromise(int, ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateDispatchQueuePromise) static winrt::fire_and_forget NegateDispatchQueuePromise(int, ReactPromise) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 42, + "NegateFuturePromise", + " REACT_METHOD(NegateFuturePromise) void NegateFuturePromise(int, ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateFuturePromise) winrt::fire_and_forget NegateFuturePromise(int, ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateFuturePromise) static void NegateFuturePromise(int, ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateFuturePromise) static winrt::fire_and_forget NegateFuturePromise(int, ReactPromise) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 43, + "voidPromise", + " REACT_METHOD(voidPromise) void voidPromise(int, ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(voidPromise) winrt::fire_and_forget voidPromise(int, ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(voidPromise) static void voidPromise(int, ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(voidPromise) static winrt::fire_and_forget voidPromise(int, ReactPromise) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 44, + "ResolveSayHelloPromise", + " REACT_METHOD(ResolveSayHelloPromise) void ResolveSayHelloPromise(ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(ResolveSayHelloPromise) winrt::fire_and_forget ResolveSayHelloPromise(ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(ResolveSayHelloPromise) static void ResolveSayHelloPromise(ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(ResolveSayHelloPromise) static winrt::fire_and_forget ResolveSayHelloPromise(ReactPromise) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 45, + "RejectSayHelloPromise", + " REACT_METHOD(RejectSayHelloPromise) void RejectSayHelloPromise(ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(RejectSayHelloPromise) winrt::fire_and_forget RejectSayHelloPromise(ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(RejectSayHelloPromise) static void RejectSayHelloPromise(ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(RejectSayHelloPromise) static winrt::fire_and_forget RejectSayHelloPromise(ReactPromise) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 46, + "StaticDividePromise", + " REACT_METHOD(StaticDividePromise) void StaticDividePromise(int, int, ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticDividePromise) winrt::fire_and_forget StaticDividePromise(int, int, ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticDividePromise) static void StaticDividePromise(int, int, ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticDividePromise) static winrt::fire_and_forget StaticDividePromise(int, int, ReactPromise) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 47, + "StaticNegatePromise", + " REACT_METHOD(StaticNegatePromise) void StaticNegatePromise(int, ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegatePromise) winrt::fire_and_forget StaticNegatePromise(int, ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegatePromise) static void StaticNegatePromise(int, ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegatePromise) static winrt::fire_and_forget StaticNegatePromise(int, ReactPromise) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 48, + "StaticNegateAsyncPromise", + " REACT_METHOD(StaticNegateAsyncPromise) void StaticNegateAsyncPromise(int, ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateAsyncPromise) winrt::fire_and_forget StaticNegateAsyncPromise(int, ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateAsyncPromise) static void StaticNegateAsyncPromise(int, ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateAsyncPromise) static winrt::fire_and_forget StaticNegateAsyncPromise(int, ReactPromise) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 49, + "StaticNegateDispatchQueuePromise", + " REACT_METHOD(StaticNegateDispatchQueuePromise) void StaticNegateDispatchQueuePromise(int, ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateDispatchQueuePromise) winrt::fire_and_forget StaticNegateDispatchQueuePromise(int, ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateDispatchQueuePromise) static void StaticNegateDispatchQueuePromise(int, ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateDispatchQueuePromise) static winrt::fire_and_forget StaticNegateDispatchQueuePromise(int, ReactPromise) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 50, + "StaticNegateFuturePromise", + " REACT_METHOD(StaticNegateFuturePromise) void StaticNegateFuturePromise(int, ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateFuturePromise) winrt::fire_and_forget StaticNegateFuturePromise(int, ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateFuturePromise) static void StaticNegateFuturePromise(int, ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateFuturePromise) static winrt::fire_and_forget StaticNegateFuturePromise(int, ReactPromise) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 51, + "staticVoidPromise", + " REACT_METHOD(staticVoidPromise) void staticVoidPromise(int, ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(staticVoidPromise) winrt::fire_and_forget staticVoidPromise(int, ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(staticVoidPromise) static void staticVoidPromise(int, ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(staticVoidPromise) static winrt::fire_and_forget staticVoidPromise(int, ReactPromise) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 52, + "StaticResolveSayHelloPromise", + " REACT_METHOD(StaticResolveSayHelloPromise) void StaticResolveSayHelloPromise(ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticResolveSayHelloPromise) winrt::fire_and_forget StaticResolveSayHelloPromise(ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticResolveSayHelloPromise) static void StaticResolveSayHelloPromise(ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticResolveSayHelloPromise) static winrt::fire_and_forget StaticResolveSayHelloPromise(ReactPromise) noexcept {/*implementation*/}\n"); + REACT_SHOW_METHOD_SPEC_ERRORS( + 53, + "StaticRejectSayHelloPromise", + " REACT_METHOD(StaticRejectSayHelloPromise) void StaticRejectSayHelloPromise(ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticRejectSayHelloPromise) winrt::fire_and_forget StaticRejectSayHelloPromise(ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticRejectSayHelloPromise) static void StaticRejectSayHelloPromise(ReactPromise) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticRejectSayHelloPromise) static winrt::fire_and_forget StaticRejectSayHelloPromise(ReactPromise) noexcept {/*implementation*/}\n"); + REACT_SHOW_SYNC_METHOD_SPEC_ERRORS( + 54, + "AddSync", + " REACT_METHOD(AddSync) int AddSync(int, int) noexcept {/*implementation*/}\n" + " REACT_METHOD(AddSync) static int AddSync(int, int) noexcept {/*implementation*/}\n"); + REACT_SHOW_SYNC_METHOD_SPEC_ERRORS( + 55, + "NegateSync", + " REACT_METHOD(NegateSync) int NegateSync(int) noexcept {/*implementation*/}\n" + " REACT_METHOD(NegateSync) static int NegateSync(int) noexcept {/*implementation*/}\n"); + REACT_SHOW_SYNC_METHOD_SPEC_ERRORS( + 56, + "SayHelloSync", + " REACT_METHOD(SayHelloSync) std::string SayHelloSync() noexcept {/*implementation*/}\n" + " REACT_METHOD(SayHelloSync) static std::string SayHelloSync() noexcept {/*implementation*/}\n"); + REACT_SHOW_SYNC_METHOD_SPEC_ERRORS( + 57, + "StaticAddSync", + " REACT_METHOD(StaticAddSync) int StaticAddSync(int, int) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticAddSync) static int StaticAddSync(int, int) noexcept {/*implementation*/}\n"); + REACT_SHOW_SYNC_METHOD_SPEC_ERRORS( + 58, + "StaticNegateSync", + " REACT_METHOD(StaticNegateSync) int StaticNegateSync(int) noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticNegateSync) static int StaticNegateSync(int) noexcept {/*implementation*/}\n"); + REACT_SHOW_SYNC_METHOD_SPEC_ERRORS( + 59, + "StaticSayHelloSync", + " REACT_METHOD(StaticSayHelloSync) std::string StaticSayHelloSync() noexcept {/*implementation*/}\n" + " REACT_METHOD(StaticSayHelloSync) static std::string StaticSayHelloSync() noexcept {/*implementation*/}\n"); + } +}; + +TEST_CLASS (TurboModuleTest) { + winrt::Microsoft::ReactNative::ReactModuleBuilderMock m_builderMock{}; + winrt::Microsoft::ReactNative::IReactModuleBuilder m_moduleBuilder; + Windows::Foundation::IInspectable m_moduleObject{nullptr}; + MyTurboModule *m_module; + + TurboModuleTest() { + m_moduleBuilder = winrt::make(m_builderMock); + auto provider = winrt::Microsoft::ReactNative::MakeTurboModuleProvider(); + m_moduleObject = m_builderMock.CreateModule(provider, m_moduleBuilder); + auto reactModule = m_moduleObject.as(); + m_module = &winrt::Microsoft::ReactNative::BoxedValue::GetImpl(reactModule); + } + + TEST_METHOD(TestMethodCall_Add) { + m_builderMock.Call1(L"Add", std::function([](int result) noexcept { TestCheckEqual(8, result); }), 3, 5); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_Negate) { + m_builderMock.Call1(L"Negate", std::function([](int result) noexcept { TestCheck(result == -3); }), 3); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_SayHello) { + m_builderMock.Call1(L"SayHello", std::function([](const std::string &result) noexcept { + TestCheck(result == "Hello"); + })); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_StaticAdd) { + m_builderMock.Call1( + L"StaticAdd", std::function([](int result) noexcept { TestCheck(result == 25); }), 20, 5); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_StaticNegate) { + m_builderMock.Call1( + L"StaticNegate", std::function([](int result) noexcept { TestCheck(result == -7); }), 7); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_StaticSayHello) { + m_builderMock.Call1(L"StaticSayHello", std::function([ + ](const std::string &result) noexcept { TestCheck(result == "Hello"); })); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_SayHello0) { + m_builderMock.Call0(L"SayHello0"); + TestCheck(m_module->Message == "Hello_0"); + } + + TEST_METHOD(TestMethodCall_PrintPoint) { + m_builderMock.Call0(L"PrintPoint", Point{/*X =*/3, /*Y =*/5}); + TestCheck(m_module->Message == "Point: (3, 5)"); + } + + TEST_METHOD(TestMethodCall_PrintLine) { + m_builderMock.Call0(L"PrintLine", Point{/*X =*/3, /*Y =*/5}, Point{/*X =*/6, /*Y =*/8}); + TestCheck(m_module->Message == "Line: (3, 5)-(6, 8)"); + } + + TEST_METHOD(TestMethodCall_StaticSayHello0) { + m_builderMock.Call0(L"StaticSayHello0"); + TestCheck(MyTurboModule::StaticMessage == "Hello_0"); + } + + TEST_METHOD(TestMethodCall_StaticPrintPoint) { + m_builderMock.Call0(L"StaticPrintPoint", Point{/*X =*/13, /*Y =*/15}); + TestCheck(MyTurboModule::StaticMessage == "Static Point: (13, 15)"); + } + + TEST_METHOD(TestMethodCall_StaticPrintLine) { + m_builderMock.Call0(L"StaticPrintLine", Point{/*X =*/13, /*Y =*/15}, Point{/*X =*/16, /*Y =*/18}); + TestCheck(MyTurboModule::StaticMessage == "Static Line: (13, 15)-(16, 18)"); + } + + TEST_METHOD(TestMethodCall_AddCallback) { + m_builderMock.Call1( + L"AddCallback", std::function([](int result) noexcept { TestCheck(result == -1); }), 7, -8); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_NegateCallback) { + m_builderMock.Call1( + L"NegateCallback", std::function([](int result) noexcept { TestCheck(result == -4); }), 4); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_NegateAsyncCallback) { + Mso::FutureWait(m_builderMock.Call1( + L"NegateAsyncCallback", std::function([](int result) noexcept { TestCheck(result == -4); }), 4)); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_NegateDispatchQueueCallback) { + Mso::FutureWait(m_builderMock.Call1( + L"NegateDispatchQueueCallback", + std::function([](int result) noexcept { TestCheck(result == -4); }), + 4)); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_NegateFutureCallback) { + Mso::FutureWait(m_builderMock.Call1( + L"NegateFutureCallback", std::function([](int result) noexcept { TestCheck(result == -4); }), 4)); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_SayHelloCallback) { + m_builderMock.Call1(L"SayHelloCallback", std::function([ + ](const std::string &result) noexcept { TestCheck(result == "Hello_2"); })); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_StaticAddCallback) { + m_builderMock.Call1( + L"StaticAddCallback", std::function([](int result) noexcept { TestCheck(result == 60); }), 4, 56); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_StaticNegateCallback) { + m_builderMock.Call1( + L"StaticNegateCallback", std::function([](int result) noexcept { TestCheck(result == -33); }), 33); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_StaticNegateAsyncCallback) { + Mso::FutureWait(m_builderMock.Call1( + L"StaticNegateAsyncCallback", + std::function([](int result) noexcept { TestCheck(result == -4); }), + 4)); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_StaticNegateDispatchQueueCallback) { + Mso::FutureWait(m_builderMock.Call1( + L"StaticNegateDispatchQueueCallback", + std::function([](int result) noexcept { TestCheck(result == -4); }), + 4)); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_StaticNegateFutureCallback) { + Mso::FutureWait(m_builderMock.Call1( + L"StaticNegateFutureCallback", + std::function([](int result) noexcept { TestCheck(result == -4); }), + 4)); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_StaticSayHelloCallback) { + m_builderMock.Call1(L"StaticSayHelloCallback", std::function([ + ](const std::string &result) noexcept { TestCheck(result == "Static Hello_2"); })); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_DivideCallbacks) { + m_builderMock.Call2( + L"DivideCallbacks", + std::function([](int result) noexcept { TestCheck(result == 3); }), + std::function( + [](std::string const &error) noexcept { TestCheck(error == "Division by 0"); }), + 6, + 2); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_DivideCallbacksError) { + m_builderMock.Call2( + L"DivideCallbacks", + std::function([](int result) noexcept { TestCheck(result == 3); }), + std::function( + [](std::string const &error) noexcept { TestCheck(error == "Division by 0"); }), + 6, + 0); + TestCheck(m_builderMock.IsRejectCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_NegateCallbacks) { + m_builderMock.Call2( + L"NegateCallbacks", + std::function([](int result) noexcept { TestCheck(result == -5); }), + std::function( + [](std::string const &error) noexcept { TestCheck(error == "Already negative"); }), + 5); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_NegateCallbacksError) { + m_builderMock.Call2( + L"NegateCallbacks", + std::function([](int result) noexcept { TestCheck(result == -5); }), + std::function( + [](std::string const &error) noexcept { TestCheck(error == "Already negative"); }), + -5); + TestCheck(m_builderMock.IsRejectCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_NegateAsyncCallbacks) { + Mso::FutureWait(m_builderMock.Call2( + L"NegateAsyncCallbacks", + std::function([](int result) noexcept { TestCheck(result == -5); }), + std::function( + [](std::string const &error) noexcept { TestCheck(error == "Already negative"); }), + 5)); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_NegateAsyncCallbacksError) { + Mso::FutureWait(m_builderMock.Call2( + L"NegateAsyncCallbacks", + std::function([](int result) noexcept { TestCheck(result == -5); }), + std::function( + [](std::string const &error) noexcept { TestCheck(error == "Already negative"); }), + -5)); + TestCheck(m_builderMock.IsRejectCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_NegateDispatchQueueCallbacks) { + Mso::FutureWait(m_builderMock.Call2( + L"NegateDispatchQueueCallbacks", + std::function([](int result) noexcept { TestCheck(result == -5); }), + std::function( + [](std::string const &error) noexcept { TestCheck(error == "Already negative"); }), + 5)); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_NegateDispatchQueueCallbacksError) { + Mso::FutureWait(m_builderMock.Call2( + L"NegateDispatchQueueCallbacks", + std::function([](int result) noexcept { TestCheck(result == -5); }), + std::function( + [](std::string const &error) noexcept { TestCheck(error == "Already negative"); }), + -5)); + TestCheck(m_builderMock.IsRejectCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_NegateFutureCallbacks) { + Mso::FutureWait(m_builderMock.Call2( + L"NegateFutureCallbacks", + std::function([](int result) noexcept { TestCheck(result == -5); }), + std::function( + [](std::string const &error) noexcept { TestCheck(error == "Already negative"); }), + 5)); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_NegateFutureCallbacksError) { + Mso::FutureWait(m_builderMock.Call2( + L"NegateFutureCallbacks", + std::function([](int result) noexcept { TestCheck(result == -5); }), + std::function( + [](std::string const &error) noexcept { TestCheck(error == "Already negative"); }), + -5)); + TestCheck(m_builderMock.IsRejectCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_ResolveSayHelloCallbacks) { + m_builderMock.Call2( + L"ResolveSayHelloCallbacks", + std::function( + [](const std::string &result) noexcept { TestCheck(result == "Hello_3"); }), + std::function( + [](std::string const &error) noexcept { TestCheck(error == "Goodbye"); })); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_RejectSayHelloCallbacks) { + m_builderMock.Call2( + L"RejectSayHelloCallbacks", + std::function( + [](const std::string &result) noexcept { TestCheck(result == "Hello_3"); }), + std::function( + [](std::string const &error) noexcept { TestCheck(error == "Goodbye"); })); + TestCheck(m_builderMock.IsRejectCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_StaticDivideCallbacks) { + m_builderMock.Call2( + L"StaticDivideCallbacks", + std::function([](int result) noexcept { TestCheck(result == 3); }), + std::function( + [](std::string const &error) noexcept { TestCheck(error == "Division by 0"); }), + 6, + 2); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_StaticDivideCallbacksError) { + m_builderMock.Call2( + L"StaticDivideCallbacks", + std::function([](int result) noexcept { TestCheck(result == 3); }), + std::function( + [](std::string const &error) noexcept { TestCheck(error == "Division by 0"); }), + 6, + 0); + TestCheck(m_builderMock.IsRejectCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_StaticNegateCallbacks) { + m_builderMock.Call2( + L"StaticNegateCallbacks", + std::function([](int result) noexcept { TestCheck(result == -5); }), + std::function( + [](std::string const &error) noexcept { TestCheck(error == "Already negative"); }), + 5); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_StaticNegateCallbacksError) { + m_builderMock.Call2( + L"StaticNegateCallbacks", + std::function([](int result) noexcept { TestCheck(result == -5); }), + std::function( + [](std::string const &error) noexcept { TestCheck(error == "Already negative"); }), + -5); + TestCheck(m_builderMock.IsRejectCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_StaticNegateAsyncCallbacks) { + Mso::FutureWait(m_builderMock.Call2( + L"StaticNegateAsyncCallbacks", + std::function([](int result) noexcept { TestCheck(result == -5); }), + std::function( + [](std::string const &error) noexcept { TestCheck(error == "Already negative"); }), + 5)); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_StaticNegateAsyncCallbacksError) { + Mso::FutureWait(m_builderMock.Call2( + L"StaticNegateAsyncCallbacks", + std::function([](int result) noexcept { TestCheck(result == -5); }), + std::function( + [](std::string const &error) noexcept { TestCheck(error == "Already negative"); }), + -5)); + TestCheck(m_builderMock.IsRejectCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_StaticNegateDispatchQueueCallbacks) { + Mso::FutureWait(m_builderMock.Call2( + L"StaticNegateDispatchQueueCallbacks", + std::function([](int result) noexcept { TestCheck(result == -5); }), + std::function( + [](std::string const &error) noexcept { TestCheck(error == "Already negative"); }), + 5)); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_StaticNegateDispatchQueueCallbacksError) { + Mso::FutureWait(m_builderMock.Call2( + L"StaticNegateDispatchQueueCallbacks", + std::function([](int result) noexcept { TestCheck(result == -5); }), + std::function( + [](std::string const &error) noexcept { TestCheck(error == "Already negative"); }), + -5)); + TestCheck(m_builderMock.IsRejectCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_StaticNegateFutureCallbacks) { + Mso::FutureWait(m_builderMock.Call2( + L"StaticNegateFutureCallbacks", + std::function([](int result) noexcept { TestCheck(result == -5); }), + std::function( + [](std::string const &error) noexcept { TestCheck(error == "Already negative"); }), + 5)); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_StaticNegateFutureCallbacksError) { + Mso::FutureWait(m_builderMock.Call2( + L"StaticNegateFutureCallbacks", + std::function([](int result) noexcept { TestCheck(result == -5); }), + std::function( + [](std::string const &error) noexcept { TestCheck(error == "Already negative"); }), + -5)); + TestCheck(m_builderMock.IsRejectCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_StaticResolveSayHelloCallbacks) { + m_builderMock.Call2( + L"StaticResolveSayHelloCallbacks", + std::function( + [](const std::string &result) noexcept { TestCheck(result == "Hello_3"); }), + std::function( + [](std::string const &error) noexcept { TestCheck(error == "Goodbye"); })); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_StaticRejectSayHelloCallbacks) { + m_builderMock.Call2( + L"StaticRejectSayHelloCallbacks", + std::function( + [](const std::string &result) noexcept { TestCheck(result == "Hello_3"); }), + std::function( + [](std::string const &error) noexcept { TestCheck(error == "Goodbye"); })); + TestCheck(m_builderMock.IsRejectCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_DividePromise) { + m_builderMock.Call2( + L"DividePromise", + std::function([](int result) noexcept { TestCheck(result == 3); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Division by 0"); }), + 6, + 2); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_DividePromiseError) { + m_builderMock.Call2( + L"DividePromise", + std::function([](int result) noexcept { TestCheck(result == 3); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Division by 0"); }), + 6, + 0); + TestCheck(m_builderMock.IsRejectCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_NegatePromise) { + m_builderMock.Call2( + L"NegatePromise", + std::function([](int result) noexcept { TestCheck(result == -5); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), + 5); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_NegatePromiseError) { + m_builderMock.Call2( + L"NegatePromise", + std::function([](int result) noexcept { TestCheck(result == -5); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), + -5); + TestCheck(m_builderMock.IsRejectCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_NegateAsyncPromise) { + Mso::FutureWait(m_builderMock.Call2( + L"NegateAsyncPromise", + std::function([](int result) noexcept { TestCheck(result == -5); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), + 5)); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_NegateAsyncPromiseError) { + Mso::FutureWait(m_builderMock.Call2( + L"NegateAsyncPromise", + std::function([](int result) noexcept { TestCheck(result == -5); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), + -5)); + TestCheck(m_builderMock.IsRejectCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_NegateDispatchQueuePromise) { + Mso::FutureWait(m_builderMock.Call2( + L"NegateDispatchQueuePromise", + std::function([](int result) noexcept { TestCheck(result == -5); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), + 5)); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_NegateDispatchQueuePromiseError) { + Mso::FutureWait(m_builderMock.Call2( + L"NegateDispatchQueuePromise", + std::function([](int result) noexcept { TestCheck(result == -5); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), + -5)); + TestCheck(m_builderMock.IsRejectCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_NegateFuturePromise) { + Mso::FutureWait(m_builderMock.Call2( + L"NegateFuturePromise", + std::function([](int result) noexcept { TestCheck(result == -5); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), + 5)); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_NegateFuturePromiseError) { + Mso::FutureWait(m_builderMock.Call2( + L"NegateFuturePromise", + std::function([](int result) noexcept { TestCheck(result == -5); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), + -5)); + TestCheck(m_builderMock.IsRejectCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_VoidPromise) { + m_builderMock.Call2( + L"voidPromise", + std::function([]() noexcept {}), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Odd unexpected"); }), + 2); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_VoidError) { + m_builderMock.Call2( + L"voidPromise", + std::function([]() noexcept {}), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Odd unexpected"); }), + 3); + TestCheck(m_builderMock.IsRejectCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_ResolveSayHelloPromise) { + m_builderMock.Call2( + L"ResolveSayHelloPromise", + std::function( + [](const std::string &result) noexcept { TestCheck(result == "Hello_4"); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Promise rejected"); })); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_RejectSayHelloPromise) { + m_builderMock.Call2( + L"RejectSayHelloPromise", + std::function( + [](const std::string &result) noexcept { TestCheck(result == "Hello_4"); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Promise rejected"); })); + TestCheck(m_builderMock.IsRejectCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_StaticDividePromise) { + m_builderMock.Call2( + L"StaticDividePromise", + std::function([](int result) noexcept { TestCheck(result == 3); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Division by 0"); }), + 6, + 2); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_StaticDividePromiseError) { + m_builderMock.Call2( + L"StaticDividePromise", + std::function([](int result) noexcept { TestCheck(result == 3); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Division by 0"); }), + 6, + 0); + TestCheck(m_builderMock.IsRejectCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_StaticNegatePromise) { + m_builderMock.Call2( + L"StaticNegatePromise", + std::function([](int result) noexcept { TestCheck(result == -5); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), + 5); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_StaticNegatePromiseError) { + Mso::FutureWait(m_builderMock.Call2( + L"StaticNegateAsyncPromise", + std::function([](int result) noexcept { TestCheck(result == -5); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), + -5)); + TestCheck(m_builderMock.IsRejectCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_StaticNegateAsyncPromise) { + Mso::FutureWait(m_builderMock.Call2( + L"StaticNegateAsyncPromise", + std::function([](int result) noexcept { TestCheck(result == -5); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), + 5)); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_StaticNegateAsyncPromiseError) { + m_builderMock.Call2( + L"StaticNegatePromise", + std::function([](int result) noexcept { TestCheck(result == -5); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), + -5); + TestCheck(m_builderMock.IsRejectCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_StaticNegateDispatchQueuePromise) { + Mso::FutureWait(m_builderMock.Call2( + L"StaticNegateDispatchQueuePromise", + std::function([](int result) noexcept { TestCheck(result == -5); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), + 5)); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_StaticNegateDispatchQueuePromiseError) { + Mso::FutureWait(m_builderMock.Call2( + L"StaticNegateDispatchQueuePromise", + std::function([](int result) noexcept { TestCheck(result == -5); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), + -5)); + TestCheck(m_builderMock.IsRejectCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_StaticNegateFuturePromise) { + Mso::FutureWait(m_builderMock.Call2( + L"StaticNegateFuturePromise", + std::function([](int result) noexcept { TestCheck(result == -5); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), + 5)); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_StaticNegateFuturePromiseError) { + Mso::FutureWait(m_builderMock.Call2( + L"StaticNegateFuturePromise", + std::function([](int result) noexcept { TestCheck(result == -5); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Already negative"); }), + -5)); + TestCheck(m_builderMock.IsRejectCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_StaticVoidPromise) { + m_builderMock.Call2( + L"staticVoidPromise", + std::function([]() noexcept {}), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Odd unexpected"); }), + 2); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_StaticVoidPromiseError) { + m_builderMock.Call2( + L"staticVoidPromise", + std::function([]() noexcept {}), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Odd unexpected"); }), + 3); + TestCheck(m_builderMock.IsRejectCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_StaticResolveSayHelloPromise) { + m_builderMock.Call2( + L"StaticResolveSayHelloPromise", + std::function( + [](const std::string &result) noexcept { TestCheck(result == "Hello_4"); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Promise rejected"); })); + TestCheck(m_builderMock.IsResolveCallbackCalled()); + } + + TEST_METHOD(TestMethodCall_StaticRejectSayHelloPromise) { + m_builderMock.Call2( + L"StaticRejectSayHelloPromise", + std::function( + [](const std::string &result) noexcept { TestCheck(result == "Hello_4"); }), + std::function( + [](React::JSValue const &error) noexcept { TestCheck(error["message"] == "Promise rejected"); })); + TestCheck(m_builderMock.IsRejectCallbackCalled()); + } + + TEST_METHOD(TestMethodSyncCall_AddSync) { + int result; + m_builderMock.CallSync(L"AddSync", /*out*/ result, 3, 5); + TestCheck(result == 8); + } + + TEST_METHOD(TestMethodSyncCall_NegateSync) { + int result; + m_builderMock.CallSync(L"NegateSync", /*out*/ result, 7); + TestCheck(result == -7); + } + + TEST_METHOD(TestMethodSyncCall_SayHelloSync) { + std::string result; + m_builderMock.CallSync(L"SayHelloSync", /*out*/ result); + TestCheck(result == "Hello"); + } + + TEST_METHOD(TestMethodSyncCall_StaticAddSync) { + int result; + m_builderMock.CallSync(L"StaticAddSync", /*out*/ result, 3, 5); + TestCheck(result == 8); + } + + TEST_METHOD(TestMethodSyncCall_StaticNegateSync) { + int result; + m_builderMock.CallSync(L"StaticNegateSync", /*out*/ result, 7); + TestCheck(result == -7); + } + + TEST_METHOD(TestMethodSyncCall_StaticSayHelloSync) { + std::string result; + m_builderMock.CallSync(L"StaticSayHelloSync", /*out*/ result); + TestCheck(result == "Hello"); + } + + TEST_METHOD(TestConstants) { + auto constants = m_builderMock.GetConstants(); + TestCheck(constants["Constant1"] == "MyConstant1"); + TestCheck(constants["const2"] == "MyConstant2"); + TestCheck(constants["const3"]["X"] == 2); + TestCheck(constants["const3"]["Y"] == 3); + TestCheck(constants["Constant4"]["X"] == 3); + TestCheck(constants["Constant4"]["Y"] == 4); + TestCheck(constants["const51"]["X"] == 12); + TestCheck(constants["const51"]["Y"] == 14); + TestCheck(constants["const52"] == "MyConstant52"); + TestCheck(constants["const61"]["X"] == 15); + TestCheck(constants["const61"]["Y"] == 17); + TestCheck(constants["const62"] == "MyConstant62"); + } + + TEST_METHOD(TestEvent_IntEventField) { + bool eventRaised = false; + m_builderMock.ExpectEvent( + L"RCTDeviceEventEmitter", L"OnIntEvent", [&eventRaised](React::JSValueArray const &args) noexcept { + TestCheck(args[0] == 42); + eventRaised = true; + }); + + m_module->OnIntEvent(42); + TestCheck(eventRaised); + } + + TEST_METHOD(TestEvent_OnNoArgEventField) { + bool eventRaised = false; + m_builderMock.ExpectEvent( + L"RCTDeviceEventEmitter", L"OnNoArgEvent", [&eventRaised](React::JSValueArray const &args) noexcept { + TestCheckEqual(0, args.size()); + eventRaised = true; + }); + + m_module->OnNoArgEvent(); + TestCheck(eventRaised); + } + + TEST_METHOD(TestEvent_TwoArgsEventField) { + bool eventRaised = false; + m_builderMock.ExpectEvent( + L"RCTDeviceEventEmitter", L"OnTwoArgsEvent", [&eventRaised](React::JSValueArray const &args) noexcept { + TestCheckEqual(4, args[0]["X"]); + TestCheckEqual(2, args[0]["Y"]); + TestCheckEqual(12, args[1]["X"]); + TestCheckEqual(18, args[1]["Y"]); + eventRaised = true; + }); + + m_module->OnTwoArgsEvent(Point{/*X =*/4, /*Y =*/2}, Point{/*X =*/12, /*Y =*/18}); + TestCheck(eventRaised); + } + + TEST_METHOD(TestEvent_JSNameEventField) { + bool eventRaised = false; + m_builderMock.ExpectEvent( + L"RCTDeviceEventEmitter", L"onPointEvent", [&eventRaised](React::JSValueArray const &args) noexcept { + TestCheck(args[0]["X"] == 4); + TestCheck(args[0]["Y"] == 2); + eventRaised = true; + }); + + m_module->OnPointEvent(Point{/*X =*/4, /*Y =*/2}); + TestCheck(eventRaised == true); + } + + TEST_METHOD(TestEvent_JSEventEmitterEventField) { + bool eventRaised = false; + m_builderMock.ExpectEvent( + L"MyEventEmitter", L"onStringEvent", [&eventRaised](React::JSValueArray const &args) noexcept { + TestCheckEqual("Hello World!", args[0]); + eventRaised = true; + }); + + m_module->OnStringEvent("Hello World!"); + TestCheck(eventRaised == true); + } + + TEST_METHOD(TestEvent_JSValueObjectEventField) { + bool eventRaised = false; + m_builderMock.ExpectEvent( + L"RCTDeviceEventEmitter", L"OnJSValueEvent", ([&eventRaised](React::JSValueArray const &args) noexcept { + TestCheck(args[0]["X"] == 4); + TestCheck(args[0]["Y"] == 2); + eventRaised = true; + })); + + m_module->OnJSValueEvent(React::JSValueObject{{"X", 4}, {"Y", 2}}); + TestCheck(eventRaised == true); + } + + TEST_METHOD(TestEvent_JSValueArrayEventField) { + bool eventRaised = false; + m_builderMock.ExpectEvent( + L"RCTDeviceEventEmitter", L"OnJSValueEvent", ([&eventRaised](React::JSValueArray const &args) noexcept { + TestCheck(args[0][0] == "X"); + TestCheck(args[0][1] == 4); + TestCheck(args[0][2] == true); + TestCheck(args[0][3]["Id"] == 42); + eventRaised = true; + })); + + m_module->OnJSValueEvent(React::JSValueArray{"X", 4, true, React::JSValueObject{{"Id", 42}}}); + TestCheck(eventRaised == true); + } + + TEST_METHOD(TestEvent_JSValueArray1EventField) { + bool eventRaised = false; + m_builderMock.ExpectEvent( + L"RCTDeviceEventEmitter", L"OnJSValueEvent", ([&eventRaised](React::JSValueArray const &args) noexcept { + TestCheck(args[0][0] == 4); + eventRaised = true; + })); + + m_module->OnJSValueEvent(React::JSValueArray{4}); + TestCheck(eventRaised == true); + } + + TEST_METHOD(TestFunction_JSIntFunctionField) { + bool functionCalled = false; + m_builderMock.ExpectFunction( + L"MyTurboModule", L"JSIntFunction", [&functionCalled](React::JSValueArray const &args) noexcept { + TestCheck(args[0] == 42); + functionCalled = true; + }); + + m_module->JSIntFunction(42); + TestCheck(functionCalled); + } + + TEST_METHOD(TestFunction_JSNameFunctionField) { + bool functionCalled = false; + m_builderMock.ExpectFunction( + L"MyTurboModule", L"pointFunc", [&functionCalled](React::JSValueArray const &args) noexcept { + TestCheck(args[0]["X"] == 4); + TestCheck(args[0]["Y"] == 2); + functionCalled = true; + }); + + m_module->JSPointFunction(Point{/*X =*/4, /*Y =*/2}); + TestCheck(functionCalled == true); + } + + TEST_METHOD(TestFunction_TwoArgFunctionField) { + bool functionCalled = false; + m_builderMock.ExpectFunction( + L"MyTurboModule", L"lineFunc", [&functionCalled](React::JSValueArray const &args) noexcept { + TestCheck(args[0]["X"] == 4); + TestCheck(args[0]["Y"] == 2); + TestCheck(args[1]["X"] == 12); + TestCheck(args[1]["Y"] == 18); + functionCalled = true; + }); + + m_module->JSLineFunction(Point{/*X =*/4, /*Y =*/2}, Point{/*X =*/12, /*Y =*/18}); + TestCheck(functionCalled == true); + } + + TEST_METHOD(TestFunction_NoArgFunctionField) { + bool functionCalled = false; + m_builderMock.ExpectFunction( + L"MyTurboModule", L"JSNoArgFunction", [&functionCalled](React::JSValueArray const &args) noexcept { + TestCheckEqual(0, args.size()); + functionCalled = true; + }); + + m_module->JSNoArgFunction(); + TestCheck(functionCalled); + } + + TEST_METHOD(TestFunction_JSModuleNameFunctionField) { + bool functionCalled = false; + m_builderMock.ExpectFunction( + L"MyModule", L"stringFunc", [&functionCalled](React::JSValueArray const &args) noexcept { + TestCheck(args[0] == "Hello World!"); + functionCalled = true; + }); + + m_module->JSStringFunction("Hello World!"); + TestCheck(functionCalled == true); + } + + TEST_METHOD(TestFunction_JSValueObjectFunctionField) { + bool functionCalled = false; + m_builderMock.ExpectFunction( + L"MyTurboModule", L"JSValueFunction", ([&functionCalled](React::JSValueArray const &args) noexcept { + TestCheck(args[0]["X"] == 4); + TestCheck(args[0]["Y"] == 2); + functionCalled = true; + })); + + m_module->JSValueFunction(React::JSValueObject{{"X", 4}, {"Y", 2}}); + TestCheck(functionCalled == true); + } + + TEST_METHOD(TestFunction_JSValueArrayFunctionField) { + bool functionCalled = false; + m_builderMock.ExpectFunction( + L"MyTurboModule", L"JSValueFunction", ([&functionCalled](React::JSValueArray const &args) noexcept { + TestCheck(args[0][0] == "X"); + TestCheck(args[0][1] == 4); + TestCheck(args[0][2] == true); + TestCheck(args[0][3]["Id"] == 42); + functionCalled = true; + })); + + m_module->JSValueFunction(React::JSValueArray{"X", 4, true, React::JSValueObject{{"Id", 42}}}); + TestCheck(functionCalled == true); + } + + TEST_METHOD(TestInitialized) { + TestCheck(m_module->IsInitialized); + } +}; + +} // namespace ReactNativeTests diff --git a/vnext/Microsoft.ReactNative.Cxx/ModuleRegistration.h b/vnext/Microsoft.ReactNative.Cxx/ModuleRegistration.h index 03916ce88e4..9f8979006d0 100644 --- a/vnext/Microsoft.ReactNative.Cxx/ModuleRegistration.h +++ b/vnext/Microsoft.ReactNative.Cxx/ModuleRegistration.h @@ -34,13 +34,13 @@ template struct moduleStruct##_ModuleRegistration; \ \ template \ - constexpr void RegisterModule(TRegistry ®istry) noexcept { \ + constexpr void GetReactModuleInfo(moduleStruct *, TRegistry ®istry) noexcept { \ registry.RegisterModule( \ - moduleName, eventEmitterName, winrt::Microsoft::ReactNative::ReactMemberId<__COUNTER__>{}); \ + moduleName, eventEmitterName, winrt::Microsoft::ReactNative::ReactAttributeId<__COUNTER__>{}); \ } #define INTERNAL_REACT_MODULE_2_ARGS(moduleStruct, moduleName) \ - INTERNAL_REACT_MODULE_3_ARGS(moduleStruct, moduleName, nullptr) + INTERNAL_REACT_MODULE_3_ARGS(moduleStruct, moduleName, L"") #define INTERNAL_REACT_MODULE_1_ARG(moduleStruct) INTERNAL_REACT_MODULE_2_ARGS(moduleStruct, L## #moduleStruct) @@ -48,21 +48,24 @@ INTERNAL_REACT_RECOMPOSER_4( \ (__VA_ARGS__, INTERNAL_REACT_MODULE_3_ARGS, INTERNAL_REACT_MODULE_2_ARGS, INTERNAL_REACT_MODULE_1_ARG, )) -// Register struct member. -// For each registered member we create a static method that registers it. +// Provide meta data information about struct member. +// For each member with a 'custom attribute' macro we create a static method to provide meta data. // The member Id is generated as a ReactMemberId<__COUNTER__> type. -// To invoke the static registration methods, we increment ReactMemberId while static member exists. -#define INTERNAL_REACT_MEMBER_4_ARGS(memberType, member, memberName, moduleName) \ - template \ - constexpr static void RegisterMember( \ - TRegistry ®istry, winrt::Microsoft::ReactNative::ReactMemberId<__COUNTER__>) noexcept { \ - registry.Register##memberType(&TClass::member, memberName, moduleName); \ +// To enumerate the static methods, we can increment ReactMemberId while static member exists. +#define INTERNAL_REACT_MEMBER_4_ARGS(memberKind, member, jsMemberName, jsModuleName) \ + template \ + constexpr static void GetReactMemberAttribute( \ + TVisitor &visitor, winrt::Microsoft::ReactNative::ReactAttributeId<__COUNTER__> attributeId) noexcept { \ + visitor.Visit( \ + &TStruct::member, \ + attributeId, \ + winrt::Microsoft::ReactNative::React##memberKind##Attribute{jsMemberName, jsModuleName}); \ } -#define INTERNAL_REACT_MEMBER_3_ARGS(memberType, member, memberName) \ - INTERNAL_REACT_MEMBER_4_ARGS(memberType, member, memberName, nullptr) +#define INTERNAL_REACT_MEMBER_3_ARGS(memberKind, member, jsMemberName) \ + INTERNAL_REACT_MEMBER_4_ARGS(memberKind, member, jsMemberName, L"") -#define INTERNAL_REACT_MEMBER_2_ARGS(memberType, member) INTERNAL_REACT_MEMBER_3_ARGS(memberType, member, L## #member) +#define INTERNAL_REACT_MEMBER_2_ARGS(memberKind, member) INTERNAL_REACT_MEMBER_3_ARGS(memberKind, member, L## #member) #define INTERNAL_REACT_MEMBER(...) \ INTERNAL_REACT_RECOMPOSER_4( \ diff --git a/vnext/Microsoft.ReactNative.Cxx/NativeModules.h b/vnext/Microsoft.ReactNative.Cxx/NativeModules.h index 305709f3aa6..a7070651b62 100644 --- a/vnext/Microsoft.ReactNative.Cxx/NativeModules.h +++ b/vnext/Microsoft.ReactNative.Cxx/NativeModules.h @@ -9,6 +9,7 @@ #include "ModuleRegistration.h" #include "ReactPromise.h" +#include #include // REACT_MODULE(moduleStruct, [opt] moduleName, [opt] eventEmitterName) @@ -47,7 +48,7 @@ // - Return non-void value. In JavaScript it is treated as a method with one Callback. Return std::pair to // be able to communicate error condition. // It can be an instance or static method. -#define REACT_METHOD(/* method, [opt] methodName */...) INTERNAL_REACT_MEMBER(__VA_ARGS__)(Method, __VA_ARGS__) +#define REACT_METHOD(/* method, [opt] methodName */...) INTERNAL_REACT_MEMBER(__VA_ARGS__)(AsyncMethod, __VA_ARGS__) // REACT_SYNC_METHOD(method, [opt] methodName) // Arguments: @@ -105,39 +106,165 @@ #define REACT_FUNCTION(/* field, [opt] functionName, [opt] moduleName */...) \ INTERNAL_REACT_MEMBER(__VA_ARGS__)(FunctionField, __VA_ARGS__) +#define REACT_SHOW_METHOD_SIGNATURES(methodName, signatures) \ + " (see details below in output).\n" \ + " It must be one of the following:\n" signatures \ + " The C++ method name could be different. In that case add the L\"" methodName \ + "\" to the attribute:\n" \ + " REACT_METHOD(method, L\"" methodName "\")\n...\n" + +#define REACT_SHOW_SYNC_METHOD_SIGNATURES(methodName, signatures) \ + " (see details below in output).\n" \ + " It must be one of the following:\n" signatures \ + " The C++ method name could be different. In that case add the L\"" methodName \ + "\" to the attribute:\n" \ + " REACT_SYNC_METHOD(method, L\"" methodName "\")\n...\n" + +#define REACT_SHOW_METHOD_SPEC_ERRORS(index, methodName, signatures) \ + static_assert(methodCheckResults[index].IsUniqueName, "Name '" methodName "' used for multiple methods"); \ + static_assert( \ + methodCheckResults[index].IsMethodFound, \ + "Method '" methodName "' is not defined" REACT_SHOW_METHOD_SIGNATURES(methodName, signatures)); \ + static_assert( \ + methodCheckResults[index].IsSignatureMatching, \ + "Method '" methodName "' does not match signature" REACT_SHOW_METHOD_SIGNATURES(methodName, signatures)); + +#define REACT_SHOW_SYNC_METHOD_SPEC_ERRORS(index, methodName, signatures) \ + static_assert(methodCheckResults[index].IsUniqueName, "Name '" methodName "' used for multiple methods"); \ + static_assert( \ + methodCheckResults[index].IsMethodFound, \ + "Method '" methodName "' is not defined" REACT_SHOW_SYNC_METHOD_SIGNATURES(methodName, signatures)); \ + static_assert( \ + methodCheckResults[index].IsSignatureMatching, \ + "Method '" methodName "' does not match signature" REACT_SHOW_SYNC_METHOD_SIGNATURES(methodName, signatures)); + +// +// Code below helps to register React native modules and verify method signatures +// against specification. +// + namespace winrt::Microsoft::ReactNative { -namespace Internal { +// Often used to create a tuple with arguments or to create a method signature. +template +using RemoveConstRef = std::remove_const_t>; -// Checks if provided type has a callback-like signature TFunc struct IsCallback : std::false_type {}; -template