Convert CopyPasteManager to runtime class (#766)

* Convert CopyPasteManager to runtime class
* merge AssertUtils and Helpers.h
* update onpastemanager
This commit is contained in:
Rudy Huyn
2019-11-13 15:15:13 -08:00
committed by GitHub
parent a217e0534b
commit b9b0e068cd
15 changed files with 604 additions and 360 deletions

View File

@@ -6,12 +6,14 @@
#include "CalcViewModel/StandardCalculatorViewModel.h"
#include "CalcViewModel/Common/CopyPasteManager.h"
#include "Helpers.h"
using namespace CalculationManager;
using namespace CalculatorApp;
using namespace CalculatorApp::Common;
using namespace CalculatorApp::ViewModel;
using namespace Platform;
using namespace Platform::Collections;
using namespace std;
using namespace Windows::ApplicationModel::DataTransfer;
using namespace Windows::ApplicationModel::Resources;
@@ -39,6 +41,13 @@ namespace CalculatorUnitTests
} \
}
#define VERIFY_MAXOPERANDLENGTHANDVALUE_ARE_EQUALS(ref, length, value, ...) \
{ \
auto result = ref; \
Assert::IsTrue(ref.maxLength == length, __VA_ARGS__); \
Assert::IsTrue(ref.maxValue == value, __VA_ARGS__); \
}
TEST_CLASS(CopyPasteManagerTest)
{
public:
@@ -58,36 +67,45 @@ namespace CalculatorUnitTests
TEST_METHOD(ValidatePasteExpressionErrorStates)
{
wstring exp_TooLong = L"";
for (int i = 0; i < m_CopyPasteManager->MaxPasteableLength / 8; i++)
for (unsigned int i = 0; i < CopyPasteManager::MaxPasteableLength / 8; i++)
{
exp_TooLong += L"-1234567";
}
VERIFY_ARE_EQUAL(
m_CopyPasteManager->ValidatePasteExpression(
StringReference(exp_TooLong.c_str()), ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown),
StringReference(exp_TooLong.c_str()),
ViewMode::Standard,
CategoryGroupType::Calculator,
NumberBase::Unknown,
BitLength::BitLengthUnknown),
StringReference(exp_TooLong.c_str()),
L"Verify ValidatePasteExpression handles expressions up to max length");
exp_TooLong += L'1';
exp_TooLong += L"1";
VERIFY_ARE_EQUAL(
m_CopyPasteManager->ValidatePasteExpression(
StringReference(exp_TooLong.c_str()), ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown),
StringReference(exp_TooLong.c_str()),
ViewMode::Standard,
CategoryGroupType::Calculator,
NumberBase::Unknown,
BitLength::BitLengthUnknown),
StringReference(L"NoOp"),
L"Verify ValidatePasteExpression returns NoOp for strings over max length");
VERIFY_ARE_EQUAL(
m_CopyPasteManager->ValidatePasteExpression(
StringReference(L""), ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown),
StringReference(L""), ViewMode::Standard, CategoryGroupType::Calculator, NumberBase::Unknown, BitLength::BitLengthUnknown),
StringReference(L"NoOp"),
L"Verify empty string is invalid");
VERIFY_ARE_EQUAL(
m_CopyPasteManager->ValidatePasteExpression(
StringReference(L"1a23f456"), ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown),
StringReference(L"1a23f456"), ViewMode::Standard, CategoryGroupType::Calculator, NumberBase::Unknown, BitLength::BitLengthUnknown),
StringReference(L"NoOp"),
L"Verify pasting unsupported strings for the current mode is invalid");
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, NumberBase::Unknown, BitLength::BitLengthUnknown),
StringReference(L"NoOp"),
L"Verify pasting without a ViewMode or Category is invalid");
};
@@ -96,48 +114,57 @@ namespace CalculatorUnitTests
{
vector<wstring> results = {};
vector<wstring> oneOperand = { L"123456" };
VERIFY_ARE_EQUAL(m_CopyPasteManager->ExtractOperands(L"123456", ViewMode::Standard), oneOperand);
oneOperand = { L"123^456" };
VERIFY_ARE_EQUAL(m_CopyPasteManager->ExtractOperands(L"123^456", ViewMode::Standard), oneOperand);
auto oneOperand = ref new Vector<String ^>();
oneOperand->Append(L"123456");
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_VECTORS_ARE_EQUAL(CopyPasteManager::ExtractOperands(L"123456", ViewMode::Standard), oneOperand);
oneOperand->Clear();
oneOperand->Append(L"123^456");
VERIFY_VECTORS_ARE_EQUAL(CopyPasteManager::ExtractOperands(L"123^456", ViewMode::Standard), oneOperand);
vector<wstring> expOperand = { L"123e456" };
VERIFY_ARE_EQUAL(m_CopyPasteManager->ExtractOperands(L"123e456", ViewMode::Standard), expOperand);
expOperand = { L"123e4567" };
VERIFY_ARE_EQUAL(m_CopyPasteManager->ExtractOperands(L"123e4567", ViewMode::Standard), expOperand);
auto twoOperands = ref new Vector<String ^>();
twoOperands->Append(L"123");
twoOperands->Append(L"456");
VERIFY_VECTORS_ARE_EQUAL(CopyPasteManager::ExtractOperands(L"123+456", ViewMode::Standard), twoOperands);
VERIFY_VECTORS_ARE_EQUAL(CopyPasteManager::ExtractOperands(L"123-456", ViewMode::Standard), twoOperands);
VERIFY_VECTORS_ARE_EQUAL(CopyPasteManager::ExtractOperands(L"123*456", ViewMode::Standard), twoOperands);
VERIFY_VECTORS_ARE_EQUAL(CopyPasteManager::ExtractOperands(L"123/456", ViewMode::Standard), twoOperands);
vector<wstring> twoOperandsParens = { L"((45)", L"(-30))" };
VERIFY_ARE_EQUAL(m_CopyPasteManager->ExtractOperands(L"((45)+(-30))", ViewMode::Scientific), twoOperandsParens);
auto expOperand = ref new Vector<String ^>();
expOperand->Append(L"123e456");
VERIFY_VECTORS_ARE_EQUAL(CopyPasteManager::ExtractOperands(L"123e456", ViewMode::Standard), expOperand);
expOperand->Clear();
expOperand->Append(L"123e4567");
VERIFY_VECTORS_ARE_EQUAL(CopyPasteManager::ExtractOperands(L"123e4567", ViewMode::Standard), expOperand);
auto twoOperandsParens = ref new Vector<String ^>();
twoOperandsParens->Append(L"((45)");
twoOperandsParens->Append(L"(-30))");
VERIFY_VECTORS_ARE_EQUAL(CopyPasteManager::ExtractOperands(L"((45)+(-30))", ViewMode::Scientific), twoOperandsParens);
};
TEST_METHOD(ValidateExtractOperandsErrors)
{
wstring exp_OperandLimit = L"";
for (int i = 0; i < m_CopyPasteManager->MaxOperandCount; i++)
auto exp_OperandLimit = ref new String(L"");
for (unsigned int i = 0; i < m_CopyPasteManager->MaxOperandCount; i++)
{
exp_OperandLimit += L"+1";
}
VERIFY_ARE_EQUAL(
m_CopyPasteManager->ExtractOperands(exp_OperandLimit, ViewMode::Standard).size(),
CopyPasteManager::ExtractOperands(exp_OperandLimit, ViewMode::Standard)->Size,
100,
L"Verify ExtractOperands handles up to MaxOperandCount operands");
exp_OperandLimit += L"+1";
VERIFY_ARE_EQUAL(
m_CopyPasteManager->ExtractOperands(exp_OperandLimit, ViewMode::Standard).size(),
CopyPasteManager::ExtractOperands(exp_OperandLimit, ViewMode::Standard)->Size,
0,
L"Verify ExtractOperands returns empty vector on too many operands");
VERIFY_ARE_EQUAL(
m_CopyPasteManager->ExtractOperands(L"12e9999", ViewMode::Standard).size(), 1, L"Verify ExtractOperands handles up to 4 digit exponents");
CopyPasteManager::ExtractOperands(L"12e9999", ViewMode::Standard)->Size, 1, L"Verify ExtractOperands handles up to 4 digit exponents");
VERIFY_ARE_EQUAL(
m_CopyPasteManager->ExtractOperands(L"12e10000", ViewMode::Standard).size(),
CopyPasteManager::ExtractOperands(L"12e10000", ViewMode::Standard)->Size,
0,
L"Verify ExtractOperands returns empty vector when the exponent is too long");
};
@@ -145,164 +172,263 @@ namespace CalculatorUnitTests
TEST_METHOD(ValidateExpressionRegExMatch)
{
VERIFY_IS_FALSE(
m_CopyPasteManager->ExpressionRegExMatch(vector<wstring>{}, ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown),
m_CopyPasteManager->ExpressionRegExMatch(
ref new Vector<String ^>(), ViewMode::Standard, CategoryGroupType::Calculator, NumberBase::Unknown, BitLength::BitLengthUnknown),
L"Verify empty list of operands returns false.");
VERIFY_IS_FALSE(
m_CopyPasteManager->ExpressionRegExMatch(
vector<wstring>{ L"123" }, ViewMode::None, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown),
ref new Vector<String ^>({ L"123" }),
ViewMode::None,
CategoryGroupType::Calculator,
NumberBase::Unknown,
BitLength::BitLengthUnknown),
L"Verify invalid ViewMode/CategoryGroups return false.");
VERIFY_IS_FALSE(
m_CopyPasteManager->ExpressionRegExMatch(
vector<wstring>{ L"123" }, ViewMode::Currency, CategoryGroupType::None, -1, BitLength::BitLengthUnknown),
ref new Vector<String ^>({ L"123" }),
ViewMode::Currency,
CategoryGroupType::None,
NumberBase::Unknown,
BitLength::BitLengthUnknown),
L"Verify invalid ViewMode/CategoryGroups return false.");
Logger::WriteMessage(L"Verify operand lengths > max return false.");
VERIFY_IS_FALSE(m_CopyPasteManager->ExpressionRegExMatch(
vector<wstring>{ L"12345678901234567" }, ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown));
ref new Vector<String ^>({ L"12345678901234567" }),
ViewMode::Standard,
CategoryGroupType::Calculator,
NumberBase::Unknown,
BitLength::BitLengthUnknown));
VERIFY_IS_FALSE(m_CopyPasteManager->ExpressionRegExMatch(
vector<wstring>{ L"123456789012345678901234567890123" }, ViewMode::Scientific, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown));
ref new Vector<String ^>({ L"123456789012345678901234567890123" }),
ViewMode::Scientific,
CategoryGroupType::Calculator,
NumberBase::Unknown,
BitLength::BitLengthUnknown));
VERIFY_IS_FALSE(m_CopyPasteManager->ExpressionRegExMatch(
vector<wstring>{ L"12345678901234567" }, ViewMode::None, CategoryGroupType::Converter, -1, BitLength::BitLengthUnknown));
ref new Vector<String ^>({ L"12345678901234567" }),
ViewMode::None,
CategoryGroupType::Converter,
NumberBase::Unknown,
BitLength::BitLengthUnknown));
VERIFY_IS_FALSE(m_CopyPasteManager->ExpressionRegExMatch(
vector<wstring>{ L"11111111111111111" }, ViewMode::Programmer, CategoryGroupType::Calculator, HexBase, BitLength::BitLengthQWord));
VERIFY_IS_FALSE(m_CopyPasteManager->ExpressionRegExMatch(
vector<wstring>{ L"12345678901234567890" }, ViewMode::Programmer, CategoryGroupType::Calculator, DecBase, BitLength::BitLengthQWord));
VERIFY_IS_FALSE(m_CopyPasteManager->ExpressionRegExMatch(
vector<wstring>{ L"11111111111111111111111" }, ViewMode::Programmer, CategoryGroupType::Calculator, OctBase, BitLength::BitLengthQWord));
VERIFY_IS_FALSE(m_CopyPasteManager->ExpressionRegExMatch(
vector<wstring>{ L"10000000000000000000000000000000000000000000000000000000000000000" },
ref new Vector<String ^>({ L"11111111111111111" }),
ViewMode::Programmer,
CategoryGroupType::Calculator,
BinBase,
NumberBase::HexBase,
BitLength::BitLengthQWord));
VERIFY_IS_FALSE(m_CopyPasteManager->ExpressionRegExMatch(
ref new Vector<String ^>({ L"12345678901234567890" }),
ViewMode::Programmer,
CategoryGroupType::Calculator,
NumberBase::DecBase,
BitLength::BitLengthQWord));
VERIFY_IS_FALSE(m_CopyPasteManager->ExpressionRegExMatch(
ref new Vector<String ^>({ L"11111111111111111111111" }),
ViewMode::Programmer,
CategoryGroupType::Calculator,
NumberBase::OctBase,
BitLength::BitLengthQWord));
VERIFY_IS_FALSE(m_CopyPasteManager->ExpressionRegExMatch(
ref new Vector<String ^>({ L"10000000000000000000000000000000000000000000000000000000000000000" }),
ViewMode::Programmer,
CategoryGroupType::Calculator,
NumberBase::BinBase,
BitLength::BitLengthQWord));
VERIFY_IS_FALSE(
m_CopyPasteManager->ExpressionRegExMatch(
vector<wstring>{ L"9223372036854775808" }, ViewMode::Programmer, CategoryGroupType::Calculator, DecBase, BitLength::BitLengthQWord),
ref new Vector<String ^>({ L"9223372036854775808" }),
ViewMode::Programmer,
CategoryGroupType::Calculator,
NumberBase::DecBase,
BitLength::BitLengthQWord),
L"Verify operand values > max return false.");
VERIFY_IS_TRUE(
m_CopyPasteManager->ExpressionRegExMatch(
vector<wstring>{ L"((((((((((((((((((((123))))))))))))))))))))" },
ref new Vector<String ^>({ L"((((((((((((((((((((123))))))))))))))))))))" }),
ViewMode::Scientific,
CategoryGroupType::Calculator,
-1,
NumberBase::Unknown,
BitLength::BitLengthUnknown),
L"Verify sanitized operand is detected as within max length.");
VERIFY_IS_TRUE(
m_CopyPasteManager->ExpressionRegExMatch(
vector<wstring>{ L"9223372036854775807" }, ViewMode::Programmer, CategoryGroupType::Calculator, DecBase, BitLength::BitLengthQWord),
ref new Vector<String ^>({ L"9223372036854775807" }),
ViewMode::Programmer,
CategoryGroupType::Calculator,
NumberBase::DecBase,
BitLength::BitLengthQWord),
L"Verify operand values == max return true.");
Logger::WriteMessage(L"Verify all operands must match patterns.");
VERIFY_IS_TRUE(m_CopyPasteManager->ExpressionRegExMatch(
vector<wstring>{ L"123", L"456" }, ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown));
ref new Vector<String ^>({ L"123", L"456" }),
ViewMode::Standard,
CategoryGroupType::Calculator,
NumberBase::Unknown,
BitLength::BitLengthUnknown));
VERIFY_IS_TRUE(m_CopyPasteManager->ExpressionRegExMatch(
vector<wstring>{ L"123", L"1e23" }, ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown));
ref new Vector<String ^>({ L"123", L"1e23" }),
ViewMode::Standard,
CategoryGroupType::Calculator,
NumberBase::Unknown,
BitLength::BitLengthUnknown));
VERIFY_IS_FALSE(m_CopyPasteManager->ExpressionRegExMatch(
vector<wstring>{ L"123", L"fab10" }, ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown));
ref new Vector<String ^>({ L"123", L"fab10" }),
ViewMode::Standard,
CategoryGroupType::Calculator,
NumberBase::Unknown,
BitLength::BitLengthUnknown));
VERIFY_IS_TRUE(
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" },
ref new Vector<String ^>(
{ 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,
CategoryGroupType::Calculator,
-1,
NumberBase::Unknown,
BitLength::BitLengthUnknown),
L"Verify exponents are accepted in scientific mode.");
VERIFY_IS_FALSE(
m_CopyPasteManager->ExpressionRegExMatch(
vector<wstring>{ L"123", L"12345678901234567" }, ViewMode::Standard, CategoryGroupType::Calculator, -1, BitLength::BitLengthUnknown),
ref new Vector<String ^>({ L"123", L"12345678901234567" }),
ViewMode::Standard,
CategoryGroupType::Calculator,
NumberBase::Unknown,
BitLength::BitLengthUnknown),
L"Verify all operands must be within maxlength");
VERIFY_IS_FALSE(
m_CopyPasteManager->ExpressionRegExMatch(
vector<wstring>{ L"123", L"9223372036854775808" }, ViewMode::Programmer, CategoryGroupType::Calculator, DecBase, BitLength::BitLengthQWord),
ref new Vector<String ^>({ L"123", L"9223372036854775808" }),
ViewMode::Programmer,
CategoryGroupType::Calculator,
NumberBase::DecBase,
BitLength::BitLengthQWord),
L"Verify all operand must be within max value.");
};
TEST_METHOD(ValidateGetMaxOperandLengthAndValue)
{
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> converterModeMaximums = make_pair(m_CopyPasteManager->MaxConverterInputLength, 0);
VERIFY_ARE_EQUAL(
m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Standard, CategoryGroupType::None, -1, BitLength::BitLengthUnknown),
standardModeMaximums,
VERIFY_MAXOPERANDLENGTHANDVALUE_ARE_EQUALS(
m_CopyPasteManager->GetMaxOperandLengthAndValue(
ViewMode::Standard, CategoryGroupType::None, NumberBase::Unknown, BitLength::BitLengthUnknown),
m_CopyPasteManager->MaxStandardOperandLength,
0,
L"Verify Standard mode maximum values");
VERIFY_ARE_EQUAL(
m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Scientific, CategoryGroupType::None, -1, BitLength::BitLengthUnknown),
scientificModeMaximums,
VERIFY_MAXOPERANDLENGTHANDVALUE_ARE_EQUALS(
m_CopyPasteManager->GetMaxOperandLengthAndValue(
ViewMode::Scientific, CategoryGroupType::None, NumberBase::Unknown, BitLength::BitLengthUnknown),
m_CopyPasteManager->MaxScientificOperandLength,
0,
L"Verify Scientific mode maximum values");
VERIFY_ARE_EQUAL(
m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::None, CategoryGroupType::Converter, -1, BitLength::BitLengthUnknown),
converterModeMaximums,
VERIFY_MAXOPERANDLENGTHANDVALUE_ARE_EQUALS(
m_CopyPasteManager->GetMaxOperandLengthAndValue(
ViewMode::None, CategoryGroupType::Converter, NumberBase::Unknown, BitLength::BitLengthUnknown),
m_CopyPasteManager->MaxConverterInputLength,
0,
L"Verify Converter mode maximum values");
unsigned long long int ullQwordMax = UINT64_MAX;
unsigned long long int ullDwordMax = UINT32_MAX;
unsigned long long int ullWordMax = UINT16_MAX;
unsigned long long int ullByteMax = UINT8_MAX;
Logger::WriteMessage(L"Verify Programmer Mode HexBase maximum values");
VERIFY_ARE_EQUAL(
m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, HexBase, BitLength::BitLengthQWord),
make_pair((size_t)16u, ullQwordMax));
VERIFY_ARE_EQUAL(
m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, HexBase, BitLength::BitLengthDWord),
make_pair((size_t)8u, ullDwordMax));
VERIFY_ARE_EQUAL(
m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, HexBase, BitLength::BitLengthWord),
make_pair((size_t)4u, ullWordMax));
VERIFY_ARE_EQUAL(
m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, HexBase, BitLength::BitLengthByte),
make_pair((size_t)2u, ullByteMax));
Logger::WriteMessage(L"Verify Programmer Mode NumberBase::HexBase maximum values");
VERIFY_MAXOPERANDLENGTHANDVALUE_ARE_EQUALS(
m_CopyPasteManager->GetMaxOperandLengthAndValue(
ViewMode::Programmer, CategoryGroupType::None, NumberBase::HexBase, BitLength::BitLengthQWord),
16u,
ullQwordMax);
VERIFY_MAXOPERANDLENGTHANDVALUE_ARE_EQUALS(
m_CopyPasteManager->GetMaxOperandLengthAndValue(
ViewMode::Programmer, CategoryGroupType::None, NumberBase::HexBase, BitLength::BitLengthDWord),
8u,
ullDwordMax);
VERIFY_MAXOPERANDLENGTHANDVALUE_ARE_EQUALS(
m_CopyPasteManager->GetMaxOperandLengthAndValue(
ViewMode::Programmer, CategoryGroupType::None, NumberBase::HexBase, BitLength::BitLengthWord),
4u,
ullWordMax);
VERIFY_MAXOPERANDLENGTHANDVALUE_ARE_EQUALS(
m_CopyPasteManager->GetMaxOperandLengthAndValue(
ViewMode::Programmer, CategoryGroupType::None, NumberBase::HexBase, BitLength::BitLengthByte),
2u,
ullByteMax);
Logger::WriteMessage(L"Verify Programmer Mode DecBase maximum values");
VERIFY_ARE_EQUAL(
m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, DecBase, BitLength::BitLengthQWord),
make_pair((size_t)19u, ullQwordMax >> 1));
VERIFY_ARE_EQUAL(
m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, DecBase, BitLength::BitLengthDWord),
make_pair((size_t)10u, ullDwordMax >> 1));
VERIFY_ARE_EQUAL(
m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, DecBase, BitLength::BitLengthWord),
make_pair((size_t)5u, ullWordMax >> 1));
VERIFY_ARE_EQUAL(
m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, DecBase, BitLength::BitLengthByte),
make_pair((size_t)3u, ullByteMax >> 1));
Logger::WriteMessage(L"Verify Programmer Mode NumberBase::DecBase maximum values");
VERIFY_MAXOPERANDLENGTHANDVALUE_ARE_EQUALS(
m_CopyPasteManager->GetMaxOperandLengthAndValue(
ViewMode::Programmer, CategoryGroupType::None, NumberBase::DecBase, BitLength::BitLengthQWord),
19u,
ullQwordMax >> 1);
VERIFY_MAXOPERANDLENGTHANDVALUE_ARE_EQUALS(
m_CopyPasteManager->GetMaxOperandLengthAndValue(
ViewMode::Programmer, CategoryGroupType::None, NumberBase::DecBase, BitLength::BitLengthDWord),
10u,
ullDwordMax >> 1);
VERIFY_MAXOPERANDLENGTHANDVALUE_ARE_EQUALS(
m_CopyPasteManager->GetMaxOperandLengthAndValue(
ViewMode::Programmer, CategoryGroupType::None, NumberBase::DecBase, BitLength::BitLengthWord),
5u,
ullWordMax >> 1);
VERIFY_MAXOPERANDLENGTHANDVALUE_ARE_EQUALS(
m_CopyPasteManager->GetMaxOperandLengthAndValue(
ViewMode::Programmer, CategoryGroupType::None, NumberBase::DecBase, BitLength::BitLengthByte),
3u,
ullByteMax >> 1);
Logger::WriteMessage(L"Verify Programmer Mode OctBase maximum values");
VERIFY_ARE_EQUAL(
m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, OctBase, BitLength::BitLengthQWord),
make_pair((size_t)22u, ullQwordMax));
VERIFY_ARE_EQUAL(
m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, OctBase, BitLength::BitLengthDWord),
make_pair((size_t)11u, ullDwordMax));
VERIFY_ARE_EQUAL(
m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, OctBase, BitLength::BitLengthWord),
make_pair((size_t)6u, ullWordMax));
VERIFY_ARE_EQUAL(
m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, OctBase, BitLength::BitLengthByte),
make_pair((size_t)3u, ullByteMax));
Logger::WriteMessage(L"Verify Programmer Mode NumberBase::OctBase maximum values");
VERIFY_MAXOPERANDLENGTHANDVALUE_ARE_EQUALS(
m_CopyPasteManager->GetMaxOperandLengthAndValue(
ViewMode::Programmer, CategoryGroupType::None, NumberBase::OctBase, BitLength::BitLengthQWord),
22u,
ullQwordMax);
VERIFY_MAXOPERANDLENGTHANDVALUE_ARE_EQUALS(
m_CopyPasteManager->GetMaxOperandLengthAndValue(
ViewMode::Programmer, CategoryGroupType::None, NumberBase::OctBase, BitLength::BitLengthDWord),
11u,
ullDwordMax);
VERIFY_MAXOPERANDLENGTHANDVALUE_ARE_EQUALS(
m_CopyPasteManager->GetMaxOperandLengthAndValue(
ViewMode::Programmer, CategoryGroupType::None, NumberBase::OctBase, BitLength::BitLengthWord),
6u,
ullWordMax);
VERIFY_MAXOPERANDLENGTHANDVALUE_ARE_EQUALS(
m_CopyPasteManager->GetMaxOperandLengthAndValue(
ViewMode::Programmer, CategoryGroupType::None, NumberBase::OctBase, BitLength::BitLengthByte),
3u,
ullByteMax);
Logger::WriteMessage(L"Verify Programmer Mode BinBase maximum values");
VERIFY_ARE_EQUAL(
m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, BinBase, BitLength::BitLengthQWord),
make_pair((size_t)64u, ullQwordMax));
VERIFY_ARE_EQUAL(
m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, BinBase, BitLength::BitLengthDWord),
make_pair((size_t)32u, ullDwordMax));
VERIFY_ARE_EQUAL(
m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, BinBase, BitLength::BitLengthWord),
make_pair((size_t)16u, ullWordMax));
VERIFY_ARE_EQUAL(
m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, BinBase, BitLength::BitLengthByte),
make_pair((size_t)8u, ullByteMax));
Logger::WriteMessage(L"Verify Programmer Mode NumberBase::BinBase maximum values");
VERIFY_MAXOPERANDLENGTHANDVALUE_ARE_EQUALS(
m_CopyPasteManager->GetMaxOperandLengthAndValue(
ViewMode::Programmer, CategoryGroupType::None, NumberBase::BinBase, BitLength::BitLengthQWord),
64u,
ullQwordMax);
VERIFY_MAXOPERANDLENGTHANDVALUE_ARE_EQUALS(
m_CopyPasteManager->GetMaxOperandLengthAndValue(
ViewMode::Programmer, CategoryGroupType::None, NumberBase::BinBase, BitLength::BitLengthDWord),
32u,
ullDwordMax);
VERIFY_MAXOPERANDLENGTHANDVALUE_ARE_EQUALS(
m_CopyPasteManager->GetMaxOperandLengthAndValue(
ViewMode::Programmer, CategoryGroupType::None, NumberBase::BinBase, BitLength::BitLengthWord),
16u,
ullWordMax);
VERIFY_MAXOPERANDLENGTHANDVALUE_ARE_EQUALS(
m_CopyPasteManager->GetMaxOperandLengthAndValue(
ViewMode::Programmer, CategoryGroupType::None, NumberBase::BinBase, BitLength::BitLengthByte),
8u,
ullByteMax);
Logger::WriteMessage(L"Verify invalid ViewModes/Categories return 0 for max values");
VERIFY_ARE_EQUAL(
m_CopyPasteManager->GetMaxOperandLengthAndValue(ViewMode::None, CategoryGroupType::None, -1, BitLength::BitLengthUnknown),
make_pair((size_t)0u, 0ull));
VERIFY_MAXOPERANDLENGTHANDVALUE_ARE_EQUALS(
m_CopyPasteManager->GetMaxOperandLengthAndValue(
ViewMode::None, CategoryGroupType::None, NumberBase::Unknown, BitLength::BitLengthUnknown),
0u,
0ull);
};
TEST_METHOD(ValidateSanitizeOperand)
@@ -326,89 +452,103 @@ namespace CalculatorUnitTests
TEST_METHOD(ValidatePrefixCurrencySymbols)
{
// ¥5
VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromWstring(L"\u00A5\u0035"), L"5");
VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromString(L"\u00A5\u0035"), L"5");
// ¤5
VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromWstring(L"\u00A4\u0035"), L"5");
VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromString(L"\u00A4\u0035"), L"5");
// ₵5
VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromWstring(L"\u20B5\u0035"), L"5");
VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromString(L"\u20B5\u0035"), L"5");
// $5
VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromWstring(L"\u0024\u0035"), L"5");
VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromString(L"\u0024\u0035"), L"5");
// ₡5
VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromWstring(L"\u20A1\u0035"), L"5");
VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromString(L"\u20A1\u0035"), L"5");
// ₩5
VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromWstring(L"\u20A9\u0035"), L"5");
VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromString(L"\u20A9\u0035"), L"5");
// ₪5
VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromWstring(L"\u20AA\u0035"), L"5");
VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromString(L"\u20AA\u0035"), L"5");
// ₦5
VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromWstring(L"\u20A6\u0035"), L"5");
VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromString(L"\u20A6\u0035"), L"5");
// ₹5
VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromWstring(L"\u20B9\u0035"), L"5");
VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromString(L"\u20B9\u0035"), L"5");
// £5
VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromWstring(L"\u00A3\u0035"), L"5");
VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromString(L"\u00A3\u0035"), L"5");
// €5
VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromWstring(L"\u20AC\u0035"), L"5");
VERIFY_ARE_EQUAL(m_CopyPasteManager->RemoveUnwantedCharsFromString(L"\u20AC\u0035"), L"5");
};
TEST_METHOD(ValidateTryOperandToULL)
{
unsigned long long int result = 0;
IBox<unsigned long long int> ^ result = nullptr;
Logger::WriteMessage(L"Verify TryOperandToULL HexBase conversion");
VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"1234", HexBase, result));
VERIFY_ARE_EQUAL(result, 0x1234ull);
VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"FF", HexBase, result));
VERIFY_ARE_EQUAL(result, 0xFFull);
VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"FFFFFFFFFFFFFFFF", HexBase, result));
VERIFY_ARE_EQUAL(result, 0xFFFF'FFFF'FFFF'FFFF);
VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"0xFFFFFFFFFFFFFFFF", HexBase, result));
VERIFY_ARE_EQUAL(result, 0xFFFF'FFFF'FFFF'FFFF);
VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"0XFFFFFFFFFFFFFFFF", HexBase, result));
VERIFY_ARE_EQUAL(result, 0xFFFF'FFFF'FFFF'FFFF);
VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"0X0FFFFFFFFFFFFFFFF", HexBase, result));
VERIFY_ARE_EQUAL(result, 0xFFFF'FFFF'FFFF'FFFF);
Logger::WriteMessage(L"Verify TryOperandToULL NumberBase::HexBase conversion");
result = CopyPasteManager::TryOperandToULL(L"1234", NumberBase::HexBase);
VERIFY_IS_NOT_NULL(result);
VERIFY_ARE_EQUAL(result->Value, 0x1234ull);
result = CopyPasteManager::TryOperandToULL(L"FF", NumberBase::HexBase);
VERIFY_IS_NOT_NULL(result);
VERIFY_ARE_EQUAL(result->Value, 0xFFull);
result = CopyPasteManager::TryOperandToULL(L"FFFFFFFFFFFFFFFF", NumberBase::HexBase);
VERIFY_IS_NOT_NULL(result);
VERIFY_ARE_EQUAL(result->Value, 0xFFFF'FFFF'FFFF'FFFF);
result = CopyPasteManager::TryOperandToULL(L"0xFFFFFFFFFFFFFFFF", NumberBase::HexBase);
VERIFY_IS_NOT_NULL(result);
VERIFY_ARE_EQUAL(result->Value, 0xFFFF'FFFF'FFFF'FFFF);
result = CopyPasteManager::TryOperandToULL(L"0XFFFFFFFFFFFFFFFF", NumberBase::HexBase);
VERIFY_IS_NOT_NULL(result);
VERIFY_ARE_EQUAL(result->Value, 0xFFFF'FFFF'FFFF'FFFF);
result = CopyPasteManager::TryOperandToULL(L"0X0FFFFFFFFFFFFFFFF", NumberBase::HexBase);
VERIFY_IS_NOT_NULL(result);
VERIFY_ARE_EQUAL(result->Value, 0xFFFF'FFFF'FFFF'FFFF);
Logger::WriteMessage(L"Verify TryOperandToULL DecBase conversion");
VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"1234", DecBase, result));
VERIFY_ARE_EQUAL(result, 1234ull);
VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"18446744073709551615", DecBase, result));
VERIFY_ARE_EQUAL(result, 0xFFFF'FFFF'FFFF'FFFF);
VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"018446744073709551615", DecBase, result));
VERIFY_ARE_EQUAL(result, 0xFFFF'FFFF'FFFF'FFFF);
Logger::WriteMessage(L"Verify TryOperandToULL NumberBase::DecBase conversion");
result = CopyPasteManager::TryOperandToULL(L"1234", NumberBase::DecBase);
VERIFY_IS_NOT_NULL(result);
VERIFY_ARE_EQUAL(result->Value, 1234ull);
result = CopyPasteManager::TryOperandToULL(L"18446744073709551615", NumberBase::DecBase);
VERIFY_IS_NOT_NULL(result);
VERIFY_ARE_EQUAL(result->Value, 0xFFFF'FFFF'FFFF'FFFF);
result = CopyPasteManager::TryOperandToULL(L"018446744073709551615", NumberBase::DecBase);
VERIFY_IS_NOT_NULL(result);
VERIFY_ARE_EQUAL(result->Value, 0xFFFF'FFFF'FFFF'FFFF);
Logger::WriteMessage(L"Verify TryOperandToULL OctBase conversion");
VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"777", OctBase, result));
VERIFY_ARE_EQUAL(result, 0777ull);
VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"0777", OctBase, result));
VERIFY_ARE_EQUAL(result, 0777ull);
VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"1777777777777777777777", OctBase, result));
VERIFY_ARE_EQUAL(result, 0xFFFF'FFFF'FFFF'FFFF);
VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"01777777777777777777777", OctBase, result));
VERIFY_ARE_EQUAL(result, 0xFFFF'FFFF'FFFF'FFFF);
Logger::WriteMessage(L"Verify TryOperandToULL NumberBase::OctBase conversion");
result = CopyPasteManager::TryOperandToULL(L"777", NumberBase::OctBase);
VERIFY_IS_NOT_NULL(result);
VERIFY_ARE_EQUAL(result->Value, 0777ull);
result = CopyPasteManager::TryOperandToULL(L"0777", NumberBase::OctBase);
VERIFY_IS_NOT_NULL(result);
VERIFY_ARE_EQUAL(result->Value, 0777ull);
result = CopyPasteManager::TryOperandToULL(L"1777777777777777777777", NumberBase::OctBase);
VERIFY_IS_NOT_NULL(result);
VERIFY_ARE_EQUAL(result->Value, 0xFFFF'FFFF'FFFF'FFFF);
result = CopyPasteManager::TryOperandToULL(L"01777777777777777777777", NumberBase::OctBase);
VERIFY_IS_NOT_NULL(result);
VERIFY_ARE_EQUAL(result->Value, 0xFFFF'FFFF'FFFF'FFFF);
Logger::WriteMessage(L"Verify TryOperandToULL BinBase conversion");
VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"1111", BinBase, result));
VERIFY_ARE_EQUAL(result, 0b1111ull);
VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"0010", BinBase, result));
VERIFY_ARE_EQUAL(result, 0b10ull);
VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"1111111111111111111111111111111111111111111111111111111111111111", BinBase, result));
VERIFY_ARE_EQUAL(result, 0xFFFF'FFFF'FFFF'FFFF);
VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"01111111111111111111111111111111111111111111111111111111111111111", BinBase, result));
VERIFY_ARE_EQUAL(result, 0xFFFF'FFFF'FFFF'FFFF);
Logger::WriteMessage(L"Verify TryOperandToULL invalid numberBase defaults to DecBase");
VERIFY_IS_TRUE(m_CopyPasteManager->TryOperandToULL(L"1234", 128, result));
VERIFY_ARE_EQUAL(result, 1234ull);
Logger::WriteMessage(L"Verify TryOperandToULL NumberBase::BinBase conversion");
result = CopyPasteManager::TryOperandToULL(L"1111", NumberBase::BinBase);
VERIFY_IS_NOT_NULL(result);
VERIFY_ARE_EQUAL(result->Value, 0b1111ull);
result = CopyPasteManager::TryOperandToULL(L"0010", NumberBase::BinBase);
VERIFY_IS_NOT_NULL(result);
VERIFY_ARE_EQUAL(result->Value, 0b10ull);
result = CopyPasteManager::TryOperandToULL(L"1111111111111111111111111111111111111111111111111111111111111111", NumberBase::BinBase);
VERIFY_IS_NOT_NULL(result);
VERIFY_ARE_EQUAL(result->Value, 0xFFFF'FFFF'FFFF'FFFF);
result = CopyPasteManager::TryOperandToULL(L"01111111111111111111111111111111111111111111111111111111111111111", NumberBase::BinBase);
VERIFY_IS_NOT_NULL(result);
VERIFY_ARE_EQUAL(result->Value, 0xFFFF'FFFF'FFFF'FFFF);
Logger::WriteMessage(L"Verify TryOperandToULL returns false when input is invalid or strtoull throws exceptions");
// Max values + 1
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"2000000000000000000000", OctBase, result));
VERIFY_IS_FALSE(m_CopyPasteManager->TryOperandToULL(L"11111111111111111111111111111111111111111111111111111111111111111", BinBase, result));
VERIFY_IS_NULL(CopyPasteManager::TryOperandToULL(L"0xFFFFFFFFFFFFFFFFF1", NumberBase::HexBase));
VERIFY_IS_NULL(CopyPasteManager::TryOperandToULL(L"18446744073709551616", NumberBase::DecBase));
VERIFY_IS_NULL(CopyPasteManager::TryOperandToULL(L"2000000000000000000000", NumberBase::OctBase));
VERIFY_IS_NULL(
CopyPasteManager::TryOperandToULL(L"11111111111111111111111111111111111111111111111111111111111111111", NumberBase::BinBase));
// Invalid values/characters
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"xyz", BinBase, result));
VERIFY_IS_NULL(CopyPasteManager::TryOperandToULL(L"-1", NumberBase::DecBase));
VERIFY_IS_NULL(CopyPasteManager::TryOperandToULL(L"5555", NumberBase::BinBase));
VERIFY_IS_NULL(CopyPasteManager::TryOperandToULL(L"xyz", NumberBase::BinBase));
};
TEST_METHOD(ValidateStandardScientificOperandLength)
@@ -423,130 +563,130 @@ namespace CalculatorUnitTests
TEST_METHOD(ValidateProgrammerOperandLength)
{
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"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"0b", BinBase), 1);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"1001", NumberBase::BinBase), 4);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"1001b", NumberBase::BinBase), 4);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"1001B", NumberBase::BinBase), 4);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"0b1001", NumberBase::BinBase), 4);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"0B1001", NumberBase::BinBase), 4);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"0y1001", NumberBase::BinBase), 4);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"0Y1001", NumberBase::BinBase), 4);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"0b", NumberBase::BinBase), 1);
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"0o123456", OctBase), 6);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"0O123456", OctBase), 6);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"123456", NumberBase::OctBase), 6);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"0t123456", NumberBase::OctBase), 6);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"0T123456", NumberBase::OctBase), 6);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"0o123456", NumberBase::OctBase), 6);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"0O123456", NumberBase::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"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"", NumberBase::DecBase), 0);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"-", NumberBase::DecBase), 0);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"12345", NumberBase::DecBase), 5);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"-12345", NumberBase::DecBase), 5);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"0n12345", NumberBase::DecBase), 5);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"0N12345", NumberBase::DecBase), 5);
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"123ABCh", HexBase), 6);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"123ABCH", HexBase), 6);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"123ABC", NumberBase::HexBase), 6);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"0x123ABC", NumberBase::HexBase), 6);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"0X123ABC", NumberBase::HexBase), 6);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"123ABCh", NumberBase::HexBase), 6);
VERIFY_ARE_EQUAL(m_CopyPasteManager->ProgrammerOperandLength(L"123ABCH", NumberBase::HexBase), 6);
};
private:
CopyPasteManager ^ m_CopyPasteManager;
String^ ValidateStandardPasteExpression(_In_ String^ pastedText)
{
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Standard, -1/*number base*/, BitLength::BitLengthUnknown);
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Standard, NumberBase::Unknown, BitLength::BitLengthUnknown);
}
String^ ValidateScientificPasteExpression(_In_ String^ pastedText)
{
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Scientific, -1/*number base*/, BitLength::BitLengthUnknown);
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Scientific, NumberBase::Unknown, BitLength::BitLengthUnknown);
}
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, NumberBase::Unknown, BitLength::BitLengthUnknown);
}
String^ ValidateProgrammerHexQwordPasteExpression(_In_ String^ pastedText)
{
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, HexBase/*number base*/, BitLength::BitLengthQWord);
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, NumberBase::HexBase, BitLength::BitLengthQWord);
}
String^ ValidateProgrammerHexDwordPasteExpression(_In_ String^ pastedText)
{
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, HexBase/*number base*/, BitLength::BitLengthDWord);
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, NumberBase::HexBase, BitLength::BitLengthDWord);
}
String^ ValidateProgrammerHexWordPasteExpression(_In_ String^ pastedText)
{
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, HexBase/*number base*/, BitLength::BitLengthWord);
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, NumberBase::HexBase, BitLength::BitLengthWord);
}
String^ ValidateProgrammerHexBytePasteExpression(_In_ String^ pastedText)
{
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, HexBase/*number base*/, BitLength::BitLengthByte);
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, NumberBase::HexBase, BitLength::BitLengthByte);
}
String^ ValidateProgrammerDecQwordPasteExpression(_In_ String^ pastedText)
{
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, DecBase/*number base*/, BitLength::BitLengthQWord);
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, NumberBase::DecBase, BitLength::BitLengthQWord);
}
String^ ValidateProgrammerDecDwordPasteExpression(_In_ String^ pastedText)
{
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, DecBase/*number base*/, BitLength::BitLengthDWord);
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, NumberBase::DecBase, BitLength::BitLengthDWord);
}
String^ ValidateProgrammerDecWordPasteExpression(_In_ String^ pastedText)
{
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, DecBase/*number base*/, BitLength::BitLengthWord);
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, NumberBase::DecBase, BitLength::BitLengthWord);
}
String^ ValidateProgrammerDecBytePasteExpression(_In_ String^ pastedText)
{
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, DecBase/*number base*/, BitLength::BitLengthByte);
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, NumberBase::DecBase, BitLength::BitLengthByte);
}
String^ ValidateProgrammerOctQwordPasteExpression(_In_ String^ pastedText)
{
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, OctBase/*number base*/, BitLength::BitLengthQWord);
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, NumberBase::OctBase, BitLength::BitLengthQWord);
}
String^ ValidateProgrammerOctDwordPasteExpression(_In_ String^ pastedText)
{
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, OctBase/*number base*/, BitLength::BitLengthDWord);
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, NumberBase::OctBase, BitLength::BitLengthDWord);
}
String^ ValidateProgrammerOctWordPasteExpression(_In_ String^ pastedText)
{
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, OctBase/*number base*/, BitLength::BitLengthWord);
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, NumberBase::OctBase, BitLength::BitLengthWord);
}
String^ ValidateProgrammerOctBytePasteExpression(_In_ String^ pastedText)
{
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, OctBase/*number base*/, BitLength::BitLengthByte);
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, NumberBase::OctBase, BitLength::BitLengthByte);
}
String^ ValidateProgrammerBinQwordPasteExpression(_In_ String^ pastedText)
{
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, BinBase/*number base*/, BitLength::BitLengthQWord);
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, NumberBase::BinBase, BitLength::BitLengthQWord);
}
String^ ValidateProgrammerBinDwordPasteExpression(_In_ String^ pastedText)
{
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, BinBase/*number base*/, BitLength::BitLengthDWord);
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, NumberBase::BinBase, BitLength::BitLengthDWord);
}
String^ ValidateProgrammerBinWordPasteExpression(_In_ String^ pastedText)
{
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, BinBase/*number base*/, BitLength::BitLengthWord);
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, NumberBase::BinBase, BitLength::BitLengthWord);
}
String^ ValidateProgrammerBinBytePasteExpression(_In_ String^ pastedText)
{
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, BinBase/*number base*/, BitLength::BitLengthByte);
return m_CopyPasteManager->ValidatePasteExpression(pastedText, ViewMode::Programmer, NumberBase::BinBase, BitLength::BitLengthByte);
}
};
@@ -587,7 +727,8 @@ namespace CalculatorUnitTests
void CopyPasteManagerTest::FunctionalCopyPasteTest()
{
// Doesn't have test where converter is involved. Will add such a test later.
StandardCalculatorViewModel ^ scvm = ref new StandardCalculatorViewModel();
StandardCalculatorViewModel ^ scvm = nullptr;
scvm = ref new StandardCalculatorViewModel();
scvm->IsStandard = true;
String ^ inputs[] = { L"123", L"12345", L"123+456", L"1,234", L"1 2 3", L"\n\r1,234\n", L"\n 1+\n2 ", L"1\"2" };

View File

@@ -1,10 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#include "pch.h"
#pragma once
#include "CalcViewModel/Common/CalculatorButtonUser.h"
#include <CppUnitTest.h>
namespace CalculatorUnitTests
{
@@ -95,3 +96,15 @@ namespace CalculatorUnitTests
{ \
Assert::IsTrue(__expectedGreater >= __expectedLess, __VA_ARGS__); \
}
template <typename T>
void VERIFY_VECTORS_ARE_EQUAL(Windows::Foundation::Collections::IVector<T> ^ vecA, Windows::Foundation::Collections::IVector<T> ^ vecB, ...)
{
if (vecA->Size != vecB->Size)
Assert::Fail();
for (unsigned int i = 0; i < vecA->Size; ++i)
{
VERIFY_ARE_EQUAL(vecA->GetAt(i), vecB->GetAt(i), __VA_ARGS__);
}
};

View File

@@ -24,7 +24,9 @@ namespace CalculatorUnitTests
void CompareVector(IVector<T> ^ vecA, IVector<T> ^ vecB)
{
if (vecA->Size != vecB->Size)
{
Assert::Fail();
}
for (unsigned int i = 0; i < vecA->Size; ++i)
{