Remove AsyncHelper, Resource and Module.cpp from CalculatorUnitTests project. (#746)
This commit is contained in:
parent
5e46ceabc8
commit
b36441ba5f
@ -1,39 +0,0 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#include "pch.h"
|
||||
#include "AsyncHelper.h"
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
using namespace std;
|
||||
using namespace concurrency;
|
||||
using namespace Platform;
|
||||
using namespace CalculatorApp;
|
||||
using namespace Windows::UI::Core;
|
||||
using namespace Windows::ApplicationModel::Core;
|
||||
|
||||
task<void> AsyncHelper::RunOnUIThreadAsync(function<void()>&& action)
|
||||
{
|
||||
auto callback = ref new DispatchedHandler([action]() { action(); });
|
||||
|
||||
return create_task(CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(CoreDispatcherPriority::Normal, callback));
|
||||
}
|
||||
|
||||
void AsyncHelper::RunOnUIThread(function<void()>&& action, DWORD timeout)
|
||||
{
|
||||
task<void> waitTask = RunOnUIThreadAsync([action]() { action(); });
|
||||
|
||||
WaitForTask<void>(waitTask, timeout);
|
||||
}
|
||||
|
||||
void AsyncHelper::Delay(DWORD milliseconds)
|
||||
{
|
||||
thread timer(bind(CalculatorApp::AsyncHelper::Sleep, milliseconds));
|
||||
timer.join();
|
||||
}
|
||||
|
||||
void AsyncHelper::Sleep(DWORD milliseconds)
|
||||
{
|
||||
this_thread::sleep_for(chrono::milliseconds(milliseconds));
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#pragma once
|
||||
#include <wrl/wrappers/corewrappers.h>
|
||||
|
||||
namespace CalculatorApp
|
||||
{
|
||||
class AsyncHelper
|
||||
{
|
||||
public:
|
||||
static concurrency::task<void> RunOnUIThreadAsync(std::function<void()>&& action);
|
||||
static void RunOnUIThread(std::function<void()>&& action, DWORD timeout = INFINITE);
|
||||
static void Delay(DWORD milliseconds);
|
||||
|
||||
template <typename T>
|
||||
static void RunOnUIThread(std::function<concurrency::task<T>()>&& action, DWORD timeout = INFINITE)
|
||||
{
|
||||
concurrency::task<T> t;
|
||||
concurrency::task<void> uiTask =
|
||||
RunOnUIThreadAsync([&t, action]() { t = action(); }).then([&t]() { t.wait(); }, concurrency::task_continuation_context::use_arbitrary());
|
||||
|
||||
WaitForTask<void>(uiTask, timeout);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static bool WaitForTask(concurrency::task<T>& t, DWORD timeout = INFINITE)
|
||||
{
|
||||
Microsoft::WRL::Wrappers::Event event(CreateEventEx(nullptr, nullptr, CREATE_EVENT_MANUAL_RESET, EVENT_ALL_ACCESS));
|
||||
if (!event.IsValid())
|
||||
{
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
|
||||
Platform::Exception ^ ex;
|
||||
t.then(
|
||||
[&event, &ex](concurrency::task<T> prevTask) {
|
||||
try
|
||||
{
|
||||
prevTask.get();
|
||||
}
|
||||
catch (Platform::Exception ^ e)
|
||||
{
|
||||
ex = e;
|
||||
}
|
||||
|
||||
if (event.IsValid())
|
||||
{
|
||||
SetEvent(event.Get());
|
||||
}
|
||||
},
|
||||
concurrency::task_continuation_context::use_arbitrary());
|
||||
|
||||
DWORD waitResult; // = STATUS_PENDING;
|
||||
waitResult = WaitForSingleObjectEx(event.Get(), timeout, true);
|
||||
event.Close();
|
||||
|
||||
if (ex != nullptr)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
|
||||
if (waitResult == WAIT_FAILED)
|
||||
{
|
||||
throw ref new Platform::Exception(-1, L"Error in waiting for task completion: " + waitResult.ToString());
|
||||
}
|
||||
|
||||
return waitResult == WAIT_OBJECT_0;
|
||||
}
|
||||
|
||||
private:
|
||||
static void Sleep(DWORD milliseconds);
|
||||
};
|
||||
}
|
Binary file not shown.
@ -207,12 +207,10 @@
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="AsyncHelper.h" />
|
||||
<ClInclude Include="DateUtils.h" />
|
||||
<ClInclude Include="Helpers.h" />
|
||||
<ClInclude Include="Mocks\CurrencyHttpClient.h" />
|
||||
<ClInclude Include="pch.h" />
|
||||
<ClInclude Include="resource.h" />
|
||||
<ClInclude Include="UnitConverterViewModelUnitTests.h" />
|
||||
<ClInclude Include="UnitTestApp.xaml.h">
|
||||
<DependentUpon>UnitTestApp.xaml</DependentUpon>
|
||||
@ -238,7 +236,6 @@
|
||||
<Image Include="Assets\Wide310x150Logo.scale-200.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="AsyncHelper.cpp" />
|
||||
<ClCompile Include="CalcEngineTests.cpp" />
|
||||
<ClCompile Include="CalcInputTest.cpp" />
|
||||
<ClCompile Include="CalculatorManagerTest.cpp" />
|
||||
@ -248,7 +245,6 @@
|
||||
<ClCompile Include="HistoryTests.cpp" />
|
||||
<ClCompile Include="LocalizationServiceUnitTests.cpp" />
|
||||
<ClCompile Include="Mocks\CurrencyHttpClient.cpp" />
|
||||
<ClCompile Include="Module.cpp" />
|
||||
<ClCompile Include="MultiWindowUnitTests.cpp" />
|
||||
<ClCompile Include="NavCategoryUnitTests.cpp" />
|
||||
<ClCompile Include="RationalTest.cpp" />
|
||||
@ -272,7 +268,6 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<SDKReference Include="CppUnitTestFramework.Universal, Version=$(UnitTestPlatformVersion)" />
|
||||
<SDKReference Include="Microsoft.VCLibs.Desktop, Version=14.0" />
|
||||
<SDKReference Include="TestPlatform.Universal, Version=$(UnitTestPlatformVersion)" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@ -288,9 +283,6 @@
|
||||
<SubType>Designer</SubType>
|
||||
</PRIResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="CalculatorUnitTests.rc" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CalcManager\CalcManager.vcxproj">
|
||||
<Project>{311e866d-8b93-4609-a691-265941fee101}</Project>
|
||||
@ -302,4 +294,4 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
</Project>
|
@ -9,7 +9,6 @@
|
||||
<PRIResource Include="Test.resw" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="AsyncHelper.cpp" />
|
||||
<ClCompile Include="CalcEngineTests.cpp" />
|
||||
<ClCompile Include="CalcInputTest.cpp" />
|
||||
<ClCompile Include="CalculatorManagerTest.cpp" />
|
||||
@ -17,7 +16,6 @@
|
||||
<ClCompile Include="CurrencyConverterUnitTests.cpp" />
|
||||
<ClCompile Include="DateCalculatorUnitTests.cpp" />
|
||||
<ClCompile Include="HistoryTests.cpp" />
|
||||
<ClCompile Include="Module.cpp" />
|
||||
<ClCompile Include="MultiWindowUnitTests.cpp" />
|
||||
<ClCompile Include="NavCategoryUnitTests.cpp" />
|
||||
<ClCompile Include="StandardViewModelUnitTests.cpp" />
|
||||
@ -33,20 +31,15 @@
|
||||
<ClCompile Include="RationalTest.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="AsyncHelper.h" />
|
||||
<ClInclude Include="DateUtils.h" />
|
||||
<ClInclude Include="Helpers.h" />
|
||||
<ClInclude Include="pch.h" />
|
||||
<ClInclude Include="UnitConverterViewModelUnitTests.h" />
|
||||
<ClInclude Include="UnitTestApp.xaml.h" />
|
||||
<ClInclude Include="resource.h" />
|
||||
<ClInclude Include="Mocks\CurrencyHttpClient.h">
|
||||
<Filter>Mocks</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="CalculatorUnitTests.rc" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Xml Include="UnitTestApp.rd.xml" />
|
||||
</ItemGroup>
|
||||
|
@ -1,22 +0,0 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#include "pch.h"
|
||||
#include <CppUnitTest.h>
|
||||
|
||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
|
||||
namespace CalculatorUnitTests
|
||||
{
|
||||
BEGIN_TEST_MODULE_ATTRIBUTE()
|
||||
TEST_MODULE_ATTRIBUTE(L"APPX:CertificateFileName", L"CalculatorUnitTests.cer:TrustedPeople")
|
||||
END_TEST_MODULE_ATTRIBUTE()
|
||||
|
||||
TEST_MODULE_INITIALIZE(ModuleSetup)
|
||||
{
|
||||
}
|
||||
|
||||
TEST_MODULE_CLEANUP(ModuleCleanup)
|
||||
{
|
||||
}
|
||||
}
|
@ -509,7 +509,7 @@ namespace CalculatorUnitTests
|
||||
VERIFY_ARE_EQUAL(Utils::GetStringValue(m_viewModel->DecimalDisplayValue), StringReference(L"15"));
|
||||
VERIFY_ARE_EQUAL(Utils::GetStringValue(m_viewModel->OctalDisplayValue), StringReference(L"17"));
|
||||
VERIFY_ARE_EQUAL(Utils::GetStringValue(m_viewModel->BinaryDisplayValue), StringReference(L"1111"));
|
||||
auto val = ref new PC::Vector<bool>(64, false);
|
||||
auto val = ref new Platform::Collections::Vector<bool>(64, false);
|
||||
val->SetAt(0, true);
|
||||
val->SetAt(1, true);
|
||||
val->SetAt(2, true);
|
||||
@ -562,7 +562,7 @@ namespace CalculatorUnitTests
|
||||
VERIFY_ARE_EQUAL(Utils::GetStringValue(m_viewModel->DecimalDisplayValue), StringReference(L"123,456,789"));
|
||||
VERIFY_ARE_EQUAL(Utils::GetStringValue(m_viewModel->OctalDisplayValue), StringReference(L"726 746 425"));
|
||||
VERIFY_ARE_EQUAL(Utils::GetStringValue(m_viewModel->BinaryDisplayValue), StringReference(L"0111 0101 1011 1100 1101 0001 0101"));
|
||||
auto val = ref new PC::Vector<bool>(64, false);
|
||||
auto val = ref new Platform::Collections::Vector<bool>(64, false);
|
||||
val->SetAt(0, true);
|
||||
val->SetAt(2, true);
|
||||
val->SetAt(4, true);
|
||||
@ -599,7 +599,7 @@ namespace CalculatorUnitTests
|
||||
Utils::GetStringValue(m_viewModel->BinaryDisplayValue),
|
||||
StringReference(L"1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1110"));
|
||||
VERIFY_ARE_EQUAL(m_viewModel->DisplayValue, StringReference(L"-2"));
|
||||
auto val = ref new PC::Vector<bool>(64, true);
|
||||
auto val = ref new Platform::Collections::Vector<bool>(64, true);
|
||||
val->SetAt(0, false);
|
||||
CompareVector<bool>(m_viewModel->BinaryDigits, val);
|
||||
}
|
||||
|
@ -48,37 +48,6 @@
|
||||
#include "winrt/Windows.Globalization.DateTimeFormatting.h"
|
||||
#include "winrt/Windows.System.UserProfile.h"
|
||||
|
||||
namespace CalculatorApp
|
||||
{
|
||||
namespace WF = Windows::Foundation;
|
||||
namespace WUC = Windows::UI::Core;
|
||||
namespace WX = Windows::UI::Xaml;
|
||||
namespace WXC = Windows::UI::Xaml::Controls;
|
||||
namespace WXCP = Windows::UI::Xaml::Controls::Primitives;
|
||||
namespace P = Platform;
|
||||
namespace PC = Platform::Collections;
|
||||
namespace WXI = Windows::UI::Xaml::Input;
|
||||
namespace WFC = Windows::Foundation::Collections;
|
||||
namespace WS = Windows::System;
|
||||
namespace WAR = Windows::ApplicationModel::Resources;
|
||||
namespace WXMA = Windows::UI::Xaml::Media::Animation;
|
||||
namespace WXD = Windows::UI::Xaml::Data;
|
||||
namespace WXInt = Windows::UI::Xaml::Interop;
|
||||
namespace WXM = Windows::UI::Xaml::Markup;
|
||||
namespace WXA = Windows::UI::Xaml::Automation;
|
||||
}
|
||||
|
||||
// The following namespaces exist as a convenience to resolve
|
||||
// ambiguity for Windows types in the Windows::UI::Xaml::Automation::Peers
|
||||
// namespace that only exist on RS3.
|
||||
// Once the app switches to min version RS3, the namespaces can be removed.
|
||||
// TODO - MSFT 12735088
|
||||
namespace StandardPeers = Windows::UI::Xaml::Automation::Peers;
|
||||
namespace CalculatorApp::Common::Automation
|
||||
{
|
||||
}
|
||||
namespace CustomPeers = CalculatorApp::Common::Automation;
|
||||
|
||||
// CalcManager Headers
|
||||
#include "CalcManager/ExpressionCommand.h"
|
||||
#include "CalcManager/CalculatorResource.h"
|
||||
|
@ -1,14 +0,0 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Visual C++ generated include file.
|
||||
// Used by CalculatorUnitTests_VS.rc
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 101
|
||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||
#define _APS_NEXT_CONTROL_VALUE 1001
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user