5
UnitTests/.gitignore
vendored
Normal file
5
UnitTests/.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
/.vs
|
||||
/*.user
|
||||
/Debug
|
||||
/Release
|
||||
/x64
|
31
UnitTests/UnitTests.sln
Normal file
31
UnitTests/UnitTests.sln
Normal file
@@ -0,0 +1,31 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.32126.315
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UnitTests", "UnitTests.vcxproj", "{9AFC377D-C32D-4D42-82C2-09FC818020A2}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Debug|x64 = Debug|x64
|
||||
Release|Win32 = Release|Win32
|
||||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{9AFC377D-C32D-4D42-82C2-09FC818020A2}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{9AFC377D-C32D-4D42-82C2-09FC818020A2}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{9AFC377D-C32D-4D42-82C2-09FC818020A2}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{9AFC377D-C32D-4D42-82C2-09FC818020A2}.Debug|x64.Build.0 = Debug|x64
|
||||
{9AFC377D-C32D-4D42-82C2-09FC818020A2}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{9AFC377D-C32D-4D42-82C2-09FC818020A2}.Release|Win32.Build.0 = Release|Win32
|
||||
{9AFC377D-C32D-4D42-82C2-09FC818020A2}.Release|x64.ActiveCfg = Release|x64
|
||||
{9AFC377D-C32D-4D42-82C2-09FC818020A2}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = false
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {BBDB843D-98C3-46EF-BDE8-0E80FD851852}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
136
UnitTests/UnitTests.vcxproj
Normal file
136
UnitTests/UnitTests.vcxproj
Normal file
@@ -0,0 +1,136 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" 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>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>16.0</VCProjectVersion>
|
||||
<ProjectGuid>{9AFC377D-C32D-4D42-82C2-09FC818020A2}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>UnitTests</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
<ProjectSubType>NativeUnitTestProject</ProjectSubType>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<UseOfMfc>false</UseOfMfc>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Debug'" Label="Configuration">
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Release'" Label="Configuration">
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration" />
|
||||
<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" />
|
||||
</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" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup>
|
||||
<RunCodeAnalysis>true</RunCodeAnalysis>
|
||||
<CodeAnalysisRuleSet>NativeRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Release'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<EnablePREfast>true</EnablePREfast>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>..\include;$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32_LEAN_AND_MEAN;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<UseFullPaths>true</UseFullPaths>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>Advapi32.lib;Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
|
||||
<ClCompile>
|
||||
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
|
||||
<ClCompile>
|
||||
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Platform)'=='Win32'">
|
||||
<ClCompile>
|
||||
<PreprocessorDefinitions>WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />
|
||||
<ItemGroup>
|
||||
<ClCompile Include="math.cpp" />
|
||||
<ClCompile Include="parser.cpp" />
|
||||
<ClCompile Include="pch.cpp">
|
||||
<PrecompiledHeader>Create</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ring.cpp" />
|
||||
<ClCompile Include="sgml.cpp" />
|
||||
<ClCompile Include="stream.cpp" />
|
||||
<ClCompile Include="unicode.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="pch.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
45
UnitTests/UnitTests.vcxproj.filters
Normal file
45
UnitTests/UnitTests.vcxproj.filters
Normal file
@@ -0,0 +1,45 @@
|
||||
<?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;c++;cppm;ixx;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;h++;hm;inl;inc;ipp;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="pch.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="sgml.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="parser.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="math.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ring.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="stream.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="unicode.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="pch.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
295
UnitTests/UnitTests.xcodeproj/project.pbxproj
Normal file
295
UnitTests/UnitTests.xcodeproj/project.pbxproj
Normal file
@@ -0,0 +1,295 @@
|
||||
// !$*UTF8*$!
|
||||
{
|
||||
archiveVersion = 1;
|
||||
classes = {
|
||||
};
|
||||
objectVersion = 56;
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
F4C07F522AB059580044EDC0 /* pch.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F4C07F512AB059580044EDC0 /* pch.cpp */; };
|
||||
F4C07F552AB05B5B0044EDC0 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F4C07F542AB05B5B0044EDC0 /* main.cpp */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXCopyFilesBuildPhase section */
|
||||
F4B7FBDA2AAF49BC00C6BE9F /* CopyFiles */ = {
|
||||
isa = PBXCopyFilesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
dstPath = /usr/share/man/man1/;
|
||||
dstSubfolderSpec = 0;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 1;
|
||||
};
|
||||
/* End PBXCopyFilesBuildPhase section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
F4B7FBDC2AAF49BC00C6BE9F /* UnitTests */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = UnitTests; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
F4C07F4E2AB059300044EDC0 /* math.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = math.cpp; sourceTree = "<group>"; };
|
||||
F4C07F502AB059580044EDC0 /* pch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pch.h; sourceTree = "<group>"; };
|
||||
F4C07F512AB059580044EDC0 /* pch.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = pch.cpp; sourceTree = "<group>"; };
|
||||
F4C07F532AB05A240044EDC0 /* compat.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = compat.hpp; sourceTree = "<group>"; };
|
||||
F4C07F542AB05B5B0044EDC0 /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = "<group>"; };
|
||||
F4C07F562AB08E690044EDC0 /* parser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = parser.cpp; sourceTree = "<group>"; };
|
||||
F4C07F572AB08E690044EDC0 /* unicode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = unicode.cpp; sourceTree = "<group>"; };
|
||||
F4C07F582AB08E690044EDC0 /* sgml.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sgml.cpp; sourceTree = "<group>"; };
|
||||
F4C07F592AB08E690044EDC0 /* ring.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ring.cpp; sourceTree = "<group>"; };
|
||||
F4C07F5A2AB08E690044EDC0 /* stream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = stream.cpp; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
F4B7FBD92AAF49BC00C6BE9F /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
F4B7FBD32AAF49BC00C6BE9F = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
F4C07F542AB05B5B0044EDC0 /* main.cpp */,
|
||||
F4C07F4E2AB059300044EDC0 /* math.cpp */,
|
||||
F4C07F562AB08E690044EDC0 /* parser.cpp */,
|
||||
F4C07F512AB059580044EDC0 /* pch.cpp */,
|
||||
F4C07F592AB08E690044EDC0 /* ring.cpp */,
|
||||
F4C07F582AB08E690044EDC0 /* sgml.cpp */,
|
||||
F4C07F5A2AB08E690044EDC0 /* stream.cpp */,
|
||||
F4C07F572AB08E690044EDC0 /* unicode.cpp */,
|
||||
F4C07F502AB059580044EDC0 /* pch.h */,
|
||||
F4C07F532AB05A240044EDC0 /* compat.hpp */,
|
||||
F4B7FBDD2AAF49BC00C6BE9F /* Products */,
|
||||
);
|
||||
sourceTree = "<group>";
|
||||
usesTabs = 1;
|
||||
};
|
||||
F4B7FBDD2AAF49BC00C6BE9F /* Products */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
F4B7FBDC2AAF49BC00C6BE9F /* UnitTests */,
|
||||
);
|
||||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
F4B7FBDB2AAF49BC00C6BE9F /* UnitTests */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = F4B7FBE32AAF49BC00C6BE9F /* Build configuration list for PBXNativeTarget "UnitTests" */;
|
||||
buildPhases = (
|
||||
F4B7FBD82AAF49BC00C6BE9F /* Sources */,
|
||||
F4B7FBD92AAF49BC00C6BE9F /* Frameworks */,
|
||||
F4B7FBDA2AAF49BC00C6BE9F /* CopyFiles */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (
|
||||
);
|
||||
name = UnitTests;
|
||||
productName = UnitTests;
|
||||
productReference = F4B7FBDC2AAF49BC00C6BE9F /* UnitTests */;
|
||||
productType = "com.apple.product-type.tool";
|
||||
};
|
||||
/* End PBXNativeTarget section */
|
||||
|
||||
/* Begin PBXProject section */
|
||||
F4B7FBD42AAF49BC00C6BE9F /* Project object */ = {
|
||||
isa = PBXProject;
|
||||
attributes = {
|
||||
BuildIndependentTargetsInParallel = 1;
|
||||
LastUpgradeCheck = 1430;
|
||||
TargetAttributes = {
|
||||
F4B7FBDB2AAF49BC00C6BE9F = {
|
||||
CreatedOnToolsVersion = 14.3.1;
|
||||
};
|
||||
};
|
||||
};
|
||||
buildConfigurationList = F4B7FBD72AAF49BC00C6BE9F /* Build configuration list for PBXProject "UnitTests" */;
|
||||
compatibilityVersion = "Xcode 14.0";
|
||||
developmentRegion = en;
|
||||
hasScannedForEncodings = 0;
|
||||
knownRegions = (
|
||||
en,
|
||||
Base,
|
||||
);
|
||||
mainGroup = F4B7FBD32AAF49BC00C6BE9F;
|
||||
productRefGroup = F4B7FBDD2AAF49BC00C6BE9F /* Products */;
|
||||
projectDirPath = "";
|
||||
projectRoot = "";
|
||||
targets = (
|
||||
F4B7FBDB2AAF49BC00C6BE9F /* UnitTests */,
|
||||
);
|
||||
};
|
||||
/* End PBXProject section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
F4B7FBD82AAF49BC00C6BE9F /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
F4C07F552AB05B5B0044EDC0 /* main.cpp in Sources */,
|
||||
F4C07F522AB059580044EDC0 /* pch.cpp in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXSourcesBuildPhase section */
|
||||
|
||||
/* Begin XCBuildConfiguration section */
|
||||
F4B7FBE12AAF49BC00C6BE9F /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
CLANG_ANALYZER_NONNULL = YES;
|
||||
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_ENABLE_OBJC_WEAK = YES;
|
||||
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_COMMA = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
|
||||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
|
||||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
||||
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
COPY_PHASE_STRIP = NO;
|
||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
ENABLE_TESTABILITY = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu11;
|
||||
GCC_DYNAMIC_NO_PIC = NO;
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
GCC_OPTIMIZATION_LEVEL = 0;
|
||||
GCC_PREPROCESSOR_DEFINITIONS = (
|
||||
"DEBUG=1",
|
||||
"$(inherited)",
|
||||
);
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
HEADER_SEARCH_PATHS = ../include;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.15;
|
||||
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
|
||||
MTL_FAST_MATH = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
OTHER_LDFLAGS = "-liconv";
|
||||
SDKROOT = macosx;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
F4B7FBE22AAF49BC00C6BE9F /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
CLANG_ANALYZER_NONNULL = YES;
|
||||
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_ENABLE_OBJC_WEAK = YES;
|
||||
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_COMMA = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
|
||||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
|
||||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
||||
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
COPY_PHASE_STRIP = NO;
|
||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||
ENABLE_NS_ASSERTIONS = NO;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu11;
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
HEADER_SEARCH_PATHS = ../include;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.15;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
MTL_FAST_MATH = YES;
|
||||
OTHER_LDFLAGS = "-liconv";
|
||||
SDKROOT = macosx;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
F4B7FBE42AAF49BC00C6BE9F /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
F4B7FBE52AAF49BC00C6BE9F /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
/* End XCBuildConfiguration section */
|
||||
|
||||
/* Begin XCConfigurationList section */
|
||||
F4B7FBD72AAF49BC00C6BE9F /* Build configuration list for PBXProject "UnitTests" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
F4B7FBE12AAF49BC00C6BE9F /* Debug */,
|
||||
F4B7FBE22AAF49BC00C6BE9F /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
F4B7FBE32AAF49BC00C6BE9F /* Build configuration list for PBXNativeTarget "UnitTests" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
F4B7FBE42AAF49BC00C6BE9F /* Debug */,
|
||||
F4B7FBE52AAF49BC00C6BE9F /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
/* End XCConfigurationList section */
|
||||
};
|
||||
rootObject = F4B7FBD42AAF49BC00C6BE9F /* Project object */;
|
||||
}
|
7
UnitTests/UnitTests.xcodeproj/project.xcworkspace/contents.xcworkspacedata
generated
Normal file
7
UnitTests/UnitTests.xcodeproj/project.xcworkspace/contents.xcworkspacedata
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Workspace
|
||||
version = "1.0">
|
||||
<FileRef
|
||||
location = "self:">
|
||||
</FileRef>
|
||||
</Workspace>
|
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>IDEDidComputeMac32BitWarning</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
77
UnitTests/compat.hpp
Normal file
77
UnitTests/compat.hpp
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
SPDX-License-Identifier: MIT
|
||||
Copyright © 2023 Amebis
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <CppUnitTest.h>
|
||||
#elif defined(__APPLE__)
|
||||
#include <stdexcept>
|
||||
|
||||
#define TEST_CLASS(name) class name
|
||||
#define TEST_METHOD(name) static void name()
|
||||
|
||||
namespace Assert
|
||||
{
|
||||
inline void IsTrue(bool c)
|
||||
{
|
||||
if (!c)
|
||||
throw std::runtime_error("not true");
|
||||
}
|
||||
|
||||
inline void IsFalse(bool c)
|
||||
{
|
||||
if (c)
|
||||
throw std::runtime_error("not false");
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void AreEqual(const T& a, const T& b)
|
||||
{
|
||||
if (!(a == b))
|
||||
throw std::runtime_error("not equal");
|
||||
}
|
||||
|
||||
inline void AreEqual(const char* a, const char* b)
|
||||
{
|
||||
if (strcmp(a, b) != 0)
|
||||
throw std::runtime_error("not equal");
|
||||
}
|
||||
|
||||
inline void AreEqual(const wchar_t* a, const wchar_t* b)
|
||||
{
|
||||
if (wcscmp(a, b) != 0)
|
||||
throw std::runtime_error("not equal");
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void AreNotEqual(const T& a, const T& b)
|
||||
{
|
||||
if (a == b)
|
||||
throw std::runtime_error("equal");
|
||||
}
|
||||
|
||||
inline void AreNotEqual(const char* a, const char* b)
|
||||
{
|
||||
if (strcmp(a, b) == 0)
|
||||
throw std::runtime_error("equal");
|
||||
}
|
||||
|
||||
inline void AreNotEqual(const wchar_t* a, const wchar_t* b)
|
||||
{
|
||||
if (wcscmp(a, b) == 0)
|
||||
throw std::runtime_error("equal");
|
||||
}
|
||||
|
||||
template <class E, typename F>
|
||||
inline void ExpectException(F functor)
|
||||
{
|
||||
try { functor(); }
|
||||
catch (const E&) { return; }
|
||||
catch (...) { throw std::runtime_error("unexpected exception"); }
|
||||
throw std::runtime_error("exception not thrown");
|
||||
}
|
||||
}
|
||||
#endif
|
38
UnitTests/main.cpp
Normal file
38
UnitTests/main.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
SPDX-License-Identifier: MIT
|
||||
Copyright © 2023 Amebis
|
||||
*/
|
||||
|
||||
#include "pch.h"
|
||||
#include "math.cpp"
|
||||
#include "parser.cpp"
|
||||
#include "ring.cpp"
|
||||
#include "sgml.cpp"
|
||||
#include "stream.cpp"
|
||||
#include "unicode.cpp"
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, const char * argv[])
|
||||
{
|
||||
try {
|
||||
UnitTests::math::mul();
|
||||
UnitTests::math::add();
|
||||
UnitTests::parser::wtest();
|
||||
UnitTests::parser::sgml_test();
|
||||
UnitTests::parser::http_test();
|
||||
UnitTests::ring::test();
|
||||
UnitTests::sgml::sgml2wstr();
|
||||
UnitTests::sgml::wstr2sgml();
|
||||
UnitTests::stream::async();
|
||||
UnitTests::stream::replicator();
|
||||
UnitTests::stream::open_close();
|
||||
UnitTests::unicode::str2wstr();
|
||||
UnitTests::unicode::wstr2str();
|
||||
std::cout << "PASS\n";
|
||||
return 0;
|
||||
}
|
||||
catch (const std::exception& ex) {
|
||||
std::cerr << ex.what() << " FAIL\n";
|
||||
return 1;
|
||||
}
|
||||
}
|
44
UnitTests/math.cpp
Normal file
44
UnitTests/math.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
SPDX-License-Identifier: MIT
|
||||
Copyright © 2023 Amebis
|
||||
*/
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
using namespace std;
|
||||
#ifdef _WIN32
|
||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
#endif
|
||||
|
||||
namespace UnitTests
|
||||
{
|
||||
TEST_CLASS(math)
|
||||
{
|
||||
public:
|
||||
TEST_METHOD(mul)
|
||||
{
|
||||
Assert::AreEqual<size_t>(10, stdex::mul(2, 5));
|
||||
Assert::AreEqual<size_t>(10, stdex::mul(5, 2));
|
||||
Assert::AreEqual<size_t>(0, stdex::mul(0, 10));
|
||||
Assert::AreEqual<size_t>(0, stdex::mul(10, 0));
|
||||
Assert::AreEqual<size_t>(0, stdex::mul(SIZE_MAX, 0));
|
||||
Assert::AreEqual<size_t>(0, stdex::mul(0, SIZE_MAX));
|
||||
Assert::AreEqual<size_t>(SIZE_MAX, stdex::mul(SIZE_MAX, 1));
|
||||
Assert::AreEqual<size_t>(SIZE_MAX, stdex::mul(1, SIZE_MAX));
|
||||
Assert::ExpectException<std::invalid_argument>([] { stdex::mul(SIZE_MAX, 2); });
|
||||
Assert::ExpectException<std::invalid_argument>([] { stdex::mul(2, SIZE_MAX); });
|
||||
}
|
||||
|
||||
TEST_METHOD(add)
|
||||
{
|
||||
Assert::AreEqual<size_t>(7, stdex::add(2, 5));
|
||||
Assert::AreEqual<size_t>(7, stdex::add(5, 2));
|
||||
Assert::AreEqual<size_t>(10, stdex::add(0, 10));
|
||||
Assert::AreEqual<size_t>(10, stdex::add(10, 0));
|
||||
Assert::AreEqual<size_t>(SIZE_MAX, stdex::add(SIZE_MAX, 0));
|
||||
Assert::AreEqual<size_t>(SIZE_MAX, stdex::add(0, SIZE_MAX));
|
||||
Assert::ExpectException<std::invalid_argument>([] { stdex::add(SIZE_MAX, 1); });
|
||||
Assert::ExpectException<std::invalid_argument>([] { stdex::add(1, SIZE_MAX); });
|
||||
}
|
||||
};
|
||||
}
|
320
UnitTests/parser.cpp
Normal file
320
UnitTests/parser.cpp
Normal file
@@ -0,0 +1,320 @@
|
||||
/*
|
||||
SPDX-License-Identifier: MIT
|
||||
Copyright © 2023 Amebis
|
||||
*/
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace stdex;
|
||||
using namespace stdex::parser;
|
||||
#ifdef _WIN32
|
||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
#endif
|
||||
|
||||
namespace UnitTests
|
||||
{
|
||||
TEST_CLASS(parser)
|
||||
{
|
||||
public:
|
||||
TEST_METHOD(wtest)
|
||||
{
|
||||
static const wchar_t text[] = L"This is a test.\nSecond line.";
|
||||
|
||||
{
|
||||
wnoop p;
|
||||
Assert::IsTrue(p.match(text));
|
||||
Assert::AreEqual((size_t)0, p.interval.start);
|
||||
Assert::AreEqual((size_t)0, p.interval.end);
|
||||
}
|
||||
|
||||
{
|
||||
wcu p(L't');
|
||||
Assert::IsFalse(p.match(text));
|
||||
Assert::IsTrue(p.match(text, 0, _countof(text), match_case_insensitive));
|
||||
Assert::AreEqual((size_t)0, p.interval.start);
|
||||
Assert::AreEqual((size_t)1, p.interval.end);
|
||||
}
|
||||
|
||||
{
|
||||
wspace_cu p;
|
||||
Assert::IsFalse(p.match(text));
|
||||
Assert::IsTrue(p.match(text, 4));
|
||||
Assert::AreEqual((size_t)4, p.interval.start);
|
||||
Assert::AreEqual((size_t)5, p.interval.end);
|
||||
}
|
||||
|
||||
{
|
||||
wpunct_cu p;
|
||||
Assert::IsFalse(p.match(text));
|
||||
Assert::IsTrue(p.match(text, 14));
|
||||
Assert::AreEqual((size_t)14, p.interval.start);
|
||||
Assert::AreEqual((size_t)15, p.interval.end);
|
||||
}
|
||||
|
||||
{
|
||||
wspace_or_punct_cu p;
|
||||
Assert::IsFalse(p.match(text));
|
||||
Assert::IsTrue(p.match(text, 4));
|
||||
Assert::AreEqual((size_t)4, p.interval.start);
|
||||
Assert::AreEqual((size_t)5, p.interval.end);
|
||||
Assert::IsTrue(p.match(text, 14));
|
||||
Assert::AreEqual((size_t)14, p.interval.start);
|
||||
Assert::AreEqual((size_t)15, p.interval.end);
|
||||
}
|
||||
|
||||
{
|
||||
wbol p;
|
||||
Assert::IsTrue(p.match(text));
|
||||
Assert::AreEqual((size_t)0, p.interval.start);
|
||||
Assert::AreEqual((size_t)0, p.interval.end);
|
||||
Assert::IsFalse(p.match(text, 1));
|
||||
Assert::IsFalse(p.match(text, 15));
|
||||
Assert::IsTrue(p.match(text, 16));
|
||||
Assert::AreEqual((size_t)16, p.interval.start);
|
||||
Assert::AreEqual((size_t)16, p.interval.end);
|
||||
}
|
||||
|
||||
{
|
||||
weol p;
|
||||
Assert::IsFalse(p.match(text));
|
||||
Assert::IsFalse(p.match(text, 1));
|
||||
Assert::IsTrue(p.match(text, 15));
|
||||
Assert::AreEqual((size_t)15, p.interval.start);
|
||||
Assert::AreEqual((size_t)15, p.interval.end);
|
||||
Assert::IsFalse(p.match(text, 16));
|
||||
}
|
||||
|
||||
{
|
||||
wcu_set p(L"abcD");
|
||||
Assert::IsFalse(p.match(text));
|
||||
Assert::IsTrue(p.match(text, 8));
|
||||
Assert::AreEqual((size_t)8, p.interval.start);
|
||||
Assert::AreEqual((size_t)9, p.interval.end);
|
||||
Assert::AreEqual((size_t)0, p.hit_offset);
|
||||
Assert::IsFalse(p.match(text, 21));
|
||||
Assert::IsTrue(p.match(text, 21, _countof(text), match_case_insensitive));
|
||||
Assert::AreEqual((size_t)21, p.interval.start);
|
||||
Assert::AreEqual((size_t)22, p.interval.end);
|
||||
Assert::AreEqual((size_t)3, p.hit_offset);
|
||||
}
|
||||
|
||||
{
|
||||
stdex::parser::wstring p(L"this");
|
||||
Assert::IsFalse(p.match(text));
|
||||
Assert::IsTrue(p.match(text, 0, sizeof(text), match_case_insensitive));
|
||||
Assert::AreEqual((size_t)0, p.interval.start);
|
||||
Assert::AreEqual((size_t)4, p.interval.end);
|
||||
}
|
||||
|
||||
{
|
||||
wany_cu chr;
|
||||
witerations p(make_shared_no_delete(&chr), 1, 5);
|
||||
Assert::IsTrue(p.match(text));
|
||||
Assert::AreEqual((size_t)0, p.interval.start);
|
||||
Assert::AreEqual((size_t)5, p.interval.end);
|
||||
}
|
||||
|
||||
{
|
||||
wspace_cu nospace(true);
|
||||
witerations p(make_shared_no_delete(&nospace), 1);
|
||||
Assert::IsTrue(p.match(text));
|
||||
Assert::AreEqual((size_t)0, p.interval.start);
|
||||
Assert::AreEqual((size_t)4, p.interval.end);
|
||||
}
|
||||
|
||||
{
|
||||
wcu chr_t(L't'), chr_h(L'h'), chr_i(L'i'), chr_s(L's');
|
||||
wspace_cu space;
|
||||
wsequence p({
|
||||
make_shared_no_delete(&chr_t),
|
||||
make_shared_no_delete(&chr_h),
|
||||
make_shared_no_delete(&chr_i),
|
||||
make_shared_no_delete(&chr_s),
|
||||
make_shared_no_delete(&space) });
|
||||
Assert::IsFalse(p.match(text));
|
||||
Assert::IsTrue(p.match(text, 0, _countof(text), match_case_insensitive));
|
||||
Assert::AreEqual((size_t)0, p.interval.start);
|
||||
Assert::AreEqual((size_t)5, p.interval.end);
|
||||
}
|
||||
|
||||
{
|
||||
stdex::parser::wstring apple(L"apple"), orange(L"orange"), _this(L"this");
|
||||
wspace_cu space;
|
||||
wbranch p({
|
||||
make_shared_no_delete(&apple),
|
||||
make_shared_no_delete(&orange),
|
||||
make_shared_no_delete(&_this),
|
||||
make_shared_no_delete(&space) });
|
||||
Assert::IsFalse(p.match(text));
|
||||
Assert::IsTrue(p.match(text, 0, _countof(text), match_case_insensitive));
|
||||
Assert::AreEqual((size_t)2, p.hit_offset);
|
||||
Assert::AreEqual((size_t)0, p.interval.start);
|
||||
Assert::AreEqual((size_t)4, p.interval.end);
|
||||
}
|
||||
|
||||
{
|
||||
wstring_branch p(L"apple", L"orange", L"this", nullptr);
|
||||
Assert::IsFalse(p.match(text));
|
||||
Assert::IsTrue(p.match(text, 0, _countof(text), match_case_insensitive));
|
||||
Assert::AreEqual((size_t)2, p.hit_offset);
|
||||
Assert::AreEqual((size_t)0, p.interval.start);
|
||||
Assert::AreEqual((size_t)4, p.interval.end);
|
||||
}
|
||||
|
||||
{
|
||||
wcu chr_s(L's'), chr_h(L'h'), chr_i(L'i'), chr_t(L't');
|
||||
wpermutation p({
|
||||
make_shared_no_delete(&chr_s),
|
||||
make_shared_no_delete(&chr_h),
|
||||
make_shared_no_delete(&chr_i),
|
||||
make_shared_no_delete(&chr_t) });
|
||||
Assert::IsFalse(p.match(text));
|
||||
Assert::IsTrue(p.match(text, 0, _countof(text), match_case_insensitive));
|
||||
Assert::AreEqual((size_t)0, p.interval.start);
|
||||
Assert::AreEqual((size_t)4, p.interval.end);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD(sgml_test)
|
||||
{
|
||||
std::locale locale_slSI("sl_SI");
|
||||
static const char text[] = "V kožuščku zlobnega mizarja stopiclja fant\nin kliče 1234567890.";
|
||||
|
||||
{
|
||||
sgml_noop p;
|
||||
Assert::IsTrue(p.match(text));
|
||||
Assert::AreEqual((size_t)0, p.interval.start);
|
||||
Assert::AreEqual((size_t)0, p.interval.end);
|
||||
}
|
||||
|
||||
{
|
||||
sgml_cp p("v");
|
||||
Assert::IsFalse(p.match(text));
|
||||
Assert::IsTrue(p.match(text, 0, _countof(text), match_case_insensitive));
|
||||
Assert::AreEqual((size_t)0, p.interval.start);
|
||||
Assert::AreEqual((size_t)1, p.interval.end);
|
||||
}
|
||||
|
||||
{
|
||||
sgml_cp p("Ž", SIZE_MAX, false, locale_slSI);
|
||||
Assert::IsFalse(p.match(text, 4));
|
||||
Assert::IsTrue(p.match(text, 4, _countof(text), match_case_insensitive));
|
||||
Assert::AreEqual((size_t)4, p.interval.start);
|
||||
Assert::AreEqual((size_t)12, p.interval.end);
|
||||
}
|
||||
|
||||
{
|
||||
sgml_space_cp p(false, locale_slSI);
|
||||
Assert::IsFalse(p.match(text));
|
||||
Assert::IsTrue(p.match(text, 1));
|
||||
Assert::AreEqual((size_t)1, p.interval.start);
|
||||
Assert::AreEqual((size_t)2, p.interval.end);
|
||||
Assert::IsTrue(p.match(text, 79));
|
||||
Assert::AreEqual((size_t)79, p.interval.start);
|
||||
Assert::AreEqual((size_t)85, p.interval.end);
|
||||
}
|
||||
|
||||
{
|
||||
sgml_string_branch p(locale_slSI, "apple", "orange", "KoŽuŠčKu", nullptr);
|
||||
Assert::IsFalse(p.match(text, 2));
|
||||
Assert::IsTrue(p.match(text, 2, _countof(text), match_case_insensitive));
|
||||
Assert::AreEqual((size_t)2, p.hit_offset);
|
||||
Assert::AreEqual((size_t)2, p.interval.start);
|
||||
Assert::AreEqual((size_t)31, p.interval.end);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD(http_test)
|
||||
{
|
||||
static const std::locale locale("en_US.UTF-8");
|
||||
static const char request[] =
|
||||
"GET / HTTP/2\r\n"
|
||||
"Host: stackoverflow.com\r\n"
|
||||
"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/110.0\r\n"
|
||||
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8\r\n"
|
||||
"Accept-Language: sl,en-US;q=0.8,en;q=0.6,de-DE;q=0.4,de;q=0.2\r\n"
|
||||
"Accept-Encoding: gzip, deflate, br\r\n"
|
||||
"DNT: 1\r\n"
|
||||
"Connection: keep-alive\r\n"
|
||||
"Cookie: prov=00000000-0000-0000-0000-000000000000; acct=t=00000000000000000%2f%2f0000%2b0000%2b000&s=00000000000000000000000000000000; OptanonConsent=isGpcEnabled=0&datestamp=Fri+Feb+03+2023+11%3A11%3A08+GMT%2B0100+(Srednjeevropski+standardni+%C4%8Das)&version=6.37.0&isIABGlobal=false&hosts=&consentId=00000000-0000-0000-0000-000000000000&interactionCount=1&landingPath=NotLandingPage&groups=00000%3A0%2C00000%3A0%2C00000%3A0%2C00000%3A0; OptanonAlertBoxClosed=2023-02-03T10:11:08.683Z\r\n"
|
||||
"Upgrade-Insecure-Requests: 1\r\n"
|
||||
"Sec-Fetch-Dest: document\r\n"
|
||||
"Sec-Fetch-Mode: navigate\r\n"
|
||||
"Sec-Fetch-Site: none\r\n"
|
||||
"Sec-Fetch-User: ?1\r\n"
|
||||
"Pragma: no-cache\r\n"
|
||||
"Cache-Control: no-cache\r\n"
|
||||
"\r\n";
|
||||
|
||||
{
|
||||
http_request p(locale);
|
||||
Assert::IsTrue(p.match(request));
|
||||
Assert::AreEqual((size_t)0, p.interval.start);
|
||||
Assert::AreEqual((size_t)14, p.interval.end);
|
||||
Assert::AreEqual((size_t)0, p.verb.start);
|
||||
Assert::AreEqual((size_t)3, p.verb.end);
|
||||
Assert::AreEqual((size_t)4, p.url.interval.start);
|
||||
Assert::AreEqual((size_t)5, p.url.interval.end);
|
||||
Assert::AreEqual((size_t)6, p.protocol.interval.start);
|
||||
Assert::AreEqual((size_t)12, p.protocol.interval.end);
|
||||
Assert::AreEqual((uint16_t)0x200, p.protocol.version);
|
||||
}
|
||||
|
||||
{
|
||||
std::list<http_header> hdrs;
|
||||
size_t offset = 14;
|
||||
for (;;) {
|
||||
http_header h;
|
||||
if (h.match(request, offset)) {
|
||||
offset = h.interval.end;
|
||||
hdrs.push_back(std::move(h));
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
Assert::AreEqual((size_t)15, hdrs.size());
|
||||
http_weighted_collection<http_weighted_value<http_language>> langs;
|
||||
for (const auto& h : hdrs)
|
||||
if (strnicmp(request + h.name.start, h.name.size(), "Accept-Language", (size_t)-1, locale) == 0)
|
||||
langs.insert(request, h.value.start, h.value.end);
|
||||
Assert::IsTrue(!langs.empty());
|
||||
{
|
||||
const vector<std::string> control = {
|
||||
"sl", "en-US", "en", "de-DE", "de"
|
||||
};
|
||||
auto c = control.cbegin();
|
||||
auto l = langs.cbegin();
|
||||
for (; c != control.cend() && l != langs.cend(); ++c, ++l)
|
||||
Assert::IsTrue(strnicmp(request + l->value.interval.start, l->value.interval.size(), c->c_str(), c->size(), locale) == 0);
|
||||
Assert::IsTrue(c == control.cend());
|
||||
Assert::IsTrue(l == langs.cend());
|
||||
}
|
||||
}
|
||||
|
||||
//static const char response[] =
|
||||
// "HTTP/2 200 OK\r\n"
|
||||
// "cache-control: private\r\n"
|
||||
// "content-type: text/html; charset=utf-8\r\n"
|
||||
// "content-encoding: gzip\r\n"
|
||||
// "strict-transport-security: max-age=15552000\r\n"
|
||||
// "x-frame-options: SAMEORIGIN\r\n"
|
||||
// "set-cookie: acct=t=00000000000000000%2f%2f0000%2b0000%2b000&s=00000000000000000000000000000000; expires=Sat, 16 Sep 2023 10:23:00 GMT; domain=.stackoverflow.com; path=/; secure; samesite=none; httponly\r\n"
|
||||
// "set-cookie: prov_tgt=; expires=Tue, 14 Mar 2023 10:23:00 GMT; domain=.stackoverflow.com; path=/; secure; samesite=none; httponly\r\n"
|
||||
// "x-request-guid: a6536a49-b473-4c6f-b313-c1e7c0d8f600\r\n"
|
||||
// "feature-policy: microphone 'none'; speaker 'none'\r\n"
|
||||
// "content-security-policy: upgrade-insecure-requests; frame-ancestors 'self' https://stackexchange.com\r\n"
|
||||
// "accept-ranges: bytes\r\n"
|
||||
// "date: Thu, 16 Mar 2023 10:23:00 GMT\r\n"
|
||||
// "via: 1.1 varnish\r\n"
|
||||
// "x-served-by: cache-vie6354-VIE\r\n"
|
||||
// "x-cache: MISS\r\n"
|
||||
// "x-cache-hits: 0\r\n"
|
||||
// "x-timer: S1678962181.533907,VS0,VE144\r\n"
|
||||
// "vary: Accept-Encoding,Fastly-SSL\r\n"
|
||||
// "x-dns-prefetch-control: off\r\n"
|
||||
// "X-Firefox-Spdy: h2\r\n"
|
||||
// "\r\n";
|
||||
}
|
||||
};
|
||||
}
|
6
UnitTests/pch.cpp
Normal file
6
UnitTests/pch.cpp
Normal file
@@ -0,0 +1,6 @@
|
||||
/*
|
||||
SPDX-License-Identifier: MIT
|
||||
Copyright © 2023 Amebis
|
||||
*/
|
||||
|
||||
#include "pch.h"
|
31
UnitTests/pch.h
Normal file
31
UnitTests/pch.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
SPDX-License-Identifier: MIT
|
||||
Copyright © 2023 Amebis
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdex/base64.hpp>
|
||||
#include <stdex/compat.hpp>
|
||||
#include <stdex/errno.hpp>
|
||||
#include <stdex/exception.hpp>
|
||||
#include <stdex/hex.hpp>
|
||||
#include <stdex/idrec.hpp>
|
||||
#include <stdex/interval.hpp>
|
||||
#include <stdex/mapping.hpp>
|
||||
#include <stdex/math.hpp>
|
||||
#include <stdex/parser.hpp>
|
||||
#include <stdex/progress.hpp>
|
||||
#include <stdex/ring.hpp>
|
||||
#include <stdex/sgml.hpp>
|
||||
#include <stdex/stream.hpp>
|
||||
#include <stdex/string.hpp>
|
||||
#include <stdex/system.hpp>
|
||||
#include <stdex/unicode.hpp>
|
||||
#include <stdex/vector_queue.hpp>
|
||||
|
||||
#include "compat.hpp"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <filesystem>
|
||||
#include <thread>
|
57
UnitTests/ring.cpp
Normal file
57
UnitTests/ring.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
SPDX-License-Identifier: MIT
|
||||
Copyright © 2023 Amebis
|
||||
*/
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
using namespace std;
|
||||
#ifdef _WIN32
|
||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
#endif
|
||||
|
||||
namespace UnitTests
|
||||
{
|
||||
constexpr size_t capacity = 50;
|
||||
|
||||
TEST_CLASS(ring)
|
||||
{
|
||||
public:
|
||||
TEST_METHOD(test)
|
||||
{
|
||||
using ring_t = stdex::ring<int, capacity>;
|
||||
ring_t ring;
|
||||
thread writer([](_Inout_ ring_t& ring)
|
||||
{
|
||||
int seed = 0;
|
||||
for (size_t retries = 1000; retries--;) {
|
||||
for (auto to_write = static_cast<size_t>(static_cast<uint64_t>(::rand()) * capacity / 5 / RAND_MAX); to_write;) {
|
||||
int* ptr; size_t num_write;
|
||||
tie(ptr, num_write) = ring.back();
|
||||
if (to_write < num_write)
|
||||
num_write = to_write;
|
||||
for (size_t i = 0; i < num_write; i++)
|
||||
ptr[i] = seed++;
|
||||
ring.push(num_write);
|
||||
to_write -= num_write;
|
||||
}
|
||||
}
|
||||
ring.quit();
|
||||
}, ref(ring));
|
||||
|
||||
int seed = 0;
|
||||
for (;;) {
|
||||
int* ptr; size_t num_read;
|
||||
tie(ptr, num_read) = ring.front();
|
||||
if (!ptr) _Unlikely_
|
||||
break;
|
||||
if (num_read > 7)
|
||||
num_read = 7;
|
||||
for (size_t i = 0; i < num_read; ++i)
|
||||
Assert::AreEqual(seed++, ptr[i]);
|
||||
ring.pop(num_read);
|
||||
}
|
||||
writer.join();
|
||||
}
|
||||
};
|
||||
}
|
67
UnitTests/sgml.cpp
Normal file
67
UnitTests/sgml.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
SPDX-License-Identifier: MIT
|
||||
Copyright © 2023 Amebis
|
||||
*/
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
using namespace std;
|
||||
#ifdef _WIN32
|
||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
#endif
|
||||
|
||||
namespace UnitTests
|
||||
{
|
||||
TEST_CLASS(sgml)
|
||||
{
|
||||
public:
|
||||
TEST_METHOD(sgml2wstr)
|
||||
{
|
||||
Assert::AreEqual(L"This is a test.", stdex::sgml2wstr("This is a test.", (size_t)-1).c_str());
|
||||
Assert::AreEqual(L"Th\u00ed\u0161 i\u22c5 a te\u0073\u0304t.&unknown;😀😅", stdex::sgml2wstr("Thíš i⋅ a te&smacr;t.&unknown;😀😅", (size_t)-1).c_str());
|
||||
Assert::AreEqual(L"This", stdex::sgml2wstr("This is a test.", 4).c_str());
|
||||
Assert::AreEqual(L"T\u0068\u0301", stdex::sgml2wstr("T&hacute;is is a test.", 9).c_str());
|
||||
Assert::AreEqual(L"T&hac", stdex::sgml2wstr("T&hacute;is is a test.", 5).c_str());
|
||||
Assert::AreEqual(L"The "quoted" & text.", stdex::sgml2wstr("The "quoted" & text.", (size_t)-1, stdex::sgml_c).c_str());
|
||||
|
||||
stdex::mapping_vector<size_t> map;
|
||||
constexpr size_t i = 0;
|
||||
constexpr size_t j = 0;
|
||||
stdex::sgml2wstr("Thíš i⋅ a te&smacr;t.&unknown;😀😅", (size_t)-1, 0, stdex::mapping<size_t>(i, j), &map);
|
||||
Assert::IsTrue(stdex::mapping_vector<size_t>{
|
||||
{ i + 2, j + 2 },
|
||||
{ i + 10, j + 3 },
|
||||
{ i + 10, j + 3 },
|
||||
{ i + 18, j + 4 },
|
||||
{ i + 20, j + 6 },
|
||||
{ i + 26, j + 7 },
|
||||
{ i + 27, j + 8 },
|
||||
{ i + 32, j + 9 },
|
||||
{ i + 35, j + 12 },
|
||||
{ i + 42, j + 14 },
|
||||
{ i + 53, j + 25 },
|
||||
#ifdef _WIN32 // wchar_t* is UTF-16
|
||||
{ i + 62, j + 27 },
|
||||
{ i + 62, j + 27 },
|
||||
{ i + 71, j + 29 },
|
||||
#else // wchar_t* is UTF-32
|
||||
{ i + 62, j + 26 },
|
||||
{ i + 62, j + 26 },
|
||||
{ i + 71, j + 27 },
|
||||
#endif
|
||||
} == map);
|
||||
}
|
||||
|
||||
TEST_METHOD(wstr2sgml)
|
||||
{
|
||||
Assert::AreEqual("This is a test.", stdex::wstr2sgml(L"This is a test.", (size_t)-1).c_str());
|
||||
Assert::AreEqual("Thíš i⋅ a te&smacr;t.&unknown;😀😅", stdex::wstr2sgml(L"Th\u00ed\u0161 i\u22c5 a te\u0073\u0304t.&unknown;😀😅", (size_t)-1).c_str());
|
||||
Assert::AreEqual("This", stdex::wstr2sgml(L"This is a test.", 4).c_str());
|
||||
Assert::AreEqual("te&smacr;", stdex::wstr2sgml(L"te\u0073\u0304t", 4).c_str());
|
||||
Assert::AreEqual("tes", stdex::wstr2sgml(L"te\u0073\u0304t", 3).c_str());
|
||||
Assert::AreEqual("⌘‰͢", stdex::wstr2sgml(L"⌘‰͢", (size_t)-1).c_str());
|
||||
Assert::AreEqual("$\"<>&", stdex::wstr2sgml(L"$\"<>&", (size_t)-1).c_str());
|
||||
Assert::AreEqual("$"<>&", stdex::wstr2sgml(L"$\"<>&", (size_t)-1, stdex::sgml_c).c_str());
|
||||
}
|
||||
};
|
||||
}
|
154
UnitTests/stream.cpp
Normal file
154
UnitTests/stream.cpp
Normal file
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
SPDX-License-Identifier: MIT
|
||||
Copyright © 2023 Amebis
|
||||
*/
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace stdex;
|
||||
using namespace stdex::stream;
|
||||
#ifdef _WIN32
|
||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
#endif
|
||||
|
||||
namespace UnitTests
|
||||
{
|
||||
TEST_CLASS(stream)
|
||||
{
|
||||
public:
|
||||
TEST_METHOD(async)
|
||||
{
|
||||
constexpr uint32_t total = 1000;
|
||||
memory_file source(mul(total, sizeof(uint32_t)));
|
||||
{
|
||||
async_writer<70> writer(source);
|
||||
for (uint32_t i = 0; i < total; ++i) {
|
||||
Assert::IsTrue(writer.ok());
|
||||
writer << i;
|
||||
}
|
||||
}
|
||||
Assert::AreEqual<stdex::stream::fpos_t>(0, source.seekbeg(0));
|
||||
{
|
||||
async_reader<50> reader(source);
|
||||
uint32_t x;
|
||||
for (uint32_t i = 0; i < total; ++i) {
|
||||
reader >> x;
|
||||
Assert::IsTrue(reader.ok());
|
||||
Assert::AreEqual(i, x);
|
||||
}
|
||||
reader >> x;
|
||||
Assert::IsFalse(reader.ok());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD(replicator)
|
||||
{
|
||||
constexpr uint32_t total = 1000;
|
||||
|
||||
memory_file f1(mul(total, sizeof(uint32_t)));
|
||||
|
||||
sstring filename2, filename3;
|
||||
filename2 = filename3 = temp_path();
|
||||
filename2 += _T("stdex-stream-replicator-2.tmp");
|
||||
file f2(
|
||||
filename2.c_str(),
|
||||
mode_for_reading | mode_for_writing | mode_create | mode_binary);
|
||||
|
||||
filename3 += _T("stdex-stream-replicator-3.tmp");
|
||||
cached_file f3(
|
||||
filename3.c_str(),
|
||||
mode_for_reading | mode_for_writing | mode_create | mode_binary,
|
||||
128);
|
||||
|
||||
{
|
||||
stdex::stream::replicator writer;
|
||||
buffer f2_buf(f2, 0, 32);
|
||||
writer.push_back(&f1);
|
||||
writer.push_back(&f2_buf);
|
||||
writer.push_back(&f3);
|
||||
for (uint32_t i = 0; i < total; ++i) {
|
||||
Assert::IsTrue(writer.ok());
|
||||
writer << i;
|
||||
}
|
||||
}
|
||||
|
||||
f1.seekbeg(0);
|
||||
f2.seekbeg(0);
|
||||
f3.seekbeg(0);
|
||||
{
|
||||
buffer f2_buf(f2, 64, 0);
|
||||
uint32_t x;
|
||||
for (uint32_t i = 0; i < total; ++i) {
|
||||
f1 >> x;
|
||||
Assert::IsTrue(f1.ok());
|
||||
Assert::AreEqual(i, x);
|
||||
f2_buf >> x;
|
||||
Assert::IsTrue(f2_buf.ok());
|
||||
Assert::AreEqual(i, x);
|
||||
f3 >> x;
|
||||
Assert::IsTrue(f3.ok());
|
||||
Assert::AreEqual(i, x);
|
||||
}
|
||||
f1 >> x;
|
||||
Assert::IsFalse(f1.ok());
|
||||
f2_buf >> x;
|
||||
Assert::IsFalse(f2_buf.ok());
|
||||
f3 >> x;
|
||||
Assert::IsFalse(f3.ok());
|
||||
}
|
||||
|
||||
f2.close();
|
||||
std::filesystem::remove(filename2);
|
||||
f3.close();
|
||||
std::filesystem::remove(filename3);
|
||||
}
|
||||
|
||||
TEST_METHOD(open_close)
|
||||
{
|
||||
cached_file dat(invalid_handle, state_t::fail, 4096);
|
||||
const sstring filepath = temp_path();
|
||||
constexpr uint32_t count = 3;
|
||||
sstring filename[count];
|
||||
stdex::stream::fpos_t start[count];
|
||||
for (uint32_t i = 0; i < count; ++i) {
|
||||
filename[i] = filepath + sprintf(_T("stdex-stream-open_close%zu.tmp"), NULL, i);
|
||||
dat.open(filename[i].c_str(), mode_for_reading | mode_for_writing | share_none | mode_preserve_existing | mode_binary);
|
||||
Assert::IsTrue(dat.ok());
|
||||
start[i] = dat.tell();
|
||||
Assert::AreNotEqual(fpos_max, start[i]);
|
||||
for (uint32_t j = 0; j < 31 + 11 * i; ++j) {
|
||||
dat << j * count + i;
|
||||
Assert::IsTrue(dat.ok());
|
||||
}
|
||||
dat.close();
|
||||
}
|
||||
for (uint32_t i = 0; i < count; ++i) {
|
||||
dat.open(filename[i].c_str(), mode_for_reading | share_none | mode_binary);
|
||||
Assert::IsTrue(dat.ok());
|
||||
for (;;) {
|
||||
uint32_t x;
|
||||
dat >> x;
|
||||
if (!dat.ok())
|
||||
break;
|
||||
Assert::AreEqual(i, x % count);
|
||||
}
|
||||
}
|
||||
dat.close();
|
||||
for (uint32_t i = 0; i < count; ++i)
|
||||
std::filesystem::remove(filename[i]);
|
||||
}
|
||||
|
||||
protected:
|
||||
static sstring temp_path()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
TCHAR temp_path[MAX_PATH];
|
||||
Assert::IsTrue(ExpandEnvironmentStrings(_T("%TEMP%\\"), temp_path, _countof(temp_path)) < MAX_PATH);
|
||||
return temp_path;
|
||||
#else
|
||||
return "/tmp/";
|
||||
#endif
|
||||
}
|
||||
};
|
||||
}
|
50
UnitTests/unicode.cpp
Normal file
50
UnitTests/unicode.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
SPDX-License-Identifier: MIT
|
||||
Copyright © 2023 Amebis
|
||||
*/
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
using namespace std;
|
||||
#ifdef _WIN32
|
||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
#endif
|
||||
|
||||
namespace UnitTests
|
||||
{
|
||||
TEST_CLASS(unicode)
|
||||
{
|
||||
public:
|
||||
TEST_METHOD(str2wstr)
|
||||
{
|
||||
Assert::AreEqual(
|
||||
L"This is a test.",
|
||||
stdex::str2wstr("This is a test.", stdex::charset_id::utf8).c_str());
|
||||
Assert::AreEqual(
|
||||
L"Th\u00ed\u0161 i\u22c5 a te\u0073\u0304t. 😀😅",
|
||||
stdex::str2wstr("Thíš i⋅ a tes̄t. 😀😅", stdex::charset_id::utf8).c_str());
|
||||
Assert::AreEqual(
|
||||
L"",
|
||||
stdex::str2wstr("test", 0, stdex::charset_id::utf8).c_str());
|
||||
Assert::AreEqual(
|
||||
L"",
|
||||
stdex::str2wstr(nullptr, 0, stdex::charset_id::utf8).c_str());
|
||||
}
|
||||
|
||||
TEST_METHOD(wstr2str)
|
||||
{
|
||||
Assert::AreEqual(
|
||||
"This is a test.",
|
||||
stdex::wstr2str(L"This is a test.", stdex::charset_id::utf8).c_str());
|
||||
Assert::AreEqual(
|
||||
"Th\xc3\xad\xc5\xa1 i\xe2\x8b\x85 a tes\xcc\x84t. \xf0\x9f\x98\x80\xf0\x9f\x98\x85",
|
||||
stdex::wstr2str(L"Thíš i⋅ a tes̄t. 😀😅", stdex::charset_id::utf8).c_str());
|
||||
Assert::AreEqual(
|
||||
"",
|
||||
stdex::wstr2str(L"test", 0, stdex::charset_id::utf8).c_str());
|
||||
Assert::AreEqual(
|
||||
"",
|
||||
stdex::wstr2str(nullptr, 0, stdex::charset_id::utf8).c_str());
|
||||
}
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user