diff --git a/Demo/main.cpp b/Demo/main.cpp index f26cdf6..2d0eea1 100644 --- a/Demo/main.cpp +++ b/Demo/main.cpp @@ -1,15 +1,19 @@ #include #include -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) -#include +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) +#define IS_WINDOWS +#endif + +#ifdef IS_WINDOWS +#include #endif #include "../QRCodeLibrary/QRCode.hpp" using namespace std; -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) +#ifdef IS_WINDOWS std::string cp1251_to_utf8(const char* str) { std::string res; @@ -49,18 +53,19 @@ string str_of(unsigned k, const string& input) { #endif int main() { -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) +#ifdef IS_WINDOWS SetConsoleCP(1251); #endif - string input, buff; + string input; + string buff; while (getline(cin, buff)) { input += buff + '\n'; } input.pop_back(); -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) +#ifdef IS_WINDOWS input = cp1251_to_utf8(input.c_str()); #endif @@ -70,7 +75,7 @@ int main() { #define SQUARE_WIDTH 2 -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) +#ifdef IS_WINDOWS const string long_sep = string((res.size() + 8) * SQUARE_WIDTH, 219), short_sep = string(4 * SQUARE_WIDTH, 219), black = string(SQUARE_WIDTH, ' '), @@ -106,7 +111,7 @@ int main() { for (int i = 0; i < 4; i++) cout << long_sep << endl; -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) +#ifdef IS_WINDOWS system("pause"); #endif -} \ No newline at end of file +} diff --git a/QRCodeLibrary/BitArray.cpp b/QRCodeLibrary/BitArray.cpp index 8a172c2..a287b24 100644 --- a/QRCodeLibrary/BitArray.cpp +++ b/QRCodeLibrary/BitArray.cpp @@ -8,7 +8,7 @@ bool BitArray::get(unsigned index) const { if (index >= size) throw std::out_of_range("No such element in array"); - return (v[index / 8] >> (8 - 1 - index % 8)) & 1; + return (v[index / 8] >> (8 - index % 8 - 1)) & 1; } BitArray::operator std::string() const @@ -16,7 +16,7 @@ BitArray::operator std::string() const std::stringstream res; for (unsigned i = 0; i < size; i++) - res << static_cast((*this).get(i)); + res << static_cast(get(i)); return res.str(); } @@ -25,32 +25,31 @@ void BitArray::set(unsigned index, bool val) { if (index >= size) throw std::out_of_range("No such element in array"); - if (val) - v[index / 8] |= 1 << (8 - 1 - index % 8); + if (val == 1) + v[index / 8] |= 1 << (8 - index % 8 - 1); else - v[index / 8] &= ~(1 << (8 - 1 - index % 8)); + v[index / 8] &= ~(1 << (8 - index % 8 - 1)); } unsigned BitArray::set(unsigned index, int32_t val, unsigned size) { if (index >= this->size) throw std::out_of_range("No such element in array"); - unsigned shift = index % 8, written = 0; + unsigned shift = index % 8; + unsigned written = 0; if (size > this->size - index) throw std::out_of_range("Number of bits to write from this index is more than BitArray capability"); - index /= 8; + for (int i = index / 8; written < size; i++) { + int input_shift = size - (8 - shift) - written; // right shift for written data + int right_rem = input_shift < 0 ? -input_shift : 0; // how many bits should I take from right side of original byte - while (written < size) { - int input_shift = size - (8 - shift) - written; - int right_rem = input_shift < 0 ? -input_shift : 0; - - v[index] = ((v[index] >> (8 - shift)) << (8 - shift)) | - (unsigned char)(((1 << (8 - shift)) - 1) & ((input_shift >= 0) ? (val >> input_shift) : (val << -input_shift))) | - (v[index] & ((1 << right_rem) - 1)); + v[i] = (v[i] & (-1 << (8 - shift))) | + (((1 << (8 - shift)) - 1) & + ((input_shift >= 0) ? (val >> input_shift) : (val << -input_shift))) | + (v[i] & ((1 << right_rem) - 1)); written += 8 - shift; - index++; shift = 0; } diff --git a/QRCodeLibrary/BitArray.hpp b/QRCodeLibrary/BitArray.hpp index 010266b..032a5af 100644 --- a/QRCodeLibrary/BitArray.hpp +++ b/QRCodeLibrary/BitArray.hpp @@ -8,7 +8,7 @@ using namespace std; -constexpr unsigned ceil_div(unsigned a, unsigned b) { +constexpr static unsigned ceil_div(unsigned a, unsigned b) { if (b == 0) throw runtime_error("Dividion by zero not possible"); return a / b + (a % b > 0); } @@ -17,15 +17,16 @@ class BitArray { public: BitArray(unsigned size_ = 0) : size{ size_ }, v(ceil_div(size_, 8), 0) {}; - BitArray(const vector& input) : size(to_U(input.size()) * 8), v{ input } {}; + BitArray(const byte_list& input) : size(to_U(input.size()) * 8), v{ input } {}; operator std::string() const; - unsigned size; - vector v; + unsigned size; // array size in bits + byte_list v; bool get(unsigned index) const; void set(unsigned index, bool val); + // sets least size bits of val starting from index unsigned set(unsigned index, int32_t val, unsigned size); void resize(unsigned new_size); diff --git a/QRCodeLibrary/DataBlocks.cpp b/QRCodeLibrary/DataBlocks.cpp index 566c997..b3d25d9 100644 --- a/QRCodeLibrary/DataBlocks.cpp +++ b/QRCodeLibrary/DataBlocks.cpp @@ -4,20 +4,19 @@ #include "Tables.hpp" #include "utils.hpp" -vector& DataBlocks::compose_joined_data_and_EC_blocks() +DataBlocks::DataBlocks(const byte_list& e_data_, CorrectionLevel corr_lvl_, char version_) : e_data{ e_data_ }, corr_lvl{ corr_lvl_ }, version{ version_ } { vector>data_block_sizes; divide_to_blocks(data_block_sizes, to_U(e_data.size()), Tables::data_blocks_number.at(corr_lvl).at(version)); unsigned EC_bytes_number = Tables::correction_bytes_num.at(corr_lvl).at(version); - vector> EC_blocks(data_block_sizes.size(), vector()); + vector EC_blocks(data_block_sizes.size(), byte_list()); + for (unsigned i = 0; i < data_block_sizes.size(); i++) compose_EC_bytes(EC_blocks[i], e_data.cbegin() + data_block_sizes[i].second, EC_bytes_number, data_block_sizes[i].first); join_data_and_EC_blocks(data, e_data, data_block_sizes, EC_blocks, EC_bytes_number); - - return data; } void DataBlocks::divide_to_blocks(vector>& db_sizes, unsigned data_size, unsigned db_number) @@ -33,14 +32,16 @@ void DataBlocks::divide_to_blocks(vector>& db_sizes, un } } -void DataBlocks::compose_EC_bytes(vector& res, const vector::const_iterator& src, unsigned corr_bytes_num, unsigned db_size) +void DataBlocks::compose_EC_bytes(byte_list& res, const byte_list::const_iterator& src, unsigned corr_bytes_num, unsigned db_size) { res.reserve(max(db_size, corr_bytes_num)); res.insert(res.end(), src, src + db_size); res.resize(res.capacity(), 0); + auto gen_poly = Tables::reed_solomon_generative_polynomial.at(corr_bytes_num); + for (unsigned j = 0; j < db_size; j++) { - unsigned char A = res[0]; + unsigned char A = res[0]; res.erase(res.begin()); res.push_back(0); @@ -50,7 +51,7 @@ void DataBlocks::compose_EC_bytes(vector& res, const vector& res, const vector& e_data, const vector>& db_sizes, const vector>& ec_codes, unsigned ec_bytes_number) +void DataBlocks::join_data_and_EC_blocks(byte_list& res, const byte_list& e_data, const vector>& db_sizes, const vector& ec_codes, unsigned ec_bytes_number) { - if (ec_codes.size()) - res.reserve(e_data.size() + ec_codes.at(0).size() * ec_codes.size()); - else - res.reserve(e_data.size()); + res.reserve(e_data.size() + ec_codes.at(0).size() * ec_codes.size()); for (unsigned i = 0; i < db_sizes[db_sizes.size() - 1].first; i++) for (unsigned j = 0; j < db_sizes.size(); j++) if (i < db_sizes[j].first) res.push_back(e_data[get_db_byte_index(j, i, db_sizes)]); - if (ec_codes.size()) - for (unsigned i = 0; i < ec_bytes_number; i++) - for (unsigned j = 0; j < ec_codes.size(); j++) - res.push_back(ec_codes[j][i]); + for (unsigned i = 0; i < ec_bytes_number; i++) + for (unsigned j = 0; j < ec_codes.size(); j++) + res.push_back(ec_codes[j][i]); } diff --git a/QRCodeLibrary/DataBlocks.hpp b/QRCodeLibrary/DataBlocks.hpp index 90c81f4..8cdde17 100644 --- a/QRCodeLibrary/DataBlocks.hpp +++ b/QRCodeLibrary/DataBlocks.hpp @@ -10,19 +10,19 @@ using namespace std; class DataBlocks { public: - DataBlocks(const vector& e_data_, CorrectionLevel corr_lvl_, char version_) : e_data{ e_data_ }, corr_lvl{ corr_lvl_ }, version{ version_ } {}; + DataBlocks(const byte_list& e_data_, CorrectionLevel corr_lvl_, char version_); - vector& compose_joined_data_and_EC_blocks(); + byte_list& get_joined_data_and_EC_blocks() { return data; }; static void divide_to_blocks(vector>& db_sizes, unsigned data_size, unsigned db_number); - static void compose_EC_bytes(vector& res, const vector::const_iterator& src, unsigned corr_bytes_num, unsigned db_size); - static void join_data_and_EC_blocks(vector&res, const vector& e_data, const vector>& db_sizes, const vector>& ec_codes, unsigned ec_bytes_number); + static void compose_EC_bytes(byte_list& res, const byte_list::const_iterator& src, unsigned corr_bytes_num, unsigned db_size); + static void join_data_and_EC_blocks(byte_list&res, const byte_list& e_data, const vector>& db_sizes, const vector& ec_codes, unsigned ec_bytes_number); private: - const vector& e_data; + const byte_list& e_data; CorrectionLevel corr_lvl; char version; - vector data; + byte_list data; }; diff --git a/QRCodeLibrary/Encoder.cpp b/QRCodeLibrary/Encoder.cpp index a3dc2a0..118dbf1 100644 --- a/QRCodeLibrary/Encoder.cpp +++ b/QRCodeLibrary/Encoder.cpp @@ -6,7 +6,7 @@ #include -BitArray& Encoder::encode() +Encoder::Encoder(const byte_list& input_, CorrectionLevel corr_lvl_, QRCodeMethod method_, char version_): input{ input_ }, corr_lvl{ corr_lvl_ }, method{ method_ }, version{ version_ } { unsigned encoded_bit_num = calculate_encoded_input_size(to_U(input.size()), method); unsigned metadata_bit_num = calculate_metadata_size(method, ((version < 0) ? 0 : version)); @@ -27,8 +27,6 @@ BitArray& Encoder::encode() encode_input(metadata_bit_num); pad_data(e, metadata_bit_num + encoded_bit_num); - - return e; } char Encoder::determite_version(unsigned size, CorrectionLevel corr_lvl) @@ -65,17 +63,20 @@ void Encoder::write_metadata(unsigned input_size, unsigned input_bits_amount_siz void Encoder::encode_numeric(const string& input, BitArray& out, unsigned offset) { + int bin; for (unsigned i = 0; i < input.size() / 3; i++) { - int bin = stoi(input.substr(i * 3, 3)); + bin = stoi(input.substr(i * 3, 3)); out.set(offset + i * 10, bin, 10); } if (input.size() % 3 == 2) { - int bin = stoi(input.substr(input.size() - 2, 2)); + bin = stoi(input.substr(input.size() - 2, 2)); out.set(offset + to_U(input.size()) / 3 * 10, bin, 7); } - else if (input.size() % 3 == 1) - out.set(offset + to_U(input.size()) / 3 * 10, input[input.size() - 1] - '0', 4); + else if (input.size() % 3 == 1) { + bin = input[input.size() - 1] - '0'; + out.set(offset + to_U(input.size()) / 3 * 10, bin, 4); + } } void Encoder::encode_alphabetic(const string& input, BitArray& out, unsigned offset) @@ -118,7 +119,7 @@ void Encoder::pad_data(BitArray& arr, unsigned bits_written) arr.v[i] = ((i - encoded_bytes) % 2 == 0) ? 0b11101100 : 0b00010001; } -BitArray Encoder::get_data() const +BitArray& Encoder::get_data() { if (e.size == 0) throw std::runtime_error("Data is not calculated yet"); diff --git a/QRCodeLibrary/Encoder.hpp b/QRCodeLibrary/Encoder.hpp index aa12a6e..3b06562 100644 --- a/QRCodeLibrary/Encoder.hpp +++ b/QRCodeLibrary/Encoder.hpp @@ -13,9 +13,7 @@ using namespace std; class Encoder { public: - Encoder(const byte_list& input_, CorrectionLevel corr_lvl_ = CorrectionLevel::M, QRCodeMethod method_ = QRCodeMethod::Dynamic, char version_ = -1) : input{ input_ }, corr_lvl{ corr_lvl_ }, method{ method_ }, version{ version_ } {}; - - BitArray& encode(); + Encoder(const byte_list& input_, CorrectionLevel corr_lvl_ = CorrectionLevel::M, QRCodeMethod method_ = QRCodeMethod::Dynamic, char version_ = -1); static char determite_version(unsigned size, CorrectionLevel corr_lvl); @@ -45,7 +43,7 @@ public: static void pad_data(BitArray& arr, unsigned bits_written); constexpr char get_version() const { return version; }; - BitArray get_data() const; + BitArray& get_data(); private: static constexpr unsigned char encode_char(char ch); diff --git a/QRCodeLibrary/QRCode.cpp b/QRCodeLibrary/QRCode.cpp index 17b51f0..ef23f98 100644 --- a/QRCodeLibrary/QRCode.cpp +++ b/QRCodeLibrary/QRCode.cpp @@ -14,19 +14,15 @@ QRCode::QRCode(const byte_list& input_, CorrectionLevel corr_lvl_, QRCodeMethod else method = QRCodeMethod::Byte; } - Encoder encoder(input, corr_lvl, method, version); - const BitArray& encoded_data = encoder.encode(); + const BitArray& encoded_data = encoder.get_data(); version = encoder.get_version(); DataBlocks data_blocks(encoded_data.v, corr_lvl, version); - const BitArray final_message(data_blocks.compose_joined_data_and_EC_blocks()); + const BitArray final_message(data_blocks.get_joined_data_and_EC_blocks()); matrix.set_version(version); - matrix.draw_patterns(); - matrix.place_metadata(corr_lvl, mask_n); - matrix.place_data(final_message, mask_n); } diff --git a/QRCodeLibrary/QRMatrix.cpp b/QRCodeLibrary/QRMatrix.cpp index f6b5ffd..d08ad87 100644 --- a/QRCodeLibrary/QRMatrix.cpp +++ b/QRCodeLibrary/QRMatrix.cpp @@ -48,6 +48,7 @@ void QRMatrix::draw_finder_square_separators() void QRMatrix::draw_alignment_patters() { auto& coordinates = Tables::alignment_patterns_coordinates.at(version); + for (unsigned i = 0; i < coordinates.size(); i++) { unsigned s = i, e = to_U(coordinates.size()); if (coordinates[i] == 6) @@ -89,6 +90,7 @@ void QRMatrix::place_metadata(CorrectionLevel corr_lvl, unsigned char mask_n) { if (version >= 6) { const auto& v_codes = Tables::version_codes.at(version-6); + for (unsigned i = 0; i < 3; i++) for (unsigned j = 0; j < 6; j++) { set(to_U(c.size()) - 11 + i, j, (v_codes.at(i) >> (6 - 1 - j)) & 1); @@ -97,7 +99,6 @@ void QRMatrix::place_metadata(CorrectionLevel corr_lvl, unsigned char mask_n) } unsigned code = Tables::corr_lvl_and_mask_codes.at(corr_lvl)[mask_n]; - unsigned y1 = 8, y2 = to_U(c.size()) - 1, x1 = 0, x2 = 8; for (unsigned i = 0; i < 15; i++) { set(y1, x1, (code >> (15 - 1 - i)) & 1); @@ -108,13 +109,16 @@ void QRMatrix::place_metadata(CorrectionLevel corr_lvl, unsigned char mask_n) if (x1 == 6) x1++; } else { - if (x1 == 8) y1--; + y1--; if (y1 == 6) y1--; } - if (y2 > c.size() - 8) y2--; - if (y2 == to_U(c.size()) - 8) { y2 = 8; x2 = to_U(c.size()) - 8; } - else if (y2 == 8) + if (y2 > c.size() - 8) + y2--; + if (y2 == to_U(c.size()) - 8) { + y2 = 8; + x2 = to_U(c.size()) - 8; + } else if (y2 == 8) x2++; } @@ -133,7 +137,7 @@ void QRMatrix::place_data(const BitArray& data, unsigned char mask_n) const auto& mask = Tables::mask_functions.at(mask_n); while (true) { - if (x == 6) + if (x == 6) // skip vertical sync line x--; if (get(y, x) == Trit::EMPTY) { @@ -144,7 +148,7 @@ void QRMatrix::place_data(const BitArray& data, unsigned char mask_n) else set(y, x, !mask(y, x)); } - if (horiz_dir) + if (horiz_dir) x--; else { x++; @@ -158,7 +162,7 @@ void QRMatrix::place_data(const BitArray& data, unsigned char mask_n) } else { if (y == c.size() - 1) { - if (x == 1) // т.к. сделали шаг "вправо" на строчке 130 + if (x == 1) // x is already shifted on line 162 (x++) so use a bigger one break; x -= 2; diff --git a/QRCodeLibrary/Tables.hpp b/QRCodeLibrary/Tables.hpp index a16df0d..d1333b8 100644 --- a/QRCodeLibrary/Tables.hpp +++ b/QRCodeLibrary/Tables.hpp @@ -37,6 +37,7 @@ namespace Tables { { QRCodeMethod::Alphabetic, 0b0010 }, { QRCodeMethod::Byte, 0b0100 } }; + static const std::map, 3>>data_amount_lengths{ { QRCodeMethod::Numeric, {{ {0, 10}, {9, 12}, {26, 14} }} }, { QRCodeMethod::Alphabetic, {{ {0, 9}, {9, 11}, {26, 13} }} }, diff --git a/QRCodeLibrary/TritMatrix.cpp b/QRCodeLibrary/TritMatrix.cpp index 0141112..252d73f 100644 --- a/QRCodeLibrary/TritMatrix.cpp +++ b/QRCodeLibrary/TritMatrix.cpp @@ -17,7 +17,7 @@ void TritMatrix::set(unsigned y, unsigned x, int32_t val, unsigned char size) { if (x + size > c.at(0).size()) throw std::out_of_range("Value to write is out of matrix range"); for (unsigned char i = 0; i < size; i++) - set(y, x + i, ((val >> (size - 1 - i)) & 1) ? Trit::T : Trit::F); + set(y, x + i, (val >> (size - 1 - i)) & 1); } void TritMatrix::set(unsigned y, unsigned x, bool val) @@ -50,31 +50,6 @@ string TritMatrix::to_ascii(char black, char white, char empty) const return res; } -string TritMatrix::to_string() const -{ - string res; - - for (unsigned i = 0; i < c.size(); i++) { - for (unsigned j = 0; j < c.at(0).size(); j++) - switch (c[i][j]) - { - case Trit::T: - res.push_back('1'); - break; - case Trit::F: - res.push_back('0'); - break; - case Trit::EMPTY: - res.push_back('E'); - break; - } - if (i != c.size() - 1) - res.push_back('\n'); - } - - return res; -} - void TritMatrix::resize(unsigned width, unsigned height) { c.resize(height); diff --git a/QRCodeLibrary/TritMatrix.hpp b/QRCodeLibrary/TritMatrix.hpp index 26c9c07..0569faf 100644 --- a/QRCodeLibrary/TritMatrix.hpp +++ b/QRCodeLibrary/TritMatrix.hpp @@ -26,7 +26,7 @@ public: void resize(unsigned width, unsigned height); string to_ascii(char black = '#', char white = ' ', char empty = 'E') const; - string to_string() const; + string to_string() const { return to_ascii('1', '0', 'E'); }; vector> to_vector() const { return c; }; protected: diff --git a/tests/DataBlocks_test.cpp b/tests/DataBlocks_test.cpp index 5c5589d..5993f5c 100644 --- a/tests/DataBlocks_test.cpp +++ b/tests/DataBlocks_test.cpp @@ -15,25 +15,25 @@ TEST(DataBlocksTests, ComposesSizesOfDatablocks) { } TEST(DataBlocksTests, GeneratesECBytes) { - const vector input{ 64, 196, 132, 84, 196, 196, 242, 194, 4, 132, 20, 37, 34, 16, 236, 17 }; - vector tmp; + const byte_list input{ 64, 196, 132, 84, 196, 196, 242, 194, 4, 132, 20, 37, 34, 16, 236, 17 }; + byte_list tmp; DataBlocks::compose_EC_bytes(tmp, input.cbegin(), 28, 16); - const vector res{ 16, 85, 12, 231, 54, 54, 140, 70, 118, 84, 10, 174, 235, 197, 99, 218, 12, 254, 246, 4, 190, 56, 39, 217, 115, 189, 193, 24 }; + const byte_list res{ 16, 85, 12, 231, 54, 54, 140, 70, 118, 84, 10, 174, 235, 197, 99, 218, 12, 254, 246, 4, 190, 56, 39, 217, 115, 189, 193, 24 }; EXPECT_EQ(tmp, res); } TEST(DataBlocksTests, JoinsDataAndECBlocks) { - vectorjoined; - const vectore_data{ + byte_list joined; + const byte_list e_data{ 67, 85, 70, 134, 87, 38, 85, 194, 119, 50, 6, 18, 6, 103, 38, 246, 246, 66, 7, 118, 134, 242, 7, 38, 86, 22, 198, 199, 146, 6, 182, 230, 247, 119, 50, 7, 118, 134, 87, 38, 82, 6, 134, 151, 50, 7, 70, 247, 118, 86, 194, 6, 151, 50, 16, 236, 17, 236, 17, 236, 17, 236 }; const vector> d_b_sizes{ {15, 0}, {15, 15}, {16, 30}, {16, 46} }; - const vector> EC_blocks{ + const vector EC_blocks{ { 213, 199, 11, 45, 115, 247, 241, 223, 229, 248, 154, 117, 154, 111, 86, 161, 111, 39 }, { 87, 204, 96, 60, 202, 182, 124, 157, 200, 134, 27, 129, 209, 17, 163, 163, 120, 133 }, { 148, 116, 177, 212, 76, 133, 75, 242, 238, 76, 195, 230, 189, 10, 108, 240, 192, 141 }, @@ -42,7 +42,7 @@ TEST(DataBlocksTests, JoinsDataAndECBlocks) { DataBlocks::join_data_and_EC_blocks(joined, e_data, d_b_sizes, EC_blocks, 18); - const vectorres{ + const byte_list res{ 67, 246, 182, 70, 85, 246, 230, 247, 70, 66, 247, 118, 134, 7, 119, 86, 87, 118, 50, 194, 38, 134, 7, 6, 85, 242, 118, 151, 194, 7, 134, 50, 119, 38, 87, 16, 50, 86, 38, 236, 6, 22, 82, 17, 18, @@ -57,7 +57,7 @@ TEST(DataBlocksTests, JoinsDataAndECBlocks) { } TEST(DataBlocksTests, ComposesJoinedDataAndECBlocks) { - const vectore_data{ + const byte_list e_data{ 67, 85, 70, 134, 87, 38, 85, 194, 119, 50, 6, 18, 6, 103, 38, 246, 246, 66, 7, 118, 134, 242, 7, 38, 86, 22, 198, 199, 146, 6, 182, 230, 247, 119, 50, 7, 118, 134, 87, 38, 82, 6, 134, 151, 50, 7, @@ -66,7 +66,7 @@ TEST(DataBlocksTests, ComposesJoinedDataAndECBlocks) { DataBlocks db(e_data, CorrectionLevel::Q, 4); - const vector joined{ + const byte_list joined{ 67, 246, 182, 70, 85, 246, 230, 247, 70, 66, 247, 118, 134, 7, 119, 86, 87, 118, 50, 194, 38, 134, 7, 6, 85, 242, 118, 151, 194, 7, 134, 50, 119, 38, 87, 16, 50, 86, 38, 236, 6, 22, 82, 17, 18, @@ -78,5 +78,5 @@ TEST(DataBlocksTests, ComposesJoinedDataAndECBlocks) { 108, 131, 161, 163, 240, 32, 111, 120, 192, 178, 39, 133, 141, 236 }; - EXPECT_EQ(db.compose_joined_data_and_EC_blocks(), joined); + EXPECT_EQ(db.get_joined_data_and_EC_blocks(), joined); } \ No newline at end of file diff --git a/tests/Encoder_test.cpp b/tests/Encoder_test.cpp index b48ae3c..939d635 100644 --- a/tests/Encoder_test.cpp +++ b/tests/Encoder_test.cpp @@ -106,14 +106,11 @@ TEST(EncoderTests, PadsData) { TEST(EncoderTests, EncodesInput) { Encoder e1(str_to_bytes("8675309"), CorrectionLevel::Q, QRCodeMethod::Numeric); - e1.encode(); EXPECT_EQ(std::string(e1.get_data()), "00010000000111110110001110000100101001001110110000010001111011000001000111101100000100011110110000010001"); Encoder e2(str_to_bytes("HELLO WORLD"), CorrectionLevel::M, QRCodeMethod::Alphabetic); - e2.encode(); EXPECT_EQ(std::string(e2.get_data()), "00100000010110110000101101111000110100010111001011011100010011010100001101000000111011000001000111101100000100011110110000010001"); Encoder e3(str_to_bytes(u8"Дмитрий Шишков"), CorrectionLevel::Q, QRCodeMethod::Byte); - e3.encode(); EXPECT_EQ(std::string(e3.get_data()), "01000001101111010000100101001101000010111100110100001011100011010001100000101101000110000000110100001011100011010000101110010010000011010000101010001101000010111000110100011000100011010000101110101101000010111110110100001011001000001110110000010001111011000001000111101100"); } \ No newline at end of file