15317bbafSopenharmony_ci/*
25317bbafSopenharmony_ci * QR Code generator test suite (C)
35317bbafSopenharmony_ci *
45317bbafSopenharmony_ci * When compiling this program, the library qrcodegen.c needs QRCODEGEN_TEST
55317bbafSopenharmony_ci * to be defined. Run this command line program with no arguments.
65317bbafSopenharmony_ci *
75317bbafSopenharmony_ci * Copyright (c) Project Nayuki. (MIT License)
85317bbafSopenharmony_ci * https://www.nayuki.io/page/qr-code-generator-library
95317bbafSopenharmony_ci *
105317bbafSopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a copy of
115317bbafSopenharmony_ci * this software and associated documentation files (the "Software"), to deal in
125317bbafSopenharmony_ci * the Software without restriction, including without limitation the rights to
135317bbafSopenharmony_ci * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
145317bbafSopenharmony_ci * the Software, and to permit persons to whom the Software is furnished to do so,
155317bbafSopenharmony_ci * subject to the following conditions:
165317bbafSopenharmony_ci * - The above copyright notice and this permission notice shall be included in
175317bbafSopenharmony_ci *   all copies or substantial portions of the Software.
185317bbafSopenharmony_ci * - The Software is provided "as is", without warranty of any kind, express or
195317bbafSopenharmony_ci *   implied, including but not limited to the warranties of merchantability,
205317bbafSopenharmony_ci *   fitness for a particular purpose and noninfringement. In no event shall the
215317bbafSopenharmony_ci *   authors or copyright holders be liable for any claim, damages or other
225317bbafSopenharmony_ci *   liability, whether in an action of contract, tort or otherwise, arising from,
235317bbafSopenharmony_ci *   out of or in connection with the Software or the use or other dealings in the
245317bbafSopenharmony_ci *   Software.
255317bbafSopenharmony_ci */
265317bbafSopenharmony_ci
275317bbafSopenharmony_ci#include <assert.h>
285317bbafSopenharmony_ci#include <limits.h>
295317bbafSopenharmony_ci#include <stdbool.h>
305317bbafSopenharmony_ci#include <stddef.h>
315317bbafSopenharmony_ci#include <stdint.h>
325317bbafSopenharmony_ci#include <stdio.h>
335317bbafSopenharmony_ci#include <stdlib.h>
345317bbafSopenharmony_ci#include <string.h>
355317bbafSopenharmony_ci#include <time.h>
365317bbafSopenharmony_ci#include "qrcodegen.h"
375317bbafSopenharmony_ci
385317bbafSopenharmony_ci#define ARRAY_LENGTH(name)  (sizeof(name) / sizeof(name[0]))
395317bbafSopenharmony_ci
405317bbafSopenharmony_ci
415317bbafSopenharmony_ci// Global variables
425317bbafSopenharmony_cistatic int numTestCases = 0;
435317bbafSopenharmony_ci
445317bbafSopenharmony_ci
455317bbafSopenharmony_ci// Prototypes of private functions under test
465317bbafSopenharmony_ciextern const int8_t ECC_CODEWORDS_PER_BLOCK[4][41];
475317bbafSopenharmony_ciextern const int8_t NUM_ERROR_CORRECTION_BLOCKS[4][41];
485317bbafSopenharmony_civoid appendBitsToBuffer(unsigned int val, int numBits, uint8_t buffer[], int *bitLen);
495317bbafSopenharmony_civoid addEccAndInterleave(uint8_t data[], int version, enum qrcodegen_Ecc ecl, uint8_t result[]);
505317bbafSopenharmony_ciint getNumDataCodewords(int version, enum qrcodegen_Ecc ecl);
515317bbafSopenharmony_ciint getNumRawDataModules(int version);
525317bbafSopenharmony_civoid reedSolomonComputeDivisor(int degree, uint8_t result[]);
535317bbafSopenharmony_civoid reedSolomonComputeRemainder(const uint8_t data[], int dataLen, const uint8_t generator[], int degree, uint8_t result[]);
545317bbafSopenharmony_ciuint8_t reedSolomonMultiply(uint8_t x, uint8_t y);
555317bbafSopenharmony_civoid initializeFunctionModules(int version, uint8_t qrcode[]);
565317bbafSopenharmony_ciint getAlignmentPatternPositions(int version, uint8_t result[7]);
575317bbafSopenharmony_cibool getModuleBounded(const uint8_t qrcode[], int x, int y);
585317bbafSopenharmony_civoid setModuleBounded(uint8_t qrcode[], int x, int y, bool isDark);
595317bbafSopenharmony_civoid setModuleUnbounded(uint8_t qrcode[], int x, int y, bool isDark);
605317bbafSopenharmony_ciint calcSegmentBitLength(enum qrcodegen_Mode mode, size_t numChars);
615317bbafSopenharmony_ciint getTotalBits(const struct qrcodegen_Segment segs[], size_t len, int version);
625317bbafSopenharmony_ci
635317bbafSopenharmony_ci
645317bbafSopenharmony_ci/*---- Test cases ----*/
655317bbafSopenharmony_ci
665317bbafSopenharmony_cistatic void testAppendBitsToBuffer(void) {
675317bbafSopenharmony_ci	{
685317bbafSopenharmony_ci		uint8_t buf[1] = {0};
695317bbafSopenharmony_ci		int bitLen = 0;
705317bbafSopenharmony_ci		appendBitsToBuffer(0, 0, buf, &bitLen);
715317bbafSopenharmony_ci		assert(bitLen == 0);
725317bbafSopenharmony_ci		assert(buf[0] == 0);
735317bbafSopenharmony_ci		appendBitsToBuffer(1, 1, buf, &bitLen);
745317bbafSopenharmony_ci		assert(bitLen == 1);
755317bbafSopenharmony_ci		assert(buf[0] == 0x80);
765317bbafSopenharmony_ci		appendBitsToBuffer(0, 1, buf, &bitLen);
775317bbafSopenharmony_ci		assert(bitLen == 2);
785317bbafSopenharmony_ci		assert(buf[0] == 0x80);
795317bbafSopenharmony_ci		appendBitsToBuffer(5, 3, buf, &bitLen);
805317bbafSopenharmony_ci		assert(bitLen == 5);
815317bbafSopenharmony_ci		assert(buf[0] == 0xA8);
825317bbafSopenharmony_ci		appendBitsToBuffer(6, 3, buf, &bitLen);
835317bbafSopenharmony_ci		assert(bitLen == 8);
845317bbafSopenharmony_ci		assert(buf[0] == 0xAE);
855317bbafSopenharmony_ci		numTestCases++;
865317bbafSopenharmony_ci	}
875317bbafSopenharmony_ci	{
885317bbafSopenharmony_ci		uint8_t buf[6] = {0};
895317bbafSopenharmony_ci		int bitLen = 0;
905317bbafSopenharmony_ci		appendBitsToBuffer(16942, 16, buf, &bitLen);
915317bbafSopenharmony_ci		assert(bitLen == 16);
925317bbafSopenharmony_ci		assert(buf[0] == 0x42 && buf[1] == 0x2E && buf[2] == 0x00 && buf[3] == 0x00 && buf[4] == 0x00 && buf[5] == 0x00);
935317bbafSopenharmony_ci		appendBitsToBuffer(10, 7, buf, &bitLen);
945317bbafSopenharmony_ci		assert(bitLen == 23);
955317bbafSopenharmony_ci		assert(buf[0] == 0x42 && buf[1] == 0x2E && buf[2] == 0x14 && buf[3] == 0x00 && buf[4] == 0x00 && buf[5] == 0x00);
965317bbafSopenharmony_ci		appendBitsToBuffer(15, 4, buf, &bitLen);
975317bbafSopenharmony_ci		assert(bitLen == 27);
985317bbafSopenharmony_ci		assert(buf[0] == 0x42 && buf[1] == 0x2E && buf[2] == 0x15 && buf[3] == 0xE0 && buf[4] == 0x00 && buf[5] == 0x00);
995317bbafSopenharmony_ci		appendBitsToBuffer(26664, 15, buf, &bitLen);
1005317bbafSopenharmony_ci		assert(bitLen == 42);
1015317bbafSopenharmony_ci		assert(buf[0] == 0x42 && buf[1] == 0x2E && buf[2] == 0x15 && buf[3] == 0xFA && buf[4] == 0x0A && buf[5] == 0x00);
1025317bbafSopenharmony_ci		numTestCases++;
1035317bbafSopenharmony_ci	}
1045317bbafSopenharmony_ci}
1055317bbafSopenharmony_ci
1065317bbafSopenharmony_ci
1075317bbafSopenharmony_ci// Ported from the Java version of the code.
1085317bbafSopenharmony_cistatic uint8_t *addEccAndInterleaveReference(const uint8_t *data, int version, enum qrcodegen_Ecc ecl) {
1095317bbafSopenharmony_ci	// Calculate parameter numbers
1105317bbafSopenharmony_ci	size_t numBlocks = (size_t)NUM_ERROR_CORRECTION_BLOCKS[(int)ecl][version];
1115317bbafSopenharmony_ci	size_t blockEccLen = (size_t)ECC_CODEWORDS_PER_BLOCK[(int)ecl][version];
1125317bbafSopenharmony_ci	size_t rawCodewords = (size_t)getNumRawDataModules(version) / 8;
1135317bbafSopenharmony_ci	size_t numShortBlocks = numBlocks - rawCodewords % numBlocks;
1145317bbafSopenharmony_ci	size_t shortBlockLen = rawCodewords / numBlocks;
1155317bbafSopenharmony_ci
1165317bbafSopenharmony_ci	// Split data into blocks and append ECC to each block
1175317bbafSopenharmony_ci	uint8_t **blocks = malloc(numBlocks * sizeof(uint8_t*));
1185317bbafSopenharmony_ci	uint8_t *generator = malloc(blockEccLen * sizeof(uint8_t));
1195317bbafSopenharmony_ci	if (blocks == NULL || generator == NULL) {
1205317bbafSopenharmony_ci		perror("malloc");
1215317bbafSopenharmony_ci		exit(EXIT_FAILURE);
1225317bbafSopenharmony_ci	}
1235317bbafSopenharmony_ci	reedSolomonComputeDivisor((int)blockEccLen, generator);
1245317bbafSopenharmony_ci	for (size_t i = 0, k = 0; i < numBlocks; i++) {
1255317bbafSopenharmony_ci		uint8_t *block = malloc((shortBlockLen + 1) * sizeof(uint8_t));
1265317bbafSopenharmony_ci		if (block == NULL) {
1275317bbafSopenharmony_ci			perror("malloc");
1285317bbafSopenharmony_ci			exit(EXIT_FAILURE);
1295317bbafSopenharmony_ci		}
1305317bbafSopenharmony_ci		size_t datLen = shortBlockLen - blockEccLen + (i < numShortBlocks ? 0 : 1);
1315317bbafSopenharmony_ci		memcpy(block, &data[k], datLen * sizeof(uint8_t));
1325317bbafSopenharmony_ci		reedSolomonComputeRemainder(&data[k], (int)datLen, generator, (int)blockEccLen, &block[shortBlockLen + 1 - blockEccLen]);
1335317bbafSopenharmony_ci		k += datLen;
1345317bbafSopenharmony_ci		blocks[i] = block;
1355317bbafSopenharmony_ci	}
1365317bbafSopenharmony_ci	free(generator);
1375317bbafSopenharmony_ci
1385317bbafSopenharmony_ci	// Interleave (not concatenate) the bytes from every block into a single sequence
1395317bbafSopenharmony_ci	uint8_t *result = malloc(rawCodewords * sizeof(uint8_t));
1405317bbafSopenharmony_ci	if (result == NULL) {
1415317bbafSopenharmony_ci		perror("malloc");
1425317bbafSopenharmony_ci		exit(EXIT_FAILURE);
1435317bbafSopenharmony_ci	}
1445317bbafSopenharmony_ci	for (size_t i = 0, k = 0; i < shortBlockLen + 1; i++) {
1455317bbafSopenharmony_ci		for (size_t j = 0; j < numBlocks; j++) {
1465317bbafSopenharmony_ci			// Skip the padding byte in short blocks
1475317bbafSopenharmony_ci			if (i != shortBlockLen - blockEccLen || j >= numShortBlocks) {
1485317bbafSopenharmony_ci				result[k] = blocks[j][i];
1495317bbafSopenharmony_ci				k++;
1505317bbafSopenharmony_ci			}
1515317bbafSopenharmony_ci		}
1525317bbafSopenharmony_ci	}
1535317bbafSopenharmony_ci	for (size_t i = 0; i < numBlocks; i++)
1545317bbafSopenharmony_ci		free(blocks[i]);
1555317bbafSopenharmony_ci	free(blocks);
1565317bbafSopenharmony_ci	return result;
1575317bbafSopenharmony_ci}
1585317bbafSopenharmony_ci
1595317bbafSopenharmony_ci
1605317bbafSopenharmony_cistatic void testAddEccAndInterleave(void) {
1615317bbafSopenharmony_ci	for (int version = 1; version <= 40; version++) {
1625317bbafSopenharmony_ci		for (int ecl = 0; ecl < 4; ecl++) {
1635317bbafSopenharmony_ci			size_t dataLen = (size_t)getNumDataCodewords(version, (enum qrcodegen_Ecc)ecl);
1645317bbafSopenharmony_ci			uint8_t *pureData = malloc(dataLen * sizeof(uint8_t));
1655317bbafSopenharmony_ci			if (pureData == NULL) {
1665317bbafSopenharmony_ci				perror("malloc");
1675317bbafSopenharmony_ci				exit(EXIT_FAILURE);
1685317bbafSopenharmony_ci			}
1695317bbafSopenharmony_ci			for (size_t i = 0; i < dataLen; i++)
1705317bbafSopenharmony_ci				pureData[i] = (uint8_t)(rand() % 256);
1715317bbafSopenharmony_ci			uint8_t *expectOutput = addEccAndInterleaveReference(pureData, version, (enum qrcodegen_Ecc)ecl);
1725317bbafSopenharmony_ci
1735317bbafSopenharmony_ci			size_t dataAndEccLen = (size_t)getNumRawDataModules(version) / 8;
1745317bbafSopenharmony_ci			uint8_t *paddedData = malloc(dataAndEccLen * sizeof(uint8_t));
1755317bbafSopenharmony_ci			if (paddedData == NULL) {
1765317bbafSopenharmony_ci				perror("malloc");
1775317bbafSopenharmony_ci				exit(EXIT_FAILURE);
1785317bbafSopenharmony_ci			}
1795317bbafSopenharmony_ci			memcpy(paddedData, pureData, dataLen * sizeof(uint8_t));
1805317bbafSopenharmony_ci			uint8_t *actualOutput = malloc(dataAndEccLen * sizeof(uint8_t));
1815317bbafSopenharmony_ci			if (actualOutput == NULL) {
1825317bbafSopenharmony_ci				perror("malloc");
1835317bbafSopenharmony_ci				exit(EXIT_FAILURE);
1845317bbafSopenharmony_ci			}
1855317bbafSopenharmony_ci			addEccAndInterleave(paddedData, version, (enum qrcodegen_Ecc)ecl, actualOutput);
1865317bbafSopenharmony_ci
1875317bbafSopenharmony_ci			assert(memcmp(actualOutput, expectOutput, dataAndEccLen * sizeof(uint8_t)) == 0);
1885317bbafSopenharmony_ci			free(pureData);
1895317bbafSopenharmony_ci			free(expectOutput);
1905317bbafSopenharmony_ci			free(paddedData);
1915317bbafSopenharmony_ci			free(actualOutput);
1925317bbafSopenharmony_ci			numTestCases++;
1935317bbafSopenharmony_ci		}
1945317bbafSopenharmony_ci	}
1955317bbafSopenharmony_ci}
1965317bbafSopenharmony_ci
1975317bbafSopenharmony_ci
1985317bbafSopenharmony_cistatic void testGetNumDataCodewords(void) {
1995317bbafSopenharmony_ci	const int cases[][3] = {
2005317bbafSopenharmony_ci		{ 3, 1,   44},
2015317bbafSopenharmony_ci		{ 3, 2,   34},
2025317bbafSopenharmony_ci		{ 3, 3,   26},
2035317bbafSopenharmony_ci		{ 6, 0,  136},
2045317bbafSopenharmony_ci		{ 7, 0,  156},
2055317bbafSopenharmony_ci		{ 9, 0,  232},
2065317bbafSopenharmony_ci		{ 9, 1,  182},
2075317bbafSopenharmony_ci		{12, 3,  158},
2085317bbafSopenharmony_ci		{15, 0,  523},
2095317bbafSopenharmony_ci		{16, 2,  325},
2105317bbafSopenharmony_ci		{19, 3,  341},
2115317bbafSopenharmony_ci		{21, 0,  932},
2125317bbafSopenharmony_ci		{22, 0, 1006},
2135317bbafSopenharmony_ci		{22, 1,  782},
2145317bbafSopenharmony_ci		{22, 3,  442},
2155317bbafSopenharmony_ci		{24, 0, 1174},
2165317bbafSopenharmony_ci		{24, 3,  514},
2175317bbafSopenharmony_ci		{28, 0, 1531},
2185317bbafSopenharmony_ci		{30, 3,  745},
2195317bbafSopenharmony_ci		{32, 3,  845},
2205317bbafSopenharmony_ci		{33, 0, 2071},
2215317bbafSopenharmony_ci		{33, 3,  901},
2225317bbafSopenharmony_ci		{35, 0, 2306},
2235317bbafSopenharmony_ci		{35, 1, 1812},
2245317bbafSopenharmony_ci		{35, 2, 1286},
2255317bbafSopenharmony_ci		{36, 3, 1054},
2265317bbafSopenharmony_ci		{37, 3, 1096},
2275317bbafSopenharmony_ci		{39, 1, 2216},
2285317bbafSopenharmony_ci		{40, 1, 2334},
2295317bbafSopenharmony_ci	};
2305317bbafSopenharmony_ci	for (size_t i = 0; i < ARRAY_LENGTH(cases); i++) {
2315317bbafSopenharmony_ci		const int *tc = cases[i];
2325317bbafSopenharmony_ci		assert(getNumDataCodewords(tc[0], (enum qrcodegen_Ecc)tc[1]) == tc[2]);
2335317bbafSopenharmony_ci		numTestCases++;
2345317bbafSopenharmony_ci	}
2355317bbafSopenharmony_ci}
2365317bbafSopenharmony_ci
2375317bbafSopenharmony_ci
2385317bbafSopenharmony_cistatic void testGetNumRawDataModules(void) {
2395317bbafSopenharmony_ci	const int cases[][2] = {
2405317bbafSopenharmony_ci		{ 1,   208},
2415317bbafSopenharmony_ci		{ 2,   359},
2425317bbafSopenharmony_ci		{ 3,   567},
2435317bbafSopenharmony_ci		{ 6,  1383},
2445317bbafSopenharmony_ci		{ 7,  1568},
2455317bbafSopenharmony_ci		{12,  3728},
2465317bbafSopenharmony_ci		{15,  5243},
2475317bbafSopenharmony_ci		{18,  7211},
2485317bbafSopenharmony_ci		{22, 10068},
2495317bbafSopenharmony_ci		{26, 13652},
2505317bbafSopenharmony_ci		{32, 19723},
2515317bbafSopenharmony_ci		{37, 25568},
2525317bbafSopenharmony_ci		{40, 29648},
2535317bbafSopenharmony_ci	};
2545317bbafSopenharmony_ci	for (size_t i = 0; i < ARRAY_LENGTH(cases); i++) {
2555317bbafSopenharmony_ci		const int *tc = cases[i];
2565317bbafSopenharmony_ci		assert(getNumRawDataModules(tc[0]) == tc[1]);
2575317bbafSopenharmony_ci		numTestCases++;
2585317bbafSopenharmony_ci	}
2595317bbafSopenharmony_ci}
2605317bbafSopenharmony_ci
2615317bbafSopenharmony_ci
2625317bbafSopenharmony_cistatic void testReedSolomonComputeDivisor(void) {
2635317bbafSopenharmony_ci	uint8_t generator[30];
2645317bbafSopenharmony_ci
2655317bbafSopenharmony_ci	reedSolomonComputeDivisor(1, generator);
2665317bbafSopenharmony_ci	assert(generator[0] == 0x01);
2675317bbafSopenharmony_ci	numTestCases++;
2685317bbafSopenharmony_ci
2695317bbafSopenharmony_ci	reedSolomonComputeDivisor(2, generator);
2705317bbafSopenharmony_ci	assert(generator[0] == 0x03);
2715317bbafSopenharmony_ci	assert(generator[1] == 0x02);
2725317bbafSopenharmony_ci	numTestCases++;
2735317bbafSopenharmony_ci
2745317bbafSopenharmony_ci	reedSolomonComputeDivisor(5, generator);
2755317bbafSopenharmony_ci	assert(generator[0] == 0x1F);
2765317bbafSopenharmony_ci	assert(generator[1] == 0xC6);
2775317bbafSopenharmony_ci	assert(generator[2] == 0x3F);
2785317bbafSopenharmony_ci	assert(generator[3] == 0x93);
2795317bbafSopenharmony_ci	assert(generator[4] == 0x74);
2805317bbafSopenharmony_ci	numTestCases++;
2815317bbafSopenharmony_ci
2825317bbafSopenharmony_ci	reedSolomonComputeDivisor(30, generator);
2835317bbafSopenharmony_ci	assert(generator[ 0] == 0xD4);
2845317bbafSopenharmony_ci	assert(generator[ 1] == 0xF6);
2855317bbafSopenharmony_ci	assert(generator[ 5] == 0xC0);
2865317bbafSopenharmony_ci	assert(generator[12] == 0x16);
2875317bbafSopenharmony_ci	assert(generator[13] == 0xD9);
2885317bbafSopenharmony_ci	assert(generator[20] == 0x12);
2895317bbafSopenharmony_ci	assert(generator[27] == 0x6A);
2905317bbafSopenharmony_ci	assert(generator[29] == 0x96);
2915317bbafSopenharmony_ci	numTestCases++;
2925317bbafSopenharmony_ci}
2935317bbafSopenharmony_ci
2945317bbafSopenharmony_ci
2955317bbafSopenharmony_cistatic void testReedSolomonComputeRemainder(void) {
2965317bbafSopenharmony_ci	{
2975317bbafSopenharmony_ci		uint8_t data[1];
2985317bbafSopenharmony_ci		uint8_t generator[3];
2995317bbafSopenharmony_ci		uint8_t remainder[ARRAY_LENGTH(generator)];
3005317bbafSopenharmony_ci		reedSolomonComputeDivisor(ARRAY_LENGTH(generator), generator);
3015317bbafSopenharmony_ci		reedSolomonComputeRemainder(data, 0, generator, ARRAY_LENGTH(generator), remainder);
3025317bbafSopenharmony_ci		assert(remainder[0] == 0);
3035317bbafSopenharmony_ci		assert(remainder[1] == 0);
3045317bbafSopenharmony_ci		assert(remainder[2] == 0);
3055317bbafSopenharmony_ci		numTestCases++;
3065317bbafSopenharmony_ci	}
3075317bbafSopenharmony_ci	{
3085317bbafSopenharmony_ci		uint8_t data[2] = {0, 1};
3095317bbafSopenharmony_ci		uint8_t generator[4];
3105317bbafSopenharmony_ci		uint8_t remainder[ARRAY_LENGTH(generator)];
3115317bbafSopenharmony_ci		reedSolomonComputeDivisor(ARRAY_LENGTH(generator), generator);
3125317bbafSopenharmony_ci		reedSolomonComputeRemainder(data, ARRAY_LENGTH(data), generator, ARRAY_LENGTH(generator), remainder);
3135317bbafSopenharmony_ci		assert(remainder[0] == generator[0]);
3145317bbafSopenharmony_ci		assert(remainder[1] == generator[1]);
3155317bbafSopenharmony_ci		assert(remainder[2] == generator[2]);
3165317bbafSopenharmony_ci		assert(remainder[3] == generator[3]);
3175317bbafSopenharmony_ci		numTestCases++;
3185317bbafSopenharmony_ci	}
3195317bbafSopenharmony_ci	{
3205317bbafSopenharmony_ci		uint8_t data[5] = {0x03, 0x3A, 0x60, 0x12, 0xC7};
3215317bbafSopenharmony_ci		uint8_t generator[5];
3225317bbafSopenharmony_ci		uint8_t remainder[ARRAY_LENGTH(generator)];
3235317bbafSopenharmony_ci		reedSolomonComputeDivisor(ARRAY_LENGTH(generator), generator);
3245317bbafSopenharmony_ci		reedSolomonComputeRemainder(data, ARRAY_LENGTH(data), generator, ARRAY_LENGTH(generator), remainder);
3255317bbafSopenharmony_ci		assert(remainder[0] == 0xCB);
3265317bbafSopenharmony_ci		assert(remainder[1] == 0x36);
3275317bbafSopenharmony_ci		assert(remainder[2] == 0x16);
3285317bbafSopenharmony_ci		assert(remainder[3] == 0xFA);
3295317bbafSopenharmony_ci		assert(remainder[4] == 0x9D);
3305317bbafSopenharmony_ci		numTestCases++;
3315317bbafSopenharmony_ci	}
3325317bbafSopenharmony_ci	{
3335317bbafSopenharmony_ci		uint8_t data[43] = {
3345317bbafSopenharmony_ci			0x38, 0x71, 0xDB, 0xF9, 0xD7, 0x28, 0xF6, 0x8E, 0xFE, 0x5E,
3355317bbafSopenharmony_ci			0xE6, 0x7D, 0x7D, 0xB2, 0xA5, 0x58, 0xBC, 0x28, 0x23, 0x53,
3365317bbafSopenharmony_ci			0x14, 0xD5, 0x61, 0xC0, 0x20, 0x6C, 0xDE, 0xDE, 0xFC, 0x79,
3375317bbafSopenharmony_ci			0xB0, 0x8B, 0x78, 0x6B, 0x49, 0xD0, 0x1A, 0xAD, 0xF3, 0xEF,
3385317bbafSopenharmony_ci			0x52, 0x7D, 0x9A,
3395317bbafSopenharmony_ci		};
3405317bbafSopenharmony_ci		uint8_t generator[30];
3415317bbafSopenharmony_ci		uint8_t remainder[ARRAY_LENGTH(generator)];
3425317bbafSopenharmony_ci		reedSolomonComputeDivisor(ARRAY_LENGTH(generator), generator);
3435317bbafSopenharmony_ci		reedSolomonComputeRemainder(data, ARRAY_LENGTH(data), generator, ARRAY_LENGTH(generator), remainder);
3445317bbafSopenharmony_ci		assert(remainder[ 0] == 0xCE);
3455317bbafSopenharmony_ci		assert(remainder[ 1] == 0xF0);
3465317bbafSopenharmony_ci		assert(remainder[ 2] == 0x31);
3475317bbafSopenharmony_ci		assert(remainder[ 3] == 0xDE);
3485317bbafSopenharmony_ci		assert(remainder[ 8] == 0xE1);
3495317bbafSopenharmony_ci		assert(remainder[12] == 0xCA);
3505317bbafSopenharmony_ci		assert(remainder[17] == 0xE3);
3515317bbafSopenharmony_ci		assert(remainder[19] == 0x85);
3525317bbafSopenharmony_ci		assert(remainder[20] == 0x50);
3535317bbafSopenharmony_ci		assert(remainder[24] == 0xBE);
3545317bbafSopenharmony_ci		assert(remainder[29] == 0xB3);
3555317bbafSopenharmony_ci		numTestCases++;
3565317bbafSopenharmony_ci	}
3575317bbafSopenharmony_ci}
3585317bbafSopenharmony_ci
3595317bbafSopenharmony_ci
3605317bbafSopenharmony_cistatic void testReedSolomonMultiply(void) {
3615317bbafSopenharmony_ci	const uint8_t cases[][3] = {
3625317bbafSopenharmony_ci		{0x00, 0x00, 0x00},
3635317bbafSopenharmony_ci		{0x01, 0x01, 0x01},
3645317bbafSopenharmony_ci		{0x02, 0x02, 0x04},
3655317bbafSopenharmony_ci		{0x00, 0x6E, 0x00},
3665317bbafSopenharmony_ci		{0xB2, 0xDD, 0xE6},
3675317bbafSopenharmony_ci		{0x41, 0x11, 0x25},
3685317bbafSopenharmony_ci		{0xB0, 0x1F, 0x11},
3695317bbafSopenharmony_ci		{0x05, 0x75, 0xBC},
3705317bbafSopenharmony_ci		{0x52, 0xB5, 0xAE},
3715317bbafSopenharmony_ci		{0xA8, 0x20, 0xA4},
3725317bbafSopenharmony_ci		{0x0E, 0x44, 0x9F},
3735317bbafSopenharmony_ci		{0xD4, 0x13, 0xA0},
3745317bbafSopenharmony_ci		{0x31, 0x10, 0x37},
3755317bbafSopenharmony_ci		{0x6C, 0x58, 0xCB},
3765317bbafSopenharmony_ci		{0xB6, 0x75, 0x3E},
3775317bbafSopenharmony_ci		{0xFF, 0xFF, 0xE2},
3785317bbafSopenharmony_ci	};
3795317bbafSopenharmony_ci	for (size_t i = 0; i < ARRAY_LENGTH(cases); i++) {
3805317bbafSopenharmony_ci		const uint8_t *tc = cases[i];
3815317bbafSopenharmony_ci		assert(reedSolomonMultiply(tc[0], tc[1]) == tc[2]);
3825317bbafSopenharmony_ci		numTestCases++;
3835317bbafSopenharmony_ci	}
3845317bbafSopenharmony_ci}
3855317bbafSopenharmony_ci
3865317bbafSopenharmony_ci
3875317bbafSopenharmony_cistatic void testInitializeFunctionModulesEtc(void) {
3885317bbafSopenharmony_ci	for (int ver = 1; ver <= 40; ver++) {
3895317bbafSopenharmony_ci		uint8_t *qrcode = malloc((size_t)qrcodegen_BUFFER_LEN_FOR_VERSION(ver) * sizeof(uint8_t));
3905317bbafSopenharmony_ci		if (qrcode == NULL) {
3915317bbafSopenharmony_ci			perror("malloc");
3925317bbafSopenharmony_ci			exit(EXIT_FAILURE);
3935317bbafSopenharmony_ci		}
3945317bbafSopenharmony_ci		initializeFunctionModules(ver, qrcode);
3955317bbafSopenharmony_ci
3965317bbafSopenharmony_ci		int size = qrcodegen_getSize(qrcode);
3975317bbafSopenharmony_ci		if (ver == 1)
3985317bbafSopenharmony_ci			assert(size == 21);
3995317bbafSopenharmony_ci		else if (ver == 40)
4005317bbafSopenharmony_ci			assert(size == 177);
4015317bbafSopenharmony_ci		else
4025317bbafSopenharmony_ci			assert(size == ver * 4 + 17);
4035317bbafSopenharmony_ci
4045317bbafSopenharmony_ci		bool hasLight = false;
4055317bbafSopenharmony_ci		bool hasDark = false;
4065317bbafSopenharmony_ci		for (int y = 0; y < size; y++) {
4075317bbafSopenharmony_ci			for (int x = 0; x < size; x++) {
4085317bbafSopenharmony_ci				bool color = qrcodegen_getModule(qrcode, x, y);
4095317bbafSopenharmony_ci				if (color)
4105317bbafSopenharmony_ci					hasDark = true;
4115317bbafSopenharmony_ci				else
4125317bbafSopenharmony_ci					hasLight = true;
4135317bbafSopenharmony_ci			}
4145317bbafSopenharmony_ci		}
4155317bbafSopenharmony_ci		assert(hasLight && hasDark);
4165317bbafSopenharmony_ci		free(qrcode);
4175317bbafSopenharmony_ci		numTestCases++;
4185317bbafSopenharmony_ci	}
4195317bbafSopenharmony_ci}
4205317bbafSopenharmony_ci
4215317bbafSopenharmony_ci
4225317bbafSopenharmony_cistatic void testGetAlignmentPatternPositions(void) {
4235317bbafSopenharmony_ci	const int cases[][9] = {
4245317bbafSopenharmony_ci		{ 1, 0,  -1,  -1,  -1,  -1,  -1,  -1,  -1},
4255317bbafSopenharmony_ci		{ 2, 2,   6,  18,  -1,  -1,  -1,  -1,  -1},
4265317bbafSopenharmony_ci		{ 3, 2,   6,  22,  -1,  -1,  -1,  -1,  -1},
4275317bbafSopenharmony_ci		{ 6, 2,   6,  34,  -1,  -1,  -1,  -1,  -1},
4285317bbafSopenharmony_ci		{ 7, 3,   6,  22,  38,  -1,  -1,  -1,  -1},
4295317bbafSopenharmony_ci		{ 8, 3,   6,  24,  42,  -1,  -1,  -1,  -1},
4305317bbafSopenharmony_ci		{16, 4,   6,  26,  50,  74,  -1,  -1,  -1},
4315317bbafSopenharmony_ci		{25, 5,   6,  32,  58,  84, 110,  -1,  -1},
4325317bbafSopenharmony_ci		{32, 6,   6,  34,  60,  86, 112, 138,  -1},
4335317bbafSopenharmony_ci		{33, 6,   6,  30,  58,  86, 114, 142,  -1},
4345317bbafSopenharmony_ci		{39, 7,   6,  26,  54,  82, 110, 138, 166},
4355317bbafSopenharmony_ci		{40, 7,   6,  30,  58,  86, 114, 142, 170},
4365317bbafSopenharmony_ci	};
4375317bbafSopenharmony_ci	for (size_t i = 0; i < ARRAY_LENGTH(cases); i++) {
4385317bbafSopenharmony_ci		const int *tc = cases[i];
4395317bbafSopenharmony_ci		uint8_t pos[7];
4405317bbafSopenharmony_ci		int num = getAlignmentPatternPositions(tc[0], pos);
4415317bbafSopenharmony_ci		assert(num == tc[1]);
4425317bbafSopenharmony_ci		for (int j = 0; j < num; j++)
4435317bbafSopenharmony_ci			assert(pos[j] == tc[2 + j]);
4445317bbafSopenharmony_ci		numTestCases++;
4455317bbafSopenharmony_ci	}
4465317bbafSopenharmony_ci}
4475317bbafSopenharmony_ci
4485317bbafSopenharmony_ci
4495317bbafSopenharmony_cistatic void testGetSetModule(void) {
4505317bbafSopenharmony_ci	uint8_t qrcode[qrcodegen_BUFFER_LEN_FOR_VERSION(23)];
4515317bbafSopenharmony_ci	initializeFunctionModules(23, qrcode);
4525317bbafSopenharmony_ci	int size = qrcodegen_getSize(qrcode);
4535317bbafSopenharmony_ci
4545317bbafSopenharmony_ci	for (int y = 0; y < size; y++) {  // Clear all to light
4555317bbafSopenharmony_ci		for (int x = 0; x < size; x++)
4565317bbafSopenharmony_ci			setModuleBounded(qrcode, x, y, false);
4575317bbafSopenharmony_ci	}
4585317bbafSopenharmony_ci	for (int y = 0; y < size; y++) {  // Check all light
4595317bbafSopenharmony_ci		for (int x = 0; x < size; x++)
4605317bbafSopenharmony_ci			assert(qrcodegen_getModule(qrcode, x, y) == false);
4615317bbafSopenharmony_ci	}
4625317bbafSopenharmony_ci	for (int y = 0; y < size; y++) {  // Set all to dark
4635317bbafSopenharmony_ci		for (int x = 0; x < size; x++)
4645317bbafSopenharmony_ci			setModuleBounded(qrcode, x, y, true);
4655317bbafSopenharmony_ci	}
4665317bbafSopenharmony_ci	for (int y = 0; y < size; y++) {  // Check all dark
4675317bbafSopenharmony_ci		for (int x = 0; x < size; x++)
4685317bbafSopenharmony_ci			assert(qrcodegen_getModule(qrcode, x, y) == true);
4695317bbafSopenharmony_ci	}
4705317bbafSopenharmony_ci
4715317bbafSopenharmony_ci	// Set some out of bounds modules to light
4725317bbafSopenharmony_ci	setModuleUnbounded(qrcode, -1, -1, false);
4735317bbafSopenharmony_ci	setModuleUnbounded(qrcode, -1, 0, false);
4745317bbafSopenharmony_ci	setModuleUnbounded(qrcode, 0, -1, false);
4755317bbafSopenharmony_ci	setModuleUnbounded(qrcode, size, 5, false);
4765317bbafSopenharmony_ci	setModuleUnbounded(qrcode, 72, size, false);
4775317bbafSopenharmony_ci	setModuleUnbounded(qrcode, size, size, false);
4785317bbafSopenharmony_ci	for (int y = 0; y < size; y++) {  // Check all dark
4795317bbafSopenharmony_ci		for (int x = 0; x < size; x++)
4805317bbafSopenharmony_ci			assert(qrcodegen_getModule(qrcode, x, y) == true);
4815317bbafSopenharmony_ci	}
4825317bbafSopenharmony_ci
4835317bbafSopenharmony_ci	// Set some modules to light
4845317bbafSopenharmony_ci	setModuleBounded(qrcode, 3, 8, false);
4855317bbafSopenharmony_ci	setModuleBounded(qrcode, 61, 49, false);
4865317bbafSopenharmony_ci	for (int y = 0; y < size; y++) {  // Check most dark
4875317bbafSopenharmony_ci		for (int x = 0; x < size; x++) {
4885317bbafSopenharmony_ci			bool light = (x == 3 && y == 8) || (x == 61 && y == 49);
4895317bbafSopenharmony_ci			assert(qrcodegen_getModule(qrcode, x, y) != light);
4905317bbafSopenharmony_ci		}
4915317bbafSopenharmony_ci	}
4925317bbafSopenharmony_ci	numTestCases++;
4935317bbafSopenharmony_ci}
4945317bbafSopenharmony_ci
4955317bbafSopenharmony_ci
4965317bbafSopenharmony_cistatic void testGetSetModuleRandomly(void) {
4975317bbafSopenharmony_ci	uint8_t qrcode[qrcodegen_BUFFER_LEN_FOR_VERSION(1)];
4985317bbafSopenharmony_ci	initializeFunctionModules(1, qrcode);
4995317bbafSopenharmony_ci	int size = qrcodegen_getSize(qrcode);
5005317bbafSopenharmony_ci
5015317bbafSopenharmony_ci	bool modules[21][21];
5025317bbafSopenharmony_ci	for (int y = 0; y < size; y++) {
5035317bbafSopenharmony_ci		for (int x = 0; x < size; x++)
5045317bbafSopenharmony_ci			modules[y][x] = qrcodegen_getModule(qrcode, x, y);
5055317bbafSopenharmony_ci	}
5065317bbafSopenharmony_ci
5075317bbafSopenharmony_ci	long trials = 100000;
5085317bbafSopenharmony_ci	for (long i = 0; i < trials; i++) {
5095317bbafSopenharmony_ci		int x = rand() % (size * 2) - size / 2;
5105317bbafSopenharmony_ci		int y = rand() % (size * 2) - size / 2;
5115317bbafSopenharmony_ci		bool isInBounds = 0 <= x && x < size && 0 <= y && y < size;
5125317bbafSopenharmony_ci		bool oldColor = isInBounds && modules[y][x];
5135317bbafSopenharmony_ci		if (isInBounds)
5145317bbafSopenharmony_ci			assert(getModuleBounded(qrcode, x, y) == oldColor);
5155317bbafSopenharmony_ci		assert(qrcodegen_getModule(qrcode, x, y) == oldColor);
5165317bbafSopenharmony_ci
5175317bbafSopenharmony_ci		bool newColor = rand() % 2 == 0;
5185317bbafSopenharmony_ci		if (isInBounds)
5195317bbafSopenharmony_ci			modules[y][x] = newColor;
5205317bbafSopenharmony_ci		if (isInBounds && rand() % 2 == 0)
5215317bbafSopenharmony_ci			setModuleBounded(qrcode, x, y, newColor);
5225317bbafSopenharmony_ci		else
5235317bbafSopenharmony_ci			setModuleUnbounded(qrcode, x, y, newColor);
5245317bbafSopenharmony_ci	}
5255317bbafSopenharmony_ci	numTestCases++;
5265317bbafSopenharmony_ci}
5275317bbafSopenharmony_ci
5285317bbafSopenharmony_ci
5295317bbafSopenharmony_cistatic void testIsAlphanumeric(void) {
5305317bbafSopenharmony_ci	struct TestCase {
5315317bbafSopenharmony_ci		bool answer;
5325317bbafSopenharmony_ci		const char *text;
5335317bbafSopenharmony_ci	};
5345317bbafSopenharmony_ci	const struct TestCase cases[] = {
5355317bbafSopenharmony_ci		{true, ""},
5365317bbafSopenharmony_ci		{true, "0"},
5375317bbafSopenharmony_ci		{true, "A"},
5385317bbafSopenharmony_ci		{false, "a"},
5395317bbafSopenharmony_ci		{true, " "},
5405317bbafSopenharmony_ci		{true, "."},
5415317bbafSopenharmony_ci		{true, "*"},
5425317bbafSopenharmony_ci		{false, ","},
5435317bbafSopenharmony_ci		{false, "|"},
5445317bbafSopenharmony_ci		{false, "@"},
5455317bbafSopenharmony_ci		{true, "XYZ"},
5465317bbafSopenharmony_ci		{false, "XYZ!"},
5475317bbafSopenharmony_ci		{true, "79068"},
5485317bbafSopenharmony_ci		{true, "+123 ABC$"},
5495317bbafSopenharmony_ci		{false, "\x01"},
5505317bbafSopenharmony_ci		{false, "\x7F"},
5515317bbafSopenharmony_ci		{false, "\x80"},
5525317bbafSopenharmony_ci		{false, "\xC0"},
5535317bbafSopenharmony_ci		{false, "\xFF"},
5545317bbafSopenharmony_ci	};
5555317bbafSopenharmony_ci	for (size_t i = 0; i < ARRAY_LENGTH(cases); i++) {
5565317bbafSopenharmony_ci		assert(qrcodegen_isAlphanumeric(cases[i].text) == cases[i].answer);
5575317bbafSopenharmony_ci		numTestCases++;
5585317bbafSopenharmony_ci	}
5595317bbafSopenharmony_ci}
5605317bbafSopenharmony_ci
5615317bbafSopenharmony_ci
5625317bbafSopenharmony_cistatic void testIsNumeric(void) {
5635317bbafSopenharmony_ci	struct TestCase {
5645317bbafSopenharmony_ci		bool answer;
5655317bbafSopenharmony_ci		const char *text;
5665317bbafSopenharmony_ci	};
5675317bbafSopenharmony_ci	const struct TestCase cases[] = {
5685317bbafSopenharmony_ci		{true, ""},
5695317bbafSopenharmony_ci		{true, "0"},
5705317bbafSopenharmony_ci		{false, "A"},
5715317bbafSopenharmony_ci		{false, "a"},
5725317bbafSopenharmony_ci		{false, " "},
5735317bbafSopenharmony_ci		{false, "."},
5745317bbafSopenharmony_ci		{false, "*"},
5755317bbafSopenharmony_ci		{false, ","},
5765317bbafSopenharmony_ci		{false, "|"},
5775317bbafSopenharmony_ci		{false, "@"},
5785317bbafSopenharmony_ci		{false, "XYZ"},
5795317bbafSopenharmony_ci		{false, "XYZ!"},
5805317bbafSopenharmony_ci		{true, "79068"},
5815317bbafSopenharmony_ci		{false, "+123 ABC$"},
5825317bbafSopenharmony_ci		{false, "\x01"},
5835317bbafSopenharmony_ci		{false, "\x7F"},
5845317bbafSopenharmony_ci		{false, "\x80"},
5855317bbafSopenharmony_ci		{false, "\xC0"},
5865317bbafSopenharmony_ci		{false, "\xFF"},
5875317bbafSopenharmony_ci	};
5885317bbafSopenharmony_ci	for (size_t i = 0; i < ARRAY_LENGTH(cases); i++) {
5895317bbafSopenharmony_ci		assert(qrcodegen_isNumeric(cases[i].text) == cases[i].answer);
5905317bbafSopenharmony_ci		numTestCases++;
5915317bbafSopenharmony_ci	}
5925317bbafSopenharmony_ci}
5935317bbafSopenharmony_ci
5945317bbafSopenharmony_ci
5955317bbafSopenharmony_cistatic void testCalcSegmentBufferSize(void) {
5965317bbafSopenharmony_ci	{
5975317bbafSopenharmony_ci		const size_t cases[][2] = {
5985317bbafSopenharmony_ci			{0, 0},
5995317bbafSopenharmony_ci			{1, 1},
6005317bbafSopenharmony_ci			{2, 1},
6015317bbafSopenharmony_ci			{3, 2},
6025317bbafSopenharmony_ci			{4, 2},
6035317bbafSopenharmony_ci			{5, 3},
6045317bbafSopenharmony_ci			{6, 3},
6055317bbafSopenharmony_ci			{1472, 614},
6065317bbafSopenharmony_ci			{2097, 874},
6075317bbafSopenharmony_ci			{5326, 2220},
6085317bbafSopenharmony_ci			{9828, 4095},
6095317bbafSopenharmony_ci			{9829, 4096},
6105317bbafSopenharmony_ci			{9830, 4096},
6115317bbafSopenharmony_ci			{9831, SIZE_MAX},
6125317bbafSopenharmony_ci			{9832, SIZE_MAX},
6135317bbafSopenharmony_ci			{12000, SIZE_MAX},
6145317bbafSopenharmony_ci			{28453, SIZE_MAX},
6155317bbafSopenharmony_ci			{55555, SIZE_MAX},
6165317bbafSopenharmony_ci			{SIZE_MAX / 6, SIZE_MAX},
6175317bbafSopenharmony_ci			{SIZE_MAX / 4, SIZE_MAX},
6185317bbafSopenharmony_ci			{SIZE_MAX / 2, SIZE_MAX},
6195317bbafSopenharmony_ci			{SIZE_MAX / 1, SIZE_MAX},
6205317bbafSopenharmony_ci		};
6215317bbafSopenharmony_ci		for (size_t i = 0; i < ARRAY_LENGTH(cases); i++) {
6225317bbafSopenharmony_ci			assert(qrcodegen_calcSegmentBufferSize(qrcodegen_Mode_NUMERIC, cases[i][0]) == cases[i][1]);
6235317bbafSopenharmony_ci			numTestCases++;
6245317bbafSopenharmony_ci		}
6255317bbafSopenharmony_ci	}
6265317bbafSopenharmony_ci	{
6275317bbafSopenharmony_ci		const size_t cases[][2] = {
6285317bbafSopenharmony_ci			{0, 0},
6295317bbafSopenharmony_ci			{1, 1},
6305317bbafSopenharmony_ci			{2, 2},
6315317bbafSopenharmony_ci			{3, 3},
6325317bbafSopenharmony_ci			{4, 3},
6335317bbafSopenharmony_ci			{5, 4},
6345317bbafSopenharmony_ci			{6, 5},
6355317bbafSopenharmony_ci			{1472, 1012},
6365317bbafSopenharmony_ci			{2097, 1442},
6375317bbafSopenharmony_ci			{5326, 3662},
6385317bbafSopenharmony_ci			{5955, 4095},
6395317bbafSopenharmony_ci			{5956, 4095},
6405317bbafSopenharmony_ci			{5957, 4096},
6415317bbafSopenharmony_ci			{5958, SIZE_MAX},
6425317bbafSopenharmony_ci			{5959, SIZE_MAX},
6435317bbafSopenharmony_ci			{12000, SIZE_MAX},
6445317bbafSopenharmony_ci			{28453, SIZE_MAX},
6455317bbafSopenharmony_ci			{55555, SIZE_MAX},
6465317bbafSopenharmony_ci			{SIZE_MAX / 10, SIZE_MAX},
6475317bbafSopenharmony_ci			{SIZE_MAX / 8, SIZE_MAX},
6485317bbafSopenharmony_ci			{SIZE_MAX / 5, SIZE_MAX},
6495317bbafSopenharmony_ci			{SIZE_MAX / 2, SIZE_MAX},
6505317bbafSopenharmony_ci			{SIZE_MAX / 1, SIZE_MAX},
6515317bbafSopenharmony_ci		};
6525317bbafSopenharmony_ci		for (size_t i = 0; i < ARRAY_LENGTH(cases); i++) {
6535317bbafSopenharmony_ci			assert(qrcodegen_calcSegmentBufferSize(qrcodegen_Mode_ALPHANUMERIC, cases[i][0]) == cases[i][1]);
6545317bbafSopenharmony_ci			numTestCases++;
6555317bbafSopenharmony_ci		}
6565317bbafSopenharmony_ci	}
6575317bbafSopenharmony_ci	{
6585317bbafSopenharmony_ci		const size_t cases[][2] = {
6595317bbafSopenharmony_ci			{0, 0},
6605317bbafSopenharmony_ci			{1, 1},
6615317bbafSopenharmony_ci			{2, 2},
6625317bbafSopenharmony_ci			{3, 3},
6635317bbafSopenharmony_ci			{1472, 1472},
6645317bbafSopenharmony_ci			{2097, 2097},
6655317bbafSopenharmony_ci			{4094, 4094},
6665317bbafSopenharmony_ci			{4095, 4095},
6675317bbafSopenharmony_ci			{4096, SIZE_MAX},
6685317bbafSopenharmony_ci			{4097, SIZE_MAX},
6695317bbafSopenharmony_ci			{5957, SIZE_MAX},
6705317bbafSopenharmony_ci			{12000, SIZE_MAX},
6715317bbafSopenharmony_ci			{28453, SIZE_MAX},
6725317bbafSopenharmony_ci			{55555, SIZE_MAX},
6735317bbafSopenharmony_ci			{SIZE_MAX / 16 + 1, SIZE_MAX},
6745317bbafSopenharmony_ci			{SIZE_MAX / 14, SIZE_MAX},
6755317bbafSopenharmony_ci			{SIZE_MAX / 9, SIZE_MAX},
6765317bbafSopenharmony_ci			{SIZE_MAX / 7, SIZE_MAX},
6775317bbafSopenharmony_ci			{SIZE_MAX / 4, SIZE_MAX},
6785317bbafSopenharmony_ci			{SIZE_MAX / 3, SIZE_MAX},
6795317bbafSopenharmony_ci			{SIZE_MAX / 2, SIZE_MAX},
6805317bbafSopenharmony_ci			{SIZE_MAX / 1, SIZE_MAX},
6815317bbafSopenharmony_ci		};
6825317bbafSopenharmony_ci		for (size_t i = 0; i < ARRAY_LENGTH(cases); i++) {
6835317bbafSopenharmony_ci			assert(qrcodegen_calcSegmentBufferSize(qrcodegen_Mode_BYTE, cases[i][0]) == cases[i][1]);
6845317bbafSopenharmony_ci			numTestCases++;
6855317bbafSopenharmony_ci		}
6865317bbafSopenharmony_ci	}
6875317bbafSopenharmony_ci	{
6885317bbafSopenharmony_ci		const size_t cases[][2] = {
6895317bbafSopenharmony_ci			{0, 0},
6905317bbafSopenharmony_ci			{1, 2},
6915317bbafSopenharmony_ci			{2, 4},
6925317bbafSopenharmony_ci			{3, 5},
6935317bbafSopenharmony_ci			{1472, 2392},
6945317bbafSopenharmony_ci			{2097, 3408},
6955317bbafSopenharmony_ci			{2519, 4094},
6965317bbafSopenharmony_ci			{2520, 4095},
6975317bbafSopenharmony_ci			{2521, SIZE_MAX},
6985317bbafSopenharmony_ci			{5957, SIZE_MAX},
6995317bbafSopenharmony_ci			{2522, SIZE_MAX},
7005317bbafSopenharmony_ci			{12000, SIZE_MAX},
7015317bbafSopenharmony_ci			{28453, SIZE_MAX},
7025317bbafSopenharmony_ci			{55555, SIZE_MAX},
7035317bbafSopenharmony_ci			{SIZE_MAX / 13 + 1, SIZE_MAX},
7045317bbafSopenharmony_ci			{SIZE_MAX / 12, SIZE_MAX},
7055317bbafSopenharmony_ci			{SIZE_MAX / 9, SIZE_MAX},
7065317bbafSopenharmony_ci			{SIZE_MAX / 4, SIZE_MAX},
7075317bbafSopenharmony_ci			{SIZE_MAX / 3, SIZE_MAX},
7085317bbafSopenharmony_ci			{SIZE_MAX / 2, SIZE_MAX},
7095317bbafSopenharmony_ci			{SIZE_MAX / 1, SIZE_MAX},
7105317bbafSopenharmony_ci		};
7115317bbafSopenharmony_ci		for (size_t i = 0; i < ARRAY_LENGTH(cases); i++) {
7125317bbafSopenharmony_ci			assert(qrcodegen_calcSegmentBufferSize(qrcodegen_Mode_KANJI, cases[i][0]) == cases[i][1]);
7135317bbafSopenharmony_ci			numTestCases++;
7145317bbafSopenharmony_ci		}
7155317bbafSopenharmony_ci	}
7165317bbafSopenharmony_ci	{
7175317bbafSopenharmony_ci		assert(qrcodegen_calcSegmentBufferSize(qrcodegen_Mode_ECI, 0) == 3);
7185317bbafSopenharmony_ci		numTestCases++;
7195317bbafSopenharmony_ci	}
7205317bbafSopenharmony_ci}
7215317bbafSopenharmony_ci
7225317bbafSopenharmony_ci
7235317bbafSopenharmony_cistatic void testCalcSegmentBitLength(void) {
7245317bbafSopenharmony_ci	struct TestCase {
7255317bbafSopenharmony_ci		size_t numChars;
7265317bbafSopenharmony_ci		int result;
7275317bbafSopenharmony_ci	};
7285317bbafSopenharmony_ci	{
7295317bbafSopenharmony_ci		const struct TestCase CASES[] = {
7305317bbafSopenharmony_ci			{0, 0},
7315317bbafSopenharmony_ci			{1, 4},
7325317bbafSopenharmony_ci			{2, 7},
7335317bbafSopenharmony_ci			{3, 10},
7345317bbafSopenharmony_ci			{4, 14},
7355317bbafSopenharmony_ci			{5, 17},
7365317bbafSopenharmony_ci			{6, 20},
7375317bbafSopenharmony_ci			{1472, 4907},
7385317bbafSopenharmony_ci			{2097, 6990},
7395317bbafSopenharmony_ci			{5326, 17754},
7405317bbafSopenharmony_ci			{9828, 32760},
7415317bbafSopenharmony_ci			{9829, 32764},
7425317bbafSopenharmony_ci			{9830, 32767},
7435317bbafSopenharmony_ci			{9831, -1},
7445317bbafSopenharmony_ci			{9832, -1},
7455317bbafSopenharmony_ci			{12000, -1},
7465317bbafSopenharmony_ci			{28453, -1},
7475317bbafSopenharmony_ci			{SIZE_MAX / 6, -1},
7485317bbafSopenharmony_ci			{SIZE_MAX / 3, -1},
7495317bbafSopenharmony_ci			{SIZE_MAX / 2, -1},
7505317bbafSopenharmony_ci			{SIZE_MAX / 1, -1},
7515317bbafSopenharmony_ci		};
7525317bbafSopenharmony_ci		for (size_t i = 0; i < ARRAY_LENGTH(CASES); i++) {
7535317bbafSopenharmony_ci			assert(calcSegmentBitLength(qrcodegen_Mode_NUMERIC, CASES[i].numChars) == CASES[i].result);
7545317bbafSopenharmony_ci			numTestCases++;
7555317bbafSopenharmony_ci		}
7565317bbafSopenharmony_ci	}
7575317bbafSopenharmony_ci	{
7585317bbafSopenharmony_ci		const struct TestCase CASES[] = {
7595317bbafSopenharmony_ci			{0, 0},
7605317bbafSopenharmony_ci			{1, 6},
7615317bbafSopenharmony_ci			{2, 11},
7625317bbafSopenharmony_ci			{3, 17},
7635317bbafSopenharmony_ci			{4, 22},
7645317bbafSopenharmony_ci			{5, 28},
7655317bbafSopenharmony_ci			{6, 33},
7665317bbafSopenharmony_ci			{1472, 8096},
7675317bbafSopenharmony_ci			{2097, 11534},
7685317bbafSopenharmony_ci			{5326, 29293},
7695317bbafSopenharmony_ci			{5955, 32753},
7705317bbafSopenharmony_ci			{5956, 32758},
7715317bbafSopenharmony_ci			{5957, 32764},
7725317bbafSopenharmony_ci			{5958, -1},
7735317bbafSopenharmony_ci			{5959, -1},
7745317bbafSopenharmony_ci			{12000, -1},
7755317bbafSopenharmony_ci			{28453, -1},
7765317bbafSopenharmony_ci			{SIZE_MAX / 10, -1},
7775317bbafSopenharmony_ci			{SIZE_MAX / 5, -1},
7785317bbafSopenharmony_ci			{SIZE_MAX / 2, -1},
7795317bbafSopenharmony_ci			{SIZE_MAX / 1, -1},
7805317bbafSopenharmony_ci		};
7815317bbafSopenharmony_ci		for (size_t i = 0; i < ARRAY_LENGTH(CASES); i++) {
7825317bbafSopenharmony_ci			assert(calcSegmentBitLength(qrcodegen_Mode_ALPHANUMERIC, CASES[i].numChars) == CASES[i].result);
7835317bbafSopenharmony_ci			numTestCases++;
7845317bbafSopenharmony_ci		}
7855317bbafSopenharmony_ci	}
7865317bbafSopenharmony_ci	{
7875317bbafSopenharmony_ci		const struct TestCase CASES[] = {
7885317bbafSopenharmony_ci			{0, 0},
7895317bbafSopenharmony_ci			{1, 8},
7905317bbafSopenharmony_ci			{2, 16},
7915317bbafSopenharmony_ci			{3, 24},
7925317bbafSopenharmony_ci			{1472, 11776},
7935317bbafSopenharmony_ci			{2097, 16776},
7945317bbafSopenharmony_ci			{4094, 32752},
7955317bbafSopenharmony_ci			{4095, 32760},
7965317bbafSopenharmony_ci			{4096, -1},
7975317bbafSopenharmony_ci			{4097, -1},
7985317bbafSopenharmony_ci			{5957, -1},
7995317bbafSopenharmony_ci			{12000, -1},
8005317bbafSopenharmony_ci			{28453, -1},
8015317bbafSopenharmony_ci			{SIZE_MAX / 15, -1},
8025317bbafSopenharmony_ci			{SIZE_MAX / 12, -1},
8035317bbafSopenharmony_ci			{SIZE_MAX / 7, -1},
8045317bbafSopenharmony_ci			{SIZE_MAX / 3, -1},
8055317bbafSopenharmony_ci			{SIZE_MAX / 1, -1},
8065317bbafSopenharmony_ci		};
8075317bbafSopenharmony_ci		for (size_t i = 0; i < ARRAY_LENGTH(CASES); i++) {
8085317bbafSopenharmony_ci			assert(calcSegmentBitLength(qrcodegen_Mode_BYTE, CASES[i].numChars) == CASES[i].result);
8095317bbafSopenharmony_ci			numTestCases++;
8105317bbafSopenharmony_ci		}
8115317bbafSopenharmony_ci	}
8125317bbafSopenharmony_ci	{
8135317bbafSopenharmony_ci		const struct TestCase CASES[] = {
8145317bbafSopenharmony_ci			{0, 0},
8155317bbafSopenharmony_ci			{1, 13},
8165317bbafSopenharmony_ci			{2, 26},
8175317bbafSopenharmony_ci			{3, 39},
8185317bbafSopenharmony_ci			{1472, 19136},
8195317bbafSopenharmony_ci			{2097, 27261},
8205317bbafSopenharmony_ci			{2519, 32747},
8215317bbafSopenharmony_ci			{2520, 32760},
8225317bbafSopenharmony_ci			{2521, -1},
8235317bbafSopenharmony_ci			{5957, -1},
8245317bbafSopenharmony_ci			{2522, -1},
8255317bbafSopenharmony_ci			{12000, -1},
8265317bbafSopenharmony_ci			{28453, -1},
8275317bbafSopenharmony_ci			{SIZE_MAX / 25, -1},
8285317bbafSopenharmony_ci			{SIZE_MAX / 20, -1},
8295317bbafSopenharmony_ci			{SIZE_MAX / 11, -1},
8305317bbafSopenharmony_ci			{SIZE_MAX / 4, -1},
8315317bbafSopenharmony_ci			{SIZE_MAX / 2, -1},
8325317bbafSopenharmony_ci			{SIZE_MAX / 1, -1},
8335317bbafSopenharmony_ci		};
8345317bbafSopenharmony_ci		for (size_t i = 0; i < ARRAY_LENGTH(CASES); i++) {
8355317bbafSopenharmony_ci			assert(calcSegmentBitLength(qrcodegen_Mode_KANJI, CASES[i].numChars) == CASES[i].result);
8365317bbafSopenharmony_ci			numTestCases++;
8375317bbafSopenharmony_ci		}
8385317bbafSopenharmony_ci	}
8395317bbafSopenharmony_ci	{
8405317bbafSopenharmony_ci		assert(calcSegmentBitLength(qrcodegen_Mode_ECI, 0) == 24);
8415317bbafSopenharmony_ci		numTestCases++;
8425317bbafSopenharmony_ci	}
8435317bbafSopenharmony_ci}
8445317bbafSopenharmony_ci
8455317bbafSopenharmony_ci
8465317bbafSopenharmony_cistatic void testMakeBytes(void) {
8475317bbafSopenharmony_ci	{
8485317bbafSopenharmony_ci		struct qrcodegen_Segment seg = qrcodegen_makeBytes(NULL, 0, NULL);
8495317bbafSopenharmony_ci		assert(seg.mode == qrcodegen_Mode_BYTE);
8505317bbafSopenharmony_ci		assert(seg.numChars == 0);
8515317bbafSopenharmony_ci		assert(seg.bitLength == 0);
8525317bbafSopenharmony_ci		numTestCases++;
8535317bbafSopenharmony_ci	}
8545317bbafSopenharmony_ci	{
8555317bbafSopenharmony_ci		const uint8_t data[] = {0x00};
8565317bbafSopenharmony_ci		uint8_t buf[1];
8575317bbafSopenharmony_ci		struct qrcodegen_Segment seg = qrcodegen_makeBytes(data, 1, buf);
8585317bbafSopenharmony_ci		assert(seg.numChars == 1);
8595317bbafSopenharmony_ci		assert(seg.bitLength == 8);
8605317bbafSopenharmony_ci		assert(seg.data[0] == 0x00);
8615317bbafSopenharmony_ci		numTestCases++;
8625317bbafSopenharmony_ci	}
8635317bbafSopenharmony_ci	{
8645317bbafSopenharmony_ci		const uint8_t data[] = {0xEF, 0xBB, 0xBF};
8655317bbafSopenharmony_ci		uint8_t buf[3];
8665317bbafSopenharmony_ci		struct qrcodegen_Segment seg = qrcodegen_makeBytes(data, 3, buf);
8675317bbafSopenharmony_ci		assert(seg.numChars == 3);
8685317bbafSopenharmony_ci		assert(seg.bitLength == 24);
8695317bbafSopenharmony_ci		assert(seg.data[0] == 0xEF);
8705317bbafSopenharmony_ci		assert(seg.data[1] == 0xBB);
8715317bbafSopenharmony_ci		assert(seg.data[2] == 0xBF);
8725317bbafSopenharmony_ci		numTestCases++;
8735317bbafSopenharmony_ci	}
8745317bbafSopenharmony_ci}
8755317bbafSopenharmony_ci
8765317bbafSopenharmony_ci
8775317bbafSopenharmony_cistatic void testMakeNumeric(void) {
8785317bbafSopenharmony_ci	{
8795317bbafSopenharmony_ci		struct qrcodegen_Segment seg = qrcodegen_makeNumeric("", NULL);
8805317bbafSopenharmony_ci		assert(seg.mode == qrcodegen_Mode_NUMERIC);
8815317bbafSopenharmony_ci		assert(seg.numChars == 0);
8825317bbafSopenharmony_ci		assert(seg.bitLength == 0);
8835317bbafSopenharmony_ci		numTestCases++;
8845317bbafSopenharmony_ci	}
8855317bbafSopenharmony_ci	{
8865317bbafSopenharmony_ci		uint8_t buf[1];
8875317bbafSopenharmony_ci		struct qrcodegen_Segment seg = qrcodegen_makeNumeric("9", buf);
8885317bbafSopenharmony_ci		assert(seg.numChars == 1);
8895317bbafSopenharmony_ci		assert(seg.bitLength == 4);
8905317bbafSopenharmony_ci		assert(seg.data[0] == 0x90);
8915317bbafSopenharmony_ci		numTestCases++;
8925317bbafSopenharmony_ci	}
8935317bbafSopenharmony_ci	{
8945317bbafSopenharmony_ci		uint8_t buf[1];
8955317bbafSopenharmony_ci		struct qrcodegen_Segment seg = qrcodegen_makeNumeric("81", buf);
8965317bbafSopenharmony_ci		assert(seg.numChars == 2);
8975317bbafSopenharmony_ci		assert(seg.bitLength == 7);
8985317bbafSopenharmony_ci		assert(seg.data[0] == 0xA2);
8995317bbafSopenharmony_ci		numTestCases++;
9005317bbafSopenharmony_ci	}
9015317bbafSopenharmony_ci	{
9025317bbafSopenharmony_ci		uint8_t buf[2];
9035317bbafSopenharmony_ci		struct qrcodegen_Segment seg = qrcodegen_makeNumeric("673", buf);
9045317bbafSopenharmony_ci		assert(seg.numChars == 3);
9055317bbafSopenharmony_ci		assert(seg.bitLength == 10);
9065317bbafSopenharmony_ci		assert(seg.data[0] == 0xA8);
9075317bbafSopenharmony_ci		assert(seg.data[1] == 0x40);
9085317bbafSopenharmony_ci		numTestCases++;
9095317bbafSopenharmony_ci	}
9105317bbafSopenharmony_ci	{
9115317bbafSopenharmony_ci		uint8_t buf[5];
9125317bbafSopenharmony_ci		struct qrcodegen_Segment seg = qrcodegen_makeNumeric("3141592653", buf);
9135317bbafSopenharmony_ci		assert(seg.numChars == 10);
9145317bbafSopenharmony_ci		assert(seg.bitLength == 34);
9155317bbafSopenharmony_ci		assert(seg.data[0] == 0x4E);
9165317bbafSopenharmony_ci		assert(seg.data[1] == 0x89);
9175317bbafSopenharmony_ci		assert(seg.data[2] == 0xF4);
9185317bbafSopenharmony_ci		assert(seg.data[3] == 0x24);
9195317bbafSopenharmony_ci		assert(seg.data[4] == 0xC0);
9205317bbafSopenharmony_ci		numTestCases++;
9215317bbafSopenharmony_ci	}
9225317bbafSopenharmony_ci}
9235317bbafSopenharmony_ci
9245317bbafSopenharmony_ci
9255317bbafSopenharmony_cistatic void testMakeAlphanumeric(void) {
9265317bbafSopenharmony_ci	{
9275317bbafSopenharmony_ci		struct qrcodegen_Segment seg = qrcodegen_makeAlphanumeric("", NULL);
9285317bbafSopenharmony_ci		assert(seg.mode == qrcodegen_Mode_ALPHANUMERIC);
9295317bbafSopenharmony_ci		assert(seg.numChars == 0);
9305317bbafSopenharmony_ci		assert(seg.bitLength == 0);
9315317bbafSopenharmony_ci		numTestCases++;
9325317bbafSopenharmony_ci	}
9335317bbafSopenharmony_ci	{
9345317bbafSopenharmony_ci		uint8_t buf[1];
9355317bbafSopenharmony_ci		struct qrcodegen_Segment seg = qrcodegen_makeAlphanumeric("A", buf);
9365317bbafSopenharmony_ci		assert(seg.numChars == 1);
9375317bbafSopenharmony_ci		assert(seg.bitLength == 6);
9385317bbafSopenharmony_ci		assert(seg.data[0] == 0x28);
9395317bbafSopenharmony_ci		numTestCases++;
9405317bbafSopenharmony_ci	}
9415317bbafSopenharmony_ci	{
9425317bbafSopenharmony_ci		uint8_t buf[2];
9435317bbafSopenharmony_ci		struct qrcodegen_Segment seg = qrcodegen_makeAlphanumeric("%:", buf);
9445317bbafSopenharmony_ci		assert(seg.numChars == 2);
9455317bbafSopenharmony_ci		assert(seg.bitLength == 11);
9465317bbafSopenharmony_ci		assert(seg.data[0] == 0xDB);
9475317bbafSopenharmony_ci		assert(seg.data[1] == 0x40);
9485317bbafSopenharmony_ci		numTestCases++;
9495317bbafSopenharmony_ci	}
9505317bbafSopenharmony_ci	{
9515317bbafSopenharmony_ci		uint8_t buf[3];
9525317bbafSopenharmony_ci		struct qrcodegen_Segment seg = qrcodegen_makeAlphanumeric("Q R", buf);
9535317bbafSopenharmony_ci		assert(seg.numChars == 3);
9545317bbafSopenharmony_ci		assert(seg.bitLength == 17);
9555317bbafSopenharmony_ci		assert(seg.data[0] == 0x96);
9565317bbafSopenharmony_ci		assert(seg.data[1] == 0xCD);
9575317bbafSopenharmony_ci		assert(seg.data[2] == 0x80);
9585317bbafSopenharmony_ci		numTestCases++;
9595317bbafSopenharmony_ci	}
9605317bbafSopenharmony_ci}
9615317bbafSopenharmony_ci
9625317bbafSopenharmony_ci
9635317bbafSopenharmony_cistatic void testMakeEci(void) {
9645317bbafSopenharmony_ci	{
9655317bbafSopenharmony_ci		uint8_t buf[1];
9665317bbafSopenharmony_ci		struct qrcodegen_Segment seg = qrcodegen_makeEci(127, buf);
9675317bbafSopenharmony_ci		assert(seg.mode == qrcodegen_Mode_ECI);
9685317bbafSopenharmony_ci		assert(seg.numChars == 0);
9695317bbafSopenharmony_ci		assert(seg.bitLength == 8);
9705317bbafSopenharmony_ci		assert(seg.data[0] == 0x7F);
9715317bbafSopenharmony_ci		numTestCases++;
9725317bbafSopenharmony_ci	}
9735317bbafSopenharmony_ci	{
9745317bbafSopenharmony_ci		uint8_t buf[2];
9755317bbafSopenharmony_ci		struct qrcodegen_Segment seg = qrcodegen_makeEci(10345, buf);
9765317bbafSopenharmony_ci		assert(seg.numChars == 0);
9775317bbafSopenharmony_ci		assert(seg.bitLength == 16);
9785317bbafSopenharmony_ci		assert(seg.data[0] == 0xA8);
9795317bbafSopenharmony_ci		assert(seg.data[1] == 0x69);
9805317bbafSopenharmony_ci		numTestCases++;
9815317bbafSopenharmony_ci	}
9825317bbafSopenharmony_ci	{
9835317bbafSopenharmony_ci		uint8_t buf[3];
9845317bbafSopenharmony_ci		struct qrcodegen_Segment seg = qrcodegen_makeEci(999999, buf);
9855317bbafSopenharmony_ci		assert(seg.numChars == 0);
9865317bbafSopenharmony_ci		assert(seg.bitLength == 24);
9875317bbafSopenharmony_ci		assert(seg.data[0] == 0xCF);
9885317bbafSopenharmony_ci		assert(seg.data[1] == 0x42);
9895317bbafSopenharmony_ci		assert(seg.data[2] == 0x3F);
9905317bbafSopenharmony_ci		numTestCases++;
9915317bbafSopenharmony_ci	}
9925317bbafSopenharmony_ci}
9935317bbafSopenharmony_ci
9945317bbafSopenharmony_ci
9955317bbafSopenharmony_cistatic void testGetTotalBits(void) {
9965317bbafSopenharmony_ci	{
9975317bbafSopenharmony_ci		assert(getTotalBits(NULL, 0, 1) == 0);
9985317bbafSopenharmony_ci		numTestCases++;
9995317bbafSopenharmony_ci		assert(getTotalBits(NULL, 0, 40) == 0);
10005317bbafSopenharmony_ci		numTestCases++;
10015317bbafSopenharmony_ci	}
10025317bbafSopenharmony_ci	{
10035317bbafSopenharmony_ci		struct qrcodegen_Segment segs[] = {
10045317bbafSopenharmony_ci			{qrcodegen_Mode_BYTE, 3, NULL, 24},
10055317bbafSopenharmony_ci		};
10065317bbafSopenharmony_ci		assert(getTotalBits(segs, ARRAY_LENGTH(segs), 2) == 36);
10075317bbafSopenharmony_ci		numTestCases++;
10085317bbafSopenharmony_ci		assert(getTotalBits(segs, ARRAY_LENGTH(segs), 10) == 44);
10095317bbafSopenharmony_ci		numTestCases++;
10105317bbafSopenharmony_ci		assert(getTotalBits(segs, ARRAY_LENGTH(segs), 39) == 44);
10115317bbafSopenharmony_ci		numTestCases++;
10125317bbafSopenharmony_ci	}
10135317bbafSopenharmony_ci	{
10145317bbafSopenharmony_ci		struct qrcodegen_Segment segs[] = {
10155317bbafSopenharmony_ci			{qrcodegen_Mode_ECI, 0, NULL, 8},
10165317bbafSopenharmony_ci			{qrcodegen_Mode_NUMERIC, 7, NULL, 24},
10175317bbafSopenharmony_ci			{qrcodegen_Mode_ALPHANUMERIC, 1, NULL, 6},
10185317bbafSopenharmony_ci			{qrcodegen_Mode_KANJI, 4, NULL, 52},
10195317bbafSopenharmony_ci		};
10205317bbafSopenharmony_ci		assert(getTotalBits(segs, ARRAY_LENGTH(segs), 9) == 133);
10215317bbafSopenharmony_ci		numTestCases++;
10225317bbafSopenharmony_ci		assert(getTotalBits(segs, ARRAY_LENGTH(segs), 21) == 139);
10235317bbafSopenharmony_ci		numTestCases++;
10245317bbafSopenharmony_ci		assert(getTotalBits(segs, ARRAY_LENGTH(segs), 27) == 145);
10255317bbafSopenharmony_ci		numTestCases++;
10265317bbafSopenharmony_ci	}
10275317bbafSopenharmony_ci	{
10285317bbafSopenharmony_ci		struct qrcodegen_Segment segs[] = {
10295317bbafSopenharmony_ci			{qrcodegen_Mode_BYTE, 4093, NULL, 32744},
10305317bbafSopenharmony_ci		};
10315317bbafSopenharmony_ci		assert(getTotalBits(segs, ARRAY_LENGTH(segs), 1) == -1);
10325317bbafSopenharmony_ci		numTestCases++;
10335317bbafSopenharmony_ci		assert(getTotalBits(segs, ARRAY_LENGTH(segs), 10) == 32764);
10345317bbafSopenharmony_ci		numTestCases++;
10355317bbafSopenharmony_ci		assert(getTotalBits(segs, ARRAY_LENGTH(segs), 27) == 32764);
10365317bbafSopenharmony_ci		numTestCases++;
10375317bbafSopenharmony_ci	}
10385317bbafSopenharmony_ci	{
10395317bbafSopenharmony_ci		struct qrcodegen_Segment segs[] = {
10405317bbafSopenharmony_ci			{qrcodegen_Mode_NUMERIC, 2047, NULL, 6824},
10415317bbafSopenharmony_ci			{qrcodegen_Mode_NUMERIC, 2047, NULL, 6824},
10425317bbafSopenharmony_ci			{qrcodegen_Mode_NUMERIC, 2047, NULL, 6824},
10435317bbafSopenharmony_ci			{qrcodegen_Mode_NUMERIC, 2047, NULL, 6824},
10445317bbafSopenharmony_ci			{qrcodegen_Mode_NUMERIC, 1617, NULL, 5390},
10455317bbafSopenharmony_ci		};
10465317bbafSopenharmony_ci		assert(getTotalBits(segs, ARRAY_LENGTH(segs), 1) == -1);
10475317bbafSopenharmony_ci		numTestCases++;
10485317bbafSopenharmony_ci		assert(getTotalBits(segs, ARRAY_LENGTH(segs), 10) == 32766);
10495317bbafSopenharmony_ci		numTestCases++;
10505317bbafSopenharmony_ci		assert(getTotalBits(segs, ARRAY_LENGTH(segs), 27) == -1);
10515317bbafSopenharmony_ci		numTestCases++;
10525317bbafSopenharmony_ci	}
10535317bbafSopenharmony_ci	{
10545317bbafSopenharmony_ci		struct qrcodegen_Segment segs[] = {
10555317bbafSopenharmony_ci			{qrcodegen_Mode_KANJI, 255, NULL, 3315},
10565317bbafSopenharmony_ci			{qrcodegen_Mode_KANJI, 255, NULL, 3315},
10575317bbafSopenharmony_ci			{qrcodegen_Mode_KANJI, 255, NULL, 3315},
10585317bbafSopenharmony_ci			{qrcodegen_Mode_KANJI, 255, NULL, 3315},
10595317bbafSopenharmony_ci			{qrcodegen_Mode_KANJI, 255, NULL, 3315},
10605317bbafSopenharmony_ci			{qrcodegen_Mode_KANJI, 255, NULL, 3315},
10615317bbafSopenharmony_ci			{qrcodegen_Mode_KANJI, 255, NULL, 3315},
10625317bbafSopenharmony_ci			{qrcodegen_Mode_KANJI, 255, NULL, 3315},
10635317bbafSopenharmony_ci			{qrcodegen_Mode_KANJI, 255, NULL, 3315},
10645317bbafSopenharmony_ci			{qrcodegen_Mode_ALPHANUMERIC, 511, NULL, 2811},
10655317bbafSopenharmony_ci		};
10665317bbafSopenharmony_ci		assert(getTotalBits(segs, ARRAY_LENGTH(segs), 9) == 32767);
10675317bbafSopenharmony_ci		numTestCases++;
10685317bbafSopenharmony_ci		assert(getTotalBits(segs, ARRAY_LENGTH(segs), 26) == -1);
10695317bbafSopenharmony_ci		numTestCases++;
10705317bbafSopenharmony_ci		assert(getTotalBits(segs, ARRAY_LENGTH(segs), 40) == -1);
10715317bbafSopenharmony_ci		numTestCases++;
10725317bbafSopenharmony_ci	}
10735317bbafSopenharmony_ci}
10745317bbafSopenharmony_ci
10755317bbafSopenharmony_ci
10765317bbafSopenharmony_ci/*---- Main runner ----*/
10775317bbafSopenharmony_ci
10785317bbafSopenharmony_ciint main(void) {
10795317bbafSopenharmony_ci	srand((unsigned int)time(NULL));
10805317bbafSopenharmony_ci	testAppendBitsToBuffer();
10815317bbafSopenharmony_ci	testAddEccAndInterleave();
10825317bbafSopenharmony_ci	testGetNumDataCodewords();
10835317bbafSopenharmony_ci	testGetNumRawDataModules();
10845317bbafSopenharmony_ci	testReedSolomonComputeDivisor();
10855317bbafSopenharmony_ci	testReedSolomonComputeRemainder();
10865317bbafSopenharmony_ci	testReedSolomonMultiply();
10875317bbafSopenharmony_ci	testInitializeFunctionModulesEtc();
10885317bbafSopenharmony_ci	testGetAlignmentPatternPositions();
10895317bbafSopenharmony_ci	testGetSetModule();
10905317bbafSopenharmony_ci	testGetSetModuleRandomly();
10915317bbafSopenharmony_ci	testIsAlphanumeric();
10925317bbafSopenharmony_ci	testIsNumeric();
10935317bbafSopenharmony_ci	testCalcSegmentBufferSize();
10945317bbafSopenharmony_ci	testCalcSegmentBitLength();
10955317bbafSopenharmony_ci	testMakeBytes();
10965317bbafSopenharmony_ci	testMakeNumeric();
10975317bbafSopenharmony_ci	testMakeAlphanumeric();
10985317bbafSopenharmony_ci	testMakeEci();
10995317bbafSopenharmony_ci	testGetTotalBits();
11005317bbafSopenharmony_ci	printf("All %d test cases passed\n", numTestCases);
11015317bbafSopenharmony_ci	return EXIT_SUCCESS;
11025317bbafSopenharmony_ci}
1103