refactor HistoryTest.cpp to test the history using HistoryViewModel (#784)

* refactor HistoryTest

* modify MultiWindowUnitTests to not use m_standardCalcManager

* rebase

Co-authored-by: Rudy Huyn <rudy.huyn@microsoft.com>
This commit is contained in:
Rudy Huyn 2020-04-07 17:08:02 -07:00 committed by GitHub
parent 0ed876db43
commit 825b42ad46
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 245 additions and 248 deletions

View file

@ -36,17 +36,6 @@ void Utils::IFTPlatformException(HRESULT hr)
}
}
String ^ Utils::GetStringValue(String ^ input)
{
// Remove first and last " characters
if (input->Length() >= 3)
{
wstring out(input->Begin() + 1, input->End() - 1);
return ref new String(out.c_str());
}
return input;
}
double Utils::GetDoubleFromWstring(wstring input)
{
constexpr wchar_t unWantedChars[] = { L' ', L',', 8234, 8235, 8236, 8237 };

View file

@ -98,7 +98,7 @@ public:
#define OBSERVABLE_NAMED_PROPERTY_R(t, n) \
OBSERVABLE_PROPERTY_R(t, n) \
internal: \
public: \
static property Platform::String ^ n##PropertyName \
{ \
Platform::String ^ get() { return Platform::StringReference(L#n); } \
@ -108,7 +108,7 @@ public:
#define OBSERVABLE_NAMED_PROPERTY_RW(t, n) \
OBSERVABLE_PROPERTY_RW(t, n) \
internal: \
public: \
static property Platform::String ^ n##PropertyName \
{ \
Platform::String ^ get() { return Platform::StringReference(L#n); } \
@ -373,7 +373,6 @@ namespace Utils
}
void IFTPlatformException(HRESULT hr);
Platform::String ^ GetStringValue(Platform::String ^ input);
bool IsLastCharacterTarget(std::wstring const& input, wchar_t target);
// Return wstring after removing characters specified by unwantedChars array

View file

@ -6,6 +6,7 @@
#include "Common/TraceLogger.h"
#include "Common/LocalizationStringUtil.h"
#include "Common/LocalizationSettings.h"
#include "StandardCalculatorViewModel.h"
using namespace CalculatorApp;
using namespace CalculatorApp::Common;
@ -258,6 +259,11 @@ void HistoryViewModel::ClearHistory()
ClearHistoryContainer(CalculationManager::CalculatorMode::Scientific);
}
unsigned long long HistoryViewModel::GetMaxItemSize()
{
return static_cast<unsigned long long>(m_calculatorManager->MaxHistorySize());
}
void HistoryViewModel::SaveHistory()
{
ApplicationDataContainer ^ historyContainer = GetHistoryContainer(m_currentMode);

View file

@ -15,6 +15,8 @@ namespace CalculatorApp
namespace ViewModel
{
ref class StandardCalculatorViewModel;
public
delegate void HideHistoryClickedHandler();
public
@ -45,6 +47,7 @@ namespace CalculatorApp
internal : HistoryViewModel(_In_ CalculationManager::CalculatorManager* calculatorManager);
void SetCalculatorDisplay(CalculatorDisplay& calculatorDisplay);
void ReloadHistory(_In_ CalculatorApp::Common::ViewMode currentMode);
unsigned long long GetMaxItemSize();
void DeleteItem(_In_ CalculatorApp::ViewModel::HistoryItemViewModel ^ e);

View file

@ -1812,3 +1812,13 @@ void StandardCalculatorViewModel::SelectHistoryItem(HistoryItemViewModel ^ item)
SetPrimaryDisplay(item->Result, false);
IsFToEEnabled = false;
}
void StandardCalculatorViewModel::ResetCalcManager(bool clearMemory)
{
m_standardCalculatorManager.Reset(clearMemory);
}
void StandardCalculatorViewModel::SendCommandToCalcManager(int commandId)
{
m_standardCalculatorManager.SendCommand(static_cast<Command>(commandId));
}

View file

@ -12,11 +12,6 @@
#include "Common/BitLength.h"
#include "Common/NumberBase.h"
namespace CalculatorFunctionalTests
{
class HistoryTests;
}
namespace CalculatorUnitTests
{
class MultiWindowUnitTests;
@ -247,7 +242,11 @@ namespace CalculatorApp
}
}
internal :
// Used by unit tests
void ResetCalcManager(bool clearMemory);
void SendCommandToCalcManager(int command);
internal:
void OnPaste(Platform::String ^ pastedString);
void OnCopyCommand(Platform::Object ^ parameter);
void OnPasteCommand(Platform::Object ^ parameter);
@ -373,7 +372,6 @@ namespace CalculatorApp
CalculatorApp::Common::ViewMode GetCalculatorMode();
friend class CalculatorDisplay;
friend class CalculatorFunctionalTests::HistoryTests;
friend class CalculatorUnitTests::MultiWindowUnitTests;
};
}