Add Common_Test project and PathUtil_Test.cpp

The tests use the new Native Unit Test framework in VS2012.
This commit is contained in:
Birunthan Mohanathas 2013-06-12 23:11:59 +03:00
parent fed4b080b0
commit 3cebbc6b53
5 changed files with 150 additions and 0 deletions

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(SolutionDir)\Project.props" />
<PropertyGroup Label="Globals">
<ProjectGuid>{442084A6-2069-4927-B0C9-51525A720CB2}</ProjectGuid>
<ConfigurationType>DynamicLibrary</ConfigurationType>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<Import Project="$(SolutionDir)\Rainmeter.props" />
<PropertyGroup>
<OutDir>$(IntDir)</OutDir>
</PropertyGroup>
<ItemGroup>
<ClCompile Include="PathUtil_Test.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="Common.vcxproj">
<Project>{19312085-aa51-4bd6-be92-4b6098cca539}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="PathUtil_Test.cpp" />
</ItemGroup>
</Project>

108
Common/PathUtil_Test.cpp Normal file
View File

@ -0,0 +1,108 @@
/*
Copyright (C) 2013 Rainmeter Team
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "CppUnitTest.h"
#include "PathUtil.h"
#include <Shlobj.h>
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace PathUtil {
TEST_CLASS(Common_PathUtil_Test)
{
public:
TEST_METHOD(TestIsSeparator)
{
Assert::IsTrue(IsSeparator(L'\\'));
Assert::IsTrue(IsSeparator(L'/'));
Assert::IsFalse(IsSeparator(L'.'));
}
TEST_METHOD(TestIsDotOrDotDot)
{
Assert::IsTrue(IsDotOrDotDot(L"."));
Assert::IsTrue(IsDotOrDotDot(L".."));
Assert::IsFalse(IsDotOrDotDot(L"..."));
Assert::IsFalse(IsDotOrDotDot(L""));
}
TEST_METHOD(TestIsUNC)
{
Assert::IsTrue(IsUNC(L"\\\\server"));
Assert::IsTrue(IsUNC(L"//server"));
}
TEST_METHOD(TestIsAbsolute)
{
Assert::IsTrue(IsAbsolute(L"\\\\server"));
Assert::IsTrue(IsAbsolute(L"C:\\test"));
Assert::IsTrue(IsAbsolute(L"C:/test"));
Assert::IsFalse(IsAbsolute(L"C:"));
}
TEST_METHOD(TestAppendBacklashIfMissing)
{
std::wstring path;
AppendBacklashIfMissing(path);
Assert::IsTrue(path.empty());
std::wstring path2 = L"C:\\test";
AppendBacklashIfMissing(path2);
Assert::IsTrue(path2 == L"C:\\test\\");
std::wstring path3 = L"C:\\test\\";
AppendBacklashIfMissing(path3);
Assert::IsTrue(path3 == L"C:\\test\\");
}
TEST_METHOD(TestGetFolderFromFilePath)
{
Assert::IsTrue(GetFolderFromFilePath(L"C:\\test.txt") == L"C:\\");
}
TEST_METHOD(TestGetVolume)
{
Assert::IsTrue(GetVolume(L"C:\\test.txt") == L"C:");
Assert::IsTrue(GetVolume(L"\\\\server\\share\\") == L"\\\\server\\share");
Assert::IsTrue(GetVolume(L"\\\\server\\C:\\path\\") == L"\\\\server\\C:");
}
TEST_METHOD(TestExpandEnvironmentVariables)
{
WCHAR appdataPath[MAX_PATH];
SHGetFolderPath(nullptr, CSIDL_APPDATA, nullptr, SHGFP_TYPE_CURRENT, appdataPath);
WCHAR windirPath[MAX_PATH];
ExpandEnvironmentStrings(L"%WINDIR%", windirPath, MAX_PATH);
std::wstring test = L"%APPDATA%";
PathUtil::ExpandEnvironmentVariables(test);
Assert::IsTrue(test == appdataPath);
std::wstring test2 = L"%APPDATA%%WINDIR%";
PathUtil::ExpandEnvironmentVariables(test2);
Assert::IsTrue(test2 == ((std::wstring)appdataPath + windirPath));
std::wstring test3 = L"%APPDATA%%WINDIR%%APPDATA%";
PathUtil::ExpandEnvironmentVariables(test3);
Assert::IsTrue(test3 == ((std::wstring)appdataPath + windirPath + appdataPath));
}
};
} // namespace PathUtil

View File

@ -32,11 +32,14 @@
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<!-- Set the version macros to 0x0601 (Win7) to avoid using Win8 specific features in the Win8 SDK. -->
<PreprocessorDefinitions>WIN32;_WINDOWS;WINVER=0x0601;_WIN32_WINNT=0x0601;_WIN32_IE=0x0601;PSAPI_VERSION=1;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
</ClCompile>
<Link>
<AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary>
<ProgramDatabaseFile>$(IntDir)$(TargetName).pdb</ProgramDatabaseFile>
<RuntimeTypeInfo>false</RuntimeTypeInfo>

View File

@ -63,6 +63,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PluginWin7Audio", "Plugins\
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PluginWindowMessage", "Plugins\PluginWindowMessage\PluginWindowMessage.vcxproj", "{B9184DBA-C6B7-44FE-8BBD-0852DB22D2E4}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Common_Test", "Common\Common_Test.vcxproj", "{442084A6-2069-4927-B0C9-51525A720CB2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
@ -299,6 +301,12 @@ Global
{B9184DBA-C6B7-44FE-8BBD-0852DB22D2E4}.Release|Win32.Build.0 = Release|Win32
{B9184DBA-C6B7-44FE-8BBD-0852DB22D2E4}.Release|x64.ActiveCfg = Release|x64
{B9184DBA-C6B7-44FE-8BBD-0852DB22D2E4}.Release|x64.Build.0 = Release|x64
{442084A6-2069-4927-B0C9-51525A720CB2}.Debug|Win32.ActiveCfg = Debug|Win32
{442084A6-2069-4927-B0C9-51525A720CB2}.Debug|Win32.Build.0 = Debug|Win32
{442084A6-2069-4927-B0C9-51525A720CB2}.Debug|x64.ActiveCfg = Debug|x64
{442084A6-2069-4927-B0C9-51525A720CB2}.Debug|x64.Build.0 = Debug|x64
{442084A6-2069-4927-B0C9-51525A720CB2}.Release|Win32.ActiveCfg = Release|Win32
{442084A6-2069-4927-B0C9-51525A720CB2}.Release|x64.ActiveCfg = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE