Added dynamic QR-code method determination
This commit is contained in:
parent
9f77df06df
commit
d4c6eff155
@ -5,6 +5,8 @@ VisualStudioVersion = 16.0.31911.196
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "QRCodeLibrary", "QRCodeLibrary\QRCodeLibrary.vcxproj", "{B1126767-CDF7-4831-8B08-85BF457DB4E2}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tests", "tests\tests.vcxproj", "{96CDAF28-007A-4900-B24E-E21676713543}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
@ -21,6 +23,14 @@ Global
|
||||
{B1126767-CDF7-4831-8B08-85BF457DB4E2}.Release|x64.Build.0 = Release|x64
|
||||
{B1126767-CDF7-4831-8B08-85BF457DB4E2}.Release|x86.ActiveCfg = Release|Win32
|
||||
{B1126767-CDF7-4831-8B08-85BF457DB4E2}.Release|x86.Build.0 = Release|Win32
|
||||
{96CDAF28-007A-4900-B24E-E21676713543}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{96CDAF28-007A-4900-B24E-E21676713543}.Debug|x64.Build.0 = Debug|x64
|
||||
{96CDAF28-007A-4900-B24E-E21676713543}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{96CDAF28-007A-4900-B24E-E21676713543}.Debug|x86.Build.0 = Debug|Win32
|
||||
{96CDAF28-007A-4900-B24E-E21676713543}.Release|x64.ActiveCfg = Release|x64
|
||||
{96CDAF28-007A-4900-B24E-E21676713543}.Release|x64.Build.0 = Release|x64
|
||||
{96CDAF28-007A-4900-B24E-E21676713543}.Release|x86.ActiveCfg = Release|Win32
|
||||
{96CDAF28-007A-4900-B24E-E21676713543}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
32
QRCodeLibrary/Method.cpp
Normal file
32
QRCodeLibrary/Method.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
#include "pch.h"
|
||||
|
||||
#include "Method.hpp"
|
||||
#include "Tables.hpp"
|
||||
|
||||
QRCodeMethod Method::determite_method(string input)
|
||||
{
|
||||
QRCodeMethod type = QRCodeMethod::Numeric;
|
||||
|
||||
for (auto ch : input) {
|
||||
if (type == QRCodeMethod::Numeric)
|
||||
if (!is_num(ch))
|
||||
type = QRCodeMethod::Alphabetic;
|
||||
if (type == QRCodeMethod::Alphabetic)
|
||||
if (!is_alphabetic(ch))
|
||||
type = QRCodeMethod::Byte;
|
||||
if (type == QRCodeMethod::Byte)
|
||||
break;
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
constexpr bool Method::is_num(char ch)
|
||||
{
|
||||
return ch >= '0' && ch <= '9';
|
||||
}
|
||||
|
||||
bool Method::is_alphabetic(char ch)
|
||||
{
|
||||
return find(Tables::alphabetic.cbegin(), Tables::alphabetic.cend(), ch) != Tables::alphabetic.cend();
|
||||
}
|
@ -1,8 +1,9 @@
|
||||
#include "pch.h"
|
||||
#include "QRCode.hpp"
|
||||
|
||||
QRCode::QRCode(string input_, CorrectionLevel corr_lvl_, QRCodeMethod method_, unsigned char version_):
|
||||
input{ input_ }, corr_lvl{ corr_lvl_ }, method{ method_ }, version{ version_ }
|
||||
QRCode::QRCode(string input_, CorrectionLevel corr_lvl_, QRCodeMethod method_, unsigned char version_) :
|
||||
input{ input_ }, corr_lvl{ corr_lvl_ }, method{ method_ }, version{ version_ }
|
||||
{
|
||||
|
||||
if (method == QRCodeMethod::Dynamic)
|
||||
method = Method::determite_method(input);
|
||||
}
|
||||
|
@ -152,11 +152,13 @@
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="framework.h" />
|
||||
<ClInclude Include="method.hpp" />
|
||||
<ClInclude Include="Method.hpp" />
|
||||
<ClInclude Include="pch.h" />
|
||||
<ClInclude Include="QRCode.hpp" />
|
||||
<ClInclude Include="Tables.hpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Method.cpp" />
|
||||
<ClCompile Include="pch.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
|
||||
@ -164,6 +166,7 @@
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="QRCode.cpp" />
|
||||
<ClCompile Include="Tables.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
|
@ -24,7 +24,10 @@
|
||||
<ClInclude Include="QRCode.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="method.hpp">
|
||||
<ClInclude Include="Method.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Tables.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
@ -35,5 +38,11 @@
|
||||
<ClCompile Include="QRCode.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Method.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Tables.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
11
QRCodeLibrary/Tables.cpp
Normal file
11
QRCodeLibrary/Tables.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
#include "pch.h"
|
||||
|
||||
#include "Tables.hpp"
|
||||
|
||||
const std::array<char, 45> Tables::alphabetic{
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
|
||||
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
|
||||
'U', 'V', 'W', 'X', 'Y', 'Z', ' ', '$', '%', '*',
|
||||
'+', '-', '.', '/', ':'
|
||||
};
|
8
QRCodeLibrary/Tables.hpp
Normal file
8
QRCodeLibrary/Tables.hpp
Normal file
@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
|
||||
class Tables {
|
||||
public:
|
||||
static const std::array<char, 45>alphabetic;
|
||||
};
|
@ -16,4 +16,12 @@ enum class CorrectionLevel {
|
||||
M,
|
||||
Q,
|
||||
H
|
||||
};
|
||||
|
||||
class Method {
|
||||
public:
|
||||
static QRCodeMethod determite_method(string input);
|
||||
|
||||
static constexpr bool is_num(char ch);
|
||||
static bool is_alphabetic(char ch);
|
||||
};
|
23
tests/Method_test.cpp
Normal file
23
tests/Method_test.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
#include "pch.h"
|
||||
|
||||
#define protected public
|
||||
#define private public
|
||||
|
||||
#include "../QRCodeLibrary/Method.hpp"
|
||||
|
||||
TEST(MethodTests, DetermitesStringMethod) {
|
||||
EXPECT_EQ(Method::determite_method("123"), QRCodeMethod::Numeric);
|
||||
EXPECT_EQ(Method::determite_method("ABC"), QRCodeMethod::Alphabetic);
|
||||
EXPECT_EQ(Method::determite_method("ghfjghfj gfjhgd"), QRCodeMethod::Byte);
|
||||
}
|
||||
|
||||
TEST(MethodTests, ChecksNumber) {
|
||||
EXPECT_TRUE(Method::is_num('1'));
|
||||
EXPECT_TRUE(Method::is_num('5'));
|
||||
EXPECT_TRUE(Method::is_num('0'));
|
||||
|
||||
EXPECT_FALSE(Method::is_num('a'));
|
||||
EXPECT_FALSE(Method::is_num('j'));
|
||||
EXPECT_FALSE(Method::is_num('\n'));
|
||||
EXPECT_FALSE(Method::is_num('_'));
|
||||
}
|
19
tests/QRCode_test.cpp
Normal file
19
tests/QRCode_test.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
#include "pch.h"
|
||||
|
||||
#define protected public
|
||||
#define private public
|
||||
|
||||
#include "../QRCodeLibrary/QRCode.hpp"
|
||||
|
||||
class QRCodeConstructorMock : public QRCode {
|
||||
public:
|
||||
template <typename ...Parameters>
|
||||
QRCodeConstructorMock(Parameters ...params) {};
|
||||
};
|
||||
TEST(QRCodeTests, ConstructsClass) {
|
||||
QRCode qr("TEST");
|
||||
|
||||
EXPECT_EQ(qr.input, "TEST");
|
||||
EXPECT_EQ(qr.corr_lvl, CorrectionLevel::Q);
|
||||
EXPECT_EQ(qr.method, QRCodeMethod::Alphabetic);
|
||||
}
|
4
tests/packages.config
Normal file
4
tests/packages.config
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn" version="1.8.1.4" targetFramework="native" />
|
||||
</packages>
|
5
tests/pch.cpp
Normal file
5
tests/pch.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
//
|
||||
// pch.cpp
|
||||
//
|
||||
|
||||
#include "pch.h"
|
7
tests/pch.h
Normal file
7
tests/pch.h
Normal file
@ -0,0 +1,7 @@
|
||||
//
|
||||
// pch.h
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "gtest/gtest.h"
|
129
tests/tests.vcxproj
Normal file
129
tests/tests.vcxproj
Normal file
@ -0,0 +1,129 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.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>
|
||||
<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">
|
||||
<ProjectGuid>{96cdaf28-007a-4900-b24e-e21676713543}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<WindowsTargetPlatformVersion>10.0.19041.0</WindowsTargetPlatformVersion>
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings" />
|
||||
<ImportGroup Label="Shared" />
|
||||
<ImportGroup Label="PropertySheets" />
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<ItemGroup>
|
||||
<ClInclude Include="pch.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Method_test.cpp" />
|
||||
<ClCompile Include="QRCode_test.cpp" />
|
||||
<ClCompile Include="pch.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\QRCodeLibrary\QRCodeLibrary.vcxproj">
|
||||
<Project>{b1126767-cdf7-4831-8b08-85bf457db4e2}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemDefinitionGroup />
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
<Import Project="..\packages\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1.4\build\native\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.targets" Condition="Exists('..\packages\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1.4\build\native\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.targets')" />
|
||||
</ImportGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>X64;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<PreprocessorDefinitions>X64;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1.4\build\native\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1.4\build\native\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.targets'))" />
|
||||
</Target>
|
||||
</Project>
|
Loading…
x
Reference in New Issue
Block a user