Added the Test project to VS2017 solution + implemented test cases for MUtils::OS::known_folder() function.

This commit is contained in:
LoRd_MuldeR 2019-05-18 21:16:10 +02:00
parent b1fe06fc33
commit 5b013d080d
4 changed files with 328 additions and 0 deletions

View File

@ -5,6 +5,8 @@ VisualStudioVersion = 15.0.26430.16
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MUtilities", "MUtilities_VS2017.vcxproj", "{55405FE1-149F-434C-9D72-4B64348D2A08}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MUtilitiesTest", "test\MUtilitiesTest_VS2017.vcxproj", "{B7BCA0A5-17AD-4F20-A42C-CD6FFBD55D89}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
@ -18,8 +20,17 @@ Global
{55405FE1-149F-434C-9D72-4B64348D2A08}.Release_Static|x86.Build.0 = Release_Static|Win32
{55405FE1-149F-434C-9D72-4B64348D2A08}.Release|x86.ActiveCfg = Release|Win32
{55405FE1-149F-434C-9D72-4B64348D2A08}.Release|x86.Build.0 = Release|Win32
{B7BCA0A5-17AD-4F20-A42C-CD6FFBD55D89}.Debug|x86.ActiveCfg = Debug|Win32
{B7BCA0A5-17AD-4F20-A42C-CD6FFBD55D89}.Debug|x86.Build.0 = Debug|Win32
{B7BCA0A5-17AD-4F20-A42C-CD6FFBD55D89}.Release_Static|x86.ActiveCfg = Release_Static|Win32
{B7BCA0A5-17AD-4F20-A42C-CD6FFBD55D89}.Release_Static|x86.Build.0 = Release_Static|Win32
{B7BCA0A5-17AD-4F20-A42C-CD6FFBD55D89}.Release|x86.ActiveCfg = Release|Win32
{B7BCA0A5-17AD-4F20-A42C-CD6FFBD55D89}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {46D377DA-C6DC-44E6-9320-01A50F650EB9}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,168 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release_Static|Win32">
<Configuration>Release_Static</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\GlobalTest.cpp" />
<ClCompile Include="src\HashTest.cpp" />
<ClCompile Include="src\Main.cpp" />
<ClCompile Include="src\OSTest.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MUtilities_VS2017.vcxproj">
<Project>{55405fe1-149f-434c-9d72-4b64348d2a08}</Project>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\MUtilsTest.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{B7BCA0A5-17AD-4F20-A42C-CD6FFBD55D89}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>MUtilitiesTest_VS2017</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
<ProjectName>MUtilitiesTest</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141_xp</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141_xp</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release_Static|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141_xp</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\MUtilities.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\MUtilities.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release_Static|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\MUtilities.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)\bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)\obj\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)\bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)\obj\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release_Static|Win32'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)\bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)\obj\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;QT_GUI_LIB;QT_CORE_LIB;QT_THREAD_SUPPORT;QT_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(SolutionDir)\include;$(QTDIR)\include;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(SolutionDir)\..\Prerequisites\GoogleTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<EnableEnhancedInstructionSet>NoExtensions</EnableEnhancedInstructionSet>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(SolutionDir)\..\Prerequisites\Qt4\$(PlatformToolset)\Debug\lib;$(SolutionDir)\..\Prerequisites\GoogleTest\lib\$(PlatformToolset)\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>notelemetry.obj;gtestd.lib;QtCored4.lib;QtGuid4.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ShowProgress>LinkVerboseLib</ShowProgress>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>Full</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;QT_GUI_LIB;QT_CORE_LIB;QT_THREAD_SUPPORT;QT_NO_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(SolutionDir)\include;$(QTDIR)\include;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(SolutionDir)\..\Prerequisites\GoogleTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<EnableEnhancedInstructionSet>NoExtensions</EnableEnhancedInstructionSet>
<BufferSecurityCheck>false</BufferSecurityCheck>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<OmitFramePointers>true</OmitFramePointers>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(SolutionDir)\..\Prerequisites\Qt4\$(PlatformToolset)\Shared\lib;$(SolutionDir)\..\Prerequisites\GoogleTest\lib\$(PlatformToolset)\Shared;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>notelemetry.obj;gtest.lib;QtCore4.lib;QtGui4.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ShowProgress>LinkVerboseLib</ShowProgress>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release_Static|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>Full</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;MUTILS_STATIC_LIB;QT_GUI_LIB;QT_CORE_LIB;QT_THREAD_SUPPORT;QT_NODLL;QT_NO_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(SolutionDir)\include;$(QTDIR)\include;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(SolutionDir)\..\Prerequisites\GoogleTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<EnableEnhancedInstructionSet>NoExtensions</EnableEnhancedInstructionSet>
<BufferSecurityCheck>false</BufferSecurityCheck>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<OmitFramePointers>true</OmitFramePointers>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(SolutionDir)\..\Prerequisites\Qt4\$(PlatformToolset)\Static\lib;$(SolutionDir)\..\Prerequisites\GoogleTest\lib\$(PlatformToolset)\Static;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>notelemetry.obj;gtest.lib;QtCore.lib;QtGui.lib;Ws2_32.lib;Winmm.lib;Imm32.lib;PowrProf.lib;Version.lib;Psapi.lib;Sensapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ShowProgress>LinkVerboseLib</ShowProgress>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\GlobalTest.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\HashTest.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\OSTest.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\MUtilsTest.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

113
test/src/OSTest.cpp Normal file
View File

@ -0,0 +1,113 @@
///////////////////////////////////////////////////////////////////////////////
// MuldeR's Utilities for Qt
// Copyright (C) 2004-2019 LoRd_MuldeR <MuldeR2@GMX.de>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// http://www.gnu.org/licenses/lgpl-2.1.txt
//////////////////////////////////////////////////////////////////////////////////
#include "MUtilsTest.h"
//MUtils
#include <MUtils/OSSupport.h>
//Qt
#include <QSet>
#include <QVector>
//Win32
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN 1
#include <Windows.h>
#endif
//===========================================================================
// TESTBED CLASS
//===========================================================================
class OSTest : public Testbed
{
protected:
virtual void SetUp()
{
}
virtual void TearDown()
{
}
};
//===========================================================================
// TEST METHODS
//===========================================================================
static QString expandEnvVars(const wchar_t *text)
{
#ifdef _WINDOWS_
const DWORD size = ExpandEnvironmentStringsW(text, NULL, 0);
QVector<wchar_t> buffer(size + 1);
const DWORD result = ExpandEnvironmentStringsW(text, buffer.data(), buffer.size());
if ((result > 0U) || (result <= size))
{
return MUTILS_QSTR(buffer.data());
}
return QString();
#else
#error "Function expandEnvVars() not implemented!"
#endif
}
//-----------------------------------------------------------------
// KnownFolder
//-----------------------------------------------------------------
#define TEST_KNOWN_FOLDER(X,Y) do \
{ \
const QString path = MUtils::OS::known_folder((MUtils::OS::##X)); \
/*_putws(MUTILS_WCHR(path));*/ \
ASSERT_FALSE(path.isEmpty()); \
const QString expected = QDir::fromNativeSeparators(expandEnvVars((Y))); \
ASSERT_STRCASEEQ(MUTILS_UTF8(path), MUTILS_UTF8(expected)); \
} \
while(0)
TEST_F(OSTest, KnownFolder01) { TEST_KNOWN_FOLDER(FOLDER_PROFILE_USER, L"%USERPROFILE%"); }
TEST_F(OSTest, KnownFolder02) { TEST_KNOWN_FOLDER(FOLDER_PROFILE_PUBL, L"%PUBLIC%"); }
TEST_F(OSTest, KnownFolder03) { TEST_KNOWN_FOLDER(FOLDER_APPDATA_ROAM, L"%APPDATA%"); }
TEST_F(OSTest, KnownFolder04) { TEST_KNOWN_FOLDER(FOLDER_APPDATA_LOCA, L"%LOCALAPPDATA%"); }
TEST_F(OSTest, KnownFolder05) { TEST_KNOWN_FOLDER(FOLDER_DOCS_USER, L"%USERPROFILE%/Documents"); }
TEST_F(OSTest, KnownFolder06) { TEST_KNOWN_FOLDER(FOLDER_DOCS_PUBL, L"%PUBLIC%/Documents"); }
TEST_F(OSTest, KnownFolder07) { TEST_KNOWN_FOLDER(FOLDER_DESKTOP_USER, L"%USERPROFILE%/Desktop"); }
TEST_F(OSTest, KnownFolder08) { TEST_KNOWN_FOLDER(FOLDER_DESKTOP_PUBL, L"%PUBLIC%/Desktop"); }
TEST_F(OSTest, KnownFolder09) { TEST_KNOWN_FOLDER(FOLDER_PICTURES_USER, L"%USERPROFILE%/Pictures"); }
TEST_F(OSTest, KnownFolder10) { TEST_KNOWN_FOLDER(FOLDER_PICTURES_PUBL, L"%PUBLIC%/Pictures"); }
TEST_F(OSTest, KnownFolder11) { TEST_KNOWN_FOLDER(FOLDER_MUSIC_USER, L"%USERPROFILE%/Music"); }
TEST_F(OSTest, KnownFolder12) { TEST_KNOWN_FOLDER(FOLDER_MUSIC_PUBL, L"%PUBLIC%/Music"); }
TEST_F(OSTest, KnownFolder13) { TEST_KNOWN_FOLDER(FOLDER_VIDEO_USER, L"%USERPROFILE%/Videos"); }
TEST_F(OSTest, KnownFolder14) { TEST_KNOWN_FOLDER(FOLDER_VIDEO_PUBL, L"%PUBLIC%/Videos"); }
#ifdef _WIN64
TEST_F(OSTest, KnownFolder15) { TEST_KNOWN_FOLDER(FOLDER_PROGRAMS_DEF, L"%ProgramFiles%"); }
TEST_F(OSTest, KnownFolder17) { TEST_KNOWN_FOLDER(FOLDER_PROGRAMS_X64, L"%ProgramW6432%"); }
#else
TEST_F(OSTest, KnownFolder15) { TEST_KNOWN_FOLDER(FOLDER_PROGRAMS_DEF, L"%ProgramFiles(x86)%"); }
#endif
TEST_F(OSTest, KnownFolder16) { TEST_KNOWN_FOLDER(FOLDER_PROGRAMS_X86, L"%ProgramFiles(x86)%"); }
TEST_F(OSTest, KnownFolder18) { TEST_KNOWN_FOLDER(FOLDER_SYSROOT, L"%SystemRoot%"); }
TEST_F(OSTest, KnownFolder19) { TEST_KNOWN_FOLDER(FOLDER_SYSTEM_DEF, L"%SystemRoot%/System32"); }
TEST_F(OSTest, KnownFolder20) { TEST_KNOWN_FOLDER(FOLDER_SYSTEM_X86, L"%SystemRoot%/SysWOW64"); }
#undef TEST_KNOWN_FOLDER