Put desktop unit tests into namespaces. (#3098)

* Put desktop unit tests into namespaces.

* Change files

* Small fix for position of "clang-format on"
This commit is contained in:
Yichen Yao 2019-09-09 12:18:20 -07:00 коммит произвёл Andrew Coates
Родитель 8c74f769ea
Коммит 6b6d0bbbc0
17 изменённых файлов: 515 добавлений и 409 удалений

Просмотреть файл

@ -0,0 +1,8 @@
{
"type": "prerelease",
"comment": "Put desktop unit tests into namespaces.",
"packageName": "react-native-windows",
"email": "yicyao@microsoft.com",
"commit": "376450bff685ade93b719d1ba5cd0d8d290eefb2",
"date": "2019-09-06T23:42:33.841Z"
}

Просмотреть файл

@ -13,82 +13,87 @@ using namespace winrt::facebook::react;
namespace ABITests { namespace ABITests {
TEST_CLASS(MemoryTrackerTests){ // We turn clang format off here because it does not work with some of the
// test macros.
// clang-format off
TEST_METHOD(Handler_AddedAndRemoved){ TEST_CLASS(MemoryTrackerTests) {
init_apartment(winrt::apartment_type::single_threaded);
IMessageQueue callbackMessageQueue = ::winrt::make<MessageQueueShim>();
MemoryTracker tracker{callbackMessageQueue};
uint32_t registrationToken = tracker.AddThresholdHandler( TEST_METHOD(Handler_AddedAndRemoved){
/* threshold */ 100, init_apartment(winrt::apartment_type::single_threaded);
/* minCallbackIntervalInMilliseconds */ 100, IMessageQueue callbackMessageQueue = ::winrt::make<MessageQueueShim>();
[](uint64_t currentUsage) {}); MemoryTracker tracker{callbackMessageQueue};
Assert::IsTrue(tracker.RemoveThresholdHandler(registrationToken));
} // namespace ABITests
TEST_METHOD(CurrentMemoryUsage_ReturnsInitialValue) { uint32_t registrationToken = tracker.AddThresholdHandler(
init_apartment(winrt::apartment_type::single_threaded); /* threshold */ 100,
IMessageQueue callbackMessageQueue = ::winrt::make<MessageQueueShim>(); /* minCallbackIntervalInMilliseconds */ 100,
MemoryTracker tracker{callbackMessageQueue}; [](uint64_t currentUsage) {});
Assert::IsTrue(tracker.RemoveThresholdHandler(registrationToken));
}
tracker.Initialize(1000); TEST_METHOD(CurrentMemoryUsage_ReturnsInitialValue) {
Assert::AreEqual( init_apartment(winrt::apartment_type::single_threaded);
1000ull, tracker.CurrentMemoryUsage(), L"CurrentMemoryUsage"); IMessageQueue callbackMessageQueue = ::winrt::make<MessageQueueShim>();
} MemoryTracker tracker{callbackMessageQueue};
TEST_METHOD(PeakMemoryUsage_ReturnsInitialValue) { tracker.Initialize(1000);
init_apartment(winrt::apartment_type::single_threaded); Assert::AreEqual(
IMessageQueue callbackMessageQueue = ::winrt::make<MessageQueueShim>(); 1000ull, tracker.CurrentMemoryUsage(), L"CurrentMemoryUsage");
MemoryTracker tracker{callbackMessageQueue}; }
tracker.Initialize(1000); TEST_METHOD(PeakMemoryUsage_ReturnsInitialValue) {
Assert::AreEqual(1000ull, tracker.PeakMemoryUsage(), L"PeakMemoryUsage"); init_apartment(winrt::apartment_type::single_threaded);
} IMessageQueue callbackMessageQueue = ::winrt::make<MessageQueueShim>();
MemoryTracker tracker{callbackMessageQueue};
TEST_METHOD(ThresholdHandler_Called) { tracker.Initialize(1000);
init_apartment(winrt::apartment_type::single_threaded); Assert::AreEqual(1000ull, tracker.PeakMemoryUsage(), L"PeakMemoryUsage");
}
DWORD testThreadId = GetCurrentThreadId(); TEST_METHOD(ThresholdHandler_Called) {
init_apartment(winrt::apartment_type::single_threaded);
auto manualMessageQueue = std::make_shared<ControllableMessageQueueThread>( DWORD testThreadId = GetCurrentThreadId();
ControllableMessageQueueThread::Mode::ManualDispatch);
IMessageQueue callbackMessageQueue = auto manualMessageQueue = std::make_shared<ControllableMessageQueueThread>(
::winrt::make<MessageQueueShim>(manualMessageQueue); ControllableMessageQueueThread::Mode::ManualDispatch);
MemoryTracker tracker{callbackMessageQueue};
tracker.Initialize(500); IMessageQueue callbackMessageQueue =
::winrt::make<MessageQueueShim>(manualMessageQueue);
MemoryTracker tracker{callbackMessageQueue};
std::vector<uint64_t> actualCallbacks; tracker.Initialize(500);
DWORD callbackThreadId;
uint32_t registrationToken = tracker.AddThresholdHandler(
/* threshold */ 1000,
/* minCallbackIntervalInMilliseconds */ 100,
[&actualCallbacks, &callbackThreadId](uint64_t currentUsage) {
actualCallbacks.push_back(currentUsage);
callbackThreadId = GetCurrentThreadId();
});
tracker.OnAllocation(1000); std::vector<uint64_t> actualCallbacks;
DWORD callbackThreadId;
uint32_t registrationToken = tracker.AddThresholdHandler(
/* threshold */ 1000,
/* minCallbackIntervalInMilliseconds */ 100,
[&actualCallbacks, &callbackThreadId](uint64_t currentUsage) {
actualCallbacks.push_back(currentUsage);
callbackThreadId = GetCurrentThreadId();
});
// allow the callback to get dispatched tracker.OnAllocation(1000);
Assert::IsTrue(
manualMessageQueue->DispatchOne(std::chrono::milliseconds(500)));
Assert::IsTrue(manualMessageQueue->IsEmpty());
Assert::AreEqual( // allow the callback to get dispatched
1500ull, tracker.CurrentMemoryUsage(), L"CurrentMemoryUsage"); Assert::IsTrue(
Assert::AreEqual(1500ull, tracker.PeakMemoryUsage(), L"PeakMemoryUsage"); manualMessageQueue->DispatchOne(std::chrono::milliseconds(500)));
Assert::IsTrue(manualMessageQueue->IsEmpty());
Assert::AreEqual(static_cast<size_t>(1), actualCallbacks.size()); Assert::AreEqual(
Assert::AreEqual(1500ull, actualCallbacks[0]); 1500ull, tracker.CurrentMemoryUsage(), L"CurrentMemoryUsage");
Assert::AreEqual(1500ull, tracker.PeakMemoryUsage(), L"PeakMemoryUsage");
Assert::AreNotEqual(testThreadId, callbackThreadId); Assert::AreEqual(static_cast<size_t>(1), actualCallbacks.size());
Assert::AreEqual(1500ull, actualCallbacks[0]);
Assert::IsTrue(tracker.RemoveThresholdHandler(registrationToken)); Assert::AreNotEqual(testThreadId, callbackThreadId);
}
} Assert::IsTrue(tracker.RemoveThresholdHandler(registrationToken));
; }
};
// clange-format on
} // namespace ABITests } // namespace ABITests

Просмотреть файл

@ -14,6 +14,8 @@
using namespace facebook::react; using namespace facebook::react;
using namespace Microsoft::VisualStudio::CppUnitTestFramework; using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace {
std::vector<folly::dynamic> returnedValues; std::vector<folly::dynamic> returnedValues;
std::condition_variable_any cv; std::condition_variable_any cv;
std::recursive_mutex m; std::recursive_mutex m;
@ -55,6 +57,10 @@ void throwLastErrorMessage() {
throw std::exception(errorMessageBuffer); throw std::exception(errorMessageBuffer);
} }
} // namespace
namespace Microsoft::React::Test {
TEST_CLASS(AsyncStorageManagerTest) { TEST_CLASS(AsyncStorageManagerTest) {
const WCHAR *m_storageFileName = L"testdomain"; const WCHAR *m_storageFileName = L"testdomain";
@ -266,3 +272,5 @@ TEST_CLASS(AsyncStorageManagerTest) {
lock.unlock(); lock.unlock();
} }
}; };
} // namespace Microsoft::React::Test

Просмотреть файл

@ -8540,6 +8540,8 @@ KVPair NewLinesAndBackSlashes = {
using namespace facebook::react; using namespace facebook::react;
using namespace Microsoft::VisualStudio::CppUnitTestFramework; using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace Microsoft::React::Test {
TEST_CLASS(AsyncStorageTest) { TEST_CLASS(AsyncStorageTest) {
public: public:
const WCHAR *m_storageFileName = L"testdomain"; const WCHAR *m_storageFileName = L"testdomain";
@ -8825,3 +8827,5 @@ TEST_CLASS(AsyncStorageTest) {
kvStorage->clear(); kvStorage->clear();
} }
}; };
} // namespace Microsoft::React::Test

Просмотреть файл

@ -16,99 +16,109 @@ using std::make_unique;
using std::promise; using std::promise;
using std::string; using std::string;
namespace Microsoft::React::Test {
using CloseCode = IWebSocket::CloseCode; using CloseCode = IWebSocket::CloseCode;
using Error = IWebSocket::Error; using Error = IWebSocket::Error;
// We turn clang format off here because it does not work with some of the
// test macros.
// clang-format off
TEST_CLASS(BaseWebSocketTest){ TEST_CLASS(BaseWebSocketTest){
BEGIN_TEST_CLASS_ATTRIBUTE() TEST_CLASS_ATTRIBUTE(L"Ignore", L"true") BEGIN_TEST_CLASS_ATTRIBUTE()
END_TEST_CLASS_ATTRIBUTE() TEST_CLASS_ATTRIBUTE(L"Ignore", L"true")
END_TEST_CLASS_ATTRIBUTE()
TEST_METHOD(CreateAndSetHandlers){ TEST_METHOD(CreateAndSetHandlers){
auto ws = make_unique<TestWebSocket>(Url("ws://localhost")); auto ws = make_unique<TestWebSocket>(Url("ws://localhost"));
Assert::IsFalse(nullptr == ws); Assert::IsFalse(nullptr == ws);
ws->SetOnConnect([]() {}); ws->SetOnConnect([]() {});
ws->SetOnPing([]() {}); ws->SetOnPing([]() {});
ws->SetOnSend([](size_t length) {}); ws->SetOnSend([](size_t length) {});
ws->SetOnMessage([](size_t length, const string &buffer) {}); ws->SetOnMessage([](size_t length, const string &buffer) {});
ws->SetOnClose([](CloseCode, const string &) {}); ws->SetOnClose([](CloseCode, const string &) {});
ws->SetOnError([](const Error &error) {}); ws->SetOnError([](const Error &error) {});
} }
TEST_METHOD(ConnectSucceeds) { TEST_METHOD(ConnectSucceeds) {
string errorMessage; string errorMessage;
bool connected = false; bool connected = false;
auto ws = make_unique<TestWebSocket>(Url("ws://localhost")); auto ws = make_unique<TestWebSocket>(Url("ws://localhost"));
ws->SetOnError([&errorMessage](Error err) { errorMessage = err.Message; }); ws->SetOnError([&errorMessage](Error err) { errorMessage = err.Message; });
ws->SetOnConnect([&connected]() { connected = true; }); ws->SetOnConnect([&connected]() { connected = true; });
ws->Connect({}, {}); ws->Connect({}, {});
ws->Close(CloseCode::Normal, {}); ws->Close(CloseCode::Normal, {});
Assert::AreEqual({}, errorMessage); Assert::AreEqual({}, errorMessage);
Assert::IsTrue(connected); Assert::IsTrue(connected);
} }
TEST_METHOD(ConnectFails) { TEST_METHOD(ConnectFails) {
string errorMessage; string errorMessage;
bool connected = false; bool connected = false;
auto ws = make_unique<TestWebSocket>(Url("ws://localhost")); auto ws = make_unique<TestWebSocket>(Url("ws://localhost"));
ws->SetOnError([&errorMessage](Error err) { errorMessage = err.Message; }); ws->SetOnError([&errorMessage](Error err) { errorMessage = err.Message; });
ws->SetOnConnect([&connected]() { connected = true; }); ws->SetOnConnect([&connected]() { connected = true; });
ws->SetConnectResult([]() -> error_code { ws->SetConnectResult([]() -> error_code {
return make_error_code(errc::state_not_recoverable); return make_error_code(errc::state_not_recoverable);
}); });
ws->Connect({}, {}); ws->Connect({}, {});
ws->Close(CloseCode::Normal, {}); ws->Close(CloseCode::Normal, {});
Assert::AreNotEqual({}, errorMessage); Assert::AreNotEqual({}, errorMessage);
Assert::IsFalse(connected); Assert::IsFalse(connected);
} }
BEGIN_TEST_METHOD_ATTRIBUTE(HandshakeFails) BEGIN_TEST_METHOD_ATTRIBUTE(HandshakeFails)
TEST_IGNORE() TEST_IGNORE()
END_TEST_METHOD_ATTRIBUTE() END_TEST_METHOD_ATTRIBUTE()
TEST_METHOD(HandshakeFails) { TEST_METHOD(HandshakeFails) {
string errorMessage; string errorMessage;
bool connected = false; bool connected = false;
auto ws = make_unique<TestWebSocket>(Url("ws://localhost")); auto ws = make_unique<TestWebSocket>(Url("ws://localhost"));
ws->SetOnError([&errorMessage](Error err) { errorMessage = err.Message; }); ws->SetOnError([&errorMessage](Error err) { errorMessage = err.Message; });
ws->SetOnConnect([&connected]() { connected = true; }); ws->SetOnConnect([&connected]() { connected = true; });
ws->SetHandshakeResult([](string, string) -> error_code { ws->SetHandshakeResult([](string, string) -> error_code {
return make_error_code(errc::state_not_recoverable); return make_error_code(errc::state_not_recoverable);
}); });
ws->Connect({}, {}); ws->Connect({}, {});
ws->Close(CloseCode::Normal, {}); ws->Close(CloseCode::Normal, {});
Assert::AreNotEqual({}, errorMessage); Assert::AreNotEqual({}, errorMessage);
Assert::IsFalse(connected); Assert::IsFalse(connected);
} }
BEGIN_TEST_METHOD_ATTRIBUTE(CloseSucceeds) BEGIN_TEST_METHOD_ATTRIBUTE(CloseSucceeds)
TEST_IGNORE() TEST_IGNORE()
END_TEST_METHOD_ATTRIBUTE() END_TEST_METHOD_ATTRIBUTE()
TEST_METHOD(CloseSucceeds) { TEST_METHOD(CloseSucceeds) {
string errorMessage; string errorMessage;
promise<void> connected; promise<void> connected;
bool closed = false; bool closed = false;
auto ws = make_unique<TestWebSocket>(Url("ws://localhost")); auto ws = make_unique<TestWebSocket>(Url("ws://localhost"));
ws->SetOnError([&errorMessage](Error err) { errorMessage = err.Message; }); ws->SetOnError([&errorMessage](Error err) { errorMessage = err.Message; });
ws->SetOnConnect([&connected]() { connected.set_value(); }); ws->SetOnConnect([&connected]() { connected.set_value(); });
ws->SetOnClose( ws->SetOnClose(
[&closed](CloseCode code, const string &message) { closed = true; }); [&closed](CloseCode code, const string &message) { closed = true; });
ws->SetCloseResult( ws->SetCloseResult(
[]() -> error_code { return make_error_code(errc::success); }); []() -> error_code { return make_error_code(errc::success); });
ws->Connect({}, {}); ws->Connect({}, {});
connected.get_future().wait(); connected.get_future().wait();
ws->Close(CloseCode::Normal, "Normal"); ws->Close(CloseCode::Normal, "Normal");
Assert::AreNotEqual({}, errorMessage); Assert::AreNotEqual({}, errorMessage);
Assert::IsTrue(closed); Assert::IsTrue(closed);
} }
} };
;
// clange-format on
} // namespace Microsoft::React::Test

Просмотреть файл

@ -36,6 +36,8 @@ std::vector<char> ReadFile(const char *filename) {
} // namespace } // namespace
namespace Microsoft::React::Test {
TEST_CLASS(BytecodeUnitTests) { TEST_CLASS(BytecodeUnitTests) {
private: private:
MinimalChakraRuntime m_chakraRuntime; MinimalChakraRuntime m_chakraRuntime;
@ -369,3 +371,5 @@ TEST_CLASS(BytecodeUnitTests) {
}); });
} }
}; };
} // namespace Microsoft::React::Test

Просмотреть файл

@ -6,6 +6,8 @@
using namespace facebook::react; using namespace facebook::react;
using namespace Microsoft::VisualStudio::CppUnitTestFramework; using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace {
constexpr auto c_typeSz = "type"; constexpr auto c_typeSz = "type";
constexpr auto c_propertySz = "property"; constexpr auto c_propertySz = "property";
constexpr auto c_noneSz = "none"; constexpr auto c_noneSz = "none";
@ -32,9 +34,9 @@ constexpr auto c_delaySz = "delay";
constexpr auto c_initialVelocitySz = "initialVelocity"; constexpr auto c_initialVelocitySz = "initialVelocity";
constexpr auto c_springDampingSz = "springDamping"; constexpr auto c_springDampingSz = "springDamping";
namespace Microsoft { } // namespace
namespace VisualStudio {
namespace CppUnitTestFramework { namespace Microsoft::VisualStudio::CppUnitTestFramework {
template <> template <>
std::wstring ToString<enum facebook::react::LayoutAnimation::AnimationType>( std::wstring ToString<enum facebook::react::LayoutAnimation::AnimationType>(
@ -75,11 +77,15 @@ ToString<enum facebook::react::LayoutAnimation::AnimatableProperty>(
return L"None"; return L"None";
} }
} // namespace CppUnitTestFramework } // namespace Microsoft::VisualStudio::CppUnitTestFramework
} // namespace VisualStudio
} // namespace Microsoft
TEST_CLASS(LayoutAnimationTests){ namespace Microsoft::React::Test {
// We turn clang format off here because it does not work with some of the
// test macros.
// clang-format off
TEST_CLASS(LayoutAnimationTests) {
/* /*
Typical layout animation: Typical layout animation:
@ -97,159 +103,162 @@ TEST_CLASS(LayoutAnimationTests){
#pragma region LayoutAnimation Config Processing Tests #pragma region LayoutAnimation Config Processing Tests
TEST_METHOD(LayoutAnimationTests_BasicLayoutAnimationPropertySetTest){ TEST_METHOD(LayoutAnimationTests_BasicLayoutAnimationPropertySetTest){
auto duration = 500.0f; auto duration = 500.0f;
auto delay = 0.0f; auto delay = 0.0f;
folly::dynamic layoutAnimation = folly::dynamic::object(c_durationSz, duration)( folly::dynamic layoutAnimation = folly::dynamic::object(c_durationSz, duration)(
c_createSz, c_createSz,
folly::dynamic::object(c_typeSz, c_linearSz)(c_propertySz, c_scaleXYSz))( folly::dynamic::object(c_typeSz, c_linearSz)(c_propertySz, c_scaleXYSz))(
c_updateSz, c_updateSz,
folly::dynamic::object(c_typeSz, c_easeInSz))( folly::dynamic::object(c_typeSz, c_easeInSz))(
c_deleteSz, c_deleteSz,
folly::dynamic::object(c_typeSz, c_easeOutSz)(c_propertySz, c_opacitySz)); folly::dynamic::object(c_typeSz, c_easeOutSz)(c_propertySz, c_opacitySz));
LayoutAnimation typedLayoutAnimation(layoutAnimation); LayoutAnimation typedLayoutAnimation(layoutAnimation);
auto typedProps = typedLayoutAnimation.Properties(); auto typedProps = typedLayoutAnimation.Properties();
Assert::AreEqual(duration, typedProps.createAnimationProps.duration); Assert::AreEqual(duration, typedProps.createAnimationProps.duration);
Assert::AreEqual(duration, typedProps.updateAnimationProps.duration); Assert::AreEqual(duration, typedProps.updateAnimationProps.duration);
Assert::AreEqual(duration, typedProps.deleteAnimationProps.duration); Assert::AreEqual(duration, typedProps.deleteAnimationProps.duration);
Assert::AreEqual( Assert::AreEqual(
LayoutAnimation::AnimationType::Linear, LayoutAnimation::AnimationType::Linear,
typedProps.createAnimationProps.animationType); typedProps.createAnimationProps.animationType);
Assert::AreEqual( Assert::AreEqual(
LayoutAnimation::AnimationType::EaseIn, LayoutAnimation::AnimationType::EaseIn,
typedProps.updateAnimationProps.animationType); typedProps.updateAnimationProps.animationType);
Assert::AreEqual( Assert::AreEqual(
LayoutAnimation::AnimationType::EaseOut, LayoutAnimation::AnimationType::EaseOut,
typedProps.deleteAnimationProps.animationType); typedProps.deleteAnimationProps.animationType);
Assert::AreEqual( Assert::AreEqual(
LayoutAnimation::AnimatableProperty::ScaleXY, LayoutAnimation::AnimatableProperty::ScaleXY,
typedProps.createAnimationProps.animatedProp); typedProps.createAnimationProps.animatedProp);
Assert::AreEqual( Assert::AreEqual(
LayoutAnimation::AnimatableProperty::None, LayoutAnimation::AnimatableProperty::None,
typedProps.updateAnimationProps.animatedProp); typedProps.updateAnimationProps.animatedProp);
Assert::AreEqual( Assert::AreEqual(
LayoutAnimation::AnimatableProperty::Opacity, LayoutAnimation::AnimatableProperty::Opacity,
typedProps.deleteAnimationProps.animatedProp); typedProps.deleteAnimationProps.animatedProp);
Assert::AreEqual(delay, typedProps.createAnimationProps.delay); Assert::AreEqual(delay, typedProps.createAnimationProps.delay);
Assert::AreEqual(delay, typedProps.updateAnimationProps.delay); Assert::AreEqual(delay, typedProps.updateAnimationProps.delay);
Assert::AreEqual(delay, typedProps.deleteAnimationProps.delay); Assert::AreEqual(delay, typedProps.deleteAnimationProps.delay);
} }
TEST_METHOD(LayoutAnimationTests_OnlyAnimateCreateTest) { TEST_METHOD(LayoutAnimationTests_OnlyAnimateCreateTest) {
folly::dynamic layoutAnimation = folly::dynamic::object(c_durationSz, 500)( folly::dynamic layoutAnimation = folly::dynamic::object(c_durationSz, 500)(
c_createSz, c_createSz,
folly::dynamic::object(c_typeSz, c_linearSz)(c_propertySz, c_scaleXYSz)); folly::dynamic::object(c_typeSz, c_linearSz)(c_propertySz, c_scaleXYSz));
LayoutAnimation typedLayoutAnimation(layoutAnimation); LayoutAnimation typedLayoutAnimation(layoutAnimation);
auto typedProps = typedLayoutAnimation.Properties(); auto typedProps = typedLayoutAnimation.Properties();
Assert::AreEqual( Assert::AreEqual(
LayoutAnimation::AnimationType::Linear, LayoutAnimation::AnimationType::Linear,
typedProps.createAnimationProps.animationType); typedProps.createAnimationProps.animationType);
Assert::AreEqual( Assert::AreEqual(
LayoutAnimation::AnimationType::None, LayoutAnimation::AnimationType::None,
typedProps.updateAnimationProps.animationType); typedProps.updateAnimationProps.animationType);
Assert::AreEqual( Assert::AreEqual(
LayoutAnimation::AnimationType::None, LayoutAnimation::AnimationType::None,
typedProps.deleteAnimationProps.animationType); typedProps.deleteAnimationProps.animationType);
} }
TEST_METHOD(LayoutAnimationTests_OnlyAnimateUpdateTest) { TEST_METHOD(LayoutAnimationTests_OnlyAnimateUpdateTest) {
folly::dynamic layoutAnimation = folly::dynamic::object(c_durationSz, 500)( folly::dynamic layoutAnimation = folly::dynamic::object(c_durationSz, 500)(
c_updateSz, c_updateSz,
folly::dynamic::object(c_typeSz, c_linearSz)(c_propertySz, c_scaleXYSz)); folly::dynamic::object(c_typeSz, c_linearSz)(c_propertySz, c_scaleXYSz));
LayoutAnimation typedLayoutAnimation(layoutAnimation); LayoutAnimation typedLayoutAnimation(layoutAnimation);
auto typedProps = typedLayoutAnimation.Properties(); auto typedProps = typedLayoutAnimation.Properties();
Assert::AreEqual( Assert::AreEqual(
LayoutAnimation::AnimationType::None, LayoutAnimation::AnimationType::None,
typedProps.createAnimationProps.animationType); typedProps.createAnimationProps.animationType);
Assert::AreEqual( Assert::AreEqual(
LayoutAnimation::AnimationType::Linear, LayoutAnimation::AnimationType::Linear,
typedProps.updateAnimationProps.animationType); typedProps.updateAnimationProps.animationType);
Assert::AreEqual( Assert::AreEqual(
LayoutAnimation::AnimationType::None, LayoutAnimation::AnimationType::None,
typedProps.deleteAnimationProps.animationType); typedProps.deleteAnimationProps.animationType);
} }
TEST_METHOD(LayoutAnimationTests_OnlyAnimateDeleteTest) { TEST_METHOD(LayoutAnimationTests_OnlyAnimateDeleteTest) {
folly::dynamic layoutAnimation = folly::dynamic::object(c_durationSz, 500)( folly::dynamic layoutAnimation = folly::dynamic::object(c_durationSz, 500)(
c_deleteSz, c_deleteSz,
folly::dynamic::object(c_typeSz, c_linearSz)(c_propertySz, c_scaleXYSz)); folly::dynamic::object(c_typeSz, c_linearSz)(c_propertySz, c_scaleXYSz));
LayoutAnimation typedLayoutAnimation(layoutAnimation); LayoutAnimation typedLayoutAnimation(layoutAnimation);
auto typedProps = typedLayoutAnimation.Properties(); auto typedProps = typedLayoutAnimation.Properties();
Assert::AreEqual( Assert::AreEqual(
LayoutAnimation::AnimationType::None, LayoutAnimation::AnimationType::None,
typedProps.createAnimationProps.animationType); typedProps.createAnimationProps.animationType);
Assert::AreEqual( Assert::AreEqual(
LayoutAnimation::AnimationType::None, LayoutAnimation::AnimationType::None,
typedProps.updateAnimationProps.animationType); typedProps.updateAnimationProps.animationType);
Assert::AreEqual( Assert::AreEqual(
LayoutAnimation::AnimationType::Linear, LayoutAnimation::AnimationType::Linear,
typedProps.deleteAnimationProps.animationType); typedProps.deleteAnimationProps.animationType);
} }
TEST_METHOD(LayoutAnimationTests_CustomizedDurationTest) { TEST_METHOD(LayoutAnimationTests_CustomizedDurationTest) {
auto defaultDuration = 500.0f; auto defaultDuration = 500.0f;
auto customDuration = 50.0f; auto customDuration = 50.0f;
folly::dynamic layoutAnimation = folly::dynamic::object( folly::dynamic layoutAnimation = folly::dynamic::object(
c_durationSz, defaultDuration)( c_durationSz, defaultDuration)(
c_createSz, c_createSz,
folly::dynamic::object(c_typeSz, c_linearSz)(c_propertySz, c_scaleXYSz))( folly::dynamic::object(c_typeSz, c_linearSz)(c_propertySz, c_scaleXYSz))(
c_updateSz, c_updateSz,
folly::dynamic::object(c_durationSz, customDuration)( folly::dynamic::object(c_durationSz, customDuration)(
c_typeSz, c_easeInSz)); c_typeSz, c_easeInSz));
LayoutAnimation typedLayoutAnimation(layoutAnimation); LayoutAnimation typedLayoutAnimation(layoutAnimation);
auto typedProps = typedLayoutAnimation.Properties(); auto typedProps = typedLayoutAnimation.Properties();
Assert::AreEqual(defaultDuration, typedProps.createAnimationProps.duration); Assert::AreEqual(defaultDuration, typedProps.createAnimationProps.duration);
Assert::AreEqual(customDuration, typedProps.updateAnimationProps.duration); Assert::AreEqual(customDuration, typedProps.updateAnimationProps.duration);
} }
TEST_METHOD(LayoutAnimationTests_MultipleDelaysTest) { TEST_METHOD(LayoutAnimationTests_MultipleDelaysTest) {
auto createDelay = 50.0f; auto createDelay = 50.0f;
auto updateDelay = 150.0f; auto updateDelay = 150.0f;
auto deleteDelay = 250.0f; auto deleteDelay = 250.0f;
folly::dynamic layoutAnimation = folly::dynamic::object(c_durationSz, 500)( folly::dynamic layoutAnimation = folly::dynamic::object(c_durationSz, 500)(
c_createSz, c_createSz,
folly::dynamic::object(c_delaySz, createDelay)(c_typeSz, c_linearSz)( folly::dynamic::object(c_delaySz, createDelay)(c_typeSz, c_linearSz)(
c_propertySz, c_scaleXYSz))( c_propertySz, c_scaleXYSz))(
c_updateSz, c_updateSz,
folly::dynamic::object(c_delaySz, updateDelay)(c_typeSz, c_easeInSz))( folly::dynamic::object(c_delaySz, updateDelay)(c_typeSz, c_easeInSz))(
c_deleteSz, c_deleteSz,
folly::dynamic::object(c_delaySz, deleteDelay)(c_typeSz, c_easeOutSz)( folly::dynamic::object(c_delaySz, deleteDelay)(c_typeSz, c_easeOutSz)(
c_propertySz, c_opacitySz)); c_propertySz, c_opacitySz));
LayoutAnimation typedLayoutAnimation(layoutAnimation); LayoutAnimation typedLayoutAnimation(layoutAnimation);
auto typedProps = typedLayoutAnimation.Properties(); auto typedProps = typedLayoutAnimation.Properties();
Assert::AreEqual(createDelay, typedProps.createAnimationProps.delay); Assert::AreEqual(createDelay, typedProps.createAnimationProps.delay);
Assert::AreEqual(updateDelay, typedProps.updateAnimationProps.delay); Assert::AreEqual(updateDelay, typedProps.updateAnimationProps.delay);
Assert::AreEqual(deleteDelay, typedProps.deleteAnimationProps.delay); Assert::AreEqual(deleteDelay, typedProps.deleteAnimationProps.delay);
} }
TEST_METHOD(LayoutAnimationTests_SpringPropertiesTest) { TEST_METHOD(LayoutAnimationTests_SpringPropertiesTest) {
auto damping = 0.7f; auto damping = 0.7f;
auto initialVelocity = 1.0f; auto initialVelocity = 1.0f;
folly::dynamic layoutAnimation = folly::dynamic::object(c_durationSz, 500)( folly::dynamic layoutAnimation = folly::dynamic::object(c_durationSz, 500)(
c_createSz, c_createSz,
folly::dynamic::object(c_typeSz, c_springSz)(c_springDampingSz, damping)( folly::dynamic::object(c_typeSz, c_springSz)(c_springDampingSz, damping)(
c_initialVelocitySz, initialVelocity)(c_propertySz, c_scaleXYSz)); c_initialVelocitySz, initialVelocity)(c_propertySz, c_scaleXYSz));
LayoutAnimation typedLayoutAnimation(layoutAnimation); LayoutAnimation typedLayoutAnimation(layoutAnimation);
auto typedProps = typedLayoutAnimation.Properties(); auto typedProps = typedLayoutAnimation.Properties();
Assert::AreEqual( Assert::AreEqual(
LayoutAnimation::AnimationType::Spring, LayoutAnimation::AnimationType::Spring,
typedProps.createAnimationProps.animationType); typedProps.createAnimationProps.animationType);
Assert::AreEqual( Assert::AreEqual(
damping, damping,
typedProps.createAnimationProps.springAnimationProperties.springDamping); typedProps.createAnimationProps.springAnimationProperties.springDamping);
Assert::AreEqual( Assert::AreEqual(
initialVelocity, initialVelocity,
typedProps.createAnimationProps.springAnimationProperties typedProps.createAnimationProps.springAnimationProperties
.initialVelocity); .initialVelocity);
} }
#pragma endregion #pragma endregion
} };
;
// clang-format on
} // namespace Microsoft::React::Test

Просмотреть файл

@ -40,6 +40,8 @@ uint32_t GetPageSize() noexcept {
} // anonymous namespace } // anonymous namespace
namespace Microsoft::JSI::Test {
TEST_CLASS(MemoryMappedBufferUnitTests) { TEST_CLASS(MemoryMappedBufferUnitTests) {
private: private:
std::wstring m_testFileName; std::wstring m_testFileName;
@ -167,3 +169,5 @@ TEST_CLASS(MemoryMappedBufferUnitTests) {
}); });
} }
}; };
} // namespace Microsoft::JSI::Test

Просмотреть файл

@ -11,6 +11,8 @@ using namespace facebook::react;
using namespace Microsoft::VisualStudio::CppUnitTestFramework; using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace std; using namespace std;
namespace Microsoft::React::Test {
TEST_CLASS(StringConversionTest_Desktop) { TEST_CLASS(StringConversionTest_Desktop) {
private: private:
JsRuntimeHandle runtime; JsRuntimeHandle runtime;
@ -45,3 +47,5 @@ TEST_CLASS(StringConversionTest_Desktop) {
} }
} }
}; };
} // namespace Microsoft::React::Test

Просмотреть файл

@ -10,6 +10,8 @@ using namespace facebook::react;
using namespace Microsoft::React::Test; using namespace Microsoft::React::Test;
using namespace Microsoft::VisualStudio::CppUnitTestFramework; using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace Microsoft::React::Test {
TEST_CLASS(UIManagerModuleTests) { TEST_CLASS(UIManagerModuleTests) {
protected: protected:
std::unique_ptr<EmptyUIManager> m_emptyUIManager; std::unique_ptr<EmptyUIManager> m_emptyUIManager;
@ -98,3 +100,5 @@ TEST_CLASS(UIManagerModuleTests) {
// EXPECT_STREQ("Some Text", it->second.c_str()); // EXPECT_STREQ("Some Text", it->second.c_str());
} }
}; };
} // namespace Microsoft::React::Test

Просмотреть файл

@ -10,6 +10,8 @@ using facebook::react::unicode::utf16ToUtf8;
using facebook::react::unicode::utf8ToUtf16; using facebook::react::unicode::utf8ToUtf16;
using Microsoft::VisualStudio::CppUnitTestFramework::Assert; using Microsoft::VisualStudio::CppUnitTestFramework::Assert;
namespace Microsoft::React::Test {
TEST_CLASS(UnicodeConversionTest) { TEST_CLASS(UnicodeConversionTest) {
public: public:
TEST_METHOD(PrerequisiteTest) { TEST_METHOD(PrerequisiteTest) {
@ -117,3 +119,5 @@ TEST_CLASS(UnicodeConversionTest) {
constexpr static const wchar_t *SimpleTestStringBomUtf16 = constexpr static const wchar_t *SimpleTestStringBomUtf16 =
L"\xfeff\x0061\x0062\x0063"; //<UTF-16BE BOM>abc L"\xfeff\x0061\x0062\x0063"; //<UTF-16BE BOM>abc
}; };
} // namespace Microsoft::React::Test

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -5,4 +5,8 @@
#include <string> #include <string>
#include <vector> #include <vector>
namespace Microsoft::React::Test {
extern std::vector<std::string> g_utf8TestStrings; extern std::vector<std::string> g_utf8TestStrings;
} // namespace Microsoft::React::Test

Просмотреть файл

@ -9,112 +9,125 @@ using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using std::string; using std::string;
TEST_CLASS(UtilsTest){void ExpectUrl( namespace Microsoft::React::Test {
string urlString,
string protocol,
string host,
string port = "",
string path = "/",
string query = ""){Url url(urlString);
Assert::AreEqual(protocol, url.scheme); // We turn clang format off here because it does not work with some of the
Assert::AreEqual(host, url.host); // test macros.
Assert::AreEqual(port, url.port); // clang-format off
Assert::AreEqual(path, url.path);
Assert::AreEqual(query, url.queryString); TEST_CLASS(UtilsTest) {
}
void ExpectUrl(
string urlString,
string protocol,
string host,
string port = "",
string path = "/",
string query = "") {
Url url(urlString);
Assert::AreEqual(protocol, url.scheme);
Assert::AreEqual(host, url.host);
Assert::AreEqual(port, url.port);
Assert::AreEqual(path, url.path);
Assert::AreEqual(query, url.queryString);
}
#pragma region Url Tests #pragma region Url Tests
TEST_METHOD(UtilsTest_ValidProtocols) { TEST_METHOD(UtilsTest_ValidProtocols) {
string protocols[4]{"http", "https", "ws", "wss"}; string protocols[4]{"http", "https", "ws", "wss"};
for (auto protocol : protocols) { for (auto protocol : protocols) {
ExpectUrl(string(protocol + "://internal"), protocol, "internal"); ExpectUrl(string(protocol + "://internal"), protocol, "internal");
}
} }
}
TEST_METHOD(UtilsTest_IntraHost) { TEST_METHOD(UtilsTest_IntraHost) {
ExpectUrl("ws://internal", "ws", "internal"); ExpectUrl("ws://internal", "ws", "internal");
} }
TEST_METHOD(UtilsTest_IntraHostTrailing) { TEST_METHOD(UtilsTest_IntraHostTrailing) {
ExpectUrl("ws://internal/", "ws", "internal"); ExpectUrl("ws://internal/", "ws", "internal");
} }
TEST_METHOD(UtilsTest_IntraHostQueryLeading) { TEST_METHOD(UtilsTest_IntraHostQueryLeading) {
ExpectUrl("ws://internal?", "ws", "internal"); ExpectUrl("ws://internal?", "ws", "internal");
} }
TEST_METHOD(UtilsTest_IntraHostTrailingQueryLeading) { TEST_METHOD(UtilsTest_IntraHostTrailingQueryLeading) {
ExpectUrl("ws://internal/?", "ws", "internal"); ExpectUrl("ws://internal/?", "ws", "internal");
} }
TEST_METHOD(UtilsTest_NormalHostQueryLeading) { TEST_METHOD(UtilsTest_NormalHostQueryLeading) {
ExpectUrl("ws://example.com?", "ws", "example.com"); ExpectUrl("ws://example.com?", "ws", "example.com");
} }
TEST_METHOD(UtilsTest_IntraPort) { TEST_METHOD(UtilsTest_IntraPort) {
ExpectUrl("ws://internal:5000", "ws", "internal", "5000"); ExpectUrl("ws://internal:5000", "ws", "internal", "5000");
} }
TEST_METHOD(UtilsTest_NormalPort) { TEST_METHOD(UtilsTest_NormalPort) {
ExpectUrl("ws://example.com:443", "ws", "example.com", "443"); ExpectUrl("ws://example.com:443", "ws", "example.com", "443");
} }
TEST_METHOD(UtilsTest_PortPath) { TEST_METHOD(UtilsTest_PortPath) {
ExpectUrl("ws://example.com:5000/ws", "ws", "example.com", "5000", "/ws"); ExpectUrl("ws://example.com:5000/ws", "ws", "example.com", "5000", "/ws");
} }
TEST_METHOD(UtilsTest_Query) { TEST_METHOD(UtilsTest_Query) {
ExpectUrl( ExpectUrl(
"ws://example.com?a=1&b=2", "ws", "example.com", "", "/", "a=1&b=2"); "ws://example.com?a=1&b=2", "ws", "example.com", "", "/", "a=1&b=2");
} }
TEST_METHOD(UtilsTest_TrailingPathQuery) { TEST_METHOD(UtilsTest_TrailingPathQuery) {
ExpectUrl( ExpectUrl(
"ws://example.com/?a=1&b=2", "ws", "example.com", "", "/", "a=1&b=2"); "ws://example.com/?a=1&b=2", "ws", "example.com", "", "/", "a=1&b=2");
} }
TEST_METHOD(UtilsTest_HyphenHostInternal) { TEST_METHOD(UtilsTest_HyphenHostInternal) {
ExpectUrl("wss://-my-hyphened-host--", "wss", "-my-hyphened-host--"); ExpectUrl("wss://-my-hyphened-host--", "wss", "-my-hyphened-host--");
} }
TEST_METHOD(UtilsTest_NestedPathTrailingSlashLeadingQuestionMark) { TEST_METHOD(UtilsTest_NestedPathTrailingSlashLeadingQuestionMark) {
ExpectUrl( ExpectUrl(
"ws://example.com/the/nested/path/?", "ws://example.com/the/nested/path/?",
"ws", "ws",
"example.com", "example.com",
"", "",
"/the/nested/path/"); "/the/nested/path/");
} }
TEST_METHOD(UtilsTest_NestedSubdomain) { TEST_METHOD(UtilsTest_NestedSubdomain) {
ExpectUrl( ExpectUrl(
"ws://nested.sub.domain.of.example.com", "ws://nested.sub.domain.of.example.com",
"ws", "ws",
"nested.sub.domain.of.example.com"); "nested.sub.domain.of.example.com");
} }
#pragma region Url Negative Tests #pragma region Url Negative Tests
TEST_METHOD(UtilsTest_EmptyStringFails) { TEST_METHOD(UtilsTest_EmptyStringFails) {
Assert::ExpectException<std::exception>([]() { Url(""); }); Assert::ExpectException<std::exception>([]() { Url(""); });
} }
TEST_METHOD(UtilsTest_WrongProtocol) { TEST_METHOD(UtilsTest_WrongProtocol) {
Assert::ExpectException<std::exception>([]() { Url("foos://internal"); }); Assert::ExpectException<std::exception>([]() { Url("foos://internal"); });
} }
TEST_METHOD(UtilsTest_BadCharsInPort) { TEST_METHOD(UtilsTest_BadCharsInPort) {
Assert::ExpectException<std::exception>([]() { Url("ws://internal:50O0"); }); Assert::ExpectException<std::exception>([]() { Url("ws://internal:50O0"); });
} }
TEST_METHOD(UtilsTest_SpacesInProtocol) { TEST_METHOD(UtilsTest_SpacesInProtocol) {
Assert::ExpectException<std::exception>([]() { Url(" ws://internal"); }); Assert::ExpectException<std::exception>([]() { Url(" ws://internal"); });
} }
#pragma endregion #pragma endregion
#pragma endregion #pragma endregion
} };
;
// clang-format on
} // namespace Microsoft::React::Test

Просмотреть файл

@ -7,11 +7,19 @@
using namespace Microsoft::React; using namespace Microsoft::React;
using namespace Microsoft::VisualStudio::CppUnitTestFramework; using namespace Microsoft::VisualStudio::CppUnitTestFramework;
TEST_CLASS(WebSocketJSExecutorTest){ namespace Microsoft::React::Test {
TEST_METHOD(WebSocketJSExecutorTest_Instantiate){
auto wsje = std::make_shared<WebSocketJSExecutor>(nullptr, nullptr);
Assert::IsFalse(nullptr == wsje); // We turn clang format off here because it does not work with some of the
} // test macros.
} // clang-format off
;
TEST_CLASS(WebSocketJSExecutorTest) {
TEST_METHOD(WebSocketJSExecutorTest_Instantiate){
auto wsje = std::make_shared<WebSocketJSExecutor>(nullptr, nullptr);
Assert::IsFalse(nullptr == wsje);
}
};
// clange-format on
} // namespace Microsoft::React::Test

Просмотреть файл

@ -8,6 +8,8 @@ using namespace facebook::react;
using namespace facebook::xplat::module; using namespace facebook::xplat::module;
using namespace Microsoft::VisualStudio::CppUnitTestFramework; using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace Microsoft::React::Test {
TEST_CLASS(WebSocketModuleTest) { TEST_CLASS(WebSocketModuleTest) {
enum class MethodId : size_t { enum class MethodId : size_t {
Connect = 0, Connect = 0,
@ -36,3 +38,5 @@ TEST_CLASS(WebSocketModuleTest) {
Assert::AreEqual(static_cast<size_t>(0), module->getConstants().size()); Assert::AreEqual(static_cast<size_t>(0), module->getConstants().size());
} }
}; };
} // namespace Microsoft::React::Test

Просмотреть файл

@ -11,48 +11,57 @@ using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using std::string; using std::string;
TEST_CLASS(WebSocketTest){TEST_METHOD(WebSocketTest_CreateAndSetHandlers){ namespace Microsoft::React::Test {
// We turn clang format off here because it does not work with some of the
// test macros.
// clang-format off
TEST_CLASS(WebSocketTest) {
TEST_METHOD(WebSocketTest_CreateAndSetHandlers) {
auto ws = std::make_shared<WebSocket>(Url("ws://validurl:0/")); auto ws = std::make_shared<WebSocket>(Url("ws://validurl:0/"));
Assert::IsFalse(nullptr == ws);
ws->SetOnConnect([]() {});
ws->SetOnPing([]() {});
ws->SetOnSend([](size_t length) {});
ws->SetOnMessage([](std::size_t length, const string &buffer) {});
ws->SetOnClose([](IWebSocket::CloseCode, const string &) {});
ws->SetOnError([](const IWebSocket::Error &error) {});
}
Assert::IsFalse(nullptr == ws); // TODO: Implement Protocol and Socket mocks.
ws->SetOnConnect([]() {}); void ConnectAndClose()
ws->SetOnPing([]() {}); // TEST_METHOD(WebSocketTest_ConnectAndClose)
ws->SetOnSend([](size_t length) {}); {
ws->SetOnMessage([](std::size_t length, const string &buffer) {}); auto ws = std::make_shared<WebSocket>(Url("ws://localhost:5555/"));
ws->SetOnClose([](IWebSocket::CloseCode, const string &) {}); bool connected = false;
ws->SetOnError([](const IWebSocket::Error &error) {}); ws->SetOnConnect([&connected]() { connected = true; });
}
// TODO: Implement Protocol and Socket mocks. ws->Connect({}, {});
void ConnectAndClose() ws->Close(IWebSocket::CloseCode::Normal, "BECAUSE!");
// TEST_METHOD(WebSocketTest_ConnectAndClose)
{
auto ws = std::make_shared<WebSocket>(Url("ws://localhost:5555/"));
bool connected = false;
ws->SetOnConnect([&connected]() { connected = true; });
ws->Connect({}, {}); Assert::IsTrue(connected);
ws->Close(IWebSocket::CloseCode::Normal, "BECAUSE!"); }
Assert::IsTrue(connected); // TODO: Implement Protocol and Socket mocks.
} void SendAndReceive()
// TEST_METHOD(WebSocketTest_SendAndReceive)
{
auto ws = std::make_shared<WebSocket>(Url("ws://localhost:5555/"));
ws->SetOnMessage([](size_t size, const string &message) {
// EXPECT_EQ("uppercaseme_response", ss.str());//TODO: Check test server.
// Sending back "hello".
Assert::AreEqual(
string("hello"),
message); // TODO: Check test server. Sending back "hello".
});
// TODO: Implement Protocol and Socket mocks. ws->Connect({}, {});
void SendAndReceive() ws->Send("uppercaseme");
// TEST_METHOD(WebSocketTest_SendAndReceive) ws->Close(IWebSocket::CloseCode::Normal, "");
{ }
auto ws = std::make_shared<WebSocket>(Url("ws://localhost:5555/")); };
ws->SetOnMessage([](size_t size, const string &message) {
// EXPECT_EQ("uppercaseme_response", ss.str());//TODO: Check test server.
// Sending back "hello".
Assert::AreEqual(
string("hello"),
message); // TODO: Check test server. Sending back "hello".
});
ws->Connect({}, {}); // clang-format on
ws->Send("uppercaseme");
ws->Close(IWebSocket::CloseCode::Normal, ""); } // namespace Microsoft::React::Test
}
}
;