Revert "Replace wstring used in public methods by Platform::String in CalcViewModel (#758)" (#767)

This reverts commit 93f1f784bb.
This commit is contained in:
Rudy Huyn 2019-11-04 17:54:12 -08:00 committed by Matt Cooley
parent 93f1f784bb
commit 049d3f4c6c
35 changed files with 533 additions and 509 deletions

View File

@ -152,7 +152,7 @@ void ApplicationViewModel::OnModeChanged()
} }
auto resProvider = AppResourceProvider::GetInstance(); auto resProvider = AppResourceProvider::GetInstance();
CategoryName = resProvider->GetResourceString(NavCategory::GetNameResourceKey(m_mode)); CategoryName = resProvider.GetResourceString(NavCategory::GetNameResourceKey(m_mode));
// Cast mode to an int in order to save it to app data. // Cast mode to an int in order to save it to app data.
// Save the changed mode, so that the new window launches in this mode. // Save the changed mode, so that the new window launches in this mode.

View File

@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved. // Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. // Licensed under the MIT License.
#include "pch.h" #include "pch.h"
@ -14,9 +14,9 @@ AppResourceProvider::AppResourceProvider()
m_cEngineStringResLoader = ResourceLoader::GetForViewIndependentUse(L"CEngineStrings"); m_cEngineStringResLoader = ResourceLoader::GetForViewIndependentUse(L"CEngineStrings");
} }
AppResourceProvider ^ AppResourceProvider::GetInstance() AppResourceProvider& AppResourceProvider::GetInstance()
{ {
static AppResourceProvider ^ s_instance = ref new AppResourceProvider(); static AppResourceProvider s_instance;
return s_instance; return s_instance;
} }

View File

@ -1,14 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved. // Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. // Licensed under the MIT License.
#pragma once #pragma once
namespace CalculatorApp namespace CalculatorApp
{ {
public ref class AppResourceProvider sealed class AppResourceProvider
{ {
public: public:
static AppResourceProvider ^ GetInstance(); static AppResourceProvider& GetInstance();
Platform::String ^ GetResourceString(_In_ Platform::String ^ key); Platform::String ^ GetResourceString(_In_ Platform::String ^ key);
Platform::String ^ GetCEngineString(_In_ Platform::String ^ key); Platform::String ^ GetCEngineString(_In_ Platform::String ^ key);

View File

@ -9,7 +9,6 @@
using namespace CalculatorApp; using namespace CalculatorApp;
using namespace CalculationManager; using namespace CalculationManager;
using namespace Platform;
using namespace std; using namespace std;
CalculatorDisplay::CalculatorDisplay() CalculatorDisplay::CalculatorDisplay()
@ -32,7 +31,7 @@ void CalculatorDisplay::SetPrimaryDisplay(_In_ const wstring& displayStringValue
{ {
if (auto calcVM = m_callbackReference.Resolve<ViewModel::StandardCalculatorViewModel>()) if (auto calcVM = m_callbackReference.Resolve<ViewModel::StandardCalculatorViewModel>())
{ {
calcVM->SetPrimaryDisplay(StringReference(displayStringValue.c_str()), isError); calcVM->SetPrimaryDisplay(displayStringValue, isError);
} }
} }
} }

View File

@ -15,7 +15,7 @@ using namespace Windows::Foundation;
using namespace Windows::System; using namespace Windows::System;
using namespace Windows::ApplicationModel::DataTransfer; using namespace Windows::ApplicationModel::DataTransfer;
StringReference PasteErrorString(L"NoOp"); String ^ CopyPasteManager::supportedFormats[] = { StandardDataFormats::Text };
static const wstring c_validBasicCharacterSet = L"0123456789+-.e"; static const wstring c_validBasicCharacterSet = L"0123456789+-.e";
static const wstring c_validStandardCharacterSet = c_validBasicCharacterSet + L"*/"; static const wstring c_validStandardCharacterSet = c_validBasicCharacterSet + L"*/";
@ -66,7 +66,7 @@ void CopyPasteManager::CopyToClipboard(String ^ stringToCopy)
Clipboard::SetContent(dataPackage); Clipboard::SetContent(dataPackage);
} }
IAsyncOperation<String ^> ^ CopyPasteManager::GetStringToPaste(ViewMode mode, CategoryGroupType modeType, int programmerNumberBase, BitLength bitLengthType) task<String ^> CopyPasteManager::GetStringToPaste(ViewMode mode, CategoryGroupType modeType, int programmerNumberBase, BitLength bitLengthType)
{ {
// Retrieve the text in the clipboard // Retrieve the text in the clipboard
auto dataPackageView = Clipboard::GetContent(); auto dataPackageView = Clipboard::GetContent();
@ -76,29 +76,36 @@ IAsyncOperation<String ^> ^ CopyPasteManager::GetStringToPaste(ViewMode mode, Ca
//-- add support to allow pasting for expressions like .2 , -.2 //-- add support to allow pasting for expressions like .2 , -.2
//-- add support to allow pasting for expressions like 1.3e12(as of now we allow 1.3e+12) //-- add support to allow pasting for expressions like 1.3e12(as of now we allow 1.3e+12)
return create_async([dataPackageView, mode, modeType, programmerNumberBase, bitLengthType] { return create_task((dataPackageView->GetTextAsync(::StandardDataFormats::Text)))
return create_task(dataPackageView->GetTextAsync(::StandardDataFormats::Text)) .then(
.then( [mode, modeType, programmerNumberBase, bitLengthType](String ^ pastedText) {
[mode, modeType, programmerNumberBase, bitLengthType](String ^ pastedText) { return ValidatePasteExpression(pastedText, mode, modeType, programmerNumberBase, bitLengthType);
return ValidatePasteExpression(pastedText, mode, modeType, programmerNumberBase, bitLengthType); },
}, task_continuation_context::use_arbitrary());
task_continuation_context::use_arbitrary());
});
} }
bool CopyPasteManager::HasStringToPaste() int CopyPasteManager::ClipboardTextFormat()
{ {
return Clipboard::GetContent()->Contains(StandardDataFormats::Text); const auto dataPackageView = Clipboard::GetContent();
for (int i = 0; i < RTL_NUMBER_OF(supportedFormats); i++)
{
if (dataPackageView->Contains(supportedFormats[i]))
{
return i;
}
}
return -1;
} }
String ^ CopyPasteManager::ValidatePasteExpression(String ^ pastedText, ViewMode mode, int programmerNumberBase, BitLength bitLengthType) String ^ CopyPasteManager::ValidatePasteExpression(String ^ pastedText, ViewMode mode, int programmerNumberBase, BitLength bitLengthType)
{ {
return ValidatePasteExpression(pastedText, mode, NavCategory::GetGroupType(mode), programmerNumberBase, bitLengthType); return CopyPasteManager::ValidatePasteExpression(pastedText, mode, NavCategory::GetGroupType(mode), programmerNumberBase, bitLengthType);
} }
// return "NoOp" if pastedText is invalid else return pastedText // return "NoOp" if pastedText is invalid else return pastedText
String
^ CopyPasteManager::ValidatePasteExpression( String ^ CopyPasteManager::ValidatePasteExpression(
String ^ pastedText, String ^ pastedText,
ViewMode mode, ViewMode mode,
CategoryGroupType modeType, CategoryGroupType modeType,
@ -109,14 +116,16 @@ String
{ {
// return NoOp to indicate don't paste anything. // return NoOp to indicate don't paste anything.
TraceLogger::GetInstance().LogError(mode, L"CopyPasteManager::ValidatePasteExpression", L"PastedExpressionSizeGreaterThanMaxAllowed"); TraceLogger::GetInstance().LogError(mode, L"CopyPasteManager::ValidatePasteExpression", L"PastedExpressionSizeGreaterThanMaxAllowed");
return PasteErrorString; return StringReference(PasteErrorString);
} }
wstring pasteExpression = pastedText->Data();
// Get english translated expression // Get english translated expression
String ^ englishString = LocalizationSettings::GetInstance().GetEnglishValueFromLocalizedDigits(pastedText); String ^ englishString = LocalizationSettings::GetInstance().GetEnglishValueFromLocalizedDigits(pasteExpression);
// Removing the spaces, comma separator from the pasteExpression to allow pasting of expressions like 1 + 2+1,333 // Removing the spaces, comma separator from the pasteExpression to allow pasting of expressions like 1 + 2+1,333
wstring pasteExpression = RemoveUnwantedCharsFromWstring(englishString->Data()); pasteExpression = RemoveUnwantedCharsFromWstring(englishString->Data());
// If the last character is an = sign, remove it from the pasteExpression to allow evaluating the result on paste. // If the last character is an = sign, remove it from the pasteExpression to allow evaluating the result on paste.
if (!pasteExpression.empty() && pasteExpression.back() == L'=') if (!pasteExpression.empty() && pasteExpression.back() == L'=')
@ -130,7 +139,7 @@ String
if (operands.empty()) if (operands.empty())
{ {
// return NoOp to indicate don't paste anything. // return NoOp to indicate don't paste anything.
return PasteErrorString; return StringReference(PasteErrorString);
} }
if (modeType == CategoryGroupType::Converter) if (modeType == CategoryGroupType::Converter)
@ -142,10 +151,10 @@ String
if (!ExpressionRegExMatch(operands, mode, modeType, programmerNumberBase, bitLengthType)) if (!ExpressionRegExMatch(operands, mode, modeType, programmerNumberBase, bitLengthType))
{ {
TraceLogger::GetInstance().LogError(mode, L"CopyPasteManager::ValidatePasteExpression", L"InvalidExpressionForPresentMode"); TraceLogger::GetInstance().LogError(mode, L"CopyPasteManager::ValidatePasteExpression", L"InvalidExpressionForPresentMode");
return PasteErrorString; return StringReference(PasteErrorString);
} }
return pastedText; return ref new String(pastedText->Data());
} }
vector<wstring> CopyPasteManager::ExtractOperands(const wstring& pasteExpression, ViewMode mode) vector<wstring> CopyPasteManager::ExtractOperands(const wstring& pasteExpression, ViewMode mode)
@ -584,8 +593,3 @@ wstring CopyPasteManager::RemoveUnwantedCharsFromWstring(const wstring& input)
wchar_t unWantedChars[] = { L' ', L',', L'"', 165, 164, 8373, 36, 8353, 8361, 8362, 8358, 8377, 163, 8364, 8234, 8235, 8236, 8237 }; wchar_t unWantedChars[] = { L' ', L',', L'"', 165, 164, 8373, 36, 8353, 8361, 8362, 8358, 8377, 163, 8364, 8234, 8235, 8236, 8237 };
return Utils::RemoveUnwantedCharsFromWstring(input, unWantedChars, 18); return Utils::RemoveUnwantedCharsFromWstring(input, unWantedChars, 18);
} }
bool CopyPasteManager::IsErrorMessage(Platform::String ^ message)
{
return message == PasteErrorString;
}

View File

@ -19,19 +19,24 @@ namespace CalculatorApp
inline constexpr auto OctBase = 7; inline constexpr auto OctBase = 7;
inline constexpr auto BinBase = 8; inline constexpr auto BinBase = 8;
public ref class CopyPasteManager sealed class CopyPasteManager
{ {
public: public:
static void CopyToClipboard(Platform::String ^ stringToCopy); static void CopyToClipboard(Platform::String ^ stringToCopy);
static Windows::Foundation::IAsyncOperation<Platform::String ^>^ GetStringToPaste( static concurrency::task<Platform::String ^> GetStringToPaste(
CalculatorApp::Common::ViewMode mode, CalculatorApp::Common::ViewMode mode,
CalculatorApp::Common::CategoryGroupType modeType, CalculatorApp::Common::CategoryGroupType modeType,
int programmerNumberBase, int programmerNumberBase = -1,
CalculatorApp::Common::BitLength bitLengthType); CalculatorApp::Common::BitLength bitLengthType = CalculatorApp::Common::BitLength::BitLengthUnknown);
static bool HasStringToPaste(); static bool HasStringToPaste()
static bool IsErrorMessage(Platform::String ^ message); {
return ClipboardTextFormat() >= 0;
}
static constexpr auto PasteErrorString = L"NoOp";
private: private:
static int ClipboardTextFormat();
static Platform::String static Platform::String
^ ValidatePasteExpression( ^ ValidatePasteExpression(
Platform::String ^ pastedText, Platform::String ^ pastedText,
@ -79,6 +84,8 @@ namespace CalculatorApp
static constexpr size_t MaxExponentLength = 4; static constexpr size_t MaxExponentLength = 4;
static constexpr size_t MaxProgrammerBitLength = 64; static constexpr size_t MaxProgrammerBitLength = 64;
static Platform::String ^ supportedFormats[];
friend class CalculatorUnitTests::CopyPasteManagerTest; friend class CalculatorUnitTests::CopyPasteManagerTest;
}; };
} }

View File

@ -519,7 +519,7 @@ void KeyboardShortcutManager::OnKeyDownHandler(CoreWindow ^ sender, KeyEventArgs
auto navView = buttons.first->second.Resolve<MUXC::NavigationView>(); auto navView = buttons.first->second.Resolve<MUXC::NavigationView>();
auto appViewModel = safe_cast<ApplicationViewModel ^>(navView->DataContext); auto appViewModel = safe_cast<ApplicationViewModel ^>(navView->DataContext);
appViewModel->Mode = ViewMode::Date; appViewModel->Mode = ViewMode::Date;
auto categoryName = AppResourceProvider::GetInstance()->GetResourceString(L"DateCalculationModeText"); auto categoryName = AppResourceProvider::GetInstance().GetResourceString(L"DateCalculationModeText");
appViewModel->CategoryName = categoryName; appViewModel->CategoryName = categoryName;
auto menuItems = static_cast<IObservableVector<Object ^> ^>(navView->MenuItemsSource); auto menuItems = static_cast<IObservableVector<Object ^> ^>(navView->MenuItemsSource);

View File

@ -94,16 +94,16 @@ LocalizationService::LocalizationService(_In_ const wchar_t * const overridedLan
m_locale = locale(""); m_locale = locale("");
} }
auto resourceLoader = AppResourceProvider::GetInstance(); auto resourceLoader = AppResourceProvider::GetInstance();
m_fontFamilyOverride = resourceLoader->GetResourceString(L"LocalizedFontFamilyOverride"); m_fontFamilyOverride = resourceLoader.GetResourceString(L"LocalizedFontFamilyOverride");
String ^ reserved = L"RESERVED_FOR_FONTLOC"; String ^ reserved = L"RESERVED_FOR_FONTLOC";
m_overrideFontApiValues = ((m_fontFamilyOverride != nullptr) && (m_fontFamilyOverride != reserved)); m_overrideFontApiValues = ((m_fontFamilyOverride != nullptr) && (m_fontFamilyOverride != reserved));
if (m_overrideFontApiValues) if (m_overrideFontApiValues)
{ {
String ^ localizedUICaptionFontSizeFactorOverride = resourceLoader->GetResourceString(L"LocalizedUICaptionFontSizeFactorOverride"); String ^ localizedUICaptionFontSizeFactorOverride = resourceLoader.GetResourceString(L"LocalizedUICaptionFontSizeFactorOverride");
String ^ localizedUITextFontSizeFactorOverride = resourceLoader->GetResourceString(L"LocalizedUITextFontSizeFactorOverride"); String ^ localizedUITextFontSizeFactorOverride = resourceLoader.GetResourceString(L"LocalizedUITextFontSizeFactorOverride");
String ^ localizedFontWeightOverride = resourceLoader->GetResourceString(L"LocalizedFontWeightOverride"); String ^ localizedFontWeightOverride = resourceLoader.GetResourceString(L"LocalizedFontWeightOverride");
// If any of the font overrides are modified then all of them need to be modified // If any of the font overrides are modified then all of them need to be modified
assert(localizedFontWeightOverride != reserved); assert(localizedFontWeightOverride != reserved);
@ -554,12 +554,12 @@ unordered_map<wstring, wstring> LocalizationService::GetTokenToReadableNameMap()
unordered_map<wstring, wstring> tokenToReadableNameMap{}; unordered_map<wstring, wstring> tokenToReadableNameMap{};
auto resProvider = AppResourceProvider::GetInstance(); auto resProvider = AppResourceProvider::GetInstance();
static const wstring openParen = resProvider->GetCEngineString(StringReference(s_openParenResourceKey))->Data(); static const wstring openParen = resProvider.GetCEngineString(StringReference(s_openParenResourceKey))->Data();
for (const auto& keyPair : s_parenEngineKeyResourceMap) for (const auto& keyPair : s_parenEngineKeyResourceMap)
{ {
wstring engineStr = resProvider->GetCEngineString(StringReference(keyPair.first.c_str()))->Data(); wstring engineStr = resProvider.GetCEngineString(StringReference(keyPair.first.c_str()))->Data();
wstring automationName = resProvider->GetResourceString(StringReference(keyPair.second.c_str()))->Data(); wstring automationName = resProvider.GetResourceString(StringReference(keyPair.second.c_str()))->Data();
tokenToReadableNameMap.emplace(engineStr + openParen, automationName); tokenToReadableNameMap.emplace(engineStr + openParen, automationName);
} }
@ -567,15 +567,15 @@ unordered_map<wstring, wstring> LocalizationService::GetTokenToReadableNameMap()
for (const auto& keyPair : s_noParenEngineKeyResourceMap) for (const auto& keyPair : s_noParenEngineKeyResourceMap)
{ {
wstring engineStr = resProvider->GetCEngineString(StringReference(keyPair.first.c_str()))->Data(); wstring engineStr = resProvider.GetCEngineString(StringReference(keyPair.first.c_str()))->Data();
wstring automationName = resProvider->GetResourceString(StringReference(keyPair.second.c_str()))->Data(); wstring automationName = resProvider.GetResourceString(StringReference(keyPair.second.c_str()))->Data();
tokenToReadableNameMap.emplace(engineStr, automationName); tokenToReadableNameMap.emplace(engineStr, automationName);
} }
s_noParenEngineKeyResourceMap.clear(); s_noParenEngineKeyResourceMap.clear();
// Also replace hyphens with "minus" // Also replace hyphens with "minus"
wstring minusText = resProvider->GetResourceString(L"minus")->Data(); wstring minusText = resProvider.GetResourceString(L"minus")->Data();
tokenToReadableNameMap.emplace(L"-", minusText); tokenToReadableNameMap.emplace(L"-", minusText);
return tokenToReadableNameMap; return tokenToReadableNameMap;
@ -592,7 +592,7 @@ String ^ LocalizationService::GetNarratorReadableToken(String ^ rawToken)
} }
else else
{ {
static const String ^ openParen = AppResourceProvider::GetInstance()->GetCEngineString(StringReference(s_openParenResourceKey)); static const String ^ openParen = AppResourceProvider::GetInstance().GetCEngineString(StringReference(s_openParenResourceKey));
return ref new String(itr->second.c_str()) + L" " + openParen; return ref new String(itr->second.c_str()) + L" " + openParen;
} }
} }

View File

@ -58,11 +58,10 @@ namespace CalculatorApp
Windows::Globalization::NumberFormatting::DecimalFormatter ^ GetRegionalSettingsAwareDecimalFormatter() const; Windows::Globalization::NumberFormatting::DecimalFormatter ^ GetRegionalSettingsAwareDecimalFormatter() const;
Windows::Globalization::DateTimeFormatting::DateTimeFormatter ^ GetRegionalSettingsAwareDateTimeFormatter(_In_ Platform::String ^ format) const; Windows::Globalization::DateTimeFormatting::DateTimeFormatter ^ GetRegionalSettingsAwareDateTimeFormatter(_In_ Platform::String ^ format) const;
Windows::Globalization::DateTimeFormatting::DateTimeFormatter Windows::Globalization::DateTimeFormatting::DateTimeFormatter ^ GetRegionalSettingsAwareDateTimeFormatter(
^ GetRegionalSettingsAwareDateTimeFormatter( _In_ Platform::String ^ format,
_In_ Platform::String ^ format, _In_ Platform::String ^ calendarIdentifier,
_In_ Platform::String ^ calendarIdentifier, _In_ Platform::String ^ clockIdentifier) const;
_In_ Platform::String ^ clockIdentifier) const;
Windows::Globalization::NumberFormatting::CurrencyFormatter ^ GetRegionalSettingsAwareCurrencyFormatter() const; Windows::Globalization::NumberFormatting::CurrencyFormatter ^ GetRegionalSettingsAwareCurrencyFormatter() const;

View File

@ -169,21 +169,20 @@ namespace CalculatorApp
} }
} }
Platform::String ^ GetEnglishValueFromLocalizedDigits(Platform::String ^ localizedString) const Platform::String ^ GetEnglishValueFromLocalizedDigits(const std::wstring& localizedString) const
{ {
if (m_resolvedName == L"en-US") if (m_resolvedName == L"en-US")
{ {
return localizedString; return ref new Platform::String(localizedString.c_str());
} }
size_t i = 0; size_t i = 0;
auto localizedStringData = localizedString->Data(); size_t length = localizedString.size();
size_t length = localizedString->Length();
std::unique_ptr<wchar_t[]> englishString(new wchar_t[length + 1]); // +1 for the null termination std::unique_ptr<wchar_t[]> englishString(new wchar_t[length + 1]); // +1 for the null termination
for (; i < length; ++i) for (; i < length; ++i)
{ {
wchar_t ch = localizedStringData[i]; wchar_t ch = localizedString[i];
if (!IsEnUsDigit(ch)) if (!IsEnUsDigit(ch))
{ {
for (int j = 0; j < 10; ++j) for (int j = 0; j < 10; ++j)
@ -282,17 +281,18 @@ namespace CalculatorApp
return m_numberGrouping; return m_numberGrouping;
} }
Platform::String ^ RemoveGroupSeparators(Platform::String ^ source) const void RemoveGroupSeparators(const wchar_t* value, const size_t length, std::wstring* rawValue) const
{ {
std::wstringstream stream; rawValue->clear();
for (auto c = source->Begin(); c < source->End(); ++c) rawValue->reserve(length);
for (size_t i = 0; i < length; i++)
{ {
if (*c != L' ' && *c != m_numberGroupSeparator) if (value[i] != L' ' && value[i] != m_numberGroupSeparator)
{ {
stream << *c; rawValue->append(1, value[i]);
} }
} }
return ref new Platform::String(stream.str().c_str());
} }
Platform::String ^ GetCalendarIdentifier() const Platform::String ^ GetCalendarIdentifier() const

View File

@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved. // Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. // Licensed under the MIT License.
#pragma once #pragma once
@ -9,88 +9,50 @@ namespace CalculatorApp
{ {
namespace Common namespace Common
{ {
class LocalizationStringUtilInternal class LocalizationStringUtil
{ {
public: public:
static Platform::String ^ GetLocalizedString(Platform::String ^ pMessage, ...) static std::wstring GetLocalizedString(const wchar_t* pMessage, ...)
{ {
std::wstring returnString = L""; std::wstring returnString = L"";
const UINT32 length = 1024; const UINT32 length = 1024;
std::unique_ptr<wchar_t[]> spBuffer = std::unique_ptr<wchar_t[]>(new wchar_t[length]); std::unique_ptr<wchar_t[]> spBuffer = std::unique_ptr<wchar_t[]>(new wchar_t[length]);
va_list args = NULL; va_list args = NULL;
va_start(args, pMessage); va_start(args, pMessage);
DWORD fmtReturnVal = FormatMessage(FORMAT_MESSAGE_FROM_STRING, pMessage->Data(), 0, 0, spBuffer.get(), length, &args); DWORD fmtReturnVal = FormatMessage(FORMAT_MESSAGE_FROM_STRING, pMessage, 0, 0, spBuffer.get(), length, &args);
va_end(args); va_end(args);
if (fmtReturnVal != 0) if (fmtReturnVal != 0)
{ {
return ref new Platform::String(spBuffer.get()); returnString = spBuffer.get();
}
else
{
return ref new Platform::String();
} }
return returnString;
} }
};
public template <typename... T>
ref class LocalizationStringUtil sealed static Platform::String^ GetLocalizedNarratorAnnouncement(Platform::String^ resourceKey, Platform::String^& formatVariable, T*... params)
{ {
public: EnsureInitialization(resourceKey, formatVariable);
static Platform::String return StringReference(GetLocalizedString(formatVariable->Data(), params...).c_str());
^ GetLocalizedString(Platform::String ^ pMessage) }
private:
static void EnsureInitialization(Platform::String^ resourceKey, Platform::String^& formatVariable)
{
if (resourceKey == nullptr || resourceKey->IsEmpty())
{ {
return LocalizationStringUtilInternal::GetLocalizedString(pMessage); return;
} }
static Platform::String // If the formatVariable already has a value, we don't need to set it again. Simply return.
^ GetLocalizedString( if (formatVariable != nullptr && !formatVariable->IsEmpty())
Platform::String ^ pMessage,
Platform::String ^ param1)
{ {
return LocalizationStringUtilInternal::GetLocalizedString(pMessage, param1->Data()); return;
} }
static Platform::String formatVariable = AppResourceProvider::GetInstance().GetResourceString(resourceKey);
^ GetLocalizedString( }
Platform::String ^ pMessage,
Platform::String ^ param1,
Platform::String ^ param2)
{
return LocalizationStringUtilInternal::GetLocalizedString(pMessage, param1->Data(), param2->Data());
}
static Platform::String
^ GetLocalizedString(
Platform::String ^ pMessage,
Platform::String ^ param1,
Platform::String ^ param2,
Platform::String
^ param3)
{
return LocalizationStringUtilInternal::GetLocalizedString(pMessage, param1->Data(), param2->Data(), param3->Data());
}
static Platform::String
^ GetLocalizedString(
Platform::String ^ pMessage,
Platform::String ^ param1,
Platform::String ^ param2,
Platform::String ^ param3,
Platform::String ^ param4)
{
return LocalizationStringUtilInternal::GetLocalizedString(pMessage, param1->Data(), param2->Data(), param3->Data(), param4->Data());
}
static Platform::String
^ GetResourceValue(Platform::String ^ resourceKey) {
if (resourceKey == nullptr || resourceKey->IsEmpty())
{
return L"";
}
return AppResourceProvider::GetInstance()->GetResourceString(resourceKey);
}
}; };
} }
} }

View File

@ -368,28 +368,33 @@ NavCategoryGroup::NavCategoryGroup(const NavCategoryGroupInitializer& groupIniti
m_GroupType = groupInitializer.type; m_GroupType = groupInitializer.type;
auto resProvider = AppResourceProvider::GetInstance(); auto resProvider = AppResourceProvider::GetInstance();
m_Name = resProvider->GetResourceString(StringReference(groupInitializer.headerResourceKey)); String ^ headerResourceKey = StringReference(groupInitializer.headerResourceKey);
String ^ groupMode = resProvider->GetResourceString(StringReference(groupInitializer.modeResourceKey)); String ^ modeResourceKey = StringReference(groupInitializer.modeResourceKey);
String ^ automationName = resProvider->GetResourceString(StringReference(groupInitializer.automationResourceKey)); String ^ automationResourceKey = StringReference(groupInitializer.automationResourceKey);
m_Name = resProvider.GetResourceString(headerResourceKey);
String ^ groupMode = resProvider.GetResourceString(modeResourceKey);
String ^ automationName = resProvider.GetResourceString(automationResourceKey);
String ^ navCategoryHeaderAutomationNameFormat = resProvider->GetResourceString(L"NavCategoryHeader_AutomationNameFormat"); String ^ navCategoryHeaderAutomationNameFormat = resProvider.GetResourceString(L"NavCategoryHeader_AutomationNameFormat");
m_AutomationName = LocalizationStringUtil::GetLocalizedString(navCategoryHeaderAutomationNameFormat, automationName); m_AutomationName =
ref new String(LocalizationStringUtil::GetLocalizedString(navCategoryHeaderAutomationNameFormat->Data(), automationName->Data()).c_str());
String ^ navCategoryItemAutomationNameFormat = resProvider->GetResourceString(L"NavCategoryItem_AutomationNameFormat"); String ^ navCategoryItemAutomationNameFormat = resProvider.GetResourceString(L"NavCategoryItem_AutomationNameFormat");
for (const NavCategoryInitializer& categoryInitializer : s_categoryManifest) for (const NavCategoryInitializer& categoryInitializer : s_categoryManifest)
{ {
if (categoryInitializer.groupType == groupInitializer.type) if (categoryInitializer.groupType == groupInitializer.type)
{ {
String ^ nameResourceKey = StringReference(categoryInitializer.nameResourceKey); String ^ nameResourceKey = StringReference(categoryInitializer.nameResourceKey);
String ^ categoryName = resProvider->GetResourceString(nameResourceKey + "Text"); String ^ categoryName = resProvider.GetResourceString(nameResourceKey + "Text");
String ^ categoryAutomationName = LocalizationStringUtil::GetLocalizedString(navCategoryItemAutomationNameFormat, categoryName, m_Name); String ^ categoryAutomationName = ref new String(
LocalizationStringUtil::GetLocalizedString(navCategoryItemAutomationNameFormat->Data(), categoryName->Data(), m_Name->Data()).c_str());
m_Categories->Append(ref new NavCategory( m_Categories->Append(ref new NavCategory(
categoryName, categoryName,
categoryAutomationName, categoryAutomationName,
StringReference(categoryInitializer.glyph), StringReference(categoryInitializer.glyph),
resProvider->GetResourceString(nameResourceKey + "AccessKey"), resProvider.GetResourceString(nameResourceKey + "AccessKey"),
groupMode, groupMode,
categoryInitializer.viewMode, categoryInitializer.viewMode,
categoryInitializer.supportsNegative)); categoryInitializer.supportsNegative));

View File

@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved. // Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. // Licensed under the MIT License.
#include "pch.h" #include "pch.h"
@ -132,8 +132,8 @@ CurrencyDataLoader::CurrencyDataLoader(_In_ unique_ptr<ICurrencyHttpClient> clie
m_ratioFormatter->IsDecimalPointAlwaysDisplayed = true; m_ratioFormatter->IsDecimalPointAlwaysDisplayed = true;
m_ratioFormatter->FractionDigits = FORMATTER_RATE_FRACTION_PADDING; m_ratioFormatter->FractionDigits = FORMATTER_RATE_FRACTION_PADDING;
m_ratioFormat = AppResourceProvider::GetInstance()->GetResourceString(L"CurrencyFromToRatioFormat"); m_ratioFormat = AppResourceProvider::GetInstance().GetResourceString(L"CurrencyFromToRatioFormat")->Data();
m_timestampFormat = AppResourceProvider::GetInstance()->GetResourceString(L"CurrencyTimestampFormat"); m_timestampFormat = AppResourceProvider::GetInstance().GetResourceString(L"CurrencyTimestampFormat")->Data();
} }
CurrencyDataLoader::~CurrencyDataLoader() CurrencyDataLoader::~CurrencyDataLoader()
@ -300,18 +300,16 @@ pair<wstring, wstring> CurrencyDataLoader::GetCurrencyRatioEquality(_In_ const U
double ratio = (iter2->second).ratio; double ratio = (iter2->second).ratio;
double rounded = RoundCurrencyRatio(ratio); double rounded = RoundCurrencyRatio(ratio);
auto digit = LocalizationSettings::GetInstance().GetDigitSymbolFromEnUsDigit(L'1'); wstring digitSymbol = wstring{ LocalizationSettings::GetInstance().GetDigitSymbolFromEnUsDigit(L'1') };
auto digitSymbol = ref new String(&digit, 1); wstring roundedFormat = m_ratioFormatter->Format(rounded)->Data();
auto roundedFormat = m_ratioFormatter->Format(rounded);
auto ratioString = LocalizationStringUtil::GetLocalizedString( wstring ratioString = LocalizationStringUtil::GetLocalizedString(
m_ratioFormat, digitSymbol, StringReference(unit1.abbreviation.c_str()), roundedFormat, StringReference(unit2.abbreviation.c_str())); m_ratioFormat.c_str(), digitSymbol.c_str(), unit1.abbreviation.c_str(), roundedFormat.c_str(), unit2.abbreviation.c_str());
auto accessibleRatioString = wstring accessibleRatioString = LocalizationStringUtil::GetLocalizedString(
LocalizationStringUtil::GetLocalizedString( m_ratioFormat.c_str(), digitSymbol.c_str(), unit1.accessibleName.c_str(), roundedFormat.c_str(), unit2.accessibleName.c_str());
m_ratioFormat, digitSymbol, StringReference(unit1.accessibleName.c_str()), roundedFormat, StringReference(unit2.accessibleName.c_str()));
return make_pair(ratioString->Data(), accessibleRatioString->Data()); return make_pair(ratioString, accessibleRatioString);
} }
} }
} }
@ -749,19 +747,21 @@ void CurrencyDataLoader::UpdateDisplayedTimestamp()
} }
wstring CurrencyDataLoader::GetCurrencyTimestamp() wstring CurrencyDataLoader::GetCurrencyTimestamp()
{ {
wstring timestamp = L"";
DateTime epoch{}; DateTime epoch{};
if (m_cacheTimestamp.UniversalTime != epoch.UniversalTime) if (m_cacheTimestamp.UniversalTime != epoch.UniversalTime)
{ {
DateTimeFormatter ^ dateFormatter = ref new DateTimeFormatter(L"shortdate"); DateTimeFormatter ^ dateFormatter = ref new DateTimeFormatter(L"shortdate");
auto date = dateFormatter->Format(m_cacheTimestamp); wstring date = dateFormatter->Format(m_cacheTimestamp)->Data();
DateTimeFormatter ^ timeFormatter = ref new DateTimeFormatter(L"shorttime"); DateTimeFormatter ^ timeFormatter = ref new DateTimeFormatter(L"shorttime");
auto time = timeFormatter->Format(m_cacheTimestamp); wstring time = timeFormatter->Format(m_cacheTimestamp)->Data();
return LocalizationStringUtil::GetLocalizedString(m_timestampFormat, date, time)->Data(); timestamp = LocalizationStringUtil::GetLocalizedString(m_timestampFormat.c_str(), date.c_str(), time.c_str());
} }
return L""; return timestamp;
} }
#pragma optimize("", off) // Turn off optimizations to work around DevDiv 393321 #pragma optimize("", off) // Turn off optimizations to work around DevDiv 393321

View File

@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved. // Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. // Licensed under the MIT License.
#pragma once #pragma once
@ -124,9 +124,9 @@ namespace CalculatorApp
std::shared_ptr<UCM::IViewModelCurrencyCallback> m_vmCallback; std::shared_ptr<UCM::IViewModelCurrencyCallback> m_vmCallback;
Windows::Globalization::NumberFormatting::DecimalFormatter ^ m_ratioFormatter; Windows::Globalization::NumberFormatting::DecimalFormatter ^ m_ratioFormatter;
Platform::String ^ m_ratioFormat; std::wstring m_ratioFormat;
Windows::Foundation::DateTime m_cacheTimestamp; Windows::Foundation::DateTime m_cacheTimestamp;
Platform::String ^ m_timestampFormat; std::wstring m_timestampFormat;
CurrencyLoadStatus m_loadStatus; CurrencyLoadStatus m_loadStatus;

View File

@ -953,7 +953,7 @@ void UnitConverterDataLoader::GetConversionData(_In_ unordered_map<ViewMode, uno
wstring UnitConverterDataLoader::GetLocalizedStringName(String ^ stringId) wstring UnitConverterDataLoader::GetLocalizedStringName(String ^ stringId)
{ {
return AppResourceProvider::GetInstance()->GetResourceString(stringId)->Data(); return AppResourceProvider::GetInstance().GetResourceString(stringId)->Data();
} }
void UnitConverterDataLoader::GetExplicitConversionData(_In_ unordered_map<int, unordered_map<int, UCM::ConversionData>>& unitToUnitConversionList) void UnitConverterDataLoader::GetExplicitConversionData(_In_ unordered_map<int, unordered_map<int, UCM::ConversionData>>& unitToUnitConversionList)

View File

@ -172,14 +172,14 @@ void DateCalculatorViewModel::UpdateDisplayResult()
{ {
IsDiffInDays = false; IsDiffInDays = false;
StrDateDiffResultInDays = L""; StrDateDiffResultInDays = L"";
StrDateDiffResult = AppResourceProvider::GetInstance()->GetResourceString(L"CalculationFailed"); StrDateDiffResult = AppResourceProvider::GetInstance().GetResourceString(L"CalculationFailed");
} }
else if (m_dateDiffResultInDays.day == 0) else if (m_dateDiffResultInDays.day == 0)
{ {
// to and from dates the same // to and from dates the same
IsDiffInDays = true; IsDiffInDays = true;
StrDateDiffResultInDays = L""; StrDateDiffResultInDays = L"";
StrDateDiffResult = AppResourceProvider::GetInstance()->GetResourceString(L"Date_SameDates"); StrDateDiffResult = AppResourceProvider::GetInstance().GetResourceString(L"Date_SameDates");
} }
else if (m_dateDiffResult == DateDifferenceUnknown || else if (m_dateDiffResult == DateDifferenceUnknown ||
(m_dateDiffResult.year == 0 && m_dateDiffResult.month == 0 && m_dateDiffResult.week == 0)) (m_dateDiffResult.year == 0 && m_dateDiffResult.month == 0 && m_dateDiffResult.week == 0))
@ -206,7 +206,7 @@ void DateCalculatorViewModel::UpdateDisplayResult()
if (m_isOutOfBound) if (m_isOutOfBound)
{ {
// Display Date out of bound message // Display Date out of bound message
StrDateResult = AppResourceProvider::GetInstance()->GetResourceString(L"Date_OutOfBoundMessage"); StrDateResult = AppResourceProvider::GetInstance().GetResourceString(L"Date_OutOfBoundMessage");
} }
else else
{ {
@ -218,14 +218,16 @@ void DateCalculatorViewModel::UpdateDisplayResult()
void DateCalculatorViewModel::UpdateStrDateDiffResultAutomationName() void DateCalculatorViewModel::UpdateStrDateDiffResultAutomationName()
{ {
String ^ automationFormat = AppResourceProvider::GetInstance()->GetResourceString(L"Date_DifferenceResultAutomationName"); String ^ automationFormat = AppResourceProvider::GetInstance().GetResourceString(L"Date_DifferenceResultAutomationName");
StrDateDiffResultAutomationName = LocalizationStringUtil::GetLocalizedString(automationFormat, StrDateDiffResult); wstring localizedAutomationName = LocalizationStringUtil::GetLocalizedString(automationFormat->Data(), StrDateDiffResult->Data());
StrDateDiffResultAutomationName = ref new String(localizedAutomationName.c_str());
} }
void DateCalculatorViewModel::UpdateStrDateResultAutomationName() void DateCalculatorViewModel::UpdateStrDateResultAutomationName()
{ {
String ^ automationFormat = AppResourceProvider::GetInstance()->GetResourceString(L"Date_ResultingDateAutomationName"); String ^ automationFormat = AppResourceProvider::GetInstance().GetResourceString(L"Date_ResultingDateAutomationName");
StrDateResultAutomationName = LocalizationStringUtil::GetLocalizedString(automationFormat, StrDateResult); wstring localizedAutomationName = LocalizationStringUtil::GetLocalizedString(automationFormat->Data(), StrDateResult->Data());
StrDateResultAutomationName = ref new String(localizedAutomationName.c_str());
} }
void DateCalculatorViewModel::InitializeDateOutputFormats(_In_ String ^ calendarIdentifier) void DateCalculatorViewModel::InitializeDateOutputFormats(_In_ String ^ calendarIdentifier)
@ -245,7 +247,7 @@ String ^ DateCalculatorViewModel::GetDateDiffString() const
{ {
wstring result; wstring result;
bool addDelimiter = false; bool addDelimiter = false;
AppResourceProvider ^ resourceLoader = AppResourceProvider::GetInstance(); AppResourceProvider resourceLoader = AppResourceProvider::GetInstance();
auto yearCount = m_dateDiffResult.year; auto yearCount = m_dateDiffResult.year;
if (yearCount > 0) if (yearCount > 0)
@ -255,11 +257,11 @@ String ^ DateCalculatorViewModel::GetDateDiffString() const
if (yearCount > 1) if (yearCount > 1)
{ {
result += resourceLoader->GetResourceString(L"Date_Years")->Data(); result += resourceLoader.GetResourceString(L"Date_Years")->Data();
} }
else else
{ {
result += resourceLoader->GetResourceString(L"Date_Year")->Data(); result += resourceLoader.GetResourceString(L"Date_Year")->Data();
} }
// set the flags to add a delimiter whenever the next unit is added // set the flags to add a delimiter whenever the next unit is added
@ -283,11 +285,11 @@ String ^ DateCalculatorViewModel::GetDateDiffString() const
if (monthCount > 1) if (monthCount > 1)
{ {
result += resourceLoader->GetResourceString(L"Date_Months")->Data(); result += resourceLoader.GetResourceString(L"Date_Months")->Data();
} }
else else
{ {
result += resourceLoader->GetResourceString(L"Date_Month")->Data(); result += resourceLoader.GetResourceString(L"Date_Month")->Data();
} }
} }
@ -308,11 +310,11 @@ String ^ DateCalculatorViewModel::GetDateDiffString() const
if (weekCount > 1) if (weekCount > 1)
{ {
result += resourceLoader->GetResourceString(L"Date_Weeks")->Data(); result += resourceLoader.GetResourceString(L"Date_Weeks")->Data();
} }
else else
{ {
result += resourceLoader->GetResourceString(L"Date_Week")->Data(); result += resourceLoader.GetResourceString(L"Date_Week")->Data();
} }
} }
@ -333,11 +335,11 @@ String ^ DateCalculatorViewModel::GetDateDiffString() const
if (dayCount > 1) if (dayCount > 1)
{ {
result += resourceLoader->GetResourceString(L"Date_Days")->Data(); result += resourceLoader.GetResourceString(L"Date_Days")->Data();
} }
else else
{ {
result += resourceLoader->GetResourceString(L"Date_Day")->Data(); result += resourceLoader.GetResourceString(L"Date_Day")->Data();
} }
} }
@ -352,11 +354,11 @@ String ^ DateCalculatorViewModel::GetDateDiffStringInDays() const
// Display the result as '1 day' or 'N days' // Display the result as '1 day' or 'N days'
if (m_dateDiffResultInDays.day > 1) if (m_dateDiffResultInDays.day > 1)
{ {
result += AppResourceProvider::GetInstance()->GetResourceString(L"Date_Days")->Data(); result += AppResourceProvider::GetInstance().GetResourceString(L"Date_Days")->Data();
} }
else else
{ {
result += AppResourceProvider::GetInstance()->GetResourceString(L"Date_Day")->Data(); result += AppResourceProvider::GetInstance().GetResourceString(L"Date_Day")->Data();
} }
return ref new String(result.data()); return ref new String(result.data());

View File

@ -371,10 +371,9 @@ void HistoryViewModel::UpdateItemSize()
ItemSize = Items->Size; ItemSize = Items->Size;
} }
Platform::String ^ HistoryViewModel::MakeHistoryClearedNarratorAnnouncement(String ^ resourceKey, String ^ formatVariable) void HistoryViewModel::MakeHistoryClearedNarratorAnnouncement(String ^ resourceKey, String ^ &formatVariable)
{ {
String ^ announcement = LocalizationStringUtil::GetLocalizedString(LocalizationStringUtil::GetResourceValue(resourceKey), formatVariable); String ^ announcement = LocalizationStringUtil::GetLocalizedNarratorAnnouncement(resourceKey, formatVariable);
HistoryAnnouncement = CalculatorAnnouncement::GetHistoryClearedAnnouncement(announcement); HistoryAnnouncement = CalculatorAnnouncement::GetHistoryClearedAnnouncement(announcement);
return announcement;
} }

View File

@ -68,7 +68,7 @@ namespace CalculatorApp
void UpdateHistoryVectorLength(_In_ int newValue, _In_ CalculationManager::CALCULATOR_MODE cMode); void UpdateHistoryVectorLength(_In_ int newValue, _In_ CalculationManager::CALCULATOR_MODE cMode);
bool IsValid(_In_ CalculationManager::HISTORYITEM item); bool IsValid(_In_ CalculationManager::HISTORYITEM item);
Platform::String ^ MakeHistoryClearedNarratorAnnouncement(Platform::String ^ resourceKey, Platform::String ^ formatVariable); void MakeHistoryClearedNarratorAnnouncement(Platform::String ^ resourceKey, Platform::String ^ &formatVariable);
friend class CalculatorDisplay; friend class CalculatorDisplay;
void UpdateItemSize(); void UpdateItemSize();

View File

@ -25,7 +25,6 @@ using namespace Windows::UI::Popups;
using namespace Windows::Storage::Streams; using namespace Windows::Storage::Streams;
using namespace Windows::Foundation::Collections; using namespace Windows::Foundation::Collections;
using namespace Utils; using namespace Utils;
using namespace concurrency;
constexpr int StandardModePrecision = 16; constexpr int StandardModePrecision = 16;
constexpr int ScientificModePrecision = 32; constexpr int ScientificModePrecision = 32;
@ -94,16 +93,15 @@ StandardCalculatorViewModel::StandardCalculatorViewModel()
, m_localizedNoRightParenthesisAddedFormat(nullptr) , m_localizedNoRightParenthesisAddedFormat(nullptr)
{ {
WeakReference calculatorViewModel(this); WeakReference calculatorViewModel(this);
auto appResourceProvider = AppResourceProvider::GetInstance();
m_calculatorDisplay.SetCallback(calculatorViewModel); m_calculatorDisplay.SetCallback(calculatorViewModel);
m_expressionAutomationNameFormat = appResourceProvider->GetResourceString(CalculatorResourceKeys::CalculatorExpression); m_expressionAutomationNameFormat = AppResourceProvider::GetInstance().GetResourceString(CalculatorResourceKeys::CalculatorExpression);
m_localizedCalculationResultAutomationFormat = appResourceProvider->GetResourceString(CalculatorResourceKeys::CalculatorResults); m_localizedCalculationResultAutomationFormat = AppResourceProvider::GetInstance().GetResourceString(CalculatorResourceKeys::CalculatorResults);
m_localizedCalculationResultDecimalAutomationFormat = m_localizedCalculationResultDecimalAutomationFormat =
appResourceProvider->GetResourceString(CalculatorResourceKeys::CalculatorResults_DecimalSeparator_Announced); AppResourceProvider::GetInstance().GetResourceString(CalculatorResourceKeys::CalculatorResults_DecimalSeparator_Announced);
m_localizedHexaDecimalAutomationFormat = appResourceProvider->GetResourceString(CalculatorResourceKeys::HexButton); m_localizedHexaDecimalAutomationFormat = AppResourceProvider::GetInstance().GetResourceString(CalculatorResourceKeys::HexButton);
m_localizedDecimalAutomationFormat = appResourceProvider->GetResourceString(CalculatorResourceKeys::DecButton); m_localizedDecimalAutomationFormat = AppResourceProvider::GetInstance().GetResourceString(CalculatorResourceKeys::DecButton);
m_localizedOctalAutomationFormat = appResourceProvider->GetResourceString(CalculatorResourceKeys::OctButton); m_localizedOctalAutomationFormat = AppResourceProvider::GetInstance().GetResourceString(CalculatorResourceKeys::OctButton);
m_localizedBinaryAutomationFormat = appResourceProvider->GetResourceString(CalculatorResourceKeys::BinButton); m_localizedBinaryAutomationFormat = AppResourceProvider::GetInstance().GetResourceString(CalculatorResourceKeys::BinButton);
// Initialize the Automation Name // Initialize the Automation Name
CalculationResultAutomationName = GetLocalizedStringFormat(m_localizedCalculationResultAutomationFormat, m_DisplayValue); CalculationResultAutomationName = GetLocalizedStringFormat(m_localizedCalculationResultAutomationFormat, m_DisplayValue);
@ -194,13 +192,13 @@ String ^ StandardCalculatorViewModel::GetNarratorStringReadRawNumbers(_In_ Strin
return ref new String(wss.str().c_str()); return ref new String(wss.str().c_str());
} }
void StandardCalculatorViewModel::SetPrimaryDisplay(_In_ String ^ displayStringValue, _In_ bool isError) void StandardCalculatorViewModel::SetPrimaryDisplay(_In_ wstring const& displayStringValue, _In_ bool isError)
{ {
String ^ localizedDisplayStringValue = LocalizeDisplayValue(displayStringValue->Data(), isError); String ^ localizedDisplayStringValue = LocalizeDisplayValue(displayStringValue, isError);
// Set this variable before the DisplayValue is modified, Otherwise the DisplayValue will // Set this variable before the DisplayValue is modified, Otherwise the DisplayValue will
// not match what the narrator is saying // not match what the narrator is saying
m_CalculationResultAutomationName = CalculateNarratorDisplayValue(displayStringValue->Data(), localizedDisplayStringValue, isError); m_CalculationResultAutomationName = CalculateNarratorDisplayValue(displayStringValue, localizedDisplayStringValue, isError);
AreAlwaysOnTopResultsUpdated = false; AreAlwaysOnTopResultsUpdated = false;
if (DisplayValue != localizedDisplayStringValue) if (DisplayValue != localizedDisplayStringValue)
@ -241,10 +239,10 @@ void StandardCalculatorViewModel::SetOpenParenthesisCountNarratorAnnouncement()
wstring localizedParenthesisCount = to_wstring(m_OpenParenthesisCount).c_str(); wstring localizedParenthesisCount = to_wstring(m_OpenParenthesisCount).c_str();
LocalizationSettings::GetInstance().LocalizeDisplayValue(&localizedParenthesisCount); LocalizationSettings::GetInstance().LocalizeDisplayValue(&localizedParenthesisCount);
String ^ announcement = LocalizationStringUtil::GetLocalizedString( String ^ announcement = LocalizationStringUtil::GetLocalizedNarratorAnnouncement(
LocalizationStringUtil::GetResourceValue(CalculatorResourceKeys::OpenParenthesisCountAutomationFormat), CalculatorResourceKeys::OpenParenthesisCountAutomationFormat,
m_localizedOpenParenthesisCountChangedAutomationFormat, m_localizedOpenParenthesisCountChangedAutomationFormat,
StringReference(localizedParenthesisCount.c_str())); localizedParenthesisCount.c_str());
Announcement = CalculatorAnnouncement::GetOpenParenthesisCountChangedAnnouncement(announcement); Announcement = CalculatorAnnouncement::GetOpenParenthesisCountChangedAnnouncement(announcement);
} }
@ -257,7 +255,7 @@ void StandardCalculatorViewModel::OnNoRightParenAdded()
void StandardCalculatorViewModel::SetNoParenAddedNarratorAnnouncement() void StandardCalculatorViewModel::SetNoParenAddedNarratorAnnouncement()
{ {
String ^ announcement = String ^ announcement =
LocalizationStringUtil::GetLocalizedString(LocalizationStringUtil::GetResourceValue(CalculatorResourceKeys::NoParenthesisAdded), m_localizedNoRightParenthesisAddedFormat); LocalizationStringUtil::GetLocalizedNarratorAnnouncement(CalculatorResourceKeys::NoParenthesisAdded, m_localizedNoRightParenthesisAddedFormat);
Announcement = CalculatorAnnouncement::GetNoRightParenthesisAddedAnnouncement(announcement); Announcement = CalculatorAnnouncement::GetNoRightParenthesisAddedAnnouncement(announcement);
} }
@ -354,7 +352,7 @@ void StandardCalculatorViewModel::SetTokens(_Inout_ shared_ptr<vector<pair<wstri
type = command->GetCommandType() == CommandType::OperandCommand ? TokenType::Operand : TokenType::Operator; type = command->GetCommandType() == CommandType::OperandCommand ? TokenType::Operand : TokenType::Operator;
} }
auto currentTokenString = StringReference(currentToken.first.c_str()); auto currentTokenString = ref new String(currentToken.first.c_str());
if (i < m_ExpressionTokens->Size) if (i < m_ExpressionTokens->Size)
{ {
auto existingItem = m_ExpressionTokens->GetAt(i); auto existingItem = m_ExpressionTokens->GetAt(i);
@ -698,7 +696,7 @@ void StandardCalculatorViewModel::OnCopyCommand(Object ^ parameter)
{ {
CopyPasteManager::CopyToClipboard(GetRawDisplayValue()); CopyPasteManager::CopyToClipboard(GetRawDisplayValue());
String ^ announcement = AppResourceProvider::GetInstance()->GetResourceString(CalculatorResourceKeys::DisplayCopied); String ^ announcement = AppResourceProvider::GetInstance().GetResourceString(CalculatorResourceKeys::DisplayCopied);
Announcement = CalculatorAnnouncement::GetDisplayCopiedAnnouncement(announcement); Announcement = CalculatorAnnouncement::GetDisplayCopiedAnnouncement(announcement);
} }
@ -729,7 +727,7 @@ void StandardCalculatorViewModel::OnPasteCommand(Object ^ parameter)
} }
// Ensure that the paste happens on the UI thread // Ensure that the paste happens on the UI thread
create_task(CopyPasteManager::GetStringToPaste(mode, NavCategory::GetGroupType(mode), NumberBase, bitLengthType)) CopyPasteManager::GetStringToPaste(mode, NavCategory::GetGroupType(mode), NumberBase, bitLengthType)
.then([that, mode](String ^ pastedString) { that->OnPaste(pastedString); }, concurrency::task_continuation_context::use_current()); .then([that, mode](String ^ pastedString) { that->OnPaste(pastedString); }, concurrency::task_continuation_context::use_current());
} }
@ -741,7 +739,7 @@ CalculationManager::Command StandardCalculatorViewModel::ConvertToOperatorsEnum(
void StandardCalculatorViewModel::OnPaste(String ^ pastedString) void StandardCalculatorViewModel::OnPaste(String ^ pastedString)
{ {
// If pastedString is invalid("NoOp") then display pasteError else process the string // If pastedString is invalid("NoOp") then display pasteError else process the string
if (CopyPasteManager::IsErrorMessage(pastedString)) if (pastedString == StringReference(CopyPasteManager::PasteErrorString))
{ {
this->DisplayPasteError(); this->DisplayPasteError();
return; return;
@ -895,7 +893,7 @@ void StandardCalculatorViewModel::OnClearMemoryCommand(Object ^ parameter)
TraceLogger::GetInstance().UpdateButtonUsage(NumbersAndOperatorsEnum::MemoryClear, GetCalculatorMode()); TraceLogger::GetInstance().UpdateButtonUsage(NumbersAndOperatorsEnum::MemoryClear, GetCalculatorMode());
String ^ announcement = LocalizationStringUtil::GetLocalizedString(LocalizationStringUtil::GetResourceValue(CalculatorResourceKeys::MemoryCleared), m_localizedMemoryCleared); String ^ announcement = LocalizationStringUtil::GetLocalizedNarratorAnnouncement(CalculatorResourceKeys::MemoryCleared, m_localizedMemoryCleared);
Announcement = CalculatorAnnouncement::GetMemoryClearedAnnouncement(announcement); Announcement = CalculatorAnnouncement::GetMemoryClearedAnnouncement(announcement);
} }
@ -1048,8 +1046,8 @@ void StandardCalculatorViewModel::OnMemoryButtonPressed()
TraceLogger::GetInstance().UpdateButtonUsage(NumbersAndOperatorsEnum::Memory, GetCalculatorMode()); TraceLogger::GetInstance().UpdateButtonUsage(NumbersAndOperatorsEnum::Memory, GetCalculatorMode());
String ^ announcement = LocalizationStringUtil::GetLocalizedString( String ^ announcement = LocalizationStringUtil::GetLocalizedNarratorAnnouncement(
LocalizationStringUtil::GetResourceValue(CalculatorResourceKeys::MemorySave), m_localizedMemorySavedAutomationFormat, m_DisplayValue); CalculatorResourceKeys::MemorySave, m_localizedMemorySavedAutomationFormat, m_DisplayValue->Data());
Announcement = CalculatorAnnouncement::GetMemoryItemAddedAnnouncement(announcement); Announcement = CalculatorAnnouncement::GetMemoryItemAddedAnnouncement(announcement);
} }
@ -1064,8 +1062,8 @@ void StandardCalculatorViewModel::OnMemoryItemChanged(unsigned int indexOfMemory
wstring localizedIndex = to_wstring(indexOfMemory + 1); wstring localizedIndex = to_wstring(indexOfMemory + 1);
LocalizationSettings::GetInstance().LocalizeDisplayValue(&localizedIndex); LocalizationSettings::GetInstance().LocalizeDisplayValue(&localizedIndex);
String ^ announcement = LocalizationStringUtil::GetLocalizedString( String ^ announcement = LocalizationStringUtil::GetLocalizedNarratorAnnouncement(
LocalizationStringUtil::GetResourceValue(CalculatorResourceKeys::MemoryItemChanged), m_localizedMemoryItemChangedAutomationFormat, StringReference(localizedIndex.c_str()), localizedValue); CalculatorResourceKeys::MemoryItemChanged, m_localizedMemoryItemChangedAutomationFormat, localizedIndex.c_str(), localizedValue->Data());
Announcement = CalculatorAnnouncement::GetMemoryItemChangedAnnouncement(announcement); Announcement = CalculatorAnnouncement::GetMemoryItemChangedAnnouncement(announcement);
} }
@ -1133,8 +1131,8 @@ void StandardCalculatorViewModel::OnMemoryClear(_In_ Object ^ memoryItemPosition
wstring localizedIndex = to_wstring(boxedPosition->Value + 1); wstring localizedIndex = to_wstring(boxedPosition->Value + 1);
LocalizationSettings::GetInstance().LocalizeDisplayValue(&localizedIndex); LocalizationSettings::GetInstance().LocalizeDisplayValue(&localizedIndex);
String ^ announcement = LocalizationStringUtil::GetLocalizedString( String ^ announcement = LocalizationStringUtil::GetLocalizedNarratorAnnouncement(
LocalizationStringUtil::GetResourceValue(CalculatorResourceKeys::MemoryItemCleared), m_localizedMemoryItemClearedAutomationFormat, StringReference(localizedIndex.c_str())); CalculatorResourceKeys::MemoryItemCleared, m_localizedMemoryItemClearedAutomationFormat, localizedIndex.c_str());
Announcement = CalculatorAnnouncement::GetMemoryClearedAnnouncement(announcement); Announcement = CalculatorAnnouncement::GetMemoryClearedAnnouncement(announcement);
} }
@ -1214,7 +1212,9 @@ String ^ StandardCalculatorViewModel::GetRawDisplayValue()
} }
else else
{ {
return LocalizationSettings::GetInstance().RemoveGroupSeparators(DisplayValue); wstring rawValue;
LocalizationSettings::GetInstance().RemoveGroupSeparators(DisplayValue->Data(), DisplayValue->Length(), &rawValue);
return ref new String(rawValue.c_str());
} }
} }
@ -1223,7 +1223,8 @@ String ^ StandardCalculatorViewModel::GetRawDisplayValue()
// 'displayValue' is a localized string containing a numerical value to be displayed to the user. // 'displayValue' is a localized string containing a numerical value to be displayed to the user.
String ^ StandardCalculatorViewModel::GetLocalizedStringFormat(String ^ format, String ^ displayValue) String ^ StandardCalculatorViewModel::GetLocalizedStringFormat(String ^ format, String ^ displayValue)
{ {
return LocalizationStringUtil::GetLocalizedString(format, displayValue); String ^ localizedString = ref new String(LocalizationStringUtil::GetLocalizedString(format->Data(), displayValue->Data()).c_str());
return localizedString;
} }
void StandardCalculatorViewModel::ResetDisplay() void StandardCalculatorViewModel::ResetDisplay()
@ -1584,7 +1585,7 @@ size_t StandardCalculatorViewModel::LengthWithoutPadding(wstring str)
wstring StandardCalculatorViewModel::AddPadding(wstring binaryString) wstring StandardCalculatorViewModel::AddPadding(wstring binaryString)
{ {
if (LocalizationSettings::GetInstance().GetEnglishValueFromLocalizedDigits(StringReference(binaryString.c_str())) == L"0") if (LocalizationSettings::GetInstance().GetEnglishValueFromLocalizedDigits(binaryString) == L"0")
{ {
return binaryString; return binaryString;
} }
@ -1683,7 +1684,7 @@ void StandardCalculatorViewModel::UpdateOperand(int pos, String ^ text)
{ {
pair<wstring, int> p = m_tokens->at(pos); pair<wstring, int> p = m_tokens->at(pos);
String ^ englishString = LocalizationSettings::GetInstance().GetEnglishValueFromLocalizedDigits(text); String ^ englishString = LocalizationSettings::GetInstance().GetEnglishValueFromLocalizedDigits(text->Data());
p.first = englishString->Data(); p.first = englishString->Data();
int commandPos = p.second; int commandPos = p.second;
@ -1807,8 +1808,8 @@ void StandardCalculatorViewModel::UpdatecommandsInRecordingMode()
void StandardCalculatorViewModel::OnMaxDigitsReached() void StandardCalculatorViewModel::OnMaxDigitsReached()
{ {
String ^ announcement = LocalizationStringUtil::GetLocalizedString( String ^ announcement = LocalizationStringUtil::GetLocalizedNarratorAnnouncement(
LocalizationStringUtil::GetResourceValue(CalculatorResourceKeys::MaxDigitsReachedFormat), m_localizedMaxDigitsReachedAutomationFormat, m_CalculationResultAutomationName); CalculatorResourceKeys::MaxDigitsReachedFormat, m_localizedMaxDigitsReachedAutomationFormat, m_CalculationResultAutomationName->Data());
Announcement = CalculatorAnnouncement::GetMaxDigitsReachedAnnouncement(announcement); Announcement = CalculatorAnnouncement::GetMaxDigitsReachedAnnouncement(announcement);
} }
@ -1827,11 +1828,11 @@ NarratorAnnouncement ^ StandardCalculatorViewModel::GetDisplayUpdatedNarratorAnn
} }
else else
{ {
announcement = LocalizationStringUtil::GetLocalizedString( announcement = LocalizationStringUtil::GetLocalizedNarratorAnnouncement(
LocalizationStringUtil::GetResourceValue(CalculatorResourceKeys::ButtonPressFeedbackFormat), CalculatorResourceKeys::ButtonPressFeedbackFormat,
m_localizedButtonPressFeedbackAutomationFormat, m_localizedButtonPressFeedbackAutomationFormat,
m_CalculationResultAutomationName, m_CalculationResultAutomationName->Data(),
m_feedbackForButtonPress); m_feedbackForButtonPress->Data());
} }
// Make sure we don't accidentally repeat an announcement. // Make sure we don't accidentally repeat an announcement.

View File

@ -340,7 +340,7 @@ namespace CalculatorApp
void OnPinUnpinCommand(Platform::Object ^ parameter); void OnPinUnpinCommand(Platform::Object ^ parameter);
void OnInputChanged(); void OnInputChanged();
void SetPrimaryDisplay(Platform::String ^ displayString, _In_ bool isError); void SetPrimaryDisplay(_In_ std::wstring const& displayString, _In_ bool isError);
void DisplayPasteError(); void DisplayPasteError();
void SetTokens(_Inout_ std::shared_ptr<std::vector<std::pair<std::wstring, int>>> const& tokens); void SetTokens(_Inout_ std::shared_ptr<std::vector<std::pair<std::wstring, int>>> const& tokens);
void SetExpressionDisplay( void SetExpressionDisplay(

View File

@ -137,12 +137,12 @@ UnitConverterViewModel::UnitConverterViewModel(const shared_ptr<UCM::IUnitConver
m_currencyMaxFractionDigits = m_currencyFormatter->FractionDigits; m_currencyMaxFractionDigits = m_currencyFormatter->FractionDigits;
auto resourceLoader = AppResourceProvider::GetInstance(); auto resourceLoader = AppResourceProvider::GetInstance();
m_localizedValueFromFormat = resourceLoader->GetResourceString(UnitConverterResourceKeys::ValueFromFormat); m_localizedValueFromFormat = resourceLoader.GetResourceString(UnitConverterResourceKeys::ValueFromFormat);
m_localizedValueToFormat = resourceLoader->GetResourceString(UnitConverterResourceKeys::ValueToFormat); m_localizedValueToFormat = resourceLoader.GetResourceString(UnitConverterResourceKeys::ValueToFormat);
m_localizedConversionResultFormat = resourceLoader->GetResourceString(UnitConverterResourceKeys::ConversionResultFormat); m_localizedConversionResultFormat = resourceLoader.GetResourceString(UnitConverterResourceKeys::ConversionResultFormat);
m_localizedValueFromDecimalFormat = resourceLoader->GetResourceString(UnitConverterResourceKeys::ValueFromDecimalFormat); m_localizedValueFromDecimalFormat = resourceLoader.GetResourceString(UnitConverterResourceKeys::ValueFromDecimalFormat);
m_localizedInputUnitName = resourceLoader->GetResourceString(UnitConverterResourceKeys::InputUnit_Name); m_localizedInputUnitName = resourceLoader.GetResourceString(UnitConverterResourceKeys::InputUnit_Name);
m_localizedOutputUnitName = resourceLoader->GetResourceString(UnitConverterResourceKeys::OutputUnit_Name); m_localizedOutputUnitName = resourceLoader.GetResourceString(UnitConverterResourceKeys::OutputUnit_Name);
Unit1AutomationName = m_localizedInputUnitName; Unit1AutomationName = m_localizedInputUnitName;
Unit2AutomationName = m_localizedOutputUnitName; Unit2AutomationName = m_localizedOutputUnitName;
@ -390,7 +390,7 @@ String ^ UnitConverterViewModel::ConvertToLocalizedString(const std::wstring& st
void UnitConverterViewModel::DisplayPasteError() void UnitConverterViewModel::DisplayPasteError()
{ {
String ^ errorMsg = AppResourceProvider::GetInstance()->GetCEngineString(StringReference(SIDS_DOMAIN)); /*SIDS_DOMAIN is for "invalid input"*/ String ^ errorMsg = AppResourceProvider::GetInstance().GetCEngineString(StringReference(SIDS_DOMAIN)); /*SIDS_DOMAIN is for "invalid input"*/
Value1 = errorMsg; Value1 = errorMsg;
Value2 = errorMsg; Value2 = errorMsg;
m_relocalizeStringOnSwitch = false; m_relocalizeStringOnSwitch = false;
@ -515,10 +515,8 @@ void UnitConverterViewModel::OnPasteCommand(Platform::Object ^ parameter)
// Ensure that the paste happens on the UI thread // Ensure that the paste happens on the UI thread
// EventWriteClipboardPaste_Start(); // EventWriteClipboardPaste_Start();
// Any converter ViewMode is fine here. // Any converter ViewMode is fine here.
CopyPasteManager::GetStringToPaste(m_Mode, NavCategory::GetGroupType(m_Mode))
auto that(this); .then([this](String ^ pastedString) { OnPaste(pastedString); }, concurrency::task_continuation_context::use_current());
create_task(CopyPasteManager::GetStringToPaste(m_Mode, NavCategory::GetGroupType(m_Mode), -1, BitLength::BitLengthUnknown))
.then([that](String ^ pastedString) { that->OnPaste(pastedString); }, concurrency::task_continuation_context::use_current());
} }
void UnitConverterViewModel::InitializeView() void UnitConverterViewModel::InitializeView()
@ -652,7 +650,7 @@ void UnitConverterViewModel::OnCurrencyDataLoadFinished(bool didLoad)
ResetCategory(); ResetCategory();
StringReference key = didLoad ? UnitConverterResourceKeys::CurrencyRatesUpdated : UnitConverterResourceKeys::CurrencyRatesUpdateFailed; StringReference key = didLoad ? UnitConverterResourceKeys::CurrencyRatesUpdated : UnitConverterResourceKeys::CurrencyRatesUpdateFailed;
String ^ announcement = AppResourceProvider::GetInstance()->GetResourceString(key); String ^ announcement = AppResourceProvider::GetInstance().GetResourceString(key);
Announcement = CalculatorAnnouncement::GetUpdateCurrencyRatesAnnouncement(announcement); Announcement = CalculatorAnnouncement::GetUpdateCurrencyRatesAnnouncement(announcement);
} }
@ -667,18 +665,17 @@ void UnitConverterViewModel::RefreshCurrencyRatios()
m_isCurrencyDataLoaded = false; m_isCurrencyDataLoaded = false;
IsCurrencyLoadingVisible = true; IsCurrencyLoadingVisible = true;
String ^ announcement = AppResourceProvider::GetInstance()->GetResourceString(UnitConverterResourceKeys::UpdatingCurrencyRates); String ^ announcement = AppResourceProvider::GetInstance().GetResourceString(UnitConverterResourceKeys::UpdatingCurrencyRates);
Announcement = CalculatorAnnouncement::GetUpdateCurrencyRatesAnnouncement(announcement); Announcement = CalculatorAnnouncement::GetUpdateCurrencyRatesAnnouncement(announcement);
auto that(this); auto refreshTask = create_task([this] { return m_model->RefreshCurrencyRatios().get(); });
auto refreshTask = create_task([that] { return that->m_model->RefreshCurrencyRatios().get(); });
refreshTask.then( refreshTask.then(
[that](const pair<bool, wstring>& refreshResult) { [this](const pair<bool, wstring>& refreshResult) {
bool didLoad = refreshResult.first; bool didLoad = refreshResult.first;
wstring timestamp = refreshResult.second; wstring timestamp = refreshResult.second;
that->OnCurrencyTimestampUpdated(timestamp, false /*isWeekOldData*/); OnCurrencyTimestampUpdated(timestamp, false /*isWeekOldData*/);
that->OnCurrencyDataLoadFinished(didLoad); OnCurrencyDataLoadFinished(didLoad);
}, },
task_continuation_context::use_current()); task_continuation_context::use_current());
} }
@ -881,7 +878,7 @@ NumbersAndOperatorsEnum UnitConverterViewModel::MapCharacterToButtonId(const wch
void UnitConverterViewModel::OnPaste(String ^ stringToPaste) void UnitConverterViewModel::OnPaste(String ^ stringToPaste)
{ {
// If pastedString is invalid("NoOp") then display pasteError else process the string // If pastedString is invalid("NoOp") then display pasteError else process the string
if (CopyPasteManager::IsErrorMessage(stringToPaste)) if (stringToPaste == StringReference(CopyPasteManager::PasteErrorString))
{ {
this->DisplayPasteError(); this->DisplayPasteError();
return; return;
@ -957,7 +954,8 @@ String ^ UnitConverterViewModel::GetLocalizedAutomationName(_In_ String ^ displa
format = m_localizedValueFromDecimalFormat; format = m_localizedValueFromDecimalFormat;
} }
return LocalizationStringUtil::GetLocalizedString(format, displayvalue, unitname); wstring localizedResult = LocalizationStringUtil::GetLocalizedString(format->Data(), displayvalue->Data(), unitname->Data());
return ref new String(localizedResult.c_str());
} }
String String
@ -967,7 +965,11 @@ String
_In_ String ^ toValue, _In_ String ^ toValue,
_In_ String ^ toUnit) _In_ String ^ toUnit)
{ {
return LocalizationStringUtil::GetLocalizedString(m_localizedConversionResultFormat, fromValue, fromUnit, toValue, toUnit); String ^ localizedString =
ref new String(LocalizationStringUtil::GetLocalizedString(
m_localizedConversionResultFormat->Data(), fromValue->Data(), fromUnit->Data(), toValue->Data(), toUnit->Data())
.c_str());
return localizedString;
} }
void UnitConverterViewModel::UpdateValue1AutomationName() void UnitConverterViewModel::UpdateValue1AutomationName()
@ -988,9 +990,9 @@ void UnitConverterViewModel::UpdateValue2AutomationName()
void UnitConverterViewModel::OnMaxDigitsReached() void UnitConverterViewModel::OnMaxDigitsReached()
{ {
String ^ format = AppResourceProvider::GetInstance()->GetResourceString(UnitConverterResourceKeys::MaxDigitsReachedFormat); String ^ format = AppResourceProvider::GetInstance().GetResourceString(UnitConverterResourceKeys::MaxDigitsReachedFormat);
auto announcement = LocalizationStringUtil::GetLocalizedString(format, m_lastAnnouncedConversionResult); const wstring& announcement = LocalizationStringUtil::GetLocalizedString(format->Data(), m_lastAnnouncedConversionResult->Data());
Announcement = CalculatorAnnouncement::GetMaxDigitsReachedAnnouncement(announcement); Announcement = CalculatorAnnouncement::GetMaxDigitsReachedAnnouncement(StringReference(announcement.c_str()));
} }
bool UnitConverterViewModel::UnitsAreValid() bool UnitConverterViewModel::UnitsAreValid()
@ -1000,18 +1002,17 @@ bool UnitConverterViewModel::UnitsAreValid()
void UnitConverterViewModel::StartConversionResultTimer() void UnitConverterViewModel::StartConversionResultTimer()
{ {
auto that(this); m_conversionResultTaskHelper = make_unique<ConversionResultTaskHelper>(CONVERSION_FINALIZED_DELAY_IN_MS, [this]() {
m_conversionResultTaskHelper = make_unique<ConversionResultTaskHelper>(CONVERSION_FINALIZED_DELAY_IN_MS, [that]() { if (UnitsAreValid())
if (that->UnitsAreValid())
{ {
String ^ valueFrom = that->m_Value1Active ? that->m_Value1 : that->m_Value2; String ^ valueFrom = m_Value1Active ? m_Value1 : m_Value2;
String ^ valueTo = that->m_Value1Active ? that->m_Value2 : that->m_Value1; String ^ valueTo = m_Value1Active ? m_Value2 : m_Value1;
} }
}); });
} }
String ^ SupplementaryResult::GetLocalizedAutomationName() String ^ SupplementaryResult::GetLocalizedAutomationName()
{ {
auto format = AppResourceProvider::GetInstance()->GetResourceString("SupplementaryUnit_AutomationName"); auto format = AppResourceProvider::GetInstance().GetResourceString("SupplementaryUnit_AutomationName");
return LocalizationStringUtil::GetLocalizedString(format, this->Value, this->Unit->Name); return ref new String(LocalizationStringUtil::GetLocalizedString(format->Data(), this->Value->Data(), this->Unit->Name->Data()).c_str());
} }

View File

@ -35,11 +35,11 @@ AboutFlyout::AboutFlyout()
this->SetVersionString(); this->SetVersionString();
Header->Text = resourceLoader->GetResourceString("AboutButton/Content"); Header->Text = resourceLoader.GetResourceString("AboutButton/Content");
auto copyrightText = auto copyrightText =
LocalizationStringUtil::GetLocalizedString(resourceLoader->GetResourceString("AboutControlCopyright"), StringReference(to_wstring(BUILD_YEAR).c_str())); LocalizationStringUtil::GetLocalizedString(resourceLoader.GetResourceString("AboutControlCopyright")->Data(), to_wstring(BUILD_YEAR).c_str());
AboutControlCopyrightRun->Text = copyrightText; AboutControlCopyrightRun->Text = ref new String(copyrightText.c_str());
} }
void AboutFlyout::FeedbackButton_Click(_In_ Object ^ sender, _In_ RoutedEventArgs ^ e) void AboutFlyout::FeedbackButton_Click(_In_ Object ^ sender, _In_ RoutedEventArgs ^ e)
@ -53,7 +53,7 @@ void AboutFlyout::FeedbackButton_Click(_In_ Object ^ sender, _In_ RoutedEventArg
void AboutFlyout::SetVersionString() void AboutFlyout::SetVersionString()
{ {
PackageVersion version = Package::Current->Id->Version; PackageVersion version = Package::Current->Id->Version;
String ^ appName = AppResourceProvider::GetInstance()->GetResourceString(L"AppName"); String ^ appName = AppResourceProvider::GetInstance().GetResourceString(L"AppName");
AboutFlyoutVersion->Text = appName + L" " + version.Major + L"." + version.Minor + L"." + version.Build + L"." + version.Revision; AboutFlyoutVersion->Text = appName + L" " + version.Major + L"." + version.Minor + L"." + version.Build + L"." + version.Revision;
} }

View File

@ -63,7 +63,11 @@ CalculationResult::CalculationResult()
Platform::String ^ CalculationResult::GetRawDisplayValue() Platform::String ^ CalculationResult::GetRawDisplayValue()
{ {
return LocalizationSettings::GetInstance().RemoveGroupSeparators(DisplayValue); std::wstring rawValue;
LocalizationSettings::GetInstance().RemoveGroupSeparators(DisplayValue->Data(), DisplayValue->Length(), &rawValue);
return ref new Platform::String(rawValue.c_str());
} }
void CalculationResult::OnApplyTemplate() void CalculationResult::OnApplyTemplate()

View File

@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved. // Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. // Licensed under the MIT License.
#include "pch.h" #include "pch.h"
@ -18,6 +18,8 @@ using namespace Windows::UI::Xaml::Data;
String ^ RadixButton::GetRawDisplayValue() String ^ RadixButton::GetRawDisplayValue()
{ {
wstring rawValue;
String ^ radixContent = Content->ToString(); String ^ radixContent = Content->ToString();
return LocalizationSettings::GetInstance().RemoveGroupSeparators(radixContent); LocalizationSettings::GetInstance().RemoveGroupSeparators(radixContent->Data(), radixContent->Length(), &rawValue);
return ref new String(rawValue.c_str());
} }

View File

@ -28,22 +28,22 @@ namespace CalculatorApp
{ {
case RADIX_TYPE::BIN_RADIX: case RADIX_TYPE::BIN_RADIX:
{ {
convertedValue = resourceLoader->GetResourceString("Bin"); convertedValue = resourceLoader.GetResourceString("Bin");
break; break;
} }
case RADIX_TYPE::OCT_RADIX: case RADIX_TYPE::OCT_RADIX:
{ {
convertedValue = resourceLoader->GetResourceString("Oct"); convertedValue = resourceLoader.GetResourceString("Oct");
break; break;
} }
case RADIX_TYPE::DEC_RADIX: case RADIX_TYPE::DEC_RADIX:
{ {
convertedValue = resourceLoader->GetResourceString("Dec"); convertedValue = resourceLoader.GetResourceString("Dec");
break; break;
} }
case RADIX_TYPE::HEX_RADIX: case RADIX_TYPE::HEX_RADIX:
{ {
convertedValue = resourceLoader->GetResourceString("Hex"); convertedValue = resourceLoader.GetResourceString("Hex");
break; break;
} }
default: default:

View File

@ -59,8 +59,8 @@ Calculator::Calculator()
m_displayFlyout = static_cast<MenuFlyout ^>(Resources->Lookup(L"DisplayContextMenu")); m_displayFlyout = static_cast<MenuFlyout ^>(Resources->Lookup(L"DisplayContextMenu"));
auto resLoader = AppResourceProvider::GetInstance(); auto resLoader = AppResourceProvider::GetInstance();
CopyMenuItem->Text = resLoader->GetResourceString(L"copyMenuItem"); CopyMenuItem->Text = resLoader.GetResourceString(L"copyMenuItem");
PasteMenuItem->Text = resLoader->GetResourceString(L"pasteMenuItem"); PasteMenuItem->Text = resLoader.GetResourceString(L"pasteMenuItem");
this->SizeChanged += ref new SizeChangedEventHandler(this, &Calculator::Calculator_SizeChanged); this->SizeChanged += ref new SizeChangedEventHandler(this, &Calculator::Calculator_SizeChanged);
} }
@ -68,10 +68,10 @@ Calculator::Calculator()
void Calculator::LoadResourceStrings() void Calculator::LoadResourceStrings()
{ {
auto resProvider = AppResourceProvider::GetInstance(); auto resProvider = AppResourceProvider::GetInstance();
m_openMemoryFlyoutAutomationName = resProvider->GetResourceString(L"MemoryButton_Open"); m_openMemoryFlyoutAutomationName = resProvider.GetResourceString(L"MemoryButton_Open");
m_closeMemoryFlyoutAutomationName = resProvider->GetResourceString(L"MemoryButton_Close"); m_closeMemoryFlyoutAutomationName = resProvider.GetResourceString(L"MemoryButton_Close");
m_openHistoryFlyoutAutomationName = resProvider->GetResourceString(L"HistoryButton_Open"); m_openHistoryFlyoutAutomationName = resProvider.GetResourceString(L"HistoryButton_Open");
m_closeHistoryFlyoutAutomationName = resProvider->GetResourceString(L"HistoryButton_Close"); m_closeHistoryFlyoutAutomationName = resProvider.GetResourceString(L"HistoryButton_Close");
AutomationProperties::SetName(MemoryButton, m_openMemoryFlyoutAutomationName); AutomationProperties::SetName(MemoryButton, m_openMemoryFlyoutAutomationName);
AutomationProperties::SetName(HistoryButton, m_openHistoryFlyoutAutomationName); AutomationProperties::SetName(HistoryButton, m_openHistoryFlyoutAutomationName);
} }
@ -123,9 +123,9 @@ void Calculator::OnLoaded(_In_ Object ^, _In_ RoutedEventArgs ^)
Model->HideMemoryClicked += ref new HideMemoryClickedHandler(this, &Calculator::OnHideMemoryClicked); Model->HideMemoryClicked += ref new HideMemoryClickedHandler(this, &Calculator::OnHideMemoryClicked);
InitializeHistoryView(Model->HistoryVM); InitializeHistoryView(Model->HistoryVM);
String ^ historyPaneName = AppResourceProvider::GetInstance()->GetResourceString(L"HistoryPane"); String ^ historyPaneName = AppResourceProvider::GetInstance().GetResourceString(L"HistoryPane");
HistoryFlyout->FlyoutPresenterStyle->Setters->Append(ref new Setter(AutomationProperties::NameProperty, historyPaneName)); HistoryFlyout->FlyoutPresenterStyle->Setters->Append(ref new Setter(AutomationProperties::NameProperty, historyPaneName));
String ^ memoryPaneName = AppResourceProvider::GetInstance()->GetResourceString(L"MemoryPane"); String ^ memoryPaneName = AppResourceProvider::GetInstance().GetResourceString(L"MemoryPane");
MemoryFlyout->FlyoutPresenterStyle->Setters->Append(ref new Setter(AutomationProperties::NameProperty, memoryPaneName)); MemoryFlyout->FlyoutPresenterStyle->Setters->Append(ref new Setter(AutomationProperties::NameProperty, memoryPaneName));
if (Windows::Foundation::Metadata::ApiInformation::IsEventPresent(L"Windows.UI.Xaml.Controls.Primitives.FlyoutBase", L"Closing")) if (Windows::Foundation::Metadata::ApiInformation::IsEventPresent(L"Windows.UI.Xaml.Controls.Primitives.FlyoutBase", L"Closing"))
@ -149,21 +149,24 @@ void Calculator::OnLoaded(_In_ Object ^, _In_ RoutedEventArgs ^)
})); }));
} }
Platform::String ^ Calculator::GetCurrentLayoutState() std::wstring Calculator::GetCurrentLayoutState()
{ {
std::wstring state;
if (IsProgrammer) if (IsProgrammer)
{ {
return L"Programmer"; state = L"Programmer";
} }
else if (IsScientific) else if (IsScientific)
{ {
return L"Scientific"; state = L"Scientific";
} }
else else
{ {
return L"Standard"; state = L"Standard";
} }
return state;
} }
void Calculator::UpdateViewState() void Calculator::UpdateViewState()
@ -476,7 +479,7 @@ void Calculator::OnHistoryItemClicked(_In_ HistoryItemViewModel ^ e)
assert(e->GetTokens() != nullptr); assert(e->GetTokens() != nullptr);
Model->SetHistoryExpressionDisplay(e->GetTokens(), e->GetCommands()); Model->SetHistoryExpressionDisplay(e->GetTokens(), e->GetCommands());
Model->SetExpressionDisplay(e->GetTokens(), e->GetCommands()); Model->SetExpressionDisplay(e->GetTokens(), e->GetCommands());
Model->SetPrimaryDisplay(e->Result, false); Model->SetPrimaryDisplay(e->Result->Data(), false);
Model->IsFToEEnabled = false; Model->IsFToEEnabled = false;
CloseHistoryFlyout(); CloseHistoryFlyout();
@ -613,7 +616,7 @@ Memory ^ Calculator::GetMemory()
if (m_memory == nullptr) if (m_memory == nullptr)
{ {
m_memory = ref new Memory(); m_memory = ref new Memory();
VisualStateManager::GoToState(m_memory, GetCurrentLayoutState(), true /*useTransitions*/); VisualStateManager::GoToState(m_memory, ref new String(GetCurrentLayoutState().c_str()), true /*useTransitions*/);
} }
return m_memory; return m_memory;
@ -669,6 +672,28 @@ void Calculator::OnHistoryFlyOutTapped(_In_ Object ^ sender, _In_ TappedRoutedEv
} }
} }
bool Calculator::IsValidRegularExpression(std::wstring str)
{
bool result = false;
std::wregex regexPatterns[3];
regexPatterns[0] = L"[-]{0,1}[0-9]{0,}[.]{0,1}[0-9]{0,}";
regexPatterns[1] = L"[-]{0,1}[0-9]{0,}[.]{0,1}[0-9]{0,}[e]{1}[+]{1}[0-9]{1,}";
regexPatterns[2] = L"[-]{0,1}[0-9]{0,}[.]{0,1}[0-9]{0,}[e]{1}[-]{1}[0-9]{1,}";
const auto& localizer = LocalizationSettings::GetInstance();
String ^ englishString = localizer.GetEnglishValueFromLocalizedDigits(str);
for (int i = 0; i < 3; ++i)
{
if (regex_match(englishString->Data(), regexPatterns[i]))
{
result = true;
break;
}
}
return result;
}
void Calculator::DockPanelTapped(_In_ TappedRoutedEventArgs ^ e) void Calculator::DockPanelTapped(_In_ TappedRoutedEventArgs ^ e)
{ {
int index = DockPivot->SelectedIndex; int index = DockPivot->SelectedIndex;

View File

@ -94,7 +94,7 @@ public
void EnsureScientific(); void EnsureScientific();
void EnsureProgrammer(); void EnsureProgrammer();
void SetFontSizeResources(); void SetFontSizeResources();
Platform::String ^ GetCurrentLayoutState(); std::wstring GetCurrentLayoutState();
void Calculator_SizeChanged(Object ^ sender, Windows::UI::Xaml::SizeChangedEventArgs ^ e); void Calculator_SizeChanged(Object ^ sender, Windows::UI::Xaml::SizeChangedEventArgs ^ e);
private: private:
@ -140,6 +140,7 @@ public
void EnableMemoryControls(bool enable); void EnableMemoryControls(bool enable);
void OnMemoryFlyOutTapped(_In_ Platform::Object ^ sender, _In_ Windows::UI::Xaml::Input::TappedRoutedEventArgs ^ e); void OnMemoryFlyOutTapped(_In_ Platform::Object ^ sender, _In_ Windows::UI::Xaml::Input::TappedRoutedEventArgs ^ e);
void OnHistoryFlyOutTapped(_In_ Platform::Object ^ sender, _In_ Windows::UI::Xaml::Input::TappedRoutedEventArgs ^ e); void OnHistoryFlyOutTapped(_In_ Platform::Object ^ sender, _In_ Windows::UI::Xaml::Input::TappedRoutedEventArgs ^ e);
bool IsValidRegularExpression(std::wstring str);
void DockPanelTapped(_In_ Windows::UI::Xaml::Input::TappedRoutedEventArgs ^ e); void DockPanelTapped(_In_ Windows::UI::Xaml::Input::TappedRoutedEventArgs ^ e);
void OnHistoryAccessKeyInvoked(_In_ Windows::UI::Xaml::UIElement ^ sender, _In_ Windows::UI::Xaml::Input::AccessKeyInvokedEventArgs ^ args); void OnHistoryAccessKeyInvoked(_In_ Windows::UI::Xaml::UIElement ^ sender, _In_ Windows::UI::Xaml::Input::AccessKeyInvokedEventArgs ^ args);
void OnMemoryAccessKeyInvoked(_In_ Windows::UI::Xaml::UIElement ^ sender, _In_ Windows::UI::Xaml::Input::AccessKeyInvokedEventArgs ^ args); void OnMemoryAccessKeyInvoked(_In_ Windows::UI::Xaml::UIElement ^ sender, _In_ Windows::UI::Xaml::Input::AccessKeyInvokedEventArgs ^ args);

View File

@ -247,11 +247,11 @@ int CalculatorProgrammerBitFlipPanel::GetIndexOfLastBit(BitLength length) const
String ^ CalculatorProgrammerBitFlipPanel::GenerateAutomationPropertiesName(int position, bool value) String ^ CalculatorProgrammerBitFlipPanel::GenerateAutomationPropertiesName(int position, bool value)
{ {
auto resourceLoader = AppResourceProvider::GetInstance(); auto resourceLoader = AppResourceProvider::GetInstance();
String ^ automationNameTemplate = resourceLoader->GetResourceString(L"BitFlipItemAutomationName"); String ^ automationNameTemplate = resourceLoader.GetResourceString(L"BitFlipItemAutomationName");
String ^ bitPosition; wstring bitPosition;
if (position == 0) if (position == 0)
{ {
bitPosition = resourceLoader->GetResourceString(L"LeastSignificantBit"); bitPosition = wstring(resourceLoader.GetResourceString(L"LeastSignificantBit")->Data());
} }
else else
{ {
@ -263,14 +263,14 @@ String ^ CalculatorProgrammerBitFlipPanel::GenerateAutomationPropertiesName(int
if (position == lastPosition) if (position == lastPosition)
{ {
bitPosition = resourceLoader->GetResourceString(L"MostSignificantBit"); bitPosition = wstring(resourceLoader.GetResourceString(L"MostSignificantBit")->Data());
} }
else else
{ {
String ^ indexName = resourceLoader->GetResourceString(ref new Platform::String(to_wstring(position).c_str())); String ^ indexName = resourceLoader.GetResourceString(ref new Platform::String(to_wstring(position).c_str()));
String ^ bitPositionTemplate = resourceLoader->GetResourceString(L"BitPosition"); String ^ bitPositionTemplate = resourceLoader.GetResourceString(L"BitPosition");
bitPosition = LocalizationStringUtil::GetLocalizedString(bitPositionTemplate, indexName); bitPosition = LocalizationStringUtil::GetLocalizedString(bitPositionTemplate->Data(), indexName->Data());
} }
} }
return LocalizationStringUtil::GetLocalizedString(automationNameTemplate, bitPosition, value ? L"1" : L"0"); return ref new String(LocalizationStringUtil::GetLocalizedString(automationNameTemplate->Data(), bitPosition.c_str(), value ? L"1" : L"0").c_str());
} }

View File

@ -33,7 +33,7 @@ CalculatorProgrammerOperators::CalculatorProgrammerOperators()
{ {
InitializeComponent(); InitializeComponent();
CopyMenuItem->Text = AppResourceProvider::GetInstance()->GetResourceString(L"copyMenuItem"); CopyMenuItem->Text = AppResourceProvider::GetInstance().GetResourceString(L"copyMenuItem");
} }
void CalculatorProgrammerOperators::HexButtonChecked(_In_ Object ^ sender, _In_ RoutedEventArgs ^ e) void CalculatorProgrammerOperators::HexButtonChecked(_In_ Object ^ sender, _In_ RoutedEventArgs ^ e)

View File

@ -92,7 +92,7 @@ DateCalculator::DateCalculator()
DateDiff_FromDate->PlaceholderText = placeholderText; DateDiff_FromDate->PlaceholderText = placeholderText;
DateDiff_ToDate->PlaceholderText = placeholderText; DateDiff_ToDate->PlaceholderText = placeholderText;
CopyMenuItem->Text = AppResourceProvider::GetInstance()->GetResourceString(L"copyMenuItem"); CopyMenuItem->Text = AppResourceProvider::GetInstance().GetResourceString(L"copyMenuItem");
m_dateCalcOptionChangedEventToken = DateCalculationOption->SelectionChanged += m_dateCalcOptionChangedEventToken = DateCalculationOption->SelectionChanged +=
ref new SelectionChangedEventHandler(this, &DateCalculator::DateCalcOption_Changed); ref new SelectionChangedEventHandler(this, &DateCalculator::DateCalcOption_Changed);
} }

View File

@ -10,7 +10,6 @@
#include "CalcViewModel/Common/AppResourceProvider.h" #include "CalcViewModel/Common/AppResourceProvider.h"
#include "Views/Memory.xaml.h" #include "Views/Memory.xaml.h"
#include "Converters/BooleanToVisibilityConverter.h" #include "Converters/BooleanToVisibilityConverter.h"
#include "CalcViewModel/Common/LocalizationStringUtil.h"
#include "Common/AppLifecycleLogger.h" #include "Common/AppLifecycleLogger.h"
using namespace CalculatorApp; using namespace CalculatorApp;
using namespace CalculatorApp::Common; using namespace CalculatorApp::Common;
@ -511,20 +510,25 @@ void MainPage::SetHeaderAutomationName()
String ^ name; String ^ name;
if (NavCategory::IsDateCalculatorViewMode(mode)) if (NavCategory::IsDateCalculatorViewMode(mode))
{ {
name = resProvider->GetResourceString(L"HeaderAutomationName_Date"); name = resProvider.GetResourceString(L"HeaderAutomationName_Date");
} }
else else
{ {
String ^ full; wstring full;
if (NavCategory::IsCalculatorViewMode(mode)) if (NavCategory::IsCalculatorViewMode(mode))
{ {
full = resProvider->GetResourceString(L"HeaderAutomationName_Calculator"); full = resProvider.GetResourceString(L"HeaderAutomationName_Calculator")->Data();
} }
else if (NavCategory::IsConverterViewMode(mode)) else if (NavCategory::IsConverterViewMode(mode))
{ {
full = resProvider->GetResourceString(L"HeaderAutomationName_Converter"); full = resProvider.GetResourceString(L"HeaderAutomationName_Converter")->Data();
} }
name = LocalizationStringUtil::GetLocalizedString(full, m_model->CategoryName);
string::size_type found = full.find(L"%1");
wstring strMode = m_model->CategoryName->Data();
full = full.replace(found, 2, strMode);
name = ref new String(full.c_str());
} }
AutomationProperties::SetName(Header, name); AutomationProperties::SetName(Header, name);

View File

@ -37,9 +37,9 @@ namespace CalculatorApp
Loaded += ref new RoutedEventHandler(this, &TitleBar::OnLoaded); Loaded += ref new RoutedEventHandler(this, &TitleBar::OnLoaded);
Unloaded += ref new RoutedEventHandler(this, &TitleBar::OnUnloaded); Unloaded += ref new RoutedEventHandler(this, &TitleBar::OnUnloaded);
#ifdef IS_STORE_BUILD #ifdef IS_STORE_BUILD
AppName->Text = AppResourceProvider::GetInstance()->GetResourceString(L"AppName"); AppName->Text = AppResourceProvider::GetInstance().GetResourceString(L"AppName");
#else #else
AppName->Text = AppResourceProvider::GetInstance()->GetResourceString(L"DevAppName"); AppName->Text = AppResourceProvider::GetInstance().GetResourceString(L"DevAppName");
#endif // IS_STORE_BUILD #endif // IS_STORE_BUILD
} }

View File

@ -40,6 +40,8 @@ using namespace Windows::UI::Xaml::Media;
using namespace Windows::UI::Xaml::Navigation; using namespace Windows::UI::Xaml::Navigation;
using namespace Windows::UI::ViewManagement; using namespace Windows::UI::ViewManagement;
// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
// Calculate number of 100-nanosecond intervals in 500 milliseconds. // Calculate number of 100-nanosecond intervals in 500 milliseconds.
// There are 10,000 intervals in 1 ms. // There are 10,000 intervals in 1 ms.
static const long long DURATION_500_MS = 10000 * 500; static const long long DURATION_500_MS = 10000 * 500;
@ -64,14 +66,14 @@ UnitConverter::UnitConverter()
m_isAnimationEnabled = userSettings->AnimationsEnabled; m_isAnimationEnabled = userSettings->AnimationsEnabled;
auto resLoader = AppResourceProvider::GetInstance(); auto resLoader = AppResourceProvider::GetInstance();
m_chargesMayApplyText = resLoader->GetResourceString(L"DataChargesMayApply"); m_chargesMayApplyText = resLoader.GetResourceString(L"DataChargesMayApply");
m_failedToRefreshText = resLoader->GetResourceString(L"FailedToRefresh"); m_failedToRefreshText = resLoader.GetResourceString(L"FailedToRefresh");
InitializeOfflineStatusTextBlock(); InitializeOfflineStatusTextBlock();
m_resultsFlyout = static_cast<MenuFlyout ^>(Resources->Lookup(L"CalculationResultContextMenu")); m_resultsFlyout = static_cast<MenuFlyout ^>(Resources->Lookup(L"CalculationResultContextMenu"));
CopyMenuItem->Text = resLoader->GetResourceString(L"copyMenuItem"); CopyMenuItem->Text = resLoader.GetResourceString(L"copyMenuItem");
PasteMenuItem->Text = resLoader->GetResourceString(L"pasteMenuItem"); PasteMenuItem->Text = resLoader.GetResourceString(L"pasteMenuItem");
} }
void UnitConverter::OnPropertyChanged(_In_ Object ^ sender, _In_ PropertyChangedEventArgs ^ e) void UnitConverter::OnPropertyChanged(_In_ Object ^ sender, _In_ PropertyChangedEventArgs ^ e)
@ -163,7 +165,7 @@ void UnitConverter::SetFailedToRefreshStatus()
void UnitConverter::InitializeOfflineStatusTextBlock() void UnitConverter::InitializeOfflineStatusTextBlock()
{ {
auto resProvider = AppResourceProvider::GetInstance(); auto resProvider = AppResourceProvider::GetInstance();
std::wstring offlineStatusHyperlinkText = resProvider->GetResourceString(L"OfflineStatusHyperlinkText")->Data(); std::wstring offlineStatusHyperlinkText = static_cast<String ^>(resProvider.GetResourceString(L"OfflineStatusHyperlinkText"))->Data();
// The resource string has the 'NetworkSettings' hyperlink wrapped with '%HL%'. // The resource string has the 'NetworkSettings' hyperlink wrapped with '%HL%'.
// Break the string and assign pieces appropriately. // Break the string and assign pieces appropriately.
@ -243,9 +245,9 @@ void UnitConverter::OnCopyMenuItemClicked(_In_ Object ^ sender, _In_ RoutedEvent
void UnitConverter::OnPasteMenuItemClicked(_In_ Object ^ sender, _In_ RoutedEventArgs ^ e) void UnitConverter::OnPasteMenuItemClicked(_In_ Object ^ sender, _In_ RoutedEventArgs ^ e)
{ {
auto that(this); CopyPasteManager::GetStringToPaste(Model->Mode, CategoryGroupType::Converter).then([this](String ^ pastedString) {
create_task(CopyPasteManager::GetStringToPaste(Model->Mode, CategoryGroupType::Converter, -1, BitLength::BitLengthUnknown)) Model->OnPaste(pastedString);
.then([that](String ^ pastedString) { that->Model->OnPaste(pastedString); }); });
} }
void UnitConverter::AnimateConverter() void UnitConverter::AnimateConverter()

View File

@ -42,10 +42,6 @@ namespace CalculatorUnitTests
TEST_CLASS(CopyPasteManagerTest) TEST_CLASS(CopyPasteManagerTest)
{ {
public: public:
CopyPasteManagerTest()
{
m_CopyPasteManager = ref new CopyPasteManager();
}
TEST_METHOD(FunctionalCopyPasteTest); TEST_METHOD(FunctionalCopyPasteTest);
TEST_METHOD(ValidateStandardPasteExpressionTest); TEST_METHOD(ValidateStandardPasteExpressionTest);
TEST_METHOD(ValidateScientificPasteExpressionTest); TEST_METHOD(ValidateScientificPasteExpressionTest);
@ -58,36 +54,35 @@ namespace CalculatorUnitTests
TEST_METHOD(ValidatePasteExpressionErrorStates) TEST_METHOD(ValidatePasteExpressionErrorStates)
{ {
wstring exp_TooLong = L""; wstring exp_TooLong = L"";
for (int i = 0; i < m_CopyPasteManager->MaxPasteableLength / 8; i++) for (int i = 0; i < m_CopyPasteManager.MaxPasteableLength / 8; i++)
{ {
exp_TooLong += L"-1234567"; exp_TooLong += L"-1234567";
} }
VERIFY_ARE_EQUAL( VERIFY_ARE_EQUAL(
m_CopyPasteManager->ValidatePasteExpression( m_CopyPasteManager.ValidatePasteExpression(StringReference(exp_TooLong.c_str()), ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown),
StringReference(exp_TooLong.c_str()), ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown),
StringReference(exp_TooLong.c_str()), StringReference(exp_TooLong.c_str()),
L"Verify ValidatePasteExpression handles expressions up to max length"); L"Verify ValidatePasteExpression handles expressions up to max length");
exp_TooLong += L"1"; exp_TooLong += L"1";
VERIFY_ARE_EQUAL( VERIFY_ARE_EQUAL(
m_CopyPasteManager->ValidatePasteExpression( m_CopyPasteManager.ValidatePasteExpression(
StringReference(exp_TooLong.c_str()), ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown), StringReference(exp_TooLong.c_str()), ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown),
StringReference(L"NoOp"), StringReference(L"NoOp"),
L"Verify ValidatePasteExpression returns NoOp for strings over max length"); L"Verify ValidatePasteExpression returns NoOp for strings over max length");
VERIFY_ARE_EQUAL( VERIFY_ARE_EQUAL(
m_CopyPasteManager->ValidatePasteExpression( m_CopyPasteManager.ValidatePasteExpression(
StringReference(L""), ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown), StringReference(L""), ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown),
StringReference(L"NoOp"), StringReference(L"NoOp"),
L"Verify empty string is invalid"); L"Verify empty string is invalid");
VERIFY_ARE_EQUAL( VERIFY_ARE_EQUAL(
m_CopyPasteManager->ValidatePasteExpression( m_CopyPasteManager.ValidatePasteExpression(
StringReference(L"1a23f456"), ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown), StringReference(L"1a23f456"), ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown),
StringReference(L"NoOp"), StringReference(L"NoOp"),
L"Verify pasting unsupported strings for the current mode is invalid"); L"Verify pasting unsupported strings for the current mode is invalid");
VERIFY_ARE_EQUAL( VERIFY_ARE_EQUAL(
m_CopyPasteManager->ValidatePasteExpression(StringReference(L"123"), ViewMode::None, CategoryGroupType::None, -1, BitLength::BitLengthUnknown), m_CopyPasteManager.ValidatePasteExpression(StringReference(L"123"), ViewMode::None, CategoryGroupType::None, -1, BitLength::BitLengthUnknown),
StringReference(L"NoOp"), StringReference(L"NoOp"),
L"Verify pasting without a ViewMode or Category is invalid"); L"Verify pasting without a ViewMode or Category is invalid");
}; };
@ -97,47 +92,47 @@ namespace CalculatorUnitTests
vector<wstring> results = {}; vector<wstring> results = {};
vector<wstring> oneOperand = { L"123456" }; vector<wstring> oneOperand = { L"123456" };
VERIFY_ARE_EQUAL(m_CopyPasteManager->ExtractOperands(L"123456", ViewMode::Standard), oneOperand); VERIFY_ARE_EQUAL(m_CopyPasteManager.ExtractOperands(L"123456", ViewMode::Standard), oneOperand);
oneOperand = { L"123^456" }; oneOperand = { L"123^456" };
VERIFY_ARE_EQUAL(m_CopyPasteManager->ExtractOperands(L"123^456", ViewMode::Standard), oneOperand); VERIFY_ARE_EQUAL(m_CopyPasteManager.ExtractOperands(L"123^456", ViewMode::Standard), oneOperand);
vector<wstring> twoOperands = { L"123", L"456" }; vector<wstring> twoOperands = { L"123", L"456" };
VERIFY_ARE_EQUAL(m_CopyPasteManager->ExtractOperands(L"123+456", ViewMode::Standard), twoOperands); VERIFY_ARE_EQUAL(m_CopyPasteManager.ExtractOperands(L"123+456", ViewMode::Standard), twoOperands);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ExtractOperands(L"123-456", ViewMode::Standard), twoOperands); VERIFY_ARE_EQUAL(m_CopyPasteManager.ExtractOperands(L"123-456", ViewMode::Standard), twoOperands);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ExtractOperands(L"123*456", ViewMode::Standard), twoOperands); VERIFY_ARE_EQUAL(m_CopyPasteManager.ExtractOperands(L"123*456", ViewMode::Standard), twoOperands);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ExtractOperands(L"123/456", ViewMode::Standard), twoOperands); VERIFY_ARE_EQUAL(m_CopyPasteManager.ExtractOperands(L"123/456", ViewMode::Standard), twoOperands);
vector<wstring> expOperand = { L"123e456" }; vector<wstring> expOperand = { L"123e456" };
VERIFY_ARE_EQUAL(m_CopyPasteManager->ExtractOperands(L"123e456", ViewMode::Standard), expOperand); VERIFY_ARE_EQUAL(m_CopyPasteManager.ExtractOperands(L"123e456", ViewMode::Standard), expOperand);
expOperand = { L"123e4567" }; expOperand = { L"123e4567" };
VERIFY_ARE_EQUAL(m_CopyPasteManager->ExtractOperands(L"123e4567", ViewMode::Standard), expOperand); VERIFY_ARE_EQUAL(m_CopyPasteManager.ExtractOperands(L"123e4567", ViewMode::Standard), expOperand);
vector<wstring> twoOperandsParens = { L"((45)", L"(-30))" }; vector<wstring> twoOperandsParens = { L"((45)", L"(-30))" };
VERIFY_ARE_EQUAL(m_CopyPasteManager->ExtractOperands(L"((45)+(-30))", ViewMode::Scientific), twoOperandsParens); VERIFY_ARE_EQUAL(m_CopyPasteManager.ExtractOperands(L"((45)+(-30))", ViewMode::Scientific), twoOperandsParens);
}; };
TEST_METHOD(ValidateExtractOperandsErrors) TEST_METHOD(ValidateExtractOperandsErrors)
{ {
wstring exp_OperandLimit = L""; wstring exp_OperandLimit = L"";
for (int i = 0; i < m_CopyPasteManager->MaxOperandCount; i++) for (int i = 0; i < m_CopyPasteManager.MaxOperandCount; i++)
{ {
exp_OperandLimit += L"+1"; exp_OperandLimit += L"+1";
} }
VERIFY_ARE_EQUAL( VERIFY_ARE_EQUAL(
m_CopyPasteManager->ExtractOperands(exp_OperandLimit, ViewMode::Standard).size(), m_CopyPasteManager.ExtractOperands(exp_OperandLimit, ViewMode::Standard).size(),
100, 100,
L"Verify ExtractOperands handles up to MaxOperandCount operands"); L"Verify ExtractOperands handles up to MaxOperandCount operands");
exp_OperandLimit += L"+1"; exp_OperandLimit += L"+1";
VERIFY_ARE_EQUAL( VERIFY_ARE_EQUAL(
m_CopyPasteManager->ExtractOperands(exp_OperandLimit, ViewMode::Standard).size(), m_CopyPasteManager.ExtractOperands(exp_OperandLimit, ViewMode::Standard).size(),
0, 0,
L"Verify ExtractOperands returns empty vector on too many operands"); L"Verify ExtractOperands returns empty vector on too many operands");
VERIFY_ARE_EQUAL( VERIFY_ARE_EQUAL(
m_CopyPasteManager->ExtractOperands(L"12e9999", ViewMode::Standard).size(), 1, L"Verify ExtractOperands handles up to 4 digit exponents"); m_CopyPasteManager.ExtractOperands(L"12e9999", ViewMode::Standard).size(), 1, L"Verify ExtractOperands handles up to 4 digit exponents");
VERIFY_ARE_EQUAL( VERIFY_ARE_EQUAL(
m_CopyPasteManager->ExtractOperands(L"12e10000", ViewMode::Standard).size(), m_CopyPasteManager.ExtractOperands(L"12e10000", ViewMode::Standard).size(),
0, 0,
L"Verify ExtractOperands returns empty vector when the exponent is too long"); L"Verify ExtractOperands returns empty vector when the exponent is too long");
}; };
@ -145,31 +140,31 @@ namespace CalculatorUnitTests
TEST_METHOD(ValidateExpressionRegExMatch) TEST_METHOD(ValidateExpressionRegExMatch)
{ {
VERIFY_IS_FALSE( VERIFY_IS_FALSE(
m_CopyPasteManager->ExpressionRegExMatch(vector<wstring>{}, ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown), m_CopyPasteManager.ExpressionRegExMatch(vector<wstring>{}, ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown),
L"Verify empty list of operands returns false."); L"Verify empty list of operands returns false.");
VERIFY_IS_FALSE( VERIFY_IS_FALSE(
m_CopyPasteManager->ExpressionRegExMatch( m_CopyPasteManager.ExpressionRegExMatch(
vector<wstring>{ L"123" }, ViewMode::None, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown), vector<wstring>{ L"123" }, ViewMode::None, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown),
L"Verify invalid ViewMode/CategoryGroups return false."); L"Verify invalid ViewMode/CategoryGroups return false.");
VERIFY_IS_FALSE( VERIFY_IS_FALSE(
m_CopyPasteManager->ExpressionRegExMatch( m_CopyPasteManager.ExpressionRegExMatch(
vector<wstring>{ L"123" }, ViewMode::Currency, CategoryGroupType::None, -1, BitLength::BitLengthUnknown), vector<wstring>{ L"123" }, ViewMode::Currency, CategoryGroupType::None, -1, BitLength::BitLengthUnknown),
L"Verify invalid ViewMode/CategoryGroups return false."); L"Verify invalid ViewMode/CategoryGroups return false.");
Logger::WriteMessage(L"Verify operand lengths > max return false."); Logger::WriteMessage(L"Verify operand lengths > max return false.");
VERIFY_IS_FALSE(m_CopyPasteManager->ExpressionRegExMatch( VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(
vector<wstring>{ L"12345678901234567" }, ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown)); vector<wstring>{ L"12345678901234567" }, ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown));
VERIFY_IS_FALSE(m_CopyPasteManager->ExpressionRegExMatch( VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(
vector<wstring>{ L"123456789012345678901234567890123" }, ViewMode::Scientific, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown)); vector<wstring>{ L"123456789012345678901234567890123" }, ViewMode::Scientific, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown));
VERIFY_IS_FALSE(m_CopyPasteManager->ExpressionRegExMatch( VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(
vector<wstring>{ L"12345678901234567" }, ViewMode::None, CategoryGroupType::Converter, -1, BitLength::BitLengthUnknown)); vector<wstring>{ L"12345678901234567" }, ViewMode::None, CategoryGroupType::Converter, -1, BitLength::BitLengthUnknown));
VERIFY_IS_FALSE(m_CopyPasteManager->ExpressionRegExMatch( VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(
vector<wstring>{ L"11111111111111111" }, ViewMode::Programmer, CategoryGroupType::Calculator, HexBase, BitLength::BitLengthQWord)); vector<wstring>{ L"11111111111111111" }, ViewMode::Programmer, CategoryGroupType::Calculator, HexBase, BitLength::BitLengthQWord));
VERIFY_IS_FALSE(m_CopyPasteManager->ExpressionRegExMatch( VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(
vector<wstring>{ L"12345678901234567890" }, ViewMode::Programmer, CategoryGroupType::Calculator, DecBase, BitLength::BitLengthQWord)); vector<wstring>{ L"12345678901234567890" }, ViewMode::Programmer, CategoryGroupType::Calculator, DecBase, BitLength::BitLengthQWord));
VERIFY_IS_FALSE(m_CopyPasteManager->ExpressionRegExMatch( VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(
vector<wstring>{ L"11111111111111111111111" }, ViewMode::Programmer, CategoryGroupType::Calculator, OctBase, BitLength::BitLengthQWord)); vector<wstring>{ L"11111111111111111111111" }, ViewMode::Programmer, CategoryGroupType::Calculator, OctBase, BitLength::BitLengthQWord));
VERIFY_IS_FALSE(m_CopyPasteManager->ExpressionRegExMatch( VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(
vector<wstring>{ L"10000000000000000000000000000000000000000000000000000000000000000" }, vector<wstring>{ L"10000000000000000000000000000000000000000000000000000000000000000" },
ViewMode::Programmer, ViewMode::Programmer,
CategoryGroupType::Calculator, CategoryGroupType::Calculator,
@ -177,12 +172,12 @@ namespace CalculatorUnitTests
BitLength::BitLengthQWord)); BitLength::BitLengthQWord));
VERIFY_IS_FALSE( VERIFY_IS_FALSE(
m_CopyPasteManager->ExpressionRegExMatch( m_CopyPasteManager.ExpressionRegExMatch(
vector<wstring>{ L"9223372036854775808" }, ViewMode::Programmer, CategoryGroupType::Calculator, DecBase, BitLength::BitLengthQWord), vector<wstring>{ L"9223372036854775808" }, ViewMode::Programmer, CategoryGroupType::Calculator, DecBase, BitLength::BitLengthQWord),
L"Verify operand values > max return false."); L"Verify operand values > max return false.");
VERIFY_IS_TRUE( VERIFY_IS_TRUE(
m_CopyPasteManager->ExpressionRegExMatch( m_CopyPasteManager.ExpressionRegExMatch(
vector<wstring>{ L"((((((((((((((((((((123))))))))))))))))))))" }, vector<wstring>{ L"((((((((((((((((((((123))))))))))))))))))))" },
ViewMode::Scientific, ViewMode::Scientific,
CategoryGroupType::Calculator, CategoryGroupType::Calculator,
@ -190,20 +185,20 @@ namespace CalculatorUnitTests
BitLength::BitLengthUnknown), BitLength::BitLengthUnknown),
L"Verify sanitized operand is detected as within max length."); L"Verify sanitized operand is detected as within max length.");
VERIFY_IS_TRUE( VERIFY_IS_TRUE(
m_CopyPasteManager->ExpressionRegExMatch( m_CopyPasteManager.ExpressionRegExMatch(
vector<wstring>{ L"9223372036854775807" }, ViewMode::Programmer, CategoryGroupType::Calculator, DecBase, BitLength::BitLengthQWord), vector<wstring>{ L"9223372036854775807" }, ViewMode::Programmer, CategoryGroupType::Calculator, DecBase, BitLength::BitLengthQWord),
L"Verify operand values == max return true."); L"Verify operand values == max return true.");
Logger::WriteMessage(L"Verify all operands must match patterns."); Logger::WriteMessage(L"Verify all operands must match patterns.");
VERIFY_IS_TRUE(m_CopyPasteManager->ExpressionRegExMatch( VERIFY_IS_TRUE(m_CopyPasteManager.ExpressionRegExMatch(
vector<wstring>{ L"123", L"456" }, ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown)); vector<wstring>{ L"123", L"456" }, ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown));
VERIFY_IS_TRUE(m_CopyPasteManager->ExpressionRegExMatch( VERIFY_IS_TRUE(m_CopyPasteManager.ExpressionRegExMatch(
vector<wstring>{ L"123", L"1e23" }, ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown)); vector<wstring>{ L"123", L"1e23" }, ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown));
VERIFY_IS_FALSE(m_CopyPasteManager->ExpressionRegExMatch( VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(
vector<wstring>{ L"123", L"fab10" }, ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown)); vector<wstring>{ L"123", L"fab10" }, ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown));
VERIFY_IS_TRUE( VERIFY_IS_TRUE(
m_CopyPasteManager->ExpressionRegExMatch( m_CopyPasteManager.ExpressionRegExMatch(
vector<wstring>{ L"1.23e+456", L"1.23e456", L".23e+456", L"123e-456", L"12e2", L"12e+2", L"12e-2", L"-12e2", L"-12e+2", L"-12e-2" }, vector<wstring>{ L"1.23e+456", L"1.23e456", L".23e+456", L"123e-456", L"12e2", L"12e+2", L"12e-2", L"-12e2", L"-12e+2", L"-12e-2" },
ViewMode::Scientific, ViewMode::Scientific,
CategoryGroupType::Calculator, CategoryGroupType::Calculator,
@ -212,30 +207,34 @@ namespace CalculatorUnitTests
L"Verify exponents are accepted in scientific mode."); L"Verify exponents are accepted in scientific mode.");
VERIFY_IS_FALSE( VERIFY_IS_FALSE(
m_CopyPasteManager->ExpressionRegExMatch( m_CopyPasteManager.ExpressionRegExMatch(
vector<wstring>{ L"123", L"12345678901234567" }, ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown), vector<wstring>{ L"123", L"12345678901234567" }, ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown),
L"Verify all operands must be within maxlength"); L"Verify all operands must be within maxlength");
VERIFY_IS_FALSE( VERIFY_IS_FALSE(
m_CopyPasteManager->ExpressionRegExMatch( m_CopyPasteManager.ExpressionRegExMatch(
vector<wstring>{ L"123", L"9223372036854775808" }, ViewMode::Programmer, CategoryGroupType::Calculator, DecBase, BitLength::BitLengthQWord), vector<wstring>{ L"123", L"9223372036854775808" },
ViewMode::Programmer,
CategoryGroupType::Calculator,
DecBase,
BitLength::BitLengthQWord),
L"Verify all operand must be within max value."); L"Verify all operand must be within max value.");
}; };
TEST_METHOD(ValidateGetMaxOperandLengthAndValue) TEST_METHOD(ValidateGetMaxOperandLengthAndValue)
{ {
pair<size_t, unsigned long long int> standardModeMaximums = make_pair(m_CopyPasteManager->MaxStandardOperandLength, 0); pair<size_t, unsigned long long int> standardModeMaximums = make_pair(m_CopyPasteManager.MaxStandardOperandLength, 0);
pair<size_t, unsigned long long int> scientificModeMaximums = make_pair(m_CopyPasteManager->MaxScientificOperandLength, 0); pair<size_t, unsigned long long int> scientificModeMaximums = make_pair(m_CopyPasteManager.MaxScientificOperandLength, 0);
pair<size_t, unsigned long long int> converterModeMaximums = make_pair(m_CopyPasteManager->MaxConverterInputLength, 0); pair<size_t, unsigned long long int> converterModeMaximums = make_pair(m_CopyPasteManager.MaxConverterInputLength, 0);
VERIFY_ARE_EQUAL( VERIFY_ARE_EQUAL(
m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Standard, CategoryGroupType::None, -1, BitLength::BitLengthUnknown), m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Standard, CategoryGroupType::None, -1, BitLength::BitLengthUnknown),
standardModeMaximums, standardModeMaximums,
L"Verify Standard mode maximum values"); L"Verify Standard mode maximum values");
VERIFY_ARE_EQUAL( VERIFY_ARE_EQUAL(
m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Scientific, CategoryGroupType::None, -1, BitLength::BitLengthUnknown), m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Scientific, CategoryGroupType::None, -1, BitLength::BitLengthUnknown),
scientificModeMaximums, scientificModeMaximums,
L"Verify Scientific mode maximum values"); L"Verify Scientific mode maximum values");
VERIFY_ARE_EQUAL( VERIFY_ARE_EQUAL(
m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::None, CategoryGroupType::Converter, -1, BitLength::BitLengthUnknown), m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::None, CategoryGroupType::Converter, -1, BitLength::BitLengthUnknown),
converterModeMaximums, converterModeMaximums,
L"Verify Converter mode maximum values"); L"Verify Converter mode maximum values");
@ -245,108 +244,108 @@ namespace CalculatorUnitTests
unsigned long long int ullByteMax = UINT8_MAX; unsigned long long int ullByteMax = UINT8_MAX;
Logger::WriteMessage(L"Verify Programmer Mode HexBase maximum values"); Logger::WriteMessage(L"Verify Programmer Mode HexBase maximum values");
VERIFY_ARE_EQUAL( VERIFY_ARE_EQUAL(
m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, HexBase, BitLength::BitLengthQWord), m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, HexBase, BitLength::BitLengthQWord),
make_pair((size_t)16u, ullQwordMax)); make_pair((size_t)16u, ullQwordMax));
VERIFY_ARE_EQUAL( VERIFY_ARE_EQUAL(
m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, HexBase, BitLength::BitLengthDWord), m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, HexBase, BitLength::BitLengthDWord),
make_pair((size_t)8u, ullDwordMax)); make_pair((size_t)8u, ullDwordMax));
VERIFY_ARE_EQUAL( VERIFY_ARE_EQUAL(
m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, HexBase, BitLength::BitLengthWord), m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, HexBase, BitLength::BitLengthWord),
make_pair((size_t)4u, ullWordMax)); make_pair((size_t)4u, ullWordMax));
VERIFY_ARE_EQUAL( VERIFY_ARE_EQUAL(
m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, HexBase, BitLength::BitLengthByte), m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, HexBase, BitLength::BitLengthByte),
make_pair((size_t)2u, ullByteMax)); make_pair((size_t)2u, ullByteMax));
Logger::WriteMessage(L"Verify Programmer Mode DecBase maximum values"); Logger::WriteMessage(L"Verify Programmer Mode DecBase maximum values");
VERIFY_ARE_EQUAL( VERIFY_ARE_EQUAL(
m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, DecBase, BitLength::BitLengthQWord), m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, DecBase, BitLength::BitLengthQWord),
make_pair((size_t)19u, ullQwordMax >> 1)); make_pair((size_t)19u, ullQwordMax >> 1));
VERIFY_ARE_EQUAL( VERIFY_ARE_EQUAL(
m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, DecBase, BitLength::BitLengthDWord), m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, DecBase, BitLength::BitLengthDWord),
make_pair((size_t)10u, ullDwordMax >> 1)); make_pair((size_t)10u, ullDwordMax >> 1));
VERIFY_ARE_EQUAL( VERIFY_ARE_EQUAL(
m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, DecBase, BitLength::BitLengthWord), m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, DecBase, BitLength::BitLengthWord),
make_pair((size_t)5u, ullWordMax >> 1)); make_pair((size_t)5u, ullWordMax >> 1));
VERIFY_ARE_EQUAL( VERIFY_ARE_EQUAL(
m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, DecBase, BitLength::BitLengthByte), m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, DecBase, BitLength::BitLengthByte),
make_pair((size_t)3u, ullByteMax >> 1)); make_pair((size_t)3u, ullByteMax >> 1));
Logger::WriteMessage(L"Verify Programmer Mode OctBase maximum values"); Logger::WriteMessage(L"Verify Programmer Mode OctBase maximum values");
VERIFY_ARE_EQUAL( VERIFY_ARE_EQUAL(
m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, OctBase, BitLength::BitLengthQWord), m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, OctBase, BitLength::BitLengthQWord),
make_pair((size_t)22u, ullQwordMax)); make_pair((size_t)22u, ullQwordMax));
VERIFY_ARE_EQUAL( VERIFY_ARE_EQUAL(
m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, OctBase, BitLength::BitLengthDWord), m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, OctBase, BitLength::BitLengthDWord),
make_pair((size_t)11u, ullDwordMax)); make_pair((size_t)11u, ullDwordMax));
VERIFY_ARE_EQUAL( VERIFY_ARE_EQUAL(
m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, OctBase, BitLength::BitLengthWord), m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, OctBase, BitLength::BitLengthWord),
make_pair((size_t)6u, ullWordMax)); make_pair((size_t)6u, ullWordMax));
VERIFY_ARE_EQUAL( VERIFY_ARE_EQUAL(
m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, OctBase, BitLength::BitLengthByte), m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, OctBase, BitLength::BitLengthByte),
make_pair((size_t)3u, ullByteMax)); make_pair((size_t)3u, ullByteMax));
Logger::WriteMessage(L"Verify Programmer Mode BinBase maximum values"); Logger::WriteMessage(L"Verify Programmer Mode BinBase maximum values");
VERIFY_ARE_EQUAL( VERIFY_ARE_EQUAL(
m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, BinBase, BitLength::BitLengthQWord), m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, BinBase, BitLength::BitLengthQWord),
make_pair((size_t)64u, ullQwordMax)); make_pair((size_t)64u, ullQwordMax));
VERIFY_ARE_EQUAL( VERIFY_ARE_EQUAL(
m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, BinBase, BitLength::BitLengthDWord), m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, BinBase, BitLength::BitLengthDWord),
make_pair((size_t)32u, ullDwordMax)); make_pair((size_t)32u, ullDwordMax));
VERIFY_ARE_EQUAL( VERIFY_ARE_EQUAL(
m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, BinBase, BitLength::BitLengthWord), m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, BinBase, BitLength::BitLengthWord),
make_pair((size_t)16u, ullWordMax)); make_pair((size_t)16u, ullWordMax));
VERIFY_ARE_EQUAL( VERIFY_ARE_EQUAL(
m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, BinBase, BitLength::BitLengthByte), m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, BinBase, BitLength::BitLengthByte),
make_pair((size_t)8u, ullByteMax)); make_pair((size_t)8u, ullByteMax));
Logger::WriteMessage(L"Verify invalid ViewModes/Categories return 0 for max values"); Logger::WriteMessage(L"Verify invalid ViewModes/Categories return 0 for max values");
VERIFY_ARE_EQUAL( VERIFY_ARE_EQUAL(
m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::None, CategoryGroupType::None, -1, BitLength::BitLengthUnknown), m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::None, CategoryGroupType::None, - 1, BitLength::BitLengthUnknown),
make_pair((size_t)0u, 0ull)); make_pair((size_t)0u, 0ull));
}; };
TEST_METHOD(ValidateSanitizeOperand) TEST_METHOD(ValidateSanitizeOperand)
{ {
VERIFY_ARE_EQUAL(m_CopyPasteManager->SanitizeOperand(L"((1234"), L"1234"); VERIFY_ARE_EQUAL(m_CopyPasteManager.SanitizeOperand(L"((1234"), L"1234");
VERIFY_ARE_EQUAL(m_CopyPasteManager->SanitizeOperand(L"1234))"), L"1234"); VERIFY_ARE_EQUAL(m_CopyPasteManager.SanitizeOperand(L"1234))"), L"1234");
VERIFY_ARE_EQUAL(m_CopyPasteManager->SanitizeOperand(L"1234))"), L"1234"); VERIFY_ARE_EQUAL(m_CopyPasteManager.SanitizeOperand(L"1234))"), L"1234");
VERIFY_ARE_EQUAL(m_CopyPasteManager->SanitizeOperand(L"-1234"), L"1234"); VERIFY_ARE_EQUAL(m_CopyPasteManager.SanitizeOperand(L"-1234"), L"1234");
VERIFY_ARE_EQUAL(m_CopyPasteManager->SanitizeOperand(L"+1234"), L"1234"); VERIFY_ARE_EQUAL(m_CopyPasteManager.SanitizeOperand(L"+1234"), L"1234");
VERIFY_ARE_EQUAL(m_CopyPasteManager->SanitizeOperand(L"-(1234)"), L"1234"); VERIFY_ARE_EQUAL(m_CopyPasteManager.SanitizeOperand(L"-(1234)"), L"1234");
VERIFY_ARE_EQUAL(m_CopyPasteManager->SanitizeOperand(L"+(1234)"), L"1234"); VERIFY_ARE_EQUAL(m_CopyPasteManager.SanitizeOperand(L"+(1234)"), L"1234");
VERIFY_ARE_EQUAL(m_CopyPasteManager->SanitizeOperand(L"12-34"), L"1234"); VERIFY_ARE_EQUAL(m_CopyPasteManager.SanitizeOperand(L"12-34"), L"1234");
VERIFY_ARE_EQUAL(m_CopyPasteManager->SanitizeOperand(L"((((1234))))"), L"1234"); VERIFY_ARE_EQUAL(m_CopyPasteManager.SanitizeOperand(L"((((1234))))"), L"1234");
VERIFY_ARE_EQUAL(m_CopyPasteManager->SanitizeOperand(L"1'2'3'4"), L"1234"); VERIFY_ARE_EQUAL(m_CopyPasteManager.SanitizeOperand(L"1'2'3'4"), L"1234");
VERIFY_ARE_EQUAL(m_CopyPasteManager->SanitizeOperand(L"'''''1234''''"), L"1234"); VERIFY_ARE_EQUAL(m_CopyPasteManager.SanitizeOperand(L"'''''1234''''"), L"1234");
VERIFY_ARE_EQUAL(m_CopyPasteManager->SanitizeOperand(L"1_2_3_4"), L"1234"); VERIFY_ARE_EQUAL(m_CopyPasteManager.SanitizeOperand(L"1_2_3_4"), L"1234");
VERIFY_ARE_EQUAL(m_CopyPasteManager->SanitizeOperand(L"______1234___"), L"1234"); VERIFY_ARE_EQUAL(m_CopyPasteManager.SanitizeOperand(L"______1234___"), L"1234");
}; };
// Using unicode literals here until the encoding issues get figured out // Using unicode literals here until the encoding issues get figured out
TEST_METHOD(ValidatePrefixCurrencySymbols) TEST_METHOD(ValidatePrefixCurrencySymbols)
{ {
// ¥5 // ¥5
VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromWstring(L"\u00A5\u0035"), L"5"); VERIFY_ARE_EQUAL(m_CopyPasteManager.RemoveUnwantedCharsFromWstring(L"\u00A5\u0035"), L"5");
// ¤5 // ¤5
VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromWstring(L"\u00A4\u0035"), L"5"); VERIFY_ARE_EQUAL(m_CopyPasteManager.RemoveUnwantedCharsFromWstring(L"\u00A4\u0035"), L"5");
// ₵5 // ₵5
VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromWstring(L"\u20B5\u0035"), L"5"); VERIFY_ARE_EQUAL(m_CopyPasteManager.RemoveUnwantedCharsFromWstring(L"\u20B5\u0035"), L"5");
// $5 // $5
VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromWstring(L"\u0024\u0035"), L"5"); VERIFY_ARE_EQUAL(m_CopyPasteManager.RemoveUnwantedCharsFromWstring(L"\u0024\u0035"), L"5");
// ₡5 // ₡5
VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromWstring(L"\u20A1\u0035"), L"5"); VERIFY_ARE_EQUAL(m_CopyPasteManager.RemoveUnwantedCharsFromWstring(L"\u20A1\u0035"), L"5");
// ₩5 // ₩5
VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromWstring(L"\u20A9\u0035"), L"5"); VERIFY_ARE_EQUAL(m_CopyPasteManager.RemoveUnwantedCharsFromWstring(L"\u20A9\u0035"), L"5");
// ₪5 // ₪5
VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromWstring(L"\u20AA\u0035"), L"5"); VERIFY_ARE_EQUAL(m_CopyPasteManager.RemoveUnwantedCharsFromWstring(L"\u20AA\u0035"), L"5");
// ₦5 // ₦5
VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromWstring(L"\u20A6\u0035"), L"5"); VERIFY_ARE_EQUAL(m_CopyPasteManager.RemoveUnwantedCharsFromWstring(L"\u20A6\u0035"), L"5");
// ₹5 // ₹5
VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromWstring(L"\u20B9\u0035"), L"5"); VERIFY_ARE_EQUAL(m_CopyPasteManager.RemoveUnwantedCharsFromWstring(L"\u20B9\u0035"), L"5");
// £5 // £5
VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromWstring(L"\u00A3\u0035"), L"5"); VERIFY_ARE_EQUAL(m_CopyPasteManager.RemoveUnwantedCharsFromWstring(L"\u00A3\u0035"), L"5");
// €5 // €5
VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromWstring(L"\u20AC\u0035"), L"5"); VERIFY_ARE_EQUAL(m_CopyPasteManager.RemoveUnwantedCharsFromWstring(L"\u20AC\u0035"), L"5");
}; };
TEST_METHOD(ValidateTryOperandToULL) TEST_METHOD(ValidateTryOperandToULL)
@ -354,199 +353,199 @@ namespace CalculatorUnitTests
unsigned long long int result = 0; unsigned long long int result = 0;
Logger::WriteMessage(L"Verify TryOperandToULL HexBase conversion"); Logger::WriteMessage(L"Verify TryOperandToULL HexBase conversion");
VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"1234", HexBase, result)); VERIFY_IS_TRUE(m_CopyPasteManager.TryOperandToULL(L"1234", HexBase, result));
VERIFY_ARE_EQUAL(result, 0x1234ull); VERIFY_ARE_EQUAL(result, 0x1234ull);
VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"FF", HexBase, result)); VERIFY_IS_TRUE(m_CopyPasteManager.TryOperandToULL(L"FF", HexBase, result));
VERIFY_ARE_EQUAL(result, 0xFFull); VERIFY_ARE_EQUAL(result, 0xFFull);
VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"FFFFFFFFFFFFFFFF", HexBase, result)); VERIFY_IS_TRUE(m_CopyPasteManager.TryOperandToULL(L"FFFFFFFFFFFFFFFF", HexBase, result));
VERIFY_ARE_EQUAL(result, 0xFFFF'FFFF'FFFF'FFFF); VERIFY_ARE_EQUAL(result, 0xFFFF'FFFF'FFFF'FFFF);
VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"0xFFFFFFFFFFFFFFFF", HexBase, result)); VERIFY_IS_TRUE(m_CopyPasteManager.TryOperandToULL(L"0xFFFFFFFFFFFFFFFF", HexBase, result));
VERIFY_ARE_EQUAL(result, 0xFFFF'FFFF'FFFF'FFFF); VERIFY_ARE_EQUAL(result, 0xFFFF'FFFF'FFFF'FFFF);
VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"0XFFFFFFFFFFFFFFFF", HexBase, result)); VERIFY_IS_TRUE(m_CopyPasteManager.TryOperandToULL(L"0XFFFFFFFFFFFFFFFF", HexBase, result));
VERIFY_ARE_EQUAL(result, 0xFFFF'FFFF'FFFF'FFFF); VERIFY_ARE_EQUAL(result, 0xFFFF'FFFF'FFFF'FFFF);
VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"0X0FFFFFFFFFFFFFFFF", HexBase, result)); VERIFY_IS_TRUE(m_CopyPasteManager.TryOperandToULL(L"0X0FFFFFFFFFFFFFFFF", HexBase, result));
VERIFY_ARE_EQUAL(result, 0xFFFF'FFFF'FFFF'FFFF); VERIFY_ARE_EQUAL(result, 0xFFFF'FFFF'FFFF'FFFF);
Logger::WriteMessage(L"Verify TryOperandToULL DecBase conversion"); Logger::WriteMessage(L"Verify TryOperandToULL DecBase conversion");
VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"1234", DecBase, result)); VERIFY_IS_TRUE(m_CopyPasteManager.TryOperandToULL(L"1234", DecBase, result));
VERIFY_ARE_EQUAL(result, 1234ull); VERIFY_ARE_EQUAL(result, 1234ull);
VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"18446744073709551615", DecBase, result)); VERIFY_IS_TRUE(m_CopyPasteManager.TryOperandToULL(L"18446744073709551615", DecBase, result));
VERIFY_ARE_EQUAL(result, 0xFFFF'FFFF'FFFF'FFFF); VERIFY_ARE_EQUAL(result, 0xFFFF'FFFF'FFFF'FFFF);
VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"018446744073709551615", DecBase, result)); VERIFY_IS_TRUE(m_CopyPasteManager.TryOperandToULL(L"018446744073709551615", DecBase, result));
VERIFY_ARE_EQUAL(result, 0xFFFF'FFFF'FFFF'FFFF); VERIFY_ARE_EQUAL(result, 0xFFFF'FFFF'FFFF'FFFF);
Logger::WriteMessage(L"Verify TryOperandToULL OctBase conversion"); Logger::WriteMessage(L"Verify TryOperandToULL OctBase conversion");
VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"777", OctBase, result)); VERIFY_IS_TRUE(m_CopyPasteManager.TryOperandToULL(L"777", OctBase, result));
VERIFY_ARE_EQUAL(result, 0777ull); VERIFY_ARE_EQUAL(result, 0777ull);
VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"0777", OctBase, result)); VERIFY_IS_TRUE(m_CopyPasteManager.TryOperandToULL(L"0777", OctBase, result));
VERIFY_ARE_EQUAL(result, 0777ull); VERIFY_ARE_EQUAL(result, 0777ull);
VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"1777777777777777777777", OctBase, result)); VERIFY_IS_TRUE(m_CopyPasteManager.TryOperandToULL(L"1777777777777777777777", OctBase, result));
VERIFY_ARE_EQUAL(result, 0xFFFF'FFFF'FFFF'FFFF); VERIFY_ARE_EQUAL(result, 0xFFFF'FFFF'FFFF'FFFF);
VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"01777777777777777777777", OctBase, result)); VERIFY_IS_TRUE(m_CopyPasteManager.TryOperandToULL(L"01777777777777777777777", OctBase, result));
VERIFY_ARE_EQUAL(result, 0xFFFF'FFFF'FFFF'FFFF); VERIFY_ARE_EQUAL(result, 0xFFFF'FFFF'FFFF'FFFF);
Logger::WriteMessage(L"Verify TryOperandToULL BinBase conversion"); Logger::WriteMessage(L"Verify TryOperandToULL BinBase conversion");
VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"1111", BinBase, result)); VERIFY_IS_TRUE(m_CopyPasteManager.TryOperandToULL(L"1111", BinBase, result));
VERIFY_ARE_EQUAL(result, 0b1111ull); VERIFY_ARE_EQUAL(result, 0b1111ull);
VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"0010", BinBase, result)); VERIFY_IS_TRUE(m_CopyPasteManager.TryOperandToULL(L"0010", BinBase, result));
VERIFY_ARE_EQUAL(result, 0b10ull); VERIFY_ARE_EQUAL(result, 0b10ull);
VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"1111111111111111111111111111111111111111111111111111111111111111", BinBase, result)); VERIFY_IS_TRUE(m_CopyPasteManager.TryOperandToULL(L"1111111111111111111111111111111111111111111111111111111111111111", BinBase, result));
VERIFY_ARE_EQUAL(result, 0xFFFF'FFFF'FFFF'FFFF); VERIFY_ARE_EQUAL(result, 0xFFFF'FFFF'FFFF'FFFF);
VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"01111111111111111111111111111111111111111111111111111111111111111", BinBase, result)); VERIFY_IS_TRUE(m_CopyPasteManager.TryOperandToULL(L"01111111111111111111111111111111111111111111111111111111111111111", BinBase, result));
VERIFY_ARE_EQUAL(result, 0xFFFF'FFFF'FFFF'FFFF); VERIFY_ARE_EQUAL(result, 0xFFFF'FFFF'FFFF'FFFF);
Logger::WriteMessage(L"Verify TryOperandToULL invalid numberBase defaults to DecBase"); Logger::WriteMessage(L"Verify TryOperandToULL invalid numberBase defaults to DecBase");
VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"1234", 128, result)); VERIFY_IS_TRUE(m_CopyPasteManager.TryOperandToULL(L"1234", 128, result));
VERIFY_ARE_EQUAL(result, 1234ull); VERIFY_ARE_EQUAL(result, 1234ull);
Logger::WriteMessage(L"Verify TryOperandToULL returns false when input is invalid or strtoull throws exceptions"); Logger::WriteMessage(L"Verify TryOperandToULL returns false when input is invalid or strtoull throws exceptions");
// Max values + 1 // Max values + 1
VERIFY_IS_FALSE(m_CopyPasteManager->TryOperandToULL(L"0xFFFFFFFFFFFFFFFFF1", HexBase, result)); VERIFY_IS_FALSE(m_CopyPasteManager.TryOperandToULL(L"0xFFFFFFFFFFFFFFFFF1", HexBase, result));
VERIFY_IS_FALSE(m_CopyPasteManager->TryOperandToULL(L"18446744073709551616", DecBase, result)); VERIFY_IS_FALSE(m_CopyPasteManager.TryOperandToULL(L"18446744073709551616", DecBase, result));
VERIFY_IS_FALSE(m_CopyPasteManager->TryOperandToULL(L"2000000000000000000000", OctBase, result)); VERIFY_IS_FALSE(m_CopyPasteManager.TryOperandToULL(L"2000000000000000000000", OctBase, result));
VERIFY_IS_FALSE(m_CopyPasteManager->TryOperandToULL(L"11111111111111111111111111111111111111111111111111111111111111111", BinBase, result)); VERIFY_IS_FALSE(m_CopyPasteManager.TryOperandToULL(L"11111111111111111111111111111111111111111111111111111111111111111", BinBase, result));
// Invalid values/characters // Invalid values/characters
VERIFY_IS_FALSE(m_CopyPasteManager->TryOperandToULL(L"-1", DecBase, result)); VERIFY_IS_FALSE(m_CopyPasteManager.TryOperandToULL(L"-1", DecBase, result));
VERIFY_IS_FALSE(m_CopyPasteManager->TryOperandToULL(L"5555", BinBase, result)); VERIFY_IS_FALSE(m_CopyPasteManager.TryOperandToULL(L"5555", BinBase, result));
VERIFY_IS_FALSE(m_CopyPasteManager->TryOperandToULL(L"xyz", BinBase, result)); VERIFY_IS_FALSE(m_CopyPasteManager.TryOperandToULL(L"xyz", BinBase, result));
}; };
TEST_METHOD(ValidateStandardScientificOperandLength) TEST_METHOD(ValidateStandardScientificOperandLength)
{ {
VERIFY_ARE_EQUAL(m_CopyPasteManager->StandardScientificOperandLength(L""), 0); VERIFY_ARE_EQUAL(m_CopyPasteManager.StandardScientificOperandLength(L""), 0);
VERIFY_ARE_EQUAL(m_CopyPasteManager->StandardScientificOperandLength(L"0.2"), 1); VERIFY_ARE_EQUAL(m_CopyPasteManager.StandardScientificOperandLength(L"0.2"), 1);
VERIFY_ARE_EQUAL(m_CopyPasteManager->StandardScientificOperandLength(L"1.2"), 2); VERIFY_ARE_EQUAL(m_CopyPasteManager.StandardScientificOperandLength(L"1.2"), 2);
VERIFY_ARE_EQUAL(m_CopyPasteManager->StandardScientificOperandLength(L"0."), 0); VERIFY_ARE_EQUAL(m_CopyPasteManager.StandardScientificOperandLength(L"0."), 0);
VERIFY_ARE_EQUAL(m_CopyPasteManager->StandardScientificOperandLength(L"12345"), 5); VERIFY_ARE_EQUAL(m_CopyPasteManager.StandardScientificOperandLength(L"12345"), 5);
VERIFY_ARE_EQUAL(m_CopyPasteManager->StandardScientificOperandLength(L"-12345"), 6); VERIFY_ARE_EQUAL(m_CopyPasteManager.StandardScientificOperandLength(L"-12345"), 6);
}; };
TEST_METHOD(ValidateProgrammerOperandLength) TEST_METHOD(ValidateProgrammerOperandLength)
{ {
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"1001", BinBase), 4); VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"1001", BinBase), 4);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"1001b", BinBase), 4); VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"1001b", BinBase), 4);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"1001B", BinBase), 4); VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"1001B", BinBase), 4);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"0b1001", BinBase), 4); VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"0b1001", BinBase), 4);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"0B1001", BinBase), 4); VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"0B1001", BinBase), 4);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"0y1001", BinBase), 4); VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"0y1001", BinBase), 4);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"0Y1001", BinBase), 4); VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"0Y1001", BinBase), 4);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"0b", BinBase), 1); VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"0b", BinBase), 1);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"123456", OctBase), 6); VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"123456", OctBase), 6);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"0t123456", OctBase), 6); VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"0t123456", OctBase), 6);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"0T123456", OctBase), 6); VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"0T123456", OctBase), 6);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"0o123456", OctBase), 6); VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"0o123456", OctBase), 6);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"0O123456", OctBase), 6); VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"0O123456", OctBase), 6);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"", DecBase), 0); VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"", DecBase), 0);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"-", DecBase), 0); VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"-", DecBase), 0);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"12345", DecBase), 5); VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"12345", DecBase), 5);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"-12345", DecBase), 5); VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"-12345", DecBase), 5);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"0n12345", DecBase), 5); VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"0n12345", DecBase), 5);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"0N12345", DecBase), 5); VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"0N12345", DecBase), 5);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"123ABC", HexBase), 6); VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"123ABC", HexBase), 6);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"0x123ABC", HexBase), 6); VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"0x123ABC", HexBase), 6);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"0X123ABC", HexBase), 6); VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"0X123ABC", HexBase), 6);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"123ABCh", HexBase), 6); VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"123ABCh", HexBase), 6);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"123ABCH", HexBase), 6); VERIFY_ARE_EQUAL(m_CopyPasteManager.ProgrammerOperandLength(L"123ABCH", HexBase), 6);
}; };
private: private:
CopyPasteManager ^ m_CopyPasteManager; CopyPasteManager m_CopyPasteManager;
String^ ValidateStandardPasteExpression(_In_ String^ pastedText) String^ ValidateStandardPasteExpression(_In_ String^ pastedText)
{ {
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Standard, -1/*number base*/, BitLength::BitLengthUnknown); return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Standard, -1/*number base*/, BitLength::BitLengthUnknown);
} }
String^ ValidateScientificPasteExpression(_In_ String^ pastedText) String^ ValidateScientificPasteExpression(_In_ String^ pastedText)
{ {
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Scientific, -1/*number base*/, BitLength::BitLengthUnknown); return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Scientific, -1/*number base*/, BitLength::BitLengthUnknown);
} }
String^ ValidateConverterPasteExpression(_In_ String^ pastedText) String^ ValidateConverterPasteExpression(_In_ String^ pastedText)
{ {
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::None, CategoryGroupType::Converter, -1/*number base*/, BitLength::BitLengthUnknown); return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::None, CategoryGroupType::Converter, -1/*number base*/, BitLength::BitLengthUnknown);
} }
String^ ValidateProgrammerHexQwordPasteExpression(_In_ String^ pastedText) String^ ValidateProgrammerHexQwordPasteExpression(_In_ String^ pastedText)
{ {
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, HexBase/*number base*/, BitLength::BitLengthQWord); return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, HexBase/*number base*/, BitLength::BitLengthQWord);
} }
String^ ValidateProgrammerHexDwordPasteExpression(_In_ String^ pastedText) String^ ValidateProgrammerHexDwordPasteExpression(_In_ String^ pastedText)
{ {
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, HexBase/*number base*/, BitLength::BitLengthDWord); return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, HexBase/*number base*/, BitLength::BitLengthDWord);
} }
String^ ValidateProgrammerHexWordPasteExpression(_In_ String^ pastedText) String^ ValidateProgrammerHexWordPasteExpression(_In_ String^ pastedText)
{ {
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, HexBase/*number base*/, BitLength::BitLengthWord); return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, HexBase/*number base*/, BitLength::BitLengthWord);
} }
String^ ValidateProgrammerHexBytePasteExpression(_In_ String^ pastedText) String^ ValidateProgrammerHexBytePasteExpression(_In_ String^ pastedText)
{ {
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, HexBase/*number base*/, BitLength::BitLengthByte); return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, HexBase/*number base*/, BitLength::BitLengthByte);
} }
String^ ValidateProgrammerDecQwordPasteExpression(_In_ String^ pastedText) String^ ValidateProgrammerDecQwordPasteExpression(_In_ String^ pastedText)
{ {
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, DecBase/*number base*/, BitLength::BitLengthQWord); return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, DecBase/*number base*/, BitLength::BitLengthQWord);
} }
String^ ValidateProgrammerDecDwordPasteExpression(_In_ String^ pastedText) String^ ValidateProgrammerDecDwordPasteExpression(_In_ String^ pastedText)
{ {
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, DecBase/*number base*/, BitLength::BitLengthDWord); return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, DecBase/*number base*/, BitLength::BitLengthDWord);
} }
String^ ValidateProgrammerDecWordPasteExpression(_In_ String^ pastedText) String^ ValidateProgrammerDecWordPasteExpression(_In_ String^ pastedText)
{ {
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, DecBase/*number base*/, BitLength::BitLengthWord); return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, DecBase/*number base*/, BitLength::BitLengthWord);
} }
String^ ValidateProgrammerDecBytePasteExpression(_In_ String^ pastedText) String^ ValidateProgrammerDecBytePasteExpression(_In_ String^ pastedText)
{ {
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, DecBase/*number base*/, BitLength::BitLengthByte); return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, DecBase/*number base*/, BitLength::BitLengthByte);
} }
String^ ValidateProgrammerOctQwordPasteExpression(_In_ String^ pastedText) String^ ValidateProgrammerOctQwordPasteExpression(_In_ String^ pastedText)
{ {
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, OctBase/*number base*/, BitLength::BitLengthQWord); return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, OctBase/*number base*/, BitLength::BitLengthQWord);
} }
String^ ValidateProgrammerOctDwordPasteExpression(_In_ String^ pastedText) String^ ValidateProgrammerOctDwordPasteExpression(_In_ String^ pastedText)
{ {
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, OctBase/*number base*/, BitLength::BitLengthDWord); return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, OctBase/*number base*/, BitLength::BitLengthDWord);
} }
String^ ValidateProgrammerOctWordPasteExpression(_In_ String^ pastedText) String^ ValidateProgrammerOctWordPasteExpression(_In_ String^ pastedText)
{ {
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, OctBase/*number base*/, BitLength::BitLengthWord); return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, OctBase/*number base*/, BitLength::BitLengthWord);
} }
String^ ValidateProgrammerOctBytePasteExpression(_In_ String^ pastedText) String^ ValidateProgrammerOctBytePasteExpression(_In_ String^ pastedText)
{ {
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, OctBase/*number base*/, BitLength::BitLengthByte); return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, OctBase/*number base*/, BitLength::BitLengthByte);
} }
String^ ValidateProgrammerBinQwordPasteExpression(_In_ String^ pastedText) String^ ValidateProgrammerBinQwordPasteExpression(_In_ String^ pastedText)
{ {
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, BinBase/*number base*/, BitLength::BitLengthQWord); return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, BinBase/*number base*/, BitLength::BitLengthQWord);
} }
String^ ValidateProgrammerBinDwordPasteExpression(_In_ String^ pastedText) String^ ValidateProgrammerBinDwordPasteExpression(_In_ String^ pastedText)
{ {
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, BinBase/*number base*/, BitLength::BitLengthDWord); return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, BinBase/*number base*/, BitLength::BitLengthDWord);
} }
String^ ValidateProgrammerBinWordPasteExpression(_In_ String^ pastedText) String^ ValidateProgrammerBinWordPasteExpression(_In_ String^ pastedText)
{ {
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, BinBase/*number base*/, BitLength::BitLengthWord); return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, BinBase/*number base*/, BitLength::BitLengthWord);
} }
String^ ValidateProgrammerBinBytePasteExpression(_In_ String^ pastedText) String^ ValidateProgrammerBinBytePasteExpression(_In_ String^ pastedText)
{ {
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, BinBase/*number base*/, BitLength::BitLengthByte); return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, BinBase/*number base*/, BitLength::BitLengthByte);
} }
}; };
@ -603,38 +602,41 @@ namespace CalculatorUnitTests
void CopyPasteManagerTest::ValidateStandardPasteExpressionTest() void CopyPasteManagerTest::ValidateStandardPasteExpressionTest()
{ {
String ^ positiveInput[] = { String ^ positiveInput[] = { L"123",
L"123", L"+123",
L"+123", L"-133",
L"-133", L"12345.",
L"12345.", L"+12.34",
L"+12.34", L"12.345",
L"12.345", L"012.034",
L"012.034", L"-23.032",
L"-23.032", L"-.123",
L"-.123", L".1234",
L".1234", L"012.012",
L"012.012", L"123+456",
L"123+456", L"123+-234",
L"123+-234", L"123*-345",
L"123*-345", L"123*4*-3",
L"123*4*-3", L"123*+4*-3",
L"123*+4*-3", L"1,234",
L"1,234", L"1 2 3",
L"1 2 3", L"\n\r1,234\n",
L"\n\r1,234\n", L"\f\n1+2\t\r\v\x85",
L"\f\n1+2\t\r\v\x85", L"\n 1+\n2 ",
L"\n 1+\n2 ", L"1\"2",
L"1\"2", L"1234567891234567" /*boundary condition <=16 digits*/,
L"1234567891234567" /*boundary condition <=16 digits*/, L"2+2=",
L"2+2=", L"2+2= ",
L"2+2= ", L"1.2e23",
L"1.2e23", L"12345e-23",
L"12345e-23",
}; };
String ^ negativeInput[] = { L"(123)+(456)", L"abcdef", L"xyz", L"ABab", L"e+234", L"12345678912345678" /*boundary condition: greater than 16 digits*/, String ^ negativeInput[] = { L"(123)+(456)", L"abcdef",
L"SIN(2)", L"2+2==", L"2=+2", L"2%2", L"10^2" }; L"xyz", L"ABab",
L"e+234", L"12345678912345678" /*boundary condition: greater than 16 digits*/,
L"SIN(2)", L"2+2==",
L"2=+2", L"2%2",
L"10^2" };
ASSERT_POSITIVE_TESTCASES(ValidateStandardPasteExpression, positiveInput); ASSERT_POSITIVE_TESTCASES(ValidateStandardPasteExpression, positiveInput);
ASSERT_NEGATIVE_TESTCASES(ValidateStandardPasteExpression, negativeInput); ASSERT_NEGATIVE_TESTCASES(ValidateStandardPasteExpression, negativeInput);
@ -672,14 +674,19 @@ namespace CalculatorUnitTests
"-(432+3232)", "-(432+3232)",
"-(+(-3213)+(-2312))", "-(+(-3213)+(-2312))",
"-(-(432+3232))", "-(-(432+3232))",
L"1.2e23" /*unsigned exponent*/, L"1.2e23"/*unsigned exponent*/,
L"12^2", L"12^2",
L"-12.12^-2", L"-12.12^-2",
L"61%99" L"61%99"
L"-6.1%99" }; L"-6.1%99" };
String String ^ negativeInput[] = { L"abcdef",
^ negativeInput[] = { L"abcdef", L"xyz", L"ABab", L"e+234", L"123456789123456781234567890123456" /*boundary condition: greater than 32 digits*/, L"xyz",
L"SIN(2)", L"2+2==", L"2=+2" }; L"ABab",
L"e+234",
L"123456789123456781234567890123456" /*boundary condition: greater than 32 digits*/,
L"SIN(2)",
L"2+2==",
L"2=+2" };
ASSERT_POSITIVE_TESTCASES(ValidateScientificPasteExpression, positiveInput); ASSERT_POSITIVE_TESTCASES(ValidateScientificPasteExpression, positiveInput);
ASSERT_NEGATIVE_TESTCASES(ValidateScientificPasteExpression, negativeInput); ASSERT_NEGATIVE_TESTCASES(ValidateScientificPasteExpression, negativeInput);
@ -1065,8 +1072,8 @@ namespace CalculatorUnitTests
void CopyPasteManagerTest::ValidateProgrammerOctPasteExpressionTest() void CopyPasteManagerTest::ValidateProgrammerOctPasteExpressionTest()
{ {
String ^ qwordPositiveInput[] = { L"123", L"123+456", L"1,234", L"1 2 3", L"1'2'3'4", L"1_2_3_4", L"\n\r1,234\n", L"\f\n1+2\t\r\v\x85", String ^ qwordPositiveInput[] = { L"123", L"123+456", L"1,234", L"1 2 3", L"1'2'3'4", L"1_2_3_4", L"\n\r1,234\n", L"\f\n1+2\t\r\v\x85",
L"\n 1+\n2 ", L"1\"2", L"(123)+(456)", L"0t1234", L"0T1234", L"0o1234", L"0O1234", L"1234u", L"\n 1+\n2 ", L"1\"2", L"(123)+(456)", L"0t1234", L"0T1234", L"0o1234", L"0O1234", L"1234u",
L"1234ul", L"1234ULL", L"2+2=", L"2+2= ", L"127%71" }; L"1234ul", L"1234ULL", L"2+2=", L"2+2= ", L"127%71" };
String ^ qwordNegativeInput[] = { L"+123", String ^ qwordNegativeInput[] = { L"+123",
L"1.23", L"1.23",
@ -1092,7 +1099,7 @@ namespace CalculatorUnitTests
L"1234ulll", L"1234ulll",
L"2+2==", L"2+2==",
L"2=+2", L"2=+2",
L"89%12" }; L"89%12"};
ASSERT_POSITIVE_TESTCASES(ValidateProgrammerOctQwordPasteExpression, qwordPositiveInput); ASSERT_POSITIVE_TESTCASES(ValidateProgrammerOctQwordPasteExpression, qwordPositiveInput);
ASSERT_NEGATIVE_TESTCASES(ValidateProgrammerOctQwordPasteExpression, qwordNegativeInput); ASSERT_NEGATIVE_TESTCASES(ValidateProgrammerOctQwordPasteExpression, qwordNegativeInput);

View File

@ -75,7 +75,7 @@ namespace CalculatorFunctionalTests
{ {
m_standardViewModel->SetHistoryExpressionDisplay(e->GetTokens(), e->GetCommands()); m_standardViewModel->SetHistoryExpressionDisplay(e->GetTokens(), e->GetCommands());
m_standardViewModel->SetExpressionDisplay(e->GetTokens(), e->GetCommands()); m_standardViewModel->SetExpressionDisplay(e->GetTokens(), e->GetCommands());
m_standardViewModel->SetPrimaryDisplay(e->Result, false /*IsError*/); m_standardViewModel->SetPrimaryDisplay(e->Result->Data(), false /*IsError*/);
m_standardViewModel->IsFToEEnabled = false; m_standardViewModel->IsFToEEnabled = false;
} }