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