Skip to content

Commit 22d3df3

Browse files
committed
adding simple unit tests
1 parent 653181d commit 22d3df3

File tree

4 files changed

+354
-0
lines changed

4 files changed

+354
-0
lines changed

UnitTests/UnitTests.cpp

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
#include "../NppExec/src/NppExecHelpers.h"
2+
#include <cassert>
3+
4+
namespace
5+
{
6+
void test_GetFileNamePart()
7+
{
8+
using namespace NppExecHelpers;
9+
10+
const tstr empty = tstr();
11+
12+
tstr path = _T("C");
13+
assert( GetFileNamePart(path, fnpDrive) == empty );
14+
assert( GetFileNamePart(path, fnpDirPath) == empty );
15+
assert( GetFileNamePart(path, fnpNameExt) == _T("C") );
16+
assert( GetFileNamePart(path, fnpName) == _T("C") );
17+
assert( GetFileNamePart(path, fnpExt) == empty );
18+
19+
path = _T("C:");
20+
assert( GetFileNamePart(path, fnpDrive) == _T("C") );
21+
assert( GetFileNamePart(path, fnpDirPath) == _T("C:") );
22+
assert( GetFileNamePart(path, fnpNameExt) == empty );
23+
assert( GetFileNamePart(path, fnpName) == empty );
24+
assert( GetFileNamePart(path, fnpExt) == empty );
25+
26+
path = _T("C:\\");
27+
assert( GetFileNamePart(path, fnpDrive) == _T("C") );
28+
assert( GetFileNamePart(path, fnpDirPath) == _T("C:\\") );
29+
assert( GetFileNamePart(path, fnpNameExt) == empty );
30+
assert( GetFileNamePart(path, fnpName) == empty );
31+
assert( GetFileNamePart(path, fnpExt) == empty );
32+
33+
path = _T("C:/");
34+
assert( GetFileNamePart(path, fnpDrive) == _T("C") );
35+
assert( GetFileNamePart(path, fnpDirPath) == _T("C:/") );
36+
assert( GetFileNamePart(path, fnpNameExt) == empty );
37+
assert( GetFileNamePart(path, fnpName) == empty );
38+
assert( GetFileNamePart(path, fnpExt) == empty );
39+
40+
path = _T(".C:");
41+
assert( GetFileNamePart(path, fnpDrive) == empty );
42+
assert( GetFileNamePart(path, fnpDirPath) == empty );
43+
assert( GetFileNamePart(path, fnpNameExt) == _T(".C:") );
44+
assert( GetFileNamePart(path, fnpName) == _T(".C:") );
45+
assert( GetFileNamePart(path, fnpExt) == _T(".C:") );
46+
47+
path = _T("\\\\");
48+
assert( GetFileNamePart(path, fnpDrive) == empty );
49+
assert( GetFileNamePart(path, fnpDirPath) == _T("\\\\") );
50+
assert( GetFileNamePart(path, fnpNameExt) == empty );
51+
assert( GetFileNamePart(path, fnpName) == empty );
52+
assert( GetFileNamePart(path, fnpExt) == empty );
53+
54+
path = _T("\\\\f.n");
55+
assert( GetFileNamePart(path, fnpDrive) == empty );
56+
assert( GetFileNamePart(path, fnpDirPath) == _T("\\\\") );
57+
assert( GetFileNamePart(path, fnpNameExt) == _T("f.n") );
58+
assert( GetFileNamePart(path, fnpName) == _T("f") );
59+
assert( GetFileNamePart(path, fnpExt) == _T(".n") );
60+
61+
path = _T("C:\\.n");
62+
assert( GetFileNamePart(path, fnpDrive) == _T("C") );
63+
assert( GetFileNamePart(path, fnpDirPath) == _T("C:\\") );
64+
assert( GetFileNamePart(path, fnpNameExt) == _T(".n") );
65+
assert( GetFileNamePart(path, fnpName) == _T(".n") );
66+
assert( GetFileNamePart(path, fnpExt) == _T(".n") );
67+
68+
path = _T("C:\\d\\f.n");
69+
assert( GetFileNamePart(path, fnpDrive) == _T("C") );
70+
assert( GetFileNamePart(path, fnpDirPath) == _T("C:\\d\\") );
71+
assert( GetFileNamePart(path, fnpNameExt) == _T("f.n") );
72+
assert( GetFileNamePart(path, fnpName) == _T("f") );
73+
assert( GetFileNamePart(path, fnpExt) == _T(".n") );
74+
75+
path = _T("C:\\d.e\\f");
76+
assert( GetFileNamePart(path, fnpDrive) == _T("C") );
77+
assert( GetFileNamePart(path, fnpDirPath) == _T("C:\\d.e\\") );
78+
assert( GetFileNamePart(path, fnpNameExt) == _T("f") );
79+
assert( GetFileNamePart(path, fnpName) == _T("f") );
80+
assert( GetFileNamePart(path, fnpExt) == empty );
81+
82+
path = _T("C:\\d.e\\.n");
83+
assert( GetFileNamePart(path, fnpDrive) == _T("C") );
84+
assert( GetFileNamePart(path, fnpDirPath) == _T("C:\\d.e\\") );
85+
assert( GetFileNamePart(path, fnpNameExt) == _T(".n") );
86+
assert( GetFileNamePart(path, fnpName) == _T(".n") );
87+
assert( GetFileNamePart(path, fnpExt) == _T(".n") );
88+
89+
path = _T("f.n");
90+
assert( GetFileNamePart(path, fnpDrive) == empty );
91+
assert( GetFileNamePart(path, fnpDirPath) == empty );
92+
assert( GetFileNamePart(path, fnpNameExt) == _T("f.n") );
93+
assert( GetFileNamePart(path, fnpName) == _T("f") );
94+
assert( GetFileNamePart(path, fnpExt) == _T(".n") );
95+
}
96+
97+
void test_IsFullLocalPath()
98+
{
99+
using namespace NppExecHelpers;
100+
101+
assert( IsFullLocalPath(_T("")) == false );
102+
assert( IsFullLocalPath(_T("\\")) == false );
103+
assert( IsFullLocalPath(_T("/")) == false );
104+
assert( IsFullLocalPath(_T("\\.")) == false );
105+
assert( IsFullLocalPath(_T("/.")) == false );
106+
assert( IsFullLocalPath(_T("\\\\")) == false );
107+
assert( IsFullLocalPath(_T("//")) == false );
108+
assert( IsFullLocalPath(_T("\\\\X")) == false );
109+
assert( IsFullLocalPath(_T("//X")) == false );
110+
assert( IsFullLocalPath(_T("\\\\X:")) == false );
111+
assert( IsFullLocalPath(_T("//X:")) == false );
112+
assert( IsFullLocalPath(_T("\\\\\\")) == false );
113+
assert( IsFullLocalPath(_T("///")) == false );
114+
assert( IsFullLocalPath(_T("\\\\.")) == false );
115+
assert( IsFullLocalPath(_T("//.")) == false );
116+
assert( IsFullLocalPath(_T("\\\\.\\")) == false );
117+
assert( IsFullLocalPath(_T("//./")) == false );
118+
assert( IsFullLocalPath(_T("\\\\.\\X")) == false );
119+
assert( IsFullLocalPath(_T("//./X")) == false );
120+
assert( IsFullLocalPath(_T("\\\\.\\X:")) == true );
121+
assert( IsFullLocalPath(_T("//./X:")) == true );
122+
assert( IsFullLocalPath(_T("\\\\.\\X:\\")) == true );
123+
assert( IsFullLocalPath(_T("//./X:/")) == true );
124+
assert( IsFullLocalPath(_T("\\\\.\\X:/")) == true );
125+
assert( IsFullLocalPath(_T("//./X:\\")) == true );
126+
assert( IsFullLocalPath(_T("\\\\.\\X:\\abc")) == true );
127+
assert( IsFullLocalPath(_T("//./X:/abc")) == true );
128+
assert( IsFullLocalPath(_T("\\\\.\\X:/abc")) == true );
129+
assert( IsFullLocalPath(_T("//./X:\\abc")) == true );
130+
assert( IsFullLocalPath(_T("\\:")) == false );
131+
assert( IsFullLocalPath(_T("/:")) == false );
132+
assert( IsFullLocalPath(_T("\\:\\")) == false );
133+
assert( IsFullLocalPath(_T("/:/")) == false );
134+
assert( IsFullLocalPath(_T("X:")) == true );
135+
assert( IsFullLocalPath(_T("X:\\")) == true );
136+
assert( IsFullLocalPath(_T("X:/")) == true );
137+
assert( IsFullLocalPath(_T("X:\\abc")) == true );
138+
assert( IsFullLocalPath(_T("X:/abc")) == true );
139+
assert( IsFullLocalPath(_T("abc")) == false );
140+
assert( IsFullLocalPath(_T("a:bc")) == false );
141+
assert( IsFullLocalPath(_T("\abc")) == false );
142+
assert( IsFullLocalPath(_T("/abc")) == false );
143+
assert( IsFullLocalPath(_T("\\abc")) == false );
144+
assert( IsFullLocalPath(_T("//abc")) == false );
145+
}
146+
147+
void tests()
148+
{
149+
test_GetFileNamePart();
150+
test_IsFullLocalPath();
151+
}
152+
}
153+
154+
int main()
155+
{
156+
tests();
157+
return 0;
158+
}

UnitTests/UnitTests.sln

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.27703.2018
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UnitTests", "UnitTests.vcxproj", "{E8C1986D-FC02-4FDB-844D-B758EA4A97E8}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Debug|x86 = Debug|x86
12+
Release|x64 = Release|x64
13+
Release|x86 = Release|x86
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{E8C1986D-FC02-4FDB-844D-B758EA4A97E8}.Debug|x64.ActiveCfg = Debug|x64
17+
{E8C1986D-FC02-4FDB-844D-B758EA4A97E8}.Debug|x64.Build.0 = Debug|x64
18+
{E8C1986D-FC02-4FDB-844D-B758EA4A97E8}.Debug|x86.ActiveCfg = Debug|Win32
19+
{E8C1986D-FC02-4FDB-844D-B758EA4A97E8}.Debug|x86.Build.0 = Debug|Win32
20+
{E8C1986D-FC02-4FDB-844D-B758EA4A97E8}.Release|x64.ActiveCfg = Release|x64
21+
{E8C1986D-FC02-4FDB-844D-B758EA4A97E8}.Release|x64.Build.0 = Release|x64
22+
{E8C1986D-FC02-4FDB-844D-B758EA4A97E8}.Release|x86.ActiveCfg = Release|Win32
23+
{E8C1986D-FC02-4FDB-844D-B758EA4A97E8}.Release|x86.Build.0 = Release|Win32
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {6AA4DEBC-8225-4007-B3D0-55AFB58573ED}
30+
EndGlobalSection
31+
EndGlobal

UnitTests/UnitTests.vcxproj

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<VCProjectVersion>15.0</VCProjectVersion>
23+
<ProjectGuid>{E8C1986D-FC02-4FDB-844D-B758EA4A97E8}</ProjectGuid>
24+
<RootNamespace>UnitTests</RootNamespace>
25+
<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
26+
</PropertyGroup>
27+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
28+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
29+
<ConfigurationType>Application</ConfigurationType>
30+
<UseDebugLibraries>true</UseDebugLibraries>
31+
<PlatformToolset>v141</PlatformToolset>
32+
<CharacterSet>Unicode</CharacterSet>
33+
</PropertyGroup>
34+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
35+
<ConfigurationType>Application</ConfigurationType>
36+
<UseDebugLibraries>false</UseDebugLibraries>
37+
<PlatformToolset>v141</PlatformToolset>
38+
<WholeProgramOptimization>true</WholeProgramOptimization>
39+
<CharacterSet>Unicode</CharacterSet>
40+
</PropertyGroup>
41+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
42+
<ConfigurationType>Application</ConfigurationType>
43+
<UseDebugLibraries>true</UseDebugLibraries>
44+
<PlatformToolset>v141</PlatformToolset>
45+
<CharacterSet>Unicode</CharacterSet>
46+
</PropertyGroup>
47+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
48+
<ConfigurationType>Application</ConfigurationType>
49+
<UseDebugLibraries>false</UseDebugLibraries>
50+
<PlatformToolset>v141</PlatformToolset>
51+
<WholeProgramOptimization>true</WholeProgramOptimization>
52+
<CharacterSet>Unicode</CharacterSet>
53+
</PropertyGroup>
54+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
55+
<ImportGroup Label="ExtensionSettings">
56+
</ImportGroup>
57+
<ImportGroup Label="Shared">
58+
</ImportGroup>
59+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
60+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
61+
</ImportGroup>
62+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
63+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
64+
</ImportGroup>
65+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
66+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
67+
</ImportGroup>
68+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
69+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
70+
</ImportGroup>
71+
<PropertyGroup Label="UserMacros" />
72+
<PropertyGroup />
73+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
74+
<ClCompile>
75+
<WarningLevel>Level3</WarningLevel>
76+
<Optimization>Disabled</Optimization>
77+
<SDLCheck>true</SDLCheck>
78+
<ConformanceMode>true</ConformanceMode>
79+
</ClCompile>
80+
<Link>
81+
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
82+
</Link>
83+
</ItemDefinitionGroup>
84+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
85+
<ClCompile>
86+
<WarningLevel>Level3</WarningLevel>
87+
<Optimization>Disabled</Optimization>
88+
<SDLCheck>true</SDLCheck>
89+
<ConformanceMode>true</ConformanceMode>
90+
</ClCompile>
91+
<Link>
92+
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
93+
</Link>
94+
</ItemDefinitionGroup>
95+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
96+
<ClCompile>
97+
<WarningLevel>Level3</WarningLevel>
98+
<Optimization>MaxSpeed</Optimization>
99+
<FunctionLevelLinking>true</FunctionLevelLinking>
100+
<IntrinsicFunctions>true</IntrinsicFunctions>
101+
<SDLCheck>true</SDLCheck>
102+
<ConformanceMode>true</ConformanceMode>
103+
</ClCompile>
104+
<Link>
105+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
106+
<OptimizeReferences>true</OptimizeReferences>
107+
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
108+
</Link>
109+
</ItemDefinitionGroup>
110+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
111+
<ClCompile>
112+
<WarningLevel>Level3</WarningLevel>
113+
<Optimization>MaxSpeed</Optimization>
114+
<FunctionLevelLinking>true</FunctionLevelLinking>
115+
<IntrinsicFunctions>true</IntrinsicFunctions>
116+
<SDLCheck>true</SDLCheck>
117+
<ConformanceMode>true</ConformanceMode>
118+
</ClCompile>
119+
<Link>
120+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
121+
<OptimizeReferences>true</OptimizeReferences>
122+
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
123+
</Link>
124+
</ItemDefinitionGroup>
125+
<ItemGroup>
126+
<ClCompile Include="..\NppExec\src\c_base\str_func.c" />
127+
<ClCompile Include="..\NppExec\src\encodings\SysUniConv.cpp" />
128+
<ClCompile Include="..\NppExec\src\NppExecHelpers.cpp" />
129+
<ClCompile Include="UnitTests.cpp" />
130+
</ItemGroup>
131+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
132+
<ImportGroup Label="ExtensionTargets">
133+
</ImportGroup>
134+
</Project>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Source Files">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="Header Files">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="Resource Files">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ClCompile Include="UnitTests.cpp">
19+
<Filter>Source Files</Filter>
20+
</ClCompile>
21+
<ClCompile Include="..\NppExec\src\NppExecHelpers.cpp">
22+
<Filter>Source Files</Filter>
23+
</ClCompile>
24+
<ClCompile Include="..\NppExec\src\encodings\SysUniConv.cpp">
25+
<Filter>Source Files</Filter>
26+
</ClCompile>
27+
<ClCompile Include="..\NppExec\src\c_base\str_func.c">
28+
<Filter>Source Files</Filter>
29+
</ClCompile>
30+
</ItemGroup>
31+
</Project>

0 commit comments

Comments
 (0)