diff --git a/QRCodeLibrary.sln b/QRCodeLibrary.sln
index 4d730e7..7598357 100644
--- a/QRCodeLibrary.sln
+++ b/QRCodeLibrary.sln
@@ -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
diff --git a/QRCodeLibrary/Method.cpp b/QRCodeLibrary/Method.cpp
new file mode 100644
index 0000000..b573028
--- /dev/null
+++ b/QRCodeLibrary/Method.cpp
@@ -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();
+}
diff --git a/QRCodeLibrary/QRCode.cpp b/QRCodeLibrary/QRCode.cpp
index 3e86d39..7206c7c 100644
--- a/QRCodeLibrary/QRCode.cpp
+++ b/QRCodeLibrary/QRCode.cpp
@@ -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);
}
diff --git a/QRCodeLibrary/QRCodeLibrary.vcxproj b/QRCodeLibrary/QRCodeLibrary.vcxproj
index cca62a9..3ea7582 100644
--- a/QRCodeLibrary/QRCodeLibrary.vcxproj
+++ b/QRCodeLibrary/QRCodeLibrary.vcxproj
@@ -152,11 +152,13 @@
-
+
+
+
Create
Create
@@ -164,6 +166,7 @@
Create
+
diff --git a/QRCodeLibrary/QRCodeLibrary.vcxproj.filters b/QRCodeLibrary/QRCodeLibrary.vcxproj.filters
index 31ba2de..cf9eef8 100644
--- a/QRCodeLibrary/QRCodeLibrary.vcxproj.filters
+++ b/QRCodeLibrary/QRCodeLibrary.vcxproj.filters
@@ -24,7 +24,10 @@
Header Files
-
+
+ Header Files
+
+
Header Files
@@ -35,5 +38,11 @@
Source Files
+
+ Source Files
+
+
+ Source Files
+
\ No newline at end of file
diff --git a/QRCodeLibrary/Tables.cpp b/QRCodeLibrary/Tables.cpp
new file mode 100644
index 0000000..7868619
--- /dev/null
+++ b/QRCodeLibrary/Tables.cpp
@@ -0,0 +1,11 @@
+#include "pch.h"
+
+#include "Tables.hpp"
+
+const std::array 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', ' ', '$', '%', '*',
+ '+', '-', '.', '/', ':'
+};
\ No newline at end of file
diff --git a/QRCodeLibrary/Tables.hpp b/QRCodeLibrary/Tables.hpp
new file mode 100644
index 0000000..a1f88bb
--- /dev/null
+++ b/QRCodeLibrary/Tables.hpp
@@ -0,0 +1,8 @@
+#pragma once
+
+#include
+
+class Tables {
+public:
+ static const std::arrayalphabetic;
+};
\ No newline at end of file
diff --git a/QRCodeLibrary/method.hpp b/QRCodeLibrary/method.hpp
index 912e775..d3a7d5d 100644
--- a/QRCodeLibrary/method.hpp
+++ b/QRCodeLibrary/method.hpp
@@ -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);
};
\ No newline at end of file
diff --git a/tests/Method_test.cpp b/tests/Method_test.cpp
new file mode 100644
index 0000000..d9b6374
--- /dev/null
+++ b/tests/Method_test.cpp
@@ -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('_'));
+}
\ No newline at end of file
diff --git a/tests/QRCode_test.cpp b/tests/QRCode_test.cpp
new file mode 100644
index 0000000..fc961d3
--- /dev/null
+++ b/tests/QRCode_test.cpp
@@ -0,0 +1,19 @@
+#include "pch.h"
+
+#define protected public
+#define private public
+
+#include "../QRCodeLibrary/QRCode.hpp"
+
+class QRCodeConstructorMock : public QRCode {
+public:
+ template
+ 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);
+}
\ No newline at end of file
diff --git a/tests/packages.config b/tests/packages.config
new file mode 100644
index 0000000..434bb12
--- /dev/null
+++ b/tests/packages.config
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/tests/pch.cpp b/tests/pch.cpp
new file mode 100644
index 0000000..250fb27
--- /dev/null
+++ b/tests/pch.cpp
@@ -0,0 +1,5 @@
+//
+// pch.cpp
+//
+
+#include "pch.h"
diff --git a/tests/pch.h b/tests/pch.h
new file mode 100644
index 0000000..0572a70
--- /dev/null
+++ b/tests/pch.h
@@ -0,0 +1,7 @@
+//
+// pch.h
+//
+
+#pragma once
+
+#include "gtest/gtest.h"
diff --git a/tests/tests.vcxproj b/tests/tests.vcxproj
new file mode 100644
index 0000000..6328d6d
--- /dev/null
+++ b/tests/tests.vcxproj
@@ -0,0 +1,129 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Release
+ Win32
+
+
+ Debug
+ x64
+
+
+ Release
+ x64
+
+
+
+ {96cdaf28-007a-4900-b24e-e21676713543}
+ Win32Proj
+ 10.0.19041.0
+ Application
+ v142
+ Unicode
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Create
+ Create
+ Create
+ Create
+
+
+
+
+ {b1126767-cdf7-4831-8b08-85bf457db4e2}
+
+
+
+
+
+
+
+
+
+
+
+
+ Use
+ pch.h
+ Disabled
+ WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ EnableFastChecks
+ MultiThreadedDebugDLL
+ Level3
+
+
+ true
+ Console
+
+
+
+
+ Use
+ pch.h
+ Disabled
+ X64;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ EnableFastChecks
+ MultiThreadedDebugDLL
+ Level3
+
+
+ true
+ Console
+
+
+
+
+ Use
+ pch.h
+ WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ MultiThreadedDLL
+ Level3
+ ProgramDatabase
+
+
+ true
+ Console
+ true
+ true
+
+
+
+
+ Use
+ pch.h
+ X64;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ MultiThreadedDLL
+ Level3
+ ProgramDatabase
+
+
+ true
+ Console
+ true
+ true
+
+
+
+
+ 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}.
+
+
+
+
\ No newline at end of file