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 {
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){
init_apartment(winrt::apartment_type::single_threaded);
IMessageQueue callbackMessageQueue = ::winrt::make<MessageQueueShim>();
MemoryTracker tracker{callbackMessageQueue};
TEST_CLASS(MemoryTrackerTests) {
uint32_t registrationToken = tracker.AddThresholdHandler(
/* threshold */ 100,
/* minCallbackIntervalInMilliseconds */ 100,
[](uint64_t currentUsage) {});
Assert::IsTrue(tracker.RemoveThresholdHandler(registrationToken));
} // namespace ABITests
TEST_METHOD(Handler_AddedAndRemoved){
init_apartment(winrt::apartment_type::single_threaded);
IMessageQueue callbackMessageQueue = ::winrt::make<MessageQueueShim>();
MemoryTracker tracker{callbackMessageQueue};
TEST_METHOD(CurrentMemoryUsage_ReturnsInitialValue) {
init_apartment(winrt::apartment_type::single_threaded);
IMessageQueue callbackMessageQueue = ::winrt::make<MessageQueueShim>();
MemoryTracker tracker{callbackMessageQueue};
uint32_t registrationToken = tracker.AddThresholdHandler(
/* threshold */ 100,
/* minCallbackIntervalInMilliseconds */ 100,
[](uint64_t currentUsage) {});
Assert::IsTrue(tracker.RemoveThresholdHandler(registrationToken));
}
tracker.Initialize(1000);
Assert::AreEqual(
1000ull, tracker.CurrentMemoryUsage(), L"CurrentMemoryUsage");
}
TEST_METHOD(CurrentMemoryUsage_ReturnsInitialValue) {
init_apartment(winrt::apartment_type::single_threaded);
IMessageQueue callbackMessageQueue = ::winrt::make<MessageQueueShim>();
MemoryTracker tracker{callbackMessageQueue};
TEST_METHOD(PeakMemoryUsage_ReturnsInitialValue) {
init_apartment(winrt::apartment_type::single_threaded);
IMessageQueue callbackMessageQueue = ::winrt::make<MessageQueueShim>();
MemoryTracker tracker{callbackMessageQueue};
tracker.Initialize(1000);
Assert::AreEqual(
1000ull, tracker.CurrentMemoryUsage(), L"CurrentMemoryUsage");
}
tracker.Initialize(1000);
Assert::AreEqual(1000ull, tracker.PeakMemoryUsage(), L"PeakMemoryUsage");
}
TEST_METHOD(PeakMemoryUsage_ReturnsInitialValue) {
init_apartment(winrt::apartment_type::single_threaded);
IMessageQueue callbackMessageQueue = ::winrt::make<MessageQueueShim>();
MemoryTracker tracker{callbackMessageQueue};
TEST_METHOD(ThresholdHandler_Called) {
init_apartment(winrt::apartment_type::single_threaded);
tracker.Initialize(1000);
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>(
ControllableMessageQueueThread::Mode::ManualDispatch);
DWORD testThreadId = GetCurrentThreadId();
IMessageQueue callbackMessageQueue =
::winrt::make<MessageQueueShim>(manualMessageQueue);
MemoryTracker tracker{callbackMessageQueue};
auto manualMessageQueue = std::make_shared<ControllableMessageQueueThread>(
ControllableMessageQueueThread::Mode::ManualDispatch);
tracker.Initialize(500);
IMessageQueue callbackMessageQueue =
::winrt::make<MessageQueueShim>(manualMessageQueue);
MemoryTracker tracker{callbackMessageQueue};
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();
});
tracker.Initialize(500);
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
Assert::IsTrue(
manualMessageQueue->DispatchOne(std::chrono::milliseconds(500)));
Assert::IsTrue(manualMessageQueue->IsEmpty());
tracker.OnAllocation(1000);
Assert::AreEqual(
1500ull, tracker.CurrentMemoryUsage(), L"CurrentMemoryUsage");
Assert::AreEqual(1500ull, tracker.PeakMemoryUsage(), L"PeakMemoryUsage");
// allow the callback to get dispatched
Assert::IsTrue(
manualMessageQueue->DispatchOne(std::chrono::milliseconds(500)));
Assert::IsTrue(manualMessageQueue->IsEmpty());
Assert::AreEqual(static_cast<size_t>(1), actualCallbacks.size());
Assert::AreEqual(1500ull, actualCallbacks[0]);
Assert::AreEqual(
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

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

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

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

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

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

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

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

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

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

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

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

@ -40,6 +40,8 @@ uint32_t GetPageSize() noexcept {
} // anonymous namespace
namespace Microsoft::JSI::Test {
TEST_CLASS(MemoryMappedBufferUnitTests) {
private:
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 std;
namespace Microsoft::React::Test {
TEST_CLASS(StringConversionTest_Desktop) {
private:
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::VisualStudio::CppUnitTestFramework;
namespace Microsoft::React::Test {
TEST_CLASS(UIManagerModuleTests) {
protected:
std::unique_ptr<EmptyUIManager> m_emptyUIManager;
@ -98,3 +100,5 @@ TEST_CLASS(UIManagerModuleTests) {
// 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 Microsoft::VisualStudio::CppUnitTestFramework::Assert;
namespace Microsoft::React::Test {
TEST_CLASS(UnicodeConversionTest) {
public:
TEST_METHOD(PrerequisiteTest) {
@ -117,3 +119,5 @@ TEST_CLASS(UnicodeConversionTest) {
constexpr static const wchar_t *SimpleTestStringBomUtf16 =
L"\xfeff\x0061\x0062\x0063"; //<UTF-16BE BOM>abc
};
} // namespace Microsoft::React::Test

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

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

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

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

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

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

@ -7,11 +7,19 @@
using namespace Microsoft::React;
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
TEST_CLASS(WebSocketJSExecutorTest){
TEST_METHOD(WebSocketJSExecutorTest_Instantiate){
auto wsje = std::make_shared<WebSocketJSExecutor>(nullptr, nullptr);
namespace Microsoft::React::Test {
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 Microsoft::VisualStudio::CppUnitTestFramework;
namespace Microsoft::React::Test {
TEST_CLASS(WebSocketModuleTest) {
enum class MethodId : size_t {
Connect = 0,
@ -36,3 +38,5 @@ TEST_CLASS(WebSocketModuleTest) {
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;
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/"));
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);
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) {});
}
// TODO: Implement Protocol and Socket mocks.
void ConnectAndClose()
// TEST_METHOD(WebSocketTest_ConnectAndClose)
{
auto ws = std::make_shared<WebSocket>(Url("ws://localhost:5555/"));
bool connected = false;
ws->SetOnConnect([&connected]() { connected = true; });
// TODO: Implement Protocol and Socket mocks.
void ConnectAndClose()
// TEST_METHOD(WebSocketTest_ConnectAndClose)
{
auto ws = std::make_shared<WebSocket>(Url("ws://localhost:5555/"));
bool connected = false;
ws->SetOnConnect([&connected]() { connected = true; });
ws->Connect({}, {});
ws->Close(IWebSocket::CloseCode::Normal, "BECAUSE!");
ws->Connect({}, {});
ws->Close(IWebSocket::CloseCode::Normal, "BECAUSE!");
Assert::IsTrue(connected);
}
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.
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".
});
ws->Connect({}, {});
ws->Send("uppercaseme");
ws->Close(IWebSocket::CloseCode::Normal, "");
}
};
ws->Connect({}, {});
ws->Send("uppercaseme");
ws->Close(IWebSocket::CloseCode::Normal, "");
}
}
;
// clang-format on
} // namespace Microsoft::React::Test