From 1c7187f632ba9106ce55fa1d26814e571205887b Mon Sep 17 00:00:00 2001 From: Matt Cooley Date: Tue, 29 Jan 2019 19:37:37 -0800 Subject: [PATCH] Clean up unit test projects (#4) * Rename CalculatorUnitTests_VS to CalculatorUnitTests, fix gitignore * Delete internal unit tests * Update pipeline paths --- .gitignore | 10 +- build/pipelines/templates/run-unit-tests.yaml | 8 +- internal/CalculatorInternal.sln | 88 -- .../CalculatorUnitTests/CalcEngineTests.cpp | 225 ---- .../CalculatorUnitTests/CalcInputTest.cpp | 366 ------ .../CalculatorManagerTest.cpp | 1123 ---------------- .../CalculatorUnitTests.vcxproj | 365 ------ .../CalculatorUnitTests.vcxproj.filters | 102 -- .../CopyPasteManagerTest.cpp | 602 --------- .../CurrencyConverterUnitTests.cpp | 605 --------- .../DateCalculatorUnitTests.cpp | 582 --------- internal/CalculatorUnitTests/DateUtils.h | 56 - internal/CalculatorUnitTests/Helpers.h | 31 - internal/CalculatorUnitTests/HistoryTests.cpp | 533 -------- .../Mocks/CurrencyHttpClient.cpp | 56 - internal/CalculatorUnitTests/Module.cpp | 22 - .../MultiWindowUnitTests.cpp | 1012 --------------- .../NavCategoryUnitTests.cpp | 410 ------ .../CalculatorUnitTests/Package.appxmanifest | 29 - .../StandardViewModelUnitTests.cpp | 1144 ----------------- internal/CalculatorUnitTests/Test.resw | 440 ------- .../CalculatorUnitTests/UnitConverterTest.cpp | 600 --------- .../UnitConverterViewModelUnitTests.cpp | 1115 ---------------- .../UnitConverterViewModelUnitTests.h | 70 - .../CalculatorUnitTests/UnitTestApp.rd.xml | 30 - internal/CalculatorUnitTests/UnitTestApp.xaml | 8 - .../CalculatorUnitTests/UnitTestApp.xaml.cpp | 111 -- .../CalculatorUnitTests/UnitTestApp.xaml.h | 35 - internal/CalculatorUnitTests/UtilsTests.cpp | 44 - internal/CalculatorUnitTests/packages.config | 6 - internal/CalculatorUnitTests/pch.cpp | 10 - internal/CalculatorUnitTests/pch.h | 120 -- .../CalculatorUnitTests/testmd.definition | 34 - src/Calculator.sln | 2 +- .../Assets/LockScreenLogo.scale-200.png | Bin .../Assets/SplashScreen.scale-200.png | Bin .../Assets/Square150x150Logo.scale-200.png | Bin .../Assets/Square44x44Logo.scale-200.png | Bin ...x44Logo.targetsize-24_altform-unplated.png | Bin .../CalculatorUnitTests/Assets/StoreLogo.png | Bin .../Assets/Wide310x150Logo.scale-200.png | Bin .../CalculatorUnitTests/AsyncHelper.cpp | 0 .../CalculatorUnitTests/AsyncHelper.h | 0 .../CalcEngineTests.cpp | 0 .../CalcInputTest.cpp | 0 .../CalculatorManagerTest.cpp | 0 .../CalculatorUnitTests.rc} | Bin .../CalculatorUnitTests.vcxproj} | 8 +- .../CalculatorUnitTests.vcxproj.filters} | 0 .../CalculatorUnitTests_TemporaryKey.pfx | Bin 0 -> 2536 bytes .../CopyPasteManagerTest.cpp | 0 .../CurrencyConverterUnitTests.cpp | 0 .../DateCalculatorUnitTests.cpp | 0 .../DateUtils.h | 0 .../Helpers.h | 0 .../HistoryTests.cpp | 0 .../Mocks/CurrencyHttpClient.cpp | 0 .../Mocks/CurrencyHttpClient.h | 0 .../Module.cpp | 0 .../MultiWindowUnitTests.cpp | 0 .../NavCategoryUnitTests.cpp | 0 .../Package.appxmanifest | 6 +- .../StandardViewModelUnitTests.cpp | 0 .../Test.resw | 0 .../UnitConverterTest.cpp | 0 .../UnitConverterViewModelUnitTests.cpp | 0 .../UnitConverterViewModelUnitTests.h | 0 .../UnitTestApp.rd.xml | 0 .../UnitTestApp.xaml | 0 .../UnitTestApp.xaml.cpp | 0 .../UnitTestApp.xaml.h | 0 .../UtilsTests.cpp | 0 .../pch.cpp | 0 .../pch.h | 0 .../resource.h | 0 .../Assets/LockScreenLogo.scale-200.png | Bin 1430 -> 0 bytes .../Assets/SplashScreen.scale-200.png | Bin 7700 -> 0 bytes .../Assets/Square150x150Logo.scale-200.png | Bin 2937 -> 0 bytes .../Assets/Square44x44Logo.scale-200.png | Bin 1647 -> 0 bytes ...x44Logo.targetsize-24_altform-unplated.png | Bin 1255 -> 0 bytes .../Assets/StoreLogo.png | Bin 1451 -> 0 bytes .../Assets/Wide310x150Logo.scale-200.png | Bin 3204 -> 0 bytes src/CalculatorUnitTests_VS/AsyncHelper.cpp | 45 - src/CalculatorUnitTests_VS/AsyncHelper.h | 77 -- .../Mocks/CurrencyHttpClient.h | 75 -- 85 files changed, 13 insertions(+), 10192 deletions(-) delete mode 100644 internal/CalculatorUnitTests/CalcEngineTests.cpp delete mode 100644 internal/CalculatorUnitTests/CalcInputTest.cpp delete mode 100644 internal/CalculatorUnitTests/CalculatorManagerTest.cpp delete mode 100644 internal/CalculatorUnitTests/CalculatorUnitTests.vcxproj delete mode 100644 internal/CalculatorUnitTests/CalculatorUnitTests.vcxproj.filters delete mode 100644 internal/CalculatorUnitTests/CopyPasteManagerTest.cpp delete mode 100644 internal/CalculatorUnitTests/CurrencyConverterUnitTests.cpp delete mode 100644 internal/CalculatorUnitTests/DateCalculatorUnitTests.cpp delete mode 100644 internal/CalculatorUnitTests/DateUtils.h delete mode 100644 internal/CalculatorUnitTests/Helpers.h delete mode 100644 internal/CalculatorUnitTests/HistoryTests.cpp delete mode 100644 internal/CalculatorUnitTests/Mocks/CurrencyHttpClient.cpp delete mode 100644 internal/CalculatorUnitTests/Module.cpp delete mode 100644 internal/CalculatorUnitTests/MultiWindowUnitTests.cpp delete mode 100644 internal/CalculatorUnitTests/NavCategoryUnitTests.cpp delete mode 100644 internal/CalculatorUnitTests/Package.appxmanifest delete mode 100644 internal/CalculatorUnitTests/StandardViewModelUnitTests.cpp delete mode 100644 internal/CalculatorUnitTests/Test.resw delete mode 100644 internal/CalculatorUnitTests/UnitConverterTest.cpp delete mode 100644 internal/CalculatorUnitTests/UnitConverterViewModelUnitTests.cpp delete mode 100644 internal/CalculatorUnitTests/UnitConverterViewModelUnitTests.h delete mode 100644 internal/CalculatorUnitTests/UnitTestApp.rd.xml delete mode 100644 internal/CalculatorUnitTests/UnitTestApp.xaml delete mode 100644 internal/CalculatorUnitTests/UnitTestApp.xaml.cpp delete mode 100644 internal/CalculatorUnitTests/UnitTestApp.xaml.h delete mode 100644 internal/CalculatorUnitTests/UtilsTests.cpp delete mode 100644 internal/CalculatorUnitTests/packages.config delete mode 100644 internal/CalculatorUnitTests/pch.cpp delete mode 100644 internal/CalculatorUnitTests/pch.h delete mode 100644 internal/CalculatorUnitTests/testmd.definition rename {internal => src}/CalculatorUnitTests/Assets/LockScreenLogo.scale-200.png (100%) rename {internal => src}/CalculatorUnitTests/Assets/SplashScreen.scale-200.png (100%) rename {internal => src}/CalculatorUnitTests/Assets/Square150x150Logo.scale-200.png (100%) rename {internal => src}/CalculatorUnitTests/Assets/Square44x44Logo.scale-200.png (100%) rename {internal => src}/CalculatorUnitTests/Assets/Square44x44Logo.targetsize-24_altform-unplated.png (100%) rename {internal => src}/CalculatorUnitTests/Assets/StoreLogo.png (100%) rename {internal => src}/CalculatorUnitTests/Assets/Wide310x150Logo.scale-200.png (100%) rename {internal => src}/CalculatorUnitTests/AsyncHelper.cpp (100%) rename {internal => src}/CalculatorUnitTests/AsyncHelper.h (100%) rename src/{CalculatorUnitTests_VS => CalculatorUnitTests}/CalcEngineTests.cpp (100%) rename src/{CalculatorUnitTests_VS => CalculatorUnitTests}/CalcInputTest.cpp (100%) rename src/{CalculatorUnitTests_VS => CalculatorUnitTests}/CalculatorManagerTest.cpp (100%) rename src/{CalculatorUnitTests_VS/CalculatorUnitTests_VS.rc => CalculatorUnitTests/CalculatorUnitTests.rc} (100%) rename src/{CalculatorUnitTests_VS/CalculatorUnitTests_VS.vcxproj => CalculatorUnitTests/CalculatorUnitTests.vcxproj} (98%) rename src/{CalculatorUnitTests_VS/CalculatorUnitTests_VS.vcxproj.filters => CalculatorUnitTests/CalculatorUnitTests.vcxproj.filters} (100%) create mode 100644 src/CalculatorUnitTests/CalculatorUnitTests_TemporaryKey.pfx rename src/{CalculatorUnitTests_VS => CalculatorUnitTests}/CopyPasteManagerTest.cpp (100%) rename src/{CalculatorUnitTests_VS => CalculatorUnitTests}/CurrencyConverterUnitTests.cpp (100%) rename src/{CalculatorUnitTests_VS => CalculatorUnitTests}/DateCalculatorUnitTests.cpp (100%) rename src/{CalculatorUnitTests_VS => CalculatorUnitTests}/DateUtils.h (100%) rename src/{CalculatorUnitTests_VS => CalculatorUnitTests}/Helpers.h (100%) rename src/{CalculatorUnitTests_VS => CalculatorUnitTests}/HistoryTests.cpp (100%) rename src/{CalculatorUnitTests_VS => CalculatorUnitTests}/Mocks/CurrencyHttpClient.cpp (100%) rename {internal => src}/CalculatorUnitTests/Mocks/CurrencyHttpClient.h (100%) rename src/{CalculatorUnitTests_VS => CalculatorUnitTests}/Module.cpp (100%) rename src/{CalculatorUnitTests_VS => CalculatorUnitTests}/MultiWindowUnitTests.cpp (100%) rename src/{CalculatorUnitTests_VS => CalculatorUnitTests}/NavCategoryUnitTests.cpp (100%) rename src/{CalculatorUnitTests_VS => CalculatorUnitTests}/Package.appxmanifest (78%) rename src/{CalculatorUnitTests_VS => CalculatorUnitTests}/StandardViewModelUnitTests.cpp (100%) rename src/{CalculatorUnitTests_VS => CalculatorUnitTests}/Test.resw (100%) rename src/{CalculatorUnitTests_VS => CalculatorUnitTests}/UnitConverterTest.cpp (100%) rename src/{CalculatorUnitTests_VS => CalculatorUnitTests}/UnitConverterViewModelUnitTests.cpp (100%) rename src/{CalculatorUnitTests_VS => CalculatorUnitTests}/UnitConverterViewModelUnitTests.h (100%) rename src/{CalculatorUnitTests_VS => CalculatorUnitTests}/UnitTestApp.rd.xml (100%) rename src/{CalculatorUnitTests_VS => CalculatorUnitTests}/UnitTestApp.xaml (100%) rename src/{CalculatorUnitTests_VS => CalculatorUnitTests}/UnitTestApp.xaml.cpp (100%) rename src/{CalculatorUnitTests_VS => CalculatorUnitTests}/UnitTestApp.xaml.h (100%) rename src/{CalculatorUnitTests_VS => CalculatorUnitTests}/UtilsTests.cpp (100%) rename src/{CalculatorUnitTests_VS => CalculatorUnitTests}/pch.cpp (100%) rename src/{CalculatorUnitTests_VS => CalculatorUnitTests}/pch.h (100%) rename src/{CalculatorUnitTests_VS => CalculatorUnitTests}/resource.h (100%) delete mode 100644 src/CalculatorUnitTests_VS/Assets/LockScreenLogo.scale-200.png delete mode 100644 src/CalculatorUnitTests_VS/Assets/SplashScreen.scale-200.png delete mode 100644 src/CalculatorUnitTests_VS/Assets/Square150x150Logo.scale-200.png delete mode 100644 src/CalculatorUnitTests_VS/Assets/Square44x44Logo.scale-200.png delete mode 100644 src/CalculatorUnitTests_VS/Assets/Square44x44Logo.targetsize-24_altform-unplated.png delete mode 100644 src/CalculatorUnitTests_VS/Assets/StoreLogo.png delete mode 100644 src/CalculatorUnitTests_VS/Assets/Wide310x150Logo.scale-200.png delete mode 100644 src/CalculatorUnitTests_VS/AsyncHelper.cpp delete mode 100644 src/CalculatorUnitTests_VS/AsyncHelper.h delete mode 100644 src/CalculatorUnitTests_VS/Mocks/CurrencyHttpClient.h diff --git a/.gitignore b/.gitignore index 459b8a3..80d64f5 100644 --- a/.gitignore +++ b/.gitignore @@ -289,13 +289,5 @@ __pycache__/ # Calculator specific Generated Files/ -# Don't ignore anything under SpkgDefs or TrexDefs -!/SpkgDefs/** -!/TrexDefs/** !/build/config/TRexDefs/** - -# Localized strings -# LCT files are loc system artifacts that we don't want in our repo. -*.lct - -WorkspaceInfo.xml +!src/CalculatorUnitTests/CalculatorUnitTests_TemporaryKey.pfx \ No newline at end of file diff --git a/build/pipelines/templates/run-unit-tests.yaml b/build/pipelines/templates/run-unit-tests.yaml index 89c3167..708b30b 100644 --- a/build/pipelines/templates/run-unit-tests.yaml +++ b/build/pipelines/templates/run-unit-tests.yaml @@ -24,18 +24,18 @@ jobs: displayName: Download CalculatorUnitTests inputs: artifactName: drop - itemPattern: drop/Release/${{ parameters.platform }}/CalculatorUnitTests_VS/AppPackages/CalculatorUnitTests_Test/** + itemPattern: drop/Release/${{ parameters.platform }}/CalculatorUnitTests/AppPackages/CalculatorUnitTests_Test/** - task: PowerShell@2 displayName: Install Certificate inputs: - filePath: $(Build.ArtifactStagingDirectory)\drop\Release\${{ parameters.platform }}\CalculatorUnitTests_VS\AppPackages\CalculatorUnitTests_Test\Add-AppDevPackage.ps1 - arguments: -CertificatePath $(Build.ArtifactStagingDirectory)\drop\Release\${{ parameters.platform }}\CalculatorUnitTests_VS\AppPackages\CalculatorUnitTests_Test\CalculatorUnitTests.cer -Force + filePath: $(Build.ArtifactStagingDirectory)\drop\Release\${{ parameters.platform }}\CalculatorUnitTests\AppPackages\CalculatorUnitTests_Test\Add-AppDevPackage.ps1 + arguments: -CertificatePath $(Build.ArtifactStagingDirectory)\drop\Release\${{ parameters.platform }}\CalculatorUnitTests\AppPackages\CalculatorUnitTests_Test\CalculatorUnitTests.cer -Force - task: VSTest@2 displayName: Run CalculatorUnitTests inputs: - testAssemblyVer2: $(Build.ArtifactStagingDirectory)\drop\Release\${{ parameters.platform }}\CalculatorUnitTests_VS\AppPackages\CalculatorUnitTests_Test\CalculatorUnitTests.appx + testAssemblyVer2: $(Build.ArtifactStagingDirectory)\drop\Release\${{ parameters.platform }}\CalculatorUnitTests\AppPackages\CalculatorUnitTests_Test\CalculatorUnitTests.appx otherConsoleOptions: /Platform:${{ parameters.platform }} - job: CleanUpUnitTests${{ parameters.platform }} diff --git a/internal/CalculatorInternal.sln b/internal/CalculatorInternal.sln index a6ee5b1..98be0fb 100644 --- a/internal/CalculatorInternal.sln +++ b/internal/CalculatorInternal.sln @@ -11,16 +11,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution nuget.config = nuget.config EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Calculator", "..\src\Calculator\Calculator.vcxproj", "{9447424A-0E05-4911-BEB8-E0354405F39A}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CalcViewModel", "..\src\CalcViewModel\CalcViewModel.vcxproj", "{90E9761D-9262-4773-942D-CAEAE75D7140}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CalcManager", "..\src\CalcManager\CalcManager.vcxproj", "{311E866D-8B93-4609-A691-265941FEE101}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Calculator.TestPackage", "Calculator.TestPackage\Calculator.TestPackage.csproj", "{24767C43-CD5A-4DC9-8D6B-429F255524E5}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CalculatorUnitTests", "CalculatorUnitTests\CalculatorUnitTests.vcxproj", "{E527A1F4-6B63-4DD0-B540-B8C06CFC3AFE}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|ARM = Debug|ARM @@ -61,62 +53,6 @@ Global {0224A709-0C48-4C4F-BA17-843A49842C15}.Release|x64.Build.0 = Release|x64 {0224A709-0C48-4C4F-BA17-843A49842C15}.Release|x86.ActiveCfg = Release|x86 {0224A709-0C48-4C4F-BA17-843A49842C15}.Release|x86.Build.0 = Release|x86 - {9447424A-0E05-4911-BEB8-E0354405F39A}.Debug|ARM.ActiveCfg = Debug|ARM - {9447424A-0E05-4911-BEB8-E0354405F39A}.Debug|ARM.Build.0 = Debug|ARM - {9447424A-0E05-4911-BEB8-E0354405F39A}.Debug|ARM.Deploy.0 = Debug|ARM - {9447424A-0E05-4911-BEB8-E0354405F39A}.Debug|ARM64.ActiveCfg = Debug|ARM64 - {9447424A-0E05-4911-BEB8-E0354405F39A}.Debug|ARM64.Build.0 = Debug|ARM64 - {9447424A-0E05-4911-BEB8-E0354405F39A}.Debug|ARM64.Deploy.0 = Debug|ARM64 - {9447424A-0E05-4911-BEB8-E0354405F39A}.Debug|x64.ActiveCfg = Debug|x64 - {9447424A-0E05-4911-BEB8-E0354405F39A}.Debug|x64.Build.0 = Debug|x64 - {9447424A-0E05-4911-BEB8-E0354405F39A}.Debug|x64.Deploy.0 = Debug|x64 - {9447424A-0E05-4911-BEB8-E0354405F39A}.Debug|x86.ActiveCfg = Debug|Win32 - {9447424A-0E05-4911-BEB8-E0354405F39A}.Debug|x86.Build.0 = Debug|Win32 - {9447424A-0E05-4911-BEB8-E0354405F39A}.Debug|x86.Deploy.0 = Debug|Win32 - {9447424A-0E05-4911-BEB8-E0354405F39A}.Release|ARM.ActiveCfg = Release|ARM - {9447424A-0E05-4911-BEB8-E0354405F39A}.Release|ARM.Build.0 = Release|ARM - {9447424A-0E05-4911-BEB8-E0354405F39A}.Release|ARM.Deploy.0 = Release|ARM - {9447424A-0E05-4911-BEB8-E0354405F39A}.Release|ARM64.ActiveCfg = Release|ARM64 - {9447424A-0E05-4911-BEB8-E0354405F39A}.Release|ARM64.Build.0 = Release|ARM64 - {9447424A-0E05-4911-BEB8-E0354405F39A}.Release|ARM64.Deploy.0 = Release|ARM64 - {9447424A-0E05-4911-BEB8-E0354405F39A}.Release|x64.ActiveCfg = Release|x64 - {9447424A-0E05-4911-BEB8-E0354405F39A}.Release|x64.Build.0 = Release|x64 - {9447424A-0E05-4911-BEB8-E0354405F39A}.Release|x64.Deploy.0 = Release|x64 - {9447424A-0E05-4911-BEB8-E0354405F39A}.Release|x86.ActiveCfg = Release|Win32 - {9447424A-0E05-4911-BEB8-E0354405F39A}.Release|x86.Build.0 = Release|Win32 - {9447424A-0E05-4911-BEB8-E0354405F39A}.Release|x86.Deploy.0 = Release|Win32 - {90E9761D-9262-4773-942D-CAEAE75D7140}.Debug|ARM.ActiveCfg = Debug|ARM - {90E9761D-9262-4773-942D-CAEAE75D7140}.Debug|ARM.Build.0 = Debug|ARM - {90E9761D-9262-4773-942D-CAEAE75D7140}.Debug|ARM64.ActiveCfg = Debug|ARM64 - {90E9761D-9262-4773-942D-CAEAE75D7140}.Debug|ARM64.Build.0 = Debug|ARM64 - {90E9761D-9262-4773-942D-CAEAE75D7140}.Debug|x64.ActiveCfg = Debug|x64 - {90E9761D-9262-4773-942D-CAEAE75D7140}.Debug|x64.Build.0 = Debug|x64 - {90E9761D-9262-4773-942D-CAEAE75D7140}.Debug|x86.ActiveCfg = Debug|Win32 - {90E9761D-9262-4773-942D-CAEAE75D7140}.Debug|x86.Build.0 = Debug|Win32 - {90E9761D-9262-4773-942D-CAEAE75D7140}.Release|ARM.ActiveCfg = Release|ARM - {90E9761D-9262-4773-942D-CAEAE75D7140}.Release|ARM.Build.0 = Release|ARM - {90E9761D-9262-4773-942D-CAEAE75D7140}.Release|ARM64.ActiveCfg = Release|ARM64 - {90E9761D-9262-4773-942D-CAEAE75D7140}.Release|ARM64.Build.0 = Release|ARM64 - {90E9761D-9262-4773-942D-CAEAE75D7140}.Release|x64.ActiveCfg = Release|x64 - {90E9761D-9262-4773-942D-CAEAE75D7140}.Release|x64.Build.0 = Release|x64 - {90E9761D-9262-4773-942D-CAEAE75D7140}.Release|x86.ActiveCfg = Release|Win32 - {90E9761D-9262-4773-942D-CAEAE75D7140}.Release|x86.Build.0 = Release|Win32 - {311E866D-8B93-4609-A691-265941FEE101}.Debug|ARM.ActiveCfg = Debug|ARM - {311E866D-8B93-4609-A691-265941FEE101}.Debug|ARM.Build.0 = Debug|ARM - {311E866D-8B93-4609-A691-265941FEE101}.Debug|ARM64.ActiveCfg = Debug|ARM64 - {311E866D-8B93-4609-A691-265941FEE101}.Debug|ARM64.Build.0 = Debug|ARM64 - {311E866D-8B93-4609-A691-265941FEE101}.Debug|x64.ActiveCfg = Debug|x64 - {311E866D-8B93-4609-A691-265941FEE101}.Debug|x64.Build.0 = Debug|x64 - {311E866D-8B93-4609-A691-265941FEE101}.Debug|x86.ActiveCfg = Debug|Win32 - {311E866D-8B93-4609-A691-265941FEE101}.Debug|x86.Build.0 = Debug|Win32 - {311E866D-8B93-4609-A691-265941FEE101}.Release|ARM.ActiveCfg = Release|ARM - {311E866D-8B93-4609-A691-265941FEE101}.Release|ARM.Build.0 = Release|ARM - {311E866D-8B93-4609-A691-265941FEE101}.Release|ARM64.ActiveCfg = Release|ARM64 - {311E866D-8B93-4609-A691-265941FEE101}.Release|ARM64.Build.0 = Release|ARM64 - {311E866D-8B93-4609-A691-265941FEE101}.Release|x64.ActiveCfg = Release|x64 - {311E866D-8B93-4609-A691-265941FEE101}.Release|x64.Build.0 = Release|x64 - {311E866D-8B93-4609-A691-265941FEE101}.Release|x86.ActiveCfg = Release|Win32 - {311E866D-8B93-4609-A691-265941FEE101}.Release|x86.Build.0 = Release|Win32 {24767C43-CD5A-4DC9-8D6B-429F255524E5}.Debug|ARM.ActiveCfg = Debug|ARM {24767C43-CD5A-4DC9-8D6B-429F255524E5}.Debug|ARM.Build.0 = Debug|ARM {24767C43-CD5A-4DC9-8D6B-429F255524E5}.Debug|ARM64.ActiveCfg = Debug|ARM64 @@ -131,30 +67,6 @@ Global {24767C43-CD5A-4DC9-8D6B-429F255524E5}.Release|x64.Build.0 = Release|x64 {24767C43-CD5A-4DC9-8D6B-429F255524E5}.Release|x86.ActiveCfg = Release|x86 {24767C43-CD5A-4DC9-8D6B-429F255524E5}.Release|x86.Build.0 = Release|x86 - {E527A1F4-6B63-4DD0-B540-B8C06CFC3AFE}.Debug|ARM.ActiveCfg = Debug|ARM - {E527A1F4-6B63-4DD0-B540-B8C06CFC3AFE}.Debug|ARM.Build.0 = Debug|ARM - {E527A1F4-6B63-4DD0-B540-B8C06CFC3AFE}.Debug|ARM.Deploy.0 = Debug|ARM - {E527A1F4-6B63-4DD0-B540-B8C06CFC3AFE}.Debug|ARM64.ActiveCfg = Debug|ARM64 - {E527A1F4-6B63-4DD0-B540-B8C06CFC3AFE}.Debug|ARM64.Build.0 = Debug|ARM64 - {E527A1F4-6B63-4DD0-B540-B8C06CFC3AFE}.Debug|ARM64.Deploy.0 = Debug|ARM64 - {E527A1F4-6B63-4DD0-B540-B8C06CFC3AFE}.Debug|x64.ActiveCfg = Debug|x64 - {E527A1F4-6B63-4DD0-B540-B8C06CFC3AFE}.Debug|x64.Build.0 = Debug|x64 - {E527A1F4-6B63-4DD0-B540-B8C06CFC3AFE}.Debug|x64.Deploy.0 = Debug|x64 - {E527A1F4-6B63-4DD0-B540-B8C06CFC3AFE}.Debug|x86.ActiveCfg = Debug|Win32 - {E527A1F4-6B63-4DD0-B540-B8C06CFC3AFE}.Debug|x86.Build.0 = Debug|Win32 - {E527A1F4-6B63-4DD0-B540-B8C06CFC3AFE}.Debug|x86.Deploy.0 = Debug|Win32 - {E527A1F4-6B63-4DD0-B540-B8C06CFC3AFE}.Release|ARM.ActiveCfg = Release|ARM - {E527A1F4-6B63-4DD0-B540-B8C06CFC3AFE}.Release|ARM.Build.0 = Release|ARM - {E527A1F4-6B63-4DD0-B540-B8C06CFC3AFE}.Release|ARM.Deploy.0 = Release|ARM - {E527A1F4-6B63-4DD0-B540-B8C06CFC3AFE}.Release|ARM64.ActiveCfg = Release|ARM64 - {E527A1F4-6B63-4DD0-B540-B8C06CFC3AFE}.Release|ARM64.Build.0 = Release|ARM64 - {E527A1F4-6B63-4DD0-B540-B8C06CFC3AFE}.Release|ARM64.Deploy.0 = Release|ARM64 - {E527A1F4-6B63-4DD0-B540-B8C06CFC3AFE}.Release|x64.ActiveCfg = Release|x64 - {E527A1F4-6B63-4DD0-B540-B8C06CFC3AFE}.Release|x64.Build.0 = Release|x64 - {E527A1F4-6B63-4DD0-B540-B8C06CFC3AFE}.Release|x64.Deploy.0 = Release|x64 - {E527A1F4-6B63-4DD0-B540-B8C06CFC3AFE}.Release|x86.ActiveCfg = Release|Win32 - {E527A1F4-6B63-4DD0-B540-B8C06CFC3AFE}.Release|x86.Build.0 = Release|Win32 - {E527A1F4-6B63-4DD0-B540-B8C06CFC3AFE}.Release|x86.Deploy.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/internal/CalculatorUnitTests/CalcEngineTests.cpp b/internal/CalculatorUnitTests/CalcEngineTests.cpp deleted file mode 100644 index 7589084..0000000 --- a/internal/CalculatorUnitTests/CalcEngineTests.cpp +++ /dev/null @@ -1,225 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#include "pch.h" -#include - -#include "CalcViewModel\Common\EngineResourceProvider.h" - -using namespace std; -using namespace WEX::Common; -using namespace WEX::Logging; -using namespace WEX::TestExecution; - -using namespace CalculatorApp; -using namespace CalculationManager; - -static constexpr size_t MAX_HISTORY_SIZE = 20; - -namespace CalculatorUnitTests -{ - class CalcEngineTests - { - TEST_CLASS(CalcEngineTests); - TEST_CLASS_SETUP(CommonSetup) - { - m_resourceProvider = make_shared(); - m_history = make_shared(CM_STD, MAX_HISTORY_SIZE); - CCalcEngine::InitialOneTimeOnlySetup(*(m_resourceProvider.get())); - m_calcEngine = make_unique(false /* Respect Order of Operations */, false /* Set to Integer Mode */, m_resourceProvider.get(), nullptr, m_history); - return true; - } - TEST_METHOD_CLEANUP(Cleanup) - { - return true; - } - - TEST_METHOD(TestGroupDigitsPerRadix) - { - // Empty/Error cases - VERIFY_IS_TRUE(m_calcEngine->GroupDigitsPerRadix(L"", 10).empty(), L"Verify grouping empty string returns empty string."); - VERIFY_ARE_EQUAL(L"12345678", m_calcEngine->GroupDigitsPerRadix(L"12345678", 9), L"Verify grouping on invalid base returns original string"); - - // Octal - VERIFY_ARE_EQUAL(L"1 234 567", m_calcEngine->GroupDigitsPerRadix(L"1234567", 8), L"Verify grouping in octal."); - VERIFY_ARE_EQUAL(L"123", m_calcEngine->GroupDigitsPerRadix(L"123", 8), L"Verify minimum grouping in octal."); - - // Binary/Hexadecimal - VERIFY_ARE_EQUAL(L"12 3456 7890", m_calcEngine->GroupDigitsPerRadix(L"1234567890", 2), L"Verify grouping in binary."); - VERIFY_ARE_EQUAL(L"1234", m_calcEngine->GroupDigitsPerRadix(L"1234", 2), L"Verify minimum grouping in binary."); - VERIFY_ARE_EQUAL(L"12 3456 7890", m_calcEngine->GroupDigitsPerRadix(L"1234567890", 16), L"Verify grouping in hexadecimal."); - VERIFY_ARE_EQUAL(L"1234", m_calcEngine->GroupDigitsPerRadix(L"1234", 16), L"Verify minimum grouping in hexadecimal."); - - // Decimal - VERIFY_ARE_EQUAL(L"1,234,567,890", m_calcEngine->GroupDigitsPerRadix(L"1234567890", 10), L"Verify grouping in base10."); - VERIFY_ARE_EQUAL(L"1,234,567.89", m_calcEngine->GroupDigitsPerRadix(L"1234567.89", 10), L"Verify grouping in base10 with decimal."); - VERIFY_ARE_EQUAL(L"1,234,567e89", m_calcEngine->GroupDigitsPerRadix(L"1234567e89", 10), L"Verify grouping in base10 with exponent."); - VERIFY_ARE_EQUAL(L"1,234,567.89e5", m_calcEngine->GroupDigitsPerRadix(L"1234567.89e5", 10), L"Verify grouping in base10 with decimal and exponent."); - VERIFY_ARE_EQUAL(L"-123,456,789", m_calcEngine->GroupDigitsPerRadix(L"-123456789", 10), L"Verify grouping in base10 with negative."); - } - - TEST_METHOD(TestIsNumberInvalid) - { - // Binary Number Checks - vector validBinStrs{ L"0", L"1", L"0011", L"1100" }; - vector invalidBinStrs{ L"2", L"A", L"0.1" }; - for (wstring const& str : validBinStrs) - { - VERIFY_ARE_EQUAL(0, m_calcEngine->IsNumberInvalid(str, 0, 0, 2 /* Binary */)); - } - for (wstring const& str : invalidBinStrs) - { - VERIFY_ARE_EQUAL(IDS_ERR_UNK_CH, m_calcEngine->IsNumberInvalid(str, 0, 0, 2 /* Binary */)); - } - - // Octal Number Checks - vector validOctStrs{ L"0", L"7", L"01234567", L"76543210" }; - vector invalidOctStrs{ L"8", L"A", L"0.7" }; - for (wstring const& str : validOctStrs) - { - VERIFY_ARE_EQUAL(0, m_calcEngine->IsNumberInvalid(str, 0, 0, 8 /* Octal */)); - } - for (wstring const& str : invalidOctStrs) - { - VERIFY_ARE_EQUAL(IDS_ERR_UNK_CH, m_calcEngine->IsNumberInvalid(str, 0, 0, 8 /* Octal */)); - } - - // Hexadecimal Number Checks - vector validHexStrs{ L"0", L"F", L"0123456789ABCDEF", L"FEDCBA9876543210" }; - vector invalidHexStrs{ L"G", L"abcdef", L"x", L"0.1" }; - for (wstring const& str : validHexStrs) - { - VERIFY_ARE_EQUAL(0, m_calcEngine->IsNumberInvalid(str, 0, 0, 16 /* HEx */)); - } - for (wstring const& str : invalidHexStrs) - { - VERIFY_ARE_EQUAL(IDS_ERR_UNK_CH, m_calcEngine->IsNumberInvalid(str, 0, 0, 16 /* Hex */)); - } - - // Decimal Number Checks - - // Special case errors: long exponent, long mantissa - wstring longExp(L"1e12345"); - VERIFY_ARE_EQUAL(0, m_calcEngine->IsNumberInvalid(longExp, 5 /* Max exp length */, 100, 10 /* Decimal */)); - VERIFY_ARE_EQUAL(IDS_ERR_INPUT_OVERFLOW, m_calcEngine->IsNumberInvalid(longExp, 4 /* Max exp length */, 100, 10 /* Decimal */)); - // Mantissa length is sum of: - // - digits before decimal separator, minus leading zeroes - // - digits after decimal separator, including trailing zeroes - // Each of these mantissa values should calculate as a length of 5 - vector longMantStrs{ L"10000", L"10.000", L"0000012345", L"123.45", L"0.00123", L"0.12345", L"-123.45e678" }; - for (wstring const& str : longMantStrs) - { - VERIFY_ARE_EQUAL(0, m_calcEngine->IsNumberInvalid(str, 100, 5 /* Max mantissa length */, 10 /* Decimal */)); - } - for (wstring const& str : longMantStrs) - { - VERIFY_ARE_EQUAL(IDS_ERR_INPUT_OVERFLOW, m_calcEngine->IsNumberInvalid(str, 100, 4 /* Max mantissa length */, 10 /* Decimal */)); - } - - // Regex matching (descriptions taken from CalcUtils.cpp) - // Use 100 for exp/mantissa length as they are tested above - vector validDecStrs{ - // Start with an optional + or - - L"+1", L"-1", L"1", - // Followed by zero or more digits - L"-", L"", L"1234567890", - // Followed by an optional decimal point - L"1.0", L"-.", L"1.", - // Followed by zero or more digits - L"0.0", L"0.123456", - // Followed by an optional exponent ('e') - L"1e", L"1.e", L"-e", - // If there's an exponent, its optionally followed by + or - - // and followed by zero or more digits - L"1e+12345", L"1e-12345", L"1e123", - // All together - L"-123.456e+789" - }; - vector invalidDecStrs{ L"x123", L"123-", L"1e1.2", L"1-e2" }; - for (wstring const& str : validDecStrs) - { - VERIFY_ARE_EQUAL(0, m_calcEngine->IsNumberInvalid(str, 100, 100, 10 /* Dec */)); - } - for (wstring const& str : invalidDecStrs) - { - VERIFY_ARE_EQUAL(IDS_ERR_UNK_CH, m_calcEngine->IsNumberInvalid(str, 100, 100, 10 /* Dec */)); - } - - } - - TEST_METHOD(TestDigitGroupingStringToGroupingVector) - { - vector groupingVector{}; - VERIFY_ARE_EQUAL(groupingVector, CCalcEngine::DigitGroupingStringToGroupingVector(L""), L"Verify empty grouping"); - - groupingVector = { 1 }; - VERIFY_ARE_EQUAL(groupingVector, CCalcEngine::DigitGroupingStringToGroupingVector(L"1"), L"Verify simple grouping"); - - groupingVector = { 3, 0 }; - VERIFY_ARE_EQUAL(groupingVector, CCalcEngine::DigitGroupingStringToGroupingVector(L"3;0"), L"Verify standard grouping"); - - groupingVector = { 3, 0, 0 }; - VERIFY_ARE_EQUAL(groupingVector, CCalcEngine::DigitGroupingStringToGroupingVector(L"3;0;0"), L"Verify expanded non-repeating grouping"); - - groupingVector = { 5, 3, 2, 4, 6 }; - VERIFY_ARE_EQUAL(groupingVector, CCalcEngine::DigitGroupingStringToGroupingVector(L"5;3;2;4;6"), L"Verify long grouping"); - - groupingVector = { 15, 15, 15, 0 }; - VERIFY_ARE_EQUAL(groupingVector, CCalcEngine::DigitGroupingStringToGroupingVector(L"15;15;15;0"), L"Verify large grouping"); - - groupingVector = { 4, 7, 0 }; - VERIFY_ARE_EQUAL(groupingVector, CCalcEngine::DigitGroupingStringToGroupingVector(L"4;16;7;25;0"), L"Verify we ignore oversize grouping"); - } - - TEST_METHOD(TestGroupDigits) - { - wstring result{ L"1234567" }; - VERIFY_ARE_EQUAL(result, m_calcEngine->GroupDigits(L"", { 3, 0 }, L"1234567", false), L"Verify handling of empty delimiter."); - VERIFY_ARE_EQUAL(result, m_calcEngine->GroupDigits(L",", {}, L"1234567", false), L"Verify handling of empty grouping."); - - result = L"1,234,567"; - VERIFY_ARE_EQUAL(result, m_calcEngine->GroupDigits(L",", { 3, 0 }, L"1234567", false), L"Verify standard digit grouping."); - - result = L"1 234 567"; - VERIFY_ARE_EQUAL(result, m_calcEngine->GroupDigits(L" ", { 3, 0 }, L"1234567", false), L"Verify delimiter change."); - - result = L"1|||234|||567"; - VERIFY_ARE_EQUAL(result, m_calcEngine->GroupDigits(L"|||", { 3, 0 }, L"1234567", false), L"Verify long delimiter."); - - result = L"12,345e67"; - VERIFY_ARE_EQUAL(result, m_calcEngine->GroupDigits(L",", { 3, 0 }, L"12345e67", false), L"Verify respect of exponent."); - - result = L"12,345.67"; - VERIFY_ARE_EQUAL(result, m_calcEngine->GroupDigits(L",", { 3, 0 }, L"12345.67", false), L"Verify respect of decimal."); - - result = L"1,234.56e7"; - VERIFY_ARE_EQUAL(result, m_calcEngine->GroupDigits(L",", { 3, 0 }, L"1234.56e7", false), L"Verify respect of exponent and decimal."); - - result = L"-1,234,567"; - VERIFY_ARE_EQUAL(result, m_calcEngine->GroupDigits(L",", { 3, 0 }, L"-1234567", true), L"Verify negative number grouping."); - - // Test various groupings - result = L"1234567890123456"; - VERIFY_ARE_EQUAL(result, m_calcEngine->GroupDigits(L",", { 0, 0 }, L"1234567890123456", false), L"Verify no grouping."); - - result = L"1234567890123,456"; - VERIFY_ARE_EQUAL(result, m_calcEngine->GroupDigits(L",", { 3 }, L"1234567890123456", false), L"Verify non-repeating grouping."); - VERIFY_ARE_EQUAL(result, m_calcEngine->GroupDigits(L",", { 3, 0, 0 }, L"1234567890123456", false), L"Verify expanded form non-repeating grouping."); - - result = L"12,34,56,78,901,23456"; - VERIFY_ARE_EQUAL(result, m_calcEngine->GroupDigits(L",", { 5, 3, 2, 0 }, L"1234567890123456", false), L"Verify multigroup with repeating grouping."); - - result = L"1234,5678,9012,3456"; - VERIFY_ARE_EQUAL(result, m_calcEngine->GroupDigits(L",", { 4, 0 }, L"1234567890123456", false), L"Verify repeating non-standard grouping."); - - result = L"123456,78,901,23456"; - VERIFY_ARE_EQUAL(result, m_calcEngine->GroupDigits(L",", { 5, 3, 2 }, L"1234567890123456", false), L"Verify multigroup non-repeating grouping."); - VERIFY_ARE_EQUAL(result, m_calcEngine->GroupDigits(L",", { 5, 3, 2, 0, 0 }, L"1234567890123456", false), L"Verify expanded form multigroup non-repeating grouping."); - } - - private: - unique_ptr m_calcEngine; - shared_ptr m_resourceProvider; - shared_ptr m_history; - }; -} diff --git a/internal/CalculatorUnitTests/CalcInputTest.cpp b/internal/CalculatorUnitTests/CalcInputTest.cpp deleted file mode 100644 index e29072b..0000000 --- a/internal/CalculatorUnitTests/CalcInputTest.cpp +++ /dev/null @@ -1,366 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#include "pch.h" -#include - -using namespace std; -using namespace WEX::Common; -using namespace WEX::Logging; -using namespace WEX::TestExecution; - -using namespace CalculationManager; - -namespace CalculatorUnitTests -{ - class CalcInputTest - { - TEST_CLASS(CalcInputTest); - TEST_CLASS_SETUP(CommonSetup) - { - m_calcInput = CalcEngine::CalcInput(L'.'); - return true; - } - TEST_METHOD_CLEANUP(Cleanup) - { - m_calcInput.Clear(); - m_calcInput.SetDecimalSymbol(L'.'); - return true; - } - - TEST_METHOD(Clear) - { - m_calcInput.TryAddDigit(1, 10, false, L"999", 64, 32); - m_calcInput.TryToggleSign(false, L"999"); - m_calcInput.TryAddDecimalPt(); - m_calcInput.TryAddDigit(2, 10, false, L"999", 64, 32); - m_calcInput.TryBeginExponent(); - m_calcInput.TryAddDigit(3, 10, false, L"999", 64, 32); - - VERIFY_ARE_EQUAL(L"-1.2e+3", m_calcInput.ToString(10, false), L"Verify input is correct."); - - m_calcInput.Clear(); - - ::Log::Comment(m_calcInput.ToString(10, false).c_str()); - VERIFY_ARE_EQUAL(L"0", m_calcInput.ToString(10, false), L"Verify input is 0 after clear."); - } - - TEST_METHOD(TryToggleSignZero) - { - VERIFY_IS_TRUE(m_calcInput.TryToggleSign(false, L"999"), L"Verify toggling 0 succeeds."); - VERIFY_ARE_EQUAL(L"0", m_calcInput.ToString(10, false), L"Verify toggling 0 does not create -0."); - } - TEST_METHOD(TryToggleSignExponent) - { - m_calcInput.TryAddDigit(1, 10, false, L"999", 64, 32); - m_calcInput.TryBeginExponent(); - m_calcInput.TryAddDigit(2, 10, false, L"999", 64, 32); - VERIFY_IS_TRUE(m_calcInput.TryToggleSign(false, L"999"), L"Verify toggling exponent sign succeeds."); - VERIFY_ARE_EQUAL(L"1.e-2", m_calcInput.ToString(10, false), L"Verify toggling exponent sign does not toggle base sign."); - VERIFY_IS_TRUE(m_calcInput.TryToggleSign(false, L"999"), L"Verify toggling exponent sign succeeds."); - VERIFY_ARE_EQUAL(L"1.e+2", m_calcInput.ToString(10, false), L"Verify toggling negative exponent sign does not toggle base sign."); - } - TEST_METHOD(TryToggleSignBase) - { - m_calcInput.TryAddDigit(1, 10, false, L"999", 64, 32); - VERIFY_IS_TRUE(m_calcInput.TryToggleSign(false, L"999"), L"Verify toggling base sign succeeds."); - VERIFY_ARE_EQUAL(L"-1", m_calcInput.ToString(10, false), L"Verify toggling base sign creates negative base."); - VERIFY_IS_TRUE(m_calcInput.TryToggleSign(false, L"999"), L"Verify toggling base sign succeeds."); - VERIFY_ARE_EQUAL(L"1", m_calcInput.ToString(10, false), L"Verify toggling negative base sign creates positive base."); - } - TEST_METHOD(TryToggleSignBaseIntegerMode) - { - m_calcInput.TryAddDigit(1, 10, false, L"999", 64, 32); - VERIFY_IS_TRUE(m_calcInput.TryToggleSign(true, L"999"), L"Verify toggling base sign in integer mode succeeds."); - VERIFY_ARE_EQUAL(L"-1", m_calcInput.ToString(10, false), L"Verify toggling base sign creates negative base."); - } - TEST_METHOD(TryToggleSignRollover) - { - m_calcInput.TryAddDigit(1, 10, false, L"999", 64, 32); - m_calcInput.TryAddDigit(2, 10, false, L"999", 64, 32); - VERIFY_IS_TRUE(m_calcInput.TryToggleSign(true, L"127"), L"Verify toggling base sign in integer mode succeeds."); - m_calcInput.TryAddDigit(8, 10, false, L"999", 64, 32); - VERIFY_IS_FALSE(m_calcInput.TryToggleSign(true, L"127"), L"Verify toggling base sign in integer mode fails on rollover."); - VERIFY_ARE_EQUAL(L"-128", m_calcInput.ToString(10, false), L"Verify toggling base sign on rollover does not change value."); - } - - TEST_METHOD(TryAddDigitLeadingZeroes) - { - VERIFY_IS_TRUE(m_calcInput.TryAddDigit(0, 10, false, L"999", 64, 32), L"Verify TryAddDigit succeeds."); - VERIFY_IS_TRUE(m_calcInput.TryAddDigit(0, 10, false, L"999", 64, 32), L"Verify TryAddDigit succeeds."); - VERIFY_IS_TRUE(m_calcInput.TryAddDigit(0, 10, false, L"999", 64, 32), L"Verify TryAddDigit succeeds."); - VERIFY_ARE_EQUAL(L"0", m_calcInput.ToString(10, false), L"Verify leading zeroes are ignored."); - } - TEST_METHOD(TryAddDigitMaxCount) - { - VERIFY_IS_TRUE(m_calcInput.TryAddDigit(1, 10, false, L"999", 64, 32), L"Verify TryAddDigit for base with length < maxDigits succeeds."); - VERIFY_ARE_EQUAL(L"1", m_calcInput.ToString(10, false), L"Verify adding digit for base with length < maxDigits succeeded."); - VERIFY_IS_FALSE(m_calcInput.TryAddDigit(2, 10, false, L"999", 64, 1), L"Verify TryAddDigit for base with length > maxDigits fails."); - VERIFY_ARE_EQUAL(L"1", m_calcInput.ToString(10, false), L"Verify digit for base was not added."); - m_calcInput.TryBeginExponent(); - VERIFY_IS_TRUE(m_calcInput.TryAddDigit(1, 10, false, L"999", 64, 32), L"Verify TryAddDigit for exponent with length < maxDigits succeeds."); - VERIFY_IS_TRUE(m_calcInput.TryAddDigit(2, 10, false, L"999", 64, 32), L"Verify TryAddDigit for exponent with length < maxDigits succeeds."); - VERIFY_IS_TRUE(m_calcInput.TryAddDigit(3, 10, false, L"999", 64, 32), L"Verify TryAddDigit for exponent with length < maxDigits succeeds."); - VERIFY_IS_TRUE(m_calcInput.TryAddDigit(4, 10, false, L"999", 64, 32), L"Verify TryAddDigit for exponent with length < maxDigits succeeds."); - VERIFY_IS_FALSE(m_calcInput.TryAddDigit(5, 10, false, L"999", 64, 32), L"Verify TryAddDigit for exponent with length > maxDigits fails."); - VERIFY_ARE_EQUAL(L"1.e+1234", m_calcInput.ToString(10, false), L"Verify adding digits for exponent with length < maxDigits succeeded."); - - m_calcInput.Clear(); - m_calcInput.TryAddDecimalPt(); - VERIFY_IS_TRUE(m_calcInput.TryAddDigit(1, 10, false, L"999", 64, 1), L"Verify decimal point and leading zero does not count toward maxDigits."); - VERIFY_ARE_EQUAL(L"0.1", m_calcInput.ToString(10, false), L"Verify input value checking dec pt and leading zero impact on maxDigits."); - } - TEST_METHOD(TryAddDigitValues) - { - // Use an arbitrary value > 16 to test that input accepts digits > hexadecimal 0xF. - // TryAddDigit does not validate whether the digit fits within the current radix. - for (unsigned int i = 0; i < 25; i++) - { - VERIFY_IS_TRUE(m_calcInput.TryAddDigit(i, 10, false, L"999", 64, 32), String().Format(L"Verify TryAddDigit succeeds for %d", i)); - m_calcInput.Clear(); - } - } - TEST_METHOD(TryAddDigitRolloverBaseCheck) - { - m_calcInput.TryAddDigit(1, 10, false, L"999", 64, 32); - VERIFY_IS_FALSE(m_calcInput.TryAddDigit(2, 16, true, L"999", 64, 1), L"Verify TryAddDigit rollover fails for bases other than 8,10."); - VERIFY_IS_FALSE(m_calcInput.TryAddDigit(1, 2, true, L"999", 64, 1), L"Verify TryAddDigit rollover fails for bases other than 8,10."); - } - TEST_METHOD(TryAddDigitRolloverOctalByte) - { - m_calcInput.TryAddDigit(1, 8, true, L"777", 64, 32); - VERIFY_IS_TRUE(m_calcInput.TryAddDigit(2, 8, true, L"377", 8, 1), L"Verify we can add an extra digit in OctalByte if first digit <= 3."); - - m_calcInput.Clear(); - m_calcInput.TryAddDigit(4, 8, true, L"777", 64, 32); - VERIFY_IS_FALSE(m_calcInput.TryAddDigit(2, 8, true, L"377", 8, 1), L"Verify we cannot add an extra digit in OctalByte if first digit > 3."); - } - TEST_METHOD(TryAddDigitRolloverOctalWord) - { - m_calcInput.TryAddDigit(1, 8, true, L"777", 64, 32); - VERIFY_IS_TRUE(m_calcInput.TryAddDigit(2, 8, true, L"377", 16, 1), L"Verify we can add an extra digit in OctalByte if first digit == 1."); - - m_calcInput.Clear(); - m_calcInput.TryAddDigit(2, 8, true, L"777", 64, 32); - VERIFY_IS_FALSE(m_calcInput.TryAddDigit(2, 8, true, L"377", 16, 1), L"Verify we cannot add an extra digit in OctalByte if first digit > 1."); - } - TEST_METHOD(TryAddDigitRolloverOctalDword) - { - m_calcInput.TryAddDigit(1, 8, true, L"777", 64, 32); - VERIFY_IS_TRUE(m_calcInput.TryAddDigit(2, 8, true, L"377", 32, 1), L"Verify we can add an extra digit in OctalByte if first digit <= 3."); - - m_calcInput.Clear(); - m_calcInput.TryAddDigit(4, 8, true, L"777", 64, 32); - VERIFY_IS_FALSE(m_calcInput.TryAddDigit(2, 8, true, L"377", 32, 1), L"Verify we cannot add an extra digit in OctalByte if first digit > 3."); - } - TEST_METHOD(TryAddDigitRolloverOctalQword) - { - m_calcInput.TryAddDigit(1, 8, true, L"777", 64, 32); - VERIFY_IS_TRUE(m_calcInput.TryAddDigit(2, 8, true, L"377", 64, 1), L"Verify we can add an extra digit in OctalByte if first digit == 1."); - - m_calcInput.Clear(); - m_calcInput.TryAddDigit(2, 8, true, L"777", 64, 32); - VERIFY_IS_FALSE(m_calcInput.TryAddDigit(2, 8, true, L"377", 64, 1), L"Verify we cannot add an extra digit in OctalByte if first digit > 1."); - } - TEST_METHOD(TryAddDigitRolloverDecimal) - { - m_calcInput.TryAddDigit(1, 10, true, L"127", 64, 32); - VERIFY_IS_FALSE(m_calcInput.TryAddDigit(0, 10, true, L"1", 8, 1), L"Verify we cannot add a digit if input size matches maxStr size."); - m_calcInput.TryAddDigit(2, 10, true, L"127", 64, 32); - VERIFY_IS_FALSE(m_calcInput.TryAddDigit(2, 10, true, L"110", 8, 2), L"Verify we cannot add a digit if n char comparison > 0."); - VERIFY_IS_TRUE(m_calcInput.TryAddDigit(7, 10, true, L"130", 8, 2), L"Verify we can add a digit if n char comparison < 0."); - - m_calcInput.Clear(); - m_calcInput.TryAddDigit(1, 10, true, L"127", 64, 32); - m_calcInput.TryAddDigit(2, 10, true, L"127", 64, 32); - VERIFY_IS_FALSE(m_calcInput.TryAddDigit(8, 10, true, L"127", 8, 2), L"Verify we cannot add a digit if digit exceeds max value."); - VERIFY_IS_TRUE(m_calcInput.TryAddDigit(7, 10, true, L"127", 8, 2), L"Verify we can add a digit if digit does not exceed max value."); - - m_calcInput.Backspace(); - m_calcInput.TryToggleSign(true, L"127"); - VERIFY_IS_FALSE(m_calcInput.TryAddDigit(9, 10, true, L"127", 8, 2), L"Negative value: verify we cannot add a digit if digit exceeds max value."); - VERIFY_IS_TRUE(m_calcInput.TryAddDigit(8, 10, true, L"127", 8, 2), L"Negative value: verify we can add a digit if digit does not exceed max value."); - } - - TEST_METHOD(TryAddDecimalPtEmpty) - { - VERIFY_IS_FALSE(m_calcInput.HasDecimalPt(), L"Verify input has no decimal point."); - VERIFY_IS_TRUE(m_calcInput.TryAddDecimalPt(), L"Verify adding decimal to empty input."); - VERIFY_IS_TRUE(m_calcInput.HasDecimalPt(), L"Verify input has decimal point."); - VERIFY_ARE_EQUAL(L"0.", m_calcInput.ToString(10, false), L"Verify decimal on empty input."); - } - TEST_METHOD(TryAddDecimalPointTwice) - { - VERIFY_IS_FALSE(m_calcInput.HasDecimalPt(), L"Verify input has no decimal point."); - VERIFY_IS_TRUE(m_calcInput.TryAddDecimalPt(), L"Verify adding decimal to empty input."); - VERIFY_IS_TRUE(m_calcInput.HasDecimalPt(), L"Verify input has decimal point."); - VERIFY_IS_FALSE(m_calcInput.TryAddDecimalPt(), L"Verify adding decimal point fails if input has decimal point."); - } - TEST_METHOD(TryAddDecimalPointExponent) - { - m_calcInput.TryAddDigit(1, 10, false, L"999", 64, 32); - m_calcInput.TryBeginExponent(); - m_calcInput.TryAddDigit(2, 10, false, L"999", 64, 32); - VERIFY_IS_FALSE(m_calcInput.TryAddDecimalPt(), L"Verify adding decimal point fails if input has exponent."); - } - - TEST_METHOD(TryBeginExponentNoExponent) - { - m_calcInput.TryAddDigit(1, 10, false, L"999", 64, 32); - VERIFY_IS_TRUE(m_calcInput.TryBeginExponent(), L"Verify adding exponent succeeds on input without exponent."); - VERIFY_ARE_EQUAL(L"1.e+0", m_calcInput.ToString(10, false), L"Verify exponent present."); - } - TEST_METHOD(TryBeginExponentWithExponent) - { - m_calcInput.TryAddDigit(1, 10, false, L"999", 64, 32); - VERIFY_IS_TRUE(m_calcInput.TryBeginExponent(), L"Verify adding exponent succeeds on input without exponent."); - VERIFY_IS_FALSE(m_calcInput.TryBeginExponent(), L"Verify cannot add exponent if input already has exponent."); - } - - TEST_METHOD(BackspaceZero) - { - m_calcInput.Backspace(); - VERIFY_ARE_EQUAL(L"0", m_calcInput.ToString(10, false), L"Verify backspace on 0 is still 0."); - } - TEST_METHOD(BackspaceSingleChar) - { - m_calcInput.TryAddDigit(1, 10, false, L"999", 64, 32); - VERIFY_ARE_EQUAL(L"1", m_calcInput.ToString(10, false), L"Verify input before backspace."); - m_calcInput.Backspace(); - VERIFY_ARE_EQUAL(L"0", m_calcInput.ToString(10, false), L"Verify input after backspace."); - } - TEST_METHOD(BackspaceMultiChar) - { - m_calcInput.TryAddDigit(1, 10, false, L"999", 64, 32); - m_calcInput.TryAddDigit(2, 10, false, L"999", 64, 32); - VERIFY_ARE_EQUAL(L"12", m_calcInput.ToString(10, false), L"Verify input before backspace."); - m_calcInput.Backspace(); - VERIFY_ARE_EQUAL(L"1", m_calcInput.ToString(10, false), L"Verify input after backspace."); - } - TEST_METHOD(BackspaceDecimal) - { - m_calcInput.TryAddDigit(1, 10, false, L"999", 64, 32); - m_calcInput.TryAddDecimalPt(); - VERIFY_ARE_EQUAL(L"1.", m_calcInput.ToString(10, false), L"Verify input before backspace."); - VERIFY_IS_TRUE(m_calcInput.HasDecimalPt(), L"Verify input has decimal point."); - m_calcInput.Backspace(); - VERIFY_ARE_EQUAL(L"1", m_calcInput.ToString(10, false), L"Verify input after backspace."); - VERIFY_IS_FALSE(m_calcInput.HasDecimalPt(), L"Verify decimal point was removed."); - } - TEST_METHOD(BackspaceMultiCharDecimal) - { - m_calcInput.TryAddDigit(1, 10, false, L"999", 64, 32); - m_calcInput.TryAddDecimalPt(); - m_calcInput.TryAddDigit(2, 10, false, L"999", 64, 32); - m_calcInput.TryAddDigit(3, 10, false, L"999", 64, 32); - VERIFY_ARE_EQUAL(L"1.23", m_calcInput.ToString(10, false), L"Verify input before backspace."); - m_calcInput.Backspace(); - VERIFY_ARE_EQUAL(L"1.2", m_calcInput.ToString(10, false), L"Verify input after backspace."); - } - - TEST_METHOD(SetDecimalSymbol) - { - m_calcInput.TryAddDecimalPt(); - VERIFY_ARE_EQUAL(L"0.", m_calcInput.ToString(10, false), L"Verify default decimal point."); - m_calcInput.SetDecimalSymbol(L','); - VERIFY_ARE_EQUAL(L"0,", m_calcInput.ToString(10, false), L"Verify new decimal point."); - } - - TEST_METHOD(ToStringEmpty) - { - VERIFY_ARE_EQUAL(L"0", m_calcInput.ToString(10, false), L"Verify ToString of empty value."); - } - TEST_METHOD(ToStringNegative) - { - m_calcInput.TryAddDigit(1, 10, false, L"999", 64, 32); - m_calcInput.TryToggleSign(false, L"999"); - VERIFY_ARE_EQUAL(L"-1", m_calcInput.ToString(10, false), L"Verify ToString of negative value."); - } - TEST_METHOD(ToStringExponentBase10) - { - m_calcInput.TryAddDigit(1, 10, false, L"999", 64, 32); - m_calcInput.TryBeginExponent(); - VERIFY_ARE_EQUAL(L"1.e+0", m_calcInput.ToString(10, false), L"Verify ToString of empty base10 exponent."); - } - TEST_METHOD(ToStringExponentBase8) - { - m_calcInput.TryAddDigit(1, 10, false, L"999", 64, 32); - m_calcInput.TryBeginExponent(); - VERIFY_ARE_EQUAL(L"1.^+0", m_calcInput.ToString(8, false), L"Verify ToString of empty base8 exponent."); - } - TEST_METHOD(ToStringExponentNegative) - { - m_calcInput.TryAddDigit(1, 8, false, L"999", 64, 32); - m_calcInput.TryBeginExponent(); - m_calcInput.TryToggleSign(false, L"999"); - VERIFY_ARE_EQUAL(L"1.e-0", m_calcInput.ToString(10, false), L"Verify ToString of empty negative exponent."); - } - TEST_METHOD(ToStringExponentPositive) - { - m_calcInput.TryAddDigit(1, 10, false, L"999", 64, 32); - m_calcInput.TryBeginExponent(); - m_calcInput.TryAddDigit(2, 10, false, L"999", 64, 32); - m_calcInput.TryAddDigit(3, 10, false, L"999", 64, 32); - m_calcInput.TryAddDigit(4, 10, false, L"999", 64, 32); - VERIFY_ARE_EQUAL(L"1.e+234", m_calcInput.ToString(10, false), L"Verify ToString of exponent with value."); - } - TEST_METHOD(ToStringInteger) - { - m_calcInput.TryAddDigit(1, 10, false, L"999", 64, 32); - VERIFY_ARE_EQUAL(L"1", m_calcInput.ToString(10, true), L"Verify ToString of integer value hides decimal."); - } - TEST_METHOD(ToStringBaseTooLong) - { - wstring maxStr{}; - for (size_t i = 0; i < MAX_STRLEN + 1; i++) - { - maxStr += L"1"; - m_calcInput.TryAddDigit(1, 10, false, maxStr, 64, 100); - } - auto result = m_calcInput.ToString(10, false); - VERIFY_IS_TRUE(result.empty(), L"Verify ToString of base value that is too large yields empty string."); - } - TEST_METHOD(ToStringExponentTooLong) - { - m_calcInput.TryAddDigit(1, 10, false, L"999", 64, 32); - m_calcInput.TryBeginExponent(); - wstring maxStr{L"11"}; - bool exponentCapped = false; - for (size_t i = 0; i < MAX_STRLEN + 1; i++) - { - maxStr += L"1"; - if (!m_calcInput.TryAddDigit(1, 10, false, maxStr, 64, MAX_STRLEN + 25)) - { - exponentCapped = true; - } - } - auto result = m_calcInput.ToString(10, false); - - // TryAddDigit caps the exponent length to C_EXP_MAX_DIGITS = 4, so ToString() succeeds. - // If that cap is removed, ToString() should return an empty string. - if (exponentCapped) - { - VERIFY_ARE_EQUAL(L"1.e+1111", result, L"Verify ToString succeeds; exponent length is capped at C_EXP_MAX_DIGITS."); - } - else - { - VERIFY_IS_TRUE(result.empty(), L"Verify ToString of exponent value that is too large yields empty string."); - } - } - - TEST_METHOD(ToRational) - { - m_calcInput.TryAddDigit(1, 10, false, L"999", 64, 32); - m_calcInput.TryAddDigit(2, 10, false, L"999", 64, 32); - m_calcInput.TryAddDigit(3, 10, false, L"999", 64, 32); - VERIFY_ARE_EQUAL(L"123", m_calcInput.ToString(10, false), L"Verify input before conversion to rational."); - - auto rat = m_calcInput.ToRational(10, false); - VERIFY_ARE_EQUAL(1, rat.P().Mantissa().size(), L"Verify digit count of rational."); - VERIFY_ARE_EQUAL(123, rat.P().Mantissa().front(), L"Verify first digit of mantissa."); - } - - private: - CalcEngine::CalcInput m_calcInput; - }; -} diff --git a/internal/CalculatorUnitTests/CalculatorManagerTest.cpp b/internal/CalculatorUnitTests/CalculatorManagerTest.cpp deleted file mode 100644 index 5101e7d..0000000 --- a/internal/CalculatorUnitTests/CalculatorManagerTest.cpp +++ /dev/null @@ -1,1123 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#include "pch.h" - -#include - -#include "CalcManager\CalculatorHistory.h" -#include "CalcViewModel\Common\EngineResourceProvider.h" - -using namespace CalculatorApp; -using namespace CalculationManager; -using namespace Platform; -using namespace std; - -namespace CalculatorManagerTest -{ - class CalculatorManagerDisplayTester : public ICalcDisplay - { - public: - CalculatorManagerDisplayTester() - { - Reset(); - } - - void Reset() - { - m_isError = false; - m_maxDigitsCalledCount = 0; - m_binaryOperatorReceivedCallCount = 0; - } - - void SetPrimaryDisplay(const wstring& text, bool isError) override - { - m_primaryDisplay = text; - m_isError = isError; - } - void SetIsInError(bool isError) override - { - m_isError = isError; - } - void SetExpressionDisplay(_Inout_ std::shared_ptr>> const &tokens, _Inout_ std::shared_ptr>> const &commands) - { - m_expression.clear(); - unsigned int nTokens = 0; - std::pair currentPair; - tokens->GetSize(&nTokens); - for (unsigned int i = 0; i < nTokens; ++i) - { - tokens->GetAt(i, ¤tPair); - m_expression += currentPair.first; - } - } - void SetMemorizedNumbers(const vector& numbers) override - { - m_memorizedNumberStrings = numbers; - } - - void SetParenDisplayText(const std::wstring& parenthesisCount) override - { - m_parenDisplay = parenthesisCount; - } - - const wstring& GetPrimaryDisplay() const - { - return m_primaryDisplay; - } - const wstring& GetExpression() const - { - return m_expression; - } - const vector& GetMemorizedNumbers() const - { - return m_memorizedNumberStrings; - } - bool GetIsError() const - { - return m_isError; - } - - void OnHistoryItemAdded(_In_ unsigned int addedItemIndex) - { - } - - void MaxDigitsReached() override - { - m_maxDigitsCalledCount++; - } - - int GetMaxDigitsCalledCount() - { - return m_maxDigitsCalledCount; - } - - void BinaryOperatorReceived() - { - m_binaryOperatorReceivedCallCount++; - } - - void MemoryItemChanged(unsigned int indexOfMemory) - { - } - - int GetBinaryOperatorReceivedCallCount() - { - return m_binaryOperatorReceivedCallCount; - } - - private: - wstring m_primaryDisplay; - wstring m_expression; - wstring m_parenDisplay; - bool m_isError; - vector m_memorizedNumberStrings; - int m_maxDigitsCalledCount; - int m_binaryOperatorReceivedCallCount; - }; - - - class TestDriver - { - private: - static shared_ptr m_displayTester; - static shared_ptr m_calculatorManager; - - public: - static void Initialize(shared_ptr displayTester, shared_ptr calculatorManager) - { - m_displayTester = displayTester; - m_calculatorManager = calculatorManager; - } - - static void Test(wstring expectedPrimary, wstring expectedExpression, Command testCommands[], - bool cleanup = true, bool isScientific = false) - { - if (cleanup) - { - m_calculatorManager->Reset(); - } - - if (isScientific) - { - m_calculatorManager->SendCommand(Command::ModeScientific); - } - - Command* currentCommand = testCommands; - while (*currentCommand != Command::CommandNULL) - { - m_calculatorManager->SendCommand(*currentCommand++); - } - - VERIFY_ARE_EQUAL(expectedPrimary, m_displayTester->GetPrimaryDisplay()); - if (expectedExpression != L"N/A") - { - VERIFY_ARE_EQUAL(expectedExpression, m_displayTester->GetExpression()); - } - } - }; - - class CalculatorManagerTest - { - public: - // Declare this class as a TestClass, and supply metadata if necessary. - TEST_CLASS(CalculatorManagerTest); - TEST_CLASS_SETUP(CommonSetup); - - TEST_METHOD(CalculatorManagerTestStandard); - - TEST_METHOD(CalculatorManagerTestScientific); - TEST_METHOD(CalculatorManagerTestScientific2); - TEST_METHOD(CalculatorManagerTestScientificParenthesis); - TEST_METHOD(CalculatorManagerTestScientificError); - TEST_METHOD(CalculatorManagerTestScientificModeChange); - - TEST_METHOD(CalculatorManagerTestModeChange); - - TEST_METHOD(CalculatorManagerTestMemory); - - TEST_METHOD(CalculatorManagerTestSerialize); - TEST_METHOD(CalculatorManagerTestSerializePrecision); - TEST_METHOD(CalculatorManagerTestSerializeMultiple); - TEST_METHOD(CalculatorManagerTestSerializeDegreeMode); - TEST_METHOD(CalculatorManagerTestSerializeMemory); - - TEST_METHOD(CalculatorManagerTestMaxDigitsReached); - TEST_METHOD(CalculatorManagerTestMaxDigitsReached_LeadingDecimal); - TEST_METHOD(CalculatorManagerTestMaxDigitsReached_TrailingDecimal); - - TEST_METHOD(CalculatorManagerTestBinaryOperatorReceived); - TEST_METHOD(CalculatorManagerTestBinaryOperatorReceived_Multiple); - TEST_METHOD(CalculatorManagerTestBinaryOperatorReceived_LongInput); - - TEST_METHOD_CLEANUP(Cleanup); - - - private: - static std::shared_ptr m_calculatorManager; - static std::shared_ptr m_resourceProvider; - static std::shared_ptr m_calculatorDisplayTester; - void ExecuteCommands(Command commands[]); - void ExecuteCommands(const vector& commands); - - vector CommandListFromStringInput(const wstring& input) - { - vector result{}; - for (auto iter = input.begin(); iter != input.end(); iter++) - { - wchar_t ch = *iter; - Command asCommand = Command::CommandNULL; - if (ch == L'.') - { - asCommand = Command::CommandPNT; - } - else if (L'0' <= ch && ch <= L'9') - { - int diff = static_cast(ch) - static_cast(L'0'); - asCommand = static_cast(diff + static_cast(Command::Command0)); - } - - if (asCommand != Command::CommandNULL) - { - result.push_back(asCommand); - } - } - - return result; - } - - void TestMaxDigitsReachedScenario(const wstring& constInput) - { - CalculatorManagerDisplayTester* pCalculatorDisplay = (CalculatorManagerDisplayTester *)m_calculatorDisplayTester.get(); - - // Make sure we're in a clean state. - VERIFY_ARE_EQUAL(0, pCalculatorDisplay->GetMaxDigitsCalledCount()); - - vector commands = CommandListFromStringInput(constInput); - VERIFY_IS_FALSE(commands.empty()); - - // The last element in the list should always cause MaxDigitsReached - // Remember the command but remove from the actual input that is sent - Command finalInput = commands[commands.size() - 1]; - commands.pop_back(); - wstring input = constInput.substr(0, constInput.length() - 1); - - m_calculatorManager->SetStandardMode(); - ExecuteCommands(commands); - - wstring expectedDisplay = input; - wstring display = pCalculatorDisplay->GetPrimaryDisplay(); - VERIFY_ARE_EQUAL(expectedDisplay, display); - - m_calculatorManager->SendCommand(finalInput); - - // Verify MaxDigitsReached - display = pCalculatorDisplay->GetPrimaryDisplay(); - VERIFY_ARE_EQUAL(expectedDisplay, display); - - // MaxDigitsReached should have been called once - VERIFY_IS_LESS_THAN(0, pCalculatorDisplay->GetMaxDigitsCalledCount()); - } - - void SerialzieAndDeSerialize() - { - auto serializedCommands = m_calculatorManager->SerializeCommands(); - auto serializedMemory = m_calculatorManager->GetSerializedMemory(); - auto serializedDisplay = m_calculatorManager->GetSerializedPrimaryDisplay(); - - Cleanup(); - - m_calculatorManager->DeSerializePrimaryDisplay(serializedDisplay); - m_calculatorManager->DeSerializeMemory(serializedMemory); - m_calculatorManager->DeSerializeCommands(serializedCommands); - } - - void VerifyPersistence() - { - auto savedPrimary = m_calculatorDisplayTester->GetPrimaryDisplay(); - auto savedExpression = m_calculatorDisplayTester->GetExpression(); - auto savedMemory = m_calculatorDisplayTester->GetMemorizedNumbers(); - SerialzieAndDeSerialize(); - VERIFY_ARE_EQUAL(savedPrimary, m_calculatorDisplayTester->GetPrimaryDisplay()); - VERIFY_ARE_EQUAL(savedExpression, m_calculatorDisplayTester->GetExpression()); - auto loadedMemory = m_calculatorDisplayTester->GetMemorizedNumbers(); - VERIFY_ARE_EQUAL(savedMemory.size(), loadedMemory.size()); - for (unsigned int i = 0; i < savedMemory.size(); i++) - { - VERIFY_ARE_EQUAL(savedMemory.at(i), loadedMemory.at(i)); - } - } - }; - - std::shared_ptr CalculatorManagerTest::m_calculatorManager; - std::shared_ptr CalculatorManagerTest::m_calculatorDisplayTester; - std::shared_ptr CalculatorManagerTest::m_resourceProvider; - std::shared_ptr TestDriver::m_displayTester; - std::shared_ptr TestDriver::m_calculatorManager; - - // Creates instance of CalculationManager before running tests - bool CalculatorManagerTest::CommonSetup() - { - m_calculatorDisplayTester = std::make_shared(); - m_resourceProvider = std::make_shared(); - m_calculatorManager = std::make_shared(m_calculatorDisplayTester.get(), m_resourceProvider.get()); - TestDriver::Initialize(m_calculatorDisplayTester, m_calculatorManager); - return true; - } - - // Resets calculator state to start state after each test - bool CalculatorManagerTest::Cleanup() - { - m_calculatorManager->Reset(); - m_calculatorDisplayTester->Reset(); - return true; - } - - void CalculatorManagerTest::ExecuteCommands(Command commands[]) - { - Command* itr = commands; - while (*itr != Command::CommandNULL) - { - m_calculatorManager->SendCommand(*itr); - itr++; - } - } - - void CalculatorManagerTest::ExecuteCommands(const vector& commands) - { - for (const Command& command : commands) - { - if (command == Command::CommandNULL) - { - break; - } - - m_calculatorManager->SendCommand(command); - } - } - - void CalculatorManagerTest::CalculatorManagerTestStandard() - { - Command commands1[] = { Command::Command1, Command::Command2, Command::Command3, - Command::CommandPNT, Command::Command4, Command::Command5, Command::Command6, Command::CommandNULL }; - TestDriver::Test(L"123.456", L"", commands1); - - Command commands2[] = { Command::CommandADD, Command::CommandNULL }; - TestDriver::Test(L"0", L"0 + ", commands2); - - Command commands3[] = { Command::CommandSQRT, Command::CommandNULL }; - TestDriver::Test(L"0", L"\x221A(0)", commands3); - - Command commands4[] = { Command::Command2, Command::CommandADD, Command::Command3, - Command::CommandEQU, Command::Command4, Command::CommandEQU, Command::CommandNULL }; - TestDriver::Test(L"7", L"", commands4); - - Command commands5[] = { Command::Command4, Command::CommandEQU, Command::CommandNULL }; - TestDriver::Test(L"4", L"", commands5); - - Command commands6[] = { Command::Command2, Command::Command5, Command::Command6, - Command::CommandSQRT, Command::CommandSQRT, Command::CommandSQRT, Command::CommandNULL }; - TestDriver::Test(L"2", L"\x221A(\x221A(\x221A(256)))", commands6); - - Command commands7[] = { Command::Command3, Command::CommandSUB, Command::Command6, - Command::CommandEQU, Command::CommandMUL, Command::Command3, - Command::CommandEQU, Command::CommandNULL }; - TestDriver::Test(L"-9", L"", commands7); - - Command commands8[] = { Command::Command9, Command::CommandMUL, Command::Command6, - Command::CommandSUB, Command::CommandCENTR, Command::Command8, - Command::CommandEQU, Command::CommandNULL }; - TestDriver::Test(L"46", L"", commands8); - - Command commands9[] = { Command::Command6, Command::CommandMUL, Command::Command6, - Command::CommandPERCENT, Command::CommandEQU, Command::CommandNULL }; - TestDriver::Test(L"0.36", L"", commands9); - - Command commands10[] = { Command::Command5, Command::Command0, Command::CommandADD, - Command::Command2, Command::Command0, Command::CommandPERCENT, - Command::CommandEQU, Command::CommandNULL }; - TestDriver::Test(L"60", L"", commands10); - - Command commands11[] = { Command::Command4, Command::CommandADD, Command::CommandEQU, Command::CommandNULL }; - TestDriver::Test(L"8", L"", commands11); - - Command commands12[] = { Command::Command5, Command::CommandADD, Command::CommandMUL, - Command::Command3, Command::CommandNULL }; - TestDriver::Test(L"3", L"5 \x00D7 ", commands12); - - Command commands13[] = { Command::Command1, Command::CommandEXP, Command::CommandSIGN, - Command::Command9, Command::Command9, Command::Command9, - Command::Command9, Command::CommandDIV, Command::Command1, - Command::Command0, Command::CommandEQU, Command::CommandNULL }; - TestDriver::Test(L"Overflow", L"1.e-9999 \x00F7 ", commands13); - - Command commands14[] = { Command::Command5, Command::Command0, Command::CommandADD, - Command::Command2, Command::Command0, Command::CommandPERCENT, - Command::CommandEQU, Command::CommandNULL }; - TestDriver::Test(L"60", L"", commands14); - - Command commands15[] = { Command::Command0, Command::CommandDIV, Command::Command0, - Command::CommandEQU, Command::CommandNULL }; - TestDriver::Test(L"Result is undefined", L"0 \x00F7 ", commands15); - - Command commands16[] = { Command::Command1, Command::CommandDIV, Command::Command0, - Command::CommandEQU, Command::CommandNULL }; - TestDriver::Test(L"Cannot divide by zero", L"1 \x00F7 ", commands16); - - Command commands17[] = { Command::Command1, Command::Command2, Command::CommandADD, - Command::Command5, Command::CommandCENTR, Command::Command2, - Command::CommandADD, Command::CommandNULL }; - TestDriver::Test(L"14", L"12 + 2 + ", commands17); - - Command commands18[] = { Command::Command1, Command::Command0, Command::Command0, - Command::CommandSIGN, Command::CommandREC, Command::CommandNULL }; - TestDriver::Test(L"-0.01", L"1/(-100)", commands18); - - Command commands19[] = { Command::Command1, Command::Command2, Command::Command3, - Command::CommandBACK, Command::CommandBACK, Command::CommandNULL }; - TestDriver::Test(L"1", L"", commands19); - - Command commands20[] = { Command::Command1, Command::Command2, Command::Command3, - Command::CommandBACK, Command::CommandBACK, Command::CommandBACK, Command::CommandNULL }; - TestDriver::Test(L"0", L"", commands20); - - Command commands21[] = { Command::Command4, Command::CommandSQRT, Command::CommandSUB, - Command::Command2, Command::CommandADD, Command::CommandNULL }; - TestDriver::Test(L"0", L"\x221A(4) - 2 + ", commands21); - - Command commands22[] = { Command::Command1, Command::Command0, Command::Command2, Command::Command4, - Command::CommandSQRT, Command::CommandSUB, Command::Command3, Command::Command2, - Command::CommandADD, Command::CommandNULL }; - TestDriver::Test(L"0", L"\x221A(1024) - 32 + ", commands22); - } - - void CalculatorManagerTest::CalculatorManagerTestScientific() - { - Command commands1[] = { Command::Command1, Command::Command2, Command::Command3, - Command::CommandPNT, Command::Command4, Command::Command5, Command::Command6, Command::CommandNULL }; - TestDriver::Test(L"123.456", L"", commands1, true, true); - - Command commands2[] = { Command::CommandADD, Command::CommandNULL }; - TestDriver::Test(L"0", L"0 + ", commands2, true, true); - - Command commands3[] = { Command::CommandSQRT, Command::CommandNULL }; - TestDriver::Test(L"0", L"\x221A(0)", commands3, true, true); - - Command commands4[] = { Command::Command1, Command::CommandADD, Command::Command0, - Command::CommandMUL, Command::Command2, Command::CommandEQU, Command::CommandNULL }; - TestDriver::Test(L"1", L"", commands4, true, true); - - Command commands5[] = { Command::Command4, Command::CommandEQU, Command::CommandNULL }; - TestDriver::Test(L"4", L"", commands5, true, true); - - Command commands6[] = { Command::Command2, Command::Command5, Command::Command6, - Command::CommandSQRT, Command::CommandSQRT, Command::CommandSQRT, Command::CommandNULL }; - TestDriver::Test(L"2", L"\x221A(\x221A(\x221A(256)))", commands6, true, true); - - Command commands7[] = { Command::Command3, Command::CommandSUB, Command::Command6, - Command::CommandEQU, Command::CommandMUL, Command::Command3, \ - Command::CommandADD, Command::CommandNULL }; - TestDriver::Test(L"-9", L"-3 \x00D7 3 + ", commands7, true, true); - - Command commands8[] = { Command::Command9, Command::CommandMUL, Command::Command6, - Command::CommandSUB, Command::CommandCENTR, Command::Command8, - Command::CommandMUL, Command::Command2, Command::CommandADD, Command::CommandNULL }; - TestDriver::Test(L"38", L"9 \x00D7 6 - 8 \x00D7 2 + ", commands8, true, true); - - Command commands9[] = { Command::Command6, Command::CommandMUL, Command::Command6, - Command::CommandSIGN, Command::CommandSQRT, Command::CommandNULL }; - TestDriver::Test(L"Invalid input", L"6 \x00D7 \x221A(-6)", commands9, true, true); - - Command commands10[] = { Command::Command5, Command::Command0, Command::CommandADD, - Command::Command2, Command::Command0, Command::CommandREC, - Command::CommandSUB, Command::CommandNULL }; - TestDriver::Test(L"50.05", L"50 + 1/(20) - ", commands10, true, true); - - Command commands11[] = { Command::Command4, Command::CommandADD, Command::CommandEQU, Command::CommandNULL }; - TestDriver::Test(L"8", L"", commands11, true, true); - - Command commands12[] = { Command::Command5, Command::CommandADD, Command::CommandMUL, - Command::Command3, Command::CommandNULL }; - TestDriver::Test(L"3", L"5 \x00D7 ", commands12, true, true); - - Command commands13[] = { Command::Command1, Command::CommandEXP, Command::CommandSIGN, - Command::Command9, Command::Command9, Command::Command9, - Command::Command9, Command::CommandDIV, Command::Command1, - Command::Command0, Command::CommandEQU, Command::CommandNULL }; - TestDriver::Test(L"Overflow", L"1.e-9999 \x00F7 ", commands13, true, true); - - Command commands14[] = { Command::Command5, Command::Command0, Command::CommandADD, - Command::Command2, Command::Command0, Command::CommandPERCENT, - Command::CommandEQU, Command::CommandNULL }; - TestDriver::Test(L"60", L"", commands14, true, true); - - Command commands15[] = { Command::Command0, Command::CommandDIV, Command::Command0, - Command::CommandEQU, Command::CommandNULL }; - TestDriver::Test(L"Result is undefined", L"0 \x00F7 ", commands15, true, true); - - Command commands16[] = { Command::Command1, Command::CommandDIV, Command::Command0, - Command::CommandEQU, Command::CommandNULL }; - TestDriver::Test(L"Cannot divide by zero", L"1 \x00F7 ", commands16, true, true); - - Command commands17[] = { Command::Command1, Command::Command2, Command::CommandADD, - Command::Command5, Command::CommandCENTR, Command::Command2, - Command::CommandADD, Command::CommandNULL }; - TestDriver::Test(L"14", L"12 + 2 + ", commands17, true, true); - - Command commands18[] = { Command::Command1, Command::Command0, Command::Command0, - Command::CommandSIGN, Command::CommandREC, Command::CommandNULL }; - TestDriver::Test(L"-0.01", L"1/(-100)", commands18, true, true); - - Command commands19[] = { Command::Command1, Command::Command2, Command::Command3, - Command::CommandBACK, Command::CommandBACK, Command::CommandNULL }; - TestDriver::Test(L"1", L"", commands19, true, true); - - Command commands20[] = { Command::Command1, Command::Command2, Command::Command3, - Command::CommandBACK, Command::CommandBACK, Command::CommandBACK, Command::CommandNULL }; - TestDriver::Test(L"0", L"", commands20, true, true); - - Command commands21[] = { Command::Command4, Command::CommandSQRT, Command::CommandSUB, - Command::Command2, Command::CommandADD, Command::CommandNULL }; - TestDriver::Test(L"0", L"\x221A(4) - 2 + ", commands21); - - Command commands22[] = { Command::Command0, Command::CommandSQRT, Command::CommandNULL }; - TestDriver::Test(L"0", L"\x221A(0)", commands22); - - Command commands23[] = { Command::Command1, Command::Command0, Command::Command2, Command::Command4, - Command::CommandSQRT, Command::CommandSUB, Command::Command3, Command::Command2, - Command::CommandADD, Command::CommandNULL }; - TestDriver::Test(L"0", L"\x221A(1024) - 32 + ", commands23); - - Command commands24[] = { Command::Command2, Command::Command5, Command::Command7, - Command::CommandSQRT, Command::CommandSQRT, Command::CommandSQRT, Command::CommandNULL }; - TestDriver::Test(L"2.0009748976330773374220277351385", L"\x221A(\x221A(\x221A(257)))", commands24, true, true); - } - - // Scientific functions from the scientific calculator - void CalculatorManagerTest::CalculatorManagerTestScientific2() - { - Command commands1[] = { Command::Command1, Command::Command2, Command::CommandSQR, Command::CommandNULL }; - TestDriver::Test(L"144", L"sqr(12)", commands1, true, true); - - Command commands2[] = { Command::Command5, Command::CommandFAC, Command::CommandNULL }; - TestDriver::Test(L"120", L"fact(5)", commands2, true, true); - - Command commands3[] = { Command::Command5, Command::CommandPWR, Command::Command2, - Command::CommandADD, Command::CommandNULL }; - TestDriver::Test(L"25", L"5 ^ 2 + ", commands3, true, true); - - Command commands4[] = { Command::Command8, Command::CommandROOT, Command::Command3, - Command::CommandMUL, Command::CommandNULL }; - TestDriver::Test(L"2", L"8 yroot 3 \x00D7 ", commands4, true, true); - - Command commands5[] = { Command::Command8, Command::CommandCUB, Command::CommandNULL }; - TestDriver::Test(L"512", L"cube(8)", commands5, true, true); -/* - Command commands6[] = { Command::Command8, Command::CommandCUB, Command::CommandCUBEROOT, Command::CommandNULL }; - TestDriver::Test(L"8", L"cuberoot(cube(8))", commands6, true, true);*/ - - Command commands7[] = { Command::Command1, Command::Command0, Command::CommandLOG, Command::CommandNULL }; - TestDriver::Test(L"1", L"log(10)", commands7, true, true); - - Command commands8[] = { Command::Command5, Command::CommandPOW10, Command::CommandNULL }; - TestDriver::Test(L"100,000", L"10^(5)", commands8, true, true); - - Command commands9[] = { Command::Command1, Command::Command0, Command::CommandLN, Command::CommandNULL }; - TestDriver::Test(L"2.3025850929940456840179914546844", L"ln(10)", commands9, true, true); - - Command commands10[] = { Command::Command1, Command::CommandSIN, Command::CommandNULL }; - TestDriver::Test(L"0.01745240643728351281941897851632", L"sin\x2080(1)", commands10, true, true); - - Command commands11[] = { Command::Command1, Command::CommandCOS, Command::CommandNULL }; - TestDriver::Test(L"0.99984769515639123915701155881391", L"cos\x2080(1)", commands11, true, true); - - Command commands12[] = { Command::Command1, Command::CommandTAN, Command::CommandNULL }; - TestDriver::Test(L"0.01745506492821758576512889521973", L"tan\x2080(1)", commands12, true, true); - - Command commands13[] = { Command::Command1, Command::CommandASIN, Command::CommandNULL }; - TestDriver::Test(L"90", L"sin\x2080\x207B\x00B9(1)", commands13, true, true); - - Command commands14[] = { Command::Command1, Command::CommandACOS, Command::CommandNULL }; - TestDriver::Test(L"0", L"cos\x2080\x207B\x00B9(1)", commands14, true, true); - - Command commands15[] = { Command::Command1, Command::CommandATAN, Command::CommandNULL }; - TestDriver::Test(L"45", L"tan\x2080\x207B\x00B9(1)", commands15, true, true); - - Command commands16[] = { Command::Command2, Command::CommandPOWE, Command::CommandNULL }; - TestDriver::Test(L"7.389056098930650227230427460575", L"e^(2)", commands16, true, true); - - Command commands17[] = { Command::Command5, Command::CommandPWR, Command::Command0, - Command::CommandADD, Command::CommandNULL }; - TestDriver::Test(L"1", L"5 ^ 0 + ", commands17); - - Command commands18[] = { Command::Command0, Command::CommandPWR, Command::Command0, - Command::CommandADD, Command::CommandNULL }; - TestDriver::Test(L"1", L"0 ^ 0 + ", commands18); - - Command commands19[] = { Command::Command2, Command::Command7, Command::CommandSIGN, Command::CommandROOT, - Command::Command3, Command::CommandADD, Command::CommandNULL }; - TestDriver::Test(L"-3", L"-27 yroot 3 + ", commands19, true, true); - - Command commands20[] = { Command::Command8, Command::CommandPWR, Command::CommandOPENP, - Command::Command2, Command::CommandDIV, Command::Command3, Command::CommandCLOSEP, - Command::CommandSUB, Command::Command4, Command::CommandADD, Command::CommandNULL }; - TestDriver::Test(L"0", L"8 ^ (2 \x00F7 3) - 4 + ", commands20, true, true); - - Command commands21[] = { Command::Command4, Command::CommandPWR, Command::CommandOPENP, - Command::Command3, Command::CommandDIV, Command::Command2, Command::CommandCLOSEP, - Command::CommandSUB, Command::Command8, Command::CommandADD, Command::CommandNULL }; - TestDriver::Test(L"0", L"4 ^ (3 \x00F7 2) - 8 + ", commands21, true, true); - - Command commands22[] = { Command::Command1, Command::Command0, Command::CommandPWR, Command::Command1, - Command::CommandPNT, Command::Command2, Command::Command3, Command::Command4, Command::Command5, - Command::Command6, Command::CommandADD, Command::CommandNULL }; - TestDriver::Test(L"17.161687912241792074207286679393", L"10 ^ 1.23456 + ", commands22, true, true); - } - - void CalculatorManagerTest::CalculatorManagerTestScientificParenthesis() - { - Command commands1[] = { Command::Command1, Command::CommandADD, Command::CommandOPENP, - Command::CommandADD, Command::Command3, Command::CommandCLOSEP, Command::CommandNULL }; - TestDriver::Test(L"3", L"1 + (0 + 3)", commands1, true, true); - - Command commands2[] = { Command::CommandOPENP, Command::CommandOPENP, Command::Command1, - Command::Command2, Command::CommandCLOSEP, Command::CommandNULL }; - TestDriver::Test(L"12", L"((12)", commands2, true, true); - - Command commands3[] = { Command::Command1, Command::Command2, Command::CommandCLOSEP, - Command::CommandCLOSEP, Command::CommandOPENP, Command::CommandNULL }; - TestDriver::Test(L"12", L"(", commands3, true, true); - - Command commands4[] = { Command::Command2, Command::CommandOPENP, Command::Command2, - Command::CommandCLOSEP, Command::CommandADD, Command::CommandNULL }; - TestDriver::Test(L"2", L"(2) + ", commands4, true, true); - - Command commands5[] = { Command::Command2, Command::CommandOPENP, Command::Command2, - Command::CommandCLOSEP, Command::CommandADD, Command::CommandEQU, Command::CommandNULL }; - TestDriver::Test(L"4", L"", commands5, true, true); - } - - void CalculatorManagerTest::CalculatorManagerTestScientificError() - { - Command commands1[] = { Command::Command1, Command::CommandDIV, Command::Command0, - Command::CommandEQU, Command::CommandNULL }; - TestDriver::Test(L"Cannot divide by zero", L"1 \x00F7 ", commands1, true, true); - VERIFY_IS_TRUE(m_calculatorDisplayTester->GetIsError()); - - Command commands2[] = { Command::Command2, Command::CommandSIGN, Command::CommandLOG, Command::CommandNULL }; - TestDriver::Test(L"Invalid input", L"log(-2)", commands2, true, true); - VERIFY_IS_TRUE(m_calculatorDisplayTester->GetIsError()); - - Command commands3[] = { Command::Command0, Command::CommandDIV, Command::Command0, - Command::CommandEQU, Command::CommandNULL }; - TestDriver::Test(L"Result is undefined", L"0 \x00F7 ", commands3, true, true); - VERIFY_IS_TRUE(m_calculatorDisplayTester->GetIsError()); - - // Do the same tests for the basic calculator - TestDriver::Test(L"Cannot divide by zero", L"1 \x00F7 ", commands1); - VERIFY_IS_TRUE(m_calculatorDisplayTester->GetIsError()); - TestDriver::Test(L"Invalid input", L"log(-2)", commands2); - VERIFY_IS_TRUE(m_calculatorDisplayTester->GetIsError()); - TestDriver::Test(L"Result is undefined", L"0 \x00F7 ", commands3); - VERIFY_IS_TRUE(m_calculatorDisplayTester->GetIsError()); - } - - // Radians and Grads Test - void CalculatorManagerTest::CalculatorManagerTestScientificModeChange() - { - Command commands1[] = { Command::CommandRAD, Command::CommandPI, Command::CommandSIN, Command::CommandNULL }; - TestDriver::Test(L"0", L"N/A", commands1, true, true); - - Command commands2[] = { Command::CommandRAD, Command::CommandPI, Command::CommandCOS, Command::CommandNULL }; - TestDriver::Test(L"-1", L"N/A", commands2, true, true); - - Command commands3[] = { Command::CommandRAD, Command::CommandPI, Command::CommandTAN, Command::CommandNULL }; - TestDriver::Test(L"0", L"N/A", commands3, true, true); - - Command commands4[] = { Command::CommandGRAD, Command::Command4, Command::Command0, Command::Command0, - Command::CommandSIN, Command::CommandNULL }; - TestDriver::Test(L"0", L"N/A", commands4, true, true); - - Command commands5[] = { Command::CommandGRAD, Command::Command4, Command::Command0, Command::Command0, - Command::CommandCOS, Command::CommandNULL }; - TestDriver::Test(L"1", L"N/A", commands5, true, true); - - Command commands6[] = { Command::CommandGRAD, Command::Command4, Command::Command0, Command::Command0, - Command::CommandTAN, Command::CommandNULL }; - TestDriver::Test(L"0", L"N/A", commands6, true, true); - } - - void CalculatorManagerTest::CalculatorManagerTestModeChange() - { - Command commands1[] = { Command::Command1, Command::Command2, Command::Command3, Command::CommandNULL }; - TestDriver::Test(L"123", L"", commands1, true, false); - - Command commands2[] = { Command::ModeScientific, Command::CommandNULL }; - TestDriver::Test(L"0", L"", commands2, true, false); - - Command commands3[] = { Command::Command1, Command::Command2, Command::Command3, Command::CommandNULL }; - TestDriver::Test(L"123", L"", commands3, true, false); - - Command commands4[] = { Command::ModeProgrammer, Command::CommandNULL }; - TestDriver::Test(L"0", L"", commands4, true, false); - - Command commands5[] = { Command::Command1, Command::Command2, Command::Command3, Command::CommandNULL }; - TestDriver::Test(L"123", L"", commands5, true, false); - - Command commands6[] = { Command::ModeScientific, Command::CommandNULL }; - TestDriver::Test(L"0", L"", commands6, true, false); - - Command commands7[] = { Command::Command6, Command::Command7, Command::CommandADD, Command::CommandNULL }; - TestDriver::Test(L"67", L"67 + ", commands7, true, false); - - Command commands8[] = { Command::ModeBasic, Command::CommandNULL }; - TestDriver::Test(L"0", L"", commands8, true, false); - } - - void CalculatorManagerTest::CalculatorManagerTestMemory() - { - Command scientificCalculatorTest52[] = { Command::Command1, Command::CommandSTORE, Command::CommandNULL }; - wstring expectedPrimaryDisplayTestScientific52(L"1"); - wstring expectedExpressionDisplayTestScientific52(L""); - - Command scientificCalculatorTest53[] = { Command::Command1, Command::CommandNULL }; - wstring expectedPrimaryDisplayTestScientific53(L"1"); - wstring expectedExpressionDisplayTestScientific53(L""); - - CalculatorManagerDisplayTester* pCalculatorDisplay = (CalculatorManagerDisplayTester *)m_calculatorDisplayTester.get(); - wstring resultPrimary = L""; - wstring resultExpression = L""; - - Cleanup(); - ExecuteCommands(scientificCalculatorTest52); - resultPrimary = pCalculatorDisplay->GetPrimaryDisplay(); - resultExpression = pCalculatorDisplay->GetExpression(); - VERIFY_ARE_EQUAL(expectedPrimaryDisplayTestScientific52, resultPrimary); - - Cleanup(); - ExecuteCommands(scientificCalculatorTest53); - m_calculatorManager->MemorizeNumber(); - m_calculatorManager->SendCommand(Command::CommandCLEAR); - m_calculatorManager->MemorizedNumberLoad(0); - resultPrimary = pCalculatorDisplay->GetPrimaryDisplay(); - resultExpression = pCalculatorDisplay->GetExpression(); - VERIFY_ARE_EQUAL(expectedPrimaryDisplayTestScientific52, resultPrimary); - - Cleanup(); - m_calculatorManager->SendCommand(Command::Command1); - m_calculatorManager->MemorizeNumber(); - m_calculatorManager->SendCommand(Command::CommandCLEAR); - m_calculatorManager->SendCommand(Command::Command2); - m_calculatorManager->MemorizeNumber(); - m_calculatorManager->SendCommand(Command::CommandCLEAR); - m_calculatorManager->MemorizedNumberLoad(1); - resultPrimary = pCalculatorDisplay->GetPrimaryDisplay(); - VERIFY_ARE_EQUAL(wstring(L"1"), resultPrimary); - - m_calculatorManager->MemorizedNumberLoad(0); - resultPrimary = pCalculatorDisplay->GetPrimaryDisplay(); - VERIFY_ARE_EQUAL(wstring(L"2"), resultPrimary); - - Cleanup(); - m_calculatorManager->SendCommand(Command::Command1); - m_calculatorManager->SendCommand(Command::CommandSIGN); - m_calculatorManager->MemorizeNumber(); - m_calculatorManager->SendCommand(Command::CommandADD); - m_calculatorManager->SendCommand(Command::Command2); - m_calculatorManager->SendCommand(Command::CommandEQU); - m_calculatorManager->MemorizeNumber(); - m_calculatorManager->SendCommand(Command::CommandMUL); - m_calculatorManager->SendCommand(Command::Command2); - m_calculatorManager->MemorizeNumber(); - - vector memorizedNumbers = pCalculatorDisplay->GetMemorizedNumbers(); - - vector expectedMemorizedNumbers; - expectedMemorizedNumbers.push_back(L"2"); - expectedMemorizedNumbers.push_back(L"1"); - expectedMemorizedNumbers.push_back(L"-1"); - - - bool isEqual = false; - if (memorizedNumbers.size() < expectedMemorizedNumbers.size()) - { - isEqual = std::equal(memorizedNumbers.begin(), memorizedNumbers.end(), expectedMemorizedNumbers.begin()); - } - else - { - isEqual = std::equal(expectedMemorizedNumbers.begin(), expectedMemorizedNumbers.end(), memorizedNumbers.begin()); - } - VERIFY_IS_TRUE(isEqual); - - m_calculatorManager->SendCommand(Command::CommandCLEAR); - m_calculatorManager->SendCommand(Command::Command2); - m_calculatorManager->MemorizedNumberAdd(0); - m_calculatorManager->MemorizedNumberAdd(1); - m_calculatorManager->MemorizedNumberAdd(2); - - memorizedNumbers = pCalculatorDisplay->GetMemorizedNumbers(); - - expectedMemorizedNumbers.clear(); - expectedMemorizedNumbers.push_back(L"4"); - expectedMemorizedNumbers.push_back(L"3"); - expectedMemorizedNumbers.push_back(L"1"); - - if (memorizedNumbers.size() < expectedMemorizedNumbers.size()) - { - isEqual = std::equal(memorizedNumbers.begin(), memorizedNumbers.end(), expectedMemorizedNumbers.begin()); - } - else - { - isEqual = std::equal(expectedMemorizedNumbers.begin(), expectedMemorizedNumbers.end(), memorizedNumbers.begin()); - } - VERIFY_IS_TRUE(isEqual); - - m_calculatorManager->SendCommand(Command::CommandCLEAR); - m_calculatorManager->SendCommand(Command::Command1); - m_calculatorManager->SendCommand(Command::CommandPNT); - m_calculatorManager->SendCommand(Command::Command5); - - m_calculatorManager->MemorizedNumberSubtract(0); - m_calculatorManager->MemorizedNumberSubtract(1); - m_calculatorManager->MemorizedNumberSubtract(2); - - memorizedNumbers = pCalculatorDisplay->GetMemorizedNumbers(); - - expectedMemorizedNumbers.clear(); - expectedMemorizedNumbers.push_back(L"2.5"); - expectedMemorizedNumbers.push_back(L"1.5"); - expectedMemorizedNumbers.push_back(L"-0.5"); - - if (memorizedNumbers.size() < expectedMemorizedNumbers.size()) - { - isEqual = std::equal(memorizedNumbers.begin(), memorizedNumbers.end(), expectedMemorizedNumbers.begin()); - } - else - { - isEqual = std::equal(expectedMemorizedNumbers.begin(), expectedMemorizedNumbers.end(), memorizedNumbers.begin()); - } - VERIFY_IS_TRUE(isEqual); - - // Memorizing 101 numbers, which exceeds the limit. - Cleanup(); - for (int i = 0; i < 101; i++) - { - m_calculatorManager->SendCommand(Command::Command1); - m_calculatorManager->MemorizeNumber(); - } - - memorizedNumbers = pCalculatorDisplay->GetMemorizedNumbers(); - VERIFY_ARE_EQUAL((size_t)100, memorizedNumbers.size()); - - // Memorizing new number, which should show up at the top of the memory - m_calculatorManager->SendCommand(Command::Command2); - m_calculatorManager->MemorizeNumber(); - memorizedNumbers = pCalculatorDisplay->GetMemorizedNumbers(); - VERIFY_ARE_EQUAL(wstring(L"2"), memorizedNumbers.at(0)); - - // Test for trying to memorize invalid value - m_calculatorManager->SendCommand(Command::Command2); - m_calculatorManager->SendCommand(Command::CommandSIGN); - m_calculatorManager->SendCommand(Command::CommandSQRT); - m_calculatorManager->MemorizeNumber(); - } - - void CalculatorManagerTest::CalculatorManagerTestSerializeMemory() - { - Cleanup(); - - Command commands[] = { Command::Command1, Command::CommandNULL }; - ExecuteCommands(commands); - - for (int i = 0; i < 110; i++) - { - m_calculatorManager->MemorizeNumber(); - } - - VerifyPersistence(); - } - - void CalculatorManagerTest::CalculatorManagerTestSerializeDegreeMode() - { - Cleanup(); - - Command commands[] = { Command::Command1, Command::CommandRAD, Command::CommandSIN, Command::CommandADD, - Command::Command1, Command::CommandGRAD, Command::CommandCOS, Command::CommandADD, - Command::Command1, Command::CommandDEG, Command::CommandTAN, Command::CommandADD, - Command::CommandNULL }; - ExecuteCommands(commands); - - VerifyPersistence(); - } - - // 1 + 2 then serialize and deserialze 3 times - // Check if the values are persisted correctly - void CalculatorManagerTest::CalculatorManagerTestSerializeMultiple() - { - Cleanup(); - - Command commands[] = { Command::Command1, Command::CommandADD, Command::Command2, Command::CommandNULL }; - ExecuteCommands(commands); - - VerifyPersistence(); - VerifyPersistence(); - VerifyPersistence(); - } - - // Calculate 1/3 then serialize and deserialize - // Multiply by 3 and check if the result is 1 not 0.999999999999999999... - void CalculatorManagerTest::CalculatorManagerTestSerializePrecision() - { - CalculatorManagerDisplayTester* pCalculatorDisplay = (CalculatorManagerDisplayTester *)m_calculatorDisplayTester.get(); - wstring resultPrimary = L""; - wstring resultExpression = L""; - Cleanup(); - - Command commands[] = { Command::Command1, Command::CommandDIV, Command::Command3, Command::CommandEQU, Command::CommandNULL }; - ExecuteCommands(commands); - - SerialzieAndDeSerialize(); - - Command commands2[] = { Command::CommandMUL, Command::Command3, Command::CommandEQU, Command::CommandNULL }; - ExecuteCommands(commands2); - - VERIFY_ARE_EQUAL(StringReference(L"1"), ref new String(pCalculatorDisplay->GetPrimaryDisplay().c_str())); - } - - void CalculatorManagerTest::CalculatorManagerTestSerialize() - { - CalculatorManagerDisplayTester* pCalculatorDisplay = (CalculatorManagerDisplayTester *)m_calculatorDisplayTester.get(); - wstring resultPrimary = L""; - wstring resultExpression = L""; - Cleanup(); - - m_calculatorManager->SendCommand(Command::ModeScientific); - m_calculatorManager->SendCommand(Command::Command1); - m_calculatorManager->SendCommand(Command::CommandADD); - m_calculatorManager->SendCommand(Command::Command2); - m_calculatorManager->SendCommand(Command::CommandMUL); - m_calculatorManager->SendCommand(Command::Command2); - m_calculatorManager->MemorizeNumber(); - m_calculatorManager->SendCommand(Command::CommandEQU); - m_calculatorManager->MemorizeNumber(); - - vector memorizedNumbers = pCalculatorDisplay->GetMemorizedNumbers(); - wstring primaryDisplay = pCalculatorDisplay->GetPrimaryDisplay(); - wstring expressionDisplay = pCalculatorDisplay->GetExpression(); - - SerialzieAndDeSerialize(); - - vector memorizedNumbersAfterDeSerialize = pCalculatorDisplay->GetMemorizedNumbers(); - wstring primaryDisplayAfterDeSerialize = pCalculatorDisplay->GetPrimaryDisplay(); - wstring expressionDisplayAfterDeSerialize = pCalculatorDisplay->GetExpression(); - - VERIFY_ARE_EQUAL(primaryDisplay, primaryDisplayAfterDeSerialize); - VERIFY_ARE_EQUAL(expressionDisplay, expressionDisplayAfterDeSerialize); - - bool isEqual = false; - - if (memorizedNumbers.size() < memorizedNumbersAfterDeSerialize.size()) - { - isEqual = std::equal(memorizedNumbers.begin(), memorizedNumbers.end(), memorizedNumbersAfterDeSerialize.begin()); - } - else - { - isEqual = std::equal(memorizedNumbersAfterDeSerialize.begin(), memorizedNumbersAfterDeSerialize.end(), memorizedNumbers.begin()); - } - VERIFY_IS_TRUE(isEqual); - - m_calculatorManager->SendCommand(Command::CommandGRAD); - m_calculatorManager->SendCommand(Command::Command5); - m_calculatorManager->SendCommand(Command::Command0); - m_calculatorManager->SendCommand(Command::CommandSIGN); - m_calculatorManager->SendCommand(Command::CommandMUL); - - memorizedNumbers = pCalculatorDisplay->GetMemorizedNumbers(); - primaryDisplay = pCalculatorDisplay->GetPrimaryDisplay(); - expressionDisplay = pCalculatorDisplay->GetExpression(); - - SerialzieAndDeSerialize(); - - memorizedNumbersAfterDeSerialize = pCalculatorDisplay->GetMemorizedNumbers(); - primaryDisplayAfterDeSerialize = pCalculatorDisplay->GetPrimaryDisplay(); - expressionDisplayAfterDeSerialize = pCalculatorDisplay->GetExpression(); - - VERIFY_ARE_EQUAL(primaryDisplay, primaryDisplayAfterDeSerialize); - VERIFY_ARE_EQUAL(expressionDisplay, expressionDisplayAfterDeSerialize); - - isEqual = false; - if (memorizedNumbers.size() < memorizedNumbersAfterDeSerialize.size()) - { - isEqual = std::equal(memorizedNumbers.begin(), memorizedNumbers.end(), memorizedNumbersAfterDeSerialize.begin()); - } - else - { - isEqual = std::equal(memorizedNumbersAfterDeSerialize.begin(), memorizedNumbersAfterDeSerialize.end(), memorizedNumbers.begin()); - } - VERIFY_IS_TRUE(isEqual); - - m_calculatorManager->SendCommand(Command::Command1); - m_calculatorManager->SendCommand(Command::Command2); - m_calculatorManager->SendCommand(Command::Command3); - m_calculatorManager->SendCommand(Command::CommandPNT); - m_calculatorManager->SendCommand(Command::Command8); - m_calculatorManager->SendCommand(Command::CommandSIGN); - m_calculatorManager->MemorizeNumber(); - m_calculatorManager->SendCommand(Command::Command2); - m_calculatorManager->SendCommand(Command::Command3); - m_calculatorManager->MemorizedNumberAdd(0); - m_calculatorManager->SendCommand(Command::CommandCENTR); - m_calculatorManager->SendCommand(Command::Command3); - m_calculatorManager->SendCommand(Command::Command1); - m_calculatorManager->SendCommand(Command::CommandSIN); - m_calculatorManager->MemorizedNumberSubtract(2); - m_calculatorManager->MemorizedNumberLoad(2); - - memorizedNumbers = pCalculatorDisplay->GetMemorizedNumbers(); - primaryDisplay = pCalculatorDisplay->GetPrimaryDisplay(); - expressionDisplay = pCalculatorDisplay->GetExpression(); - - SerialzieAndDeSerialize(); - - memorizedNumbersAfterDeSerialize = pCalculatorDisplay->GetMemorizedNumbers(); - primaryDisplayAfterDeSerialize = pCalculatorDisplay->GetPrimaryDisplay(); - expressionDisplayAfterDeSerialize = pCalculatorDisplay->GetExpression(); - - VERIFY_ARE_EQUAL(primaryDisplay, primaryDisplayAfterDeSerialize); - VERIFY_ARE_EQUAL(expressionDisplay, expressionDisplayAfterDeSerialize); - - isEqual = false; - if (memorizedNumbers.size() < memorizedNumbersAfterDeSerialize.size()) - { - isEqual = std::equal(memorizedNumbers.begin(), memorizedNumbers.end(), memorizedNumbersAfterDeSerialize.begin()); - } - else - { - isEqual = std::equal(memorizedNumbersAfterDeSerialize.begin(), memorizedNumbersAfterDeSerialize.end(), memorizedNumbers.begin()); - } - VERIFY_IS_TRUE(isEqual); - } - - // Send 12345678910111213 and verify MaxDigitsReached - void CalculatorManagerTest::CalculatorManagerTestMaxDigitsReached() - { - TestMaxDigitsReachedScenario(L"1,234,567,891,011,1213"); - } - - void CalculatorManagerTest::CalculatorManagerTestMaxDigitsReached_LeadingDecimal() - { - TestMaxDigitsReachedScenario(L"0.12345678910111213"); - } - - void CalculatorManagerTest::CalculatorManagerTestMaxDigitsReached_TrailingDecimal() - { - TestMaxDigitsReachedScenario(L"123,456,789,101,112.13"); - } - - void CalculatorManagerTest::CalculatorManagerTestBinaryOperatorReceived() - { - CalculatorManagerDisplayTester* pCalculatorDisplay = (CalculatorManagerDisplayTester *)m_calculatorDisplayTester.get(); - - VERIFY_ARE_EQUAL(0, pCalculatorDisplay->GetBinaryOperatorReceivedCallCount()); - - ExecuteCommands({ - Command::Command1, - Command::CommandADD - }); - - wstring display = pCalculatorDisplay->GetPrimaryDisplay(); - VERIFY_ARE_EQUAL(wstring(L"1"), display); - - // Verify BinaryOperatorReceived - VERIFY_ARE_EQUAL(1, pCalculatorDisplay->GetBinaryOperatorReceivedCallCount()); - } - - void CalculatorManagerTest::CalculatorManagerTestBinaryOperatorReceived_Multiple() - { - CalculatorManagerDisplayTester* pCalculatorDisplay = (CalculatorManagerDisplayTester *)m_calculatorDisplayTester.get(); - - VERIFY_ARE_EQUAL(0, pCalculatorDisplay->GetBinaryOperatorReceivedCallCount()); - - ExecuteCommands({ - Command::Command1, - Command::CommandADD, - Command::CommandSUB, - Command::CommandMUL - }); - - wstring display = pCalculatorDisplay->GetPrimaryDisplay(); - VERIFY_ARE_EQUAL(wstring(L"1"), display); - - // Verify BinaryOperatorReceived - VERIFY_ARE_EQUAL(3, pCalculatorDisplay->GetBinaryOperatorReceivedCallCount()); - } - - void CalculatorManagerTest::CalculatorManagerTestBinaryOperatorReceived_LongInput() - { - CalculatorManagerDisplayTester* pCalculatorDisplay = (CalculatorManagerDisplayTester *)m_calculatorDisplayTester.get(); - - VERIFY_ARE_EQUAL(0, pCalculatorDisplay->GetBinaryOperatorReceivedCallCount()); - - ExecuteCommands({ - Command::Command1, - Command::CommandADD, - Command::Command2, - Command::CommandMUL, - Command::Command1, - Command::Command0, - Command::CommandSUB, - Command::Command5, - Command::CommandDIV, - Command::Command5, - Command::CommandEQU - }); - - wstring display = pCalculatorDisplay->GetPrimaryDisplay(); - VERIFY_ARE_EQUAL(wstring(L"5"), display); - - // Verify BinaryOperatorReceived - VERIFY_ARE_EQUAL(4, pCalculatorDisplay->GetBinaryOperatorReceivedCallCount()); - } - -} /* namespace CalculationManagerUnitTests */ - diff --git a/internal/CalculatorUnitTests/CalculatorUnitTests.vcxproj b/internal/CalculatorUnitTests/CalculatorUnitTests.vcxproj deleted file mode 100644 index e92bdfa..0000000 --- a/internal/CalculatorUnitTests/CalculatorUnitTests.vcxproj +++ /dev/null @@ -1,365 +0,0 @@ - - - - - - - {E527A1F4-6B63-4DD0-B540-B8C06CFC3AFE} - CalculatorUnitTests - en-US - 15.0 - true - Windows Store - 10.0.17763.0 - 10.0.17134.0 - 10.0 - CalculatorUnitTests - - true - true - - true - - - - - x64 - - - true - true - false - - - true - true - false - - - true - false - - - true - false - - - true - true - false - - - true - false - - - true - true - false - - - true - false - - - - Debug - ARM - - - Debug - ARM64 - - - Debug - Win32 - - - Debug - x64 - - - Release - ARM - - - Release - ARM64 - - - Release - Win32 - - - Release - x64 - - - - Application - true - v141 - - - Application - true - v141 - - - Application - true - v141 - - - Application - true - v141 - - - Application - false - true - v141 - - - Application - false - true - v141 - - - Application - false - true - v141 - - - Application - false - true - v141 - - - - - - - - - - - - - - - - - - - - - - - - - - - - TemporaryKey.pfx - - - - /bigobj /await /std:c++17 /permissive- /Zc:twoPhase- %(AdditionalOptions) - 4453;28204 - $(SolutionDir)..\src\;$(SolutionDir)..\src\CalcManager;$(SolutionDir)..\src\CalcViewModel;%(AdditionalIncludeDirectories) - - - %(AdditionalLibraryDirectories) - - - - - /bigobj /await /std:c++17 /permissive- /Zc:twoPhase- %(AdditionalOptions) - 4453;28204 - $(SolutionDir)..\src\;$(SolutionDir)..\src\CalcManager;$(SolutionDir)..\src\CalcViewModel;%(AdditionalIncludeDirectories) - - - %(AdditionalLibraryDirectories) - - - - - /bigobj /await /std:c++17 /permissive- /Zc:twoPhase- %(AdditionalOptions) - 4453;28204 - $(SolutionDir)..\src\;$(SolutionDir)..\src\CalcManager;$(SolutionDir)..\src\CalcViewModel;%(AdditionalIncludeDirectories) - - - %(AdditionalLibraryDirectories) - - - - - /bigobj /await /std:c++17 /permissive- /Zc:twoPhase- %(AdditionalOptions) - 4453;28204 - $(SolutionDir)..\src\;$(SolutionDir)..\src\CalcManager;$(SolutionDir)..\src\CalcViewModel;%(AdditionalIncludeDirectories) - - - %(AdditionalLibraryDirectories) - - - - - /bigobj /await /std:c++17 /permissive- /Zc:twoPhase- %(AdditionalOptions) - 4453;28204 - $(SolutionDir)..\src\;$(SolutionDir)..\src\CalcManager;$(SolutionDir)..\src\CalcViewModel;%(AdditionalIncludeDirectories) - - - %(AdditionalLibraryDirectories) - - - - - /bigobj /await /std:c++17 /permissive- /Zc:twoPhase- %(AdditionalOptions) - 4453;28204 - $(SolutionDir)..\src\;$(SolutionDir)..\src\CalcManager;$(SolutionDir)..\src\CalcViewModel;%(AdditionalIncludeDirectories) - - - %(AdditionalLibraryDirectories) - - - - - /bigobj /await /std:c++17 /permissive- /Zc:twoPhase- %(AdditionalOptions) - 4453;28204 - $(SolutionDir)..\src\;$(SolutionDir)..\src\CalcManager;$(SolutionDir)..\src\CalcViewModel;%(AdditionalIncludeDirectories) - - - %(AdditionalLibraryDirectories) - - - - - /bigobj /await /std:c++17 /permissive- /Zc:twoPhase- %(AdditionalOptions) - 4453;28204 - $(SolutionDir)..\src\;$(SolutionDir)..\src\CalcManager;$(SolutionDir)..\src\CalcViewModel;%(AdditionalIncludeDirectories) - - - %(AdditionalLibraryDirectories) - - - - - - - - - - - - - - - - - - - - - - UnitTestApp.xaml - - - - - Designer - - - - - Designer - - - - - - - - - - - - - - - - - - - - - UnitTestApp.xaml - - - Create - Create - Create - Create - Create - Create - Create - Create - - - - - - - - - - - - - - - - - - {311e866d-8b93-4609-a691-265941fee101} - - - {90e9761d-9262-4773-942d-caeae75d7140} - - - - - - - $(UniversalTestCustomMacros)AppxPackageVCLibsDependency=$(AppxPackageTestDir)Dependencies\x86\Microsoft.VCLibs.x86.Debug.14.00.appx; - $(UniversalTestCustomMacros)AppxPackageVCLibsDependency=$(AppxPackageTestDir)Dependencies\x86\Microsoft.VCLibs.x86.14.00.appx; - $(UniversalTestCustomMacros)AppxPackageVCLibsDependency=$(AppxPackageTestDir)Dependencies\x64\Microsoft.VCLibs.x64.Debug.14.00.appx; - $(UniversalTestCustomMacros)AppxPackageVCLibsDependency=$(AppxPackageTestDir)Dependencies\x64\Microsoft.VCLibs.x64.14.00.appx; - $(UniversalTestCustomMacros)AppxPackageVCLibsDependency=$(AppxPackageTestDir)Dependencies\ARM\Microsoft.VCLibs.arm.Debug.14.00.appx; - $(UniversalTestCustomMacros)AppxPackageVCLibsDependency=$(AppxPackageTestDir)Dependencies\ARM64\Microsoft.VCLibs.arm64.Debug.14.00.appx; - $(UniversalTestCustomMacros)AppxPackageVCLibsDependency=$(AppxPackageTestDir)Dependencies\ARM\Microsoft.VCLibs.arm.14.00.appx; - $(UniversalTestCustomMacros)AppxPackageVCLibsDependency=$(AppxPackageTestDir)Dependencies\ARM64\Microsoft.VCLibs.arm64.14.00.appx; - $(UniversalTestCustomMacros)AppxPackagePublicKeyFile=$(AppxPackagePublicKeyFile);AppxPackageOutput=$(AppxPackageOutput); - - - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - - - - - - \ No newline at end of file diff --git a/internal/CalculatorUnitTests/CalculatorUnitTests.vcxproj.filters b/internal/CalculatorUnitTests/CalculatorUnitTests.vcxproj.filters deleted file mode 100644 index ac251d6..0000000 --- a/internal/CalculatorUnitTests/CalculatorUnitTests.vcxproj.filters +++ /dev/null @@ -1,102 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/internal/CalculatorUnitTests/CopyPasteManagerTest.cpp b/internal/CalculatorUnitTests/CopyPasteManagerTest.cpp deleted file mode 100644 index f4e9329..0000000 --- a/internal/CalculatorUnitTests/CopyPasteManagerTest.cpp +++ /dev/null @@ -1,602 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#include "pch.h" -#include - -#include "CalcViewModel\StandardCalculatorViewModel.h" -#include "CalcViewModel\Common\CopyPasteManager.h" - -using namespace CalculationManager; -using namespace CalculatorApp; -using namespace CalculatorApp::Common; -using namespace CalculatorApp::ViewModel; -using namespace Platform; -using namespace std; -using namespace WEX::Logging; -using namespace Windows::ApplicationModel::DataTransfer; -using namespace Windows::ApplicationModel::Resources; -using namespace Windows::Globalization; -using namespace Windows::Storage; - -namespace CalculatorUnitTests -{ - extern void ChangeMode(StandardCalculatorViewModel^ viewModel, int mode); - -#define ASSERT_POSITIVE_TESTCASES(func, dataSet) \ -{\ - int size = sizeof(dataSet)/sizeof(*dataSet);\ - while(--size)\ - {\ - VERIFY_ARE_EQUAL(func(dataSet[size]), dataSet[size]);\ - }\ -} - -#define ASSERT_NEGATIVE_TESTCASES(func, dataSet) \ -{\ - int size = sizeof(dataSet)/sizeof(*dataSet);;\ - while(--size)\ - {\ - VERIFY_ARE_EQUAL(func(dataSet[size]), StringReference(L"NoOp"));\ - }\ -} - -// returns a iterator from end -#define START_LOOP(dataSet)\ -{\ - int size = sizeof(dataSet)/sizeof(*dataSet);\ - while(--size)\ - { - -#define END_LOOP\ - }\ -} - - class CopyPasteManagerTest - { - public: - TEST_CLASS(CopyPasteManagerTest); - - TEST_METHOD(FunctionalCopyPasteTest); - TEST_METHOD(ValidateStandardPasteExpressionTest); - TEST_METHOD(ValidateScientificPasteExpressionTest); - TEST_METHOD(ValidateProgrammerDecPasteExpressionTest); - TEST_METHOD(ValidateProgrammerOctPasteExpressionTest); - TEST_METHOD(ValidateProgrammerHexPasteExpressionTest); - TEST_METHOD(ValidateProgrammerBinPasteExpressionTest); - TEST_METHOD(ValidateConverterPasteExpressionTest); - - TEST_METHOD(ValidatePasteExpressionErrorStates) - { - wstring exp_TooLong = L""; - for (int i = 0; i < m_CopyPasteManager.MaxPasteableLength / 8; i++) - { - exp_TooLong += L"-1234567"; - } - VERIFY_ARE_EQUAL(m_CopyPasteManager.ValidatePasteExpression(StringReference(exp_TooLong.c_str()), ViewMode::Standard, CategoryGroupType::Calculator, -1, -1), StringReference(exp_TooLong.c_str()), L"Verify ValidatePasteExpression handles expressions up to max length"); - exp_TooLong += L"1"; - VERIFY_ARE_EQUAL(m_CopyPasteManager.ValidatePasteExpression(StringReference(exp_TooLong.c_str()), ViewMode::Standard, CategoryGroupType::Calculator, -1, -1), 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, -1), StringReference(L"NoOp"), L"Verify empty string is invalid"); - - VERIFY_ARE_EQUAL(m_CopyPasteManager.ValidatePasteExpression(StringReference(L"123e456"), ViewMode::Standard, CategoryGroupType::Calculator, -1, -1), 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, -1), StringReference(L"NoOp"), L"Verify pasting without a ViewMode or Category is invalid"); - }; - - TEST_METHOD(ValidateExtractOperands) - { - vector results = {}; - - vector 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); - - vector 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); - - vector 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); - - vector twoOperandsParens = { L"((45)", L"(-30))" }; - VERIFY_ARE_EQUAL(m_CopyPasteManager.ExtractOperands(L"((45)+(-30))", ViewMode::Scientific), twoOperandsParens); - }; - - TEST_METHOD(ValidateExtractOperandsErrors) - { - wstring exp_OperandLimit = L""; - for (int i = 0; i < m_CopyPasteManager.MaxOperandCount; i++) - { - exp_OperandLimit += L"+1"; - } - VERIFY_ARE_EQUAL(m_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(), 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"); - VERIFY_ARE_EQUAL(m_CopyPasteManager.ExtractOperands(L"12e10000", ViewMode::Standard).size(), 0, L"Verify ExtractOperands returns empty vector when the exponent is too long"); - }; - - TEST_METHOD(ValidateExpressionRegExMatch) - { - VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(vector{}, ViewMode::Standard, CategoryGroupType::Calculator, -1, -1), L"Verify empty list of operands returns false."); - VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(vector{ L"123" }, ViewMode::None, CategoryGroupType::Calculator, -1, -1), L"Verify invalid ViewMode/CategoryGroups return false."); - VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(vector{ L"123" }, ViewMode::Currency, CategoryGroupType::None, -1, -1), L"Verify invalid ViewMode/CategoryGroups return false."); - - Log::Comment(L"Verify operand lengths > max return false."); - VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(vector{ L"12345678901234567" }, ViewMode::Standard, CategoryGroupType::Calculator, -1, -1)); - VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(vector{ L"123456789012345678901234567890123" }, ViewMode::Scientific, CategoryGroupType::Calculator, -1, -1)); - VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(vector{ L"12345678901234567" }, ViewMode::None, CategoryGroupType::Converter, -1, -1)); - VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(vector{ L"11111111111111111" }, ViewMode::Programmer, CategoryGroupType::Calculator, HexBase, QwordType)); - VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(vector{ L"12345678901234567890" }, ViewMode::Programmer, CategoryGroupType::Calculator, DecBase, QwordType)); - VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(vector{ L"11111111111111111111111" }, ViewMode::Programmer, CategoryGroupType::Calculator, OctBase, QwordType)); - VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(vector{ L"10000000000000000000000000000000000000000000000000000000000000000" }, ViewMode::Programmer, CategoryGroupType::Calculator, BinBase, QwordType)); - - VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(vector{ L"9223372036854775808" }, ViewMode::Programmer, CategoryGroupType::Calculator, DecBase, QwordType), L"Verify operand values > max return false."); - - VERIFY_IS_TRUE(m_CopyPasteManager.ExpressionRegExMatch(vector{ L"((((((((((((((((((((123))))))))))))))))))))" }, ViewMode::Scientific, CategoryGroupType::Calculator, -1, -1), L"Verify sanitized operand is detected as within max length."); - VERIFY_IS_TRUE(m_CopyPasteManager.ExpressionRegExMatch(vector{ L"9223372036854775807" }, ViewMode::Programmer, CategoryGroupType::Calculator, DecBase, QwordType), L"Verify operand values == max return true."); - - Log::Comment(L"Verify all operands must match patterns."); - VERIFY_IS_TRUE(m_CopyPasteManager.ExpressionRegExMatch(vector{ L"123", L"456" }, ViewMode::Standard, CategoryGroupType::Calculator, -1, -1)); - VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(vector{ L"123", L"1e23" }, ViewMode::Standard, CategoryGroupType::Calculator, -1, -1)); - - VERIFY_IS_TRUE(m_CopyPasteManager.ExpressionRegExMatch(vector{ L"1.23e+456" }, ViewMode::Scientific, CategoryGroupType::Calculator, -1, -1), L"Verify operand only needs to match one pattern."); - - VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(vector{ L"123", L"12345678901234567" }, ViewMode::Standard, CategoryGroupType::Calculator, -1, -1), L"Verify all operands must be within maxlength"); - VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(vector{ L"123", L"9223372036854775808" }, ViewMode::Programmer, CategoryGroupType::Calculator, DecBase, QwordType), L"Verify all operand must be within max value."); - }; - - TEST_METHOD(ValidateGetMaxOperandLengthAndValue) - { - pair standardModeMaximums = make_pair(m_CopyPasteManager.MaxStandardOperandLength, 0); - pair scientificModeMaximums = make_pair(m_CopyPasteManager.MaxScientificOperandLength, 0); - pair converterModeMaximums = make_pair(m_CopyPasteManager.MaxConverterInputLength, 0); - VERIFY_ARE_EQUAL(m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Standard, CategoryGroupType::None, -1, -1), standardModeMaximums, L"Verify Standard mode maximum values"); - VERIFY_ARE_EQUAL(m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Scientific, CategoryGroupType::None, -1, -1), scientificModeMaximums, L"Verify Scientific mode maximum values"); - VERIFY_ARE_EQUAL(m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::None, CategoryGroupType::Converter, -1, -1), converterModeMaximums, 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; - Log::Comment(L"Verify Programmer Mode HexBase maximum values"); - VERIFY_ARE_EQUAL(m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, HexBase, QwordType), make_pair((size_t)16u, ullQwordMax)); - VERIFY_ARE_EQUAL(m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, HexBase, DwordType), make_pair((size_t)8u, ullDwordMax)); - VERIFY_ARE_EQUAL(m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, HexBase, WordType), make_pair((size_t)4u, ullWordMax)); - VERIFY_ARE_EQUAL(m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, HexBase, ByteType), make_pair((size_t)2u, ullByteMax)); - - Log::Comment(L"Verify Programmer Mode DecBase maximum values"); - VERIFY_ARE_EQUAL(m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, DecBase, QwordType), make_pair((size_t)19u, ullQwordMax >> 1)); - VERIFY_ARE_EQUAL(m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, DecBase, DwordType), make_pair((size_t)10u, ullDwordMax >> 1)); - VERIFY_ARE_EQUAL(m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, DecBase, WordType), make_pair((size_t)5u, ullWordMax >> 1)); - VERIFY_ARE_EQUAL(m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, DecBase, ByteType), make_pair((size_t)3u, ullByteMax >> 1)); - - Log::Comment(L"Verify Programmer Mode OctBase maximum values"); - VERIFY_ARE_EQUAL(m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, OctBase, QwordType), make_pair((size_t)22u, ullQwordMax)); - VERIFY_ARE_EQUAL(m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, OctBase, DwordType), make_pair((size_t)11u, ullDwordMax)); - VERIFY_ARE_EQUAL(m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, OctBase, WordType), make_pair((size_t)6u, ullWordMax)); - VERIFY_ARE_EQUAL(m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, OctBase, ByteType), make_pair((size_t)3u, ullByteMax)); - - Log::Comment(L"Verify Programmer Mode BinBase maximum values"); - VERIFY_ARE_EQUAL(m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, BinBase, QwordType), make_pair((size_t)64u, ullQwordMax)); - VERIFY_ARE_EQUAL(m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, BinBase, DwordType), make_pair((size_t)32u, ullDwordMax)); - VERIFY_ARE_EQUAL(m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, BinBase, WordType), make_pair((size_t)16u, ullWordMax)); - VERIFY_ARE_EQUAL(m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::Programmer, CategoryGroupType::None, BinBase, ByteType), make_pair((size_t)8u, ullByteMax)); - - Log::Comment(L"Verify invalid ViewModes/Categories return 0 for max values"); - VERIFY_ARE_EQUAL(m_CopyPasteManager.GetMaxOperandLengthAndValue(ViewMode::None, CategoryGroupType::None, -1, -1), make_pair((size_t)0u, 0ull)); - }; - - 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"12-34"), 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"'''''1234''''"), 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"); - }; - - TEST_METHOD(ValidateTryOperandToULL) - { - unsigned long long int result = 0; - - Log::Comment(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); - - Log::Comment(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); - - Log::Comment(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); - - Log::Comment(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); - - Log::Comment(L"Verify TryOperandToULL invalid numberBase defaults to DecBase"); - VERIFY_IS_TRUE(m_CopyPasteManager.TryOperandToULL(L"1234", 128, result)); - VERIFY_ARE_EQUAL(result, 1234ull); - - Log::Comment(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)); - // 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)); - - }; - - TEST_METHOD(ValidateStandardScientificOperandLength) - { - 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"1.2"), 2); - 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"), 6); - - }; - - 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"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"", 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"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); - }; - - private: - CopyPasteManager m_CopyPasteManager; - String^ ValidateStandardPasteExpression(_In_ String^ pastedText) - { - return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Standard, -1/*number base*/, -1/*bitlength Type*/); - } - - String^ ValidateScientificPasteExpression(_In_ String^ pastedText) - { - return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Scientific, -1/*number base*/, -1/*bitlength Type*/); - } - - String^ ValidateConverterPasteExpression(_In_ String^ pastedText) - { - return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::None, CategoryGroupType::Converter, -1/*number base*/, -1/*bitlength Type*/); - } - - String^ ValidateProgrammerHexQwordPasteExpression(_In_ String^ pastedText) - { - return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, HexBase/*number base*/, QwordType/*bitlength Type*/); - } - - String^ ValidateProgrammerHexDwordPasteExpression(_In_ String^ pastedText) - { - return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, HexBase/*number base*/, DwordType/*bitlength Type*/); - } - - String^ ValidateProgrammerHexWordPasteExpression(_In_ String^ pastedText) - { - return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, HexBase/*number base*/, WordType/*bitlength Type*/); - } - - String^ ValidateProgrammerHexBytePasteExpression(_In_ String^ pastedText) - { - return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, HexBase/*number base*/, ByteType/*bitlength Type*/); - } - - String^ ValidateProgrammerDecQwordPasteExpression(_In_ String^ pastedText) - { - return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, DecBase/*number base*/, QwordType/*bitlength Type*/); - } - - String^ ValidateProgrammerDecDwordPasteExpression(_In_ String^ pastedText) - { - return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, DecBase/*number base*/, DwordType/*bitlength Type*/); - } - - String^ ValidateProgrammerDecWordPasteExpression(_In_ String^ pastedText) - { - return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, DecBase/*number base*/, WordType/*bitlength Type*/); - } - - String^ ValidateProgrammerDecBytePasteExpression(_In_ String^ pastedText) - { - return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, DecBase/*number base*/, ByteType/*bitlength Type*/); - } - - String^ ValidateProgrammerOctQwordPasteExpression(_In_ String^ pastedText) - { - return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, OctBase/*number base*/, QwordType/*bitlength Type*/); - } - - String^ ValidateProgrammerOctDwordPasteExpression(_In_ String^ pastedText) - { - return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, OctBase/*number base*/, DwordType/*bitlength Type*/); - } - - String^ ValidateProgrammerOctWordPasteExpression(_In_ String^ pastedText) - { - return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, OctBase/*number base*/, WordType/*bitlength Type*/); - } - - String^ ValidateProgrammerOctBytePasteExpression(_In_ String^ pastedText) - { - return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, OctBase/*number base*/, ByteType/*bitlength Type*/); - } - - String^ ValidateProgrammerBinQwordPasteExpression(_In_ String^ pastedText) - { - return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, BinBase/*number base*/, QwordType/*bitlength Type*/); - } - - String^ ValidateProgrammerBinDwordPasteExpression(_In_ String^ pastedText) - { - return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, BinBase/*number base*/, DwordType/*bitlength Type*/); - } - - String^ ValidateProgrammerBinWordPasteExpression(_In_ String^ pastedText) - { - return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, BinBase/*number base*/, WordType/*bitlength Type*/); - } - - String^ ValidateProgrammerBinBytePasteExpression(_In_ String^ pastedText) - { - return m_CopyPasteManager.ValidatePasteExpression(pastedText, ViewMode::Programmer, BinBase/*number base*/, ByteType/*bitlength Type*/); - } - - - }; - - /************************************* - standard: - can paste simple numbers / expressions not exponential numbers / expressions - - scientific : - can paste exponential numbers / expressions too - - programmer : - can paste specific numbers / expressions based on radixes.Hex numbers such 13abe is allowed when radix is set to hex, but not allowed otherwise. - - converter : - can paste simple numbers not expressions - - List of test cases: - 1. simple unsigned number - 2. negative number - 3. exponential number with positive exp - 4. exponential number with negative exp - 5. exponential number with unsigned exp - 6. exponential number with very large(larger than 4 digit) exp - 7. expression involving simple numbers - 8. expression involving exponential numbers - 9. number with random text like xyz - 10. hex numbers - 11. binary numbers - 12. octal numbers - 13. very large number - 14. number with some escape characters in b/w like ",/. \n\r ", '" - 15. expression involving sin, cos or other mathematic functions - 16. expression having more than one operator in b/w operands - 17. expression involving open and close parenthesis (, ) - - ****************************************/ - - void CopyPasteManagerTest::FunctionalCopyPasteTest() - { - // Doesn't have test where converter is involved. Will add such a test later. - StandardCalculatorViewModel^ scvm = ref new StandardCalculatorViewModel(); - scvm->IsStandard = true; - String^ input[] = { 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" }; - - START_LOOP(input) - // paste number in standard mode and then validate the pastability of displayed number for other modes - scvm->OnPaste(input[size], ViewMode::Standard); - VERIFY_ARE_EQUAL(ValidateStandardPasteExpression(scvm->DisplayValue), scvm->DisplayValue); - VERIFY_ARE_EQUAL(ValidateScientificPasteExpression(scvm->DisplayValue), scvm->DisplayValue); - VERIFY_ARE_EQUAL(ValidateProgrammerHexQwordPasteExpression(scvm->DisplayValue), scvm->DisplayValue); - END_LOOP - } - - - void CopyPasteManagerTest::ValidateStandardPasteExpressionTest() - { - String^ positiveInput[] = { L"123", L"+123", L"-133", L"12345.", L"+12.34", L"12.345", L"012.034", L"-23.032", L"-.123", L".1234", L"012.012", L"123+456", L"123+-234", L"123*-345", L"123*4*-3", L"123*+4*-3", L"1,234", L"1 2 3", L"\n\r1,234\n", L"\f\n1+2\t\r\v\x85", L"\n 1+\n2 ", L"1\"2", L"1234567891234567"/*boundary condition <=16 digits*/, L"2+2=", L"2+2= " }; - String^ negativeInput[] = { L"(123)+(456)", L"1.2e23"/*unsigned exponent*/, L"12345e-23", L"abcdef", L"xyz", L"ABab", L"e+234", L"12345678912345678"/*boundary condition: greater than 16 digits*/, L"SIN(2)", L"2+2==", L"2=+2" }; - - ASSERT_POSITIVE_TESTCASES(ValidateStandardPasteExpression, positiveInput); - ASSERT_NEGATIVE_TESTCASES(ValidateStandardPasteExpression, negativeInput); - } - - void CopyPasteManagerTest::ValidateScientificPasteExpressionTest() - { - String^ positiveInput[] = { L"123", L"+123", L"-133", L"123+456", L"12345e+023", L"1,234", L"1.23", L"-.123", L".1234", L"012.012", L"123+-234", L"123*-345", L"123*4*-3", L"123*+4*-3", L"1 2 3", L"\n\r1,234\n", L"\f\n1+2\t\r\v\x85", L"\n 1+\n2 ", L"1\"2", L"1.2e+023", L"12345e-23", L"(123)+(456)", L"12345678912345678123456789012345", L"(123)+(456)=", L"2+2= " }; - String^ negativeInput[] = { L"1.2e23"/*unsigned exponent*/, L"abcdef", L"xyz", 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_NEGATIVE_TESTCASES(ValidateScientificPasteExpression, negativeInput); - } - - void CopyPasteManagerTest::ValidateProgrammerHexPasteExpressionTest() - { - 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"12345e-23"/*note: here is considered as E of hex*/, 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"e+234", L"1\"2", L"(123)+(456)", L"abcdef", L"ABab", L"ABCDF21abc41a"/*within boundary*/, L"0x1234", L"0xab12", L"0X1234", L"AB12h", L"BC34H", L"1234u", L"1234ul", L"1234ULL", L"2+2=", L"2+2= " }; - String^ qwordNegativeInput[] = { L"+123", L"1.23"/*floating number*/, L"1''2", L"'123", L"123'", L"1__2", L"_123", L"123_", L"-133", L"1.2e+023", L"1.2e23"/*unsigned exponent*/, L"xyz", L"ABCDEF21abc41abc7"/*outside boundary of 16 digitis*/, L"SIN(2)", L"123+-234", L"1234x", L"A0x1234", L"0xx1234", L"1234uu", L"1234ulll", L"2+2==", L"2=+2" }; - - ASSERT_POSITIVE_TESTCASES(ValidateProgrammerHexQwordPasteExpression, qwordPositiveInput); - ASSERT_NEGATIVE_TESTCASES(ValidateProgrammerHexQwordPasteExpression, qwordNegativeInput); - - String^ dwordPositiveInput[] = { L"123", L"123+456", L"1,234", L"1 2 3", L"1'2'3'4", L"1_2_3_4", L"12345e-23"/*note: here is considered as E of hex*/, L"\n\r1,234\n", L"\f\n1+2\t\r\v\x85", L"\n 1+\n2 ", L"e+234", L"1\"2", L"(123)+(456)", L"abcdef", L"ABab", L"ABCD123a"/*within boundary*/, L"0x1234", L"0xab12", L"0X1234", L"AB12h", L"BC34H", L"1234u", L"1234ul", L"1234ULL" }; - String^ dwordNegativeInput[] = { L"+123", L"1.23"/*floating number*/, L"1''2", L"'123", L"123'", L"1__2", L"_123", L"123_", L"-133", L"1.2e+023", L"1.2e23"/*unsigned exponent*/, L"xyz", L"ABCD123ab"/*outside boundary of 8 digitis*/, L"SIN(2)", L"123+-234", L"1234x", L"A0x1234", L"0xx1234", L"1234uu", L"1234ulll" }; - - ASSERT_POSITIVE_TESTCASES(ValidateProgrammerHexDwordPasteExpression, dwordPositiveInput); - ASSERT_NEGATIVE_TESTCASES(ValidateProgrammerHexDwordPasteExpression, dwordNegativeInput); - - String^ wordPositiveInput[] = { L"123", L"13+456", L"1,34", L"12 3", L"1'2'3'4", L"1_2_3_4", L"15e-23"/*note: here is considered as E of hex*/, L"\r1", L"\n\r1,4", L"\n1,4\n", L"\f\n1+2\t\r\v", L"\n 1+\n2 ", L"e+24", L"1\"2", L"(23)+(4)", L"aef", L"ABab", L"A1a3"/*within boundary*/, L"0x1234", L"0xab12", L"0X1234", L"AB12h", L"BC34H", L"1234u", L"1234ul", L"1234ULL" }; - String^ wordNegativeInput[] = { L"+123", L"1.23"/*floating number*/, L"1''2", L"'123", L"123'", L"1__2", L"_123", L"123_", L"-133", L"1.2e+023", L"1.2e23"/*unsigned exponent*/, L"xyz", L"A1a3b"/*outside boundary of 4 digitis*/, L"SIN(2)", L"123+-234", L"1234x", L"A0x1234", L"0xx1234", L"1234uu", L"1234ulll" }; - - ASSERT_POSITIVE_TESTCASES(ValidateProgrammerHexWordPasteExpression, wordPositiveInput); - ASSERT_NEGATIVE_TESTCASES(ValidateProgrammerHexWordPasteExpression, wordNegativeInput); - - String^ bytePositiveInput[] = { L"13", L"13+6", L"1,4", L"2 3", L"1'2", L"1_2", L"5e-3"/*note: here is considered as E of hex*/, L"\r1", L"a", L"ab", L"A1"/*within boundary*/, L"0x12", L"0xab", L"0X12", L"A9h", L"B8H", L"12u", L"12ul", L"12ULL" }; - String^ byteNegativeInput[] = { L"+3", L"1.2"/*floating number*/, L"1''2", L"'12", L"12'", L"1__2", L"_12", L"12_", L"-3", L"1.1e+02", L"1.2e3"/*unsigned exponent*/, L"xz", L"A3a"/*outside boundary of 2 digitis*/, L"SIN(2)", L"13+-23", L"12x", L"A0x1", L"0xx12", L"12uu", L"12ulll" }; - - ASSERT_POSITIVE_TESTCASES(ValidateProgrammerHexBytePasteExpression, bytePositiveInput); - ASSERT_NEGATIVE_TESTCASES(ValidateProgrammerHexBytePasteExpression, byteNegativeInput); - } - - void CopyPasteManagerTest::ValidateProgrammerDecPasteExpressionTest() - { - String^ qwordPositiveInput[] = { L"123", L"+123", L"-133", 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"123+-234", L"123*-345", L"123*4*-3", L"123*+4*-3", L"9223372036854775807", L"-9223372036854775807"/*boundary condition: max/min allowed number*/, L"0n1234", L"0N1234", L"1234u", L"1234ul", L"1234ULL", L"2+2=", L"2+2= " }; - String^ qwordNegativeInput[] = { L"1.23", L"1''2", L"'123", L"123'", L"1__2", L"_123", L"123_", L"1.2e23"/*unsigned exponent*/, L"1.2e+023", L"12345e-23", L"abcdef", L"xyz", L"ABab", L"e+234", L"9223372036854775809"/*boundary condition: greater than max allowed number 9223372036854775807*/, L"SIN(2)", L"-0n123", L"0nn1234", L"1234uu", L"1234ulll", L"2+2==", L"2=+2" }; - - ASSERT_POSITIVE_TESTCASES(ValidateProgrammerDecQwordPasteExpression, qwordPositiveInput); - ASSERT_NEGATIVE_TESTCASES(ValidateProgrammerDecQwordPasteExpression, qwordNegativeInput); - - String^ dwordPositiveInput[] = { L"123", L"+123", L"-133", 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"123+-234", L"123*-345", L"123*4*-3", L"123*+4*-3", L"2147483647", L"-2147483647"/*boundary condition: max/min allowed number*/, L"0n1234", L"0N1234", L"1234u", L"1234ul", L"1234ULL" }; - String^ dwordNegativeInput[] = { L"1.23", L"1''2", L"'123", L"123'", L"1__2", L"_123", L"123_", L"1.2e23"/*unsigned exponent*/, L"1.2e+023", L"12345e-23", L"abcdef", L"xyz", L"ABab", L"e+234", L"2147483649"/*boundary condition: greater than max allowed number 2147483647*/, L"SIN(2)", L"-0n123", L"0nn1234", L"1234uu", L"1234ulll" }; - - ASSERT_POSITIVE_TESTCASES(ValidateProgrammerDecDwordPasteExpression, dwordPositiveInput); - ASSERT_NEGATIVE_TESTCASES(ValidateProgrammerDecDwordPasteExpression, dwordNegativeInput); - - String^ wordPositiveInput[] = { L"123", L"+123", L"-133", L"123+456", L"1,234", L"1 2 3", L"1'2'3'4", L"1_2_3_4", L"\f\n1+2\t\r\v\x85", L"1\"2", L"(123)+(456)", L"123+-234", L"123*-345", L"123*4*-3", L"123*+4*-3", L"32767", L"-32767"/*boundary condition: max/min allowed number*/, L"0n1234", L"0N1234", L"1234u", L"1234ul", L"1234ULL" }; - String^ wordNegativeInput[] = { L"1.23", L"1''2", L"'123", L"123'", L"1__2", L"_123", L"123_", L"1.2e23"/*unsigned exponent*/, L"1.2e+023", L"12345e-23", L"abcdef", L"xyz", L"ABab", L"e+234", L"32769"/*boundary condition: greater than max allowed number 32769*/, L"SIN(2)", L"-0n123", L"0nn1234", L"1234uu", L"1234ulll" }; - - ASSERT_POSITIVE_TESTCASES(ValidateProgrammerDecWordPasteExpression, wordPositiveInput); - ASSERT_NEGATIVE_TESTCASES(ValidateProgrammerDecWordPasteExpression, wordNegativeInput); - - String^ bytePositiveInput[] = { L"13", L"+13", L"-13", L"13+46", L"13+-34", L"13*-3", L"3*4*-3", L"3*+4*-3", L"1,3", L"1 3", L"1'2'3", L"1_2_3", L"1\"2", L"127", L"-127"/*boundary condition: max/min allowed number*/, L"0n123", L"0N123", L"123u", L"123ul", L"123ULL" }; - String^ byteNegativeInput[] = { L"1.23", L"1''2", L"'123", L"123'", L"1__2", L"_123", L"123_", L"1.2e23"/*unsigned exponent*/, L"1.2e+023", L"15e-23", L"abcdef", L"xyz", L"ABab", L"e+24", L"129"/*boundary condition: greater than max allowed number 127*/, L"SIN(2)", L"-0n123", L"0nn1234", L"123uu", L"123ulll" }; - - ASSERT_POSITIVE_TESTCASES(ValidateProgrammerDecBytePasteExpression, bytePositiveInput); - ASSERT_NEGATIVE_TESTCASES(ValidateProgrammerDecBytePasteExpression, byteNegativeInput); - } - - 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", 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= " }; - String^ qwordNegativeInput[] = { L"+123", L"1.23", L"1''2", L"'123", L"123'", L"1__2", L"_123", L"123_", L"-133", L"1.2e23"/*unsigned exponent*/, L"1.2e+023", L"12345e-23", L"abcdef", L"xyz", L"ABab", L"e+234", L"12345678901234567890123"/*boundary condition: greater than max allowed digits 22*/, L"SIN(2)", L"123+-234", L"0ot1234", L"1234uu", L"1234ulll", L"2+2==", L"2=+2" }; - - ASSERT_POSITIVE_TESTCASES(ValidateProgrammerOctQwordPasteExpression, qwordPositiveInput); - ASSERT_NEGATIVE_TESTCASES(ValidateProgrammerOctQwordPasteExpression, qwordNegativeInput); - - String^ dwordPositiveInput[] = { 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"37777777777"/*boundary condition: max allowed number*/, L"0t1234", L"0T1234", L"0o1234", L"0O1234", L"1234u", L"1234ul", L"1234ULL" }; - String^ dwordNegativeInput[] = { L"+123", L"1.23", L"1''2", L"'123", L"123'", L"1__2", L"_123", L"123_", L"-133", L"1.2e23"/*unsigned exponent*/, L"1.2e+023", L"12345e-23", L"abcdef", L"xyz", L"ABab", L"e+234", L"377777777771"/*boundary condition: greater than max allowed number 37777777777*/, L"SIN(2)", L"123+-234", L"0ot1234", L"1234uu", L"1234ulll" }; - - ASSERT_POSITIVE_TESTCASES(ValidateProgrammerOctDwordPasteExpression, dwordPositiveInput); - ASSERT_NEGATIVE_TESTCASES(ValidateProgrammerOctDwordPasteExpression, dwordNegativeInput); - - String^ wordPositiveInput[] = { L"123", L"123+456", L"1,234", L"1 2 3", L"1'2'3'4", L"1_2_3_4", L"\f\n1+2\t\r\v\x85", L"1\"2", L"(123)+(456)", L"177777"/*boundary condition: max allowed number*/, L"0t1234", L"0T1234", L"0o1234", L"0O1234", L"1234u", L"1234ul", L"1234ULL" }; - String^ wordNegativeInput[] = { L"+123", L"1.23", L"1''2", L"'123", L"123'", L"1__2", L"_123", L"123_", L"-133", L"1.2e23"/*unsigned exponent*/, L"1.2e+023", L"12345e-23", L"abcdef", L"xyz", L"ABab", L"e+234", L"1777771"/*boundary condition: greater than max allowed number 177777*/, L"SIN(2)", L"123+-234", L"0ot1234", L"1234uu", L"1234ulll" }; - - ASSERT_POSITIVE_TESTCASES(ValidateProgrammerOctWordPasteExpression, wordPositiveInput); - ASSERT_NEGATIVE_TESTCASES(ValidateProgrammerOctWordPasteExpression, wordNegativeInput); - - String^ bytePositiveInput[] = { L"13", L"13+46", L"1,3", L"1 3", L"1'2'3", L"1_2_3", L"1\"2", L"377"/*boundary condition: max allowed number*/, L"0t123", L"0T123", L"0o123", L"0O123", L"123u", L"123ul", L"123ULL" }; - String^ byteNegativeInput[] = { L"+123", L"1.23", L"1''2", L"'123", L"123'", L"1__2", L"_123", L"123_", L"-13", L"1.2e23"/*unsigned exponent*/, L"1.2e+023", L"15e-23", L"abcdef", L"xyz", L"ABab", L"e+24", L"477"/*boundary condition: greater than max allowed number 377*/, L"SIN(2)", L"123+-34", L"0ot123", L"123uu", L"123ulll" }; - - ASSERT_POSITIVE_TESTCASES(ValidateProgrammerOctBytePasteExpression, bytePositiveInput); - ASSERT_NEGATIVE_TESTCASES(ValidateProgrammerOctBytePasteExpression, byteNegativeInput); - } - - void CopyPasteManagerTest::ValidateProgrammerBinPasteExpressionTest() - { - String^ qwordPositiveInput[] = { L"100", L"100+101", L"1,001", L"1 0 1", L"1'0'0'1", L"1_0_0_1", L"\n\r1,010\n", L"\f\n1+11\t\r\v\x85", L"\n 1+\n1 ", L"1\"1", L"(101)+(10)", L"0b1001", L"0B1111", L"0y1001", L"0Y1001", L"1100b", L"1101B", L"1111u", L"1111ul", L"1111ULL", L"1010101010101010101010101011110110100100101010101001010101001010"/*boundary condition: max allowed digits 64*/, L"1+10=", L"1+10= " }; - String^ qwordNegativeInput[] = { L"+10101", L"1.01", L"1''0", L"'101", L"101'", L"1__0", L"_101", L"101_", L"-10101001", L"123", L"1.2e23"/*unsigned exponent*/, L"1.2e+023", L"101010e-1010", L"abcdef", L"xyz", L"ABab", L"e+10101", L"b1001", L"10b01", L"0x10", L"1001x", L"1001h", L"0bb1111", L"1111uu", L"1111ulll", L"10101010101010101010101010111101101001001010101010010101010010100"/*boundary condition: greater than max allowed digits 64*/, L"SIN(01010)", L"10+-10101010101", L"1+10==", L"1=+10" }; - - ASSERT_POSITIVE_TESTCASES(ValidateProgrammerBinQwordPasteExpression, qwordPositiveInput); - ASSERT_NEGATIVE_TESTCASES(ValidateProgrammerBinQwordPasteExpression, qwordNegativeInput); - - String^ dwordPositiveInput[] = { L"100", L"100+101", L"1,001", L"1 0 1", L"1'0'0'1", L"1_0_0_1", L"\n\r1,010\n", L"\f\n1+11\t\r\v\x85", L"\n 1+\n1 ", L"1\"1", L"(101)+(10)", L"0b1001", L"0B1111", L"0y1001", L"0Y1001", L"1100b", L"1101B", L"1111u", L"1111ul", L"1111ULL", L"10101001001010101101010111111100"/*boundary condition: max allowed number*/ }; - String^ dwordNegativeInput[] = { L"+10101", L"1.01", L"1''0", L"'101", L"101'", L"1__0", L"_101", L"101_", L"-10101001", L"123", L"1.2e23"/*unsigned exponent*/, L"1.2e+023", L"101010e-1010", L"abcdef", L"xyz", L"ABab", L"e+10101", L"b1001", L"10b01", L"0x10", L"1001x", L"1001h", L"0bb1111", L"1111uu", L"1111ulll", L"101010010010101011010101111111001"/*boundary condition: greater than max allowed digits 32*/, L"SIN(01010)", L"10+-10101010101" }; - - ASSERT_POSITIVE_TESTCASES(ValidateProgrammerBinDwordPasteExpression, dwordPositiveInput); - ASSERT_NEGATIVE_TESTCASES(ValidateProgrammerBinDwordPasteExpression, dwordNegativeInput); - - String^ wordPositiveInput[] = { L"100", L"100+101", L"1,001", L"1 0 1", L"1'0'0'1", L"1_0_0_1", L"\n\r1,010\n", L"\f\n1+11\t\r\v\x85", L"\n 1+\n1 ", L"1\"1", L"(101)+(10)", L"0b1001", L"0B1111", L"0y1001", L"0Y1001", L"1100b", L"1101B", L"1111u", L"1111ul", L"1111ULL", L"1010101010010010"/*boundary condition: max allowed number*/ }; - String^ wordNegativeInput[] = { L"+10101", L"1.01", L"1''0", L"'101", L"101'", L"1__0", L"_101", L"101_", L"-10101001", L"123", L"1.2e23"/*unsigned exponent*/, L"1.2e+023", L"101010e-1010", L"abcdef", L"xyz", L"ABab", L"e+10101", L"b1001", L"10b01", L"0x10", L"1001x", L"1001h", L"0bb1111", L"1111uu", L"1111ulll", L"10101010100100101"/*boundary condition: greater than max allowed digits 16*/, L"SIN(01010)", L"10+-10101010101" }; - - ASSERT_POSITIVE_TESTCASES(ValidateProgrammerBinWordPasteExpression, wordPositiveInput); - ASSERT_NEGATIVE_TESTCASES(ValidateProgrammerBinWordPasteExpression, wordNegativeInput); - - String^ bytePositiveInput[] = { L"100", L"100+101", L"1,001", L"1 0 1", L"1'0'0'1", L"1_0_0_1", L"\n\r1,010\n", L"\n 1+\n1 ", L"1\"1", L"(101)+(10)", L"0b1001", L"0B1111", L"0y1001", L"0Y1001", L"1100b", L"1101B", L"1111u", L"1111ul", L"1111ULL", L"10100010"/*boundary condition: max allowed number*/ }; - String^ byteNegativeInput[] = { L"+10101", L"1.01", L"1''0", L"'101", L"101'", L"1__0", L"_101", L"101_", L"-10101001", L"123", L"1.2e23"/*unsigned exponent*/, L"1.2e+023", L"101010e-1010", L"abcdef", L"xyz", L"ABab", L"e+10101", L"b1001", L"10b01", L"0x10", L"1001x", L"1001h", L"0bb1111", L"1111uu", L"1111ulll", L"101000101"/*boundary condition: greater than max allowed digits 8*/, L"SIN(01010)", L"10+-1010101" }; - - ASSERT_POSITIVE_TESTCASES(ValidateProgrammerBinBytePasteExpression, bytePositiveInput); - ASSERT_NEGATIVE_TESTCASES(ValidateProgrammerBinBytePasteExpression, byteNegativeInput); - } - - void CopyPasteManagerTest::ValidateConverterPasteExpressionTest() - { - String^ positiveInput[] = { L"123", L"+123", L"-133", L"12345.", L"012.012", L"1,234", L"1 2 3", L"\n\r1,234\n", L"\f\n12\t\r\v\x85", L"1\"2", L"100=", L"100= " }; - String^ negativeInput[] = { L"(123)+(456)", L"1.2e23"/*unsigned exponent*/, L"12345e-23", L"\n 1+\n2 ", L"123+456", L"abcdef", L"\n 1+\n2 ", L"xyz", L"ABab", L"e+234", L"12345678912345678"/*boundary condition: greater than 16 bits*/, L"SIN(2)", L"123+-234", L"100==", L"=100" }; - - ASSERT_POSITIVE_TESTCASES(ValidateConverterPasteExpression, positiveInput); - ASSERT_NEGATIVE_TESTCASES(ValidateConverterPasteExpression, negativeInput); - } -} - diff --git a/internal/CalculatorUnitTests/CurrencyConverterUnitTests.cpp b/internal/CalculatorUnitTests/CurrencyConverterUnitTests.cpp deleted file mode 100644 index 04aaa7d..0000000 --- a/internal/CalculatorUnitTests/CurrencyConverterUnitTests.cpp +++ /dev/null @@ -1,605 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#include "pch.h" -#include - -#include "CalcViewModel\DataLoaders\CurrencyDataLoader.h" -#include "CalcViewModel\Common\LocalizationService.h" - -using namespace CalculatorApp::Common; -using namespace CalculatorApp::Common::LocalizationServiceProperties; -using namespace CalculatorApp::DataLoaders; -using namespace CalculatorApp::ViewModel; -using namespace CalculatorUnitTests; -using namespace Concurrency; -using namespace Platform; -using namespace std; -using namespace UnitConversionManager; -using namespace Windows::Foundation; -using namespace Windows::Storage; -using namespace Windows::Web::Http; - -namespace CalculatorApp -{ - namespace DataLoaders - { - class MockCurrencyHttpClientWithResult : public CurrencyHttpClient - { - public: - MockCurrencyHttpClientWithResult(String^ staticResponse, String^ allRatiosResponse) : - m_staticResponse(staticResponse), - m_allRatiosResponse(allRatiosResponse) - { - } - - IAsyncOperationWithProgress^ GetCurrencyMetadata() override - { - return ref new MockAsyncOperationWithProgress(m_staticResponse); - } - - IAsyncOperationWithProgress^ GetCurrencyRatios() override - { - return ref new MockAsyncOperationWithProgress(m_allRatiosResponse); - } - - private: - String^ m_staticResponse; - String^ m_allRatiosResponse; - }; - - class MockCurrencyHttpClientThrowsException : public CurrencyHttpClient - { - public: - MockCurrencyHttpClientThrowsException() {} - - IAsyncOperationWithProgress^ GetCurrencyMetadata() override - { - throw ref new NotImplementedException(); - } - - IAsyncOperationWithProgress^ GetCurrencyRatios() override - { - throw ref new NotImplementedException(); - } - }; - } -} - -class DataLoadedCallback : public UnitConversionManager::IViewModelCurrencyCallback -{ -public: - DataLoadedCallback(task_completion_event tce) : - m_task_completion_event{ tce } - {} - - void CurrencyDataLoadFinished(bool didLoad) override - { - m_task_completion_event.set(); - } - - void CurrencySymbolsCallback(_In_ const wstring& fromSymbol, _In_ const wstring& toSymbol) override {} - void CurrencyRatiosCallback(_In_ const wstring& ratioEquality, _In_ const wstring& accRatioEquality) override {} - void CurrencyTimestampCallback(_In_ const std::wstring& timestamp, bool isWeekOldData) override {} - void NetworkBehaviorChanged(_In_ int newBehavior) override {} - -private: - Concurrency::task_completion_event m_task_completion_event; -}; - -namespace CalculatorUnitTests -{ - constexpr auto sc_Language_EN = L"en-US"; - - const UCM::Category CURRENCY_CATEGORY = { NavCategory::Serialize(ViewMode::Currency), L"Currency", false /*supportsNegative*/ }; - - unique_ptr MakeLoaderWithResults(String^ staticResponse, String^ allRatiosResponse) - { - auto client = make_unique(staticResponse, allRatiosResponse); - client->SetSourceCurrencyCode(StringReference(DefaultCurrencyCode.data())); - return make_unique(move(client)); - } - - String^ SerializeContent(const vector& data) - { - String^ result = L""; - String^ delimiter = CurrencyDataLoaderConstants::CacheDelimiter; - for (String^ content : data) - { - result += (delimiter + content); - } - - return result; - } - - bool WriteToFileInLocalCacheFolder(String^ filename, String^ content) - { - try - { - StorageFolder^ localFolder = ApplicationData::Current->LocalCacheFolder; - StorageFile^ file = create_task(localFolder->CreateFileAsync(filename, CreationCollisionOption::ReplaceExisting)).get(); - create_task(FileIO::WriteTextAsync(file, content)).wait(); - return true; - } - catch (Exception^ ex) - { - return false; - } - } - - bool DeleteFileFromLocalCacheFolder(String^ filename) - { - try - { - StorageFolder^ folder = ApplicationData::Current->LocalCacheFolder; - IAsyncOperation^ fileOperation = folder->GetFileAsync(filename); - StorageFile^ file = create_task(fileOperation).get(); - create_task(file->DeleteAsync()).get(); - return true; - } - catch (Platform::Exception^ ex) - { - // FileNotFoundException is a valid result - return ex->HResult == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND); - } - catch (...) - { - return false; - } - } - - bool DeleteCurrencyCacheFiles() - { - try - { - bool deletedStaticData = DeleteFileFromLocalCacheFolder(CurrencyDataLoaderConstants::StaticDataFilename); - bool deletedAllRatiosData = DeleteFileFromLocalCacheFolder(CurrencyDataLoaderConstants::AllRatiosDataFilename); - - return deletedStaticData && deletedAllRatiosData; - } - catch (...) - { - return false; - } - } - - void InsertToLocalSettings(String^ key, Object^ value) - { - ApplicationData::Current->LocalSettings->Values->Insert(key, value); - } - - void RemoveFromLocalSettings(String^ key) - { - // Safe to call, even if the key does not exist. - ApplicationData::Current->LocalSettings->Values->Remove(key); - } - - void StandardCacheSetup() - { - // Insert current time so data is less than a day old. - DateTime now = Utils::GetUniversalSystemTime(); - InsertToLocalSettings(CurrencyDataLoaderConstants::CacheTimestampKey, now); - InsertToLocalSettings(CurrencyDataLoaderConstants::CacheLangcodeKey, StringReference(sc_Language_EN)); - - VERIFY_IS_TRUE(DeleteCurrencyCacheFiles()); - - VERIFY_IS_TRUE(WriteToFileInLocalCacheFolder(CurrencyDataLoaderConstants::StaticDataFilename, CurrencyHttpClient::GetRawStaticDataResponse())); - VERIFY_IS_TRUE(WriteToFileInLocalCacheFolder(CurrencyDataLoaderConstants::AllRatiosDataFilename, CurrencyHttpClient::GetRawAllRatiosDataResponse())); - } - - class CurrencyConverterLoadTests - { - public: - TEST_CLASS(CurrencyConverterLoadTests); - - - TEST_METHOD_SETUP(DeleteCacheFiles) - { - return DeleteCurrencyCacheFiles(); - } - - TEST_METHOD(LoadFromCache_Fail_NoCacheKey) - { - RemoveFromLocalSettings(CurrencyDataLoaderConstants::CacheTimestampKey); - - CurrencyDataLoader loader{ nullptr }; - - bool didLoad = loader.TryLoadDataFromCacheAsync().get(); - - VERIFY_IS_FALSE(didLoad); - VERIFY_IS_FALSE(loader.LoadFinished()); - VERIFY_IS_FALSE(loader.LoadedFromCache()); - } - - TEST_METHOD(LoadFromCache_Fail_OlderThanADay) - { - // Insert 24 hours ago so data is considered stale. - // This will cause the load from cache to fail. - DateTime now = Utils::GetUniversalSystemTime(); - DateTime dayOld; - dayOld.UniversalTime = now.UniversalTime - CurrencyDataLoaderConstants::DayDuration - 1; - InsertToLocalSettings(CurrencyDataLoaderConstants::CacheTimestampKey, dayOld); - - CurrencyDataLoader loader{ nullptr }; - - bool didLoad = loader.TryLoadDataFromCacheAsync().get(); - - VERIFY_IS_FALSE(didLoad); - VERIFY_IS_FALSE(loader.LoadFinished()); - VERIFY_IS_FALSE(loader.LoadedFromCache()); - } - - TEST_METHOD(LoadFromCache_Fail_StaticDataFileDoesNotExist) - { - // Insert current time so data is less than a day old. - // This will cause the load to continue to attempt to load the file. - DateTime now = Utils::GetUniversalSystemTime(); - InsertToLocalSettings(CurrencyDataLoaderConstants::CacheTimestampKey, now); - - VERIFY_IS_TRUE(DeleteFileFromLocalCacheFolder(CurrencyDataLoaderConstants::StaticDataFilename)); - VERIFY_IS_TRUE(WriteToFileInLocalCacheFolder(CurrencyDataLoaderConstants::AllRatiosDataFilename, CurrencyHttpClient::GetRawAllRatiosDataResponse())); - - CurrencyDataLoader loader{ nullptr }; - - bool didLoad = loader.TryLoadDataFromCacheAsync().get(); - - VERIFY_IS_FALSE(didLoad); - VERIFY_IS_FALSE(loader.LoadFinished()); - VERIFY_IS_FALSE(loader.LoadedFromCache()); - } - - TEST_METHOD(LoadFromCache_Fail_AllRatiosDataFileDoesNotExist) - { - // Insert current time so data is less than a day old. - // This will cause the load to continue to attempt to load the file. - DateTime now = Utils::GetUniversalSystemTime(); - InsertToLocalSettings(CurrencyDataLoaderConstants::CacheTimestampKey, now); - - VERIFY_IS_TRUE(WriteToFileInLocalCacheFolder(CurrencyDataLoaderConstants::StaticDataFilename, CurrencyHttpClient::GetRawStaticDataResponse())); - VERIFY_IS_TRUE(DeleteFileFromLocalCacheFolder(CurrencyDataLoaderConstants::AllRatiosDataFilename)); - - CurrencyDataLoader loader{ nullptr }; - - bool didLoad = loader.TryLoadDataFromCacheAsync().get(); - - VERIFY_IS_FALSE(didLoad); - VERIFY_IS_FALSE(loader.LoadFinished()); - VERIFY_IS_FALSE(loader.LoadedFromCache()); - } - - TEST_METHOD(LoadFromCache_Fail_ResponseLanguageChanged) - { - DateTime now = Utils::GetUniversalSystemTime(); - InsertToLocalSettings(CurrencyDataLoaderConstants::CacheTimestampKey, now); - - // Tests always use en-US as response language. Insert a different lang-code to fail the test. - InsertToLocalSettings(CurrencyDataLoaderConstants::CacheLangcodeKey, L"ar-SA"); - - VERIFY_IS_TRUE(WriteToFileInLocalCacheFolder(CurrencyDataLoaderConstants::StaticDataFilename, CurrencyHttpClient::GetRawStaticDataResponse())); - VERIFY_IS_TRUE(DeleteFileFromLocalCacheFolder(CurrencyDataLoaderConstants::AllRatiosDataFilename)); - - CurrencyDataLoader loader{ nullptr }; - - bool didLoad = loader.TryLoadDataFromCacheAsync().get(); - - VERIFY_IS_FALSE(didLoad); - VERIFY_IS_FALSE(loader.LoadFinished()); - VERIFY_IS_FALSE(loader.LoadedFromCache()); - } - - TEST_METHOD(LoadFromCache_Success) - { - StandardCacheSetup(); - - CurrencyDataLoader loader{ nullptr }; - - bool didLoad = loader.TryLoadDataFromCacheAsync().get(); - - VERIFY_IS_TRUE(didLoad); - VERIFY_IS_TRUE(loader.LoadFinished()); - VERIFY_IS_TRUE(loader.LoadedFromCache()); - } - - TEST_METHOD(LoadFromWeb_Fail_ClientIsNullptr) - { - CurrencyDataLoader loader{ nullptr }; - - bool didLoad = loader.TryLoadDataFromWebAsync().get(); - - VERIFY_IS_FALSE(didLoad); - VERIFY_IS_FALSE(loader.LoadFinished()); - VERIFY_IS_FALSE(loader.LoadedFromWeb()); - } - - TEST_METHOD(LoadFromWeb_Fail_WebException) - { - CurrencyDataLoader loader{ make_unique() }; - - bool didLoad = loader.TryLoadDataFromWebAsync().get(); - - VERIFY_IS_FALSE(didLoad); - VERIFY_IS_FALSE(loader.LoadFinished()); - VERIFY_IS_FALSE(loader.LoadedFromWeb()); - } - - TEST_METHOD(LoadFromWeb_Success) - { - String^ staticResponse = CurrencyHttpClient::GetRawStaticDataResponse(); - String^ allRatiosResponse = CurrencyHttpClient::GetRawAllRatiosDataResponse(); - unique_ptr loader = MakeLoaderWithResults(staticResponse, allRatiosResponse); - - bool didLoad = loader->TryLoadDataFromWebAsync().get(); - - VERIFY_IS_TRUE(didLoad); - VERIFY_IS_TRUE(loader->LoadFinished()); - VERIFY_IS_TRUE(loader->LoadedFromWeb()); - } - - TEST_METHOD(Load_Success_LoadedFromCache) - { - StandardCacheSetup(); - - CurrencyDataLoader loader{ nullptr }; - - auto data_loaded_event = task_completion_event(); - loader.SetViewModelCallback(make_shared(data_loaded_event)); - - auto data_loaded_task = create_task(data_loaded_event); - loader.LoadData(); - data_loaded_task.wait(); - - VERIFY_IS_TRUE(loader.LoadFinished()); - VERIFY_IS_TRUE(loader.LoadedFromCache()); - VERIFY_IS_FALSE(loader.LoadedFromWeb()); - } - - TEST_METHOD(Load_Success_LoadedFromWeb) - { - // Insert 24 hours ago so data is considered stale. - // This will cause the load from cache to fail. - DateTime now = Utils::GetUniversalSystemTime(); - DateTime dayOld; - dayOld.UniversalTime = now.UniversalTime - CurrencyDataLoaderConstants::DayDuration - 1; - InsertToLocalSettings(CurrencyDataLoaderConstants::CacheTimestampKey, dayOld); - - String^ staticResponse = CurrencyHttpClient::GetRawStaticDataResponse(); - String^ allRatiosResponse = CurrencyHttpClient::GetRawAllRatiosDataResponse(); - unique_ptr loader = MakeLoaderWithResults(staticResponse, allRatiosResponse); - - auto data_loaded_event = task_completion_event(); - loader->SetViewModelCallback(make_shared(data_loaded_event)); - - auto data_loaded_task = create_task(data_loaded_event); - loader->LoadData(); - data_loaded_task.wait(); - - VERIFY_IS_TRUE(loader->LoadFinished()); - VERIFY_IS_FALSE(loader->LoadedFromCache()); - VERIFY_IS_TRUE(loader->LoadedFromWeb()); - } - }; - - class CurrencyConverterUnitTests - { - TEST_CLASS(CurrencyConverterUnitTests); - - const UCM::Unit GetUnit(const vector& unitList, const wstring& target) - { - return *find_if(begin(unitList), end(unitList), [&target](const UCM::Unit& u) { return u.abbreviation == target; }); - } - - TEST_METHOD(Loaded_LoadOrderedUnits) - { - StandardCacheSetup(); - - CurrencyDataLoader loader{ nullptr }; - - auto data_loaded_event = task_completion_event(); - loader.SetViewModelCallback(make_shared(data_loaded_event)); - - auto data_loaded_task = create_task(data_loaded_event); - loader.LoadData(); - data_loaded_task.wait(); - - VERIFY_IS_TRUE(loader.LoadFinished()); - VERIFY_IS_TRUE(loader.LoadedFromCache()); - VERIFY_IS_FALSE(loader.LoadedFromWeb()); - - vector unitList = loader.LoadOrderedUnits(CURRENCY_CATEGORY); - VERIFY_ARE_EQUAL(size_t{ 2 }, unitList.size()); - - const UCM::Unit usdUnit = GetUnit(unitList, L"USD"); - const UCM::Unit eurUnit = GetUnit(unitList, L"EUR"); - - VERIFY_ARE_EQUAL(StringReference(L"United States - Dollar"), ref new String(usdUnit.name.c_str())); - VERIFY_ARE_EQUAL(StringReference(L"USD"), ref new String(usdUnit.abbreviation.c_str())); - - VERIFY_ARE_EQUAL(StringReference(L"Europe - Euro"), ref new String(eurUnit.name.c_str())); - VERIFY_ARE_EQUAL(StringReference(L"EUR"), ref new String(eurUnit.abbreviation.c_str())); - } - - TEST_METHOD(Loaded_LoadOrderedRatios) - { - StandardCacheSetup(); - - CurrencyDataLoader loader{ nullptr }; - - auto data_loaded_event = task_completion_event(); - loader.SetViewModelCallback(make_shared(data_loaded_event)); - - auto data_loaded_task = create_task(data_loaded_event); - loader.LoadData(); - data_loaded_task.wait(); - - VERIFY_IS_TRUE(loader.LoadFinished()); - VERIFY_IS_TRUE(loader.LoadedFromCache()); - VERIFY_IS_FALSE(loader.LoadedFromWeb()); - - vector unitList = loader.LoadOrderedUnits(CURRENCY_CATEGORY); - VERIFY_ARE_EQUAL(size_t{ 2 }, unitList.size()); - - const UCM::Unit usdUnit = GetUnit(unitList, L"USD"); - const UCM::Unit eurUnit = GetUnit(unitList, L"EUR"); - - unordered_map ratios = loader.LoadOrderedRatios(usdUnit); - VERIFY_ARE_EQUAL(size_t{ 2 }, ratios.size()); - - UCM::ConversionData usdRatioData = ratios[usdUnit]; - VERIFY_IS_TRUE((std::abs(1.0 - usdRatioData.ratio) < 1e-1)); - - UCM::ConversionData eurRatioData = ratios[eurUnit]; - VERIFY_IS_TRUE((std::abs(0.920503 - eurRatioData.ratio) < 1e-6)); - } - - TEST_METHOD(Loaded_GetCurrencySymbols_Valid) - { - StandardCacheSetup(); - - CurrencyDataLoader loader{ nullptr }; - - auto data_loaded_event = task_completion_event(); - loader.SetViewModelCallback(make_shared(data_loaded_event)); - - auto data_loaded_task = create_task(data_loaded_event); - loader.LoadData(); - data_loaded_task.wait(); - - VERIFY_IS_TRUE(loader.LoadFinished()); - VERIFY_IS_TRUE(loader.LoadedFromCache()); - VERIFY_IS_FALSE(loader.LoadedFromWeb()); - - vector unitList = loader.LoadOrderedUnits(CURRENCY_CATEGORY); - VERIFY_ARE_EQUAL(size_t{ 2 }, unitList.size()); - - const UCM::Unit usdUnit = GetUnit(unitList, L"USD"); - const UCM::Unit eurUnit = GetUnit(unitList, L"EUR"); - - const pair symbols = loader.GetCurrencySymbols(usdUnit, eurUnit); - - VERIFY_ARE_EQUAL(ref new String(L"$"), StringReference(symbols.first.c_str())); - VERIFY_ARE_EQUAL(ref new String(L"€"), StringReference(symbols.second.c_str())); - } - - TEST_METHOD(Loaded_GetCurrencySymbols_Invalid) - { - StandardCacheSetup(); - - CurrencyDataLoader loader{ nullptr }; - - auto data_loaded_event = task_completion_event(); - loader.SetViewModelCallback(make_shared(data_loaded_event)); - - auto data_loaded_task = create_task(data_loaded_event); - loader.LoadData(); - data_loaded_task.wait(); - - VERIFY_IS_TRUE(loader.LoadFinished()); - VERIFY_IS_TRUE(loader.LoadedFromCache()); - VERIFY_IS_FALSE(loader.LoadedFromWeb()); - - const UCM::Unit fakeUnit1 = { - 1, L"fakeUnit1", L"FUD1", false, false, false - }; - - const UCM::Unit fakeUnit2 = { - 2, L"fakeUnit2", L"FUD2", false, false, false - }; - - pair symbols = loader.GetCurrencySymbols(fakeUnit1, fakeUnit2); - - VERIFY_ARE_EQUAL(ref new String(L""), StringReference(symbols.first.c_str())); - VERIFY_ARE_EQUAL(ref new String(L""), StringReference(symbols.second.c_str())); - - // Verify that when only one unit is valid, both symbols return as empty string. - vector unitList = loader.LoadOrderedUnits(CURRENCY_CATEGORY); - VERIFY_ARE_EQUAL(size_t{ 2 }, unitList.size()); - - const UCM::Unit usdUnit = GetUnit(unitList, L"USD"); - - symbols = loader.GetCurrencySymbols(fakeUnit1, usdUnit); - - VERIFY_ARE_EQUAL(ref new String(L""), StringReference(symbols.first.c_str())); - VERIFY_ARE_EQUAL(ref new String(L""), StringReference(symbols.second.c_str())); - - symbols = loader.GetCurrencySymbols(usdUnit, fakeUnit1); - - VERIFY_ARE_EQUAL(ref new String(L""), StringReference(symbols.first.c_str())); - VERIFY_ARE_EQUAL(ref new String(L""), StringReference(symbols.second.c_str())); - } - - TEST_METHOD(Loaded_GetCurrencyRatioEquality_Valid) - { - StandardCacheSetup(); - - CurrencyDataLoader loader{ nullptr }; - - auto data_loaded_event = task_completion_event(); - loader.SetViewModelCallback(make_shared(data_loaded_event)); - - auto data_loaded_task = create_task(data_loaded_event); - loader.LoadData(); - data_loaded_task.wait(); - - VERIFY_IS_TRUE(loader.LoadFinished()); - VERIFY_IS_TRUE(loader.LoadedFromCache()); - VERIFY_IS_FALSE(loader.LoadedFromWeb()); - - vector unitList = loader.LoadOrderedUnits(CURRENCY_CATEGORY); - VERIFY_ARE_EQUAL(size_t{ 2 }, unitList.size()); - - const UCM::Unit usdUnit = GetUnit(unitList, L"USD"); - const UCM::Unit eurUnit = GetUnit(unitList, L"EUR"); - - const pair ratio = loader.GetCurrencyRatioEquality(usdUnit, eurUnit); - - VERIFY_ARE_EQUAL(ref new String(L"1 USD = 0.9205 EUR"), StringReference(ratio.first.c_str())); - VERIFY_ARE_EQUAL(ref new String(L"1 United States Dollar = 0.9205 Europe Euro"), StringReference(ratio.second.c_str())); - } - - TEST_METHOD(Loaded_GetCurrencyRatioEquality_Invalid) - { - StandardCacheSetup(); - - CurrencyDataLoader loader{ nullptr }; - - auto data_loaded_event = task_completion_event(); - loader.SetViewModelCallback(make_shared(data_loaded_event)); - - auto data_loaded_task = create_task(data_loaded_event); - loader.LoadData(); - data_loaded_task.wait(); - - VERIFY_IS_TRUE(loader.LoadFinished()); - VERIFY_IS_TRUE(loader.LoadedFromCache()); - VERIFY_IS_FALSE(loader.LoadedFromWeb()); - - const UCM::Unit fakeUnit1 = { - 1, L"fakeUnit1", L"fakeCountry1", L"FUD1", false, false, false - }; - const UCM::Unit fakeUnit2 = { - 2, L"fakeUnit2", L"fakeCountry2", L"FUD2", false, false, false - }; - - pair ratio = loader.GetCurrencyRatioEquality(fakeUnit1, fakeUnit2); - - VERIFY_ARE_EQUAL(ref new String(L""), StringReference(ratio.first.c_str())); - VERIFY_ARE_EQUAL(ref new String(L""), StringReference(ratio.second.c_str())); - - // Verify that when only one unit is valid, both symbols return as empty string. - vector unitList = loader.LoadOrderedUnits(CURRENCY_CATEGORY); - VERIFY_ARE_EQUAL(size_t{ 2 }, unitList.size()); - - const UCM::Unit usdUnit = GetUnit(unitList, L"USD"); - - ratio = loader.GetCurrencyRatioEquality(fakeUnit1, usdUnit); - - VERIFY_ARE_EQUAL(ref new String(L""), StringReference(ratio.first.c_str())); - VERIFY_ARE_EQUAL(ref new String(L""), StringReference(ratio.second.c_str())); - - ratio = loader.GetCurrencyRatioEquality(usdUnit, fakeUnit1); - - VERIFY_ARE_EQUAL(ref new String(L""), StringReference(ratio.first.c_str())); - VERIFY_ARE_EQUAL(ref new String(L""), StringReference(ratio.second.c_str())); - } - }; -} diff --git a/internal/CalculatorUnitTests/DateCalculatorUnitTests.cpp b/internal/CalculatorUnitTests/DateCalculatorUnitTests.cpp deleted file mode 100644 index d6df439..0000000 --- a/internal/CalculatorUnitTests/DateCalculatorUnitTests.cpp +++ /dev/null @@ -1,582 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#include "pch.h" -#include -#include "DateUtils.h" - -#include "CalcViewModel\Common\DateCalculator.h" -#include "CalcViewModel\DateCalculatorViewModel.h" - -using namespace Platform; -using namespace std; -using namespace Windows::Foundation; -using namespace Windows::Globalization; -using namespace Windows::Globalization::DateTimeFormatting; -using namespace CalculatorApp::Common::DateCalculation; -using namespace CalculatorApp::ViewModel; - -namespace DateCalculationUnitTests -{ - const int c_numDate = 15; - const int c_diffTestCase = 9; - const int c_numAddOobDate = 2; - const int c_numSubtractOobDate = 2; - const int c_addCases = 3; - const int c_subtractCases = 3; - const int c_dateDiff = 14; - - DateCalculationEngine m_DateCalcEngine(CalendarIdentifiers::Gregorian); - - typedef struct - { - SYSTEMTIME startDate; - SYSTEMTIME endDate; - DateDifference dateDiff; - } DateTimeTestCase; - - SYSTEMTIME date[c_numDate]; - DateDifference dateDifference[c_dateDiff]; - DateTimeTestCase datetimeDifftest[c_diffTestCase]; - DateTimeTestCase datetimeBoundAdd[c_numAddOobDate]; - DateTimeTestCase datetimeBoundSubtract[c_numSubtractOobDate]; - DateTimeTestCase datetimeAddCase[c_addCases]; - DateTimeTestCase datetimeSubtractCase[c_subtractCases]; - - - // Test Class - class DateCalculatorUnitTests - { - public: - TEST_CLASS(DateCalculatorUnitTests); - - TEST_CLASS_SETUP(TestClassSetup) - { - /* Test Case Data */ - - // Dates - DD.MM.YYYY - /*31.12.9999*/ date[0].wYear = 9999; date[0].wMonth = 12; date[0].wDayOfWeek = 5; date[0].wDay = 31; date[0].wHour = 0; date[0].wMinute = 0; date[0].wSecond = 0; date[0].wMilliseconds = 0; - /*30.12.9999*/ date[1].wYear = 9999; date[1].wMonth = 12; date[1].wDayOfWeek = 4; date[1].wDay = 30; date[1].wHour = 0; date[1].wMinute = 0; date[1].wSecond = 0; date[1].wMilliseconds = 0; - /*31.12.9998*/ date[2].wYear = 9998; date[2].wMonth = 12; date[2].wDayOfWeek = 4; date[2].wDay = 31; date[2].wHour = 0; date[2].wMinute = 0; date[2].wSecond = 0; date[2].wMilliseconds = 0; - /*01.01.1601*/ date[3].wYear = 1601; date[3].wMonth = 1; date[3].wDayOfWeek = 1; date[3].wDay = 1; date[3].wHour = 0; date[3].wMinute = 0; date[3].wSecond = 0; date[3].wMilliseconds = 0; - /*02.01.1601*/ date[4].wYear = 1601; date[4].wMonth = 1; date[4].wDayOfWeek = 2; date[4].wDay = 2; date[4].wHour = 0; date[4].wMinute = 0; date[4].wSecond = 0; date[4].wMilliseconds = 0; - /*10.05.2008*/ date[5].wYear = 2008; date[5].wMonth = 5; date[5].wDayOfWeek = 6; date[5].wDay = 10; date[5].wHour = 0; date[5].wMinute = 0; date[5].wSecond = 0; date[5].wMilliseconds = 0; - /*10.03.2008*/ date[6].wYear = 2008; date[6].wMonth = 3; date[6].wDayOfWeek = 1; date[6].wDay = 10; date[6].wHour = 0; date[6].wMinute = 0; date[6].wSecond = 0; date[6].wMilliseconds = 0; - /*29.02.2008*/ date[7].wYear = 2008; date[7].wMonth = 2; date[7].wDayOfWeek = 5; date[7].wDay = 29; date[7].wHour = 0; date[7].wMinute = 0; date[7].wSecond = 0; date[7].wMilliseconds = 0; - /*28.02.2007*/ date[8].wYear = 2007; date[8].wMonth = 2; date[8].wDayOfWeek = 3; date[8].wDay = 28; date[8].wHour = 0; date[8].wMinute = 0; date[8].wSecond = 0; date[8].wMilliseconds = 0; - /*10.03.2007*/ date[9].wYear = 2007; date[9].wMonth = 3; date[9].wDayOfWeek = 6; date[9].wDay = 10; date[9].wHour = 0; date[9].wMinute = 0; date[9].wSecond = 0; date[9].wMilliseconds = 0; - /*10.05.2007*/ date[10].wYear = 2007; date[10].wMonth = 5; date[10].wDayOfWeek = 4; date[10].wDay = 10; date[10].wHour = 0; date[10].wMinute = 0; date[10].wSecond = 0; date[10].wMilliseconds = 0; - /*29.01.2008*/ date[11].wYear = 2008; date[11].wMonth = 1; date[11].wDayOfWeek = 2; date[11].wDay = 29; date[11].wHour = 0; date[11].wMinute = 0; date[11].wSecond = 0; date[11].wMilliseconds = 0; - /*28.01.2007*/ date[12].wYear = 2007; date[12].wMonth = 1; date[12].wDayOfWeek = 0; date[12].wDay = 28; date[12].wHour = 0; date[12].wMinute = 0; date[12].wSecond = 0; date[12].wMilliseconds = 0; - /*31.01.2008*/ date[13].wYear = 2008; date[13].wMonth = 1; date[13].wDayOfWeek = 4; date[13].wDay = 31; date[13].wHour = 0; date[13].wMinute = 0; date[13].wSecond = 0; date[13].wMilliseconds = 0; - /*31.03.2008*/ date[14].wYear = 2008; date[14].wMonth = 3; date[14].wDayOfWeek = 1; date[14].wDay = 31; date[14].wHour = 0; date[14].wMinute = 0; date[14].wSecond = 0; date[14].wMilliseconds = 0; - - // Date Differences - dateDifference[0].year = 1; dateDifference[0].month = 1; - dateDifference[1].month = 1; dateDifference[1].day = 10; - dateDifference[2].day = 2; - /*date[2]-[0]*/ dateDifference[3].week = 52; dateDifference[3].day = 1; - /*date[2]-[0]*/ dateDifference[4].year = 1; - dateDifference[5].day = 365; - dateDifference[6].month = 1; - dateDifference[7].month = 1; dateDifference[7].day = 2; - dateDifference[8].day = 31; - dateDifference[9].month = 11; dateDifference[9].day = 1; - dateDifference[10].year = 8398; dateDifference[10].month = 11; dateDifference[10].day = 30; - dateDifference[11].year = 2008; - dateDifference[12].year = 7991; dateDifference[12].month = 11; - dateDifference[13].week = 416998; dateDifference[13].day = 1; - - - - /* Test Cases */ - - // Date Difference test cases - datetimeDifftest[0].startDate = date[0]; datetimeDifftest[0].endDate = date[3]; datetimeDifftest[0].dateDiff = dateDifference[10]; - datetimeDifftest[1].startDate = date[0]; datetimeDifftest[1].endDate = date[2]; datetimeDifftest[1].dateDiff = dateDifference[5]; - datetimeDifftest[2].startDate = date[0]; datetimeDifftest[2].endDate = date[2]; datetimeDifftest[2].dateDiff = dateDifference[4]; - datetimeDifftest[3].startDate = date[0]; datetimeDifftest[3].endDate = date[2]; datetimeDifftest[3].dateDiff = dateDifference[3]; - datetimeDifftest[4].startDate = date[14]; datetimeDifftest[4].endDate = date[7]; datetimeDifftest[4].dateDiff = dateDifference[7]; - datetimeDifftest[5].startDate = date[14]; datetimeDifftest[5].endDate = date[7]; datetimeDifftest[5].dateDiff = dateDifference[8]; - datetimeDifftest[6].startDate = date[11]; datetimeDifftest[6].endDate = date[8]; datetimeDifftest[6].dateDiff = dateDifference[9]; - datetimeDifftest[7].startDate = date[13]; datetimeDifftest[7].endDate = date[0]; datetimeDifftest[7].dateDiff = dateDifference[12]; - datetimeDifftest[8].startDate = date[13]; datetimeDifftest[8].endDate = date[0]; datetimeDifftest[8].dateDiff = dateDifference[13]; - - // Date Add Out of Bound test cases (Negative tests) - /*OutofBound*/ datetimeBoundAdd[0].startDate = date[1]; datetimeBoundAdd[0].endDate = date[0]; datetimeBoundAdd[0].dateDiff = dateDifference[2]; // on Add date[0] not used - /*OutofBound*/ datetimeBoundAdd[1].startDate = date[2]; datetimeBoundAdd[1].endDate = date[0]; datetimeBoundAdd[1].dateDiff = dateDifference[11]; // on Add date[0] not used - - // Date Subtract Out of Bound test cases (Negative tests) - /*OutofBound*/ datetimeBoundSubtract[0].startDate = date[3]; datetimeBoundSubtract[0].endDate = date[0]; datetimeBoundSubtract[0].dateDiff = dateDifference[2]; // on subtract date[0] not used - /*OutofBound*/ datetimeBoundSubtract[1].startDate = date[14]; datetimeBoundSubtract[1].endDate = date[0]; datetimeBoundSubtract[1].dateDiff = dateDifference[11]; // on subtract date[0] not used - - // Date Add test cases (Positive tests) - datetimeAddCase[0].startDate = date[13]; datetimeAddCase[0].endDate = date[7]; datetimeAddCase[0].dateDiff = dateDifference[6];// add - datetimeAddCase[1].startDate = date[14]; datetimeAddCase[1].endDate = date[5]; datetimeAddCase[1].dateDiff = dateDifference[1];// add - datetimeAddCase[2].startDate = date[13]; datetimeAddCase[2].endDate = date[6]; datetimeAddCase[2].dateDiff = dateDifference[1];// add - - // Date Subtract test cases (Positive tests) - datetimeSubtractCase[0].startDate = date[14]; datetimeSubtractCase[0].endDate = date[7]; datetimeSubtractCase[0].dateDiff = dateDifference[6];// subtract - datetimeSubtractCase[1].startDate = date[6]; datetimeSubtractCase[1].endDate = date[11]; datetimeSubtractCase[1].dateDiff = dateDifference[1];// subtract - datetimeSubtractCase[2].startDate = date[9]; datetimeSubtractCase[2].endDate = date[12]; datetimeSubtractCase[2].dateDiff = dateDifference[1];// subtract - - return true; - } - - - /* Duration Between Two Date Tests -- Timediff obtained after calculation should be checked to be identical */ - TEST_METHOD(TestDateDiff) - { - // TODO - MSFT 10331900, fix this test - - //for (int testIndex = 0; testIndex < c_diffTestCase; testIndex++) - //{ - // DateDifference diff; - // DateUnit dateOutputFormat; - - // switch (testIndex) - // { - // case 0: - // case 2: - // dateOutputFormat = DateUnit::Year | DateUnit::Month | DateUnit::Day; - // break; - // case 1: - // dateOutputFormat = DateUnit::Day; - // break; - // case 3: - // case 8: - // dateOutputFormat = DateUnit::Week | DateUnit::Day; - // break; - // case 7: - // dateOutputFormat = DateUnit::Year | DateUnit::Month | DateUnit::Day; - // break; - // case 4: - // case 6: - // dateOutputFormat = DateUnit::Month | DateUnit::Day; - // break; - // case 5: - // dateOutputFormat = DateUnit::Day; - // break; - // } - - // // Calculate the difference - // m_DateCalcEngine.GetDateDifference(DateUtils::SystemTimeToDateTime(datetimeDifftest[testIndex].startDate), DateUtils::SystemTimeToDateTime(datetimeDifftest[testIndex].endDate), dateOutputFormat, &diff); - - // // Assert for the result - // bool areIdentical = true; - // if (diff.year != datetimeDifftest[testIndex].dateDiff.year || - // diff.month != datetimeDifftest[testIndex].dateDiff.month || - // diff.week != datetimeDifftest[testIndex].dateDiff.week || - // diff.day != datetimeDifftest[testIndex].dateDiff.day) - // { - // areIdentical = false; - // } - - // VERIFY_IS_TRUE(areIdentical); - //} - } - - /*Add Out of bound Tests*/ - TEST_METHOD(TestAddOob) - { - // TODO - MSFT 10331900, fix this test - - //for (int testIndex = 0; testIndex< c_numAddOobDate; testIndex++) - //{ - // DateTime endDate; - - // // Add Duration - // bool isValid = m_DateCalcEngine.AddDuration(DateUtils::SystemTimeToDateTime(datetimeBoundAdd[testIndex].startDate), datetimeBoundAdd[testIndex].dateDiff, &endDate); - - // // Assert for the result - // VERIFY_IS_FALSE(isValid); - //} - } - - /*Subtract Out of bound Tests*/ - TEST_METHOD(TestSubtractOob) - { - for (int testIndex = 0; testIndex< c_numSubtractOobDate; testIndex++) - { - DateTime endDate; - - // Subtract Duration - bool isValid = m_DateCalcEngine.SubtractDuration(DateUtils::SystemTimeToDateTime(datetimeBoundSubtract[testIndex].startDate), datetimeBoundSubtract[testIndex].dateDiff, &endDate); - - // Assert for the result - VERIFY_IS_FALSE(isValid); - } - } - - // Add Tests - TEST_METHOD(TestAddition) - { - // TODO - MSFT 10331900, fix this test - - //for (int testIndex = 0; testIndex < c_addCases; testIndex++) - //{ - // DateTime endDate; - - // // Add Duration - // bool isValid = m_DateCalcEngine.AddDuration(DateUtils::SystemTimeToDateTime(datetimeAddCase[testIndex].startDate), datetimeAddCase[testIndex].dateDiff, &endDate); - - // // Assert for the result - // VERIFY_IS_TRUE(isValid); - - // SYSTEMTIME systemTime = DateUtils::DateTimeToSystemTime(endDate); - // if (systemTime.wYear != datetimeAddCase[testIndex].endDate.wYear || - // systemTime.wMonth != datetimeAddCase[testIndex].endDate.wMonth || - // systemTime.wDay != datetimeAddCase[testIndex].endDate.wDay || - // systemTime.wDayOfWeek != datetimeAddCase[testIndex].endDate.wDayOfWeek) - // { - // isValid = false; - // } - - // VERIFY_IS_TRUE(isValid); - //} - } - - // Subtract Tests - TEST_METHOD(TestSubtraction) - { - // TODO - MSFT 10331900, fix this test - - //for (int testIndex = 0; testIndex < c_subtractCases; testIndex++) - //{ - // DateTime endDate; - - // // Subtract Duration - // bool isValid = m_DateCalcEngine.SubtractDuration(DateUtils::SystemTimeToDateTime(datetimeSubtractCase[testIndex].startDate), datetimeSubtractCase[testIndex].dateDiff, &endDate); - - // // assert for the result - // VERIFY_IS_TRUE(isValid); - - // SYSTEMTIME systemTime = DateUtils::DateTimeToSystemTime(endDate); - // if (systemTime.wYear != datetimeSubtractCase[testIndex].endDate.wYear || - // systemTime.wMonth != datetimeSubtractCase[testIndex].endDate.wMonth || - // systemTime.wDay != datetimeSubtractCase[testIndex].endDate.wDay || - // systemTime.wDayOfWeek != datetimeSubtractCase[testIndex].endDate.wDayOfWeek) - // { - // isValid = false; - // } - - // VERIFY_IS_TRUE(isValid); - //} - } - - private: - - }; - - class DateCalculatorViewModelTests - { - public: - TEST_CLASS(DateCalculatorViewModelTests); - - TEST_CLASS_SETUP(TestClassSetup) - { - /* Test Case Data */ - - // Dates - DD.MM.YYYY - /*31.12.9999*/ date[0].wYear = 9999; date[0].wMonth = 12; date[0].wDayOfWeek = 5; date[0].wDay = 31; date[0].wHour = 0; date[0].wMinute = 0; date[0].wSecond = 0; date[0].wMilliseconds = 0; - /*30.12.9999*/ date[1].wYear = 9999; date[1].wMonth = 12; date[1].wDayOfWeek = 4; date[1].wDay = 30; date[1].wHour = 0; date[1].wMinute = 0; date[1].wSecond = 0; date[1].wMilliseconds = 0; - /*31.12.9998*/ date[2].wYear = 9998; date[2].wMonth = 12; date[2].wDayOfWeek = 4; date[2].wDay = 31; date[2].wHour = 0; date[2].wMinute = 0; date[2].wSecond = 0; date[2].wMilliseconds = 0; - /*01.01.1601*/ date[3].wYear = 1601; date[3].wMonth = 1; date[3].wDayOfWeek = 1; date[3].wDay = 1; date[3].wHour = 0; date[3].wMinute = 0; date[3].wSecond = 0; date[3].wMilliseconds = 0; - /*02.01.1601*/ date[4].wYear = 1601; date[4].wMonth = 1; date[4].wDayOfWeek = 2; date[4].wDay = 2; date[4].wHour = 0; date[4].wMinute = 0; date[4].wSecond = 0; date[4].wMilliseconds = 0; - /*10.05.2008*/ date[5].wYear = 2008; date[5].wMonth = 5; date[5].wDayOfWeek = 6; date[5].wDay = 10; date[5].wHour = 0; date[5].wMinute = 0; date[5].wSecond = 0; date[5].wMilliseconds = 0; - /*10.03.2008*/ date[6].wYear = 2008; date[6].wMonth = 3; date[6].wDayOfWeek = 1; date[6].wDay = 10; date[6].wHour = 0; date[6].wMinute = 0; date[6].wSecond = 0; date[6].wMilliseconds = 0; - /*29.02.2008*/ date[7].wYear = 2008; date[7].wMonth = 2; date[7].wDayOfWeek = 5; date[7].wDay = 29; date[7].wHour = 0; date[7].wMinute = 0; date[7].wSecond = 0; date[7].wMilliseconds = 0; - /*28.02.2007*/ date[8].wYear = 2007; date[8].wMonth = 2; date[8].wDayOfWeek = 3; date[8].wDay = 28; date[8].wHour = 0; date[8].wMinute = 0; date[8].wSecond = 0; date[8].wMilliseconds = 0; - /*10.03.2007*/ date[9].wYear = 2007; date[9].wMonth = 3; date[9].wDayOfWeek = 6; date[9].wDay = 10; date[9].wHour = 0; date[9].wMinute = 0; date[9].wSecond = 0; date[9].wMilliseconds = 0; - /*10.05.2007*/ date[10].wYear = 2007; date[10].wMonth = 5; date[10].wDayOfWeek = 4; date[10].wDay = 10; date[10].wHour = 0; date[10].wMinute = 0; date[10].wSecond = 0; date[10].wMilliseconds = 0; - /*29.01.2008*/ date[11].wYear = 2008; date[11].wMonth = 1; date[11].wDayOfWeek = 2; date[11].wDay = 29; date[11].wHour = 0; date[11].wMinute = 0; date[11].wSecond = 0; date[11].wMilliseconds = 0; - /*28.01.2007*/ date[12].wYear = 2007; date[12].wMonth = 1; date[12].wDayOfWeek = 0; date[12].wDay = 28; date[12].wHour = 0; date[12].wMinute = 0; date[12].wSecond = 0; date[12].wMilliseconds = 0; - /*31.01.2008*/ date[13].wYear = 2008; date[13].wMonth = 1; date[13].wDayOfWeek = 4; date[13].wDay = 31; date[13].wHour = 0; date[13].wMinute = 0; date[13].wSecond = 0; date[13].wMilliseconds = 0; - /*31.03.2008*/ date[14].wYear = 2008; date[14].wMonth = 3; date[14].wDayOfWeek = 1; date[14].wDay = 31; date[14].wHour = 0; date[14].wMinute = 0; date[14].wSecond = 0; date[14].wMilliseconds = 0; - - // Date Differences - dateDifference[0].year = 1; dateDifference[0].month = 1; - dateDifference[1].month = 1; dateDifference[1].day = 10; - dateDifference[2].day = 2; - /*date[2]-[0]*/ dateDifference[3].week = 52; dateDifference[3].day = 1; - /*date[2]-[0]*/ dateDifference[4].year = 1; - dateDifference[5].day = 365; - dateDifference[6].month = 1; - dateDifference[7].month = 1; dateDifference[7].day = 2; - dateDifference[8].day = 31; - dateDifference[9].month = 11; dateDifference[9].day = 1; - dateDifference[10].year = 8398; dateDifference[10].month = 11; dateDifference[10].day = 30; - dateDifference[11].year = 2008; - dateDifference[12].year = 7991; dateDifference[12].month = 11; - dateDifference[13].week = 416998; dateDifference[13].day = 1; - - - - /* Test Cases */ - - // Date Difference test cases - datetimeDifftest[0].startDate = date[0]; datetimeDifftest[0].endDate = date[3]; datetimeDifftest[0].dateDiff = dateDifference[10]; - datetimeDifftest[1].startDate = date[0]; datetimeDifftest[1].endDate = date[2]; datetimeDifftest[1].dateDiff = dateDifference[5]; - datetimeDifftest[2].startDate = date[0]; datetimeDifftest[2].endDate = date[2]; datetimeDifftest[2].dateDiff = dateDifference[4]; - datetimeDifftest[3].startDate = date[0]; datetimeDifftest[3].endDate = date[2]; datetimeDifftest[3].dateDiff = dateDifference[3]; - datetimeDifftest[4].startDate = date[14]; datetimeDifftest[4].endDate = date[7]; datetimeDifftest[4].dateDiff = dateDifference[7]; - datetimeDifftest[5].startDate = date[14]; datetimeDifftest[5].endDate = date[7]; datetimeDifftest[5].dateDiff = dateDifference[8]; - datetimeDifftest[6].startDate = date[11]; datetimeDifftest[6].endDate = date[8]; datetimeDifftest[6].dateDiff = dateDifference[9]; - datetimeDifftest[7].startDate = date[13]; datetimeDifftest[7].endDate = date[0]; datetimeDifftest[7].dateDiff = dateDifference[12]; - datetimeDifftest[8].startDate = date[13]; datetimeDifftest[8].endDate = date[0]; datetimeDifftest[8].dateDiff = dateDifference[13]; - - // Date Add Out of Bound test cases (Negative tests) - /*OutofBound*/ datetimeBoundAdd[0].startDate = date[1]; datetimeBoundAdd[0].endDate = date[0]; datetimeBoundAdd[0].dateDiff = dateDifference[2]; // on Add date[0] not used - /*OutofBound*/ datetimeBoundAdd[1].startDate = date[2]; datetimeBoundAdd[1].endDate = date[0]; datetimeBoundAdd[1].dateDiff = dateDifference[11]; // on Add date[0] not used - - // Date Subtract Out of Bound test cases (Negative tests) - /*OutofBound*/ datetimeBoundSubtract[0].startDate = date[3]; datetimeBoundSubtract[0].endDate = date[0]; datetimeBoundSubtract[0].dateDiff = dateDifference[2]; // on subtract date[0] not used - /*OutofBound*/ datetimeBoundSubtract[1].startDate = date[14]; datetimeBoundSubtract[1].endDate = date[0]; datetimeBoundSubtract[1].dateDiff = dateDifference[11]; // on subtract date[0] not used - - // Date Add test cases (Positive tests) - datetimeAddCase[0].startDate = date[13]; datetimeAddCase[0].endDate = date[7]; datetimeAddCase[0].dateDiff = dateDifference[6];// add - datetimeAddCase[1].startDate = date[14]; datetimeAddCase[1].endDate = date[5]; datetimeAddCase[1].dateDiff = dateDifference[1];// add - datetimeAddCase[2].startDate = date[13]; datetimeAddCase[2].endDate = date[6]; datetimeAddCase[2].dateDiff = dateDifference[1];// add - - // Date Subtract test cases (Positive tests) - datetimeSubtractCase[0].startDate = date[14]; datetimeSubtractCase[0].endDate = date[7]; datetimeSubtractCase[0].dateDiff = dateDifference[6];// subtract - datetimeSubtractCase[1].startDate = date[6]; datetimeSubtractCase[1].endDate = date[11]; datetimeSubtractCase[1].dateDiff = dateDifference[1];// subtract - datetimeSubtractCase[2].startDate = date[9]; datetimeSubtractCase[2].endDate = date[12]; datetimeSubtractCase[2].dateDiff = dateDifference[1];// subtract - return true; - } - - TEST_METHOD(DateCalcViewModelInitializationTest) - { - auto viewModel = ref new DateCalculatorViewModel(); - - // Check for the initialized values - VERIFY_IS_TRUE(viewModel->IsDateDiffMode); - VERIFY_IS_TRUE(viewModel->IsAddMode); - - VERIFY_IS_TRUE(0 != viewModel->FromDate.UniversalTime); - VERIFY_IS_TRUE(0 != viewModel->ToDate.UniversalTime); - VERIFY_IS_TRUE(0 != viewModel->StartDate.UniversalTime); - - VERIFY_ARE_EQUAL(0, viewModel->DaysOffset); - VERIFY_ARE_EQUAL(0, viewModel->MonthsOffset); - VERIFY_ARE_EQUAL(0, viewModel->YearsOffset); - - VERIFY_IS_TRUE(viewModel->IsDiffInDays); - VERIFY_ARE_EQUAL(StringReference(L"Same dates"), viewModel->StrDateDiffResult); - VERIFY_IS_NULL(viewModel->StrDateDiffResultInDays); - - VERIFY_IS_NULL(viewModel->StrDateResult); - } - - TEST_METHOD(DateCalcViewModelAddSubtractInitTest) - { - auto viewModel = ref new DateCalculatorViewModel(); - viewModel->IsDateDiffMode = false; - - // Check for the initialized values - VERIFY_IS_FALSE(viewModel->IsDateDiffMode); - VERIFY_IS_TRUE(viewModel->IsAddMode); - - VERIFY_IS_TRUE(0 != viewModel->FromDate.UniversalTime); - VERIFY_IS_TRUE(0 != viewModel->ToDate.UniversalTime); - VERIFY_IS_TRUE(0 != viewModel->StartDate.UniversalTime); - - VERIFY_ARE_EQUAL(0, viewModel->DaysOffset); - VERIFY_ARE_EQUAL(0, viewModel->MonthsOffset); - VERIFY_ARE_EQUAL(0, viewModel->YearsOffset); - - VERIFY_IS_TRUE(viewModel->IsDiffInDays); - VERIFY_ARE_EQUAL(StringReference(L"Same dates"), viewModel->StrDateDiffResult); - VERIFY_IS_NULL(viewModel->StrDateDiffResultInDays); - - VERIFY_IS_NOT_NULL(viewModel->StrDateResult); - VERIFY_IS_TRUE(StringReference(L"") != viewModel->StrDateResult); - } - - TEST_METHOD(DateCalcViewModelAddTest) - { - // TODO - MSFT 10331900, fix this test - // A few issues to be investigated.. - // The date returned by DateUtils::GetLongDate can be a different string than expected - // based on the values of date[7]. This is because date[7] is in UTC but GetLongDate - // doesn't format according to UTC. If it did, the test would still be incorrect because - // the ViewModel is not necessarily in UTC. - // - // The DateTime value assigned to StartDate after the conversion SystemTimeToDateTime is not - // the same DateTime value as if the user were to select the same date from the CalendarDatePicker. - // This means testing a specific date here, is *not* the same as selecting that date in the app. - - //auto viewModel = ref new DateCalculatorViewModel(); - //viewModel->Initialize(); - - //viewModel->IsDateDiffMode = false; - //viewModel->IsAddMode = true; - //VERIFY_IS_FALSE(viewModel->IsDateDiffMode); - //VERIFY_IS_TRUE(viewModel->IsAddMode); - - //viewModel->StartDate = DateUtils::SystemTimeToDateTime(datetimeAddCase[0].startDate); - //viewModel->DaysOffset = datetimeAddCase[0].dateDiff.day; - //viewModel->MonthsOffset = datetimeAddCase[0].dateDiff.month; - //viewModel->YearsOffset = datetimeAddCase[0].dateDiff.year; - - //// Assert for the result - //VERIFY_ARE_EQUAL(DateUtils::GetLongDate(date[7]), viewModel->StrDateResult); - } - - TEST_METHOD(DateCalcViewModelSubtractTest) - { - // TODO - MSFT 10331900, fix this test - // A few issues to be investigated.. - // The date returned by DateUtils::GetLongDate can be a different string than expected - // based on the values of date[7]. This is because date[7] is in UTC but GetLongDate - // doesn't format according to UTC. If it did, the test would still be incorrect because - // the ViewModel is not necessarily in UTC. - // - // The DateTime value assigned to StartDate after the conversion SystemTimeToDateTime is not - // the same DateTime value as if the user were to select the same date from the CalendarDatePicker. - // This means testing a specific date here, is *not* the same as selecting that date in the app. - - //auto viewModel = ref new DateCalculatorViewModel(); - //viewModel->Initialize(); - - //viewModel->IsDateDiffMode = false; - //viewModel->IsAddMode = false; - //VERIFY_IS_FALSE(viewModel->IsDateDiffMode); - //VERIFY_IS_FALSE(viewModel->IsAddMode); - - //viewModel->StartDate = DateUtils::SystemTimeToDateTime(datetimeSubtractCase[0].startDate); - //viewModel->DaysOffset = datetimeSubtractCase[0].dateDiff.day; - //viewModel->MonthsOffset = datetimeSubtractCase[0].dateDiff.month; - //viewModel->YearsOffset = datetimeSubtractCase[0].dateDiff.year; - - //// Assert for the result - //VERIFY_ARE_EQUAL(DateUtils::GetLongDate(date[7]), viewModel->StrDateResult); - } - - TEST_METHOD(DateCalcViewModelAddOobTest) - { - // TODO - MSFT 10331900, fix this test - // Curiously enough, this test fails because it fails to go Oob. - // Possibly need to update test to use a new max date. - - //auto viewModel = ref new DateCalculatorViewModel(); - //viewModel->Initialize(); - - //viewModel->IsDateDiffMode = false; - //viewModel->IsAddMode = true; - //VERIFY_IS_FALSE(viewModel->IsDateDiffMode); - //VERIFY_IS_TRUE(viewModel->IsAddMode); - - //for (int testIndex = 0; testIndex< c_numAddOobDate; testIndex++) - //{ - // viewModel->StartDate = DateUtils::SystemTimeToDateTime(datetimeBoundAdd[testIndex].startDate); - // viewModel->DaysOffset = datetimeBoundAdd[testIndex].dateDiff.day; - // viewModel->MonthsOffset = datetimeBoundAdd[testIndex].dateDiff.month; - // viewModel->YearsOffset = datetimeBoundAdd[testIndex].dateDiff.year; - - // // Assert for the result - // VERIFY_ARE_EQUAL(StringReference(L"Date out of Bound"), viewModel->StrDateResult); - //} - } - - TEST_METHOD(DateCalcViewModelSubtractOobTest) - { - auto viewModel = ref new DateCalculatorViewModel(); - - viewModel->IsDateDiffMode = false; - viewModel->IsAddMode = false; - VERIFY_IS_FALSE(viewModel->IsDateDiffMode); - VERIFY_IS_FALSE(viewModel->IsAddMode); - - for (int testIndex = 0; testIndex < c_numSubtractOobDate; testIndex++) - { - viewModel->StartDate = DateUtils::SystemTimeToDateTime(datetimeBoundSubtract[testIndex].startDate); - viewModel->DaysOffset = datetimeBoundSubtract[testIndex].dateDiff.day; - viewModel->MonthsOffset = datetimeBoundSubtract[testIndex].dateDiff.month; - viewModel->YearsOffset = datetimeBoundSubtract[testIndex].dateDiff.year; - - // Assert for the result - VERIFY_ARE_EQUAL(StringReference(L"Date out of Bound"), viewModel->StrDateResult); - } - } - - TEST_METHOD(DateCalcViewModelDateDiffTest) - { - // TODO - MSFT 10331900, fix this test - // The last VERIFY checks with expected value "8398 years, 11 months, 4 weeks, 2 days" - // The viewmodel result is something like "8398 years, 12 months, 6568892 weeks, 1 day", - // which shows there is a problem with the viewmodel's reduction algorithm. - - //auto viewModel = ref new DateCalculatorViewModel(); - //viewModel->Initialize(); - - //viewModel->IsDateDiffMode = true; - //VERIFY_IS_TRUE(viewModel->IsDateDiffMode); - - //viewModel->FromDate = DateUtils::SystemTimeToDateTime(datetimeDifftest[0].startDate); - //viewModel->ToDate = DateUtils::SystemTimeToDateTime(datetimeDifftest[0].endDate); - - //// Assert for the result - //VERIFY_IS_FALSE(viewModel->IsDiffInDays); - //VERIFY_ARE_EQUAL(StringReference(L"3067670 days"), viewModel->StrDateDiffResultInDays); - //VERIFY_ARE_EQUAL(StringReference(L"8398 years, 11 months, 4 weeks, 2 days"), viewModel->StrDateDiffResult); - } - - TEST_METHOD(DateCalcViewModelDateDiffResultInDaysTest) - { - auto viewModel = ref new DateCalculatorViewModel(); - - viewModel->IsDateDiffMode = true; - VERIFY_IS_TRUE(viewModel->IsDateDiffMode); - - viewModel->FromDate = DateUtils::SystemTimeToDateTime(date[0]); - viewModel->ToDate = DateUtils::SystemTimeToDateTime(date[1]); - - // Assert for the result - VERIFY_IS_TRUE(viewModel->IsDiffInDays); - VERIFY_ARE_EQUAL(StringReference(L"1 day"), viewModel->StrDateDiffResult); - VERIFY_IS_NULL(viewModel->StrDateDiffResultInDays); - } - - // Tests that the automation name for the resulting date in Add Mode - // contains the DayOfWeek, Day, Month, and Year - TEST_METHOD(DateCalcViewModelAddSubtractResultAutomationNameTest) - { - auto viewModel = ref new DateCalculatorViewModel(); - - auto cal = ref new Calendar(); - cal->Year = 2007; - cal->Month = 5; - cal->Day = 10; - cal->Hour = 12; - cal->Period = 2; - cal->Nanosecond = 0; - cal->Second = 0; - - DateTime startDate = cal->GetDateTime(); - viewModel->StartDate = startDate; - - viewModel->IsDateDiffMode = false; - viewModel->IsAddMode = true; - - wstring actualValue = viewModel->StrDateResultAutomationName->Data(); - - // Verify each component is present in the result - wstring components[] = { - L"dayofweek.full", - L"month.full", - L"year.full", - L"day" - }; - - for (const wstring &component : components) - { - auto formatter = ref new DateTimeFormatter(ref new String(component.c_str())); - wstring expectedValue = formatter->Format(startDate)->Data(); - wstring message = L"Verifying " + component + L" is present in the result"; - VERIFY_IS_TRUE(actualValue.find(expectedValue) != wstring::npos, message.c_str()); - } - } - }; -} - diff --git a/internal/CalculatorUnitTests/DateUtils.h b/internal/CalculatorUnitTests/DateUtils.h deleted file mode 100644 index c2625bd..0000000 --- a/internal/CalculatorUnitTests/DateUtils.h +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#include "pch.h" - -namespace DateCalculationUnitTests -{ - /** Date Utils **/ - class DateUtils - { - public: - // Converts SYSTEMTIME structure to DateTime value - // Converts: SYSTEMTIME -> FILETIME -> DateTime - static Windows::Foundation::DateTime SystemTimeToDateTime(SYSTEMTIME systemTime) - { - LPFILETIME lpFileTime = new FILETIME(); - SystemTimeToFileTime(&systemTime, lpFileTime); - - Windows::Foundation::DateTime dateTime; - dateTime.UniversalTime = (DWORD)lpFileTime->dwHighDateTime; - dateTime.UniversalTime <<= 32; - dateTime.UniversalTime |= (DWORD)lpFileTime->dwLowDateTime; - - return dateTime; - } - - // Converts DateTime value to SYSTEMTIME structure - // Converts: DateTime -> FILETIME -> SYSTEMTIME - static SYSTEMTIME DateTimeToSystemTime(Windows::Foundation::DateTime dateTime) - { - FILETIME fileTime; - fileTime.dwLowDateTime = (DWORD)(dateTime.UniversalTime & 0xffffffff); - fileTime.dwHighDateTime = (DWORD)(dateTime.UniversalTime >> 32); - - SYSTEMTIME systemTime; - FileTimeToSystemTime(&fileTime, &systemTime); - - return systemTime; - } - - // Returns long date format for a date - static Platform::String^ GetLongDate(SYSTEMTIME systemTime) - { - auto formatter = ref new Windows::Globalization::DateTimeFormatting::DateTimeFormatter( - L"longdate", - Windows::Globalization::ApplicationLanguages::Languages, - Windows::System::UserProfile::GlobalizationPreferences::HomeGeographicRegion, - Windows::Globalization::CalendarIdentifiers::Gregorian, - Windows::Globalization::ClockIdentifiers::TwentyFourHour); - - Windows::Foundation::DateTime dateTime = SystemTimeToDateTime(systemTime); - return formatter->Format(dateTime); - } - }; -} - diff --git a/internal/CalculatorUnitTests/Helpers.h b/internal/CalculatorUnitTests/Helpers.h deleted file mode 100644 index c7df962..0000000 --- a/internal/CalculatorUnitTests/Helpers.h +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#include "pch.h" - -#pragma once -#include "CalcViewModel\Common\CalculatorButtonUser.h" - -namespace CalculatorUnitTests -{ - #define StandardModePrecision 16 - #define ScientificModePrecision 32 - #define ProgrammerModePrecision 64 - - typedef struct item - { - CalculatorApp::NumbersAndOperatorsEnum command; - std::wstring expectedPrimaryDisplay; - std::wstring expectedExpressions; - } TESTITEM; - - namespace UtfUtils { - constexpr wchar_t LRE = 0x202a; // Left-to-Right Embedding - constexpr wchar_t PDF = 0x202c; // Pop Directional Formatting - constexpr wchar_t LRO = 0x202d; // Left-to-Right Override - constexpr wchar_t MUL = 0x00d7; // Multiplication Symbol - } - - -} - diff --git a/internal/CalculatorUnitTests/HistoryTests.cpp b/internal/CalculatorUnitTests/HistoryTests.cpp deleted file mode 100644 index 53012fa..0000000 --- a/internal/CalculatorUnitTests/HistoryTests.cpp +++ /dev/null @@ -1,533 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#include "pch.h" -#include - -#include "CalcViewModel\HistoryViewModel.h" -#include "CalcViewModel\StandardCalculatorViewModel.h" - -using namespace CalculationManager; -using namespace CalculatorApp; -using namespace CalculatorApp::Common; -using namespace CalculatorApp::ViewModel; -using namespace CalculatorUnitTests; -using namespace Platform; -using namespace std; -using namespace Windows::Storage; -using namespace Windows::ApplicationModel::Resources; - -namespace CalculatorFunctionalTests -{ - class HistoryTests - { - public: - TEST_CLASS(HistoryTests); - TEST_METHOD(TestHistoryItemClicked); - TEST_METHOD(TestHistoryItemAddSingleItem); - TEST_METHOD(TestHistoryItemAddMaxItems); - TEST_METHOD(TestHistoryClearCommand); - TEST_METHOD(TestHistoryClearCommandWithEmptyHistory); - TEST_METHOD(TestReLoadHistory); - TEST_METHOD(TestSaveAndReloadHistory); - TEST_METHOD(TestSerializeDeSerializeHistoryItem); - TEST_METHOD(TestHistoryItemWithPrettyExpressions); - TEST_METHOD(TestHistoryItemWithPrettyExpressionsMixedRadix); - TEST_METHOD(TestHistoryItemLoadAndContinueCalculation); - TEST_METHOD(TestDisplayValueAutomationNames); - TEST_METHOD(TestRadixAutomationName); - TEST_METHOD(TestHistoryEmpty); - - private: - HistoryViewModel^ m_historyViewModel; - StandardCalculatorViewModel^ m_standardViewModel; - - void Initialize(unsigned int windowId = 0) - { - m_standardViewModel = ref new StandardCalculatorViewModel(); - m_standardViewModel->IsStandard = true; - m_historyViewModel = ref new HistoryViewModel(m_standardViewModel->m_standardCalculatorManager.get()); - m_historyViewModel->SetCalculatorDisplay(m_standardViewModel->m_calculatorDisplay); - } - - void Cleanup(unsigned int windowId = 0) - { - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::ModeBasic); - m_historyViewModel->OnClearCommand(nullptr); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::ModeScientific); - m_historyViewModel->OnClearCommand(nullptr); - m_standardViewModel->m_standardCalculatorManager->Reset(); - } - - bool IsHistoryContainerEmpty(_In_ String^ historyContainerKey) - { - ApplicationDataContainer^ localSettings = ApplicationData::Current->LocalSettings; - return !(localSettings->Containers->HasKey(historyContainerKey)); - } - - String^ GetHistoryContainerKeyHelper(CalculationManager::CALCULATOR_MODE cMode) - { - ValueType^ modeValue = static_cast(cMode); - return String::Concat(modeValue->ToString(), L"_History"); - } - - void MockOnHistoryItemClicked(CalculatorApp::ViewModel::HistoryItemViewModel^ e) - { - m_standardViewModel->SetHistoryExpressionDisplay(e->GetTokens(), e->GetCommands()); - m_standardViewModel->SetExpressionDisplay(e->GetTokens(), e->GetCommands()); - m_standardViewModel->SetPrimaryDisplay(e->Result->Data(), false/*IsError*/); - m_standardViewModel->IsFToEEnabled = false; - } - - void AddSingleHistoryItem(unsigned int windowId = 0) - { - Initialize(windowId); - int initialSize = m_historyViewModel->ItemSize; - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::Command1); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandADD); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::Command8); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandEQU); - int sizeAfterItemAdd = m_historyViewModel->ItemSize; - auto historyItem = m_standardViewModel->m_standardCalculatorManager->GetHistoryItem(0); - String^ expression = UtfUtils::LRO + L"1 + 8 =" + UtfUtils::PDF; - String ^result = StringReference(L"9"); - VERIFY_ARE_EQUAL(initialSize + 1, sizeAfterItemAdd); - VERIFY_ARE_EQUAL(expression, StringReference(historyItem->historyItemVector.expression.c_str())); - VERIFY_ARE_EQUAL(result, StringReference(historyItem->historyItemVector.result.c_str())); - Cleanup(windowId); - } - - void AddMaxHistoryItems(unsigned int windowId = 0) - { - Initialize(windowId); - int initialSize = m_historyViewModel->ItemSize; - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::Command1); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandADD); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::Command1); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandEQU); - for (int i = 1; i < m_standardViewModel->m_standardCalculatorManager->MaxHistorySize(); i++) - { - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::Command1); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandADD); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::Command2); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandEQU); - } - VERIFY_ARE_EQUAL(m_historyViewModel->ItemSize, m_standardViewModel->m_standardCalculatorManager->MaxHistorySize()); - String ^expression = UtfUtils::LRO + L"1 + 1 =" + UtfUtils::PDF; - int output = 2; - String ^result = output.ToString(); - auto historyItem = m_standardViewModel->m_standardCalculatorManager->GetHistoryItem(0); - VERIFY_ARE_EQUAL(expression, StringReference(historyItem->historyItemVector.expression.c_str())); - VERIFY_ARE_EQUAL(result, StringReference(historyItem->historyItemVector.result.c_str())); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::Command1); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandADD); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::Command5); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandEQU); - VERIFY_ARE_EQUAL(m_historyViewModel->ItemSize, m_standardViewModel->m_standardCalculatorManager->MaxHistorySize()); - expression = UtfUtils::LRO + L"1 + 2 =" + UtfUtils::PDF; - output = 3; - result = output.ToString(); - historyItem = m_standardViewModel->m_standardCalculatorManager->GetHistoryItem(0); - VERIFY_ARE_EQUAL(expression, StringReference(historyItem->historyItemVector.expression.c_str())); - VERIFY_ARE_EQUAL(result, StringReference(historyItem->historyItemVector.result.c_str())); - Cleanup(windowId); - } - - void ReloadHistory(unsigned int windowId = 0) - { - Initialize(windowId); - - m_standardViewModel->m_standardCalculatorManager->Reset(); - int scientificItems = 5; - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::ModeScientific); - for (int i = 0; i < scientificItems; i++) - { - Command nextCommand = Command(130 + i); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::Command1); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandADD); - m_standardViewModel->m_standardCalculatorManager->SendCommand(nextCommand); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandEQU); - } - - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::ModeBasic); - int standardItems = 2; - for (int i = 0; i < standardItems; i++) - { - Command nextCommand = Command(130 + i); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::Command1); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandADD); - m_standardViewModel->m_standardCalculatorManager->SendCommand(nextCommand); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandEQU); - } - - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::ModeScientific); - m_historyViewModel->ReloadHistory(ViewMode::Scientific); - VERIFY_ARE_EQUAL(scientificItems, m_historyViewModel->ItemSize); - for (int i = 0; i < scientificItems; i++) - { - wstring expr = L"1 + " + wstring(i.ToString()->Data()) + L" ="; - expr = UtfUtils::LRO + expr + UtfUtils::PDF; - int output = 1 + i; - String ^result = output.ToString(); - auto historyItem = m_standardViewModel->m_standardCalculatorManager->GetHistoryItem(i); - VERIFY_ARE_EQUAL(expr, historyItem->historyItemVector.expression); - VERIFY_ARE_EQUAL(result, StringReference(historyItem->historyItemVector.result.c_str())); - } - - m_historyViewModel->ReloadHistory(ViewMode::Standard); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::ModeBasic); - VERIFY_ARE_EQUAL(standardItems, m_historyViewModel->ItemSize); - for (int i = 0; i < standardItems; i++) - { - wstring expr = L"1 + " + wstring(i.ToString()->Data()) + L" ="; - expr = UtfUtils::LRO + expr + UtfUtils::PDF; - int output = 1 + i; - String ^result = output.ToString(); - auto historyItem = m_standardViewModel->m_standardCalculatorManager->GetHistoryItem(i); - VERIFY_ARE_EQUAL(expr, historyItem->historyItemVector.expression); - VERIFY_ARE_EQUAL(result, StringReference(historyItem->historyItemVector.result.c_str())); - } - Cleanup(windowId); - } - - void ClearHistory(unsigned int windowId = 0) - { - Initialize(windowId); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::ModeScientific); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::Command1); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandADD); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::Command2); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandEQU); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::ModeBasic); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::Command1); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandADD); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::Command2); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandEQU); - m_historyViewModel->OnClearCommand(nullptr); - VERIFY_ARE_EQUAL(0, m_historyViewModel->ItemSize); - VERIFY_IS_TRUE(IsHistoryContainerEmpty(GetHistoryContainerKeyHelper(CM_STD))); - VERIFY_IS_TRUE(IsHistoryContainerEmpty(GetHistoryContainerKeyHelper(CM_SCI))); - Cleanup(windowId); - } - - void SerializeDeSerializeHistoryItem(unsigned int windowId = 0) - { - Initialize(windowId); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::ModeScientific); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::Command1); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandADD); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::Command2); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandEQU); - auto itemBeforeSerializeDeserialize = m_standardViewModel->m_standardCalculatorManager->GetHistoryItem(0); - m_historyViewModel->SaveHistory(); - m_historyViewModel->ReloadHistory(ViewMode::Scientific); - auto itemAfterSerializeDeserialize = m_standardViewModel->m_standardCalculatorManager->GetHistoryItem(0); - VERIFY_IS_TRUE((itemBeforeSerializeDeserialize->historyItemVector.expression == itemAfterSerializeDeserialize->historyItemVector.expression) && (itemBeforeSerializeDeserialize->historyItemVector.result == itemAfterSerializeDeserialize->historyItemVector.result) && (itemBeforeSerializeDeserialize->historyItemVector.spCommands == itemAfterSerializeDeserialize->historyItemVector.spCommands) && (itemBeforeSerializeDeserialize->historyItemVector.spTokens == itemAfterSerializeDeserialize->historyItemVector.spTokens)); - Cleanup(windowId); - } - - void SaveAndReloadHistory(unsigned int windowid = 0) - { - Initialize(windowid); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::ModeScientific); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::Command1); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandADD); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::Command8); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandEQU); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::Command1); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandADD); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::Command2); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandEQU); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::ModeBasic); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::Command1); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandADD); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::Command6); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandEQU); - int itemsBeforeSaveAndReload = m_historyViewModel->ItemSize; - m_historyViewModel->SaveHistory(); - m_historyViewModel->ReloadHistory(ViewMode::Scientific); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::ModeScientific); - wstring expr = L"1 + 8 ="; - // add double quotes around the expression - expr = UtfUtils::LRO + expr + UtfUtils::PDF; - String ^result = StringReference(L"9"); - int itemsAfterSaveAndReload = m_historyViewModel->ItemSize; - auto historyItem = m_standardViewModel->m_standardCalculatorManager->GetHistoryItem(0); - - VERIFY_ARE_EQUAL(expr, historyItem->historyItemVector.expression); - VERIFY_ARE_EQUAL(result, StringReference(historyItem->historyItemVector.result.c_str())); - VERIFY_ARE_NOT_EQUAL(itemsBeforeSaveAndReload, itemsAfterSaveAndReload); - VERIFY_ARE_EQUAL(itemsBeforeSaveAndReload, itemsAfterSaveAndReload + 1); - Cleanup(windowid); - } - - void HistoryItemWithPrettyExpressions(unsigned int windowId = 0) - { - Initialize(windowId); - Command commands[] = { Command::CommandSIN, Command::CommandCOS, Command::CommandTAN, Command::CommandASIN, Command::CommandACOS, Command::CommandATAN }; - Command mode[] = { Command::CommandDEG, Command::CommandRAD, Command::CommandGRAD }; - int modes = sizeof(mode) / sizeof(Command); - int commandsSize = sizeof(commands) / sizeof(Command); - ResourceLoader^ m_uiResourceLoader = ResourceLoader::GetForViewIndependentUse(L"CEngineStrings"); - int itemIndex = 0; - int commandResource = 67; - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::ModeScientific); - for (int index = 0; index < modes; index++) - { - m_standardViewModel->m_standardCalculatorManager->SendCommand(mode[index]); - for (int command = 0; command < commandsSize; command++) - { - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::Command1); - m_standardViewModel->m_standardCalculatorManager->SendCommand(commands[command]); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandEQU); - auto historyItem = m_standardViewModel->m_standardCalculatorManager->GetHistoryItem(itemIndex); - String^ expression = m_uiResourceLoader->GetString(commandResource.ToString()); - expression += L"( 1 ) ="; - wstring expr = wstring(expression->Data()); - expr = UtfUtils::LRO + expr + UtfUtils::PDF; - VERIFY_ARE_EQUAL(historyItem->historyItemVector.expression, expr); - commandResource++; - itemIndex++; - } - } - Cleanup(windowId); - } - - void HistoryItemWithPrettyExpressionsMixedRadix(unsigned int windowId = 0) - { - Initialize(windowId); - ResourceLoader^ m_uiResourceLoader = ResourceLoader::GetForViewIndependentUse(L"CEngineStrings"); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::ModeScientific); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandDEG); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::Command1); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandSIN); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandADD); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandRAD); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::Command1); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandSIN); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandADD); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandGRAD); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::Command1); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandSIN); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandEQU); - auto historyItem = m_standardViewModel->m_standardCalculatorManager->GetHistoryItem(0); - String^ expression = m_uiResourceLoader->GetString(L"67"); - expression += L"( 1 ) + "; - expression += m_uiResourceLoader->GetString(L"73"); - expression += L"( 1 ) + "; - expression += m_uiResourceLoader->GetString(L"79"); - expression += L"( 1 ) ="; - wstring expr = wstring(expression->Data()); - expr = UtfUtils::LRO + expr + UtfUtils::PDF; - VERIFY_ARE_EQUAL(historyItem->historyItemVector.expression,expr); - - Cleanup(windowId); - } - - void HistoryItemClicked(unsigned int windowId = 0) - { - Initialize(windowId); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::ModeScientific); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::Command1); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandADD); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::Command5); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandADD); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::Command3); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandEQU); - auto historyItem = m_standardViewModel->m_standardCalculatorManager->GetHistoryItem(0); - String^ expression = StringReference(historyItem->historyItemVector.expression.c_str()); - String^ result = StringReference(historyItem->historyItemVector.result.c_str()); - HistoryItemViewModel ^ item = ref new HistoryItemViewModel(expression, result, historyItem->historyItemVector.spTokens, historyItem->historyItemVector.spCommands); - MockOnHistoryItemClicked(item); - VERIFY_ARE_EQUAL(StringReference(L"9"), m_standardViewModel->DisplayValue); - VERIFY_ARE_EQUAL(StringReference(L"1"), m_standardViewModel->ExpressionTokens->GetAt(0)->Token); - VERIFY_ARE_EQUAL(StringReference(L" "), m_standardViewModel->ExpressionTokens->GetAt(1)->Token); - VERIFY_ARE_EQUAL(StringReference(L"+"), m_standardViewModel->ExpressionTokens->GetAt(2)->Token); - VERIFY_ARE_EQUAL(StringReference(L" "), m_standardViewModel->ExpressionTokens->GetAt(3)->Token); - VERIFY_ARE_EQUAL(StringReference(L"5"), m_standardViewModel->ExpressionTokens->GetAt(4)->Token); - VERIFY_ARE_EQUAL(StringReference(L" "), m_standardViewModel->ExpressionTokens->GetAt(5)->Token); - VERIFY_ARE_EQUAL(StringReference(L"+"), m_standardViewModel->ExpressionTokens->GetAt(6)->Token); - VERIFY_ARE_EQUAL(StringReference(L" "), m_standardViewModel->ExpressionTokens->GetAt(7)->Token); - Cleanup(windowId); - } - - void HistoryItemLoadAndContinueCalculation(unsigned int windowId = 0) - { - Initialize(windowId); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::ModeBasic); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::Command1); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandADD); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::Command5); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandADD); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::Command3); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandEQU); - - auto historyItem = m_standardViewModel->m_standardCalculatorManager->GetHistoryItem(0); - String^ expression = StringReference(historyItem->historyItemVector.expression.c_str()); - String^ result = StringReference(historyItem->historyItemVector.result.c_str()); - HistoryItemViewModel ^ item = ref new HistoryItemViewModel(expression, result, historyItem->historyItemVector.spTokens, historyItem->historyItemVector.spCommands); - MockOnHistoryItemClicked(item); - - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandADD); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::Command5); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandEQU); - VERIFY_ARE_EQUAL(StringReference(L"14"), m_standardViewModel->DisplayValue); - historyItem = m_standardViewModel->m_standardCalculatorManager->GetHistoryItem(0); - expression = StringReference(historyItem->historyItemVector.expression.c_str()); - result = StringReference(historyItem->historyItemVector.result.c_str()); - item = ref new HistoryItemViewModel(expression, result, historyItem->historyItemVector.spTokens, historyItem->historyItemVector.spCommands); - MockOnHistoryItemClicked(item); - VERIFY_ARE_EQUAL(StringReference(L"9"), m_standardViewModel->DisplayValue); - - historyItem = m_standardViewModel->m_standardCalculatorManager->GetHistoryItem(1); - expression = StringReference(historyItem->historyItemVector.expression.c_str()); - result = StringReference(historyItem->historyItemVector.result.c_str()); - item = ref new HistoryItemViewModel(expression, result, historyItem->historyItemVector.spTokens, historyItem->historyItemVector.spCommands); - MockOnHistoryItemClicked(item); - VERIFY_ARE_EQUAL(StringReference(L"14"), m_standardViewModel->DisplayValue); - Cleanup(windowId); - } - - void DisplayValueAutomationNames(unsigned int windowId = 0) - { - Initialize(windowId); - - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::Command1); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandADD); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::Command8); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandEQU); - String ^expression = StringReference(L"Display is 9"); - VERIFY_ARE_EQUAL(expression, m_standardViewModel->CalculationResultAutomationName); - - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::ModeScientific); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::Command1); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandADD); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::Command5); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandEQU); - expression = StringReference(L"Display is 6"); - VERIFY_ARE_EQUAL(expression, m_standardViewModel->CalculationResultAutomationName); - - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::ModeProgrammer); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::Command1); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandADD); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::Command2); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandEQU); - expression = StringReference(L"Display is 3"); - VERIFY_ARE_EQUAL(expression, m_standardViewModel->CalculationResultAutomationName); - - Cleanup(windowId); - } - - void RadixAutomationName(unsigned int windowId = 0) - { - Initialize(windowId); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::ModeProgrammer); - m_standardViewModel->IsProgrammer = true; - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::Command1); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandADD); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::Command7); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::CommandEQU); - String ^expression = L"HexaDecimal" + L" 8"; - String ^result = L"HexaDecimal " + Utils::GetStringValue(m_standardViewModel->HexDisplayValue); - VERIFY_ARE_EQUAL(expression, result); - expression = StringReference(L"Octal 10"); - result = L"Octal " + Utils::GetStringValue(m_standardViewModel->OctalDisplayValue); - VERIFY_ARE_EQUAL(expression, result); - expression = StringReference(L"Binary 1000"); - result = L"Binary " + Utils::GetStringValue(m_standardViewModel->BinaryDisplayValue); - VERIFY_ARE_EQUAL(expression, result); - Cleanup(windowId); - } - - void HistoryEmpty(unsigned int windowId = 0) - { - Initialize(windowId); - VERIFY_ARE_EQUAL(0, m_historyViewModel->ItemSize); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::ModeScientific); - VERIFY_ARE_EQUAL(0, m_historyViewModel->ItemSize); - Cleanup(windowId); - } - - void HistoryClearCommandWithEmptyHistory(unsigned int windowId = 0) - { - Initialize(windowId); - VERIFY_ARE_EQUAL(0, m_historyViewModel->ItemSize); - m_standardViewModel->m_standardCalculatorManager->SendCommand(Command::ModeScientific); - m_historyViewModel->OnClearCommand(nullptr); - VERIFY_ARE_EQUAL(0, m_historyViewModel->ItemSize); - Cleanup(windowId); - - } - }; - - void HistoryTests::TestHistoryItemAddSingleItem() - { - AddSingleHistoryItem(); - } - - void HistoryTests::TestHistoryItemAddMaxItems() - { - AddMaxHistoryItems(); - } - - void HistoryTests::TestReLoadHistory() - { - ReloadHistory(); - } - - void HistoryTests::TestHistoryClearCommand() - { - ClearHistory(); - } - - void HistoryTests::TestSerializeDeSerializeHistoryItem() - { - SerializeDeSerializeHistoryItem(); - } - - void HistoryTests::TestSaveAndReloadHistory() - { - SaveAndReloadHistory(); - } - - void HistoryTests::TestHistoryItemWithPrettyExpressions() - { - HistoryItemWithPrettyExpressions(); - } - - void HistoryTests::TestHistoryItemWithPrettyExpressionsMixedRadix() - { - HistoryItemWithPrettyExpressionsMixedRadix(); - } - - void HistoryTests::TestHistoryItemClicked() - { - HistoryItemClicked(); - } - - void HistoryTests::TestHistoryItemLoadAndContinueCalculation() - { - HistoryItemLoadAndContinueCalculation(); - } - - void HistoryTests::TestDisplayValueAutomationNames() - { - DisplayValueAutomationNames(); - } - - void HistoryTests::TestRadixAutomationName() - { - RadixAutomationName(); - } - - void HistoryTests::TestHistoryEmpty() - { - HistoryEmpty(); - } - - void HistoryTests::TestHistoryClearCommandWithEmptyHistory() - { - HistoryClearCommandWithEmptyHistory(); - } -} - diff --git a/internal/CalculatorUnitTests/Mocks/CurrencyHttpClient.cpp b/internal/CalculatorUnitTests/Mocks/CurrencyHttpClient.cpp deleted file mode 100644 index 9eb5d06..0000000 --- a/internal/CalculatorUnitTests/Mocks/CurrencyHttpClient.cpp +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#pragma once - -#include "pch.h" -#include "CurrencyHttpClient.h" - -#include "CalcViewModel\Common\NetworkManager.h" - -using namespace CalculatorApp::DataLoaders; -using namespace Platform; -using namespace Windows::Foundation; -using namespace Windows::System::UserProfile; -using namespace Windows::Web::Http; - -// Generic responses so unit tests will pass. -static constexpr auto STATIC_DATA_RESPONSE = LR"([{"CountryCode":"USA","CountryName":"United States","CurrencyCode":"USD","CurrencyName":"Dollar","CurrencySymbol":"$"},{"CountryCode":"EUR","CountryName":"Europe","CurrencyCode":"EUR","CurrencyName":"Euro","CurrencySymbol":"€"}])"; -static constexpr auto ALL_RATIOS_RESPONSE = LR"([{"An":"USD","Ch":0,"Pc":0,"Rt":1},{"An":"EUR","Ch":0.003803,"Pc":0.4149,"Rt":0.920503,"Yh":0.9667,"Yl":0.86701}])"; - -CurrencyHttpClient::CurrencyHttpClient() -{ -} - -String^ CurrencyHttpClient::GetRawStaticDataResponse() -{ - return StringReference(STATIC_DATA_RESPONSE); -} - -String^ CurrencyHttpClient::GetRawAllRatiosDataResponse() -{ - return StringReference(ALL_RATIOS_RESPONSE); -} - -IAsyncOperationWithProgress^ CurrencyHttpClient::GetCurrencyMetadata() -{ - return ref new MockAsyncOperationWithProgress(StringReference(STATIC_DATA_RESPONSE)); -} - -IAsyncOperationWithProgress^ CurrencyHttpClient::GetCurrencyRatios() -{ - return ref new MockAsyncOperationWithProgress(StringReference(ALL_RATIOS_RESPONSE)); -} - -MockAsyncOperationWithProgress::MockAsyncOperationWithProgress(String^ result) : - m_result(result) -{ -} - -HResult MockAsyncOperationWithProgress::ErrorCode::get() -{ - HResult okayResult; - okayResult.Value = S_OK; - return okayResult; -} - diff --git a/internal/CalculatorUnitTests/Module.cpp b/internal/CalculatorUnitTests/Module.cpp deleted file mode 100644 index 3cb0d4c..0000000 --- a/internal/CalculatorUnitTests/Module.cpp +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#include "pch.h" -#include - -namespace CalculatorUnitTests -{ - BEGIN_MODULE() - MODULE_PROPERTY(L"APPX:CertificateFileName", L"CalculatorUnitTests.cer:TrustedPeople") - END_MODULE() - - MODULE_SETUP(ModuleSetup) - { - return true; - } - - MODULE_CLEANUP(ModuleCleanup) - { - return true; - } -} diff --git a/internal/CalculatorUnitTests/MultiWindowUnitTests.cpp b/internal/CalculatorUnitTests/MultiWindowUnitTests.cpp deleted file mode 100644 index 6b8887c..0000000 --- a/internal/CalculatorUnitTests/MultiWindowUnitTests.cpp +++ /dev/null @@ -1,1012 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#include "pch.h" -#include -#include "UnitConverterViewModelUnitTests.h" -#include "DateUtils.h" - -#include "CalcViewModel\StandardCalculatorViewModel.h" -#include "CalcViewModel\UnitConverterViewModel.h" -#include "CalcViewModel\DateCalculatorViewModel.h" -#include "CalcViewModel\DataLoaders\UnitConverterDataLoader.h" - -using namespace Platform; -using namespace Platform::Collections; -using namespace CalculatorApp; -using namespace CalculatorApp::Common; -using namespace CalculatorApp::ViewModel; -using namespace CalculationManager; -using namespace Windows::ApplicationModel::Resources; -using namespace Windows::Devices::Input; -using namespace Windows::Foundation::Collections; -using namespace Windows::Globalization; -using namespace Utils; -using namespace DateCalculationUnitTests; - -namespace CalculatorUnitTests -{ - extern void ChangeMode(StandardCalculatorViewModel^ viewModel, int mode); - extern void ValidateViewModelByCommands(StandardCalculatorViewModel^ viewModel, TESTITEM item[], bool doReset = false); - - // Validated the Mode set for a given instance of Standard Calculator View Model - void ValidateViewModelMode(StandardCalculatorViewModel^ viewModel, int mode) - { - // Standard - if (mode == 0) - { - VERIFY_IS_TRUE(viewModel->IsStandard); - VERIFY_IS_FALSE(viewModel->IsScientific); - VERIFY_IS_FALSE(viewModel->IsProgrammer); - } - // Scientific - else if (mode == 1) - { - VERIFY_IS_FALSE(viewModel->IsStandard); - VERIFY_IS_TRUE(viewModel->IsScientific); - VERIFY_IS_FALSE(viewModel->IsProgrammer); - } - // Programmer - else if (mode == 2) - { - VERIFY_IS_FALSE(viewModel->IsStandard); - VERIFY_IS_FALSE(viewModel->IsScientific); - VERIFY_IS_TRUE(viewModel->IsProgrammer); - } - } - - // Test class containing Test Methods to validate Multi Window - class MultiWindowUnitTests - { - public: - TEST_CLASS(MultiWindowUnitTests); - - // Create 3 instances of StandardCalculatorViewModel - TEST_METHOD(InitializeMultipleInstancesTest) - { - std::vector viewModels(3); - - // Create 3 instances of StandardCalculatorViewModel - for (int i = 0; i < 3; i++) - { - viewModels[i] = ref new StandardCalculatorViewModel(); - viewModels[i]->IsStandard = true; - } - - // Assert that the Display Value is "0" for all instances - for (int i = 0; i < 3; i++) - { - VERIFY_IS_TRUE("0" == viewModels[i]->DisplayValue); - } - } - - // Create 3 separate instances of Calulator in different modes - TEST_METHOD(InitializeMultipleModeInstancesTest) - { - std::vector viewModels(3); - - // Create 3 instances of StandardCalculatorViewModel in different modes - for (int i = 0; i < 3; i++) - { - viewModels[i] = ref new StandardCalculatorViewModel(); - - ChangeMode(viewModels[i], i); - } - - // Assert for the Modes and DisplayValues - for (int i = 0; i < 3; i++) - { - ValidateViewModelMode(viewModels[i], i); - - VERIFY_IS_TRUE("0" == viewModels[i]->DisplayValue); - } - } - - // Perform calculations on diferent calculator modes and verify that they work independently - TEST_METHOD(MultipleModesCalculationTest) - { - std::vector viewModels(3); - - // Create 3 instances of StandardCalculatorViewModel in different modes - for (int i = 0; i < 3; i++) - { - viewModels[i] = ref new StandardCalculatorViewModel(); - - ChangeMode(viewModels[i], i); - } - - // Perform Calculations on all instances and check that they work independently - - // Standard Mode: Expression 1+2= - TESTITEM standardModeTestItems[] = { - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Add, L"1", L"1 + " }, - { NumbersAndOperatorsEnum::Two, L"2", L"1 + " }, - { NumbersAndOperatorsEnum::Equals, L"3", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(viewModels[0], standardModeTestItems, true); - - // Scientific Mode: Expression 1+2*3 - TESTITEM scientificModeTestItems[] = { - { NumbersAndOperatorsEnum::IsScientificMode, L"0", L"" }, - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Add, L"1", L"1 + " }, - { NumbersAndOperatorsEnum::Two, L"2", L"1 + " }, - { NumbersAndOperatorsEnum::Multiply, L"2", L"1 + 2 * " }, - { NumbersAndOperatorsEnum::Three, L"3", L"1 + 2 * " }, - { NumbersAndOperatorsEnum::Equals, L"7", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(viewModels[1], scientificModeTestItems, true); - - // Programmer Mode: Expression F - TESTITEM programmerModeTestItems[] = { - { NumbersAndOperatorsEnum::HexButton, L"0", L"" }, - { NumbersAndOperatorsEnum::F, L"F", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(viewModels[2], programmerModeTestItems, false); - VERIFY_ARE_EQUAL(GetStringValue(viewModels[2]->HexDisplayValue), StringReference(L"F")); - VERIFY_ARE_EQUAL(GetStringValue(viewModels[2]->DecimalDisplayValue), StringReference(L"15")); - VERIFY_ARE_EQUAL(GetStringValue(viewModels[2]->OctalDisplayValue), StringReference(L"17")); - VERIFY_ARE_EQUAL(GetStringValue(viewModels[2]->BinaryDisplayValue), StringReference(L"1111")); - - // Assert that Standard and Scientific mode Display Values are unchanged - VERIFY_ARE_EQUAL(GetStringValue(viewModels[0]->DisplayValue), StringReference(L"3")); - VERIFY_ARE_EQUAL(GetStringValue(viewModels[1]->DisplayValue), StringReference(L"7")); - } - - // Perform calculations on 2 instances of Calculator in Standard Mode and verify that they work independently - TEST_METHOD(MultipleStandardModeCalculationTest) - { - // Create 2 instances of Standard Mode - StandardCalculatorViewModel^ standardViewModel1 = ref new StandardCalculatorViewModel(); - StandardCalculatorViewModel^ standardViewModel2 = ref new StandardCalculatorViewModel(); - - ChangeMode(standardViewModel1, 0); - ChangeMode(standardViewModel2, 0); - - ValidateViewModelMode(standardViewModel1, 0); - ValidateViewModelMode(standardViewModel2, 0); - - // Perform Calculations on the 2 instances and check that they work independently - - // Standard Mode 1: Expression 3-2= - TESTITEM standardModeTestItems1[] = { - { NumbersAndOperatorsEnum::Three, L"3", L"" }, - { NumbersAndOperatorsEnum::Subtract, L"3", L"3 - " }, - { NumbersAndOperatorsEnum::Two, L"2", L"3 - " }, - { NumbersAndOperatorsEnum::Equals, L"1", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(standardViewModel1, standardModeTestItems1, true); - - // Standard Mode 2: Expression 4*5= - TESTITEM standardModeTestItems2[] = { - { NumbersAndOperatorsEnum::Four, L"4", L"" }, - { NumbersAndOperatorsEnum::Multiply, L"4", L"4 * " }, - { NumbersAndOperatorsEnum::Five, L"5", L"4 * " }, - { NumbersAndOperatorsEnum::Equals, L"20", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(standardViewModel2, standardModeTestItems2, true); - - // Assert that the Display Value of 1st instance is unchanged - VERIFY_ARE_EQUAL(GetStringValue(standardViewModel1->DisplayValue), StringReference(L"1")); - } - - // Perform calculations on 2 instances of Calculator in Scientific Mode and verify that they work independently - TEST_METHOD(MultipleScientificModeCalculationTest) - { - // Create 2 instances of Standard Mode - StandardCalculatorViewModel^ scientificViewModel1 = ref new StandardCalculatorViewModel(); - StandardCalculatorViewModel^ scientificViewModel2 = ref new StandardCalculatorViewModel(); - - ChangeMode(scientificViewModel1, 1); - ChangeMode(scientificViewModel2, 1); - - ValidateViewModelMode(scientificViewModel1, 1); - ValidateViewModelMode(scientificViewModel2, 1); - - // Perform Calculations on the 2 instances and check that they work independently - - // Standard Mode 1: Expression 3-2= - TESTITEM scientificModeTestItems1[] = { - { NumbersAndOperatorsEnum::Three, L"3", L"" }, - { NumbersAndOperatorsEnum::Subtract, L"3", L"3 - " }, - { NumbersAndOperatorsEnum::Two, L"2", L"3 - " }, - { NumbersAndOperatorsEnum::Equals, L"1", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(scientificViewModel1, scientificModeTestItems1, true); - - // Standard Mode 2: Expression 4*5= - TESTITEM scientificModeTestItems2[] = { - { NumbersAndOperatorsEnum::Four, L"4", L"" }, - { NumbersAndOperatorsEnum::Multiply, L"4", L"4 * " }, - { NumbersAndOperatorsEnum::Five, L"5", L"4 * " }, - { NumbersAndOperatorsEnum::Equals, L"20", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(scientificViewModel2, scientificModeTestItems2, true); - - // Assert that the Display Value of 1st instance is unchanged - VERIFY_ARE_EQUAL(GetStringValue(scientificViewModel1->DisplayValue), StringReference(L"1")); - } - - // Perform calculations on 2 instances of Calculator in Scientific Mode - // (with different Angle types, HYP and F-E settings) and verify that they work independently - TEST_METHOD(MultipleScientificModeWithDifferentSettingsTest) - { - // Create 2 instances of Standard Mode - StandardCalculatorViewModel^ scientificViewModel1 = ref new StandardCalculatorViewModel(); - StandardCalculatorViewModel^ scientificViewModel2 = ref new StandardCalculatorViewModel(); - - ChangeMode(scientificViewModel1, 1); - ChangeMode(scientificViewModel2, 1); - - ValidateViewModelMode(scientificViewModel1, 1); - ValidateViewModelMode(scientificViewModel2, 1); - - // Perform Calculations on the 2 instances and check that they work independently - - // Scientific Mode 1: Degrees with HYP checked - TESTITEM scientificModeInitializeItems1[] = { - { NumbersAndOperatorsEnum::Degree, L"0", L"" }, - { NumbersAndOperatorsEnum::Hyp, L"0", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(scientificViewModel1, scientificModeInitializeItems1, true); - - // Scientific Mode 2: Radians with F-E checked - TESTITEM scientificModeInitializeItems2[] = { - { NumbersAndOperatorsEnum::Radians, L"0", L"" }, - { NumbersAndOperatorsEnum::FToE, L"0.e+0", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(scientificViewModel2, scientificModeInitializeItems2, true); - - // Scientific Mode 1: Expression CosH(0 degrees) - TESTITEM scientificModeTestItems1[] = { - { NumbersAndOperatorsEnum::Zero, L"0", L"" }, - { NumbersAndOperatorsEnum::Cosh, L"1", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(scientificViewModel1, scientificModeTestItems1, true); - - // Scientific Mode 2: Expression Cos(pi radians) - TESTITEM scientificModeTestItems2[] = { - { NumbersAndOperatorsEnum::Pi, L"3.1415926535897932384626433832795e+0", L"" }, - { NumbersAndOperatorsEnum::Cos, L"-1.e+0", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(scientificViewModel2, scientificModeTestItems2, true); - } - - // Perform calculations on 2 instances of Calculator in Programmer Mode and verify that they work independently - TEST_METHOD(MultipleProgrammerModeCalculationTest) - { - // Create 2 instances of Standard Mode - StandardCalculatorViewModel^ programmerViewModel1 = ref new StandardCalculatorViewModel(); - StandardCalculatorViewModel^ programmerViewModel2 = ref new StandardCalculatorViewModel(); - - ChangeMode(programmerViewModel1, 2); - ChangeMode(programmerViewModel2, 2); - - ValidateViewModelMode(programmerViewModel1, 2); - ValidateViewModelMode(programmerViewModel2, 2); - - // Perform Calculations on the 2 instances and check that they work independently - - // Radix Type: Hexadecimal, Expression: F - TESTITEM programmerModeTestItems1[] = { - { NumbersAndOperatorsEnum::HexButton, L"0", L"" }, - { NumbersAndOperatorsEnum::F, L"F", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - - ValidateViewModelByCommands(programmerViewModel1, programmerModeTestItems1, false); - VERIFY_ARE_EQUAL(GetStringValue(programmerViewModel1->HexDisplayValue), StringReference(L"F")); - VERIFY_ARE_EQUAL(GetStringValue(programmerViewModel1->DecimalDisplayValue), StringReference(L"15")); - VERIFY_ARE_EQUAL(GetStringValue(programmerViewModel1->OctalDisplayValue), StringReference(L"17")); - VERIFY_ARE_EQUAL(GetStringValue(programmerViewModel1->BinaryDisplayValue), StringReference(L"1111")); - - // Radix Type: Octal, Expression: 7 - TESTITEM programmerModeTestItems2[] = { - { NumbersAndOperatorsEnum::OctButton, L"0", L"" }, - { NumbersAndOperatorsEnum::Seven, L"7", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - - ValidateViewModelByCommands(programmerViewModel2, programmerModeTestItems2, false); - VERIFY_ARE_EQUAL(GetStringValue(programmerViewModel2->HexDisplayValue), StringReference(L"7")); - VERIFY_ARE_EQUAL(GetStringValue(programmerViewModel2->DecimalDisplayValue), StringReference(L"7")); - VERIFY_ARE_EQUAL(GetStringValue(programmerViewModel2->OctalDisplayValue), StringReference(L"7")); - VERIFY_ARE_EQUAL(GetStringValue(programmerViewModel2->BinaryDisplayValue), StringReference(L"0111")); - - // Assert that displayed values of 1st instance are unchanged - VERIFY_ARE_EQUAL(GetStringValue(programmerViewModel1->DisplayValue), StringReference(L"F")); - VERIFY_ARE_EQUAL(GetStringValue(programmerViewModel1->HexDisplayValue), StringReference(L"F")); - VERIFY_ARE_EQUAL(GetStringValue(programmerViewModel1->DecimalDisplayValue), StringReference(L"15")); - VERIFY_ARE_EQUAL(GetStringValue(programmerViewModel1->OctalDisplayValue), StringReference(L"17")); - VERIFY_ARE_EQUAL(GetStringValue(programmerViewModel1->BinaryDisplayValue), StringReference(L"1111")); - } - - // Perform calculations on 2 instances of Calculator in Programmer Mode - // (with different Bit lengths and Radix types) and verify that they work independently - TEST_METHOD(MultipleProgrammerModeWithDifferentSettingsTest) - { - // Create 2 instances of Standard Mode - StandardCalculatorViewModel^ programmerViewModel1 = ref new StandardCalculatorViewModel(); - StandardCalculatorViewModel^ programmerViewModel2 = ref new StandardCalculatorViewModel(); - - ChangeMode(programmerViewModel1, 2); - ChangeMode(programmerViewModel2, 2); - - ValidateViewModelMode(programmerViewModel1, 2); - ValidateViewModelMode(programmerViewModel2, 2); - - // Perform Calculations on the 2 instances and check that they work independently - - // Bit length: Byte & Radix Type: Hex - TESTITEM programmerModeInitializeItems1[] = { - { NumbersAndOperatorsEnum::Byte, L"0", L"" }, - { NumbersAndOperatorsEnum::HexButton, L"0", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - - ValidateViewModelByCommands(programmerViewModel1, programmerModeInitializeItems1, false); - - // Bit Length: Word & Radix Type: Oct - TESTITEM programmerModeInitializeItems2[] = { - { NumbersAndOperatorsEnum::Word, L"0", L"" }, - { NumbersAndOperatorsEnum::OctButton, L"0", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - - ValidateViewModelByCommands(programmerViewModel2, programmerModeInitializeItems2, false); - - TESTITEM programmerModeTestItems1[] = { - { NumbersAndOperatorsEnum::F, L"F", L"" }, - { NumbersAndOperatorsEnum::F, L"FF", L"" }, - // One more F shouldn't have any effect, testing for precision - { NumbersAndOperatorsEnum::F, L"FF", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - - ValidateViewModelByCommands(programmerViewModel1, programmerModeTestItems1, false); - VERIFY_ARE_EQUAL(GetStringValue(programmerViewModel1->HexDisplayValue), StringReference(L"FF")); - VERIFY_ARE_EQUAL(GetStringValue(programmerViewModel1->DecimalDisplayValue), StringReference(L"-1")); - VERIFY_ARE_EQUAL(GetStringValue(programmerViewModel1->OctalDisplayValue), StringReference(L"377")); - VERIFY_ARE_EQUAL(GetStringValue(programmerViewModel1->BinaryDisplayValue), StringReference(L"1111 1111")); - - TESTITEM programmerModeTestItems2[] = { - { NumbersAndOperatorsEnum::Seven, L"7", L"" }, - { NumbersAndOperatorsEnum::Seven, L"77", L"" }, - { NumbersAndOperatorsEnum::Seven, L"777", L"" }, - { NumbersAndOperatorsEnum::Seven, L"7 777", L"" }, - { NumbersAndOperatorsEnum::Seven, L"77 777", L"" }, - // One more '7' shouldn't have any effect, testing for precision - { NumbersAndOperatorsEnum::Seven, L"77 777", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - - ValidateViewModelByCommands(programmerViewModel2, programmerModeTestItems2, false); - VERIFY_ARE_EQUAL(GetStringValue(programmerViewModel2->HexDisplayValue), StringReference(L"7FFF")); - VERIFY_ARE_EQUAL(GetStringValue(programmerViewModel2->DecimalDisplayValue), StringReference(L"32,767")); - VERIFY_ARE_EQUAL(GetStringValue(programmerViewModel2->OctalDisplayValue), StringReference(L"77 777")); - VERIFY_ARE_EQUAL(GetStringValue(programmerViewModel2->BinaryDisplayValue), StringReference(L"0111 1111 1111 1111")); - } - - // Perform calculations on 2 separate instances of Calculator and verify that their History list items are maintained separately - TEST_METHOD(MultipleModesHistoryAddItemTest) - { - std::vector viewModels(2); - - // Create 3 instances of StandardCalculatorViewModel in Standard and Scientific mode - for (int i = 0; i < 2; i++) - { - viewModels[i] = ref new StandardCalculatorViewModel(); - - ChangeMode(viewModels[i], i); - - // Validate that the history items list is initially empty - VERIFY_IS_TRUE(0 == viewModels[i]->m_standardCalculatorManager->GetHistoryItems().size()); - } - - // Perform Calculations on both the instances and check that the History items work independently - - // Standard Mode: Expression 1+2= - TESTITEM standardModeTestItems[] = { - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Add, L"1", L"1 + " }, - { NumbersAndOperatorsEnum::Two, L"2", L"1 + " }, - { NumbersAndOperatorsEnum::Equals, L"3", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(viewModels[0], standardModeTestItems, true); - - // Scientific Mode: Expression 1+2*3 - TESTITEM scientificModeTestItems[] = { - { NumbersAndOperatorsEnum::IsScientificMode, L"0", L"" }, - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Add, L"1", L"1 + " }, - { NumbersAndOperatorsEnum::Two, L"2", L"1 + " }, - { NumbersAndOperatorsEnum::Multiply, L"2", L"1 + 2 * " }, - { NumbersAndOperatorsEnum::Three, L"3", L"1 + 2 * " }, - { NumbersAndOperatorsEnum::Equals, L"7", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(viewModels[1], scientificModeTestItems, true); - - // Assert for the history list items of 1st instance - VERIFY_IS_TRUE(1 == viewModels[0]->m_standardCalculatorManager->GetHistoryItems().size()); - - auto item1 = viewModels[0]->m_standardCalculatorManager->GetHistoryItem(0); - String ^expression1 = UtfUtils::LRO + L"1 + 2 =" + UtfUtils::PDF; - String^ result1 = L"3"; - - VERIFY_ARE_EQUAL(expression1, StringReference(item1->historyItemVector.expression.c_str())); - VERIFY_ARE_EQUAL(result1, StringReference(item1->historyItemVector.result.c_str())); - - // Assert for the history list items of 2nd instance - VERIFY_IS_TRUE(1 == viewModels[1]->m_standardCalculatorManager->GetHistoryItems().size()); - - auto item2 = viewModels[1]->m_standardCalculatorManager->GetHistoryItem(0); - String^ expression2 = UtfUtils::LRO + L"1 + 2 " + UtfUtils::MUL + L" 3 =" + UtfUtils::PDF; - String^ result2 = L"7"; - - VERIFY_ARE_EQUAL(expression2, StringReference(item2->historyItemVector.expression.c_str())); - VERIFY_ARE_EQUAL(result2, StringReference(item2->historyItemVector.result.c_str())); - } - - // Perform calculations on 2 separate instances of Standard Modes and verify that their History list items are maintained separately - TEST_METHOD(MultipleStandardModesHistoryAddItemTest) - { - std::vector viewModels(2); - - // Create 3 instances of StandardCalculatorViewModel in Standard and Scientific mode - for (int i = 0; i < 2; i++) - { - viewModels[i] = ref new StandardCalculatorViewModel(); - - // Standard Mode - ChangeMode(viewModels[i], 0); - - // Validate that the history items list is initially empty - VERIFY_IS_TRUE(0 == viewModels[i]->m_standardCalculatorManager->GetHistoryItems().size()); - } - - // Perform Calculations on both the instances and check that the History items work independently - - // Standard Mode: Expression 1+2= - TESTITEM standardModeTestItems[2][8] = { - { - { NumbersAndOperatorsEnum::IsScientificMode, L"0", L"" }, - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Add, L"1", L"1 + " }, - { NumbersAndOperatorsEnum::Two, L"2", L"1 + " }, - { NumbersAndOperatorsEnum::Equals, L"3", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }, - { - { NumbersAndOperatorsEnum::IsScientificMode, L"0", L"" }, - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Add, L"1", L"1 + " }, - { NumbersAndOperatorsEnum::Two, L"2", L"1 + " }, - { NumbersAndOperatorsEnum::Multiply, L"2", L"1 + 2 * " }, - { NumbersAndOperatorsEnum::Three, L"3", L"1 + 2 * " }, - { NumbersAndOperatorsEnum::Equals, L"7", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - } - }; - - // Run the commands - for (int i = 0; i < 2; i++) - { - ValidateViewModelByCommands(viewModels[i], standardModeTestItems[i], true); - } - - String^ expression[] = { UtfUtils::LRO + L"1 + 2 =" + UtfUtils::PDF, UtfUtils::LRO + L"1 + 2 " + UtfUtils::MUL + L" 3 =" + UtfUtils::PDF }; - String^ result[] = { L"3", L"7" }; - - // Assert for the history list items of the instances - for (int i = 0; i < 2; i++) - { - VERIFY_IS_TRUE(1 == viewModels[i]->m_standardCalculatorManager->GetHistoryItems().size()); - - auto item = viewModels[i]->m_standardCalculatorManager->GetHistoryItem(0); - - VERIFY_ARE_EQUAL(expression[i], StringReference(item->historyItemVector.expression.c_str())); - VERIFY_ARE_EQUAL(result[i], StringReference(item->historyItemVector.result.c_str())); - } - } - - // Perform calculations on 2 separate instances of Scientific Modes and verify that their History list items are maintained separately - TEST_METHOD(MultipleScientificModesHistoryAddItemTest) - { - std::vector viewModels(2); - - // Create 3 instances of StandardCalculatorViewModel in Standard and Scientific mode - for (int i = 0; i < 2; i++) - { - viewModels[i] = ref new StandardCalculatorViewModel(); - - // Scientific Mode - ChangeMode(viewModels[i], 1); - - // Validate that the history items list is initially empty - VERIFY_IS_TRUE(0 == viewModels[i]->m_standardCalculatorManager->GetHistoryItems().size()); - } - - // Perform Calculations on both the instances and check that the History items work independently - - // Standard Mode: Expression 1+2= - TESTITEM standardModeTestItems[2][8] = { - { - { NumbersAndOperatorsEnum::IsStandardMode, L"0", L"" }, - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Add, L"1", L"1 + " }, - { NumbersAndOperatorsEnum::Two, L"2", L"1 + " }, - { NumbersAndOperatorsEnum::Equals, L"3", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }, - { - { NumbersAndOperatorsEnum::IsStandardMode, L"0", L"" }, - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Add, L"1", L"1 + " }, - { NumbersAndOperatorsEnum::Two, L"2", L"1 + " }, - { NumbersAndOperatorsEnum::Multiply, L"3", L"1 + 2 * " }, - { NumbersAndOperatorsEnum::Three, L"3", L"1 + 2 * " }, - { NumbersAndOperatorsEnum::Equals, L"9", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - } - }; - - // Run the commands - for (int i = 0; i < 2; i++) - { - ValidateViewModelByCommands(viewModels[i], standardModeTestItems[i], true); - } - - String^ expression[] = { UtfUtils::LRO + L"1 + 2 =" + Utils::PDF, UtfUtils::LRO + L"1 + 2 " + UtfUtils::MUL + L" 3 =" + Utils::PDF }; - String^ result[] = { L"3", L"9" }; - - // Assert for the history list items of the instances - for (int i = 0; i < 2; i++) - { - VERIFY_IS_TRUE(1 == viewModels[i]->m_standardCalculatorManager->GetHistoryItems().size()); - - auto item = viewModels[i]->m_standardCalculatorManager->GetHistoryItem(0); - - VERIFY_ARE_EQUAL(expression[i], StringReference(item->historyItemVector.expression.c_str())); - VERIFY_ARE_EQUAL(result[i], StringReference(item->historyItemVector.result.c_str())); - } - } - - // Perform calculations on 3 separate instances of Calcuator and verify that their Memory List items are maintained separately - TEST_METHOD(MultipleModesMemoryAddItemTest) - { - std::vector viewModels(3); - - // Create 3 instances of StandardCalculatorViewModel in Standard and Scientific mode - for (int i = 0; i < 3; i++) - { - viewModels[i] = ref new StandardCalculatorViewModel(); - - ChangeMode(viewModels[i], i); - - // Validate that the history items list is initially empty - VERIFY_IS_TRUE(0 == viewModels[i]->MemorizedNumbers->Size); - } - - // Perform Calculations on both the instances and check that the Memory items work independently - - // Standard Mode: Expression 1+2= - TESTITEM standardModeTestItems[] = { - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Add, L"1", L"1 + " }, - { NumbersAndOperatorsEnum::Two, L"2", L"1 + " }, - { NumbersAndOperatorsEnum::Equals, L"3", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(viewModels[0], standardModeTestItems, true); - - // Scientific Mode: Expression 1+2*3 - TESTITEM scientificModeTestItems[] = { - { NumbersAndOperatorsEnum::IsScientificMode, L"0", L"" }, - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Add, L"1", L"1 + " }, - { NumbersAndOperatorsEnum::Two, L"2", L"1 + " }, - { NumbersAndOperatorsEnum::Multiply, L"2", L"1 + 2 * " }, - { NumbersAndOperatorsEnum::Three, L"3", L"1 + 2 * " }, - { NumbersAndOperatorsEnum::Equals, L"7", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(viewModels[1], scientificModeTestItems, true); - - // Programmer Mode: Expression F - TESTITEM programmerModeTestItems[] = { - { NumbersAndOperatorsEnum::HexButton, L"0", L"" }, - { NumbersAndOperatorsEnum::F, L"F", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(viewModels[2], programmerModeTestItems, false); - - // Press the Memory Button to save Values to Memory - for (int i = 0; i < 3; i++) - { - viewModels[i]->ButtonPressed->Execute(NumbersAndOperatorsEnum::Memory); - } - - String^ expectedMemoryValues[] = { - UtfUtils::LRO + L"3" + UtfUtils::PDF, - UtfUtils::LRO + L"7" + UtfUtils::PDF, - UtfUtils::LRO + L"F" + UtfUtils::PDF}; - - // Validate that only one item is present in the memory - // Also assert for their value - for (int i = 0; i < 3; i++) - { - VERIFY_IS_TRUE(1 == viewModels[i]->MemorizedNumbers->Size); - auto memorySlot = viewModels[i]->MemorizedNumbers->GetAt(0); - VERIFY_ARE_EQUAL(expectedMemoryValues[i], memorySlot->Value); - } - } - - TEST_METHOD(MultipleDateCalculatorTest) - { - // TODO - MSFT 10331900, fix this test - // This test mostly passes, but the last set of VERIFYs succeeds for - // the check of viewModels[2]->StrDateResult when in a UTC- time, - // however, both the expected and actual results are incorrect. Test - // needs to be updated with correct expected value and viewmodel needs - // to be updated to calculate correct value. - - //DateCalculatorViewModel^ viewModels[4]; - - //// Initialize the view models - //for (int i = 0; i < 4; i++) - //{ - // auto vm = ref new DateCalculatorViewModel(); - // vm->Initialize(); - - // viewModels[i] = vm; - //} - - //viewModels[2]->IsDateDiffMode = false; - //viewModels[3]->IsDateDiffMode = false; - - //viewModels[2]->IsAddMode = true; - //viewModels[3]->IsAddMode = false; - - //// Verify the initialization - //for (int i = 0; i < 2; i++) - //{ - // VERIFY_IS_TRUE(viewModels[i]->IsDateDiffMode); - // VERIFY_IS_TRUE(viewModels[i]->FromDate.UniversalTime != 0); - // VERIFY_IS_TRUE(viewModels[i]->ToDate.UniversalTime != 0); - // VERIFY_ARE_EQUAL(StringReference(L"Same dates"), viewModels[i]->StrDateDiffResult); - // VERIFY_IS_NULL(viewModels[i]->StrDateDiffResultInDays); - //} - - //for (int i = 2; i < 4; i++) - //{ - // VERIFY_IS_FALSE(viewModels[i]->IsDateDiffMode); - // VERIFY_IS_TRUE(viewModels[i]->DaysOffset == 0); - // VERIFY_IS_TRUE(viewModels[i]->MonthsOffset == 0); - // VERIFY_IS_TRUE(viewModels[i]->YearsOffset == 0); - // VERIFY_IS_NOT_NULL(viewModels[i]->StrDateResult); - // VERIFY_IS_TRUE(StringReference(L"") != viewModels[i]->StrDateResult); - //} - - //VERIFY_IS_TRUE(viewModels[2]->IsAddMode); - //VERIFY_IS_FALSE(viewModels[3]->IsAddMode); - - //// Perform some calculations - //// Diff in viewModels[0] - //SYSTEMTIME date1, date2, resultDate; - ///* 01-10-2015 */ date1.wDay = 1; date1.wMonth = 10; date1.wYear = 2015; date1.wDayOfWeek = 4; date1.wHour = 0; date1.wMinute = 0; date1.wSecond = 0; date1.wMilliseconds = 0; - ///* 15-02-2016 */ date2.wDay = 15; date2.wMonth = 2; date2.wYear = 2016; date2.wDayOfWeek = 1; date2.wHour = 0; date2.wMinute = 0; date2.wSecond = 0; date2.wMilliseconds = 0; - - //viewModels[0]->FromDate = DateUtils::SystemTimeToDateTime(date1); - //viewModels[0]->ToDate = DateUtils::SystemTimeToDateTime(date2); - - //// Diff in viewModels[1] - ///* 12-12-2015 */ date1.wDay = 12; date1.wMonth = 12; date1.wYear = 2015; date1.wDayOfWeek = 6; - ///* 15-12-2015 */ date2.wDay = 15; date2.wMonth = 12; date2.wYear = 2015; date2.wDayOfWeek = 2; - ///* 17-01-2018 */ resultDate.wDay = 17; resultDate.wMonth = 1; resultDate.wYear = 2018; resultDate.wDayOfWeek = 3; resultDate.wHour = 0; resultDate.wMinute = 0; resultDate.wSecond = 0; resultDate.wMilliseconds = 0; - - //viewModels[1]->FromDate = DateUtils::SystemTimeToDateTime(date1); - //viewModels[1]->ToDate = DateUtils::SystemTimeToDateTime(date2); - - //// Add in viewModels[2] - //viewModels[2]->StartDate = DateUtils::SystemTimeToDateTime(date1); - //viewModels[2]->DaysOffset = 5; - //viewModels[2]->MonthsOffset = 1; - //viewModels[2]->YearsOffset = 2; - - //// Subtract OOB in viewModels[3] - //viewModels[3]->StartDate = DateUtils::SystemTimeToDateTime(date2); - //viewModels[3]->DaysOffset = 5; - //viewModels[3]->MonthsOffset = 1; - //viewModels[3]->YearsOffset = 500; - - //// Assert for the result - //VERIFY_IS_FALSE(viewModels[0]->IsDiffInDays); - //VERIFY_ARE_EQUAL(StringReference(L"137 days"), viewModels[0]->StrDateDiffResultInDays); - //VERIFY_ARE_EQUAL(StringReference(L"4 months, 2 weeks"), viewModels[0]->StrDateDiffResult); - - //VERIFY_IS_TRUE(viewModels[1]->IsDiffInDays); - //VERIFY_ARE_EQUAL(StringReference(L"3 days"), viewModels[1]->StrDateDiffResult); - //VERIFY_IS_NULL(viewModels[1]->StrDateDiffResultInDays); - - //// TODO - MSFT 10331900 : both GetLongDate and viewmodel return incorrect values! - //VERIFY_ARE_EQUAL(DateUtils::GetLongDate(resultDate), viewModels[2]->StrDateResult); - //VERIFY_ARE_EQUAL(StringReference(L"Date out of Bound"), viewModels[3]->StrDateResult); - } - - TEST_METHOD(InitializeMultipleConverterTest) - { - std::shared_ptr unitConverterMocks[3]; - UnitConverterViewModel^ viewModels[3]; - - for (int i = 0; i < 3; i++) - { - unitConverterMocks[i] = std::make_shared(); - viewModels[i] = ref new UnitConverterViewModel(unitConverterMocks[i]); - IObservableVector^ cats = viewModels[i]->Categories; - VERIFY_ARE_EQUAL((UINT)1, unitConverterMocks[i]->m_getCategoriesCallCount); - VERIFY_ARE_EQUAL((UINT)3, cats->Size); - // Verify that we match current category - VERIFY_IS_TRUE(CAT2 == viewModels[i]->CurrentCategory->GetModelCategory()); - } - - // Change category of 1st instance to CAT1 and that of 2nd instance to CAT2 - viewModels[0]->CurrentCategory = viewModels[0]->Categories->GetAt(0); - viewModels[2]->CurrentCategory = viewModels[1]->Categories->GetAt(2); - - // Verify that the instance properties were set independently - for (int i = 0; i < 2; i++) - { - VERIFY_ARE_EQUAL((UINT)3, viewModels[i]->Categories->Size); - VERIFY_ARE_EQUAL((UINT)3, viewModels[i]->Units->Size); - } - - VERIFY_IS_TRUE(CAT1 == viewModels[0]->CurrentCategory->GetModelCategory()); - VERIFY_IS_TRUE(CAT2 == viewModels[1]->CurrentCategory->GetModelCategory()); - VERIFY_IS_TRUE(CAT3 == viewModels[2]->CurrentCategory->GetModelCategory()); - - VERIFY_IS_TRUE(UNIT1 == viewModels[0]->Unit1->GetModelUnit()); - VERIFY_IS_TRUE(UNIT2 == viewModels[0]->Unit2->GetModelUnit()); - - VERIFY_IS_TRUE(UNIT4 == viewModels[1]->Unit1->GetModelUnit()); - VERIFY_IS_TRUE(UNIT6 == viewModels[1]->Unit2->GetModelUnit()); - - VERIFY_IS_TRUE(UNIT9 == viewModels[2]->Unit1->GetModelUnit()); - VERIFY_IS_TRUE(UNIT7 == viewModels[2]->Unit2->GetModelUnit()); - } - - TEST_METHOD(MultipleConverterModeCalculationTest) - { - UnitConverterViewModel^ viewModels[3]; - ResourceLoader^ resLoader = ResourceLoader::GetForViewIndependentUse("Test"); - - for (int i = 0; i < 3; i++) - { - viewModels[i] = ref new UnitConverterViewModel(std::make_shared(std::make_shared(ref new GeographicRegion()), nullptr)); - IObservableVector^ categories = viewModels[i]->Categories; - VERIFY_ARE_EQUAL((UINT)13, categories->Size); - } - - IObservableVector^ categoryList = viewModels[0]->Categories; - IObservableVector^ unitsList[3]; - - // viewModels 0 & 1 have same category(Volume) and viewModel 2 has different category(Length) - int volumeIndex = NavCategory::GetIndexInGroup(ViewMode::Volume, CategoryGroupType::Converter); - int lengthIndex = NavCategory::GetIndexInGroup(ViewMode::Length, CategoryGroupType::Converter); - viewModels[0]->CurrentCategory = categoryList->GetAt(volumeIndex); - viewModels[1]->CurrentCategory = categoryList->GetAt(volumeIndex); - viewModels[2]->CurrentCategory = categoryList->GetAt(lengthIndex); - - for (int i = 0; i < 3; i++) - { - unitsList[i] = viewModels[i]->Units; - } - - // Milliliters - viewModels[0]->Unit1 = unitsList[0]->GetAt(0); - // Cubic centimeters - viewModels[0]->Unit2 = unitsList[0]->GetAt(1); - - // Liters - viewModels[1]->Unit1 = unitsList[1]->GetAt(2); - // Cubic meters - viewModels[1]->Unit2 = unitsList[1]->GetAt(3); - - // Nanometers - viewModels[2]->Unit1 = unitsList[2]->GetAt(0); - // Microns - viewModels[2]->Unit2 = unitsList[2]->GetAt(1); - - // Check that the units in multiple instances got set correctly - VERIFY_IS_TRUE(unitsList[0]->GetAt(0) == viewModels[0]->Unit1); - VERIFY_IS_TRUE(unitsList[0]->GetAt(1) == viewModels[0]->Unit2); - - VERIFY_IS_TRUE(unitsList[1]->GetAt(2) == viewModels[1]->Unit1); - VERIFY_IS_TRUE(unitsList[1]->GetAt(3) == viewModels[1]->Unit2); - - VERIFY_IS_TRUE(unitsList[2]->GetAt(0) == viewModels[2]->Unit1); - VERIFY_IS_TRUE(unitsList[2]->GetAt(1) == viewModels[2]->Unit2); - - // Perform conversions - viewModels[0]->ButtonPressed->Execute(NumbersAndOperatorsEnum::One); - - viewModels[1]->ButtonPressed->Execute(NumbersAndOperatorsEnum::Two); - - viewModels[2]->ButtonPressed->Execute(NumbersAndOperatorsEnum::Three); - - // Validate Value1 and Value2 which is the result - for (int i = 0; i < 3; i++) - { - auto expectedValue1 = (i + 1).ToString(); - auto actualValue1 = viewModels[i]->Value1; - - VERIFY_ARE_EQUAL(expectedValue1, GetStringValue(actualValue1)); - - std::wstring unit1Name = viewModels[i]->Unit1->Name->Data(); - std::wstring unit2Name = viewModels[i]->Unit2->Name->Data(); - - auto resKey = String::Concat(ref new String((unit1Name + L"-" + unit2Name + L"-").c_str()), expectedValue1); - String^ expectedResult = resLoader->GetString(resKey); - - String^ actualResult = GetStringValue(viewModels[i]->Value2); - - VERIFY_ARE_EQUAL(expectedResult, actualResult); - } - } - - TEST_METHOD(TestStandardUnitConverterAndDateViewModels) - { - // Create instances of SCVM in Standard Mode and UnitConverterViewModel - StandardCalculatorViewModel^ standardViewModel = ref new StandardCalculatorViewModel(); - UnitConverterViewModel^ unitConverterViewModel = ref new UnitConverterViewModel(std::make_shared(std::make_shared(ref new GeographicRegion()), nullptr)); - DateCalculatorViewModel^ dateCalcViewModel = ref new DateCalculatorViewModel(); - - // Initialize Standard Calculator - ChangeMode(standardViewModel, 0); - - // Initialize Date Calculator - dateCalcViewModel->IsDateDiffMode = false; - dateCalcViewModel->IsAddMode = true; - - // Initialize Unit Converter - int volumeCategoryIndex = NavCategory::GetIndexInGroup(ViewMode::Volume, CategoryGroupType::Converter); - IObservableVector^ categories = unitConverterViewModel->Categories; - unitConverterViewModel->CurrentCategory = categories->GetAt(volumeCategoryIndex); - unitConverterViewModel->Unit1 = unitConverterViewModel->Units->GetAt(2); - unitConverterViewModel->Unit2 = unitConverterViewModel->Units->GetAt(3); - - // Validate Calculator mode and UC Category and Units - ValidateViewModelMode(standardViewModel, 0); - - VERIFY_ARE_EQUAL(categories->GetAt(volumeCategoryIndex), unitConverterViewModel->CurrentCategory); - VERIFY_ARE_EQUAL(unitConverterViewModel->Units->GetAt(2), unitConverterViewModel->Unit1); - VERIFY_ARE_EQUAL(unitConverterViewModel->Units->GetAt(3), unitConverterViewModel->Unit2); - - // Perform Calculations on these instances and check that they work independently - - // Standard Mode 1: Expression 3-2= - TESTITEM standardModeTestItems1[] = { - { NumbersAndOperatorsEnum::Three, L"3", L"" }, - { NumbersAndOperatorsEnum::Subtract, L"3", L"3 - " }, - { NumbersAndOperatorsEnum::Two, L"2", L"3 - " }, - { NumbersAndOperatorsEnum::Equals, L"1", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(standardViewModel, standardModeTestItems1, true); - - SYSTEMTIME startDate, endDate; - /* 01-10-2015 */ startDate.wDay = 1; startDate.wMonth = 10; startDate.wYear = 2015; startDate.wDayOfWeek = 4; startDate.wHour = 0; startDate.wMinute = 0; startDate.wSecond = 0; startDate.wMilliseconds = 0; - /* 02-12-2018 */ endDate.wDay = 2; endDate.wMonth = 12; endDate.wYear = 2018; endDate.wDayOfWeek = 0; endDate.wHour = 0; endDate.wMinute = 0; endDate.wSecond = 0; endDate.wMilliseconds = 0; - - dateCalcViewModel->StartDate = DateUtils::SystemTimeToDateTime(startDate); - dateCalcViewModel->DaysOffset = 1; - dateCalcViewModel->MonthsOffset = 2; - dateCalcViewModel->YearsOffset = 3; - - unitConverterViewModel->ButtonPressed->Execute(NumbersAndOperatorsEnum::Two); - - // Validate the Result - VERIFY_ARE_EQUAL(StringReference(L"2"), GetStringValue(unitConverterViewModel->Value1)); - VERIFY_ARE_EQUAL(StringReference(L"0.002"), GetStringValue(unitConverterViewModel->Value2)); - - // Assert that the Display Value of Standard Calc instance is unchanged - VERIFY_ARE_EQUAL(GetStringValue(standardViewModel->DisplayValue), StringReference(L"1")); - - // Again perform calculations on Standard Calc instance and validate that the Converter remains unaffected - - // Standard Mode: Expression 1+2= - TESTITEM standardModeTestItems2[] = { - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Add, L"1", L"1 + " }, - { NumbersAndOperatorsEnum::Two, L"2", L"1 + " }, - { NumbersAndOperatorsEnum::Equals, L"3", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(standardViewModel, standardModeTestItems2, true); - VERIFY_ARE_EQUAL(StringReference(L"3"), GetStringValue(standardViewModel->DisplayValue)); - - // Validate the Date Calculator - VERIFY_ARE_EQUAL(DateUtils::GetLongDate(endDate), dateCalcViewModel->StrDateResult); - - // Validate the Unit Converter - VERIFY_ARE_EQUAL(StringReference(L"2"), GetStringValue(unitConverterViewModel->Value1)); - VERIFY_ARE_EQUAL(StringReference(L"0.002"), GetStringValue(unitConverterViewModel->Value2)); - } - - // Change the radix in programmer mode and check that other modes are not affected - TEST_METHOD(MultipleModesWithChangeInProgrammerRadix) - { - std::vector viewModels(3); - - // Create 2 instances of StandardCalculatorViewModel in Standard and Programmer modes - viewModels[0] = ref new StandardCalculatorViewModel(); - ChangeMode(viewModels[0], 0); - - viewModels[1] = ref new StandardCalculatorViewModel(); - ChangeMode(viewModels[1], 2); - - // Change the programmer mode radix to hex - TESTITEM programmerModeTestItems[] = { - { NumbersAndOperatorsEnum::HexButton, L"0", L"" }, - { NumbersAndOperatorsEnum::F, L"F", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(viewModels[1], programmerModeTestItems, false /*doReset*/); - VERIFY_ARE_EQUAL(GetStringValue(viewModels[1]->HexDisplayValue), StringReference(L"F")); - - // Standard Mode: Expression 10+2= - // Radix should be decimal, not hex - TESTITEM standardModeTestItems[] = { - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Zero, L"10", L"" }, - { NumbersAndOperatorsEnum::Add, L"10", L"10 + " }, - { NumbersAndOperatorsEnum::Two, L"2", L"10 + " }, - { NumbersAndOperatorsEnum::Equals, L"12", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(viewModels[0], standardModeTestItems, false /*doReset*/); - - //Launch a new instance in standard mode - viewModels[2] = ref new StandardCalculatorViewModel(); - ChangeMode(viewModels[2], 0); - - // Standard Mode: Expression 10+2= - // Radix will be decimal by default - TESTITEM standardModeTestItemsNew[] = { - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Zero, L"10", L"" }, - { NumbersAndOperatorsEnum::Add, L"10", L"10 + " }, - { NumbersAndOperatorsEnum::Two, L"2", L"10 + " }, - { NumbersAndOperatorsEnum::Equals, L"12", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(viewModels[2], standardModeTestItemsNew, false /*doReset*/); - - //Radix in the programmer mode launched should still be hex. - // A + 1 = B - TESTITEM programmerModeTestItemsNew[] = { - { NumbersAndOperatorsEnum::A, L"A", L"" }, - { NumbersAndOperatorsEnum::Add, L"A", L"A + " }, - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Equals, L"B", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(viewModels[1], programmerModeTestItemsNew, true /*doReset*/); - VERIFY_ARE_EQUAL(GetStringValue(viewModels[1]->HexDisplayValue), StringReference(L"B")); - } - }; -} - diff --git a/internal/CalculatorUnitTests/NavCategoryUnitTests.cpp b/internal/CalculatorUnitTests/NavCategoryUnitTests.cpp deleted file mode 100644 index e0ecebb..0000000 --- a/internal/CalculatorUnitTests/NavCategoryUnitTests.cpp +++ /dev/null @@ -1,410 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#include "pch.h" -#include - -using namespace CalculatorApp::Common; -using namespace CalculatorUnitTests; -using namespace Platform; -using namespace std; -using namespace Windows::Foundation::Collections; - -namespace CalculatorUnitTests -{ - class NavCategoryUnitTests - { - public: - TEST_CLASS(NavCategoryUnitTests); - - TEST_METHOD(Serialize); - TEST_METHOD(Deserialize_AllValid); - TEST_METHOD(Deserialize_AllInvalid); - - TEST_METHOD(IsValidViewMode_AllValid); - TEST_METHOD(IsValidViewMode_AllInvalid); - - TEST_METHOD(IsCalculatorViewMode); - TEST_METHOD(IsDateCalculatorViewMode); - TEST_METHOD(IsConverterViewMode); - - TEST_METHOD(GetFriendlyName); - TEST_METHOD(GetGroupType); - TEST_METHOD(GetIndex); - TEST_METHOD(GetPosition); - TEST_METHOD(GetIndex_GetPosition_Relationship); - TEST_METHOD(GetIndexInGroup); - - TEST_METHOD(GetViewModeForVirtualKey); - }; - - void NavCategoryUnitTests::Serialize() - { - // While values in other tests may change (for example, the order - // of a navigation item might change), these values should NEVER - // change. We are validating the unique ID for each mode, not - // it's position or index. - VERIFY_ARE_EQUAL(0, NavCategory::Serialize(ViewMode::Standard)); - VERIFY_ARE_EQUAL(1, NavCategory::Serialize(ViewMode::Scientific)); - VERIFY_ARE_EQUAL(2, NavCategory::Serialize(ViewMode::Programmer)); - VERIFY_ARE_EQUAL(3, NavCategory::Serialize(ViewMode::Date)); - VERIFY_ARE_EQUAL(16, NavCategory::Serialize(ViewMode::Currency)); - VERIFY_ARE_EQUAL(4, NavCategory::Serialize(ViewMode::Volume)); - VERIFY_ARE_EQUAL(5, NavCategory::Serialize(ViewMode::Length)); - VERIFY_ARE_EQUAL(6, NavCategory::Serialize(ViewMode::Weight)); - VERIFY_ARE_EQUAL(7, NavCategory::Serialize(ViewMode::Temperature)); - VERIFY_ARE_EQUAL(8, NavCategory::Serialize(ViewMode::Energy)); - VERIFY_ARE_EQUAL(9, NavCategory::Serialize(ViewMode::Area)); - VERIFY_ARE_EQUAL(10, NavCategory::Serialize(ViewMode::Speed)); - VERIFY_ARE_EQUAL(11, NavCategory::Serialize(ViewMode::Time)); - VERIFY_ARE_EQUAL(12, NavCategory::Serialize(ViewMode::Power)); - VERIFY_ARE_EQUAL(13, NavCategory::Serialize(ViewMode::Data)); - VERIFY_ARE_EQUAL(14, NavCategory::Serialize(ViewMode::Pressure)); - VERIFY_ARE_EQUAL(15, NavCategory::Serialize(ViewMode::Angle)); - - VERIFY_ARE_EQUAL(-1, NavCategory::Serialize(ViewMode::None)); - } - - void NavCategoryUnitTests::Deserialize_AllValid() - { - // While values in other tests may change (for example, the order - // of a navigation item might change), these values should NEVER - // change. We are validating the unique ID for each mode, not - // it's position or index. - VERIFY_ARE_EQUAL(ViewMode::Standard, NavCategory::Deserialize(ref new Box(0))); - VERIFY_ARE_EQUAL(ViewMode::Scientific, NavCategory::Deserialize(ref new Box(1))); - VERIFY_ARE_EQUAL(ViewMode::Programmer, NavCategory::Deserialize(ref new Box(2))); - VERIFY_ARE_EQUAL(ViewMode::Date, NavCategory::Deserialize(ref new Box(3))); - VERIFY_ARE_EQUAL(ViewMode::Currency, NavCategory::Deserialize(ref new Box(16))); - VERIFY_ARE_EQUAL(ViewMode::Volume, NavCategory::Deserialize(ref new Box(4))); - VERIFY_ARE_EQUAL(ViewMode::Length, NavCategory::Deserialize(ref new Box(5))); - VERIFY_ARE_EQUAL(ViewMode::Weight, NavCategory::Deserialize(ref new Box(6))); - VERIFY_ARE_EQUAL(ViewMode::Temperature, NavCategory::Deserialize(ref new Box(7))); - VERIFY_ARE_EQUAL(ViewMode::Energy, NavCategory::Deserialize(ref new Box(8))); - VERIFY_ARE_EQUAL(ViewMode::Area, NavCategory::Deserialize(ref new Box(9))); - VERIFY_ARE_EQUAL(ViewMode::Speed, NavCategory::Deserialize(ref new Box(10))); - VERIFY_ARE_EQUAL(ViewMode::Time, NavCategory::Deserialize(ref new Box(11))); - VERIFY_ARE_EQUAL(ViewMode::Power, NavCategory::Deserialize(ref new Box(12))); - VERIFY_ARE_EQUAL(ViewMode::Data, NavCategory::Deserialize(ref new Box(13))); - VERIFY_ARE_EQUAL(ViewMode::Pressure, NavCategory::Deserialize(ref new Box(14))); - VERIFY_ARE_EQUAL(ViewMode::Angle, NavCategory::Deserialize(ref new Box(15))); - } - - void NavCategoryUnitTests::Deserialize_AllInvalid() - { - VERIFY_ARE_EQUAL(ViewMode::None, NavCategory::Deserialize(nullptr)); - VERIFY_ARE_EQUAL(ViewMode::None, NavCategory::Deserialize(ref new String(L"fail"))); - - // Boundary testing - VERIFY_ARE_EQUAL(ViewMode::None, NavCategory::Deserialize(ref new Box(-1))); - VERIFY_ARE_EQUAL(ViewMode::None, NavCategory::Deserialize(ref new Box(17))); - } - - void NavCategoryUnitTests::IsValidViewMode_AllValid() - { - VERIFY_IS_TRUE(NavCategory::IsValidViewMode(ViewMode::Standard)); - VERIFY_IS_TRUE(NavCategory::IsValidViewMode(ViewMode::Scientific)); - VERIFY_IS_TRUE(NavCategory::IsValidViewMode(ViewMode::Programmer)); - VERIFY_IS_TRUE(NavCategory::IsValidViewMode(ViewMode::Date)); - VERIFY_IS_TRUE(NavCategory::IsValidViewMode(ViewMode::Currency)); - VERIFY_IS_TRUE(NavCategory::IsValidViewMode(ViewMode::Volume)); - VERIFY_IS_TRUE(NavCategory::IsValidViewMode(ViewMode::Length)); - VERIFY_IS_TRUE(NavCategory::IsValidViewMode(ViewMode::Weight)); - VERIFY_IS_TRUE(NavCategory::IsValidViewMode(ViewMode::Temperature)); - VERIFY_IS_TRUE(NavCategory::IsValidViewMode(ViewMode::Energy)); - VERIFY_IS_TRUE(NavCategory::IsValidViewMode(ViewMode::Area)); - VERIFY_IS_TRUE(NavCategory::IsValidViewMode(ViewMode::Speed)); - VERIFY_IS_TRUE(NavCategory::IsValidViewMode(ViewMode::Time)); - VERIFY_IS_TRUE(NavCategory::IsValidViewMode(ViewMode::Power)); - VERIFY_IS_TRUE(NavCategory::IsValidViewMode(ViewMode::Data)); - VERIFY_IS_TRUE(NavCategory::IsValidViewMode(ViewMode::Pressure)); - VERIFY_IS_TRUE(NavCategory::IsValidViewMode(ViewMode::Angle)); - } - - void NavCategoryUnitTests::IsValidViewMode_AllInvalid() - { - VERIFY_IS_FALSE(NavCategory::IsValidViewMode(ViewMode::None)); - - // There are 17 total options so int 17 should be the first invalid - VERIFY_IS_TRUE(NavCategory::IsValidViewMode(static_cast(16))); - VERIFY_IS_FALSE(NavCategory::IsValidViewMode(static_cast(17))); - - // Also verify the lower bound - VERIFY_IS_TRUE(NavCategory::IsValidViewMode(static_cast(0))); - VERIFY_IS_FALSE(NavCategory::IsValidViewMode(static_cast(-1))); - } - - void NavCategoryUnitTests::IsCalculatorViewMode() - { - VERIFY_IS_TRUE(NavCategory::IsCalculatorViewMode(ViewMode::Standard)); - VERIFY_IS_TRUE(NavCategory::IsCalculatorViewMode(ViewMode::Scientific)); - VERIFY_IS_TRUE(NavCategory::IsCalculatorViewMode(ViewMode::Programmer)); - - VERIFY_IS_FALSE(NavCategory::IsCalculatorViewMode(ViewMode::Date)); - - VERIFY_IS_FALSE(NavCategory::IsCalculatorViewMode(ViewMode::Currency)); - VERIFY_IS_FALSE(NavCategory::IsCalculatorViewMode(ViewMode::Volume)); - VERIFY_IS_FALSE(NavCategory::IsCalculatorViewMode(ViewMode::Length)); - VERIFY_IS_FALSE(NavCategory::IsCalculatorViewMode(ViewMode::Weight)); - VERIFY_IS_FALSE(NavCategory::IsCalculatorViewMode(ViewMode::Temperature)); - VERIFY_IS_FALSE(NavCategory::IsCalculatorViewMode(ViewMode::Energy)); - VERIFY_IS_FALSE(NavCategory::IsCalculatorViewMode(ViewMode::Area)); - VERIFY_IS_FALSE(NavCategory::IsCalculatorViewMode(ViewMode::Speed)); - VERIFY_IS_FALSE(NavCategory::IsCalculatorViewMode(ViewMode::Time)); - VERIFY_IS_FALSE(NavCategory::IsCalculatorViewMode(ViewMode::Power)); - VERIFY_IS_FALSE(NavCategory::IsCalculatorViewMode(ViewMode::Data)); - VERIFY_IS_FALSE(NavCategory::IsCalculatorViewMode(ViewMode::Pressure)); - VERIFY_IS_FALSE(NavCategory::IsCalculatorViewMode(ViewMode::Angle)); - } - - void NavCategoryUnitTests::IsDateCalculatorViewMode() - { - VERIFY_IS_FALSE(NavCategory::IsDateCalculatorViewMode(ViewMode::Standard)); - VERIFY_IS_FALSE(NavCategory::IsDateCalculatorViewMode(ViewMode::Scientific)); - VERIFY_IS_FALSE(NavCategory::IsDateCalculatorViewMode(ViewMode::Programmer)); - - VERIFY_IS_TRUE(NavCategory::IsDateCalculatorViewMode(ViewMode::Date)); - - VERIFY_IS_FALSE(NavCategory::IsDateCalculatorViewMode(ViewMode::Currency)); - VERIFY_IS_FALSE(NavCategory::IsDateCalculatorViewMode(ViewMode::Volume)); - VERIFY_IS_FALSE(NavCategory::IsDateCalculatorViewMode(ViewMode::Length)); - VERIFY_IS_FALSE(NavCategory::IsDateCalculatorViewMode(ViewMode::Weight)); - VERIFY_IS_FALSE(NavCategory::IsDateCalculatorViewMode(ViewMode::Temperature)); - VERIFY_IS_FALSE(NavCategory::IsDateCalculatorViewMode(ViewMode::Energy)); - VERIFY_IS_FALSE(NavCategory::IsDateCalculatorViewMode(ViewMode::Area)); - VERIFY_IS_FALSE(NavCategory::IsDateCalculatorViewMode(ViewMode::Speed)); - VERIFY_IS_FALSE(NavCategory::IsDateCalculatorViewMode(ViewMode::Time)); - VERIFY_IS_FALSE(NavCategory::IsDateCalculatorViewMode(ViewMode::Power)); - VERIFY_IS_FALSE(NavCategory::IsDateCalculatorViewMode(ViewMode::Data)); - VERIFY_IS_FALSE(NavCategory::IsDateCalculatorViewMode(ViewMode::Pressure)); - VERIFY_IS_FALSE(NavCategory::IsDateCalculatorViewMode(ViewMode::Angle)); - } - - void NavCategoryUnitTests::IsConverterViewMode() - { - VERIFY_IS_FALSE(NavCategory::IsConverterViewMode(ViewMode::Standard)); - VERIFY_IS_FALSE(NavCategory::IsConverterViewMode(ViewMode::Scientific)); - VERIFY_IS_FALSE(NavCategory::IsConverterViewMode(ViewMode::Programmer)); - - VERIFY_IS_FALSE(NavCategory::IsConverterViewMode(ViewMode::Date)); - - VERIFY_IS_TRUE(NavCategory::IsConverterViewMode(ViewMode::Currency)); - VERIFY_IS_TRUE(NavCategory::IsConverterViewMode(ViewMode::Volume)); - VERIFY_IS_TRUE(NavCategory::IsConverterViewMode(ViewMode::Length)); - VERIFY_IS_TRUE(NavCategory::IsConverterViewMode(ViewMode::Weight)); - VERIFY_IS_TRUE(NavCategory::IsConverterViewMode(ViewMode::Temperature)); - VERIFY_IS_TRUE(NavCategory::IsConverterViewMode(ViewMode::Energy)); - VERIFY_IS_TRUE(NavCategory::IsConverterViewMode(ViewMode::Area)); - VERIFY_IS_TRUE(NavCategory::IsConverterViewMode(ViewMode::Speed)); - VERIFY_IS_TRUE(NavCategory::IsConverterViewMode(ViewMode::Time)); - VERIFY_IS_TRUE(NavCategory::IsConverterViewMode(ViewMode::Power)); - VERIFY_IS_TRUE(NavCategory::IsConverterViewMode(ViewMode::Data)); - VERIFY_IS_TRUE(NavCategory::IsConverterViewMode(ViewMode::Pressure)); - VERIFY_IS_TRUE(NavCategory::IsConverterViewMode(ViewMode::Angle)); - } - - void NavCategoryUnitTests::GetFriendlyName() - { - VERIFY_ARE_EQUAL(StringReference(L"Standard"), NavCategory::GetFriendlyName(ViewMode::Standard)); - VERIFY_ARE_EQUAL(StringReference(L"Scientific"), NavCategory::GetFriendlyName(ViewMode::Scientific)); - VERIFY_ARE_EQUAL(StringReference(L"Programmer"), NavCategory::GetFriendlyName(ViewMode::Programmer)); - VERIFY_ARE_EQUAL(StringReference(L"Date"), NavCategory::GetFriendlyName(ViewMode::Date)); - VERIFY_ARE_EQUAL(StringReference(L"Currency"), NavCategory::GetFriendlyName(ViewMode::Currency)); - VERIFY_ARE_EQUAL(StringReference(L"Volume"), NavCategory::GetFriendlyName(ViewMode::Volume)); - VERIFY_ARE_EQUAL(StringReference(L"Length"), NavCategory::GetFriendlyName(ViewMode::Length)); - VERIFY_ARE_EQUAL(StringReference(L"Weight and Mass"), NavCategory::GetFriendlyName(ViewMode::Weight)); - VERIFY_ARE_EQUAL(StringReference(L"Temperature"), NavCategory::GetFriendlyName(ViewMode::Temperature)); - VERIFY_ARE_EQUAL(StringReference(L"Energy"), NavCategory::GetFriendlyName(ViewMode::Energy)); - VERIFY_ARE_EQUAL(StringReference(L"Area"), NavCategory::GetFriendlyName(ViewMode::Area)); - VERIFY_ARE_EQUAL(StringReference(L"Speed"), NavCategory::GetFriendlyName(ViewMode::Speed)); - VERIFY_ARE_EQUAL(StringReference(L"Time"), NavCategory::GetFriendlyName(ViewMode::Time)); - VERIFY_ARE_EQUAL(StringReference(L"Power"), NavCategory::GetFriendlyName(ViewMode::Power)); - VERIFY_ARE_EQUAL(StringReference(L"Data"), NavCategory::GetFriendlyName(ViewMode::Data)); - VERIFY_ARE_EQUAL(StringReference(L"Pressure"), NavCategory::GetFriendlyName(ViewMode::Pressure)); - VERIFY_ARE_EQUAL(StringReference(L"Angle"), NavCategory::GetFriendlyName(ViewMode::Angle)); - - VERIFY_ARE_EQUAL(StringReference(L"None"), NavCategory::GetFriendlyName(ViewMode::None)); - } - - void NavCategoryUnitTests::GetGroupType() - { - VERIFY_ARE_EQUAL(CategoryGroupType::Calculator, NavCategory::GetGroupType(ViewMode::Standard)); - VERIFY_ARE_EQUAL(CategoryGroupType::Calculator, NavCategory::GetGroupType(ViewMode::Scientific)); - VERIFY_ARE_EQUAL(CategoryGroupType::Calculator, NavCategory::GetGroupType(ViewMode::Programmer)); - VERIFY_ARE_EQUAL(CategoryGroupType::Calculator, NavCategory::GetGroupType(ViewMode::Date)); - - VERIFY_ARE_EQUAL(CategoryGroupType::Converter, NavCategory::GetGroupType(ViewMode::Currency)); - VERIFY_ARE_EQUAL(CategoryGroupType::Converter, NavCategory::GetGroupType(ViewMode::Volume)); - VERIFY_ARE_EQUAL(CategoryGroupType::Converter, NavCategory::GetGroupType(ViewMode::Length)); - VERIFY_ARE_EQUAL(CategoryGroupType::Converter, NavCategory::GetGroupType(ViewMode::Weight)); - VERIFY_ARE_EQUAL(CategoryGroupType::Converter, NavCategory::GetGroupType(ViewMode::Temperature)); - VERIFY_ARE_EQUAL(CategoryGroupType::Converter, NavCategory::GetGroupType(ViewMode::Energy)); - VERIFY_ARE_EQUAL(CategoryGroupType::Converter, NavCategory::GetGroupType(ViewMode::Area)); - VERIFY_ARE_EQUAL(CategoryGroupType::Converter, NavCategory::GetGroupType(ViewMode::Speed)); - VERIFY_ARE_EQUAL(CategoryGroupType::Converter, NavCategory::GetGroupType(ViewMode::Time)); - VERIFY_ARE_EQUAL(CategoryGroupType::Converter, NavCategory::GetGroupType(ViewMode::Power)); - VERIFY_ARE_EQUAL(CategoryGroupType::Converter, NavCategory::GetGroupType(ViewMode::Data)); - VERIFY_ARE_EQUAL(CategoryGroupType::Converter, NavCategory::GetGroupType(ViewMode::Pressure)); - VERIFY_ARE_EQUAL(CategoryGroupType::Converter, NavCategory::GetGroupType(ViewMode::Angle)); - } - - void NavCategoryUnitTests::GetIndex() - { - // Index is the 0-based ordering of modes - vector orderedModes = { - ViewMode::Standard, - ViewMode::Scientific, - ViewMode::Programmer, - ViewMode::Date, - ViewMode::Currency, - ViewMode::Volume, - ViewMode::Length, - ViewMode::Weight, - ViewMode::Temperature, - ViewMode::Energy, - ViewMode::Area, - ViewMode::Speed, - ViewMode::Time, - ViewMode::Power, - ViewMode::Data, - ViewMode::Pressure, - ViewMode::Angle - }; - - for (size_t index = 0; index < orderedModes.size(); index++) - { - ViewMode mode = orderedModes[index]; - VERIFY_ARE_EQUAL(index, NavCategory::GetIndex(mode)); - } - - VERIFY_ARE_EQUAL(-1, NavCategory::GetIndex(ViewMode::None)); - } - - void NavCategoryUnitTests::GetPosition() - { - // Position is the 1-based ordering of modes - vector orderedModes = { - ViewMode::Standard, - ViewMode::Scientific, - ViewMode::Programmer, - ViewMode::Date, - ViewMode::Currency, - ViewMode::Volume, - ViewMode::Length, - ViewMode::Weight, - ViewMode::Temperature, - ViewMode::Energy, - ViewMode::Area, - ViewMode::Speed, - ViewMode::Time, - ViewMode::Power, - ViewMode::Data, - ViewMode::Pressure, - ViewMode::Angle - }; - - for (size_t pos = 1; pos <= orderedModes.size(); pos++) - { - ViewMode mode = orderedModes[pos - 1]; - VERIFY_ARE_EQUAL(pos, NavCategory::GetPosition(mode)); - } - - VERIFY_ARE_EQUAL(-1, NavCategory::GetPosition(ViewMode::None)); - } - - void NavCategoryUnitTests::GetIndex_GetPosition_Relationship() - { - // Index should be 1 less than Position. - // The other checks verify the order of Index and Position. - // Just verify the relationship here. - VERIFY_ARE_EQUAL(NavCategory::GetIndex(ViewMode::Standard) + 1, NavCategory::GetPosition(ViewMode::Standard)); - VERIFY_ARE_EQUAL(NavCategory::GetPosition(ViewMode::Volume) - 1, NavCategory::GetIndex(ViewMode::Volume)); - } - - void NavCategoryUnitTests::GetIndexInGroup() - { - VERIFY_ARE_EQUAL(0, NavCategory::GetIndexInGroup(ViewMode::Standard, CategoryGroupType::Calculator)); - VERIFY_ARE_EQUAL(1, NavCategory::GetIndexInGroup(ViewMode::Scientific, CategoryGroupType::Calculator)); - VERIFY_ARE_EQUAL(2, NavCategory::GetIndexInGroup(ViewMode::Programmer, CategoryGroupType::Calculator)); - VERIFY_ARE_EQUAL(3, NavCategory::GetIndexInGroup(ViewMode::Date, CategoryGroupType::Calculator)); - - VERIFY_ARE_EQUAL(0, NavCategory::GetIndexInGroup(ViewMode::Currency, CategoryGroupType::Converter)); - VERIFY_ARE_EQUAL(1, NavCategory::GetIndexInGroup(ViewMode::Volume, CategoryGroupType::Converter)); - VERIFY_ARE_EQUAL(2, NavCategory::GetIndexInGroup(ViewMode::Length, CategoryGroupType::Converter)); - VERIFY_ARE_EQUAL(3, NavCategory::GetIndexInGroup(ViewMode::Weight, CategoryGroupType::Converter)); - VERIFY_ARE_EQUAL(4, NavCategory::GetIndexInGroup(ViewMode::Temperature, CategoryGroupType::Converter)); - VERIFY_ARE_EQUAL(5, NavCategory::GetIndexInGroup(ViewMode::Energy, CategoryGroupType::Converter)); - VERIFY_ARE_EQUAL(6, NavCategory::GetIndexInGroup(ViewMode::Area, CategoryGroupType::Converter)); - VERIFY_ARE_EQUAL(7, NavCategory::GetIndexInGroup(ViewMode::Speed, CategoryGroupType::Converter)); - VERIFY_ARE_EQUAL(8, NavCategory::GetIndexInGroup(ViewMode::Time, CategoryGroupType::Converter)); - VERIFY_ARE_EQUAL(9, NavCategory::GetIndexInGroup(ViewMode::Power, CategoryGroupType::Converter)); - VERIFY_ARE_EQUAL(10, NavCategory::GetIndexInGroup(ViewMode::Data, CategoryGroupType::Converter)); - VERIFY_ARE_EQUAL(11, NavCategory::GetIndexInGroup(ViewMode::Pressure, CategoryGroupType::Converter)); - VERIFY_ARE_EQUAL(12, NavCategory::GetIndexInGroup(ViewMode::Angle, CategoryGroupType::Converter)); - - VERIFY_ARE_EQUAL(-1, NavCategory::GetIndexInGroup(ViewMode::None, CategoryGroupType::Calculator)); - VERIFY_ARE_EQUAL(-1, NavCategory::GetIndexInGroup(ViewMode::None, CategoryGroupType::Converter)); - } - - void NavCategoryUnitTests::GetViewModeForVirtualKey() - { - VERIFY_ARE_EQUAL(ViewMode::Standard, NavCategory::GetViewModeForVirtualKey(MyVirtualKey::Number1)); - VERIFY_ARE_EQUAL(ViewMode::Scientific, NavCategory::GetViewModeForVirtualKey(MyVirtualKey::Number2)); - VERIFY_ARE_EQUAL(ViewMode::Programmer, NavCategory::GetViewModeForVirtualKey(MyVirtualKey::Number3)); - } - - class NavCategoryGroupUnitTests - { - public: - TEST_CLASS(NavCategoryGroupUnitTests); - - TEST_METHOD(CreateNavCategoryGroup); - - private: - void ValidateNavCategory(IObservableVector^ categories, unsigned int index, ViewMode expectedMode, int expectedPosition) - { - VERIFY_IS_LESS_THAN(0u, categories->Size); - VERIFY_IS_GREATER_THAN(categories->Size, index); - - NavCategory^ category = categories->GetAt(index); - VERIFY_ARE_EQUAL(expectedMode, category->Mode); - VERIFY_ARE_EQUAL(expectedPosition, category->Position); - } - }; - - void NavCategoryGroupUnitTests::CreateNavCategoryGroup() - { - IObservableVector^ menuOptions = NavCategoryGroup::CreateMenuOptions(); - - VERIFY_ARE_EQUAL(2, menuOptions->Size); - - NavCategoryGroup^ calculatorGroup = menuOptions->GetAt(0); - VERIFY_ARE_EQUAL(CategoryGroupType::Calculator, calculatorGroup->GroupType); - - IObservableVector^ calculatorCategories = calculatorGroup->Categories; - VERIFY_ARE_EQUAL(4, calculatorCategories->Size); - ValidateNavCategory(calculatorCategories, 0u, ViewMode::Standard, 1); - ValidateNavCategory(calculatorCategories, 1u, ViewMode::Scientific, 2); - ValidateNavCategory(calculatorCategories, 2u, ViewMode::Programmer, 3); - ValidateNavCategory(calculatorCategories, 3u, ViewMode::Date, 4); - - NavCategoryGroup^ converterGroup = menuOptions->GetAt(1); - VERIFY_ARE_EQUAL(CategoryGroupType::Converter, converterGroup->GroupType); - - IObservableVector^ converterCategories = converterGroup->Categories; - VERIFY_ARE_EQUAL(13, converterCategories->Size); - ValidateNavCategory(converterCategories, 0u, ViewMode::Currency, 5); - ValidateNavCategory(converterCategories, 1u, ViewMode::Volume, 6); - ValidateNavCategory(converterCategories, 2u, ViewMode::Length, 7); - ValidateNavCategory(converterCategories, 3u, ViewMode::Weight, 8); - ValidateNavCategory(converterCategories, 4u, ViewMode::Temperature, 9); - ValidateNavCategory(converterCategories, 5u, ViewMode::Energy, 10); - ValidateNavCategory(converterCategories, 6u, ViewMode::Area, 11); - ValidateNavCategory(converterCategories, 7u, ViewMode::Speed, 12); - ValidateNavCategory(converterCategories, 8u, ViewMode::Time, 13); - ValidateNavCategory(converterCategories, 9u, ViewMode::Power, 14); - ValidateNavCategory(converterCategories, 10u, ViewMode::Data, 15); - ValidateNavCategory(converterCategories, 11u, ViewMode::Pressure, 16); - ValidateNavCategory(converterCategories, 12u, ViewMode::Angle, 17); - } -} diff --git a/internal/CalculatorUnitTests/Package.appxmanifest b/internal/CalculatorUnitTests/Package.appxmanifest deleted file mode 100644 index 62c0b67..0000000 --- a/internal/CalculatorUnitTests/Package.appxmanifest +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - CalculatorUnitTests - Microsoft Corporation - Assets\StoreLogo.png - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/internal/CalculatorUnitTests/StandardViewModelUnitTests.cpp b/internal/CalculatorUnitTests/StandardViewModelUnitTests.cpp deleted file mode 100644 index 3164303..0000000 --- a/internal/CalculatorUnitTests/StandardViewModelUnitTests.cpp +++ /dev/null @@ -1,1144 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#include "pch.h" -#include - -#include "CalcViewModel/StandardCalculatorViewModel.h" -#include "CalcViewModel/Common/CalculatorButtonPressedEventArgs.h" - -#include "CalcViewModel/StandardCalculatorViewModel.h" -#include "CalcViewModel/Common/CalculatorButtonPressedEventArgs.h" - -using namespace CalculationManager; -using namespace CalculatorApp; -using namespace CalculatorApp::Common; -using namespace CalculatorApp::ViewModel; -using namespace Platform; - -namespace CalculatorUnitTests -{ - - void ChangeMode(StandardCalculatorViewModel^ viewModel, int mode) - { - if (mode == 0) - { - viewModel->IsStandard = true; - viewModel->IsScientific = false; - viewModel->IsProgrammer = false; - viewModel->ResetDisplay(); - viewModel->SetPrecision(StandardModePrecision); - } - else if (mode == 1) - { - viewModel->IsScientific = true; - viewModel->IsProgrammer = false; - viewModel->IsStandard = false; - viewModel->ResetDisplay(); - viewModel->SetPrecision(ScientificModePrecision); - } - else if (mode == 2) - { - viewModel->IsProgrammer = true; - viewModel->IsScientific = false; - viewModel->IsStandard = false; - viewModel->ResetDisplay(); - viewModel->SetPrecision(ProgrammerModePrecision); - } - } - - Object^ CommandParameterFromTestItem(TESTITEM* item) - { - // Need to wrap Binary Operators with their feedback - static const std::vector> binOps = { - { NumbersAndOperatorsEnum::Add, L"plus" }, - { NumbersAndOperatorsEnum::Subtract, L"minus" }, - { NumbersAndOperatorsEnum::Multiply, L"times" }, - { NumbersAndOperatorsEnum::Divide, L"divided by" } - }; - - for (auto& binOp : binOps) - { - if (item->command == binOp.first) - { - return ref new CalculatorButtonPressedEventArgs(binOp.second, binOp.first); - } - } - - return item->command; - } - - void ValidateViewModelByCommands(StandardCalculatorViewModel^ viewModel, TESTITEM item[], bool doReset = false) - { - if (doReset) - { - viewModel->ButtonPressed->Execute(NumbersAndOperatorsEnum::Clear); - viewModel->ButtonPressed->Execute(NumbersAndOperatorsEnum::ClearEntry); - viewModel->ClearMemoryCommand->Execute(nullptr); - viewModel->Deserialize(ref new Platform::Array(0)); - } - - TESTITEM* currentItem = item; - - while (currentItem->command != NumbersAndOperatorsEnum::None) - { - Object^ commandParam = CommandParameterFromTestItem(currentItem); - viewModel->ButtonPressed->Execute(commandParam); - - if (currentItem->expectedPrimaryDisplay != L"N/A") - { - VERIFY_ARE_EQUAL(Platform::StringReference(currentItem->expectedPrimaryDisplay.c_str()), viewModel->DisplayValue); - } - if (currentItem->expectedExpressions != L"N/A" && viewModel->DisplayStringExpression != nullptr) - { - VERIFY_ARE_EQUAL(Platform::StringReference(currentItem->expectedExpressions.c_str()), viewModel->DisplayStringExpression); - } - currentItem++; - } - } - - class StandardViewModelUnitTests - { - public: - TEST_CLASS(StandardViewModelUnitTests); - - TEST_METHOD_SETUP(InitializeViewModel) - { - m_viewModel = ref new StandardCalculatorViewModel(); - m_viewModel->IsStandard = true; - m_engineResourceProvider = std::make_shared(); - m_decimalSeparator = ref new Platform::String(m_engineResourceProvider->GetCEngineString(L"sDecimal").c_str()); - return true; - } - - void ValidateViewModelValueAndExpression(String ^ value, String ^expression = nullptr) - { - String^ displayValue = m_viewModel->DisplayValue; - String^ displayExpression = m_viewModel->DisplayStringExpression; - if (value != nullptr) - { - VERIFY_ARE_EQUAL(value, displayValue); - } - - if (expression != nullptr) - { - VERIFY_ARE_EQUAL(expression, displayExpression); - } - } - - void ValidateViewModelValueAndSecondaryExpression(String ^ value, String ^expression = nullptr) - { - String^ displayValue = m_viewModel->DisplayValue; - - unsigned int nTokens = m_viewModel->ExpressionTokens->Size; - String^ displaySecondaryExpression = ref new String(); - - for (unsigned int i = 0; i < nTokens; ++i) - { - DisplayExpressionToken^ currentToken; - currentToken = m_viewModel->ExpressionTokens->GetAt(i); - displaySecondaryExpression = String::Concat(displaySecondaryExpression, currentToken->Token); - } - - if (value != nullptr) - { - VERIFY_ARE_EQUAL(value, displayValue); - } - - if (expression != nullptr) - { - VERIFY_ARE_EQUAL(expression, displaySecondaryExpression); - } - } - - TEST_METHOD(ViewModelConstructorDisplayValueAndExpressionInitializedTest) - { - StandardCalculatorViewModel^ vmconstructortest = ref new StandardCalculatorViewModel(); - vmconstructortest->IsStandard = true; - String^ displayValue = vmconstructortest->DisplayValue; - String^ displayExpression = vmconstructortest->DisplayStringExpression; - String^ calculationResultAutomationName = vmconstructortest->CalculationResultAutomationName; - - VERIFY_ARE_EQUAL(StringReference(L"0"), displayValue); - VERIFY_ARE_EQUAL(StringReference(L"Display is 0"), calculationResultAutomationName); - } - - TEST_METHOD(ViewModelConstructorButtonPressedInitializedTest) - { - StandardCalculatorViewModel^ vmconstructortest = ref new StandardCalculatorViewModel(); - vmconstructortest->IsStandard = true; - VERIFY_IS_NOT_NULL(vmconstructortest->ButtonPressed); - } - - /// Expression : 135 - TEST_METHOD(ButtonPressedLeftHandOperandEnteredTest) - { - TESTITEM items[] = { - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Three, L"13", L"" }, - { NumbersAndOperatorsEnum::Five, L"135", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items, true); - } - - /// Expression : 13. - TEST_METHOD(ButtonPressedLeftHandOperandAndDecimalEnteredTest) - { - TESTITEM items[] = { - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Three, L"13", L"" }, - { NumbersAndOperatorsEnum::Decimal, L"13" + std::wstring(m_decimalSeparator->Data()), L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items, true); - } - - /// Expression : 13== - TEST_METHOD(ButtonPressedLeftHandOperandAndEqualsEnteredTest) - { - TESTITEM items[] = { - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Three, L"13", L"" }, - { NumbersAndOperatorsEnum::Equals, L"13", L"" }, - { NumbersAndOperatorsEnum::Equals, L"13", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items, true); - } - - /// Expression : 13+ - TEST_METHOD(ButtonPressedLeftHandOperandAndOperationEnteredTest) - { - TESTITEM items[] = { - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Three, L"13", L"" }, - { NumbersAndOperatorsEnum::Add, L"13", L"13 + " }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items, true); - } - - /// Expression : 13+801 - TEST_METHOD(ButtonPressedRightHandOperandEnteredTest) - { - TESTITEM items[] = { - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Three, L"13", L"" }, - { NumbersAndOperatorsEnum::Add, L"13", L"13 + " }, - { NumbersAndOperatorsEnum::Eight, L"8", L"13 + " }, - { NumbersAndOperatorsEnum::Zero, L"80", L"13 + " }, - { NumbersAndOperatorsEnum::One, L"801", L"13 + " }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items, true); - } - - /// Expression : 1+2= - TEST_METHOD(ButtonPressedAdditionWithEqualsTest) - { - TESTITEM items[] = { - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Add, L"1", L"1 + " }, - { NumbersAndOperatorsEnum::Two, L"2", L"1 + " }, - { NumbersAndOperatorsEnum::Equals, L"3", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items, true); - } - - /// Expression : 1-2= - TEST_METHOD(ButtonPressedSubtractionWithEqualsTest) - { - TESTITEM items[] = { - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Subtract, L"1", L"1 - " }, - { NumbersAndOperatorsEnum::Two, L"2", L"1 - " }, - { NumbersAndOperatorsEnum::Equals, L"-1", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items, true); - } - - /// Expression : 3*5= - TEST_METHOD(ButtonPressedMultiplyWithEqualsTest) - { - TESTITEM items[] = { - { NumbersAndOperatorsEnum::Three, L"3", L"" }, - { NumbersAndOperatorsEnum::Multiply, L"3", L"3 * " }, - { NumbersAndOperatorsEnum::Five, L"5", L"3 * " }, - { NumbersAndOperatorsEnum::Equals, L"15", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items, true); - } - - /// Expression : 9/3= - TEST_METHOD(ButtonPressedDivideTest) - { - TESTITEM items[] = { - { NumbersAndOperatorsEnum::Nine, L"9", L"" }, - { NumbersAndOperatorsEnum::Divide, L"9", L"9 / " }, - { NumbersAndOperatorsEnum::Three, L"3", L"9 / " }, - { NumbersAndOperatorsEnum::Equals, L"3", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items, true); - } - - /// Expression : 7.555*3= - TEST_METHOD(ButtonPressedDecimalOperationTest) - { - TESTITEM items[] = { - { NumbersAndOperatorsEnum::Seven, L"7", L"" }, - { NumbersAndOperatorsEnum::Decimal, L"7" + std::wstring(m_decimalSeparator->Data()), L"" }, - { NumbersAndOperatorsEnum::Five, L"7" + std::wstring(m_decimalSeparator->Data()) + L"5", L"" }, - { NumbersAndOperatorsEnum::Five, L"7" + std::wstring(m_decimalSeparator->Data()) + L"55", L"" }, - { NumbersAndOperatorsEnum::Five, L"7" + std::wstring(m_decimalSeparator->Data()) + L"555", L"" }, - { NumbersAndOperatorsEnum::Multiply, L"7" + std::wstring(m_decimalSeparator->Data()) + L"555", L"7" + std::wstring(m_decimalSeparator->Data()) + L"555 * " }, - { NumbersAndOperatorsEnum::Three, L"3", L"7" + std::wstring(m_decimalSeparator->Data()) + L"555 * " }, - { NumbersAndOperatorsEnum::Equals, L"22" + std::wstring(m_decimalSeparator->Data()) + L"665", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items, true); - } - - /// Expression : 7/0 - TEST_METHOD(ButtonPressedDivideByZeroNegativeTest) - { - TESTITEM items[] = { - { NumbersAndOperatorsEnum::Seven, L"7", L"" }, - { NumbersAndOperatorsEnum::Divide, L"7", L"7 / " }, - { NumbersAndOperatorsEnum::Zero, L"0", L"7 / " }, - { NumbersAndOperatorsEnum::Equals, L"Cannot divide by zero", L"7 / " }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items, true); - } - - /// Expression : 8/2* - TEST_METHOD(ButtonPressedExpressionWithMultipleOperatorsTest) - { - TESTITEM items[] = { - { NumbersAndOperatorsEnum::Eight, L"8", L"" }, - { NumbersAndOperatorsEnum::Divide, L"8", L"8 / " }, - { NumbersAndOperatorsEnum::Two, L"2", L"8 / " }, - { NumbersAndOperatorsEnum::Multiply, L"4", L"8 / 2 * " }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items, true); - } - - /// Expression : 8/+*2* - TEST_METHOD(ButtonPressedExpressionWithMultipleOperatorsInSuccessionTest) - { - TESTITEM items[] = { - { NumbersAndOperatorsEnum::Eight, L"8", L"" }, - { NumbersAndOperatorsEnum::Divide, L"8", L"8 / " }, - { NumbersAndOperatorsEnum::Add, L"8", L"8 + " }, - { NumbersAndOperatorsEnum::Multiply, L"8", L"8 * " }, - { NumbersAndOperatorsEnum::Two, L"2", L"8 * " }, - { NumbersAndOperatorsEnum::Multiply, L"16", L"8 * 2 * " }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items, true); - } - - /// Expression : 8*2== - TEST_METHOD(ButtonPressedExpressionWithMultipleEqualsAfterEvaluateTest) - { - TESTITEM items[] = { - { NumbersAndOperatorsEnum::Eight, L"8", L"" }, - { NumbersAndOperatorsEnum::Multiply, L"8", L"8 * " }, - { NumbersAndOperatorsEnum::Two, L"2", L"8 * " }, - { NumbersAndOperatorsEnum::Equals, L"16", L"" }, - { NumbersAndOperatorsEnum::Equals, L"32", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items, true); - } - - /// Expression : 7-6 and Backspace - TEST_METHOD(ButtonPressedExpressionWithBackSpaceTest) - { - TESTITEM items[] = { - { NumbersAndOperatorsEnum::Seven, L"7", L"" }, - { NumbersAndOperatorsEnum::Subtract, L"7", L"7 - " }, - { NumbersAndOperatorsEnum::Six, L"6", L"7 - " }, - { NumbersAndOperatorsEnum::Backspace, L"0", L"7 - " }, - { NumbersAndOperatorsEnum::Backspace, L"0", L"7 - " }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items, true); - } - - /// Expression : 91-68 and Clear - TEST_METHOD(ButtonPressedExpressionWithClearTest) - { - TESTITEM items[] = { - { NumbersAndOperatorsEnum::Nine, L"9", L"" }, - { NumbersAndOperatorsEnum::One, L"91", L"" }, - { NumbersAndOperatorsEnum::Subtract, L"91", L"91 - " }, - { NumbersAndOperatorsEnum::Six, L"6", L"91 - " }, - { NumbersAndOperatorsEnum::Eight, L"68", L"91 - " }, - { NumbersAndOperatorsEnum::Clear, L"0", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items, true); - } - - /// - /// Paste tests - /// - template - void ValidateIntegralsAreEqual(NumbersAndOperatorsEnum a, NumbersAndOperatorsEnum b) - { - VERIFY_ARE_EQUAL(static_cast(a), static_cast(b)); - } - - void ValidateNumbersAndOperatorsAreEqual(NumbersAndOperatorsEnum a, NumbersAndOperatorsEnum b) - { - ValidateIntegralsAreEqual(a, b); - } - - /// Low-level test of character mapping - TEST_METHOD(VerifyCorrectCharacterMapping) - { - bool canSendNegate = false; - - // Valid numbers - NumbersAndOperatorsEnum n = m_viewModel->MapCharacterToButtonId(L'0', canSendNegate); - ValidateNumbersAndOperatorsAreEqual(n, NumbersAndOperatorsEnum::Zero); - - n = m_viewModel->MapCharacterToButtonId(L'1', canSendNegate); - ValidateNumbersAndOperatorsAreEqual(n, NumbersAndOperatorsEnum::One); - - // Valid operators - n = m_viewModel->MapCharacterToButtonId(L'+', canSendNegate); - ValidateNumbersAndOperatorsAreEqual(n, NumbersAndOperatorsEnum::Add); - - n = m_viewModel->MapCharacterToButtonId(L'=', canSendNegate); - ValidateNumbersAndOperatorsAreEqual(n, NumbersAndOperatorsEnum::Equals); - - n = m_viewModel->MapCharacterToButtonId(L'a', canSendNegate); - ValidateNumbersAndOperatorsAreEqual(n, NumbersAndOperatorsEnum::A); - - // Invalid character - n = m_viewModel->MapCharacterToButtonId(L'$', canSendNegate); - ValidateNumbersAndOperatorsAreEqual(n, NumbersAndOperatorsEnum::None); - } - - /// Various strings get pasted - TEST_METHOD(PasteExpressions) - { - m_viewModel->IsScientific = false; - - m_viewModel->OnPaste("-0.99", ViewMode::Standard); - ValidateViewModelValueAndExpression("-0" + m_decimalSeparator + "99", ""); - - m_viewModel->OnPaste("1+1=", ViewMode::Standard); - ValidateViewModelValueAndExpression("2", ""); - - // This result is not obvious: it's the result of the previous operation - m_viewModel->OnPaste("0=", ViewMode::Standard); - ValidateViewModelValueAndExpression("1", ""); - - // Negative value - m_viewModel->OnPaste("-1", ViewMode::Standard); - ValidateViewModelValueAndExpression("-1", ""); - - // Negated expression - m_viewModel->OnPaste("-(1+1)", ViewMode::Standard); - ValidateViewModelValueAndSecondaryExpression("-2", "negate(1 + 1)"); - - // More complicated Negated expression - m_viewModel->OnPaste("-(-(-1))", ViewMode::Standard); - ValidateViewModelValueAndSecondaryExpression("-1", "negate(0 - (0 - 1))"); - - // Switch to scientific mode - m_viewModel->IsScientific = true; - - VERIFY_IS_FALSE(m_viewModel->IsFToEChecked); - - //// Positive exponent - m_viewModel->OnPaste("1.23e+10", ViewMode::Scientific); - ValidateViewModelValueAndExpression("1" + m_decimalSeparator + "23e+10", ""); - - //// Negative exponent - m_viewModel->OnPaste("1.23e-10", ViewMode::Scientific); - ValidateViewModelValueAndExpression("1" + m_decimalSeparator + "23e-10", ""); - - //// Uppercase E (for exponent) - m_viewModel->OnPaste("1.23E-10", ViewMode::Scientific); - ValidateViewModelValueAndExpression("1" + m_decimalSeparator + "23e-10", ""); - } - - // Verify Calculator CalculationResultAutomationName is set correctly - TEST_METHOD(CalculationResultAutomationNameVerification) - { - TESTITEM items[] = { - { NumbersAndOperatorsEnum::IsStandardMode, L"0", L"" }, - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Two, L"12", L"" }, - { NumbersAndOperatorsEnum::Three, L"123", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items, true); - VERIFY_ARE_EQUAL(StringReference(L"Display is 123"), m_viewModel->CalculationResultAutomationName); - - TESTITEM items2[] = { - { NumbersAndOperatorsEnum::IsScientificMode, L"0", L"" }, - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Add, L"1", L"1 + " }, - { NumbersAndOperatorsEnum::Two, L"2", L"1 + " }, - { NumbersAndOperatorsEnum::Multiply, L"2", L"1 + 2 * " }, - { NumbersAndOperatorsEnum::Three, L"3", L"1 + 2 * " }, - { NumbersAndOperatorsEnum::Equals, L"7", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items2, true); - VERIFY_ARE_EQUAL(StringReference(L"Display is 7"), m_viewModel->CalculationResultAutomationName); - - TESTITEM items3[] = { - { NumbersAndOperatorsEnum::Clear, L"0", L"" }, - { NumbersAndOperatorsEnum::IsScientificMode, L"0", L"" }, - { NumbersAndOperatorsEnum::Five, L"5", L"" }, - { NumbersAndOperatorsEnum::InvSin, L"Invalid input", L"asind(5)" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items3, false); - VERIFY_ARE_EQUAL(StringReference(L"Display is Invalid input"), m_viewModel->CalculationResultAutomationName); - } - - // Switch Calculator Mode and verify if mode switch is happening as expected. - // Test precendence to check if mode switch is happening - // Standard mode 1+2*3 = 9; Scientific mode 1+2*3 = 7 - // Intermediate value is also different. after 1 + 2 * , standard shows 3, scientific shows 2 - TEST_METHOD(ButtonPressedCalculatorModeSwitch) - { - TESTITEM items[] = { - { NumbersAndOperatorsEnum::IsStandardMode, L"0", L"" }, - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Add, L"1", L"1 + " }, - { NumbersAndOperatorsEnum::Two, L"2", L"1 + " }, - { NumbersAndOperatorsEnum::Multiply, L"3", L"1 + 2 * " }, - { NumbersAndOperatorsEnum::Three, L"3", L"1 + 2 * " }, - { NumbersAndOperatorsEnum::Equals, L"9", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items, true); - - TESTITEM items2[] = { - { NumbersAndOperatorsEnum::IsScientificMode, L"0", L"" }, - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Add, L"1", L"1 + " }, - { NumbersAndOperatorsEnum::Two, L"2", L"1 + " }, - { NumbersAndOperatorsEnum::Multiply, L"2", L"1 + 2 * " }, - { NumbersAndOperatorsEnum::Three, L"3", L"1 + 2 * " }, - { NumbersAndOperatorsEnum::Equals, L"7", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items2, true); - } - - // Test AutoConvertedValue - TEST_METHOD(ProgrammerModeAutoConvertedValue) - { - TESTITEM none[] = { - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, none, true); - m_viewModel->IsProgrammer = true; - TESTITEM items[] = { - { NumbersAndOperatorsEnum::HexButton, L"0", L"" }, - { NumbersAndOperatorsEnum::F, L"F", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items, false); - VERIFY_ARE_EQUAL(Utils::GetStringValue(m_viewModel->HexDisplayValue), StringReference(L"F")); - VERIFY_ARE_EQUAL(Utils::GetStringValue(m_viewModel->DecimalDisplayValue), StringReference(L"15")); - VERIFY_ARE_EQUAL(Utils::GetStringValue(m_viewModel->OctalDisplayValue), StringReference(L"17")); - VERIFY_ARE_EQUAL(Utils::GetStringValue(m_viewModel->BinaryDisplayValue), StringReference(L"1111")); - } - - // Test Button disabling in different Radixes - TEST_METHOD(ProgrammerModeButtonsDisable) - { - /* m_viewModel->IsProgrammer = true; - m_viewModel->SwitchProgrammerModeBase(OCT_RADIX); - VERIFY_IS_TRUE(m_viewModel->AreOCTButtonsEnabled); - VERIFY_IS_FALSE(m_viewModel->AreHEXButtonsEnabled); - VERIFY_IS_FALSE(m_viewModel->AreDECButtonsEnabled); - m_viewModel->SwitchProgrammerModeBase(DEC_RADIX); - VERIFY_IS_FALSE(m_viewModel->AreHEXButtonsEnabled); - VERIFY_IS_TRUE(m_viewModel->AreDECButtonsEnabled); - VERIFY_IS_TRUE(m_viewModel->AreOCTButtonsEnabled); - m_viewModel->SwitchProgrammerModeBase(HEX_RADIX); - VERIFY_IS_TRUE(m_viewModel->AreHEXButtonsEnabled); - VERIFY_IS_TRUE(m_viewModel->AreDECButtonsEnabled); - VERIFY_IS_TRUE(m_viewModel->AreOCTButtonsEnabled); - m_viewModel->SwitchProgrammerModeBase(BIN_RADIX); - VERIFY_IS_FALSE(m_viewModel->AreHEXButtonsEnabled); - VERIFY_IS_FALSE(m_viewModel->AreDECButtonsEnabled); - VERIFY_IS_FALSE(m_viewModel->AreOCTButtonsEnabled);*/ - - } - - // Test digit grouping for different radix in programmer mode - TEST_METHOD(ProgrammerModeRadixGrouping) - { - TESTITEM none[] = { - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, none, true); - m_viewModel->IsProgrammer = true; - TESTITEM items[] = { - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Two, L"12", L"" }, - { NumbersAndOperatorsEnum::Three, L"123", L"" }, - { NumbersAndOperatorsEnum::Four, L"1,234", L"" }, - { NumbersAndOperatorsEnum::Five, L"12,345", L"" }, - { NumbersAndOperatorsEnum::Six, L"123,456", L"" }, - { NumbersAndOperatorsEnum::Seven, L"1,234,567", L"" }, - { NumbersAndOperatorsEnum::Eight, L"12,345,678", L"" }, - { NumbersAndOperatorsEnum::Nine, L"123,456,789", L"" }, - { NumbersAndOperatorsEnum::None, L"1", L"" }, - }; - ValidateViewModelByCommands(m_viewModel, items, true); - VERIFY_ARE_EQUAL(Utils::GetStringValue(m_viewModel->HexDisplayValue), StringReference(L"75B CD15")); - VERIFY_ARE_EQUAL(Utils::GetStringValue(m_viewModel->DecimalDisplayValue), StringReference(L"123,456,789")); - VERIFY_ARE_EQUAL(Utils::GetStringValue(m_viewModel->OctalDisplayValue), StringReference(L"726 746 425")); - VERIFY_ARE_EQUAL(Utils::GetStringValue(m_viewModel->BinaryDisplayValue), StringReference(L"0111 0101 1011 1100 1101 0001 0101")); - } - - // Test Not functionality - TEST_METHOD(ProgrammerModeNot) - { - TESTITEM none[] = { - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, none, true); - m_viewModel->IsProgrammer = true; - TESTITEM items[] = { - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Not, L"-2", L"~(1)" }, - { NumbersAndOperatorsEnum::None, L"N/A", L"N/A" } - }; - ValidateViewModelByCommands(m_viewModel, items, false); - VERIFY_ARE_EQUAL(Utils::GetStringValue(m_viewModel->HexDisplayValue), StringReference(L"FFFF FFFF FFFF FFFE")); - VERIFY_ARE_EQUAL(Utils::GetStringValue(m_viewModel->DecimalDisplayValue), StringReference(L"-2")); - VERIFY_ARE_EQUAL(Utils::GetStringValue(m_viewModel->OctalDisplayValue), StringReference(L"1 777 777 777 777 777 777 776")); - VERIFY_ARE_EQUAL(Utils::GetStringValue(m_viewModel->BinaryDisplayValue), StringReference(L"1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1110")); - VERIFY_ARE_EQUAL(m_viewModel->DisplayValue, StringReference(L"-2")); - } - - // Test And Or functionality - TEST_METHOD(ProgrammerModeAndOr) - { - TESTITEM none[] = { - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, none, true); - m_viewModel->IsProgrammer = true; - - TESTITEM items[] = { - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Or, L"1", L"1 ||" }, - { NumbersAndOperatorsEnum::Two, L"2", L"1 ||" }, - { NumbersAndOperatorsEnum::Equals, L"3", L"" }, - { NumbersAndOperatorsEnum::None, L"3", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items, false); - - TESTITEM items2[] = { - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::And, L"1", L"1 &" }, - { NumbersAndOperatorsEnum::Two, L"2", L"1 &" }, - { NumbersAndOperatorsEnum::Equals, L"0", L"" }, - { NumbersAndOperatorsEnum::None, L"0", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items2, false); - } - - // Test CE and C buttons functionality - TEST_METHOD(ProgrammerModeClear) - { - TESTITEM none[] = { - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, none, true); - m_viewModel->IsProgrammer = true; - - TESTITEM items[] = { - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Or, L"1", L"1 ||" }, - { NumbersAndOperatorsEnum::Two, L"2", L"1 ||" }, - { NumbersAndOperatorsEnum::ClearEntry, L"0", L"1 ||" }, - { NumbersAndOperatorsEnum::None, L"", L"1 ||" } - }; - ValidateViewModelByCommands(m_viewModel, items, false); - - TESTITEM items2[] = { - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::And, L"1", L"1 &" }, - { NumbersAndOperatorsEnum::Two, L"2", L"1 &" }, - { NumbersAndOperatorsEnum::Clear, L"0", L"" }, - { NumbersAndOperatorsEnum::None, L"0", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items2, false); - } - - // Test unary operators - TEST_METHOD(ButtonPressedUnaryOperatorTest) - { - TESTITEM items[] = { - { NumbersAndOperatorsEnum::IsStandardMode, L"0", L"" }, - { NumbersAndOperatorsEnum::Five, L"5", L"" }, - { NumbersAndOperatorsEnum::Invert, L"0" + std::wstring(m_decimalSeparator->Data()) + L"2", L"reciproc(5)" }, - { NumbersAndOperatorsEnum::Equals, L"0" + std::wstring(m_decimalSeparator->Data()) + L"2", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items, true); - - TESTITEM items2[] = { - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Six, L"16", L"" }, - { NumbersAndOperatorsEnum::Sqrt, L"4", L"sqrt(16)" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items2, false); - - TESTITEM items3[] = { - { NumbersAndOperatorsEnum::Six, L"6", L"" }, - { NumbersAndOperatorsEnum::Negate, L"-6", L"" }, - { NumbersAndOperatorsEnum::Nine, L"-69", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items3, false); - - TESTITEM items4[] = { - { NumbersAndOperatorsEnum::Clear, L"0", L"" }, - { NumbersAndOperatorsEnum::IsScientificMode, L"0", L"" }, - { NumbersAndOperatorsEnum::Five, L"5", L"" }, - { NumbersAndOperatorsEnum::InvSin, L"Invalid input", L"asind(5)" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items4, false); - - TESTITEM items5[] = { - { NumbersAndOperatorsEnum::Clear, L"0", L"" }, - { NumbersAndOperatorsEnum::Four, L"4", L"" }, - { NumbersAndOperatorsEnum::Factorial, L"24", L"fact(4)" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items5, false); - } - - // IsMemoryEmpty Property - TEST_METHOD(IsMemoryEmptyTest) - { - StandardCalculatorViewModel^ viewModel = ref new StandardCalculatorViewModel(); - viewModel->IsStandard = true; - VERIFY_ARE_EQUAL(static_cast(0), viewModel->MemorizedNumbers->Size); - viewModel->OnMemoryButtonPressed(); - VERIFY_ARE_EQUAL(static_cast(1), viewModel->MemorizedNumbers->Size); - viewModel->ClearMemoryCommand->Execute(nullptr); - VERIFY_ARE_EQUAL(static_cast(0), viewModel->MemorizedNumbers->Size); - } - - // IsOperatorCommand Property - TEST_METHOD(IsOperatorCommandTest) - { - StandardCalculatorViewModel^ viewModel = ref new StandardCalculatorViewModel(); - viewModel->IsStandard = true; - viewModel->ButtonPressed->Execute(NumbersAndOperatorsEnum::One); - VERIFY_ARE_EQUAL(viewModel->IsOperatorCommand, false); - viewModel->ButtonPressed->Execute(NumbersAndOperatorsEnum::Two); - VERIFY_ARE_EQUAL(viewModel->IsOperatorCommand, false); - viewModel->ButtonPressed->Execute(NumbersAndOperatorsEnum::Three); - VERIFY_ARE_EQUAL(viewModel->IsOperatorCommand, false); - viewModel->ButtonPressed->Execute(NumbersAndOperatorsEnum::Four); - VERIFY_ARE_EQUAL(viewModel->IsOperatorCommand, false); - viewModel->ButtonPressed->Execute(NumbersAndOperatorsEnum::Five); - VERIFY_ARE_EQUAL(viewModel->IsOperatorCommand, false); - viewModel->ButtonPressed->Execute(NumbersAndOperatorsEnum::Six); - VERIFY_ARE_EQUAL(viewModel->IsOperatorCommand, false); - viewModel->ButtonPressed->Execute(NumbersAndOperatorsEnum::Seven); - VERIFY_ARE_EQUAL(viewModel->IsOperatorCommand, false); - viewModel->ButtonPressed->Execute(NumbersAndOperatorsEnum::Eight); - VERIFY_ARE_EQUAL(viewModel->IsOperatorCommand, false); - viewModel->ButtonPressed->Execute(NumbersAndOperatorsEnum::Nine); - VERIFY_ARE_EQUAL(viewModel->IsOperatorCommand, false); - viewModel->ButtonPressed->Execute(NumbersAndOperatorsEnum::Decimal); - VERIFY_ARE_EQUAL(viewModel->IsOperatorCommand, false); - viewModel->ButtonPressed->Execute(NumbersAndOperatorsEnum::Zero); - VERIFY_ARE_EQUAL(viewModel->IsOperatorCommand, false); - viewModel->ButtonPressed->Execute(NumbersAndOperatorsEnum::Multiply); - VERIFY_ARE_EQUAL(viewModel->IsOperatorCommand, true); - viewModel->ButtonPressed->Execute(NumbersAndOperatorsEnum::Add); - VERIFY_ARE_EQUAL(viewModel->IsOperatorCommand, true); - viewModel->ButtonPressed->Execute(NumbersAndOperatorsEnum::Zero); - VERIFY_ARE_EQUAL(viewModel->IsOperatorCommand, false); - } - - //When memory button is pressed - verify if display value is being stored in vector - TEST_METHOD(OnMemoryButtonPressed) - { - StandardCalculatorViewModel^ viewModel = ref new StandardCalculatorViewModel(); - viewModel->IsStandard = true; - viewModel->DisplayValue = L"1001"; - viewModel->OnMemoryButtonPressed(); - viewModel->OnMemoryButtonPressed(); - VERIFY_ARE_EQUAL((int)viewModel->MemorizedNumbers->Size, 2); - } - - //when memory list is empty and M+ is pressed - TEST_METHOD(OnMemoryAddWhenMemoryEmpty) - { - m_viewModel->IsStandard = true; - TESTITEM items[] = { - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Zero, L"10", L"" }, - { NumbersAndOperatorsEnum::Zero, L"100", L"" }, - { NumbersAndOperatorsEnum::One, L"1,001", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items, true); - m_viewModel->OnMemoryAdd(ref new Platform::Box(0)); - m_viewModel->OnMemoryItemPressed(ref new Platform::Box(0)); - VERIFY_ARE_EQUAL(Platform::StringReference(L"1,001"), m_viewModel->DisplayValue); - } - - - //when memory list is empty and M- is pressed - TEST_METHOD(OnMemorySubtractWhenMemoryEmpty) - { - m_viewModel->IsStandard = true; - TESTITEM items[] = { - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Zero, L"10", L"" }, - { NumbersAndOperatorsEnum::Zero, L"100", L"" }, - { NumbersAndOperatorsEnum::One, L"1,001", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items, true); - m_viewModel->OnMemorySubtract(ref new Platform::Box(0)); - m_viewModel->OnMemoryItemPressed(ref new Platform::Box(0)); - VERIFY_ARE_EQUAL(Platform::StringReference(L"-1,001"), m_viewModel->DisplayValue); - } - - //when negative number is saved in memory - TEST_METHOD(OnNegativeEntryInMemory) - { - ChangeMode(m_viewModel, 0/*Standard*/); - TESTITEM items[] = { - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Zero, L"10", L"" }, - { NumbersAndOperatorsEnum::Zero, L"100", L"" }, - { NumbersAndOperatorsEnum::One, L"1,001", L"" }, - { NumbersAndOperatorsEnum::Negate, L"N/A", L"N/A" }, - { NumbersAndOperatorsEnum::None, L"", L"" }, - }; - ValidateViewModelByCommands(m_viewModel, items, true); - m_viewModel->OnMemoryButtonPressed(); - m_viewModel->OnMemoryItemPressed(ref new Platform::Box(0)); - VERIFY_ARE_EQUAL(Platform::StringReference(L"-1,001"), m_viewModel->DisplayValue); - MemoryItemViewModel^ memorySlotStandard = (MemoryItemViewModel^)m_viewModel->MemorizedNumbers->GetAt(0); - VERIFY_ARE_EQUAL(Platform::StringReference(L"-1,001"), Utils::GetStringValue(memorySlotStandard->Value)); - ChangeMode(m_viewModel, 1/*scientific*/); - MemoryItemViewModel^ memorySlotScientific = (MemoryItemViewModel^)m_viewModel->MemorizedNumbers->GetAt(0); - VERIFY_ARE_EQUAL(Platform::StringReference(L"-1,001"), Utils::GetStringValue(memorySlotScientific->Value)); - ChangeMode(m_viewModel, 2/*Programmer*/); - MemoryItemViewModel^ memorySlotProgrammer = (MemoryItemViewModel^)m_viewModel->MemorizedNumbers->GetAt(0); - VERIFY_ARE_EQUAL(Platform::StringReference(L"-1,001"), Utils::GetStringValue(memorySlotProgrammer->Value)); - } - - //when decimal number is saved in memory - TEST_METHOD(OnDecimalEntryInMemory) - { - ChangeMode(m_viewModel, 0/*Standard*/); - TESTITEM items[] = { - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Zero, L"10", L"" }, - { NumbersAndOperatorsEnum::Zero, L"100", L"" }, - { NumbersAndOperatorsEnum::One, L"1,001", L"" }, - { NumbersAndOperatorsEnum::Decimal, L"1,001.", L"" }, - { NumbersAndOperatorsEnum::One, L"1,001.1", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" }, - }; - ValidateViewModelByCommands(m_viewModel, items, true); - m_viewModel->OnMemoryButtonPressed(); - m_viewModel->OnMemoryItemPressed(ref new Platform::Box(0)); - VERIFY_ARE_EQUAL(Platform::StringReference(L"1,001.1"), m_viewModel->DisplayValue); - MemoryItemViewModel^ memorySlotStandard = (MemoryItemViewModel^)m_viewModel->MemorizedNumbers->GetAt(0); - VERIFY_ARE_EQUAL(Platform::StringReference(L"1,001.1"), Utils::GetStringValue(memorySlotStandard->Value)); - ChangeMode(m_viewModel, 1/*Scientific*/); - MemoryItemViewModel^ memorySlotScientific = (MemoryItemViewModel^)m_viewModel->MemorizedNumbers->GetAt(0); - VERIFY_ARE_EQUAL(Platform::StringReference(L"1,001.1"), Utils::GetStringValue(memorySlotScientific->Value)); - ChangeMode(m_viewModel, 2/*Programmer*/); - MemoryItemViewModel^ memorySlotProgrammer = (MemoryItemViewModel^)m_viewModel->MemorizedNumbers->GetAt(0); - VERIFY_ARE_EQUAL(Platform::StringReference(L"1,001"), Utils::GetStringValue(memorySlotProgrammer->Value)); - } - - //when negative decimal number is saved in memory - TEST_METHOD(OnNegativeDecimalInMemory) - { - m_viewModel->IsStandard = true; - TESTITEM items[] = { - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Zero, L"10", L"" }, - { NumbersAndOperatorsEnum::Zero, L"100", L"" }, - { NumbersAndOperatorsEnum::One, L"1,001", L"" }, - { NumbersAndOperatorsEnum::Decimal, L"1,001.", L"" }, - { NumbersAndOperatorsEnum::One, L"1,001.1", L"" }, - { NumbersAndOperatorsEnum::Negate, L"N/A", L"N/A" }, - { NumbersAndOperatorsEnum::None, L"", L"" }, - }; - ValidateViewModelByCommands(m_viewModel, items, true); - m_viewModel->OnMemoryButtonPressed(); - m_viewModel->OnMemoryItemPressed(ref new Platform::Box(0)); - VERIFY_ARE_EQUAL(Platform::StringReference(L"-1,001.1"), m_viewModel->DisplayValue); - } - - //when decimal number is added to the memory - TEST_METHOD(OnDecimalAddedToMemory) - { - m_viewModel->IsStandard = true; - TESTITEM items[] = { - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Zero, L"10", L"" }, - { NumbersAndOperatorsEnum::Zero, L"100", L"" }, - { NumbersAndOperatorsEnum::One, L"1,001", L"" }, - { NumbersAndOperatorsEnum::Decimal, L"1,001.", L"" }, - { NumbersAndOperatorsEnum::One, L"1,001.1", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" }, - }; - ValidateViewModelByCommands(m_viewModel, items, true); - m_viewModel->OnMemoryButtonPressed(); - TESTITEM items2[] = { - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Zero, L"10", L"" }, - { NumbersAndOperatorsEnum::Zero, L"100", L"" }, - { NumbersAndOperatorsEnum::One, L"1,001", L"" }, - { NumbersAndOperatorsEnum::Decimal, L"1,001.", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" }, - }; - ValidateViewModelByCommands(m_viewModel, items2, false); - m_viewModel->OnMemoryButtonPressed(); - m_viewModel->OnMemoryAdd(1); - m_viewModel->OnMemoryItemPressed(1); - VERIFY_ARE_EQUAL(Platform::StringReference(L"2,002.1"), m_viewModel->DisplayValue); - } - - //when memory is saved in programmer as Hex value and then we switch to standard mode, test to see that memory gets converted to decimal - TEST_METHOD(OnMemorySavedInHexRadixAndSwitchedToStandardMode) - { - ChangeMode(m_viewModel, 2/*programmer*/); - TESTITEM items[] = { - { NumbersAndOperatorsEnum::HexButton, L"0", L"" }, - { NumbersAndOperatorsEnum::F, L"F", L"" }, - { NumbersAndOperatorsEnum::F, L"FF", L"" }, - { NumbersAndOperatorsEnum::None, L"FF", L"" }, - }; - ValidateViewModelByCommands(m_viewModel, items, true); - m_viewModel->OnMemoryButtonPressed(); - ChangeMode(m_viewModel, 1/*Scientific*/); - m_viewModel->OnMemoryItemPressed(ref new Box(0)); - VERIFY_ARE_EQUAL(Platform::StringReference(L"255"), m_viewModel->DisplayValue); - MemoryItemViewModel^ memorySlot = (MemoryItemViewModel^)m_viewModel->MemorizedNumbers->GetAt(0); - VERIFY_ARE_EQUAL(Platform::StringReference(L"255"), Utils::GetStringValue(memorySlot->Value)); - } - - - TEST_METHOD(OnMemorySavedInHexRadixAndRadixChanges) - { - ChangeMode(m_viewModel, 2/*programmer*/); - TESTITEM items[] = { - { NumbersAndOperatorsEnum::HexButton, L"0", L"" }, - { NumbersAndOperatorsEnum::F, L"F", L"" }, - { NumbersAndOperatorsEnum::F, L"FF", L"" }, - { NumbersAndOperatorsEnum::None, L"FF", L"" }, - }; - ValidateViewModelByCommands(m_viewModel, items, true); - m_viewModel->OnMemoryButtonPressed(); - m_viewModel->SwitchProgrammerModeBase(RADIX_TYPE::OCT_RADIX); - MemoryItemViewModel^ memorySlotOct = (MemoryItemViewModel^)m_viewModel->MemorizedNumbers->GetAt(0); - VERIFY_ARE_EQUAL(Platform::StringReference(L"377"), Utils::GetStringValue(memorySlotOct->Value)); - m_viewModel->SwitchProgrammerModeBase(RADIX_TYPE::DEC_RADIX); - MemoryItemViewModel^ memorySlotDec = (MemoryItemViewModel^)m_viewModel->MemorizedNumbers->GetAt(0); - VERIFY_ARE_EQUAL(Platform::StringReference(L"255"), Utils::GetStringValue(memorySlotDec->Value)); - m_viewModel->SwitchProgrammerModeBase(RADIX_TYPE::BIN_RADIX); - MemoryItemViewModel^ memorySlotBin = (MemoryItemViewModel^)m_viewModel->MemorizedNumbers->GetAt(0); - VERIFY_ARE_EQUAL(Platform::StringReference(L"1111 1111"), Utils::GetStringValue(memorySlotBin->Value)); - - } - - //When memory button is pressed more than max number of slots allowed, - //the MemorizedNumbers vector size should not increase. - TEST_METHOD(OnMemoryButtonPressedMaxTimes) - { - StandardCalculatorViewModel^ viewModel = ref new StandardCalculatorViewModel(); - viewModel->IsStandard = true; - viewModel->DisplayValue = L"1001"; - for (int i = 0; i < 110; i++) - { - viewModel->OnMemoryButtonPressed(); - } - VERIFY_ARE_EQUAL((int)viewModel->MemorizedNumbers->Size, 100); - } - - // When memory slot is pressed verify if the display value is updated correctly - TEST_METHOD(OnMemoryItemPressed) - { - TESTITEM items[] = { - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Zero, L"10", L"" }, - { NumbersAndOperatorsEnum::Zero, L"100", L"" }, - { NumbersAndOperatorsEnum::One, L"1,001", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items, true); - - m_viewModel->OnMemoryButtonPressed(); - - TESTITEM items2[] = { - { NumbersAndOperatorsEnum::Two, L"2", L"" }, - { NumbersAndOperatorsEnum::Zero, L"20", L"" }, - { NumbersAndOperatorsEnum::Zero, L"200", L"" }, - { NumbersAndOperatorsEnum::Two, L"2,002", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items2, false); - - m_viewModel->OnMemoryButtonPressed(); - m_viewModel->OnMemoryItemPressed(1); - - VERIFY_ARE_EQUAL(Platform::StringReference(L"1,001"), m_viewModel->DisplayValue); - } - - // verify nothing happens if there is no memory and the memory slot pressed action is taken - TEST_METHOD(OnMemoryItemPressedNoMemory) - { - TESTITEM items[] = { - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Two, L"12", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items, true); - - m_viewModel->OnMemoryItemPressed(ref new Platform::Box(0)); - - VERIFY_ARE_EQUAL(StringReference(L"12"), m_viewModel->DisplayValue); - VERIFY_ARE_EQUAL((UINT)0, m_viewModel->MemorizedNumbers->Size); - } - - // When memory slot is pressed verify if the display value is updated correctly - TEST_METHOD(OnMemoryItemAddAndSubtract) - { - TESTITEM items[] = { - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Zero, L"10", L"" }, - { NumbersAndOperatorsEnum::Zero, L"100", L"" }, - { NumbersAndOperatorsEnum::One, L"1,001", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items, true); - - m_viewModel->OnMemoryButtonPressed(); - - TESTITEM items2[] = { - { NumbersAndOperatorsEnum::Two, L"2", L"" }, - { NumbersAndOperatorsEnum::Zero, L"20", L"" }, - { NumbersAndOperatorsEnum::Zero, L"200", L"" }, - { NumbersAndOperatorsEnum::Two, L"2,002", L"" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items2, false); - - m_viewModel->OnMemoryButtonPressed(); - m_viewModel->OnMemoryItemPressed(1); - m_viewModel->OnMemoryAdd(ref new Platform::Box(0)); - MemoryItemViewModel^ memorySlot = (MemoryItemViewModel^)m_viewModel->MemorizedNumbers->GetAt(0); - VERIFY_ARE_EQUAL(Platform::StringReference(L"3,003"), Utils::GetStringValue(memorySlot->Value)); - } - - // Verify that raw, unformatted numbers are provided correctly - TEST_METHOD(VerifyRawFormatting) - { - m_viewModel->DisplayValue = L"1,001"; - VERIFY_ARE_EQUAL(StringReference(L"1001"), m_viewModel->GetRawDisplayValue()); - - m_viewModel->DisplayValue = L"999"; - VERIFY_ARE_EQUAL(StringReference(L"999"), m_viewModel->GetRawDisplayValue()); - - m_viewModel->DisplayValue = L"1,001,001"; - VERIFY_ARE_EQUAL(StringReference(L"1001001"), m_viewModel->GetRawDisplayValue()); - - m_viewModel->DisplayValue = L"1,001, 001"; - VERIFY_ARE_EQUAL(StringReference(L"1001001"), m_viewModel->GetRawDisplayValue()); - - } - - TEST_METHOD(VerifyAnnouncementAfterBinaryOperatorReceived) - { - TESTITEM items[] = { - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Zero, L"10", L"" }, - { NumbersAndOperatorsEnum::Zero, L"100", L"" }, - { NumbersAndOperatorsEnum::One, L"1,001", L"" }, - { NumbersAndOperatorsEnum::Multiply, L"1,001", L"1001 x" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items, true); - - VERIFY_ARE_EQUAL(StringReference(L"Display is 1,001 times"), m_viewModel->Announcement->Announcement); - } - - TEST_METHOD(VerifyAnnouncementAfterMultipleBinaryOperatorsReceived) - { - TESTITEM items[] = { - { NumbersAndOperatorsEnum::One, L"1", L"" }, - { NumbersAndOperatorsEnum::Zero, L"10", L"" }, - { NumbersAndOperatorsEnum::Zero, L"100", L"" }, - { NumbersAndOperatorsEnum::One, L"1,001", L"" }, - { NumbersAndOperatorsEnum::Multiply, L"1,001", L"1001 x" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items, true); - - VERIFY_ARE_EQUAL(StringReference(L"Display is 1,001 times"), m_viewModel->Announcement->Announcement); - - - TESTITEM items2[] = { - { NumbersAndOperatorsEnum::Divide, L"1,001", L"1001 ÷" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items2, false /*reset*/); - - VERIFY_ARE_EQUAL(StringReference(L"Display is 1,001 divided by"), m_viewModel->Announcement->Announcement); - - TESTITEM items3[] = { - { NumbersAndOperatorsEnum::Add, L"1,001", L"1001 +" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items3, false /*reset*/); - - VERIFY_ARE_EQUAL(StringReference(L"Display is 1,001 plus"), m_viewModel->Announcement->Announcement); - - - TESTITEM items4[] = { - { NumbersAndOperatorsEnum::Subtract, L"1,001", L"1001 x" }, - { NumbersAndOperatorsEnum::None, L"", L"" } - }; - ValidateViewModelByCommands(m_viewModel, items4, false /*reset*/); - - VERIFY_ARE_EQUAL(StringReference(L"Display is 1,001 minus"), m_viewModel->Announcement->Announcement); - } - - private: - StandardCalculatorViewModel^ m_viewModel; - std::shared_ptr m_engineResourceProvider; - Platform::String^ m_decimalSeparator; - }; -} - diff --git a/internal/CalculatorUnitTests/Test.resw b/internal/CalculatorUnitTests/Test.resw deleted file mode 100644 index 5cb77d9..0000000 --- a/internal/CalculatorUnitTests/Test.resw +++ /dev/null @@ -1,440 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - -4046.8564224 - -1 - -0.09290304 - -0.83612736 - -0.000001 - -0.0001 - -0.00064516 - -2589988.110336 - -1000000 - -10000 - -0.012516104 - -0.06032246 - -10869.66 - -100000 - -0.000000125 - -0.000001 - -0.001 - -1 - -1000 - -1000000 - -1000000000 - -1000000000000 - -1000000000000000 - -1000000000000000000 - -0.000125 - -0.125 - -125 - -125000 - -125000000 - -125000000000 - -125000000000000 - -125000000000000000 - -134.217728 - -1073.741824 - -0.000128 - -0.001024 - -0.131072 - -1.048576 - -140737488.355328 - -1125899906.842624 - -137438.953472 - -1099511.627776 - -144115188075.855872 - -1152921504606.846976 - -147573952589676.412928 - -1180591620717411.303424 - -151115727451828646.838272 - -1208925819614629174.706176 - -1.509949 - -734.003200 - -5046.586573 - -4.184 - -4184 - -1055.056 - -1000 - -0.0000000000000000001602176565 - -1 - -1.3558179483314 - -9000 - -439614 - -1046700 - -0.0254 - -0.3048 - -0.9144 - -1609.344 - -0.000001 - -0.001 - -0.000000001 - -0.01 - -1 - -1000 - -1852 - -0.035052 - -0.18669 - -76 - -17.58426666666667 - -0.0225969658055233 - -1 - -1000 - -745.69987158227022 - -60 - -745.7 - -2982799.486329081 - -86400 - -1 - -604800 - -31557600 - -0.001 - -0.000001 - -60 - -3600 - -236.588237 - -473.176473 - -568.26125 - -946.352946 - -1136.5225 - -3785.411784 - -4546.09 - -1000 - -4.928922 - -14.786765 - -1 - -764554.857984 - -1000000 - -1 - -16.387064 - -28316.846592 - -29.5735295625 - -28.4130625 - -5.91938802083333333333 - -17.7581640625 - -236.5882 - -378541.2 - -3750000000 - -1 - -0.1 - -0.01 - -0.001 - -0.45359237 - -0.028349523125 - -0.000001 - -0.00001 - -0.0001 - -1016.0469088 - -1000 - -6.35029318 - -0.0002 - -907.18474 - -0.000002 - -0.4325 - -4000 - -90000 - -1 - -30.48 - -27.777777777777777777778 - -51.44 - -34030 - -100 - -44.7 - -8.94 - -2011.5 - -24585 - -1 - -57.29577951308233 - -0.9 - -1 - -0.9869232667160128 - -0.0098692326671601 - -0.0013155687145324 - -9.869232667160128e-6 - -0.068045961016531 - - 0.002 - - - 1 - - - 1 - - - 1000 - - - 1 - - - 0.003 - - \ No newline at end of file diff --git a/internal/CalculatorUnitTests/UnitConverterTest.cpp b/internal/CalculatorUnitTests/UnitConverterTest.cpp deleted file mode 100644 index 8c002d6..0000000 --- a/internal/CalculatorUnitTests/UnitConverterTest.cpp +++ /dev/null @@ -1,600 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#include "pch.h" - -#include - -using namespace UnitConversionManager; -using namespace std; - -namespace UnitConverterUnitTests -{ - - void SetUnitParams(Unit* type, int id, wstring name, wstring abbreviation, bool conversionSource, bool conversionTarget, bool isWhimsical) - { - type->id = id; - type->name = name; - type->abbreviation = abbreviation; - type->isConversionSource = conversionSource; - type->isConversionTarget = conversionTarget; - type->isWhimsical = isWhimsical; - } - - void SetCategoryParams(Category* type, int id, wstring name, bool supportsNegative) - { - type->id = id; - type->name = name; - type->supportsNegative = supportsNegative; - } - - void SetConversionDataParams(ConversionData* type, double ratio, double offset, bool offsetFirst) - { - type->ratio = ratio; - type->offset = offset; - type->offsetFirst = offsetFirst; - } - - class TestUnitConverterConfigLoader : public IConverterDataLoader - { - public: - TestUnitConverterConfigLoader() : - m_loadDataCallCount(0) - { - Category c1, c2; - SetCategoryParams(&c1, 1, L"Length", true); - SetCategoryParams(&c2, 2, L"Weight", false); - m_categories.push_back(c1); - m_categories.push_back(c2); - - Unit u1, u2, u3, u4; - SetUnitParams(&u1, 1, L"Inches", L"In", true, true, false); - SetUnitParams(&u2, 2, L"Feet", L"Ft", false, false, false); - SetUnitParams(&u3, 3, L"Pounds", L"Lb", true, true, false); - SetUnitParams(&u4, 4, L"Kilograms", L"Kg", false, false, false); - - vector c1units = vector(); - vector c2units = vector(); - c1units.push_back(u1); - c1units.push_back(u2); - c2units.push_back(u3); - c2units.push_back(u4); - - m_units[c1] = c1units; - m_units[c2] = c2units; - - unordered_map unit1Map = unordered_map(); - unordered_map unit2Map = unordered_map(); - unordered_map unit3Map = unordered_map(); - unordered_map unit4Map = unordered_map(); - - ConversionData conversion1, conversion2, conversion3, conversion4, conversion5; - SetConversionDataParams(&conversion1, 1.0, 0, false); - SetConversionDataParams(&conversion2, 0.08333333333333333333333333333333, 0, false); - SetConversionDataParams(&conversion3, 12.0, 0, false); - SetConversionDataParams(&conversion4, 0.453592, 0, false); - SetConversionDataParams(&conversion5, 2.20462, 0, false); - - //Setting the conversion ratios for testing - unit1Map[u1] = conversion1; - unit1Map[u2] = conversion2; - - unit2Map[u1] = conversion3; - unit2Map[u2] = conversion1; - - unit3Map[u3] = conversion1; - unit3Map[u4] = conversion4; - - unit4Map[u3] = conversion5; - unit4Map[u4] = conversion1; - - - m_ratioMaps[u1] = unit1Map; - m_ratioMaps[u2] = unit2Map; - m_ratioMaps[u3] = unit3Map; - m_ratioMaps[u4] = unit4Map; - } - - void LoadData() - { - m_loadDataCallCount++; - } - - vector LoadOrderedCategories() - { - return m_categories; - } - - vector LoadOrderedUnits(const Category& c) - { - return m_units[c]; - } - - unordered_map LoadOrderedRatios(const Unit& u) - { - return m_ratioMaps[u]; - } - - bool SupportsCategory(const Category& target) - { - return true; - } - - UINT m_loadDataCallCount; - private: - vector m_categories; - CategoryToUnitVectorMap m_units; - UnitToUnitToConversionDataMap m_ratioMaps; - }; - - class TestUnitConverterVMCallback : public IUnitConverterVMCallback - { - public: - void Reset() - { - m_maxDigitsReachedCallCount = 0; - } - - void DisplayCallback(const wstring& from, const wstring& to) override - { - m_lastFrom = from; - m_lastTo = to; - } - - void SuggestedValueCallback(const vector>& suggestedValues) override - { - m_lastSuggested = suggestedValues; - } - - void MaxDigitsReached() override - { - m_maxDigitsReachedCallCount++; - } - - int GetMaxDigitsReachedCallCount() - { - return m_maxDigitsReachedCallCount; - } - - bool CheckDisplayValues(wstring from, wstring to) - { - return (from == m_lastFrom && to == m_lastTo); - } - - bool CheckSuggestedValues(vector> suggested) - { - if (suggested.size() != m_lastSuggested.size()) - { - return false; - } - bool returnValue = true; - for (unsigned int i = 0; i < suggested.size(); i++) - { - if (suggested[i] != m_lastSuggested[i]) - { - returnValue = false; - break; - } - } - return returnValue; - } - private: - wstring m_lastFrom; - wstring m_lastTo; - vector> m_lastSuggested; - int m_maxDigitsReachedCallCount = 0; - }; - - class UnitConverterTest - { - public: - // Declare this class as a TestClass, and supply metadata if necessary. - TEST_CLASS(UnitConverterTest); - TEST_CLASS_SETUP(CommonSetup); - - TEST_METHOD_CLEANUP(Cleanup); - - TEST_METHOD(UnitConverterTestInit); - TEST_METHOD(UnitConverterTestBasic); - TEST_METHOD(UnitConverterTestGetters); - TEST_METHOD(UnitConverterTestGetCategory); - TEST_METHOD(UnitConverterTestUnitTypeSwitching); - TEST_METHOD(UnitConverterTestSerialization); - TEST_METHOD(UnitConverterTestDeSerialization); - TEST_METHOD(UnitConverterTestQuote); - TEST_METHOD(UnitConverterTestUnquote); - TEST_METHOD(UnitConverterTestBackspace); - TEST_METHOD(UnitConverterTestScientificInputs); - TEST_METHOD(UnitConverterTestSupplementaryResultRounding); - TEST_METHOD(UnitConverterTestMaxDigitsReached); - TEST_METHOD(UnitConverterTestMaxDigitsReached_LeadingDecimal); - TEST_METHOD(UnitConverterTestMaxDigitsReached_TrailingDecimal); - TEST_METHOD(UnitConverterTestMaxDigitsReached_MultipleTimes); - private: - static void ExecuteCommands(vector commands); - - static shared_ptr s_unitConverter; - static shared_ptr s_xmlLoader; - static shared_ptr s_testVMCallback; - static Category s_testLength; - static Category s_testWeight; - static Unit s_testInches; - static Unit s_testFeet; - static Unit s_testPounds; - static Unit s_testKilograms; - }; - - shared_ptr UnitConverterTest::s_unitConverter; - shared_ptr UnitConverterTest::s_xmlLoader; - shared_ptr UnitConverterTest::s_testVMCallback; - Category UnitConverterTest::s_testLength; - Category UnitConverterTest::s_testWeight; - Unit UnitConverterTest::s_testInches; - Unit UnitConverterTest::s_testFeet; - Unit UnitConverterTest::s_testPounds; - Unit UnitConverterTest::s_testKilograms; - - // Creates instance of UnitConverter before running tests - bool UnitConverterTest::CommonSetup() - { - s_testVMCallback = make_shared(); - s_xmlLoader = make_shared(); - s_unitConverter = make_shared(s_xmlLoader); - s_unitConverter->SetViewModelCallback(s_testVMCallback); - SetCategoryParams(&s_testLength, 1, L"Length", true); - SetCategoryParams(&s_testWeight, 2, L"Weight", false); - SetUnitParams(&s_testInches, 1, L"Inches", L"In", true, true, false); - SetUnitParams(&s_testFeet, 2, L"Feet", L"Ft", false, false, false); - SetUnitParams(&s_testPounds, 3, L"Pounds", L"Lb", true, true, false); - SetUnitParams(&s_testKilograms, 4, L"Kilograms", L"Kg", false, false, false); - return true; - } - - // Resets calculator state to start state after each test - bool UnitConverterTest::Cleanup() - { - s_unitConverter->DeSerialize(wstring()); - s_testVMCallback->Reset(); - return true; - } - - void UnitConverterTest::ExecuteCommands(vector commands) - { - for (size_t i = 0; i < commands.size() && commands[i] != Command::None; i++) - { - s_unitConverter->SendCommand(commands[i]); - } - } - - // Test ctor/initialization states - void UnitConverterTest::UnitConverterTestInit() - { - VERIFY_ARE_EQUAL((UINT)0, s_xmlLoader->m_loadDataCallCount); // shouldn't have initialized the loader yet - s_unitConverter->Initialize(); - VERIFY_ARE_EQUAL((UINT)1, s_xmlLoader->m_loadDataCallCount); // now we should have loaded - } - - // Verify a basic input command stream.'3', '2', '.', '0' - void UnitConverterTest::UnitConverterTestBasic() - { - tuple test1[] = {tuple(wstring(L"0.25"), s_testFeet)}; - tuple test2[] = {tuple(wstring(L"2.5"), s_testFeet)}; - - s_unitConverter->SendCommand(Command::Three); - VERIFY_IS_TRUE(s_testVMCallback->CheckDisplayValues(wstring(L"3"), wstring(L"3"))); - VERIFY_IS_TRUE(s_testVMCallback->CheckSuggestedValues(vector>(begin(test1),end(test1)))); - s_unitConverter->SendCommand(Command::Zero); - VERIFY_IS_TRUE(s_testVMCallback->CheckDisplayValues(wstring(L"30"), wstring(L"30"))); - VERIFY_IS_TRUE(s_testVMCallback->CheckSuggestedValues(vector>(begin(test2),end(test2)))); - s_unitConverter->SendCommand(Command::Decimal); - VERIFY_IS_TRUE(s_testVMCallback->CheckDisplayValues(wstring(L"30."), wstring(L"30"))); - VERIFY_IS_TRUE(s_testVMCallback->CheckSuggestedValues(vector>(begin(test2),end(test2)))); - s_unitConverter->SendCommand(Command::Zero); - VERIFY_IS_TRUE(s_testVMCallback->CheckDisplayValues(wstring(L"30.0"), wstring(L"30"))); - VERIFY_IS_TRUE(s_testVMCallback->CheckSuggestedValues(vector>(begin(test2),end(test2)))); - } - - // Check the getter functions - void UnitConverterTest::UnitConverterTestGetters() - { - Category test1[] = {s_testLength, s_testWeight}; - Unit test2[] = {s_testInches, s_testFeet}; - - VERIFY_IS_TRUE(s_unitConverter->GetCategories() == vector(begin(test1),end(test1))); - VERIFY_IS_TRUE(get<0>(s_unitConverter->SetCurrentCategory(test1[0])) == vector(begin(test2),end(test2))); - } - - // Test getting category after it has been set. - void UnitConverterTest::UnitConverterTestGetCategory() - { - s_unitConverter->SetCurrentCategory(s_testWeight); - VERIFY_IS_TRUE(s_unitConverter->GetCurrentCategory() == s_testWeight); - } - - // Test switching of unit types - void UnitConverterTest::UnitConverterTestUnitTypeSwitching() - { - // Enter 57 into the from field, then switch focus to the to field (making it the new from field) - s_unitConverter->SendCommand(Command::Five); - s_unitConverter->SendCommand(Command::Seven); - s_unitConverter->SwitchActive(wstring(L"57")); - // Now set unit conversion to go from kilograms to pounds - s_unitConverter->SetCurrentCategory(s_testWeight); - s_unitConverter->SetCurrentUnitTypes(s_testKilograms, s_testPounds); - s_unitConverter->SendCommand(Command::Five); - VERIFY_IS_TRUE(s_testVMCallback->CheckDisplayValues(wstring(L"5"), wstring(L"11.0231"))); - VERIFY_IS_TRUE(s_testVMCallback->CheckSuggestedValues(vector>())); - } - - // Test serialization - void UnitConverterTest::UnitConverterTestSerialization() - { - wstring test1 = wstring(L"4;Kilograms;Kg;0;0;0;|3;Pounds;Lb;1;1;0;|2;0;Weight;|1;1;0;52.8;116.4039;|1;1;Length;,2;0;Weight;,|1;1;Length;[1;Inches;In;1;1;0;,2;Feet;Ft;0;0;0;,[]2;0;Weight;[3;Pounds;Lb;1;1;0;,4;Kilograms;Kg;0;0;0;,[]|1;Inches;In;1;1;0;[1;Inches;In;1;1;0;:1;0;0;:,2;Feet;Ft;0;0;0;:0.08333333333333332870740406406185;0;0;:,[]2;Feet;Ft;0;0;0;[1;Inches;In;1;1;0;:12;0;0;:,2;Feet;Ft;0;0;0;:1;0;0;:,[]3;Pounds;Lb;1;1;0;[3;Pounds;Lb;1;1;0;:1;0;0;:,4;Kilograms;Kg;0;0;0;:0.45359199999999999519673110626172;0;0;:,[]4;Kilograms;Kg;0;0;0;[3;Pounds;Lb;1;1;0;:2.20461999999999980204279381723609;0;0;:,4;Kilograms;Kg;0;0;0;:1;0;0;:,[]|"); - s_unitConverter->SendCommand(Command::Five); - s_unitConverter->SendCommand(Command::Two); - s_unitConverter->SendCommand(Command::Decimal); - s_unitConverter->SendCommand(Command::Eight); - s_unitConverter->SetCurrentCategory(s_testWeight); - s_unitConverter->SetCurrentUnitTypes(s_testKilograms, s_testPounds); - VERIFY_IS_TRUE(s_unitConverter->Serialize().compare(test1) == 0); - } - - // Test input escaping - void UnitConverterTest::UnitConverterTestQuote() - { - wstring input1 = L"Weight"; - wstring output1 = L"Weight"; - wstring input2 = L"{p}Weig;[ht|"; - wstring output2 = L"{lb}p{rb}Weig{sc}{lc}ht{p}"; - wstring input3 = L"{{{t;s}}},:]"; - wstring output3 = L"{lb}{lb}{lb}t{sc}s{rb}{rb}{rb}{cm}{co}{rc}"; - VERIFY_IS_TRUE(UnitConverter::Quote(input1) == output1); - VERIFY_IS_TRUE(UnitConverter::Quote(input2) == output2); - VERIFY_IS_TRUE(UnitConverter::Quote(input3) == output3); - } - - // Test output unescaping - void UnitConverterTest::UnitConverterTestUnquote() - { - wstring input1 = L"Weight"; - wstring input2 = L"{p}Weig;[ht|"; - wstring input3 = L"{{{t;s}}},:]"; - VERIFY_IS_TRUE(UnitConverter::Unquote(input1) == input1); - VERIFY_IS_TRUE(UnitConverter::Unquote(UnitConverter::Quote(input1)) == input1); - VERIFY_IS_TRUE(UnitConverter::Unquote(UnitConverter::Quote(input2)) == input2); - VERIFY_IS_TRUE(UnitConverter::Unquote(UnitConverter::Quote(input3)) == input3); - } - - // Test de-serialization - void UnitConverterTest::UnitConverterTestDeSerialization() - { - wstring test1 = wstring(L"4;Kilograms;Kg;0;0;0;|3;Pounds;Lb;1;1;0;|2;0;Weight;|1;1;0;52.8;116.4039;|1;1;Length;,2;0;Weight;,|1;1;Length;[1;Inches;In;1;1;0;,2;Feet;Ft;0;0;0;,[]2;0;Weight;[3;Pounds;Lb;1;1;0;,4;Kilograms;Kg;0;0;0;,[]|1;Inches;In;1;1;0;[1;Inches;In;1;1;0;:1;0;0;:,2;Feet;Ft;0;0;0;:0.08333333333333332870740406406185;0;0;:,[]2;Feet;Ft;0;0;0;[1;Inches;In;1;1;0;:12;0;0;:,2;Feet;Ft;0;0;0;:1;0;0;:,[]3;Pounds;Lb;1;1;0;[3;Pounds;Lb;1;1;0;:1;0;0;:,4;Kilograms;Kg;0;0;0;:0.45359199999999999519673110626172;0;0;:,[]4;Kilograms;Kg;0;0;0;[3;Pounds;Lb;1;1;0;:2.20461999999999980204279381723609;0;0;:,4;Kilograms;Kg;0;0;0;:1;0;0;:,[]|"); - s_unitConverter->DeSerialize(test1); - VERIFY_IS_TRUE(s_testVMCallback->CheckDisplayValues(wstring(L"52.8"), wstring(L"116.4039"))); - VERIFY_IS_TRUE(s_testVMCallback->CheckSuggestedValues(vector>())); - } - - // Test backspace commands - void UnitConverterTest::UnitConverterTestBackspace() - { - tuple test1[] = {tuple(wstring(L"13.66"), s_testKilograms)}; - tuple test2[] = {tuple(wstring(L"13.65"), s_testKilograms)}; - tuple test3[] = {tuple(wstring(L"13.61"), s_testKilograms)}; - tuple test4[] = {tuple(wstring(L"1.36"), s_testKilograms)}; - - s_unitConverter->SetCurrentCategory(s_testWeight); - s_unitConverter->SetCurrentUnitTypes(s_testPounds, s_testPounds); - s_unitConverter->SendCommand(Command::Three); - s_unitConverter->SendCommand(Command::Zero); - s_unitConverter->SendCommand(Command::Decimal); - s_unitConverter->SendCommand(Command::One); - s_unitConverter->SendCommand(Command::Two); - VERIFY_IS_TRUE(s_testVMCallback->CheckDisplayValues(wstring(L"30.12"), wstring(L"30.12"))); - VERIFY_IS_TRUE(s_testVMCallback->CheckSuggestedValues(vector>(begin(test1),end(test1)))); - s_unitConverter->SendCommand(Command::Backspace); - VERIFY_IS_TRUE(s_testVMCallback->CheckDisplayValues(wstring(L"30.1"), wstring(L"30.1"))); - VERIFY_IS_TRUE(s_testVMCallback->CheckSuggestedValues(vector>(begin(test2),end(test2)))); - s_unitConverter->SendCommand(Command::Backspace); - VERIFY_IS_TRUE(s_testVMCallback->CheckDisplayValues(wstring(L"30."), wstring(L"30"))); - VERIFY_IS_TRUE(s_testVMCallback->CheckSuggestedValues(vector>(begin(test3),end(test3)))); - s_unitConverter->SendCommand(Command::Backspace); - VERIFY_IS_TRUE(s_testVMCallback->CheckDisplayValues(wstring(L"30"), wstring(L"30"))); - VERIFY_IS_TRUE(s_testVMCallback->CheckSuggestedValues(vector>(begin(test3),end(test3)))); - s_unitConverter->SendCommand(Command::Backspace); - VERIFY_IS_TRUE(s_testVMCallback->CheckDisplayValues(wstring(L"3"), wstring(L"3"))); - VERIFY_IS_TRUE(s_testVMCallback->CheckSuggestedValues(vector>(begin(test4),end(test4)))); - s_unitConverter->SendCommand(Command::Backspace); - VERIFY_IS_TRUE(s_testVMCallback->CheckDisplayValues(wstring(L"0"), wstring(L"0"))); - VERIFY_IS_TRUE(s_testVMCallback->CheckSuggestedValues(vector>())); - } - - // Test large values - void UnitConverterTest::UnitConverterTestScientificInputs() - { - s_unitConverter->SetCurrentCategory(s_testWeight); - s_unitConverter->SetCurrentUnitTypes(s_testPounds, s_testKilograms); - s_unitConverter->SendCommand(Command::Decimal); - s_unitConverter->SendCommand(Command::Zero); - s_unitConverter->SendCommand(Command::Zero); - s_unitConverter->SendCommand(Command::Zero); - s_unitConverter->SendCommand(Command::Zero); - s_unitConverter->SendCommand(Command::Zero); - s_unitConverter->SendCommand(Command::Zero); - s_unitConverter->SendCommand(Command::Zero); - s_unitConverter->SendCommand(Command::Zero); - s_unitConverter->SendCommand(Command::Zero); - s_unitConverter->SendCommand(Command::Zero); - s_unitConverter->SendCommand(Command::Zero); - s_unitConverter->SendCommand(Command::Zero); - s_unitConverter->SendCommand(Command::Zero); - s_unitConverter->SendCommand(Command::One); - VERIFY_IS_TRUE(s_testVMCallback->CheckDisplayValues(wstring(L"0.00000000000001"), wstring(L"4.535920e-15"))); - s_unitConverter->SwitchActive(wstring(L"4.535920e-15")); - s_unitConverter->SendCommand(Command::Nine); - s_unitConverter->SendCommand(Command::Nine); - s_unitConverter->SendCommand(Command::Nine); - s_unitConverter->SendCommand(Command::Nine); - s_unitConverter->SendCommand(Command::Nine); - s_unitConverter->SendCommand(Command::Nine); - s_unitConverter->SendCommand(Command::Nine); - s_unitConverter->SendCommand(Command::Nine); - s_unitConverter->SendCommand(Command::Nine); - s_unitConverter->SendCommand(Command::Nine); - s_unitConverter->SendCommand(Command::Nine); - s_unitConverter->SendCommand(Command::Nine); - s_unitConverter->SendCommand(Command::Nine); - s_unitConverter->SendCommand(Command::Nine); - s_unitConverter->SendCommand(Command::Nine); - s_unitConverter->SendCommand(Command::Nine); - VERIFY_IS_TRUE(s_testVMCallback->CheckDisplayValues(wstring(L"999999999999999"), wstring(L"2.204620e+15"))); - s_unitConverter->SwitchActive(wstring(L"2.20463e+15")); - s_unitConverter->SendCommand(Command::One); - s_unitConverter->SendCommand(Command::Two); - s_unitConverter->SendCommand(Command::Three); - s_unitConverter->SendCommand(Command::Four); - s_unitConverter->SendCommand(Command::Five); - s_unitConverter->SendCommand(Command::Six); - s_unitConverter->SendCommand(Command::Seven); - VERIFY_IS_TRUE(s_testVMCallback->CheckDisplayValues(wstring(L"1234567"), wstring(L"559989.7"))); - s_unitConverter->SwitchActive(wstring(L"559989.7")); - s_unitConverter->SendCommand(Command::One); - s_unitConverter->SendCommand(Command::Two); - s_unitConverter->SendCommand(Command::Three); - s_unitConverter->SendCommand(Command::Four); - s_unitConverter->SendCommand(Command::Five); - s_unitConverter->SendCommand(Command::Six); - s_unitConverter->SendCommand(Command::Seven); - s_unitConverter->SendCommand(Command::Eight); - VERIFY_IS_TRUE(s_testVMCallback->CheckDisplayValues(wstring(L"12345678"), wstring(L"27217528.63236"))); - } - - // Test large values - void UnitConverterTest::UnitConverterTestSupplementaryResultRounding() - { - tuple test1[] = {tuple(wstring(L"27.75"), s_testFeet)}; - tuple test2[] = {tuple(wstring(L"277.8"), s_testFeet)}; - tuple test3[] = {tuple(wstring(L"2778"), s_testFeet)}; - s_unitConverter->SendCommand(Command::Three); - s_unitConverter->SendCommand(Command::Three); - s_unitConverter->SendCommand(Command::Three); - VERIFY_IS_TRUE(s_testVMCallback->CheckSuggestedValues(vector>(begin(test1),end(test1)))); - s_unitConverter->SendCommand(Command::Three); - VERIFY_IS_TRUE(s_testVMCallback->CheckSuggestedValues(vector>(begin(test2),end(test2)))); - s_unitConverter->SendCommand(Command::Three); - VERIFY_IS_TRUE(s_testVMCallback->CheckSuggestedValues(vector>(begin(test3),end(test3)))); - } - - void UnitConverterTest::UnitConverterTestMaxDigitsReached() - { - ExecuteCommands({ - Command::One, - Command::Two, - Command::Three, - Command::Four, - Command::Five, - Command::Six, - Command::Seven, - Command::Eight, - Command::Nine, - Command::One, - Command::Zero, - Command::One, - Command::One, - Command::One, - Command::Two - }); - - VERIFY_ARE_EQUAL(0, s_testVMCallback->GetMaxDigitsReachedCallCount()); - - ExecuteCommands({ Command::One }); - - VERIFY_ARE_EQUAL(1, s_testVMCallback->GetMaxDigitsReachedCallCount()); - } - - void UnitConverterTest::UnitConverterTestMaxDigitsReached_LeadingDecimal() - { - ExecuteCommands({ - Command::Zero, - Command::Decimal, - Command::One, - Command::Two, - Command::Three, - Command::Four, - Command::Five, - Command::Six, - Command::Seven, - Command::Eight, - Command::Nine, - Command::One, - Command::Zero, - Command::One, - Command::One, - Command::One - }); - - VERIFY_ARE_EQUAL(0, s_testVMCallback->GetMaxDigitsReachedCallCount()); - - ExecuteCommands({ Command::Two }); - - VERIFY_ARE_EQUAL(1, s_testVMCallback->GetMaxDigitsReachedCallCount()); - } - - void UnitConverterTest::UnitConverterTestMaxDigitsReached_TrailingDecimal() - { - ExecuteCommands({ - Command::One, - Command::Two, - Command::Three, - Command::Four, - Command::Five, - Command::Six, - Command::Seven, - Command::Eight, - Command::Nine, - Command::One, - Command::Zero, - Command::One, - Command::One, - Command::One, - Command::Two, - Command::Decimal - }); - - VERIFY_ARE_EQUAL(0, s_testVMCallback->GetMaxDigitsReachedCallCount()); - - ExecuteCommands({ Command::One }); - - VERIFY_ARE_EQUAL(1, s_testVMCallback->GetMaxDigitsReachedCallCount()); - } - - void UnitConverterTest::UnitConverterTestMaxDigitsReached_MultipleTimes() - { - ExecuteCommands({ - Command::One, - Command::Two, - Command::Three, - Command::Four, - Command::Five, - Command::Six, - Command::Seven, - Command::Eight, - Command::Nine, - Command::One, - Command::Zero, - Command::One, - Command::One, - Command::One, - Command::Two - }); - - VERIFY_ARE_EQUAL(0, s_testVMCallback->GetMaxDigitsReachedCallCount()); - - for (auto count = 1; count <= 10; count++) - { - ExecuteCommands({ Command::Three }); - - VERIFY_ARE_EQUAL(count, s_testVMCallback->GetMaxDigitsReachedCallCount(), to_wstring(count).c_str()); - } - } -} - diff --git a/internal/CalculatorUnitTests/UnitConverterViewModelUnitTests.cpp b/internal/CalculatorUnitTests/UnitConverterViewModelUnitTests.cpp deleted file mode 100644 index 7d4d18e..0000000 --- a/internal/CalculatorUnitTests/UnitConverterViewModelUnitTests.cpp +++ /dev/null @@ -1,1115 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#include "pch.h" -#include -#include "UnitConverterViewModelUnitTests.h" - -#include "CalcViewModel\UnitConverterViewModel.h" -#include "CalcViewModel\DataLoaders\UnitConverterDataLoader.h" - -using namespace CalculatorApp; -using namespace CalculatorApp::Common; -using namespace CalculatorApp::ViewModel; -using namespace Platform; -using namespace Platform::Collections; -using namespace std; -using namespace Utils; -using namespace Windows::ApplicationModel::Resources; -using namespace Windows::Foundation::Collections; -using namespace Windows::UI::Xaml; -using namespace Windows::UI::Xaml::Data; - -namespace UCM = UnitConversionManager; -namespace VM = CalculatorApp::ViewModel; -using namespace Windows::Globalization; - -namespace CalculatorUnitTests -{ - String^ AddUnicodeLTRMarkers(wstring str) - { - str.insert(str.begin(), L'\u202a'); - str.push_back(L'\u202c'); - return ref new String(str.c_str()); - } - - class CategoryViewModelTests - { - public: - TEST_CLASS(CategoryViewModelTests); - - // Test all binding values: - - TEST_METHOD(TestGetNameReturnsCorrectName) - { - wstring name = L"TestName"; - UCM::Category cat; - cat.name = name; - VM::Category^ vmcat = ref new VM::Category(cat); - VERIFY_ARE_EQUAL(vmcat->Name->Data(), name); - } - - TEST_METHOD(TestGetVisibilityReturnsVisible) - { - UCM::Category cat; - cat.supportsNegative = true; - VM::Category^ vmcat = ref new VM::Category(cat); - VERIFY_IS_TRUE(Visibility::Visible == vmcat->NegateVisibility); - } - - TEST_METHOD(TestGetVisibilityReturnsCollapsed) - { - UCM::Category cat; - cat.supportsNegative = false; - VM::Category^ vmcat = ref new VM::Category(cat); - VERIFY_IS_TRUE(Visibility::Collapsed == vmcat->NegateVisibility); - } - }; - - class UnitViewModelTests - { - public: - TEST_CLASS(UnitViewModelTests); - - // Test all binding values: - - TEST_METHOD(TestGetNameReturnsCorrectName) - { - wstring name = L"TestName"; - UCM::Unit unit; - unit.name = name; - VM::Unit^ vmunit = ref new VM::Unit(unit); - VERIFY_ARE_EQUAL(vmunit->Name->Data(), name); - } - - TEST_METHOD(TestGetAbbreviationReturnsCorrectAbbreviation) - { - wstring abbr = L"TestName"; - UCM::Unit unit; - unit.abbreviation = abbr; - VM::Unit^ vmunit = ref new VM::Unit(unit); - VERIFY_ARE_EQUAL(vmunit->Abbreviation->Data(), abbr); - } - }; - - class SupplementaryResultsViewModelTests - { - public: - TEST_CLASS(SupplementaryResultsViewModelTests); - - // Test all binding values: - - TEST_METHOD(TestGetValueReturnsCorrectValue) - { - wstring value = L"TestName"; - UCM::Unit unit = { 1, L"", L"", false, false, false }; - VM::Unit^ vmunit = ref new VM::Unit(unit); - VM::SupplementaryResult^ vmsupp = ref new VM::SupplementaryResult(ref new String(value.c_str()), vmunit); - VERIFY_ARE_EQUAL(vmsupp->Value->Data(), value); - } - - TEST_METHOD(TestGetUnitNameReturnsCorrectValue) - { - wstring name = L"TestName"; - UCM::Unit unit = { 1, name, L"", false, false, false }; - unit.name = name; - VM::Unit^ vmunit = ref new VM::Unit(unit); - VM::SupplementaryResult^ vmsupp = ref new VM::SupplementaryResult(L"", vmunit); - VERIFY_ARE_EQUAL(vmsupp->Unit->Name->Data(), name); - } - - TEST_METHOD(TestGetIsWhimsicalReturnsCorrectValue) - { - UCM::Unit unit = { 1, L"", L"", false, false, false }; - UCM::Unit unitW = { 2, L"", L"", false, false, true }; - VM::Unit^ vmUnit = ref new VM::Unit(unit); - VM::Unit^ vmUnitW = ref new VM::Unit(unitW); - VM::SupplementaryResult^ vmsupp = ref new VM::SupplementaryResult(L"", vmUnit); - VM::SupplementaryResult^ vmsuppW = ref new VM::SupplementaryResult(L"", vmUnitW); - VERIFY_IS_FALSE(vmsupp->IsWhimsical()); - VERIFY_IS_TRUE(vmsuppW->IsWhimsical()); - } - }; - - UnitConverterMock::UnitConverterMock() : - m_initCallCount(0), - m_getCategoriesCallCount(0), - m_setCurrentCategoryCallCount(0), - m_setCurUnitTypesCallCount(0), - m_switchActiveCallCount(0), - m_sendCommandCallCount(0), - m_setVMCallbackCallCount(0), - m_serializeCallCount(0), - m_deSerializeCallCount(0) - { } - - // IUnitConverter - - void UnitConverterMock::Initialize() - { - m_initCallCount++; - } - - vector UnitConverterMock::GetCategories() - { - m_getCategoriesCallCount++; - - vector cats; - cats.push_back(CAT1); - cats.push_back(CAT2); - cats.push_back(CAT3); - - m_curCategory = CAT2; - - return cats; - } - - UCM::CategorySelectionInitializer UnitConverterMock::SetCurrentCategory(const UCM::Category& input) - { - m_setCurrentCategoryCallCount++; - m_curCategory = input; - vector units; - switch (input.id) - { - case 1: - { - units.push_back(UNIT1); - units.push_back(UNIT2); - units.push_back(UNIT3); - break; - } - case 2: - { - units.push_back(UNIT4); - units.push_back(UNIT5); - units.push_back(UNIT6); - break; - } - case 3: - { - units.push_back(UNIT7); - units.push_back(UNIT8); - units.push_back(UNIT9); - break; - } - default: - throw; - } - - for (const UCM::Unit& unit : units) - { - if (unit.isConversionSource) - { - m_curFrom = unit; - } - - if (unit.isConversionTarget) - { - m_curTo = unit; - } - } - - units.push_back(UNITWHIMSY); // needs to be filtered out - - return make_tuple(units, m_curFrom, m_curTo); - } - - UCM::Category UnitConverterMock::GetCurrentCategory() - { - return m_curCategory; - } - - void UnitConverterMock::SetCurrentUnitTypes(const UCM::Unit& fromType, const UCM::Unit& toType) - { - m_setCurUnitTypesCallCount++; - m_curFrom = fromType; - m_curTo = toType; - m_vmCallback->SuggestedValueCallback(m_suggestedList); - } - - void UnitConverterMock::SwitchActive(const std::wstring& newValue) - { - m_switchActiveCallCount++; - m_curValue = newValue; - } - - wstring UnitConverterMock::Serialize() - { - m_serializeCallCount++; - return wstring(L""); - } - - void UnitConverterMock::DeSerialize(const wstring& serializedData) - { - m_deSerializeCallCount++; - } - - std::wstring UnitConverterMock::SaveUserPreferences() - { - return L"TEST"; - }; - - void UnitConverterMock::RestoreUserPreferences(_In_ const std::wstring& userPreferences) - { - }; - - void UnitConverterMock::SendCommand(UCM::Command command) - { - m_sendCommandCallCount++; - m_lastCommand = command; - - m_vmCallback->SuggestedValueCallback(m_suggestedList); - } - - void UnitConverterMock::SetViewModelCallback(const shared_ptr& newCallback) - { - m_setVMCallbackCallCount++; - m_vmCallback = newCallback; - } - - ref class MockActivatable sealed : public VM::IActivatable - { - private: - bool m_active; - - public: - MockActivatable(bool active) : m_active(active) - { } - - virtual property bool IsActive - { - bool get() { return m_active; } - void set(bool value) { m_active = value; } - } - }; - - class UnitConverterDataLoaderTests - { - public: - TEST_CLASS(UnitConverterDataLoaderTests); - - TEST_METHOD(FuncUnitConverterAllUnitCombinations) - { - VM::UnitConverterViewModel^ vm = ref new UnitConverterViewModel(make_shared(make_shared(ref new GeographicRegion()), nullptr)); - IObservableVector^ categoryList = vm->Categories; - ResourceLoader^ m_resLoader = ResourceLoader::GetForViewIndependentUse("Test"); - double epsilon = 0.1; //Could be more precise like 0.001 except atm to pascal conversion - - for (unsigned int k = 0; k < categoryList->Size; k++) - { - vm->CurrentCategory = categoryList->GetAt(k); - IObservableVector^ unitList = vm->Units; - for (unsigned int i = 0; i < unitList->Size; i++) - { - vm->Unit1 = unitList->GetAt(i); - wstring unit1Name = vm->Unit1->Name->Data(); - for (unsigned int j = 0; j < unitList->Size; j++) - { - vm->Value2Active = true; - vm->Value1Active = false; - vm->Unit2 = unitList->GetAt(j); - wstring unit2Name = vm->Unit2->Name->Data(); - //change value2 as 1. - vm->ButtonPressed->Execute(NumbersAndOperatorsEnum::One); - String^ expectedResult = m_resLoader->GetString(ref new String((unit1Name + L"-" + unit2Name).c_str())); - - // if the corresponding conversion ratio is present in Test.resw file - if (expectedResult != nullptr) - { - wstring expResult = expectedResult->Data(); - - double expectedConversion = GetDoubleFromWstring(expResult); - double actualConversion = GetDoubleFromWstring(GetStringValue(vm->Value1)->Data()); - double diff = abs(expectedConversion - actualConversion); - - // assert for diff less than epsilonth fraction of expected conversion result - VERIFY_IS_LESS_THAN_OR_EQUAL(diff, epsilon*expectedConversion); - } - //clearing the value1 - vm->ButtonPressed->Execute(NumbersAndOperatorsEnum::Clear); - } - } - } - } - }; - - class UnitConverterViewModelTests - { - public: - TEST_CLASS(UnitConverterViewModelTests); - - // Test that the ctor makes value1 active and value2 passive - TEST_METHOD(TestUnitConverterCtorSetsUpCorrectActiveValue) - { - shared_ptr mock = make_shared(); - VM::UnitConverterViewModel vm(mock); - VERIFY_IS_TRUE(vm.Value1Active); - VERIFY_IS_FALSE(vm.Value2Active); - } - - // Test that we've created all the vectors on init. - TEST_METHOD(TestUnitConverterCtorSetsUpVectors) - { - shared_ptr mock = make_shared(); - VM::UnitConverterViewModel vm(mock); - VERIFY_IS_NOT_NULL(vm.Categories); - VERIFY_IS_NOT_NULL(vm.Units); - VERIFY_IS_NOT_NULL(vm.SupplementaryResults); - } - - // Test that we've set up all the display callbacks on init. - TEST_METHOD(TestUnitConverterLoadSetsUpCallbacks) - { - shared_ptr mock = make_shared(); - VM::UnitConverterViewModel vm(mock); - VERIFY_ARE_EQUAL((UINT)1, mock->m_setVMCallbackCallCount); - } - - // Test that we've set up all categories on load and that the first - // category is selected. - TEST_METHOD(TestUnitConverterLoadSetsUpCategories) - { - shared_ptr mock = make_shared(); - VM::UnitConverterViewModel vm(mock); - IObservableVector^ cats = vm.Categories; - VERIFY_ARE_EQUAL((UINT)1, mock->m_getCategoriesCallCount); - VERIFY_ARE_EQUAL((UINT)3, cats->Size); - // Verify that we match current category - VERIFY_IS_TRUE(CAT2 == vm.CurrentCategory->GetModelCategory()); - } - - // Test that we've set up all units on load and that the default - // units are selected. - TEST_METHOD(TestUnitConverterLoadSetsUpUnits) - { - shared_ptr mock = make_shared(); - - VM::UnitConverterViewModel vm(mock); - IObservableVector^ units = vm.Units; - VERIFY_ARE_EQUAL((UINT)1, mock->m_setCurrentCategoryCallCount); - VERIFY_ARE_EQUAL((UINT)3, units->Size); - VERIFY_IS_TRUE(UNIT4 == vm.Unit1->GetModelUnit()); - VERIFY_IS_TRUE(UNIT6 == vm.Unit2->GetModelUnit()); - VERIFY_ARE_EQUAL((UINT)1, mock->m_setCurUnitTypesCallCount); - VERIFY_IS_TRUE(mock->m_curFrom == UNIT4); - VERIFY_IS_TRUE(mock->m_curTo == UNIT6); - } - - // Test that changing units updates the current unit types - // in the model - TEST_METHOD(TestUnitSelectionChangeUpdatesModel) - { - shared_ptr mock = make_shared(); - VM::UnitConverterViewModel vm(mock); - vm.Unit1 = vm.Units->GetAt(1); // Change from u4 to u5 - // count will be 2 here since it was already called once at init - VERIFY_ARE_EQUAL((UINT)2, mock->m_setCurUnitTypesCallCount); - VERIFY_IS_TRUE(UNIT5 == mock->m_curFrom); - VERIFY_IS_TRUE(UNIT6 == mock->m_curTo); - vm.Unit2 = vm.Units->GetAt(0); // Change from u3 to u1 - VERIFY_ARE_EQUAL((UINT)3, mock->m_setCurUnitTypesCallCount); - VERIFY_IS_TRUE(UNIT5 == mock->m_curFrom); - VERIFY_IS_TRUE(UNIT4 == mock->m_curTo); - } - - // Test that changing categories updates the unit list - TEST_METHOD(TestCategorySelectionChangeUpdatesUnits) - { - shared_ptr mock = make_shared(); - VM::UnitConverterViewModel vm(mock); - vm.CurrentCategory = vm.Categories->GetAt(2); // Change from cat1 to cat3 - // counts will be 2 here since the first call should have happened during init - VERIFY_IS_GREATER_THAN_OR_EQUAL(2u, mock->m_setCurrentCategoryCallCount); - VERIFY_ARE_EQUAL((UINT)3, vm.Units->Size); - VERIFY_IS_TRUE(UNIT7 == vm.Units->GetAt(0)->GetModelUnit()); - VERIFY_IS_TRUE(UNIT8 == vm.Units->GetAt(1)->GetModelUnit()); - VERIFY_IS_TRUE(UNIT9 == vm.Units->GetAt(2)->GetModelUnit()); - } - - // Test that changing categories updates the current unit types - // in the model - TEST_METHOD(TestCategorySelectionChangeUpdatesModel) - { - shared_ptr mock = make_shared(); - VM::UnitConverterViewModel vm(mock); - vm.CurrentCategory = vm.Categories->GetAt(2); // Change from cat1 to cat3 - // counts will be 2 here since the first call should have happened during init - VERIFY_IS_GREATER_THAN_OR_EQUAL(2u, mock->m_setCurrentCategoryCallCount); - VERIFY_IS_TRUE(UNIT9 == vm.Unit1->GetModelUnit()); - VERIFY_IS_TRUE(UNIT7 == vm.Unit2->GetModelUnit()); - VERIFY_IS_GREATER_THAN_OR_EQUAL(2u, mock->m_setCurUnitTypesCallCount); - VERIFY_IS_TRUE(UNIT9 == mock->m_curFrom); - VERIFY_IS_TRUE(UNIT7 == mock->m_curTo); - } - - // Test that the displaycallback updates the display values - TEST_METHOD(TestDisplayCallbackUpdatesDisplayValues) - { - shared_ptr mock = make_shared(); - VM::UnitConverterViewModel vm(mock); - const WCHAR * vFrom = L"1234", *vTo = L"56.78"; - vm.UpdateDisplay(vFrom, vTo); - VERIFY_IS_TRUE(vm.Value1 == AddUnicodeLTRMarkers(L"1,234")); - VERIFY_IS_TRUE(vm.Value2 == AddUnicodeLTRMarkers(vTo)); - } - - // Test that the calculator button command correctly fires - // commands to the model. - TEST_METHOD(TestButtonCommandFiresModelCommands) - { - shared_ptr mock = make_shared(); - VM::UnitConverterViewModel vm(mock); - - // Call count is being set to 1 because we send 'CE' command as the first call - UINT callCount = 1; - - vm.ButtonPressed->Execute(CalculatorApp::NumbersAndOperatorsEnum::Zero); - VERIFY_ARE_EQUAL(++callCount, mock->m_sendCommandCallCount); - VERIFY_IS_TRUE(UCM::Command::Zero == mock->m_lastCommand); - vm.ButtonPressed->Execute(CalculatorApp::NumbersAndOperatorsEnum::One); - VERIFY_ARE_EQUAL(++callCount, mock->m_sendCommandCallCount); - VERIFY_IS_TRUE(UCM::Command::One == mock->m_lastCommand); - vm.ButtonPressed->Execute(CalculatorApp::NumbersAndOperatorsEnum::Two); - VERIFY_ARE_EQUAL(++callCount, mock->m_sendCommandCallCount); - VERIFY_IS_TRUE(UCM::Command::Two == mock->m_lastCommand); - vm.ButtonPressed->Execute(CalculatorApp::NumbersAndOperatorsEnum::Three); - VERIFY_ARE_EQUAL(++callCount, mock->m_sendCommandCallCount); - VERIFY_IS_TRUE(UCM::Command::Three == mock->m_lastCommand); - vm.ButtonPressed->Execute(CalculatorApp::NumbersAndOperatorsEnum::Four); - VERIFY_ARE_EQUAL(++callCount, mock->m_sendCommandCallCount); - VERIFY_IS_TRUE(UCM::Command::Four == mock->m_lastCommand); - vm.ButtonPressed->Execute(CalculatorApp::NumbersAndOperatorsEnum::Five); - VERIFY_ARE_EQUAL(++callCount, mock->m_sendCommandCallCount); - VERIFY_IS_TRUE(UCM::Command::Five == mock->m_lastCommand); - vm.ButtonPressed->Execute(CalculatorApp::NumbersAndOperatorsEnum::Six); - VERIFY_ARE_EQUAL(++callCount, mock->m_sendCommandCallCount); - VERIFY_IS_TRUE(UCM::Command::Six == mock->m_lastCommand); - vm.ButtonPressed->Execute(CalculatorApp::NumbersAndOperatorsEnum::Seven); - VERIFY_ARE_EQUAL(++callCount, mock->m_sendCommandCallCount); - VERIFY_IS_TRUE(UCM::Command::Seven == mock->m_lastCommand); - vm.ButtonPressed->Execute(CalculatorApp::NumbersAndOperatorsEnum::Eight); - VERIFY_ARE_EQUAL(++callCount, mock->m_sendCommandCallCount); - VERIFY_IS_TRUE(UCM::Command::Eight == mock->m_lastCommand); - vm.ButtonPressed->Execute(CalculatorApp::NumbersAndOperatorsEnum::Nine); - VERIFY_ARE_EQUAL(++callCount, mock->m_sendCommandCallCount); - VERIFY_IS_TRUE(UCM::Command::Nine == mock->m_lastCommand); - vm.ButtonPressed->Execute(CalculatorApp::NumbersAndOperatorsEnum::Decimal); - VERIFY_ARE_EQUAL(++callCount, mock->m_sendCommandCallCount); - VERIFY_IS_TRUE(UCM::Command::Decimal == mock->m_lastCommand); - vm.ButtonPressed->Execute(CalculatorApp::NumbersAndOperatorsEnum::Negate); - VERIFY_ARE_EQUAL(++callCount, mock->m_sendCommandCallCount); - VERIFY_IS_TRUE(UCM::Command::Negate == mock->m_lastCommand); - vm.ButtonPressed->Execute(CalculatorApp::NumbersAndOperatorsEnum::Backspace); - VERIFY_ARE_EQUAL(++callCount, mock->m_sendCommandCallCount); - VERIFY_IS_TRUE(UCM::Command::Backspace == mock->m_lastCommand); - vm.ButtonPressed->Execute(CalculatorApp::NumbersAndOperatorsEnum::Clear); - VERIFY_ARE_EQUAL(++callCount, mock->m_sendCommandCallCount); - VERIFY_IS_TRUE(UCM::Command::Clear == mock->m_lastCommand); - - for (NumbersAndOperatorsEnum button = NumbersAndOperatorsEnum::Add; button <= NumbersAndOperatorsEnum::None; button++) - { - if (button == NumbersAndOperatorsEnum::Decimal || - button == NumbersAndOperatorsEnum::Negate || - button == NumbersAndOperatorsEnum::Backspace) - { - continue; - } - vm.ButtonPressed->Execute(button); - VERIFY_ARE_EQUAL(++callCount, mock->m_sendCommandCallCount); - VERIFY_IS_TRUE(UCM::Command::None == mock->m_lastCommand); - } - } - - // Tests that when we fire the OnGotFocus, it activates the given control - TEST_METHOD(TestOnValueGotFocusActivatesControl) - { - //shared_ptr mock = make_shared(); - //VM::UnitConverterViewModel vm(mock); - //MockActivatable^ activatable = ref new MockActivatable(false); - //vm.OnValueGotFocus(AsActivatable(activatable)); - //VERIFY_IS_TRUE(activatable->IsActive); - //vm.OnValueGotFocus(AsActivatable(activatable)); // try again, starting with true - //VERIFY_IS_TRUE(activatable->IsActive); - } - - // Tests that when we select the currently active value, nothing - // happens - TEST_METHOD(TestReselectCurrentlyActiveValueDoesNothing) - { - shared_ptr mock = make_shared(); - VM::UnitConverterViewModel vm(mock); - const WCHAR * vFrom = L"1", *vTo = L"234"; - vm.UpdateDisplay(vFrom, vTo); - // Establish base condition - VERIFY_ARE_EQUAL((UINT)0, mock->m_switchActiveCallCount); - VERIFY_ARE_EQUAL((UINT)1, mock->m_sendCommandCallCount); - VERIFY_ARE_EQUAL((UINT)1, mock->m_setCurUnitTypesCallCount); - vm.Value1Active = true; - VERIFY_ARE_EQUAL((UINT)0, mock->m_switchActiveCallCount); - VERIFY_ARE_EQUAL((UINT)1, mock->m_sendCommandCallCount); - VERIFY_ARE_EQUAL((UINT)1, mock->m_setCurUnitTypesCallCount); - } - - // Tests that when we set switch the active value, it sets the oppsite value - // to inactive - TEST_METHOD(TestActivatingValueDeactivatesOther) - { - shared_ptr mock = make_shared(); - VM::UnitConverterViewModel vm(mock); - vm.Value1Active = true; // base - VERIFY_IS_TRUE(vm.Value1Active); - VERIFY_IS_FALSE(vm.Value2Active); - vm.Value2Active = true; // change - VERIFY_IS_TRUE(vm.Value2Active); - VERIFY_IS_FALSE(vm.Value1Active); - vm.Value2Active = true; // setting it to true again doesnt change anything - VERIFY_IS_TRUE(vm.Value2Active); - VERIFY_IS_FALSE(vm.Value1Active); - vm.Value1Active = true; // back to 1 - VERIFY_IS_TRUE(vm.Value1Active); - VERIFY_IS_FALSE(vm.Value2Active); - } - - // Tests that when we switch the active value, the active value - // gets updated in the model - TEST_METHOD(TestSwitchActiveValueUpdatesActiveValueInModel) - { - shared_ptr mock = make_shared(); - VM::UnitConverterViewModel vm(mock); - const WCHAR * vFrom = L"1", *vTo = L"234"; - vm.UpdateDisplay(vFrom, vTo); - vm.Value2Active = true; - VERIFY_ARE_EQUAL((UINT)1, mock->m_switchActiveCallCount); - VERIFY_ARE_EQUAL(0, mock->m_curValue.compare(vTo)); - } - - // Tests that the suggested visibility value gets updated correctly - TEST_METHOD(TestSuggestedVisibilityIsUpdated) - { - shared_ptr mock = make_shared(); - VM::UnitConverterViewModel vm(mock); - VERIFY_IS_TRUE(Visibility::Collapsed == vm.SupplementaryVisibility); - vector> supp; - supp.push_back(tuple(L"1", UNIT1)); - vm.UpdateSupplementaryResults(supp); - WaitForSingleObjectEx(GetCurrentThread(), 1100, FALSE); - VERIFY_IS_TRUE(Visibility::Visible == vm.SupplementaryVisibility); - vm.UpdateSupplementaryResults(vector>()); - WaitForSingleObjectEx(GetCurrentThread(), 1100, FALSE); - VERIFY_IS_TRUE(Visibility::Collapsed == vm.SupplementaryVisibility); - } - - // Tests that when we switch the active field and get display - // updates, the correct values are being updated. - TEST_METHOD(TestDisplayValueUpdatesAfterSwitchingActiveUpdateTheRightDisplay) - { - shared_ptr mock = make_shared(); - VM::UnitConverterViewModel vm(mock); - const WCHAR * vFrom = L"1", *vTo = L"234"; - vm.UpdateDisplay(vFrom, vTo); - vm.Value2Active = true; - const WCHAR * newvFrom = L"3", *newvTo = L"57"; - vm.UpdateDisplay(newvFrom, newvTo); - VERIFY_IS_TRUE(vm.Value2 == AddUnicodeLTRMarkers(newvFrom)); - VERIFY_IS_TRUE(vm.Value1 == AddUnicodeLTRMarkers(newvTo)); - } - - // Tests that when we switch the active field and get change units, - // the correct unit values are being passed. - TEST_METHOD(TestUnitChangeAfterSwitchingActiveUpdateUnitsCorrectly) - { - shared_ptr mock = make_shared(); - VM::UnitConverterViewModel vm(mock); - const WCHAR * vFrom = L"1", *vTo = L"234"; - vm.UpdateDisplay(vFrom, vTo); - vm.Value2Active = true; - vm.Unit2 = vm.Units->GetAt(0); - VERIFY_IS_TRUE(UNIT4 == mock->m_curFrom); - vm.Unit1 = vm.Units->GetAt(2); - VERIFY_IS_TRUE(UNIT6 == mock->m_curTo); - } - - // Test that if we switch categories and come back, our first - // and second units are still the same - TEST_METHOD(TestCategorySwitchAndBackKeepsUnitsUnchanged) - { - shared_ptr mock = make_shared(); - VM::UnitConverterViewModel vm(mock); - const WCHAR * vFrom = L"1", *vTo = L"234"; - vm.UpdateDisplay(vFrom, vTo); - vm.CurrentCategory = vm.Categories->GetAt(2); - vm.CurrentCategory = vm.Categories->GetAt(0); - VERIFY_IS_TRUE(UNIT1 == vm.Unit1->GetModelUnit()); - VERIFY_IS_TRUE(UNIT2 == vm.Unit2->GetModelUnit()); - } - - // Test that if we switch categories and active, and then - // come back, our first and second units are swapped - // and second unit is active - TEST_METHOD(TestCategoryAndActiveSwitchAndBack) - { - shared_ptr mock = make_shared(); - VM::UnitConverterViewModel vm(mock); - const WCHAR * vFrom = L"1", *vTo = L"234"; - vm.UpdateDisplay(vFrom, vTo); - vm.CurrentCategory = vm.Categories->GetAt(2); - vm.Value2Active = true; - vm.CurrentCategory = vm.Categories->GetAt(0); - VERIFY_IS_TRUE(UNIT2 == vm.Unit1->GetModelUnit()); - VERIFY_IS_TRUE(UNIT1 == vm.Unit2->GetModelUnit()); - VERIFY_IS_TRUE(vm.Value2Active); - } - - // Tests that when we switch the active field and then change - // category, the correct units are displayed. - TEST_METHOD(TestCategoryChangeAfterSwitchingActiveUpdatesDisplayCorrectly) - { - shared_ptr mock = make_shared(); - VM::UnitConverterViewModel vm(mock); - const WCHAR * vFrom = L"1", *vTo = L"234"; - vm.UpdateDisplay(vFrom, vTo); - vm.Value2Active = true; - vm.CurrentCategory = vm.Categories->GetAt(2); - VERIFY_IS_TRUE(UNIT7 == vm.Unit1->GetModelUnit()); - VERIFY_IS_TRUE(UNIT9 == vm.Unit2->GetModelUnit()); - VERIFY_IS_TRUE(UNIT9 == mock->m_curFrom); - VERIFY_IS_TRUE(UNIT7 == mock->m_curTo); - VERIFY_ARE_EQUAL((UINT)1, mock->m_switchActiveCallCount); - const wchar_t * newvFrom = L"5", *newvTo = L"7"; - vm.UpdateDisplay(newvFrom, newvTo); - VERIFY_IS_TRUE(vm.Value2 == AddUnicodeLTRMarkers(newvFrom)); - VERIFY_IS_TRUE(vm.Value1 == AddUnicodeLTRMarkers(newvTo)); - } - - // Repeat above active switch tests but with a second switch to ensure - // transitions work both ways. - TEST_METHOD(TestSwitchAndReselectCurrentlyActiveValueDoesNothing) - { - shared_ptr mock = make_shared(); - VM::UnitConverterViewModel vm(mock); - const WCHAR * vFrom = L"1", *vTo = L"234"; - vm.UpdateDisplay(vFrom, vTo); - vm.Value2Active = true; - // Establish base condition - VERIFY_ARE_EQUAL((UINT)1, mock->m_switchActiveCallCount); - VERIFY_ARE_EQUAL((UINT)1, mock->m_sendCommandCallCount); - VERIFY_ARE_EQUAL((UINT)1, mock->m_setCurUnitTypesCallCount); - vm.Value2Active = true; - VERIFY_ARE_EQUAL((UINT)1, mock->m_switchActiveCallCount); - VERIFY_ARE_EQUAL((UINT)1, mock->m_sendCommandCallCount); - VERIFY_ARE_EQUAL((UINT)1, mock->m_setCurUnitTypesCallCount); - } - - TEST_METHOD(TestSwitchActiveValueTwiceUpdatesActiveValueInModel) - { - shared_ptr mock = make_shared(); - VM::UnitConverterViewModel vm(mock); - const WCHAR * vFrom = L"1", *vTo = L"234"; - vm.UpdateDisplay(vFrom, vTo); - vm.Value2Active = true; - vm.Value1Active = true; - VERIFY_ARE_EQUAL((UINT)2, mock->m_switchActiveCallCount); - VERIFY_ARE_EQUAL(0, mock->m_curValue.compare(vFrom)); - } - - TEST_METHOD(TestDisplayValueUpdatesAfterSwitchingActiveTwiceUpdateTheRightDisplay) - { - shared_ptr mock = make_shared(); - VM::UnitConverterViewModel vm(mock); - const WCHAR * vFrom = L"1", *vTo = L"234"; - vm.UpdateDisplay(vFrom, vTo); - vm.Value2Active = true; - vm.Value1Active = true; - const WCHAR * newvFrom = L"3", *newvTo = L"57"; - vm.UpdateDisplay(newvFrom, newvTo); - VERIFY_IS_TRUE(vm.Value1 == AddUnicodeLTRMarkers(newvFrom)); - VERIFY_IS_TRUE(vm.Value2 == AddUnicodeLTRMarkers(newvTo)); - } - - TEST_METHOD(TestUnitChangeAfterSwitchingActiveTwiceUpdateUnitsCorrectly) - { - shared_ptr mock = make_shared(); - VM::UnitConverterViewModel vm(mock); - const WCHAR * vFrom = L"1", *vTo = L"234"; - vm.UpdateDisplay(vFrom, vTo); - vm.Value2Active = true; - vm.Value1Active = true; - vm.Unit2 = vm.Units->GetAt(0); - VERIFY_IS_TRUE(UNIT4 == mock->m_curTo); - vm.Unit1 = vm.Units->GetAt(2); - VERIFY_IS_TRUE(UNIT6 == mock->m_curFrom); - } - - TEST_METHOD(TestCategoryChangeAfterSwitchingActiveTwiceUpdatesDisplayCorrectly) - { - shared_ptr mock = make_shared(); - VM::UnitConverterViewModel vm(mock); - const WCHAR * vFrom = L"1", *vTo = L"234"; - vm.UpdateDisplay(vFrom, vTo); - vm.Value2Active = true; - vm.Value1Active = true; - vm.CurrentCategory = vm.Categories->GetAt(2); - VERIFY_IS_TRUE(UNIT9 == vm.Unit1->GetModelUnit()); - VERIFY_IS_TRUE(UNIT7 == vm.Unit2->GetModelUnit()); - VERIFY_IS_TRUE(UNIT9 == mock->m_curFrom); - VERIFY_IS_TRUE(UNIT7 == mock->m_curTo); - VERIFY_ARE_EQUAL((UINT)2, mock->m_switchActiveCallCount); - const wchar_t * newvFrom = L"5", *newvTo = L"7"; - vm.UpdateDisplay(newvFrom, newvTo); - VERIFY_IS_TRUE(vm.Value1 == AddUnicodeLTRMarkers(newvFrom)); - VERIFY_IS_TRUE(vm.Value2 == AddUnicodeLTRMarkers(newvTo)); - } - - // There is a 100 ms fudge time for the time based tests below - - // Test that UpdateSupplementaryResults updates the supplementary results - // after a delay - TEST_METHOD(TestSuggestedValuesCallbackUpdatesSupplementaryResults) - { - shared_ptr mock = make_shared(); - VM::UnitConverterViewModel vm(mock); - vector> supp; - supp.push_back(tuple(L"1", UNIT1)); - supp.push_back(tuple(L"2", UNIT2)); - supp.push_back(tuple(L"3", UNIT3)); - vm.UpdateSupplementaryResults(supp); - VERIFY_ARE_EQUAL((UINT)0, vm.SupplementaryResults->Size); - WaitForSingleObjectEx(GetCurrentThread(), 200, FALSE); - // Now we should see it - VERIFY_ARE_EQUAL((UINT)3, vm.SupplementaryResults->Size); - VERIFY_IS_TRUE((AddUnicodeLTRMarkers(L"1")) == vm.SupplementaryResults->GetAt(0)->Value); - VERIFY_IS_TRUE(UNIT1 == vm.SupplementaryResults->GetAt(0)->Unit->GetModelUnit()); - VERIFY_IS_TRUE((AddUnicodeLTRMarkers(L"2")) == vm.SupplementaryResults->GetAt(1)->Value); - VERIFY_IS_TRUE(UNIT2 == vm.SupplementaryResults->GetAt(1)->Unit->GetModelUnit()); - VERIFY_IS_TRUE((AddUnicodeLTRMarkers(L"3")) == vm.SupplementaryResults->GetAt(2)->Value); - VERIFY_IS_TRUE(UNIT3 == vm.SupplementaryResults->GetAt(2)->Unit->GetModelUnit()); - } - - // Test that changing category immediately updates supplementary results - TEST_METHOD(TestCategoryChangeImmediatelyUpdatesSupplementaryResults) - { - shared_ptr mock = make_shared(); - VM::UnitConverterViewModel vm(mock); - - vector> supp; - supp.push_back(tuple(L"1", UNIT1)); - supp.push_back(tuple(L"2", UNIT2)); - supp.push_back(tuple(L"3", UNIT3)); - vm.UpdateSupplementaryResults(supp); - WaitForSingleObjectEx(GetCurrentThread(), 1100, FALSE); - VERIFY_ARE_EQUAL((UINT)3, vm.SupplementaryResults->Size); // Verify we're in the state we expect as a pre condition - - vm.CurrentCategory = vm.Categories->GetAt(2); - VERIFY_ARE_EQUAL((UINT)0, vm.SupplementaryResults->Size); - } - - // Test that changing category immediately updates supplementary results - TEST_METHOD(TestCategoryChangeImmediatelyUpdatesSupplementaryResultsWhimsy) - { - shared_ptr mock = make_shared(); - VM::UnitConverterViewModel vm(mock); - - vector> supp; - supp.push_back(tuple(L"1", UNIT1)); - supp.push_back(tuple(L"2", UNIT2)); - supp.push_back(tuple(L"3", UNIT3)); - supp.push_back(tuple(L"4", UNITWHIMSY)); - vm.UpdateSupplementaryResults(supp); - WaitForSingleObjectEx(GetCurrentThread(), 1100, FALSE); - VERIFY_ARE_EQUAL((UINT)4, vm.SupplementaryResults->Size); // Verify we're in the state we expect as a pre condition - - VERIFY_IS_TRUE(vm.SupplementaryResults->GetAt(3)->Unit->GetModelUnit().isWhimsical); - VERIFY_IS_FALSE(vm.SupplementaryResults->GetAt(0)->Unit->GetModelUnit().isWhimsical); - } - - // Test that changing units immediately updates supplementary results - TEST_METHOD(TestUnitChangeImmediatelyUpdatesSupplementaryResults) - { - shared_ptr mock = make_shared(); - VM::UnitConverterViewModel vm(mock); - - vector> supp; - supp.push_back(tuple(L"1", UNIT1)); - supp.push_back(tuple(L"2", UNIT2)); - supp.push_back(tuple(L"3", UNIT3)); - vm.UpdateSupplementaryResults(supp); - WaitForSingleObjectEx(GetCurrentThread(), 1100, FALSE); - VERIFY_ARE_EQUAL((UINT)3, vm.SupplementaryResults->Size); // Verify we're in the state we expect as a pre condition - - vm.Unit1 = vm.Units->GetAt(2); - VERIFY_ARE_EQUAL((UINT)0, vm.SupplementaryResults->Size); - - // Reset and try with other unit - vm.UpdateSupplementaryResults(supp); - WaitForSingleObjectEx(GetCurrentThread(), 1100, FALSE); - VERIFY_ARE_EQUAL((UINT)3, vm.SupplementaryResults->Size); // Verify we're in the state we expect as a pre condition - - vm.Unit2 = vm.Units->GetAt(0); - VERIFY_ARE_EQUAL((UINT)0, vm.SupplementaryResults->Size); - } - - // Test that only the first whimsical unit is selected and is appended - // to end of supplementary results. - TEST_METHOD(TestSupplementaryResultsWhimsicalUnits) - { - shared_ptr mock = make_shared(); - VM::UnitConverterViewModel vm(mock); - - UCM::Unit unit; - unit.isWhimsical = false; - - UCM::Unit unitWhimSubsequent; - unitWhimSubsequent.isWhimsical = true; - - vector> suggestedList; - suggestedList.push_back(tuple(L"", unit)); - suggestedList.push_back(tuple(L"", unit)); - suggestedList.push_back(tuple(L"", UNITWHIMSY)); - suggestedList.push_back(tuple(L"", unitWhimSubsequent)); - suggestedList.push_back(tuple(L"", unit)); - suggestedList.push_back(tuple(L"", unit)); - suggestedList.push_back(tuple(L"", unitWhimSubsequent)); - suggestedList.push_back(tuple(L"", unit)); - - vm.UpdateSupplementaryResults(suggestedList); - WaitForSingleObjectEx(GetCurrentThread(), 1100, FALSE); - VERIFY_ARE_EQUAL((UINT)6, vm.SupplementaryResults->Size); - while (vm.SupplementaryResults->Size > 1) - { - VERIFY_IS_FALSE(vm.SupplementaryResults->GetAt(0)->IsWhimsical()); - vm.SupplementaryResults->RemoveAt(0); - } - // Last item - VERIFY_IS_TRUE(vm.SupplementaryResults->GetAt(0)->Unit->GetModelUnit() == UNITWHIMSY); - } - - // Test deserialization - TEST_METHOD(TestUnitConverterViewModelDeserialization) - { - String ^ serializedTest = L"0[;;;]0[;;;]0[;;;]1[;;;]1.5[;;;]25[;;;]1.5[;;;]25[;;;][###][###]"; - shared_ptr mock = make_shared(); - VM::UnitConverterViewModel vm(mock); - vm.Deserialize(serializedTest); - VERIFY_IS_TRUE(vm.Value1 == L"1.5"); - VERIFY_IS_TRUE(vm.Value2 == L"25"); - VERIFY_IS_TRUE(vm.GetValueFromUnlocalized() == L"1.5"); - VERIFY_IS_TRUE(vm.GetValueToUnlocalized() == L"25"); - VERIFY_ARE_EQUAL(vm.Value1Active, false); - VERIFY_ARE_EQUAL(vm.Value2Active, true); - VERIFY_IS_TRUE(mock->m_deSerializeCallCount == 1); - } - - // Test serialization - /*TEST_METHOD(TestUnitConverterViewModelSerialization) - { - String ^ serializedTest = L"0[;;;]0[;;;]0[;;;]1[;;;];;;]1.5[;;;[;;;]25[###[;;;]0[;;;]0[;;;][###][###]"; - shared_ptr mock = make_shared(); - VM::UnitConverterViewModel vm(mock); - vm.Value1 = L";;;]1.5[;;;"; - vm.Value2 = L"25[###"; - vm.Value1Active = false; - vm.Value2Active = true; - String ^ test = vm.Serialize(); - VERIFY_IS_TRUE(serializedTest == test); - VERIFY_IS_TRUE(mock->m_serializeCallCount == 1); - }*/ - - TEST_METHOD(TestOnPaste) - { - shared_ptr mock = make_shared(); - VM::UnitConverterViewModel vm(mock); - - // Call count is being set to 1 because we send 'CE' command as the first call in OnPaste method of the ViewModel - UINT callCount = 1; - ViewMode mode = ViewMode::Volume; // Some temp mode for UnitConverter - - // Paste an invalid character - verify that call count doesn't increment - vm.OnPaste("z", mode); - VERIFY_ARE_EQUAL(callCount, mock->m_sendCommandCallCount); - - - // Test all valid characters. Verify that two commands are sent for each character - vm.OnPaste("0", mode); - callCount += 2; - VERIFY_ARE_EQUAL(callCount, mock->m_sendCommandCallCount); - VERIFY_IS_TRUE(UCM::Command::Zero == mock->m_lastCommand); - - vm.OnPaste("1", mode); - callCount += 2; - VERIFY_ARE_EQUAL(callCount, mock->m_sendCommandCallCount); - VERIFY_IS_TRUE(UCM::Command::One == mock->m_lastCommand); - - vm.OnPaste("2", mode); - callCount += 2; - VERIFY_ARE_EQUAL(callCount, mock->m_sendCommandCallCount); - VERIFY_IS_TRUE(UCM::Command::Two == mock->m_lastCommand); - - vm.OnPaste("3", mode); - callCount += 2; - VERIFY_ARE_EQUAL(callCount, mock->m_sendCommandCallCount); - VERIFY_IS_TRUE(UCM::Command::Three == mock->m_lastCommand); - - vm.OnPaste("4", mode); - callCount += 2; - VERIFY_ARE_EQUAL(callCount, mock->m_sendCommandCallCount); - VERIFY_IS_TRUE(UCM::Command::Four == mock->m_lastCommand); - - vm.OnPaste("5", mode); - callCount += 2; - VERIFY_ARE_EQUAL(callCount, mock->m_sendCommandCallCount); - VERIFY_IS_TRUE(UCM::Command::Five == mock->m_lastCommand); - - vm.OnPaste("6", mode); - callCount += 2; - VERIFY_ARE_EQUAL(callCount, mock->m_sendCommandCallCount); - VERIFY_IS_TRUE(UCM::Command::Six == mock->m_lastCommand); - - vm.OnPaste("7", mode); - callCount += 2; - VERIFY_ARE_EQUAL(callCount, mock->m_sendCommandCallCount); - VERIFY_IS_TRUE(UCM::Command::Seven == mock->m_lastCommand); - - vm.OnPaste("8", mode); - callCount += 2; - VERIFY_ARE_EQUAL(callCount, mock->m_sendCommandCallCount); - VERIFY_IS_TRUE(UCM::Command::Eight == mock->m_lastCommand); - - vm.OnPaste("9", mode); - callCount += 2; - VERIFY_ARE_EQUAL(callCount, mock->m_sendCommandCallCount); - VERIFY_IS_TRUE(UCM::Command::Nine == mock->m_lastCommand); - - vm.OnPaste(".", mode); - callCount += 2; - VERIFY_ARE_EQUAL(callCount, mock->m_sendCommandCallCount); - VERIFY_IS_TRUE(UCM::Command::Decimal == mock->m_lastCommand); - - vm.OnPaste("-", mode); - // Call count should increment by one (the Clear command) since negate isn't - // sent by itself, only after another legal character - ++callCount; - VERIFY_ARE_EQUAL(callCount, mock->m_sendCommandCallCount); - - // Send an invalid character - - vm.OnPaste("a", mode); - // Count should remain the same - VERIFY_ARE_EQUAL(callCount, mock->m_sendCommandCallCount); - // Last command should remain the same - VERIFY_IS_TRUE(UCM::Command::Clear == mock->m_lastCommand); - } - - TEST_METHOD(TestDecimalFormattingLogic) - { - // verify that a dangling decimal is left alone until the user switches active fields, and that trailing zeroes - // entered by the user remain in the display even after a switch. - - shared_ptr mock = make_shared(); - VM::UnitConverterViewModel vm(mock); - const WCHAR * vFrom = L"3.", *vTo = L"2.50"; - vm.UpdateDisplay(vFrom, vTo); - // Establish base condition - VERIFY_IS_TRUE(vm.Value1 == AddUnicodeLTRMarkers(L"3.")); - VERIFY_IS_TRUE(vm.Value2 == AddUnicodeLTRMarkers(L"2.50")); - vm.SwitchActive->Execute(nullptr); - VERIFY_IS_TRUE(vm.Value1 == AddUnicodeLTRMarkers(L"3")); // dangling decimal now removed - VERIFY_IS_TRUE(vm.Value2 == AddUnicodeLTRMarkers(L"2.50")); - vm.SwitchActive->Execute(nullptr); - VERIFY_IS_TRUE(vm.Value1 == AddUnicodeLTRMarkers(L"3")); - VERIFY_IS_TRUE(vm.Value2 == AddUnicodeLTRMarkers(L"2.50")); - } - // Tests that when we switch the active field and get display - // updates, the correct automation names are are being updated. - TEST_METHOD(TestValue1AndValue2AutomationNameChanges) - { - shared_ptr mock = make_shared(); - VM::UnitConverterViewModel vm(mock); - vm.Value1 = L"1"; - vm.Unit1 = vm.Units->GetAt(1); - VERIFY_IS_TRUE(vm.Value1AutomationName == L"Convert from 1 UNIT5"); - VERIFY_IS_TRUE(vm.Value2AutomationName == L"Converts into 0 UNIT6"); - vm.Value2 = L"234"; - vm.Value2Active = true; - VERIFY_IS_TRUE(vm.Value2AutomationName == L"Convert from 234 UNIT6"); - VERIFY_IS_TRUE(vm.Value1AutomationName == L"Converts into 1 UNIT5"); - vm.Value2 = L"3"; - vm.Unit2 = vm.Units->GetAt(0); - VERIFY_IS_TRUE(vm.Value2AutomationName == L"Convert from 3 UNIT4"); - VERIFY_IS_TRUE(vm.Value1AutomationName == L"Converts into 1 UNIT5"); - vm.Value1Active = true; - VERIFY_IS_TRUE(vm.Value1AutomationName == L"Convert from 1 UNIT5"); - VERIFY_IS_TRUE(vm.Value2AutomationName == L"Converts into 3 UNIT4"); - } - - // Test that an invalid model unit list results in a Units list of size 1 - // containing EMPTY_UNIT. - TEST_METHOD(TestUnitsListBuildsFromEmptyModelUnitList) - { - shared_ptr mock = make_shared(); - VM::UnitConverterViewModel vm(mock); - - vm.BuildUnitList({}); - - VERIFY_ARE_EQUAL(1u, vm.Units->Size); - VERIFY_ARE_EQUAL((UCM::EMPTY_UNIT).id, (vm.Units->GetAt(0)->GetModelUnit()).id); - } - - // Test that a valid model unit list vuilds - TEST_METHOD(TestUnitsListBuildsFromValidModelUnitList) - { - shared_ptr mock = make_shared(); - VM::UnitConverterViewModel vm(mock); - - vm.BuildUnitList({ - UNIT1, - UNIT2, - UNIT3 - }); - - VERIFY_ARE_EQUAL(3u, vm.Units->Size); - VERIFY_ARE_EQUAL(UNIT1.id, (vm.Units->GetAt(0)->GetModelUnit()).id); - VERIFY_ARE_EQUAL(UNIT2.id, (vm.Units->GetAt(1)->GetModelUnit()).id); - VERIFY_ARE_EQUAL(UNIT3.id, (vm.Units->GetAt(2)->GetModelUnit()).id); - } - - TEST_METHOD(TestFindInListWhenListIsValid) - { - shared_ptr mock = make_shared(); - VM::UnitConverterViewModel vm(mock); - - vm.BuildUnitList({ - UNIT1, - UNIT2, - UNIT3 - }); - - Unit^ foundUnit = vm.FindUnitInList(UNIT1); - VERIFY_ARE_EQUAL(UNIT1.id, foundUnit->GetModelUnit().id); - } - - TEST_METHOD(TestFindInListWhenListIsInvalid) - { - shared_ptr mock = make_shared(); - VM::UnitConverterViewModel vm(mock); - - vm.BuildUnitList({}); - - Unit^ foundUnit = vm.FindUnitInList(UNIT1); - - VERIFY_ARE_EQUAL(UCM::EMPTY_UNIT.id, foundUnit->GetModelUnit().id); - } - - TEST_METHOD(TestSetSelectedUnits) - { - shared_ptr mock = make_shared(); - VM::UnitConverterViewModel vm(mock); - - vm.CurrentCategory = vm.Categories->GetAt(0); - - vm.SetSelectedUnits(); - VERIFY_ARE_NOT_EQUAL(UCM::EMPTY_UNIT.id, vm.Unit1->GetModelUnit().id); - VERIFY_ARE_NOT_EQUAL(UCM::EMPTY_UNIT.id, vm.Unit2->GetModelUnit().id); - } - }; -} - diff --git a/internal/CalculatorUnitTests/UnitConverterViewModelUnitTests.h b/internal/CalculatorUnitTests/UnitConverterViewModelUnitTests.h deleted file mode 100644 index 2585f75..0000000 --- a/internal/CalculatorUnitTests/UnitConverterViewModelUnitTests.h +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#include "pch.h" - -namespace UCM = UnitConversionManager; - -#pragma once - -namespace CalculatorUnitTests -{ - static UCM::Unit UNIT1 = { 1, L"UNIT1", L"U1", true, false, false }; - static UCM::Unit UNIT2 = { 2, L"UNIT2", L"U2", false, true, false }; - static UCM::Unit UNIT3 = { 3, L"UNIT3", L"U3", false, false, false }; - static UCM::Unit UNIT4 = { 4, L"UNIT4", L"U4", true, false, false }; - static UCM::Unit UNIT5 = { 5, L"UNIT5", L"U5", false, false, false }; - static UCM::Unit UNIT6 = { 6, L"UNIT6", L"U6", false, true, false }; - static UCM::Unit UNIT7 = { 7, L"UNIT7", L"U7", false, true, false }; - static UCM::Unit UNIT8 = { 8, L"UNIT8", L"U8", false, false, false }; - static UCM::Unit UNIT9 = { 9, L"UNIT9", L"U9", true, false, false }; - static UCM::Unit UNITWHIMSY = { 10, L"Whimsy", L"UW", true, false, true }; - - static UCM::Category CAT1 = { 1, L"CAT1", false }; // contains Unit1 - Unit3 - static UCM::Category CAT2 = { 2, L"CAT2", false }; // contains Unit4 - Unit6 - static UCM::Category CAT3 = { 3, L"CAT3", false }; // contains Unit7 - Unit9 - - - class UnitConverterMock : public UnitConversionManager::IUnitConverter - { - public: - UnitConverterMock(); - void Initialize() override; - std::vector GetCategories() override; - UCM::CategorySelectionInitializer SetCurrentCategory(const UCM::Category& input) override; - UCM::Category GetCurrentCategory(); - void SetCurrentUnitTypes(const UCM::Unit& fromType, const UCM::Unit& toType) override; - void SwitchActive(const std::wstring& newValue); - std::wstring Serialize() override; - void DeSerialize(const std::wstring& serializedData) override; - std::wstring SaveUserPreferences() override; - void RestoreUserPreferences(_In_ const std::wstring& userPreferences) override; - void SendCommand(UCM::Command command) override; - void SetViewModelCallback(const std::shared_ptr& newCallback) override; - void SetViewModelCurrencyCallback(_In_ const std::shared_ptr& newCallback) override {} - concurrency::task> RefreshCurrencyRatios() override - { - co_return std::make_pair(L"", L""); - } - - UINT m_initCallCount; - UINT m_getCategoriesCallCount; - UINT m_setCurrentCategoryCallCount; - UINT m_setCurUnitTypesCallCount; - UINT m_switchActiveCallCount; - UINT m_sendCommandCallCount; - UINT m_setVMCallbackCallCount; - UINT m_serializeCallCount; - UINT m_deSerializeCallCount; - - UCM::Category m_curCategory; - UCM::Unit m_curFrom; - UCM::Unit m_curTo; - UCM::Command m_lastCommand; - - std::shared_ptr m_vmCallback; - std::vector> m_suggestedList; - std::wstring m_curValue; - }; -} - diff --git a/internal/CalculatorUnitTests/UnitTestApp.rd.xml b/internal/CalculatorUnitTests/UnitTestApp.rd.xml deleted file mode 100644 index 74506cf..0000000 --- a/internal/CalculatorUnitTests/UnitTestApp.rd.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/internal/CalculatorUnitTests/UnitTestApp.xaml b/internal/CalculatorUnitTests/UnitTestApp.xaml deleted file mode 100644 index 54e3454..0000000 --- a/internal/CalculatorUnitTests/UnitTestApp.xaml +++ /dev/null @@ -1,8 +0,0 @@ - - - diff --git a/internal/CalculatorUnitTests/UnitTestApp.xaml.cpp b/internal/CalculatorUnitTests/UnitTestApp.xaml.cpp deleted file mode 100644 index 88cfcb1..0000000 --- a/internal/CalculatorUnitTests/UnitTestApp.xaml.cpp +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// -// App.xaml.cpp -// Implementation of the App class. -// - -#include "pch.h" -#include "UnitTestApp.xaml.h" - -using namespace CalculatorUnitTests; - -using namespace Platform; -using namespace Windows::ApplicationModel; -using namespace Windows::ApplicationModel::Activation; -using namespace Windows::Foundation; -using namespace Windows::Foundation::Collections; -using namespace Windows::UI::Xaml; -using namespace Windows::UI::Xaml::Controls; -using namespace Windows::UI::Xaml::Controls::Primitives; -using namespace Windows::UI::Xaml::Data; -using namespace Windows::UI::Xaml::Input; -using namespace Windows::UI::Xaml::Interop; -using namespace Windows::UI::Xaml::Media; -using namespace Windows::UI::Xaml::Navigation; - -// The Blank Application template is documented at http://go.microsoft.com/fwlink/?LinkId=402347&clcid=0x409 - -/// -/// Initializes the singleton application object. This is the first line of authored code -/// executed, and as such is the logical equivalent of main() or WinMain(). -/// -App::App() -{ - InitializeComponent(); - Suspending += ref new SuspendingEventHandler(this, &App::OnSuspending); -} - -/// -/// Invoked when the application is launched normally by the end user. Other entry points -/// will be used such as when the application is launched to open a specific file. -/// -/// Details about the launch request and process. -void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ e) -{ - -#if _DEBUG - // Show graphics profiling information while debugging. - if (IsDebuggerPresent()) - { - // Display the current frame rate counters - DebugSettings->EnableFrameRateCounter = true; - } -#endif - - auto rootFrame = dynamic_cast(Window::Current->Content); - - // Do not repeat app initialization when the Window already has content, - // just ensure that the window is active - if (rootFrame == nullptr) - { - // Create a Frame to act as the navigation context and associate it with - // a SuspensionManager key - rootFrame = ref new Frame(); - - rootFrame->NavigationFailed += ref new Windows::UI::Xaml::Navigation::NavigationFailedEventHandler(this, &App::OnNavigationFailed); - - if (e->PreviousExecutionState == ApplicationExecutionState::Terminated) - { - // TODO: Restore the saved session state only when appropriate, scheduling the - // final launch steps after the restore is complete - - } - - // Place the frame in the current Window - Window::Current->Content = rootFrame; - } - - Microsoft::VisualStudio::TestPlatform::TestExecutor::WinRTCore::UnitTestClient::CreateDefaultUI(); - - Window::Current->Activate(); - - Microsoft::VisualStudio::TestPlatform::TestExecutor::WinRTCore::UnitTestClient::Run(e->Arguments); -} - -/// -/// Invoked when application execution is being suspended. Application state is saved -/// without knowing whether the application will be terminated or resumed with the contents -/// of memory still intact. -/// -/// The source of the suspend request. -/// Details about the suspend request. -void App::OnSuspending(Object^ sender, SuspendingEventArgs^ e) -{ - (void) sender; // Unused parameter - (void) e; // Unused parameter - - //TODO: Save application state and stop any background activity -} - -/// -/// Invoked when Navigation to a certain page fails -/// -/// The Frame which failed navigation -/// Details about the navigation failure -void App::OnNavigationFailed(Platform::Object ^sender, Windows::UI::Xaml::Navigation::NavigationFailedEventArgs ^e) -{ - throw ref new FailureException("Failed to load Page " + e->SourcePageType.Name); -} - diff --git a/internal/CalculatorUnitTests/UnitTestApp.xaml.h b/internal/CalculatorUnitTests/UnitTestApp.xaml.h deleted file mode 100644 index f514d6d..0000000 --- a/internal/CalculatorUnitTests/UnitTestApp.xaml.h +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// -// App.xaml.h -// Declaration of the App class. -// - -#pragma once - -#include "UnitTestApp.g.h" -#include "CalcViewModel\DateCalculatorViewModel.h" -#include "CalcViewModel\StandardCalculatorViewModel.h" -#include "CalcViewModel\UnitConverterViewModel.h" -#include "CalcViewModel\MemoryItemViewModel.h" - -namespace CalculatorUnitTests -{ - /// - /// Provides application-specific behavior to supplement the default Application class. - /// - ref class App sealed - { - protected: - virtual void OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ e) override; - - internal: - App(); - - private: - void OnSuspending(Platform::Object^ sender, Windows::ApplicationModel::SuspendingEventArgs^ e); - void OnNavigationFailed(Platform::Object ^sender, Windows::UI::Xaml::Navigation::NavigationFailedEventArgs ^e); - }; -} - diff --git a/internal/CalculatorUnitTests/UtilsTests.cpp b/internal/CalculatorUnitTests/UtilsTests.cpp deleted file mode 100644 index 7b53a0c..0000000 --- a/internal/CalculatorUnitTests/UtilsTests.cpp +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#include "pch.h" -#include - -namespace CalculatorUnitTests -{ - class UtilsTests - { - public: - TEST_CLASS(UtilsTests); - - TEST_METHOD(IsLastCharacterSuccess) - { - VERIFY_IS_TRUE(Utils::IsLastCharacterTarget(L"Test.", L'.')); - } - - TEST_METHOD(IsLastCharacterSuccessMultipleSuffices) - { - VERIFY_IS_TRUE(Utils::IsLastCharacterTarget(L"Test..", L'.')); - } - - TEST_METHOD(IsLastCharacterFailure) - { - VERIFY_IS_FALSE(Utils::IsLastCharacterTarget(L"Test", L'.')); - } - - TEST_METHOD(IsLastCharacterFailureAllButLastMatch) - { - VERIFY_IS_FALSE(Utils::IsLastCharacterTarget(L".....T", L'.')); - } - - TEST_METHOD(IsLastCharacterFailureEmptyInput) - { - VERIFY_IS_FALSE(Utils::IsLastCharacterTarget({}, L'.')); - } - - TEST_METHOD(IsLastCharacterFailureNullTarget) - { - VERIFY_IS_FALSE(Utils::IsLastCharacterTarget({}, NULL)); - } - }; -} diff --git a/internal/CalculatorUnitTests/packages.config b/internal/CalculatorUnitTests/packages.config deleted file mode 100644 index 6b2ab24..0000000 --- a/internal/CalculatorUnitTests/packages.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/internal/CalculatorUnitTests/pch.cpp b/internal/CalculatorUnitTests/pch.cpp deleted file mode 100644 index 2297336..0000000 --- a/internal/CalculatorUnitTests/pch.cpp +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// -// pch.cpp -// Include the standard header and generate the precompiled header. -// - -#include "pch.h" - diff --git a/internal/CalculatorUnitTests/pch.h b/internal/CalculatorUnitTests/pch.h deleted file mode 100644 index fd760ad..0000000 --- a/internal/CalculatorUnitTests/pch.h +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// -// pch.h -// Header for standard system include files. -// - -#pragma once - -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif - -#define UNIT_TESTS - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// C++\WinRT Headers -#include "winrt\base.h" -#include "winrt\Windows.Foundation.Diagnostics.h" -#include "winrt\Windows.Globalization.h" -#include "winrt\Windows.Globalization.DateTimeFormatting.h" -#include "winrt\Windows.System.UserProfile.h" - -namespace CalculatorApp -{ - namespace WF = Windows::Foundation; - namespace WUC = Windows::UI::Core; - namespace WX = Windows::UI::Xaml; - namespace WXC = Windows::UI::Xaml::Controls; - namespace WXCP = Windows::UI::Xaml::Controls::Primitives; - namespace P = Platform; - namespace PC = Platform::Collections; - namespace WXI = Windows::UI::Xaml::Input; - namespace WFC = Windows::Foundation::Collections; - namespace WS = Windows::System; - namespace WAR = Windows::ApplicationModel::Resources; - namespace WXMA = Windows::UI::Xaml::Media::Animation; - namespace WXD = Windows::UI::Xaml::Data; - namespace WXInt = Windows::UI::Xaml::Interop; - namespace WXM = Windows::UI::Xaml::Markup; - namespace WXA = Windows::UI::Xaml::Automation; -} - -// The following namespaces exist as a convenience to resolve -// ambiguity for Windows types in the Windows::UI::Xaml::Automation::Peers -// namespace that only exist on RS3. -// Once the app switches to min version RS3, the namespaces can be removed. -// TODO - MSFT 12735088 -namespace StandardPeers = Windows::UI::Xaml::Automation::Peers; -namespace CalculatorApp::Common::Automation {} -namespace CustomPeers = CalculatorApp::Common::Automation; - -//CalcManager Headers -#include "CalcManager\CalculatorVector.h" -#include "CalcManager\ExpressionCommand.h" -#include "CalcManager\CalculatorResource.h" -#include "CalcManager\CalculatorManager.h" -#include "CalcManager\UnitConverter.h" - -// CalcViewModel Headers -#include "CalcViewModel\Common\DelegateCommand.h" -#include "CalcViewModel\Common\Utils.h" -#include "CalcViewModel\Common\MyVirtualKey.h" -#include "CalcViewModel\Common\NavCategory.h" -#include "CalcViewModel\Common\CalculatorButtonUser.h" -#include "CalcViewModel\Common\NetworkManager.h" - -#include "Mocks\CurrencyHttpClient.h" -#include "Helpers.h" - -#include "UnitTestApp.xaml.h" - -#define TEST_METHOD_IGNORE();\ - BEGIN_TEST_METHOD_PROPERTIES()\ - TEST_METHOD_PROPERTY(L"Ignore", L"true")\ - END_TEST_METHOD_PROPERTIES() - -#define VERIFY_THROWS_WINRT(__operation, __exception, ...) \ -{ \ - bool __exceptionHit = false; \ - try \ - { \ - __operation; \ - } \ - catch(__exception __e) \ - { \ - WEX::TestExecution::Private::MacroVerify::ExpectedExceptionThrown(__e, L#__exception, L#__operation, __VA_ARGS__); \ - __exceptionHit = true; \ - } \ - \ - if (!__exceptionHit) \ - { \ - WEX::TestExecution::Private::MacroVerify::ExpectedExceptionNotThrown(L#__exception, L#__operation, PRIVATE_VERIFY_ERROR_INFO, __VA_ARGS__); \ - } \ -} - - diff --git a/internal/CalculatorUnitTests/testmd.definition b/internal/CalculatorUnitTests/testmd.definition deleted file mode 100644 index d3ca47d..0000000 --- a/internal/CalculatorUnitTests/testmd.definition +++ /dev/null @@ -1,34 +0,0 @@ -{ - "$schema": "http://universaltest/schema/testmddefinition-4.json", - "Package": { - "ComponentName": "Calculator", - "SubComponentName": "UnitTests" - }, - "SupportedArchitectures": [ "All" ], - "Execution": { - "Type": "TAEF", - "Parameter": "/APPX:CertificateFileName=CalculatorUnitTests.cer:TrustedPeople /screenCaptureOnError /TestMode:EnsureLoggedOnUser /TestMode:EtwLogger", - "ExecutionTimeoutInMinutes": "30" - }, - "Dependencies": { - "Files": [ - { - "SourcePath": "$(AppxPackagePublicKeyFile)", - "DestinationFolderPath": "$$(TEST_DEPLOY_BIN)" - }, - { - "SourcePath": "$(AppxPackageVCLibsDependency)", - "DestinationFolderPath": "$$(TEST_DEPLOY_BIN)" - } - ], - "Packages": [ - "Microsoft-Windows-Test-Taef", - "Microsoft-Windows-Test-EtwProcessor", - "Microsoft-Test-Taef-EnsureLoggedOnUserTestMode", - "Microsoft-Test-Taef-EtwLoggerTestMode" - ] - }, - "Logs": [], - "Plugins": [], - "Profiles": [] -} diff --git a/src/Calculator.sln b/src/Calculator.sln index cfcae41..2d36a93 100644 --- a/src/Calculator.sln +++ b/src/Calculator.sln @@ -14,7 +14,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CalcViewModel", "CalcViewModel\CalcViewModel.vcxproj", "{90E9761D-9262-4773-942D-CAEAE75D7140}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CalculatorUnitTests_VS", "CalculatorUnitTests_VS\CalculatorUnitTests_VS.vcxproj", "{D3BAED2C-4B07-4E1D-8807-9D6499450349}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CalculatorUnitTests", "CalculatorUnitTests\CalculatorUnitTests.vcxproj", "{D3BAED2C-4B07-4E1D-8807-9D6499450349}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/internal/CalculatorUnitTests/Assets/LockScreenLogo.scale-200.png b/src/CalculatorUnitTests/Assets/LockScreenLogo.scale-200.png similarity index 100% rename from internal/CalculatorUnitTests/Assets/LockScreenLogo.scale-200.png rename to src/CalculatorUnitTests/Assets/LockScreenLogo.scale-200.png diff --git a/internal/CalculatorUnitTests/Assets/SplashScreen.scale-200.png b/src/CalculatorUnitTests/Assets/SplashScreen.scale-200.png similarity index 100% rename from internal/CalculatorUnitTests/Assets/SplashScreen.scale-200.png rename to src/CalculatorUnitTests/Assets/SplashScreen.scale-200.png diff --git a/internal/CalculatorUnitTests/Assets/Square150x150Logo.scale-200.png b/src/CalculatorUnitTests/Assets/Square150x150Logo.scale-200.png similarity index 100% rename from internal/CalculatorUnitTests/Assets/Square150x150Logo.scale-200.png rename to src/CalculatorUnitTests/Assets/Square150x150Logo.scale-200.png diff --git a/internal/CalculatorUnitTests/Assets/Square44x44Logo.scale-200.png b/src/CalculatorUnitTests/Assets/Square44x44Logo.scale-200.png similarity index 100% rename from internal/CalculatorUnitTests/Assets/Square44x44Logo.scale-200.png rename to src/CalculatorUnitTests/Assets/Square44x44Logo.scale-200.png diff --git a/internal/CalculatorUnitTests/Assets/Square44x44Logo.targetsize-24_altform-unplated.png b/src/CalculatorUnitTests/Assets/Square44x44Logo.targetsize-24_altform-unplated.png similarity index 100% rename from internal/CalculatorUnitTests/Assets/Square44x44Logo.targetsize-24_altform-unplated.png rename to src/CalculatorUnitTests/Assets/Square44x44Logo.targetsize-24_altform-unplated.png diff --git a/internal/CalculatorUnitTests/Assets/StoreLogo.png b/src/CalculatorUnitTests/Assets/StoreLogo.png similarity index 100% rename from internal/CalculatorUnitTests/Assets/StoreLogo.png rename to src/CalculatorUnitTests/Assets/StoreLogo.png diff --git a/internal/CalculatorUnitTests/Assets/Wide310x150Logo.scale-200.png b/src/CalculatorUnitTests/Assets/Wide310x150Logo.scale-200.png similarity index 100% rename from internal/CalculatorUnitTests/Assets/Wide310x150Logo.scale-200.png rename to src/CalculatorUnitTests/Assets/Wide310x150Logo.scale-200.png diff --git a/internal/CalculatorUnitTests/AsyncHelper.cpp b/src/CalculatorUnitTests/AsyncHelper.cpp similarity index 100% rename from internal/CalculatorUnitTests/AsyncHelper.cpp rename to src/CalculatorUnitTests/AsyncHelper.cpp diff --git a/internal/CalculatorUnitTests/AsyncHelper.h b/src/CalculatorUnitTests/AsyncHelper.h similarity index 100% rename from internal/CalculatorUnitTests/AsyncHelper.h rename to src/CalculatorUnitTests/AsyncHelper.h diff --git a/src/CalculatorUnitTests_VS/CalcEngineTests.cpp b/src/CalculatorUnitTests/CalcEngineTests.cpp similarity index 100% rename from src/CalculatorUnitTests_VS/CalcEngineTests.cpp rename to src/CalculatorUnitTests/CalcEngineTests.cpp diff --git a/src/CalculatorUnitTests_VS/CalcInputTest.cpp b/src/CalculatorUnitTests/CalcInputTest.cpp similarity index 100% rename from src/CalculatorUnitTests_VS/CalcInputTest.cpp rename to src/CalculatorUnitTests/CalcInputTest.cpp diff --git a/src/CalculatorUnitTests_VS/CalculatorManagerTest.cpp b/src/CalculatorUnitTests/CalculatorManagerTest.cpp similarity index 100% rename from src/CalculatorUnitTests_VS/CalculatorManagerTest.cpp rename to src/CalculatorUnitTests/CalculatorManagerTest.cpp diff --git a/src/CalculatorUnitTests_VS/CalculatorUnitTests_VS.rc b/src/CalculatorUnitTests/CalculatorUnitTests.rc similarity index 100% rename from src/CalculatorUnitTests_VS/CalculatorUnitTests_VS.rc rename to src/CalculatorUnitTests/CalculatorUnitTests.rc diff --git a/src/CalculatorUnitTests_VS/CalculatorUnitTests_VS.vcxproj b/src/CalculatorUnitTests/CalculatorUnitTests.vcxproj similarity index 98% rename from src/CalculatorUnitTests_VS/CalculatorUnitTests_VS.vcxproj rename to src/CalculatorUnitTests/CalculatorUnitTests.vcxproj index 63730e7..f7e40b2 100644 --- a/src/CalculatorUnitTests_VS/CalculatorUnitTests_VS.vcxproj +++ b/src/CalculatorUnitTests/CalculatorUnitTests.vcxproj @@ -2,7 +2,7 @@ {d3baed2c-4b07-4e1d-8807-9d6499450349} - CalculatorUnitTests_VS + CalculatorUnitTests en-US 15.0 true @@ -129,7 +129,7 @@ - CalculatorUnitTests_VS_TemporaryKey.pfx + CalculatorUnitTests_TemporaryKey.pfx 3F0C32266A4D995CC08C9AEC3960CFF3EF0D1853 @@ -259,7 +259,7 @@ - + @@ -269,7 +269,7 @@ - + diff --git a/src/CalculatorUnitTests_VS/CalculatorUnitTests_VS.vcxproj.filters b/src/CalculatorUnitTests/CalculatorUnitTests.vcxproj.filters similarity index 100% rename from src/CalculatorUnitTests_VS/CalculatorUnitTests_VS.vcxproj.filters rename to src/CalculatorUnitTests/CalculatorUnitTests.vcxproj.filters diff --git a/src/CalculatorUnitTests/CalculatorUnitTests_TemporaryKey.pfx b/src/CalculatorUnitTests/CalculatorUnitTests_TemporaryKey.pfx new file mode 100644 index 0000000000000000000000000000000000000000..d4e928e86b82c8002615ff2abe96c1409ed2db26 GIT binary patch literal 2536 zcmZWpc{tQ-8~)80!x+gnGm`CCjx}bCCHu%O*^X098Qa)*8rc$N?8`)UA|zXUhzvP0 zDN`I2iI8k5TgZ~EeRI0L@0{zqzCWJ#xu5%f@8^C0c;5$2hJ6HsSkPoxDHJA`V4ARd z0>lO?CBrfyWLP?rPDYbi_y0#?U4f8UKQrlhW=uoj|8a40fWW0>$T6A>*+&aOIsQvC zn{z?fBOBFD9h9FE1%ugML&%VKD0Oq&q=e8^r}7uKi95sES8hJL9=arXFWQz{O;bts zbVnFHi9-X^ViA_b=XvG}7J$%3aVbgS`rB^|AZ$e&7iRGiirMBmk zR^P;LdP-@Ea$Q^7MPQ%m3zdV-lM2wP;@&74HRZLmX|hL7_x{ruGz}_+X2EGaCy3bFP>c_0GPzmU>xZBg zwr>s@J6lMF_%8SYd{9qbFlk)Ae%k5@g+X?omMA)Sg8MQkdaddu?}uUQt7+>wjhpm@ zue$zPwZ@0K`?UpbUA%>J)wEY{SV}HGhsQ3o2{zOP>c!>sOD9_w+qtI)^2|m*$lW!n z?>-}UN6V_PoQ8)B?F!L7H2bsknv&Xo72TA3(_(r@Kv#7-ti3bZlcnp1CUqH#MZMVh z)6nSQ%Hel6{*7q;(F2IZIf@l#^oV2^9-25*u;IP-^xXAfcKTTc>p5Y~{^j$i#rcN3 z$KmVJxicC+2o|YmuUm)%`OPh>wy6X4UEz7f^WT99)IEi=qt+qzw~){`p{#KZbn(^s z`_`kOCCRI&=@jR%>m50jfAkt@X)s2JBuS1O}EA z|B5mf@JlkVbGt$49Z3@q&yej^SYF>UaM^jRwJ6N(5;+(=r|GWkTnTR{G~J_KjfU=7 z(mjh+JWWNb5^;p!iD#RmS@i40RKw$oP~e_^8oLTc1~^ z(;_y$0rtrEG97^iixXVNcZZQYS+_Iw^2&NYDG#Y|^%Whhbi7^4(-nMFoMD>2fU}EH zlu6)iD>&8*k{InGJ=096#!FT?WYlw;KGNivd)~%>#??qYxZ?1eEAE<#;o+s6f!4&e zhP%`TZky|qeAun6$TF`j=vcvLHSK^luualDw&HVEPq&}!>BJeuv*GRR5;B6{%?T*% zm^|`{IA=W=qxby|StD0I0Af5D^^wJVC+bD@ade1v^_nhXP@_QB;9UKz0cOF-ji!U3 zr)mo)*YrFTFYpU`hf8<36`ENU9)TIUs;=P_44fd|W5z*XEd{_2EfB#=1 zdSl&fQ79Y&Xz*B%zX&h1qzLHPD9#xQa0Y@KSGlF-eh=4)8IHgC`jK)S)JmlP&let| z!-uZiN|H>x&^gu1~)VALZXWiNaVfw5TMmZG;lEqCKLGMi`J4$dw%S zN5&3q=Ld#)=6+a%Qn1cmt!2U|AF3L!NVwFa6f4tBNSw~_6s_|7herr7Xaz0p-W8G% z2Yt}%N_U;AAFZuWQ#&tDET-G%S=hz#N^Sx+nsKMP+RS*%p-$j^y!%>DC&KTYQ!Ax* zY;@`l*K^$W%-@5vWH7MFKm;&9!v#O3HfwTLBf z0q|nB3I+mzYs_#5NPrmd8*}}O@drGZl>rln1A$B~fLRAKTLl81KV4#g_0N6RnUyQ^ zs9-diCGqc@vq4MAEMZKF1O@@jsS@b1COsKMMmVSm1C5NXT1s|By6zh z7j36Goss!4lBZrdBTPG%#$n$gFr}_d)dv$rW2UP3XHmT$YGGWN-}G2Z*gBP@FXHtl z(|lreh)G6f@yDG5Ca-GZlApIY%(xNSrpCwi=dDzfbb|C3E za0GbNLT4}Q#DV>+WLsk)^8VBFEA?|p+q>hi)zEllSYU=~ti4}r1+7zrVrBRF;DjWsgpa1q5H~@4X-sE^$-Tqo|Uo5)V?&r@0qTJ~kD*NF+^qYyMbO z_M4Awi+KPIlK2HOI`(OA@K|=oSg2X0c3kWBZ8YVUBBFFtEt?(u{hsD(>lX`)ZRKnw z;oWg+vE5x7QZwcO#;7Ec+^HH7MWZFnE24`;4w@P3HCP)n9E_-Dh;+e4yJnNVjIP%5 zWD6Q2w`%i5Q}#H`PH`N+%$F#;GsS#vR)LN^x!}=?PYs<2ULjJc8)(S8cd@n2%ZM&Z_2$?-h3q# zGq@Q-PzXvGy^7A*(sAr{vF%*hz#`WBtYc2<=*D&t%|44Oq>{2D65|(c7!Hj87F&me z`l)!vqp{#$AMoFj=XF~E literal 0 HcmV?d00001 diff --git a/src/CalculatorUnitTests_VS/CopyPasteManagerTest.cpp b/src/CalculatorUnitTests/CopyPasteManagerTest.cpp similarity index 100% rename from src/CalculatorUnitTests_VS/CopyPasteManagerTest.cpp rename to src/CalculatorUnitTests/CopyPasteManagerTest.cpp diff --git a/src/CalculatorUnitTests_VS/CurrencyConverterUnitTests.cpp b/src/CalculatorUnitTests/CurrencyConverterUnitTests.cpp similarity index 100% rename from src/CalculatorUnitTests_VS/CurrencyConverterUnitTests.cpp rename to src/CalculatorUnitTests/CurrencyConverterUnitTests.cpp diff --git a/src/CalculatorUnitTests_VS/DateCalculatorUnitTests.cpp b/src/CalculatorUnitTests/DateCalculatorUnitTests.cpp similarity index 100% rename from src/CalculatorUnitTests_VS/DateCalculatorUnitTests.cpp rename to src/CalculatorUnitTests/DateCalculatorUnitTests.cpp diff --git a/src/CalculatorUnitTests_VS/DateUtils.h b/src/CalculatorUnitTests/DateUtils.h similarity index 100% rename from src/CalculatorUnitTests_VS/DateUtils.h rename to src/CalculatorUnitTests/DateUtils.h diff --git a/src/CalculatorUnitTests_VS/Helpers.h b/src/CalculatorUnitTests/Helpers.h similarity index 100% rename from src/CalculatorUnitTests_VS/Helpers.h rename to src/CalculatorUnitTests/Helpers.h diff --git a/src/CalculatorUnitTests_VS/HistoryTests.cpp b/src/CalculatorUnitTests/HistoryTests.cpp similarity index 100% rename from src/CalculatorUnitTests_VS/HistoryTests.cpp rename to src/CalculatorUnitTests/HistoryTests.cpp diff --git a/src/CalculatorUnitTests_VS/Mocks/CurrencyHttpClient.cpp b/src/CalculatorUnitTests/Mocks/CurrencyHttpClient.cpp similarity index 100% rename from src/CalculatorUnitTests_VS/Mocks/CurrencyHttpClient.cpp rename to src/CalculatorUnitTests/Mocks/CurrencyHttpClient.cpp diff --git a/internal/CalculatorUnitTests/Mocks/CurrencyHttpClient.h b/src/CalculatorUnitTests/Mocks/CurrencyHttpClient.h similarity index 100% rename from internal/CalculatorUnitTests/Mocks/CurrencyHttpClient.h rename to src/CalculatorUnitTests/Mocks/CurrencyHttpClient.h diff --git a/src/CalculatorUnitTests_VS/Module.cpp b/src/CalculatorUnitTests/Module.cpp similarity index 100% rename from src/CalculatorUnitTests_VS/Module.cpp rename to src/CalculatorUnitTests/Module.cpp diff --git a/src/CalculatorUnitTests_VS/MultiWindowUnitTests.cpp b/src/CalculatorUnitTests/MultiWindowUnitTests.cpp similarity index 100% rename from src/CalculatorUnitTests_VS/MultiWindowUnitTests.cpp rename to src/CalculatorUnitTests/MultiWindowUnitTests.cpp diff --git a/src/CalculatorUnitTests_VS/NavCategoryUnitTests.cpp b/src/CalculatorUnitTests/NavCategoryUnitTests.cpp similarity index 100% rename from src/CalculatorUnitTests_VS/NavCategoryUnitTests.cpp rename to src/CalculatorUnitTests/NavCategoryUnitTests.cpp diff --git a/src/CalculatorUnitTests_VS/Package.appxmanifest b/src/CalculatorUnitTests/Package.appxmanifest similarity index 78% rename from src/CalculatorUnitTests_VS/Package.appxmanifest rename to src/CalculatorUnitTests/Package.appxmanifest index 9bd25f9..503376f 100644 --- a/src/CalculatorUnitTests_VS/Package.appxmanifest +++ b/src/CalculatorUnitTests/Package.appxmanifest @@ -3,7 +3,7 @@ - CalculatorUnitTests_VS + CalculatorUnitTests Microsoft Corporation Assets\StoreLogo.png @@ -14,8 +14,8 @@ - - + + diff --git a/src/CalculatorUnitTests_VS/StandardViewModelUnitTests.cpp b/src/CalculatorUnitTests/StandardViewModelUnitTests.cpp similarity index 100% rename from src/CalculatorUnitTests_VS/StandardViewModelUnitTests.cpp rename to src/CalculatorUnitTests/StandardViewModelUnitTests.cpp diff --git a/src/CalculatorUnitTests_VS/Test.resw b/src/CalculatorUnitTests/Test.resw similarity index 100% rename from src/CalculatorUnitTests_VS/Test.resw rename to src/CalculatorUnitTests/Test.resw diff --git a/src/CalculatorUnitTests_VS/UnitConverterTest.cpp b/src/CalculatorUnitTests/UnitConverterTest.cpp similarity index 100% rename from src/CalculatorUnitTests_VS/UnitConverterTest.cpp rename to src/CalculatorUnitTests/UnitConverterTest.cpp diff --git a/src/CalculatorUnitTests_VS/UnitConverterViewModelUnitTests.cpp b/src/CalculatorUnitTests/UnitConverterViewModelUnitTests.cpp similarity index 100% rename from src/CalculatorUnitTests_VS/UnitConverterViewModelUnitTests.cpp rename to src/CalculatorUnitTests/UnitConverterViewModelUnitTests.cpp diff --git a/src/CalculatorUnitTests_VS/UnitConverterViewModelUnitTests.h b/src/CalculatorUnitTests/UnitConverterViewModelUnitTests.h similarity index 100% rename from src/CalculatorUnitTests_VS/UnitConverterViewModelUnitTests.h rename to src/CalculatorUnitTests/UnitConverterViewModelUnitTests.h diff --git a/src/CalculatorUnitTests_VS/UnitTestApp.rd.xml b/src/CalculatorUnitTests/UnitTestApp.rd.xml similarity index 100% rename from src/CalculatorUnitTests_VS/UnitTestApp.rd.xml rename to src/CalculatorUnitTests/UnitTestApp.rd.xml diff --git a/src/CalculatorUnitTests_VS/UnitTestApp.xaml b/src/CalculatorUnitTests/UnitTestApp.xaml similarity index 100% rename from src/CalculatorUnitTests_VS/UnitTestApp.xaml rename to src/CalculatorUnitTests/UnitTestApp.xaml diff --git a/src/CalculatorUnitTests_VS/UnitTestApp.xaml.cpp b/src/CalculatorUnitTests/UnitTestApp.xaml.cpp similarity index 100% rename from src/CalculatorUnitTests_VS/UnitTestApp.xaml.cpp rename to src/CalculatorUnitTests/UnitTestApp.xaml.cpp diff --git a/src/CalculatorUnitTests_VS/UnitTestApp.xaml.h b/src/CalculatorUnitTests/UnitTestApp.xaml.h similarity index 100% rename from src/CalculatorUnitTests_VS/UnitTestApp.xaml.h rename to src/CalculatorUnitTests/UnitTestApp.xaml.h diff --git a/src/CalculatorUnitTests_VS/UtilsTests.cpp b/src/CalculatorUnitTests/UtilsTests.cpp similarity index 100% rename from src/CalculatorUnitTests_VS/UtilsTests.cpp rename to src/CalculatorUnitTests/UtilsTests.cpp diff --git a/src/CalculatorUnitTests_VS/pch.cpp b/src/CalculatorUnitTests/pch.cpp similarity index 100% rename from src/CalculatorUnitTests_VS/pch.cpp rename to src/CalculatorUnitTests/pch.cpp diff --git a/src/CalculatorUnitTests_VS/pch.h b/src/CalculatorUnitTests/pch.h similarity index 100% rename from src/CalculatorUnitTests_VS/pch.h rename to src/CalculatorUnitTests/pch.h diff --git a/src/CalculatorUnitTests_VS/resource.h b/src/CalculatorUnitTests/resource.h similarity index 100% rename from src/CalculatorUnitTests_VS/resource.h rename to src/CalculatorUnitTests/resource.h diff --git a/src/CalculatorUnitTests_VS/Assets/LockScreenLogo.scale-200.png b/src/CalculatorUnitTests_VS/Assets/LockScreenLogo.scale-200.png deleted file mode 100644 index 735f57adb5dfc01886d137b4e493d7e97cf13af3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1430 zcmaJ>TTC2P7~aKltDttVHYH6u8Io4i*}3fO&d$gd*bA_<3j~&e7%8(eXJLfhS!M@! zKrliY>>6yT4+Kr95$!DoD(Qn-5TP|{V_KS`k~E6(LGS@#`v$hQo&^^BKsw3HIsZBT z_y6C2n`lK@apunKojRQ^(_P}Mgewt$(^BBKCTZ;*xa?J3wQ7~@S0lUvbcLeq1Bg4o zH-bvQi|wt~L7q$~a-gDFP!{&TQfc3fX*6=uHv* zT&1&U(-)L%Xp^djI2?~eBF2cxC@YOP$+9d?P&h?lPy-9M2UT9fg5jKm1t$m#iWE{M zIf%q9@;fyT?0UP>tcw-bLkz;s2LlKl2qeP0w zECS7Ate+Awk|KQ+DOk;fl}Xsy4o^CY=pwq%QAAKKl628_yNPsK>?A>%D8fQG6IgdJ ztnxttBz#NI_a@fk7SU`WtrpsfZsNs9^0(2a z@C3#YO3>k~w7?2hipBf{#b6`}Xw1hlG$yi?;1dDs7k~xDAw@jiI*+tc;t2Lflg&bM)0!Y;0_@=w%`LW^8DsYpS#-bLOklX9r?Ei}TScw|4DbpW%+7 zFgAI)f51s}{y-eWb|vrU-Ya!GuYKP)J7z#*V_k^Xo>4!1Yqj*m)x&0L^tg3GJbVAJ zJ-Pl$R=NAabouV=^z_t;^K*0AvFs!vYU>_<|I^#c?>>CR<(T?=%{;U=aI*SbZADLH z&(f2wz_Y0??Tf|g;?|1Znw6}6U43Q#qNRwv1vp9uFn1)V#*4p&%$mP9x&15^OaBiDS(XppT|z^>;B{PLVEbS3IFYV yGvCsSX*m diff --git a/src/CalculatorUnitTests_VS/Assets/SplashScreen.scale-200.png b/src/CalculatorUnitTests_VS/Assets/SplashScreen.scale-200.png deleted file mode 100644 index 023e7f1feda78d5100569825acedfd213a0d84e9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 7700 zcmeHLYj~4Yw%(;oxoEH#Kxq-eR|+VkP17b#Vk;?4QwkI+A{L04G+#<<(x#Un1#+h5>eArRq zTw$)ZvTWW_Y?bDho0nPVTh08+s`sp!j74rJTTtXIDww0SILedFv?sZ?yb@@}GN;#8 znk_b~Q(A0YR#uV4ef!osoV1M3;vQ8N$O|fStfgf$S5;ddUNv`tWtGjM;koG#N;7M< zP*84lnx(bn_KF&9Z5Ai$)#Cs3a|$OFw>WKCT$of*L7_CqQEinflT|W{JT+aKp-E0v zsxmYg)1(T>DROm+LN1eQw8}KCTp=C!$H7`PU!t9_Hw@TsTI2`udRZv*!a5`#A9hK6Y95L(CDUX&_@QxKV z_feX{UhA#ZWlvgpL$#w^D#lq`_A4AzDqd|Zv6y9PX&DNcN|l}_D^{q@GG&H^Pg583 z8FI6N8^H7b5WjGp;urW)d7F+_lcp%KsLX0viCmE(OHH+=%ZfD_=`voUuoUxFO^L;- z;!;2{g-YiiO6m4bs89OuF9!p{FGtH-f%8<2gY!h9s)4ciN%{Kh1+`}{^}M~+TDH9N z^Z5PlgVXMC&2&k*Hw^Lb9gny#ro$MOIxIt{+r)EA10$VR3 zanN8D{TUkl+v0CQ_>ZoHP<M-x#8@8ZiT#$Kh`(uRaX1g$Bg|qy$<#7 zSSAi{Nb8Y=lvNVeio+UGLCAtoLBfL`iOv`)yoJMDJBN>4IH@(l7YRF;61@>qq1iM9 zr@b#OC~SAxSle?5Pp8Z78{VO0YFr1x7kZU64Z23eLf2T2#6J_t;-E}DkB?NufZ0Ug zi?J&byXeaB-uTNVhuiM!UVQw}bZrJ3GtAETYp->!{q#zfN7D3AS9@Q7*V^85jGx#R z(QxYV(wW#F0XF9^^s>>H8pPlVJ>)3Oz z&_X8Sf@~?cH_O*cgi$U#`v`RRfv#y3m(ZpKk^5uLup+lVs$~}FZU$r_+}#hl%?g5m z-u-}-666ssp-xWQak~>PPy$mRc|~?pVSs1_@mBEXpPVfLF6(Ktf1S* zPPh@QZ=tFMs?LM2(5P3L2;l_6XX6s&cYsP1ip#eg0`ZEP0HGYh{UmS@o`MihLLvkU zgyAG0G`b1|qjxxh1(ODKFE%AP}Dq=3vK$P7TXP4GrM1kQ72!GUVMDl`rDC&2;TA}*nF z8$nQD&6ys_nc1*E7$*1S@R8$ymy(sQV}imGSedB@{!QR5P&N_H=-^o!?LsWs+2|mH z-e=)T^SvI)=_JIm7}j4;@*Z17=(#}m=~YF~z~CLI+vdAGlJDcdF$TM?CVI1%LhUrN zaa6DJ=Yh$)$k&Oz{-~8yw^GM^8prYxSxo zvI4k#ibryMa%%*8oI-5m61Koa_A_xg=(fwp0aBX{;X4Q;NXUhtaoJDo1>TqhWtn=_ zd5~chq#&6~c%8JZK#t_&J(9EVUU&upYeIovLt1>vaHe}UUq>#RGQj!EN#5+0@T`(@ z^g~>*c`VGRiSt;!$_4+0hk^I!@O3``5=sZ8IwlxWW7km1B&_t&E*u0_9UBa#VqwY* zz>nxv?FAsVnRaD(Bui=6i==BFUw0k4n$>`umU`F2l?7CYTD^)c2X+d9X&ddS9|gj? zM?knGkGCX&W8offw8aLC2$D{PjC3nVZwd4k?eZH8*mZ)U@3Qk8RDFOz_#WUA#vnzy zyP>KrCfKwSXea7}jgJjBc}PGY+4#6%lbZyjhy`5sZd_Vy6Wz;ixa?czkN}J9It1K6 zY!eu>|AwF^fwZlLAYyQI*lM@^>O>Iu6Vf6i>Q$?v!SeUS<{>UYMwz$*%Aq?w^`j{h z!$GZbhu=^D{&ET8;))LL%ZBDZkQqRd2;u~!d9bHGmLRhLDctNgYyjsuvoSZ#iVdoB z2!f--UUA#U;<{je#?cYt^{PIyKa%hW>}uepWMyAI{{Zo7?2>?$c9;whJae%oN|I-kpTQSx_C$Z&;f zi2i)qmEn=y4U0uvk)$m;zKfjPK@oc?I`}1Jzl$Q~aoKBd3kt7L#7gyt|A_qgz6ai< z=X%D1i!d2h?rHR^R8SUj&G||dkC?DT>{o#Yau<@uqVT{Xef&XG}5*E4aPk{}~ zplx&XhaV)&1EfI3Em;Bw#O5SV^c;{twb-1Rw)+=0!e_BLbd7tYmXCH0wrlOSS+~`7He8Iqx0{CN+DVit9;*6L~JAN zD&cyT)2?h}xnYmL?^)<7YyzZ3$FHU^Eg;DLqAV{#wv#Wj7S`Jdl1pX&{3(uZ?!uh} zDc$ZTNV*7le_W6}Hju~GMTxZQ1aWCeUc%!jv3MHAzt>Y-nQK%zfT*3ebDQA5b?iGn; zBjv3B+GhLTexd_(CzZDP4|#n5^~scvB6#Pk%Ho!kQ>yYw((Dv{6=$g3jT1!u6gORW zx5#`7Wy-ZHRa~IxGHdrp(bm%lf>2%J660nj$fCqN(epv@y!l9s7@k6EvxS{AMP>WY zX4$@F8^kayphIx-RGO$+LYl9YdoI5d|4#q9##`_F5Xnx`&GPzp2fB{-{P@ATw=X@~ z_|&^UMWAKD;jjBKTK(~o?cUFRK8EX=6>cXpfzg4ZpMB>*w_^8GSiT-Jp|xBOnzM+j z*09-@-~qJ(eqWq5@R4i^u4^{McCP(!3}C|v_WsTR*bIUxN(Nx`u##3B4{sE`Z`v8w zAwIG`?1~PkID~W{uDzmqH98Pew_1(;x2%8r^vY{)_&J2K)cN{W+h5+g)ZcjP&Ci#O zgy|8K@4kyMfwilHd&6TDlhb%++Pk!>9HRld6HT7gwyZGrxS$}CsD6`>6!!2K1@Mjf z(P0WYB7V_OFZyeWrbOFb>O54BNXf~K&?}3=^v;v_wT{DKr?jN^DtN&DXwX%u?s*c6`%8>WFz z7}YW^tp0bp^NriE)AB6M2l<7rn7fzePtR*omOevpfm9n?}2V*+0iW;S)C zhg`NAjL?D=W#k*$aR{>pGf~lD-rVtD;5jW1_*Jn1j1=es@Kcx4ySM_bwcQCT=d+DV z>Sz~L=Hj@(X%31nK$mWI@7d>}ORB`K(p=+`UD)+99YUGQc7y^bHZ1F(8|tL0 zdK*DT0kSXG_{BKTpP2*2PecdKV9;dq$^ZZDP;Nyq1kp-&GI5eAyZsK!e3V zK@rPy*{(`KIfo+lc878mDKk^V#`VT05}64kBtk%DgwLrOvLMj5-;*GNKv6c6pzMuL z6EP%ob|_0IW}lLRXCP2!9wWhEw3LA7iF#1O1mIZ@Z=6&bz41F;@S_GvYAG-#CW3z{ zP3+6vHhvP&A3$##Vo9$dT^#MoGg^|MDm=Bt1d2RRwSZ<;ZHICpLBv5Xs!D?BH^(9_ z7`H=N&^v|Z-%mP}wNzG{aiFCsRgwzwq!N6obW9+7(R; z(SZ=23`|`>qil!LMGG{_Heq!BD>(Y-zV9wD)}hz25JA37YR%39;kI4y9pgtcUass6 zP24}ZY$vvYeI`zy&)A_X#nY3017ap*0&jx|mVwyGhg3;!keU53a}Uhm3BZI$N$6Se zLWlAmy1S0xKJm4G_U@sN_Tm=`$xWJSEwKU98rZ&)1R^*$$1vA3oG#&*%SMxY_~oGP zP&PFJatFLM-Ps%84IV-+Ow)T{C7cqUAvauy4C z(FRz&?6$Rypj{xO!`y=*J5o4@U8Q-(y5(*=YoKeZ+-1YdljXxkA#B)zo=FeQH#?Le zycNUmEEHWO9a=X^pb#&cOq7-`7UA87#|S22)<7RUtZo|(zibX=w;K3qur9vy#`MNV z6UUcf9ZwEnKCCp+OoBnF@OdbvH)ANXO0o~Pi9l8=x3))}L<#vO0-~O4!~--Ket?d} zJaqsj<@CD1%S2cTW%rOP{Vto%0sGW~1RMa_j^)5nil0Yw- z0EE#bP+l4#P^%PQ+N*oxu1Zq05xZ!bXfYTg>9c{(Iw*lnjR^>kz%lAN^zFce7rppy zY8zA~3GD=A6d*hze&l4D_wA~+O!56)BZTe_rEu}Ezi<4!kG|W#amBZ5{&XS2@6R~H z{9o^y*BkH4$~yX9U&@CgbOzX1bn9xqF|zh$Dh0Y5y*E0e90*$!ObrHY3Ok0`2=O~r zCuke6KrP9KOf?V(YDsM<6pX2nVoN%M$LT^q#FmtaF?1^27F*IcNX~XRB(|hCFvdcc zc)$=S-)acdk$g4?_>jRqxpI6M3vHZk?0c^3=byamYDNf;uB{3NlKW5IhnOS3DNkMV z?tK8?kJ}pmvp%&&eTVOVjHP`q34hN1@!aK}H(K!vI`~gf|Gv+FNEQD5Yd<~yX7k_l h&G-K)@HZb3BABY{)U1?^%I#E6`MGoTtustd{~yM6srvu` diff --git a/src/CalculatorUnitTests_VS/Assets/Square150x150Logo.scale-200.png b/src/CalculatorUnitTests_VS/Assets/Square150x150Logo.scale-200.png deleted file mode 100644 index af49fec1a5484db1d52a7f9b5ec90a27c7030186..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2937 zcma)84OCO-8BSud5)jwMLRVKgX(S?$n?Ld|vrsm<$CF7)&zTbyy1FE5bU`Q17MRv`9ue$;R(@8kR;#vJ*IM0>cJIAOte!d7oRgdH zd%ySjdB6L9=gX^A6)VzH7p2l@v~3zJAMw|DFy#^)F@@F*`mqUn=Il>l)8_+ab;nOW{%+iPx z+s{Eu|&pIs)Z7{La9~?xKfyl z#43?gjEL15d4WbOZo#SiP%>DB^+BcnJ=7dHEe;r#G=tuw|ka z%q@}##Uh7;tc%L_64m(kHtw74ty%BJMb)_1)#S0j`)F8_1jF7vScpsnH=0V19bO8y zR`0SjIdCUo&=>JwMQF8KHA<{ODHTiQh}0^@5QRmCA?gOH6_H3K^-_sNB^RrdNuK-R zOO*vOrKCVvDwgUck`kF(E7j{I#iiN;b*ZdCt4m@HPA`EuEqGGf4%!K<;(=I=&Vyrw z%TwcWtxa}8mCZ%Cyf&ActJ6_$ox5z6-D!0-dvnRx6t7y3d+h6QYpKWO;8OdnvERo7 zuEf>ih5`wqY)~o@OeVt-wM?Q!>QzdGRj!bz6fzYrfw$hZfAKzr2-M+D+R>}~oT574c;_3zquHcElqKIsryILt3g8n3jcMb+j?i?-L3FpZJ z2WRVBRdDPc+G5aaYg#5hpE+6nQ|(VSoxT3|biF;BUq#==-27Xi=gihDPYP$7?=9cP zYKE$jeQ|3~_L0VG-(F~2ZPyD0=k{J4Q~h(t__{-mz_w8{JDY9{`1ouzz!Vr5!ECdE z6U~O1k8c}24V7~zzXWTV-Pe4)y}wQJS&q%H5`Fo_f_JvIU489aCX$;P`u#!I-=^4ijC2{&9!O&h>mi?9oYD=GC#%)6{GzN6nQYw+Fal50!#x^asjBBR50i`+mho*ttoqV)ubM2KD9S~k7+FR4>{29?6 z{!l6kDdyTN0YJ9LgkPWeXm|gyi@zM3?0@{&pXT12w|78&W-q!RRF)&iLCEZVH<|fR zN0fr2^t8H(>L?>K#>^+jWROLral(Qy-xoBq1U7A&DV||wClb)Otd9?(gZ|8znMF}D zf<1haWz^s0qgecz;RFGt0C-B4g`jNGHsFU+;{<%t65v^sjk^h$lmWn#B0#_)9ij&d z-~lc`A)YYExi^7sBuPM^Y|wA2g*5?`K?#7tzELQYNxGo$UB$4J8RJp1k(8Jj+~hMT zlN~>M@KTTh^--8y3PK_NZ@AC!{PT=CziBzGd+wTJ^@icH!Bd}%)g8V)%K?|c&WTUk zy}qv1C%(fjRoZ4ozC3{O%@5?)XzH35zHns$pgU*Q?fj4v?fp1Qbm+j;3l;9jam9Da zXVcKjPlQ73x78QPu|Ffm6x?`~e3oD=gl=4kYK?={kD5j~QCXU)`HSdduNNENzA*2$ zOm3PzF!lN5e*06-f1Uot67wY#{o-S1!KZ7E=!~7ynnk9_iJR#kFoNbAOT#^2Gd17F zMmvU6>lndZQGd|ax9kUoXXO+$N?|j@6qpsF&_j7YXvwo_C{JpmLw5&#e6k>atv%es z5)7r*Wvv_JkUpT}M!_o!nVlEk1Zbl=a*2hQ*<|%*K1Glj^FcF`6kTzGQ3lz~2tCc@ z&x|tj;aH&1&9HwcJBcT`;{?a+pnej;M1HO(6Z{#J!cZA04hnFl;NXA+&`=7bjW_^o zfC40u3LMG?NdPtwGl>Tq6u}*QG)}-y;)lu-_>ee3kibW(69n0$0Zy!}9rQz%*v1iO zT9_H>99yIrSPYVy6^);rR}7Yo=J_T@hi+qhTZXnVWyf;JDYm5#eYLTxr*?kiNn!+Y zQ+LUkBafNJ#rH#C(?d5^;gw9o#%daEI{mA*LHPIHPU`#|H$hD zwm>0&+kahQ)E#%~k>&5@&#Vg82H?s%71=)(soi@174pi9--2{w{1$}Sz4zGn3Du&x bht0Iza^2ykEt4(epJ78uh5nDlX8(TxzDYwP diff --git a/src/CalculatorUnitTests_VS/Assets/Square44x44Logo.scale-200.png b/src/CalculatorUnitTests_VS/Assets/Square44x44Logo.scale-200.png deleted file mode 100644 index ce342a2ec8a61291ba76c54604aea7e9d20af11b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1647 zcmaJ?eM}Q)7(e+G1Q(|`V9JhTI2>MkceK4;p;PR&$Pi?ejk3YQ_3o`S&|W_dsOZ8# zWPTt69g`t$ab`0cj-Y0yiBSOqmd)tG7G(}M5aP0_%&9TijB#&)I{zSE^4@#z^FF`l z`8{8`o%wlL(UI|y2!cdsuVamHH~H86F!*-15em4)NqUpCQM5?aoC_eCf@lV4wvF2a zjDQn1JBL69f&@2M3rvzJcfE!eZ8FZUBlFlC5RD)it33{mF9#B82AiyQE%w)`vlwa> zv{<1sm&kSKK$&%2jSFn7$t&P%%6Ue>R=EAnG8N7fqynWG8L3p!4801a;8{+nliO(qd(jNJ_?+9W3#hLIDLoT6~3fx9=`CC-D}-AMrpEO7HK zt3$GicGPc?GmDjy7K2P@La;eu4!$zWCZ`ym{Z$b zu-O6RM&K4JT|BIZB`E-gxqG%FzanI#+2FFmqHqXG7yxWB=w55RGOM)$xMb(>kSNR z2w=1AZi%z=AmG~yea~XaXJR!v7vLn(RUnELfiB1|6D84ICOS}^Zo2AdN}<&*h}G_u z{xZ!(%>tLT3J3<5XhWy-tg+6)0nmUUENLW8TWA{R6bgVd3X;anYFZ^IRis*_P-C-r z;i>%1^eL3UI2-{w8nuFFcs0e~7J{O2k^~Ce%+Ly4U?|=!0LH=t6()xi<^I-rs+9sF z*q{E-CxZbGPeu#a;XJwE;9S1?#R&uns>^0G3p`hEUF*v`M?@h%T%J%RChmD|EVydq zmHWh*_=S%emRC*mhxaVLzT@>Z2SX0u9v*DIJ@WC^kLVdlGV6LpK$KIrlJqc zpJ921)+3JJdTx|<`G&kXpKkjGJv=76R`yYIQ{#c-`%+`#V(7}Q;&@6U8!Td1`d;?N z_9mnI#?AA}4J!r)LN4!E-@H5eXauuB7TOawS>Y|{-P?NNx-lq+z1W-+y(;39P&&LP zL{N80?&=C*qKmdA^moMZRuPcD!B<*mq$ch=0Cnlitw#txRWhb3%TQvPqjkC`F69G4b! ze7z9MZ#+;_#l?H37UqUhDFb^l&s2{oM$3I0o^Q!yx;;V)QmCMo)Tb_ui|mit8MS?U zm##6$sZZ1$@|s%?l@>4Z<*Q}sRBSKMhb4I{e5LdEhsHIHTe8Bod5c>6QtT>$XgUBz z6MK`kO$=jmt@FqggOhJ5j~e@ygRbG;<{Vu)*+nn9aQeo0;$#j;|MS=S$&L?BeV25z xs3B`@=#`5TF{^6(A1rvdY@|-RtQ|iS5{tyX+wH?;n8E)G$kykv-D^wh{{!TZT%7;_ diff --git a/src/CalculatorUnitTests_VS/Assets/Square44x44Logo.targetsize-24_altform-unplated.png b/src/CalculatorUnitTests_VS/Assets/Square44x44Logo.targetsize-24_altform-unplated.png deleted file mode 100644 index f6c02ce97e0a802b85f6021e822c89f8bf57d5cd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1255 zcmaJ>TWs4@7*5+{G#S+&C!qC#> zf>5N3P6jO*Cz>ug*(_DmW=)kea&m$gZ^+nyiF`;j%w@}y8)>p*SH}C`m?DXeieF2U zyQHecc_L%Gh!7GMt+hG06y;+|p4>m~}PjA}rKViGiEnn7G0ZO<>G|7q;2?NwGCM3s?eued6%hd$B+ z*kQJ{#~$S=DFE(%=E+UkmlEI*%3llUf~8Ja9YU1Vui0IbGBkW_gHB%Rd&!!ioX zs40O?i9I{};kle7GMvE7(rk`la=gTI)47=>%?q@^iL-nUo3}h4S}N-KHn8t5mVP8w z&bSErwp+37 zNJJ8?a|{r5Q3R0Z5s-LB1WHOwYC@7pCHWND#cL1cZ?{kJ368_*(UDWUDyb<}0y@o# zfMF016iMWPCb6obAxT$JlB6(2DrlXDTB&!0`!m??4F(qWMhjVZo?JXQmz`1*58Z=& zcDmB|S-E@j?BoFGix0flckqdS4jsPNzhfWyWIM98GxcLs89C(~dw%$_t;JjX-SD}E zfiGV;{8Q%8r}w9x>EEigW81>`kvnU@pK)4+xk9@+bNj9L!AAZ@SZ@q|)&BmY3+HZx zul~BeG4|}-;L%cHViQGQX?^zFfO0&#cHwel=d`lH9sJ-@Sl@n*(8J2>%Ac`IxyY?Q z{=GhWvC#gu-~Ia7*n{=+;qM?Ul_wy1+u7ho;=`>EwP^g~R@{unBds`!#@}tluZQpS zm)M~nYEifJWJGx?_6DcTy>#uh%>!H9=hb^(v`=m3F1{L>db=<5_tm+_&knAQ2EU$s Mu9UqpbNZeC0BbUo^Z)<= diff --git a/src/CalculatorUnitTests_VS/Assets/StoreLogo.png b/src/CalculatorUnitTests_VS/Assets/StoreLogo.png deleted file mode 100644 index 7385b56c0e4d3c6b0efe3324aa1194157d837826..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1451 zcmaJ>eN5D57_Z|bH;{0+1#mbl)eTU3{h)Wf7EZV?;HD@XL@{B`Ui%(2aMxQ~xdXSv z5nzWi(LW)U2=Vc-cY@s7nPt{i0hc6!7xN4NNHI#EQl>YNBy8l4%x9gr_W-j zEZMQmmTIy(>;lblRfh`dIyTgc9W5d!VP$L4(kKrN1c5G~(O_#xG zAJCNTstD^5SeXFB+&$h=ToJP2H>xr$iqPs-#O*;4(!Fjw25-!gEb*)mU}=)J;Iu>w zxK(5XoD0wrPSKQ~rbL^Cw6O_03*l*}i=ydbu7adJ6y;%@tjFeXIXT+ms30pmbOP%Q zX}S;+LBh8Tea~TSkHzvX6$rYb)+n&{kSbIqh|c7hmlxmwSiq5iVhU#iEQ<>a18|O^Sln-8t&+t`*{qBWo5M?wFM(JuimAOb5!K#D}XbslM@#1ZVz_;!9U zpfEpLAOz=0g@bd6Xj_ILi-x^!M}73h^o@}hM$1jflTs|Yuj9AL@A3<-?MV4!^4q`e z)fO@A;{9K^?W?DbnesnPr6kK>$zaKo&;FhFd(GYFCIU^T+OIMb%Tqo+P%oq(IdX7S zf6+HLO?7o0m+p>~Tp5UrXWh!UH!wZ5kv!E`_w)PTpI(#Iw{AS`gH4^b(bm^ZCq^FZ zY9DD7bH}rq9mg88+KgA$Zp!iWncuU2n1AuIa@=sWvUR-s`Qb{R*kk(SPU^`$6BXz8 zn#7yaFOIK%qGxyi`dYtm#&qqox0$h=pNi#u=M8zUG@bpiZ=3sT=1}Trr}39cC)H|v zbL?W)=&s4zrh)7>L(|cc%$1#!zfL?HjpeP%T+x_a+jZ16b^iKOHxFEX$7d|8${H-* zIrOJ5w&i$>*D>AKaIoYg`;{L@jM((Kt?$N$5OnuPqVvq**Nm}(f0wwOF%iX_Pba;V z;m@wxX&NcV3?<1+u?A{y_DIj7#m3Af1rCE)o`D&Y3}0%7E;iX1yMDiS)sh0wKi!36 zL!Wmq?P^Ku&rK~HJd97KkLTRl>ScGFYZNlYytWnhmuu|)L&ND8_PmkayQb{HOY640 bno1(wj@u8DCVuFR|31B*4ek@pZJqxCDDe1x diff --git a/src/CalculatorUnitTests_VS/Assets/Wide310x150Logo.scale-200.png b/src/CalculatorUnitTests_VS/Assets/Wide310x150Logo.scale-200.png deleted file mode 100644 index 288995b397fdbef1fb7e85afd71445d5de1952c5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3204 zcmbVPeQXow8NYmBd90>}0NP?GhXW~VaeThm=a0tV#EwJMI!)6M3}|c4_Bl3=Kd>G0 z(GHx1wl<7(tP?FsOQkTilSo*iIvF%uArExJ73~P zSv1xEy!U(Wd4A9D`FQV@W3@F^qJ@PEF$@z`Z!*BbFsS(^?B zyiAzJ+q})bkgiQHWqEb*jJD-coHYr1^iocg)l!Qa{Xqs-l~6J}p-|##ZHYofskQ3$ zI0;xzXyhazBeXhIsg5A=%ufo@f)1yy&ScKS0;HF^!r_2UE^lpZEom(+@duma3awTv zCrCL-%D_SvYWIcdHkmI}#50(fkUi)Qgx!80ju>g1za^}ff>JI8Z@^-iCiaCgg@TgF z+vtE?Q9{VQUX&MW9SYYmGcxA14%N2@7FwBTD4N<(2{nWgV8$e3?-F=L^&FrtWn~(U_Q~~^uYiyeY6-KoTnfh9AWz@ zIKje0)u!_Lw)E}G!#kEfwKVdNt(UAf9*f>tEL_(=xco-T%jTi@7YlC3hs2ik%Le0H ztj}RTeCF(5mwvi3_56>-yB?l;J>-1%!9~=fs|QcNG3J~a@JCu`4SB460s0ZO+##4fFUSGLcj_ja^fL4&BKALfb#$6$O?>P@qx2Agl^x0i&ugt zsy5Pyu=()`7HRMG3IB7F1@`_ z+-!J%#i6e^U$e#+C%Q>_qVRzWRsG^W_n+@OcX@vzI&z;mzHNb!GQ?LWA(wtpqHqTM z1OFw_{Zn?fD)p)`c`kOgv{de=v@suGRqY{N^U7gI1VF3*F=obwaXI6ob5__Yn zVTguS!%(NI09J8x#AO_aW!9W7k*UvB;IWDFC3srwftr{kHj%g)fvnAm;&h_dnl~

MY- zf+K}sCe8qU6Ujs`3ua{U0Of$R_gVQBuUA za0v=mu#vIOqiiAZOr&h*$WyOw&k-xr$;G4Ixa!#TJNr>95(h>l%)PUy4p+^SgR(uR zta%k*?ny-+nAr8spEk1fo{J4i!b^Fia`N{_F6@zidA2ZTTrjl#^5Z-2KfB@Cu}l9s z(*|Z2jc?p~vn2f)3y9i*7zJV1L{$?|&q)4oaT;uXi6>1GkRXVTOzAz(RHEmr=eFIi z`}<>-Q?K0GN8!IYxeP1XKXO+jsJbp~o^);Bc;%b7Flpe7;1`Ny@3r7ZR;?R)aJt8C ziNlEC<@3f_lIV4TwV}&e;D!Ee5_|e#g0LUh=5vmYWYm7&2h*M>QPKvGh9-)wfMMW3 z8J9b%1k7dzPzO0_NGQy92BZ^FR6R~6;^6?lqO;-QUP4BY%cG%3vEhbm#>4vIhPBh3 z-+pZGjh$x%Hp{?=FHsMp0&wNPlj00us{&`1ZOZTqs8%4X&xH=UDr*xyBW(Zp&Em94 zf)ZSfn#yg0N)>!1kWdkqJ^S*z0FF5|fj&qcE#Na|%OY0$uO>!&hP+1ywfD_WXk@4J(?MBftK7>$Nvqh@tDuarN%PrTLQ2Uzysx>UV=V zk^RrDSvdQ?0;=hY67EgII-f4`t=+i*yS=Y~!XlqIy_4x&%+OdfbKOFPXS2X5%4R{N z$SQMX^AK6(fA -#include - -using namespace std; -using namespace concurrency; -using namespace Platform; -using namespace CalculatorApp; -using namespace Windows::UI::Core; -using namespace Windows::ApplicationModel::Core; - -task AsyncHelper::RunOnUIThreadAsync(function&& action) -{ - auto callback = ref new DispatchedHandler([action]() - { - action(); - }); - - return create_task(CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(CoreDispatcherPriority::Normal, callback)); -} - -void AsyncHelper::RunOnUIThread(function&& action, DWORD timeout) -{ - task waitTask = RunOnUIThreadAsync([action]() - { - action(); - }); - - WaitForTask(waitTask, timeout); -} - -void AsyncHelper::Delay(DWORD milliseconds) -{ - thread timer(bind(CalculatorApp::AsyncHelper::Sleep, milliseconds)); - timer.join(); -} - -void AsyncHelper::Sleep(DWORD milliseconds) -{ - this_thread::sleep_for(chrono::milliseconds(milliseconds)); -} diff --git a/src/CalculatorUnitTests_VS/AsyncHelper.h b/src/CalculatorUnitTests_VS/AsyncHelper.h deleted file mode 100644 index de3a88e..0000000 --- a/src/CalculatorUnitTests_VS/AsyncHelper.h +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#pragma once -#include - -namespace CalculatorApp -{ - class AsyncHelper - { - public: - static concurrency::task RunOnUIThreadAsync(std::function&& action); - static void RunOnUIThread(std::function&& action, DWORD timeout = INFINITE); - static void Delay(DWORD milliseconds); - - template - static void RunOnUIThread(std::function()>&& action, DWORD timeout = INFINITE) - { - concurrency::task t; - concurrency::task uiTask = RunOnUIThreadAsync([&t, action]() - { - t = action(); - }).then([&t]() - { - t.wait(); - }, concurrency::task_continuation_context::use_arbitrary()); - - WaitForTask(uiTask, timeout); - } - - template - static bool WaitForTask(concurrency::task& t, DWORD timeout = INFINITE) - { - Microsoft::WRL::Wrappers::Event event(CreateEventEx(nullptr, nullptr, CREATE_EVENT_MANUAL_RESET, EVENT_ALL_ACCESS)); - if (!event.IsValid()) - { - throw std::bad_alloc(); - } - - Platform::Exception^ ex; - t.then([&event, &ex](concurrency::task prevTask) - { - try - { - prevTask.get(); - } - catch (Platform::Exception^ e) - { - ex = e; - } - - if (event.IsValid()) - { - SetEvent(event.Get()); - } - }, concurrency::task_continuation_context::use_arbitrary()); - - DWORD waitResult;// = STATUS_PENDING; - waitResult = WaitForSingleObjectEx(event.Get(), timeout, true); - event.Close(); - - if (ex != nullptr) - { - throw ex; - } - - if (waitResult == WAIT_FAILED) - { - throw ref new Platform::Exception(-1, L"Error in waiting for task completion: " + waitResult.ToString()); - } - - return waitResult == WAIT_OBJECT_0; - } - private: - static void Sleep(DWORD milliseconds); - }; -} diff --git a/src/CalculatorUnitTests_VS/Mocks/CurrencyHttpClient.h b/src/CalculatorUnitTests_VS/Mocks/CurrencyHttpClient.h deleted file mode 100644 index e9bff41..0000000 --- a/src/CalculatorUnitTests_VS/Mocks/CurrencyHttpClient.h +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#pragma once - -#include "CalcViewModel\DataLoaders\ICurrencyHttpClient.h" - -namespace CalculatorApp -{ - namespace DataLoaders - { - class CurrencyHttpClient : public ICurrencyHttpClient - { - public: - CurrencyHttpClient(); - - static Platform::String^ GetRawStaticDataResponse(); - static Platform::String^ GetRawAllRatiosDataResponse(); - - // ICurrencyHttpClient - void SetSourceCurrencyCode(Platform::String^ sourceCurrencyCode) override {} - void SetResponseLanguage(Platform::String^ responseLanguage) override {} - - virtual Windows::Foundation::IAsyncOperationWithProgress^ GetCurrencyMetadata() override; - virtual Windows::Foundation::IAsyncOperationWithProgress^ GetCurrencyRatios() override; - // ICurrencyHttpClient - }; - - public ref class MockAsyncOperationWithProgress sealed : - public Windows::Foundation::IAsyncOperationWithProgress - { - public: - MockAsyncOperationWithProgress(Platform::String^ result); - - // IAsyncInfo - virtual property Windows::Foundation::HResult ErrorCode - { - Windows::Foundation::HResult get(); - } - - virtual property unsigned int Id - { - unsigned int get() { return 128u; } - } - - virtual property Windows::Foundation::AsyncStatus Status - { - Windows::Foundation::AsyncStatus get() { return Windows::Foundation::AsyncStatus::Completed; } - } - - virtual void Cancel() {} - virtual void Close() {} - // IAsyncInfo - - // IAsyncOperationWithProgress - virtual property Windows::Foundation::AsyncOperationProgressHandler^ Progress - { - Windows::Foundation::AsyncOperationProgressHandler^ get() { return nullptr; } - void set(Windows::Foundation::AsyncOperationProgressHandler^ handler) {} - } - - virtual property Windows::Foundation::AsyncOperationWithProgressCompletedHandler^ Completed - { - Windows::Foundation::AsyncOperationWithProgressCompletedHandler^ get() { return nullptr; } - void set(Windows::Foundation::AsyncOperationWithProgressCompletedHandler^ handler) {} - } - - virtual Platform::String^ GetResults() { return m_result; } - // IAsyncOperationWithProgress - - private: - Platform::String^ m_result; - }; - } -}