go my file uploader
This commit is contained in:
16
tests/phlib-test/main.c
Normal file
16
tests/phlib-test/main.c
Normal file
@@ -0,0 +1,16 @@
|
||||
#include "tests.h"
|
||||
|
||||
int __cdecl wmain(int argc, wchar_t *argv[])
|
||||
{
|
||||
NTSTATUS status;
|
||||
|
||||
status = PhInitializePhLib();
|
||||
assert(NT_SUCCESS(status));
|
||||
|
||||
Test_basesup();
|
||||
Test_avltree();
|
||||
Test_format();
|
||||
Test_util();
|
||||
|
||||
return 0;
|
||||
}
|
||||
116
tests/phlib-test/phlib-test.vcxproj
Normal file
116
tests/phlib-test/phlib-test.vcxproj
Normal file
@@ -0,0 +1,116 @@
|
||||
<?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|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{0C21014E-BC90-4AE5-AA32-398445C13B28}</ProjectGuid>
|
||||
<RootNamespace>phlib-test</RootNamespace>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<WindowsTargetPlatformVersion>10.0.10586.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup>
|
||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(ProjectDir)bin\$(Configuration)\</OutDir>
|
||||
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(ProjectDir)obj\$(Configuration)\</IntDir>
|
||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
|
||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(ProjectDir)bin\$(Configuration)\</OutDir>
|
||||
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(ProjectDir)obj\$(Configuration)\</IntDir>
|
||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>..\..\phnt\include;..\..\phlib\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_PHLIB_;_CONSOLE;WIN32;DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
<CallingConvention>StdCall</CallingConvention>
|
||||
<TreatWarningAsError>true</TreatWarningAsError>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>phlib.lib;ntdll.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>..\..\phlib\bin\$(Configuration)$(PlatformArchitecture);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<TargetMachine>MachineX86</TargetMachine>
|
||||
<MinimumRequiredVersion>5.01</MinimumRequiredVersion>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<AdditionalIncludeDirectories>..\..\phnt\include;..\..\phlib\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_PHLIB_;_CONSOLE;WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
<CallingConvention>StdCall</CallingConvention>
|
||||
<TreatWarningAsError>true</TreatWarningAsError>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>phlib.lib;ntdll.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>..\..\phlib\bin\$(Configuration)$(PlatformArchitecture);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<TargetMachine>MachineX86</TargetMachine>
|
||||
<SetChecksum>true</SetChecksum>
|
||||
<MinimumRequiredVersion>5.01</MinimumRequiredVersion>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.c" />
|
||||
<ClCompile Include="t_avltree.c" />
|
||||
<ClCompile Include="t_basesup.c" />
|
||||
<ClCompile Include="t_format.c" />
|
||||
<ClCompile Include="t_util.c" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\phlib\phlib.vcxproj">
|
||||
<Project>{477d0215-f252-41a1-874b-f27e3ea1ed17}</Project>
|
||||
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="tests.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
35
tests/phlib-test/phlib-test.vcxproj.filters
Normal file
35
tests/phlib-test/phlib-test.vcxproj.filters
Normal file
@@ -0,0 +1,35 @@
|
||||
<?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;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="t_basesup.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="t_format.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="t_avltree.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="t_util.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="tests.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
100
tests/phlib-test/t_avltree.c
Normal file
100
tests/phlib-test/t_avltree.c
Normal file
@@ -0,0 +1,100 @@
|
||||
#include "tests.h"
|
||||
|
||||
typedef struct _NODE
|
||||
{
|
||||
PH_AVL_LINKS Links;
|
||||
ULONG Value;
|
||||
} NODE, *PNODE;
|
||||
|
||||
static LONG CompareFunction(
|
||||
_In_ PPH_AVL_LINKS Links1,
|
||||
_In_ PPH_AVL_LINKS Links2
|
||||
)
|
||||
{
|
||||
PNODE node1 = CONTAINING_RECORD(Links1, NODE, Links);
|
||||
PNODE node2 = CONTAINING_RECORD(Links2, NODE, Links);
|
||||
|
||||
return uintcmp(node1->Value, node2->Value);
|
||||
}
|
||||
|
||||
#define BOUND_FUNCTION(DefineName, FunctionName) \
|
||||
static ULONG DefineName( \
|
||||
_In_ PPH_AVL_TREE Tree, \
|
||||
_In_ ULONG Value \
|
||||
) \
|
||||
{ \
|
||||
NODE node; \
|
||||
PPH_AVL_LINKS result; \
|
||||
\
|
||||
node.Value = Value; \
|
||||
result = FunctionName(Tree, &node.Links); \
|
||||
\
|
||||
if (result) \
|
||||
return CONTAINING_RECORD(result, NODE, Links)->Value; \
|
||||
else \
|
||||
return -1; \
|
||||
}
|
||||
|
||||
BOUND_FUNCTION(lbound, PhLowerBoundElementAvlTree);
|
||||
BOUND_FUNCTION(ubound, PhUpperBoundElementAvlTree);
|
||||
BOUND_FUNCTION(ldbound, PhLowerDualBoundElementAvlTree);
|
||||
BOUND_FUNCTION(udbound, PhUpperDualBoundElementAvlTree);
|
||||
|
||||
VOID Test_avltree(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
PH_AVL_TREE tree;
|
||||
NODE nodes[4];
|
||||
|
||||
PhInitializeAvlTree(&tree, CompareFunction);
|
||||
|
||||
nodes[0].Value = 3;
|
||||
PhAddElementAvlTree(&tree, &nodes[0].Links);
|
||||
nodes[1].Value = 1;
|
||||
PhAddElementAvlTree(&tree, &nodes[1].Links);
|
||||
nodes[2].Value = 5;
|
||||
PhAddElementAvlTree(&tree, &nodes[2].Links);
|
||||
nodes[3].Value = 7;
|
||||
PhAddElementAvlTree(&tree, &nodes[3].Links);
|
||||
|
||||
assert(lbound(&tree, 0) == 1);
|
||||
assert(lbound(&tree, 1) == 1);
|
||||
assert(lbound(&tree, 2) == 3);
|
||||
assert(lbound(&tree, 3) == 3);
|
||||
assert(lbound(&tree, 4) == 5);
|
||||
assert(lbound(&tree, 5) == 5);
|
||||
assert(lbound(&tree, 6) == 7);
|
||||
assert(lbound(&tree, 7) == 7);
|
||||
assert(lbound(&tree, 8) == -1);
|
||||
|
||||
assert(ubound(&tree, 0) == 1);
|
||||
assert(ubound(&tree, 1) == 3);
|
||||
assert(ubound(&tree, 2) == 3);
|
||||
assert(ubound(&tree, 3) == 5);
|
||||
assert(ubound(&tree, 4) == 5);
|
||||
assert(ubound(&tree, 5) == 7);
|
||||
assert(ubound(&tree, 6) == 7);
|
||||
assert(ubound(&tree, 7) == -1);
|
||||
assert(ubound(&tree, 8) == -1);
|
||||
|
||||
assert(ldbound(&tree, 0) == -1);
|
||||
assert(ldbound(&tree, 1) == -1);
|
||||
assert(ldbound(&tree, 2) == 1);
|
||||
assert(ldbound(&tree, 3) == 1);
|
||||
assert(ldbound(&tree, 4) == 3);
|
||||
assert(ldbound(&tree, 5) == 3);
|
||||
assert(ldbound(&tree, 6) == 5);
|
||||
assert(ldbound(&tree, 7) == 5);
|
||||
assert(ldbound(&tree, 8) == 7);
|
||||
|
||||
assert(udbound(&tree, 0) == -1);
|
||||
assert(udbound(&tree, 1) == 1);
|
||||
assert(udbound(&tree, 2) == 1);
|
||||
assert(udbound(&tree, 3) == 3);
|
||||
assert(udbound(&tree, 4) == 3);
|
||||
assert(udbound(&tree, 5) == 5);
|
||||
assert(udbound(&tree, 6) == 5);
|
||||
assert(udbound(&tree, 7) == 7);
|
||||
assert(udbound(&tree, 8) == 7);
|
||||
}
|
||||
352
tests/phlib-test/t_basesup.c
Normal file
352
tests/phlib-test/t_basesup.c
Normal file
@@ -0,0 +1,352 @@
|
||||
#include "tests.h"
|
||||
|
||||
static VOID Test_time(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
LARGE_INTEGER time;
|
||||
FILETIME fileTime;
|
||||
LARGE_INTEGER localTime;
|
||||
FILETIME localFileTime;
|
||||
LARGE_INTEGER systemTime;
|
||||
FILETIME systemFileTime;
|
||||
|
||||
PhQuerySystemTime(&time);
|
||||
fileTime.dwLowDateTime = time.LowPart;
|
||||
fileTime.dwHighDateTime = time.HighPart;
|
||||
|
||||
PhSystemTimeToLocalTime(&time, &localTime);
|
||||
FileTimeToLocalFileTime(&fileTime, &localFileTime);
|
||||
|
||||
assert(localTime.LowPart == localFileTime.dwLowDateTime);
|
||||
assert(localTime.HighPart == localFileTime.dwHighDateTime);
|
||||
|
||||
PhLocalTimeToSystemTime(&localTime, &systemTime);
|
||||
LocalFileTimeToFileTime(&localFileTime, &systemFileTime);
|
||||
|
||||
assert(systemTime.LowPart == systemFileTime.dwLowDateTime);
|
||||
assert(systemTime.HighPart == systemFileTime.dwHighDateTime);
|
||||
}
|
||||
|
||||
static VOID Test_stringz(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
BOOLEAN result;
|
||||
CHAR inputA[16] = "test";
|
||||
CHAR outputA[16];
|
||||
WCHAR inputW[16] = L"test";
|
||||
WCHAR outputW[16];
|
||||
ULONG returnCount;
|
||||
PWSTR zero = L"\0\0\0\0\0\0\0\0";
|
||||
PWSTR asdf = L"asdfasdfasdfasdf";
|
||||
ULONG i;
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
assert(PhCountStringZ(zero + i) == 0);
|
||||
for (i = 0; i < 16; i++)
|
||||
assert(PhCountStringZ(asdf + i) == 16 - i);
|
||||
|
||||
result = PhCopyBytesZ(inputA, 4, outputA, 4, &returnCount);
|
||||
assert(!result && returnCount == 5);
|
||||
result = PhCopyBytesZ(inputA, 100, outputA, 4, &returnCount);
|
||||
assert(!result && returnCount == 5);
|
||||
result = PhCopyBytesZ(inputA, 3, outputA, 4, &returnCount);
|
||||
assert(result && returnCount == 4);
|
||||
result = PhCopyBytesZ(inputA, 4, outputA, 5, &returnCount);
|
||||
assert(result && returnCount == 5);
|
||||
result = PhCopyBytesZ(inputA, 100, outputA, 5, &returnCount);
|
||||
assert(result && returnCount == 5);
|
||||
|
||||
result = PhCopyStringZ(inputW, 100, outputW, 4, &returnCount);
|
||||
assert(!result && returnCount == 5);
|
||||
result = PhCopyStringZ(inputW, 4, outputW, 5, &returnCount);
|
||||
assert(result && returnCount == 5);
|
||||
result = PhCopyStringZ(inputW, 100, outputW, 5, &returnCount);
|
||||
assert(result && returnCount == 5);
|
||||
|
||||
result = PhCopyStringZFromMultiByte(inputA, 4, outputW, 4, &returnCount);
|
||||
assert(!result && returnCount == 5);
|
||||
result = PhCopyStringZFromMultiByte(inputA, 100, outputW, 4, &returnCount);
|
||||
assert(!result && returnCount == 5);
|
||||
result = PhCopyStringZFromMultiByte(inputA, 3, outputW, 4, &returnCount);
|
||||
assert(result && returnCount == 4);
|
||||
result = PhCopyStringZFromMultiByte(inputA, 4, outputW, 5, &returnCount);
|
||||
assert(result && returnCount == 5);
|
||||
result = PhCopyStringZFromMultiByte(inputA, 100, outputW, 5, &returnCount);
|
||||
assert(result && returnCount == 5);
|
||||
|
||||
assert(PhCompareStringZNatural(L"abc", L"abc", FALSE) == 0);
|
||||
assert(PhCompareStringZNatural(L"abc", L"abc", TRUE) == 0);
|
||||
assert(PhCompareStringZNatural(L"abc", L"ABC", FALSE) != 0);
|
||||
assert(PhCompareStringZNatural(L"abc", L"ABC", TRUE) == 0);
|
||||
assert(PhCompareStringZNatural(L"abc", L"abd", FALSE) < 0);
|
||||
assert(PhCompareStringZNatural(L"abe", L"abd", FALSE) > 0);
|
||||
assert(PhCompareStringZNatural(L"1", L"2", FALSE) < 0);
|
||||
assert(PhCompareStringZNatural(L"12", L"9", FALSE) > 0);
|
||||
assert(PhCompareStringZNatural(L"file-1", L"file-9", FALSE) < 0);
|
||||
assert(PhCompareStringZNatural(L"file-12", L"file-9", FALSE) > 0);
|
||||
assert(PhCompareStringZNatural(L"file-12", L"file-90", FALSE) < 0);
|
||||
}
|
||||
|
||||
VOID Test_stringref(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
ULONG i;
|
||||
ULONG j;
|
||||
PH_STRINGREF s1;
|
||||
PH_STRINGREF s2;
|
||||
PH_STRINGREF s3;
|
||||
WCHAR buffer[26 * 2];
|
||||
|
||||
// PhEqualStringRef, PhFindCharInStringRef, PhFindLastCharInStringRef
|
||||
|
||||
// Alignment tests
|
||||
|
||||
s1.Buffer = buffer;
|
||||
s1.Length = sizeof(buffer);
|
||||
|
||||
for (i = 0; i < 26; i++)
|
||||
s1.Buffer[i] = (WCHAR)i;
|
||||
|
||||
for (i = 0; i < 26; i++)
|
||||
assert(PhFindCharInStringRef(&s1, (WCHAR)i, FALSE) == i);
|
||||
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
s1.Length = 0;
|
||||
|
||||
for (i = 0; i < 26; i++)
|
||||
assert(PhFindCharInStringRef(&s1, 0, FALSE) == -1);
|
||||
|
||||
buffer[26] = 1;
|
||||
|
||||
for (i = 0; i < 26; i++)
|
||||
{
|
||||
s1.Buffer = buffer + 26 - i;
|
||||
s1.Length = i * sizeof(WCHAR);
|
||||
assert(PhFindCharInStringRef(&s1, 1, FALSE) == -1);
|
||||
}
|
||||
|
||||
for (i = 1; i < 26; i++)
|
||||
{
|
||||
s1.Buffer = buffer;
|
||||
s1.Length = i * 2 * sizeof(WCHAR);
|
||||
|
||||
for (j = 0; j < i; j++)
|
||||
{
|
||||
buffer[j] = (WCHAR)('a' + j);
|
||||
buffer[i + j] = (WCHAR)('A' + j);
|
||||
}
|
||||
|
||||
s2.Buffer = buffer;
|
||||
s2.Length = i * sizeof(WCHAR);
|
||||
s3.Buffer = buffer + i;
|
||||
s3.Length = i * sizeof(WCHAR);
|
||||
assert(!PhEqualStringRef(&s2, &s3, FALSE));
|
||||
assert(PhEqualStringRef(&s2, &s3, TRUE));
|
||||
|
||||
for (j = 0; j < i; j++)
|
||||
{
|
||||
buffer[j] = 'z';
|
||||
assert(!PhEqualStringRef(&s2, &s3, FALSE));
|
||||
assert(!PhEqualStringRef(&s2, &s3, TRUE));
|
||||
buffer[j] = (WCHAR)('a' + j);
|
||||
}
|
||||
|
||||
s3 = s2;
|
||||
assert(PhEqualStringRef(&s2, &s3, FALSE));
|
||||
assert(PhEqualStringRef(&s2, &s3, TRUE));
|
||||
|
||||
for (j = 0; j < i; j++)
|
||||
{
|
||||
assert(PhFindCharInStringRef(&s1, s1.Buffer[j], FALSE) == j);
|
||||
assert(PhFindLastCharInStringRef(&s1, s1.Buffer[j], FALSE) == j);
|
||||
assert(PhFindCharInStringRef(&s1, s1.Buffer[j], TRUE) == j % i);
|
||||
assert(PhFindLastCharInStringRef(&s1, s1.Buffer[j], TRUE) == i + j % i);
|
||||
}
|
||||
|
||||
s1.Length = i * sizeof(WCHAR);
|
||||
|
||||
for (j = 0; j < i; j++)
|
||||
{
|
||||
assert(PhFindCharInStringRef(&s1, s1.Buffer[j] - ('a' - 'A'), FALSE) == -1);
|
||||
assert(PhFindLastCharInStringRef(&s1, s1.Buffer[j] - ('a' - 'A'), FALSE) == -1);
|
||||
assert(PhFindCharInStringRef(&s1, s1.Buffer[j] - ('a' - 'A'), TRUE) == j);
|
||||
assert(PhFindLastCharInStringRef(&s1, s1.Buffer[j] - ('a' - 'A'), TRUE) == j);
|
||||
}
|
||||
|
||||
s1.Buffer += i;
|
||||
|
||||
for (j = 0; j < i; j++)
|
||||
{
|
||||
assert(PhFindCharInStringRef(&s1, s1.Buffer[j] + ('a' - 'A'), FALSE) == -1);
|
||||
assert(PhFindLastCharInStringRef(&s1, s1.Buffer[j] + ('a' - 'A'), FALSE) == -1);
|
||||
assert(PhFindCharInStringRef(&s1, s1.Buffer[j] + ('a' - 'A'), TRUE) == j);
|
||||
assert(PhFindLastCharInStringRef(&s1, s1.Buffer[j] + ('a' - 'A'), TRUE) == j);
|
||||
}
|
||||
}
|
||||
|
||||
// PhFindStringInStringRef
|
||||
|
||||
#define DO_STRSTR_TEST(func, s1, s2, expected, ...) \
|
||||
do { \
|
||||
PH_STRINGREF ___t1; \
|
||||
PH_STRINGREF ___t2; \
|
||||
PhInitializeStringRef(&___t1, s1); \
|
||||
PhInitializeStringRef(&___t2, s2); \
|
||||
assert(func(&___t1, &___t2, __VA_ARGS__) == expected); \
|
||||
} while (0)
|
||||
|
||||
DO_STRSTR_TEST(PhFindStringInStringRef, L"asdfasdf", L"f", 3, FALSE);
|
||||
DO_STRSTR_TEST(PhFindStringInStringRef, L"asdfasdf", L"g", -1, FALSE);
|
||||
DO_STRSTR_TEST(PhFindStringInStringRef, L"asdfasdg", L"g", 7, FALSE);
|
||||
DO_STRSTR_TEST(PhFindStringInStringRef, L"asdfasdg", L"asdg", 4, FALSE);
|
||||
DO_STRSTR_TEST(PhFindStringInStringRef, L"asdfasdg", L"asdgh", -1, FALSE);
|
||||
DO_STRSTR_TEST(PhFindStringInStringRef, L"asdfasdg", L"asdfasdg", 0, FALSE);
|
||||
DO_STRSTR_TEST(PhFindStringInStringRef, L"asdfasdg", L"sdfasdg", 1, FALSE);
|
||||
DO_STRSTR_TEST(PhFindStringInStringRef, L"asdfasdg", L"asdfasdgg", -1, FALSE);
|
||||
DO_STRSTR_TEST(PhFindStringInStringRef, L"asdfasdg", L"asdfasdgggggg", -1, FALSE);
|
||||
DO_STRSTR_TEST(PhFindStringInStringRef, L"", L"asdfasdgggggg", -1, FALSE);
|
||||
DO_STRSTR_TEST(PhFindStringInStringRef, L"asdfasdg", L"", 0, FALSE);
|
||||
DO_STRSTR_TEST(PhFindStringInStringRef, L"", L"", 0, FALSE);
|
||||
// Test roll-over
|
||||
DO_STRSTR_TEST(PhFindStringInStringRef, L"0sdfasdf1sdfasdf2sdfasdf3sdfasdg4sdfg", L"0sdfasdf1sdfasdf2sdfasdf3sdfasdg4sdfg", 0, FALSE);
|
||||
DO_STRSTR_TEST(PhFindStringInStringRef, L"0sdfasdf1sdfasdf2sdfasdf3sdfasdg4sdfg", L"asdg4sdfg", 28, FALSE);
|
||||
DO_STRSTR_TEST(PhFindStringInStringRef, L"0sdfasdf1sdfasdf2sdfasdf3sdfasdg4sdfg", L"asdg4Gdfg", -1, FALSE);
|
||||
}
|
||||
|
||||
VOID Test_hexstring(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
BOOLEAN result;
|
||||
PH_STRINGREF sr;
|
||||
PPH_STRING string;
|
||||
UCHAR buffer[16];
|
||||
|
||||
PhInitializeStringRef(&sr, L"0011223344");
|
||||
result = PhHexStringToBuffer(&sr, buffer);
|
||||
assert(result && buffer[0] == 0 && buffer[1] == 0x11 && buffer[2] == 0x22 && buffer[3] == 0x33 && buffer[4] == 0x44);
|
||||
|
||||
PhInitializeStringRef(&sr, L"00111");
|
||||
result = PhHexStringToBuffer(&sr, buffer);
|
||||
assert(!result);
|
||||
|
||||
buffer[0] = 0;
|
||||
buffer[1] = 0x99;
|
||||
buffer[2] = 0xff;
|
||||
|
||||
string = PhBufferToHexString(buffer, 3);
|
||||
assert(wcscmp(string->Buffer, L"0099ff") == 0);
|
||||
}
|
||||
|
||||
VOID Test_strint(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
PH_STRINGREF sr;
|
||||
LONG64 integer;
|
||||
PPH_STRING string;
|
||||
|
||||
PhInitializeStringRef(&sr, L"123");
|
||||
PhStringToInteger64(&sr, 0, &integer);
|
||||
assert(integer == 123);
|
||||
PhStringToInteger64(&sr, 10, &integer);
|
||||
assert(integer == 123);
|
||||
PhStringToInteger64(&sr, 8, &integer);
|
||||
assert(integer == 0123);
|
||||
PhStringToInteger64(&sr, 16, &integer);
|
||||
assert(integer == 0x123);
|
||||
|
||||
PhInitializeStringRef(&sr, L"0o123");
|
||||
PhStringToInteger64(&sr, 0, &integer);
|
||||
assert(integer == 0123);
|
||||
PhInitializeStringRef(&sr, L"0x123");
|
||||
PhStringToInteger64(&sr, 0, &integer);
|
||||
assert(integer == 0x123);
|
||||
|
||||
string = PhIntegerToString64(123, 0, FALSE);
|
||||
assert(wcscmp(string->Buffer, L"123") == 0);
|
||||
string = PhIntegerToString64(123, 10, FALSE);
|
||||
assert(wcscmp(string->Buffer, L"123") == 0);
|
||||
string = PhIntegerToString64(123, 8, FALSE);
|
||||
assert(wcscmp(string->Buffer, L"173") == 0);
|
||||
string = PhIntegerToString64(123, 16, FALSE);
|
||||
assert(wcscmp(string->Buffer, L"7b") == 0);
|
||||
|
||||
string = PhIntegerToString64(-123, 0, TRUE);
|
||||
assert(wcscmp(string->Buffer, L"-123") == 0);
|
||||
string = PhIntegerToString64(-123, 10, TRUE);
|
||||
assert(wcscmp(string->Buffer, L"-123") == 0);
|
||||
string = PhIntegerToString64(-123, 8, TRUE);
|
||||
assert(wcscmp(string->Buffer, L"-173") == 0);
|
||||
string = PhIntegerToString64(-123, 16, TRUE);
|
||||
assert(wcscmp(string->Buffer, L"-7b") == 0);
|
||||
|
||||
string = PhIntegerToString64(-123, 0, FALSE);
|
||||
assert(wcscmp(string->Buffer, L"18446744073709551493") == 0);
|
||||
}
|
||||
|
||||
VOID Test_unicode(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
BOOLEAN result;
|
||||
ULONG codePoints[6];
|
||||
SIZE_T i;
|
||||
WCHAR utf16[sizeof(codePoints) / sizeof(WCHAR)];
|
||||
CHAR utf8[sizeof(codePoints) / sizeof(CHAR)];
|
||||
ULONG numberOfCodePoints;
|
||||
SIZE_T utf16Position = 0;
|
||||
SIZE_T utf8Position = 0;
|
||||
PPH_STRING utf16_1, utf16_2, utf16_3;
|
||||
PPH_BYTES utf8_1, utf8_2, utf8_3;
|
||||
|
||||
codePoints[0] = 0;
|
||||
codePoints[1] = 0x50;
|
||||
codePoints[2] = 0x312;
|
||||
codePoints[3] = 0x3121;
|
||||
codePoints[4] = 0x31212;
|
||||
codePoints[5] = PH_UNICODE_MAX_CODE_POINT;
|
||||
|
||||
for (i = 0; i < sizeof(codePoints) / sizeof(ULONG); i++)
|
||||
{
|
||||
result = PhEncodeUnicode(PH_UNICODE_UTF16, codePoints[i], utf16 + utf16Position, &numberOfCodePoints);
|
||||
assert(result);
|
||||
utf16Position += numberOfCodePoints;
|
||||
|
||||
result = PhEncodeUnicode(PH_UNICODE_UTF8, codePoints[i], utf8 + utf8Position, &numberOfCodePoints);
|
||||
assert(result);
|
||||
utf8Position += numberOfCodePoints;
|
||||
}
|
||||
|
||||
utf16_1 = PhCreateStringEx(utf16, utf16Position * sizeof(WCHAR));
|
||||
utf8_1 = PhCreateBytesEx(utf8, utf8Position);
|
||||
utf16_2 = PhConvertUtf8ToUtf16Ex(utf8_1->Buffer, utf8_1->Length);
|
||||
utf8_2 = PhConvertUtf16ToUtf8Ex(utf16_1->Buffer, utf16_1->Length);
|
||||
utf16_3 = PhConvertUtf8ToUtf16Ex(utf8_2->Buffer, utf8_2->Length);
|
||||
utf8_3 = PhConvertUtf16ToUtf8Ex(utf16_2->Buffer, utf16_2->Length);
|
||||
|
||||
assert(utf16_1->Length == utf16_2->Length);
|
||||
assert(memcmp(utf16_1->Buffer, utf16_2->Buffer, utf16_1->Length) == 0);
|
||||
assert(utf16_2->Length == utf16_3->Length);
|
||||
assert(memcmp(utf16_2->Buffer, utf16_3->Buffer, utf16_2->Length) == 0);
|
||||
|
||||
assert(utf8_1->Length == utf8_2->Length);
|
||||
assert(memcmp(utf8_1->Buffer, utf8_2->Buffer, utf8_1->Length) == 0);
|
||||
assert(utf8_2->Length == utf8_3->Length);
|
||||
assert(memcmp(utf8_2->Buffer, utf8_3->Buffer, utf8_2->Length) == 0);
|
||||
}
|
||||
|
||||
VOID Test_basesup(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
Test_time();
|
||||
Test_stringz();
|
||||
Test_stringref();
|
||||
Test_hexstring();
|
||||
Test_strint();
|
||||
Test_unicode();
|
||||
}
|
||||
511
tests/phlib-test/t_format.c
Normal file
511
tests/phlib-test/t_format.c
Normal file
@@ -0,0 +1,511 @@
|
||||
#include "tests.h"
|
||||
|
||||
static VOID Test_buffer(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
#define OUTPUT_COUNT 10
|
||||
|
||||
BOOLEAN result;
|
||||
PH_FORMAT format[1];
|
||||
WCHAR buffer[16];
|
||||
SIZE_T returnLength;
|
||||
|
||||
format[0].Type = Int32FormatType;
|
||||
format[0].u.Int32 = 1234567890;
|
||||
|
||||
result = PhFormatToBuffer(format, 1, buffer, (OUTPUT_COUNT + 1) * sizeof(WCHAR), &returnLength);
|
||||
assert(result && wcscmp(buffer, L"1234567890") == 0 && returnLength == (OUTPUT_COUNT + 1) * sizeof(WCHAR));
|
||||
result = PhFormatToBuffer(format, 1, buffer, 16 * sizeof(WCHAR), &returnLength);
|
||||
assert(result && wcscmp(buffer, L"1234567890") == 0 && returnLength == (OUTPUT_COUNT + 1) * sizeof(WCHAR));
|
||||
result = PhFormatToBuffer(format, 1, buffer, OUTPUT_COUNT * sizeof(WCHAR), &returnLength);
|
||||
assert(!result && buffer[0] == 0 && returnLength == (OUTPUT_COUNT + 1) * sizeof(WCHAR));
|
||||
result = PhFormatToBuffer(format, 1, buffer, 0, &returnLength);
|
||||
assert(!result && returnLength == (OUTPUT_COUNT + 1) * sizeof(WCHAR));
|
||||
result = PhFormatToBuffer(format, 1, NULL, 9999, &returnLength);
|
||||
assert(!result && returnLength == (OUTPUT_COUNT + 1) * sizeof(WCHAR));
|
||||
}
|
||||
|
||||
static VOID Test_char(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
BOOLEAN result;
|
||||
PH_FORMAT format[2];
|
||||
WCHAR buffer[1024];
|
||||
|
||||
format[0].Type = CharFormatType;
|
||||
format[0].u.Char = 'H';
|
||||
format[1].Type = CharFormatType;
|
||||
format[1].u.Char = 'i';
|
||||
result = PhFormatToBuffer(format, 2, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"Hi") == 0);
|
||||
}
|
||||
|
||||
static VOID Test_string(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
BOOLEAN result;
|
||||
PH_FORMAT format[4];
|
||||
WCHAR buffer[1024];
|
||||
|
||||
format[0].Type = StringFormatType;
|
||||
PhInitializeStringRef(&format[0].u.String, L"This ");
|
||||
format[1].Type = StringZFormatType;
|
||||
format[1].u.StringZ = L"is ";
|
||||
format[2].Type = MultiByteStringFormatType;
|
||||
PhInitializeBytesRef(&format[2].u.MultiByteString, "a ");
|
||||
format[3].Type = MultiByteStringZFormatType;
|
||||
format[3].u.MultiByteStringZ = "string.";
|
||||
result = PhFormatToBuffer(format, 4, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"This is a string.") == 0);
|
||||
}
|
||||
|
||||
static BOOLEAN IsThousandSepComma(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
WCHAR thousandSep[4];
|
||||
|
||||
if (!GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND, thousandSep, 4))
|
||||
return FALSE;
|
||||
if (thousandSep[0] != ',' || thousandSep[1] != 0)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static VOID Test_integer(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
BOOLEAN result;
|
||||
PH_FORMAT format[1];
|
||||
WCHAR buffer[1024];
|
||||
|
||||
// Basic
|
||||
|
||||
format[0].Type = Int32FormatType;
|
||||
format[0].u.Int32 = 0;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"0") == 0);
|
||||
|
||||
format[0].Type = Int32FormatType;
|
||||
format[0].u.Int32 = 123;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"123") == 0);
|
||||
|
||||
format[0].Type = Int32FormatType;
|
||||
format[0].u.Int32 = -123;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"-123") == 0);
|
||||
|
||||
format[0].Type = UInt32FormatType;
|
||||
format[0].u.UInt32 = -123;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"4294967173") == 0);
|
||||
|
||||
format[0].Type = Int64FormatType;
|
||||
format[0].u.Int64 = -1234567890;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"-1234567890") == 0);
|
||||
|
||||
format[0].Type = UInt64FormatType;
|
||||
format[0].u.UInt64 = 12345678901234567890;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"12345678901234567890") == 0);
|
||||
|
||||
// Bases
|
||||
|
||||
format[0].Type = UInt64FormatType | FormatUseRadix;
|
||||
format[0].u.UInt64 = 12345678901234567890;
|
||||
format[0].Radix = 16;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"ab54a98ceb1f0ad2") == 0);
|
||||
|
||||
format[0].Type = UInt64FormatType | FormatUseRadix | FormatUpperCase;
|
||||
format[0].u.UInt64 = 12345678901234567890;
|
||||
format[0].Radix = 16;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"AB54A98CEB1F0AD2") == 0);
|
||||
|
||||
format[0].Type = Int32FormatType | FormatUseRadix;
|
||||
format[0].u.Int32 = -1234;
|
||||
format[0].Radix = 8;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"-2322") == 0);
|
||||
|
||||
// Prefix sign
|
||||
|
||||
format[0].Type = Int32FormatType | FormatPrefixSign;
|
||||
format[0].u.Int32 = 1234;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"+1234") == 0);
|
||||
|
||||
format[0].Type = Int32FormatType | FormatPrefixSign;
|
||||
format[0].u.Int32 = -1234;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"-1234") == 0);
|
||||
|
||||
// Zero pad
|
||||
|
||||
format[0].Type = Int32FormatType | FormatPadZeros;
|
||||
format[0].Width = 6;
|
||||
|
||||
format[0].u.Int32 = 0;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"000000") == 0);
|
||||
format[0].u.Int32 = 1;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"000001") == 0);
|
||||
format[0].u.Int32 = 12345;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"012345") == 0);
|
||||
format[0].u.Int32 = 123456;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"123456") == 0);
|
||||
format[0].u.Int32 = 1234567890;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"1234567890") == 0);
|
||||
format[0].u.Int32 = -1;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"-00001") == 0);
|
||||
format[0].u.Int32 = -1234;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"-01234") == 0);
|
||||
format[0].u.Int32 = -12345;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"-12345") == 0);
|
||||
format[0].u.Int32 = -1234567890;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"-1234567890") == 0);
|
||||
|
||||
// Digit grouping
|
||||
|
||||
if (!IsThousandSepComma())
|
||||
return;
|
||||
|
||||
format[0].Type = Int32FormatType | FormatGroupDigits;
|
||||
|
||||
format[0].u.Int32 = 0;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"0") == 0);
|
||||
format[0].u.Int32 = 1;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"1") == 0);
|
||||
format[0].u.Int32 = 12;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"12") == 0);
|
||||
format[0].u.Int32 = 123;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"123") == 0);
|
||||
format[0].u.Int32 = 1234;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"1,234") == 0);
|
||||
format[0].u.Int32 = 12345;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"12,345") == 0);
|
||||
format[0].u.Int32 = 123456;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"123,456") == 0);
|
||||
format[0].u.Int32 = -123;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"-123") == 0);
|
||||
format[0].u.Int32 = -1234;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"-1,234") == 0);
|
||||
format[0].u.Int32 = -12345;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"-12,345") == 0);
|
||||
}
|
||||
|
||||
static VOID Test_float(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
BOOLEAN result;
|
||||
PH_FORMAT format[1];
|
||||
WCHAR buffer[1024];
|
||||
|
||||
// TODO: Standard and hexadecimal form
|
||||
|
||||
// Basic
|
||||
|
||||
format[0].Type = DoubleFormatType;
|
||||
format[0].u.Double = 0;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"0.000000") == 0);
|
||||
|
||||
format[0].Type = DoubleFormatType;
|
||||
format[0].u.Double = 1;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"1.000000") == 0);
|
||||
|
||||
format[0].Type = DoubleFormatType;
|
||||
format[0].u.Double = 123456789;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"123456789.000000") == 0);
|
||||
|
||||
format[0].Type = DoubleFormatType;
|
||||
format[0].u.Double = 3.14159265358979;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"3.141593") == 0);
|
||||
|
||||
// Precision
|
||||
|
||||
format[0].Type = DoubleFormatType | FormatUsePrecision;
|
||||
format[0].u.Double = 0;
|
||||
format[0].Precision = 0;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"0") == 0);
|
||||
|
||||
format[0].Type = DoubleFormatType | FormatUsePrecision;
|
||||
format[0].u.Double = 3.14159265358979;
|
||||
format[0].Precision = 0;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"3") == 0);
|
||||
|
||||
format[0].Type = DoubleFormatType | FormatUsePrecision;
|
||||
format[0].u.Double = 3.14159265358979;
|
||||
format[0].Precision = 1;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"3.1") == 0);
|
||||
|
||||
format[0].Type = DoubleFormatType | FormatUsePrecision;
|
||||
format[0].u.Double = 3.14159265358979;
|
||||
format[0].Precision = 4;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"3.1416") == 0);
|
||||
|
||||
// Crop zeros
|
||||
|
||||
format[0].Type = DoubleFormatType | FormatUsePrecision | FormatCropZeros;
|
||||
format[0].u.Double = 0;
|
||||
format[0].Precision = 3;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"0") == 0);
|
||||
|
||||
format[0].Type = DoubleFormatType | FormatUsePrecision | FormatCropZeros;
|
||||
format[0].u.Double = 1.2;
|
||||
format[0].Precision = 3;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"1.2") == 0);
|
||||
|
||||
format[0].Type = DoubleFormatType | FormatUsePrecision | FormatCropZeros;
|
||||
format[0].u.Double = 1.21;
|
||||
format[0].Precision = 3;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"1.21") == 0);
|
||||
|
||||
format[0].Type = DoubleFormatType | FormatUsePrecision | FormatCropZeros;
|
||||
format[0].u.Double = 1.216;
|
||||
format[0].Precision = 3;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"1.216") == 0);
|
||||
|
||||
format[0].Type = DoubleFormatType | FormatUsePrecision | FormatCropZeros;
|
||||
format[0].u.Double = 1.2159;
|
||||
format[0].Precision = 3;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"1.216") == 0);
|
||||
|
||||
// Prefix sign
|
||||
|
||||
format[0].Type = DoubleFormatType | FormatPrefixSign;
|
||||
format[0].u.Double = 1234;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"+1234.000000") == 0);
|
||||
|
||||
format[0].Type = DoubleFormatType | FormatUsePrecision | FormatPrefixSign;
|
||||
format[0].u.Double = 1234;
|
||||
format[0].Precision = 0;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"+1234") == 0);
|
||||
|
||||
format[0].Type = DoubleFormatType | FormatPrefixSign;
|
||||
format[0].u.Double = -1234;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"-1234.000000") == 0);
|
||||
|
||||
format[0].Type = DoubleFormatType | FormatPrefixSign;
|
||||
format[0].u.Double = -1234.12;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"-1234.120000") == 0);
|
||||
|
||||
// Zero pad
|
||||
|
||||
format[0].Type = DoubleFormatType | FormatUsePrecision | FormatPadZeros;
|
||||
format[0].Width = 6;
|
||||
|
||||
format[0].u.Double = 0;
|
||||
format[0].Precision = 3;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"00.000") == 0);
|
||||
format[0].u.Double = 1.23;
|
||||
format[0].Precision = 3;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"01.230") == 0);
|
||||
format[0].u.Double = 123456;
|
||||
format[0].Precision = 3;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"123456.000") == 0);
|
||||
format[0].u.Double = -1.23;
|
||||
format[0].Precision = 2;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"-01.23") == 0);
|
||||
format[0].u.Double = -1.23;
|
||||
format[0].Precision = 3;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"-1.230") == 0);
|
||||
|
||||
// Digit grouping
|
||||
|
||||
if (!IsThousandSepComma())
|
||||
return;
|
||||
|
||||
format[0].Type = DoubleFormatType | FormatUsePrecision | FormatGroupDigits;
|
||||
|
||||
format[0].u.Double = 0;
|
||||
format[0].Precision = 0;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"0") == 0);
|
||||
format[0].u.Double = 1;
|
||||
format[0].Precision = 0;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"1") == 0);
|
||||
format[0].u.Double = 12;
|
||||
format[0].Precision = 0;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"12") == 0);
|
||||
format[0].u.Double = 123;
|
||||
format[0].Precision = 0;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"123") == 0);
|
||||
format[0].u.Double = 1234;
|
||||
format[0].Precision = 0;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"1,234") == 0);
|
||||
format[0].u.Double = 12345;
|
||||
format[0].Precision = 0;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"12,345") == 0);
|
||||
format[0].u.Double = 123456;
|
||||
format[0].Precision = 0;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"123,456") == 0);
|
||||
format[0].u.Double = -123;
|
||||
format[0].Precision = 0;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"-123") == 0);
|
||||
format[0].u.Double = -1234;
|
||||
format[0].Precision = 0;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"-1,234") == 0);
|
||||
format[0].u.Double = -12345;
|
||||
format[0].Precision = 0;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"-12,345") == 0);
|
||||
format[0].u.Double = -12345;
|
||||
format[0].Precision = 2;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"-12,345.00") == 0);
|
||||
format[0].u.Double = -9876543.21;
|
||||
format[0].Precision = 5;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"-9,876,543.21000") == 0);
|
||||
}
|
||||
|
||||
static VOID Test_width(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
BOOLEAN result;
|
||||
PH_FORMAT format[2];
|
||||
WCHAR buffer[1024];
|
||||
|
||||
PhInitializeStringRef(&format[0].u.String, L"asdf");
|
||||
|
||||
format[0].Type = StringFormatType;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"asdf") == 0);
|
||||
|
||||
// Left align
|
||||
|
||||
format[0].Type = StringFormatType | FormatLeftAlign;
|
||||
format[0].Width = 4;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"asdf") == 0);
|
||||
|
||||
format[0].Type = StringFormatType | FormatLeftAlign;
|
||||
format[0].Width = 2;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"asdf") == 0);
|
||||
|
||||
format[0].Type = StringFormatType | FormatLeftAlign;
|
||||
format[0].Width = 5;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"asdf ") == 0);
|
||||
|
||||
format[0].Type = StringFormatType | FormatLeftAlign;
|
||||
format[0].Width = 10;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"asdf ") == 0);
|
||||
|
||||
format[0].Type = StringFormatType | FormatLeftAlign | FormatUsePad;
|
||||
format[0].Width = 6;
|
||||
format[0].Pad = '!';
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"asdf!!") == 0);
|
||||
|
||||
// Right align
|
||||
|
||||
format[0].Type = StringFormatType | FormatRightAlign;
|
||||
format[0].Width = 4;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"asdf") == 0);
|
||||
|
||||
format[0].Type = StringFormatType | FormatRightAlign;
|
||||
format[0].Width = 2;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"asdf") == 0);
|
||||
|
||||
format[0].Type = StringFormatType | FormatRightAlign;
|
||||
format[0].Width = 5;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L" asdf") == 0);
|
||||
|
||||
format[0].Type = StringFormatType | FormatRightAlign;
|
||||
format[0].Width = 10;
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L" asdf") == 0);
|
||||
|
||||
format[0].Type = StringFormatType | FormatRightAlign | FormatUsePad;
|
||||
format[0].Width = 6;
|
||||
format[0].Pad = '!';
|
||||
result = PhFormatToBuffer(format, 1, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L"!!asdf") == 0);
|
||||
|
||||
// Multiple
|
||||
|
||||
format[0].Type = Int32FormatType | FormatRightAlign;
|
||||
format[0].u.Int32 = 1234;
|
||||
format[0].Width = 7;
|
||||
format[1].Type = StringZFormatType | FormatLeftAlign;
|
||||
format[1].u.StringZ = L"asdf";
|
||||
format[1].Width = 10;
|
||||
result = PhFormatToBuffer(format, 2, buffer, sizeof(buffer), NULL);
|
||||
assert(result && wcscmp(buffer, L" 1234asdf ") == 0);
|
||||
}
|
||||
|
||||
VOID Test_format(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
Test_buffer();
|
||||
Test_char();
|
||||
Test_string();
|
||||
Test_integer();
|
||||
Test_float();
|
||||
Test_width();
|
||||
}
|
||||
257
tests/phlib-test/t_util.c
Normal file
257
tests/phlib-test/t_util.c
Normal file
@@ -0,0 +1,257 @@
|
||||
#include "tests.h"
|
||||
|
||||
static VOID Test_rectangle(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
PH_RECTANGLE r1;
|
||||
PH_RECTANGLE r2;
|
||||
|
||||
r1.Left = 0;
|
||||
r1.Top = 0;
|
||||
r1.Width = 1024;
|
||||
r1.Height = 1024;
|
||||
|
||||
r2.Width = 100;
|
||||
r2.Height = 100;
|
||||
|
||||
r2.Left = -10;
|
||||
r2.Top = -10;
|
||||
PhAdjustRectangleToBounds(&r2, &r1);
|
||||
assert(r2.Left == 0 && r2.Top == 0 && r2.Width == 100 && r2.Height == 100);
|
||||
|
||||
r2.Left = 1100;
|
||||
r2.Top = 1100;
|
||||
PhAdjustRectangleToBounds(&r2, &r1);
|
||||
assert(r2.Left == 924 && r2.Top == 924 && r2.Width == 100 && r2.Height == 100);
|
||||
|
||||
PhCenterRectangle(&r2, &r1);
|
||||
assert(r2.Left == 462 && r2.Top == 462 && r2.Width == 100 && r2.Height == 100);
|
||||
}
|
||||
|
||||
static BOOLEAN AreGuidsEqual(
|
||||
_In_ PGUID Guid1,
|
||||
_In_ PWSTR Guid2
|
||||
)
|
||||
{
|
||||
GUID guid2;
|
||||
UNICODE_STRING us;
|
||||
|
||||
RtlInitUnicodeString(&us, Guid2);
|
||||
RtlGUIDFromString(&us, &guid2);
|
||||
|
||||
return memcmp(Guid1, &guid2, sizeof(GUID)) == 0;
|
||||
}
|
||||
|
||||
static VOID Test_guid(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
GUID guid;
|
||||
GUID ns;
|
||||
UNICODE_STRING dnsNamespace = RTL_CONSTANT_STRING(L"{6ba7b810-9dad-11d1-80b4-00c04fd430c8}");
|
||||
UNICODE_STRING urlNamespace = RTL_CONSTANT_STRING(L"{6ba7b811-9dad-11d1-80b4-00c04fd430c8}");
|
||||
UNICODE_STRING oidNamespace = RTL_CONSTANT_STRING(L"{6ba7b812-9dad-11d1-80b4-00c04fd430c8}");
|
||||
UNICODE_STRING x500Namespace = RTL_CONSTANT_STRING(L"{6ba7b814-9dad-11d1-80b4-00c04fd430c8}");
|
||||
|
||||
// Taken from http://svn.python.org/projects/python/branches/py3k/Lib/test/test_uuid.py
|
||||
|
||||
RtlGUIDFromString(&dnsNamespace, &ns);
|
||||
PhGenerateGuidFromName(&guid, &ns, "python.org", 10, GUID_VERSION_MD5);
|
||||
assert(AreGuidsEqual(&guid, L"{6fa459ea-ee8a-3ca4-894e-db77e160355e}"));
|
||||
|
||||
RtlGUIDFromString(&urlNamespace, &ns);
|
||||
PhGenerateGuidFromName(&guid, &ns, "http://python.org/", 18, GUID_VERSION_MD5);
|
||||
assert(AreGuidsEqual(&guid, L"{9fe8e8c4-aaa8-32a9-a55c-4535a88b748d}"));
|
||||
|
||||
RtlGUIDFromString(&oidNamespace, &ns);
|
||||
PhGenerateGuidFromName(&guid, &ns, "1.3.6.1", 7, GUID_VERSION_SHA1);
|
||||
assert(AreGuidsEqual(&guid, L"{1447fa61-5277-5fef-a9b3-fbc6e44f4af3}"));
|
||||
|
||||
RtlGUIDFromString(&x500Namespace, &ns);
|
||||
PhGenerateGuidFromName(&guid, &ns, "c=ca", 4, GUID_VERSION_SHA1);
|
||||
assert(AreGuidsEqual(&guid, L"{cc957dd1-a972-5349-98cd-874190002798}"));
|
||||
}
|
||||
|
||||
static VOID Test_ellipsis(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
PPH_STRING input;
|
||||
PPH_STRING output;
|
||||
|
||||
// Normal
|
||||
|
||||
input = PhCreateString(L"asdf 1234");
|
||||
|
||||
output = PhEllipsisString(input, 9);
|
||||
assert(wcscmp(output->Buffer, L"asdf 1234") == 0);
|
||||
output = PhEllipsisString(input, 999);
|
||||
assert(wcscmp(output->Buffer, L"asdf 1234") == 0);
|
||||
output = PhEllipsisString(input, 8);
|
||||
assert(wcscmp(output->Buffer, L"asdf ...") == 0);
|
||||
output = PhEllipsisString(input, 7);
|
||||
assert(wcscmp(output->Buffer, L"asdf...") == 0);
|
||||
output = PhEllipsisString(input, 5);
|
||||
assert(wcscmp(output->Buffer, L"as...") == 0);
|
||||
output = PhEllipsisString(input, 4);
|
||||
assert(wcscmp(output->Buffer, L"a...") == 0);
|
||||
output = PhEllipsisString(input, 3);
|
||||
assert(wcscmp(output->Buffer, L"...") == 0);
|
||||
output = PhEllipsisString(input, 2);
|
||||
assert(wcscmp(output->Buffer, L"asdf 1234") == 0);
|
||||
output = PhEllipsisString(input, 1);
|
||||
assert(wcscmp(output->Buffer, L"asdf 1234") == 0);
|
||||
output = PhEllipsisString(input, 0);
|
||||
assert(wcscmp(output->Buffer, L"asdf 1234") == 0);
|
||||
|
||||
// Path
|
||||
|
||||
input = PhCreateString(L"C:\\abcdef\\1234.abc");
|
||||
|
||||
output = PhEllipsisStringPath(input, 18);
|
||||
assert(wcscmp(output->Buffer, L"C:\\abcdef\\1234.abc") == 0);
|
||||
output = PhEllipsisStringPath(input, 999);
|
||||
assert(wcscmp(output->Buffer, L"C:\\abcdef\\1234.abc") == 0);
|
||||
output = PhEllipsisStringPath(input, 17);
|
||||
assert(wcscmp(output->Buffer, L"C:\\ab...\\1234.abc") == 0); // last part is kept
|
||||
output = PhEllipsisStringPath(input, 16);
|
||||
assert(wcscmp(output->Buffer, L"C:\\a...\\1234.abc") == 0);
|
||||
output = PhEllipsisStringPath(input, 15);
|
||||
assert(wcscmp(output->Buffer, L"C:\\...\\1234.abc") == 0);
|
||||
output = PhEllipsisStringPath(input, 14);
|
||||
assert(wcscmp(output->Buffer, L"C:...\\1234.abc") == 0);
|
||||
output = PhEllipsisStringPath(input, 13);
|
||||
assert(wcscmp(output->Buffer, L"C...\\1234.abc") == 0);
|
||||
output = PhEllipsisStringPath(input, 12);
|
||||
assert(wcscmp(output->Buffer, L"...\\1234.abc") == 0);
|
||||
output = PhEllipsisStringPath(input, 11);
|
||||
assert(wcscmp(output->Buffer, L"C:\\a....abc") == 0); // the two sides are split as evenly as possible
|
||||
output = PhEllipsisStringPath(input, 10);
|
||||
assert(wcscmp(output->Buffer, L"C:\\....abc") == 0);
|
||||
output = PhEllipsisStringPath(input, 9);
|
||||
assert(wcscmp(output->Buffer, L"C:\\...abc") == 0);
|
||||
output = PhEllipsisStringPath(input, 8);
|
||||
assert(wcscmp(output->Buffer, L"C:...abc") == 0);
|
||||
output = PhEllipsisStringPath(input, 7);
|
||||
assert(wcscmp(output->Buffer, L"C:...bc") == 0);
|
||||
output = PhEllipsisStringPath(input, 6);
|
||||
assert(wcscmp(output->Buffer, L"C...bc") == 0);
|
||||
output = PhEllipsisStringPath(input, 5);
|
||||
assert(wcscmp(output->Buffer, L"C...c") == 0);
|
||||
output = PhEllipsisStringPath(input, 4);
|
||||
assert(wcscmp(output->Buffer, L"...c") == 0);
|
||||
output = PhEllipsisStringPath(input, 3);
|
||||
assert(wcscmp(output->Buffer, L"...") == 0);
|
||||
output = PhEllipsisStringPath(input, 2);
|
||||
assert(wcscmp(output->Buffer, L"C:\\abcdef\\1234.abc") == 0);
|
||||
output = PhEllipsisStringPath(input, 1);
|
||||
assert(wcscmp(output->Buffer, L"C:\\abcdef\\1234.abc") == 0);
|
||||
output = PhEllipsisStringPath(input, 0);
|
||||
assert(wcscmp(output->Buffer, L"C:\\abcdef\\1234.abc") == 0);
|
||||
}
|
||||
|
||||
VOID Test_compareignoremenuprefix(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"", L"", FALSE, FALSE) == 0);
|
||||
assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"asdf", L"asdf", FALSE, FALSE) == 0);
|
||||
assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"asdf", L"asDF", FALSE, FALSE) > 0);
|
||||
assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"asdf", L"asDF", TRUE, FALSE) == 0);
|
||||
assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"asdf", L"asdff", FALSE, FALSE) < 0);
|
||||
assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"asdfff", L"asdff", FALSE, FALSE) > 0);
|
||||
|
||||
assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"&asdf", L"asdf", FALSE, FALSE) == 0);
|
||||
assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"&asdf", L"&asdf", FALSE, FALSE) == 0);
|
||||
assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"&&asdf", L"&asdf", FALSE, FALSE) != 0);
|
||||
assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"&&asdf", L"&&asdf", FALSE, FALSE) == 0);
|
||||
assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"&&&asdf", L"&&asdf", FALSE, FALSE) == 0);
|
||||
assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"&&&&asdf", L"&&asdf", FALSE, FALSE) != 0);
|
||||
assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"AAA&&asdf", L"aaa&&&asdf", TRUE, FALSE) == 0);
|
||||
assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"AAA&&&&asdf", L"aaa&&&&asdf", TRUE, FALSE) == 0);
|
||||
|
||||
assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"", L"", FALSE, TRUE) == 0);
|
||||
assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"asdf", L"asdf", FALSE, TRUE) == 0);
|
||||
assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"asdf", L"asDF", FALSE, TRUE) > 0);
|
||||
assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"asdf", L"asDF", TRUE, TRUE) == 0);
|
||||
assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"asdf", L"asdff", FALSE, TRUE) == 0);
|
||||
assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"asdfff", L"asdff", FALSE, TRUE) != 0);
|
||||
|
||||
assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"&asdf", L"asdf", FALSE, TRUE) == 0);
|
||||
assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"&asdf", L"&asdf", FALSE, TRUE) == 0);
|
||||
assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"&&asdf", L"&asdf", FALSE, TRUE) != 0);
|
||||
assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"&&asdf", L"&&asdf&", FALSE, TRUE) == 0);
|
||||
assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"&&asdf", L"&&asdf&&", FALSE, TRUE) == 0);
|
||||
assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"&&asdf&", L"&&asdf", FALSE, TRUE) == 0);
|
||||
assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"&&asdf&&", L"&&asdf", FALSE, TRUE) != 0);
|
||||
assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"&&&asdf", L"&&asdf", FALSE, TRUE) == 0);
|
||||
assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"&&&&asdf", L"&&asdf&&", FALSE, TRUE) != 0);
|
||||
assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"AAA&&asdf", L"aaa&&&asdf&&", TRUE, TRUE) == 0);
|
||||
assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"AAA&&&&asdf", L"aaa&&&&asdf&&", TRUE, TRUE) == 0);
|
||||
}
|
||||
|
||||
static VOID Test_wildcards(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
static WCHAR *testCases[][3] =
|
||||
{
|
||||
{ L"", L"", L"true" },
|
||||
{ L"", L"a", L"false" },
|
||||
{ L"a", L"a", L"true" },
|
||||
{ L"a", L"b", L"false" },
|
||||
{ L"?", L"b", L"true" },
|
||||
{ L"??", L"bc", L"true" },
|
||||
{ L"?c", L"bc", L"true" },
|
||||
{ L"b?", L"bc", L"true" },
|
||||
{ L"*", L"a", L"true" },
|
||||
{ L"**", L"a", L"true" },
|
||||
{ L"*", L"", L"true" },
|
||||
{ L"*bc*hij", L"abcdfghij", L"true" },
|
||||
{ L"*b*a*", L"b", L"false" },
|
||||
{ L"*bc*hik", L"abcdfghij", L"false" },
|
||||
{ L"abc*", L"abc", L"true" },
|
||||
{ L"abc**", L"abc", L"true" },
|
||||
{ L"*???", L"abc", L"true" },
|
||||
{ L"*???", L"ab", L"false" },
|
||||
{ L"*???", L"abcd", L"true" },
|
||||
{ L"*?*", L"abcd", L"true" },
|
||||
{ L"*bc", L"abc", L"true" },
|
||||
{ L"*cc", L"abc", L"false" },
|
||||
{ L"*a*", L"de", L"false" },
|
||||
{ L"*???*", L"123", L"true" },
|
||||
{ L"a*bc", L"abbc", L"true" },
|
||||
{ L"a*b", L"a", L"false" },
|
||||
{ L"a*?b", L"axb", L"true" },
|
||||
{ L"a**b", L"axb", L"true" }
|
||||
};
|
||||
|
||||
ULONG i;
|
||||
BOOLEAN r;
|
||||
BOOLEAN fail;
|
||||
|
||||
for (i = 0; i < sizeof(testCases) / sizeof(WCHAR *[3]); i++)
|
||||
{
|
||||
r = PhMatchWildcards(testCases[i][0], testCases[i][1], TRUE);
|
||||
fail = r != PhEqualStringZ(testCases[i][2], L"true", FALSE);
|
||||
|
||||
if (fail)
|
||||
{
|
||||
wprintf(L"pattern '%s' against '%s': %s (%s expected)\n",
|
||||
testCases[i][0], testCases[i][1], r ? L"true" : L"false", testCases[i][2]);
|
||||
assert(FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
VOID Test_util(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
Test_rectangle();
|
||||
Test_guid();
|
||||
Test_ellipsis();
|
||||
Test_compareignoremenuprefix();
|
||||
Test_wildcards();
|
||||
}
|
||||
22
tests/phlib-test/tests.h
Normal file
22
tests/phlib-test/tests.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#ifndef TESTS_H
|
||||
#define TESTS_H
|
||||
|
||||
#include <ph.h>
|
||||
|
||||
VOID Test_basesup(
|
||||
VOID
|
||||
);
|
||||
|
||||
VOID Test_avltree(
|
||||
VOID
|
||||
);
|
||||
|
||||
VOID Test_format(
|
||||
VOID
|
||||
);
|
||||
|
||||
VOID Test_util(
|
||||
VOID
|
||||
);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user