void test_encodeLongData(void) { QRinput *stream; unsigned char data[7090]; int maxlength[4][4] = {{7089,5596,3993,3057}, {4296,3391,2420,1852}, {2953,2331,1663,1273}, {1817*2,1435*2,1024*2, 784*2}}; int i, l, len, ret; QRcode *qrcode; testStart("Encoding long data."); for(i=QR_MODE_NUM; i<=QR_MODE_KANJI; i++) { if(i != QR_MODE_KANJI) { memset(data, '0', maxlength[i][0] + 1); } else { for(l=0; l<=maxlength[i][0]/2+1; l++) { data[l*2] = 0x93; data[l*2+1] = 0x5f; } } for(l=QR_ECLEVEL_L; l<=QR_ECLEVEL_H; l++) { stream = QRinput_new2(0, l); ret = QRinput_append(stream, i, maxlength[i][l], data); assert_zero(ret, "Failed to add %d-byte %s to a QRinput\n", maxlength[i][l], modeStr[i]); qrcode = QRcode_encodeInput(stream); assert_nonnull(qrcode, "(QRcode_encodeInput) failed to encode %d-byte %s in level %d.\n", maxlength[i][l], modeStr[i], l); if(qrcode != NULL) { QRcode_free(qrcode); } QRinput_free(stream); stream = QRinput_new2(0, l); len = maxlength[i][l]; if(i == QR_MODE_KANJI) { len += 2; } else { len += 1; } ret = QRinput_append(stream, i, len, data); if(ret == 0) { qrcode = QRcode_encodeInput(stream); assert_null(qrcode, "(QRcode_encodeInput) incorrectly succeeded to encode %d-byte %s in level %d.\n", len, modeStr[i], l); if(qrcode != NULL) { printf("version: %d\n", qrcode->version); QRcode_free(qrcode); } } QRinput_free(stream); } } testFinish(); }
QRcode_List *QRcode_encodeInputStructured(QRinput_Struct *s) { QRcode_List *head = NULL; QRcode_List *tail = NULL; QRcode_List *entry; QRinput_InputList *list = s->head; while(list != NULL) { if(head == NULL) { entry = QRcode_List_newEntry(); if(entry == NULL) goto ABORT; head = entry; tail = head; } else { entry = QRcode_List_newEntry(); if(entry == NULL) goto ABORT; tail->next = entry; tail = tail->next; } tail->code = QRcode_encodeInput(list->input); if(tail->code == NULL) { goto ABORT; } list = list->next; } return head; ABORT: QRcode_List_free(head); return NULL; }
QRcode *QRcode_encodeString(const char *string, int version, QRecLevel level, QRencodeMode hint, int casesensitive) { QRinput *input; QRcode *code; int ret; if(hint != QR_MODE_8 && hint != QR_MODE_KANJI) { errno = EINVAL; return NULL; } input = QRinput_new2(version, level); if(input == NULL) return NULL; ret = Split_splitStringToQRinput(string, input, hint, casesensitive); if(ret < 0) { QRinput_free(input); return NULL; } code = QRcode_encodeInput(input); QRinput_free(input); return code; }
static QRcode *QRcode_encodeDataReal(const unsigned char *data, int length, int version, QRecLevel level, int mqr) { QRinput *input; QRcode *code; int ret; if(data == NULL || length == 0) { errno = EINVAL; return NULL; } if(mqr) { input = QRinput_newMQR(version, level); } else { input = QRinput_new2(version, level); } if(input == NULL) return NULL; ret = QRinput_append(input, QR_MODE_8, length, data); if(ret < 0) { QRinput_free(input); return NULL; } code = QRcode_encodeInput(input); QRinput_free(input); return code; }
void print_01234567(void) { QRinput *stream; char num[9] = "01234567"; QRcode *qrcode; stream = QRinput_new2(1, QR_ECLEVEL_M); QRinput_append(stream, QR_MODE_NUM, 8, (unsigned char *)num); qrcode = QRcode_encodeInput(stream); printQRcode(qrcode); QRinput_free(stream); QRcode_free(qrcode); }
void test_invalid_input(void) { QRinput *input; QRcode *code; testStart("Testing invalid input."); input = QRinput_new(); QRinput_append(input, QR_MODE_AN, 5, (unsigned char *)"TEST1"); input->version = -1; input->level = QR_ECLEVEL_L; code = QRcode_encodeInput(input); assert_null(code, "invalid version(-1) was not checked.\n"); if(code != NULL) QRcode_free(code); input->version = 41; input->level = QR_ECLEVEL_L; code = QRcode_encodeInput(input); assert_null(code, "invalid version(41) access was not checked.\n"); if(code != NULL) QRcode_free(code); input->version = 1; input->level = (QRecLevel)(QR_ECLEVEL_H + 1); code = QRcode_encodeInput(input); assert_null(code, "invalid level(H+1) access was not checked.\n"); if(code != NULL) QRcode_free(code); input->version = 1; input->level = (QRecLevel)-1; code = QRcode_encodeInput(input); assert_null(code, "invalid level(-1) access was not checked.\n"); if(code != NULL) QRcode_free(code); QRinput_free(input); testFinish(); }
void test_encode3(void) { QRcode *code1, *code2; QRinput *input; testStart("Compare encodeString and encodeInput"); code1 = QRcode_encodeString("0123456", 0, QR_ECLEVEL_L, QR_MODE_8, 0); input = QRinput_new2(0, QR_ECLEVEL_L); QRinput_append(input, QR_MODE_NUM, 7, (unsigned char *)"0123456"); code2 = QRcode_encodeInput(input); testEnd(memcmp(code1->data, code2->data, code1->width * code1->width)); QRcode_free(code1); QRcode_free(code2); QRinput_free(input); }
void test_01234567(void) { QRinput *stream; char num[9] = "01234567"; int i, err = 0; QRcode *qrcode; unsigned char correct[] = { 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0xc0, 0x84, 0x03, 0x02, 0x03, 0x03, 0xc0, 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc1, 0xc0, 0x84, 0x03, 0x03, 0x03, 0x03, 0xc0, 0xc1, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc1, 0xc1, 0xc0, 0xc1, 0xc1, 0xc1, 0xc0, 0xc1, 0xc0, 0x85, 0x02, 0x02, 0x02, 0x02, 0xc0, 0xc1, 0xc0, 0xc1, 0xc1, 0xc1, 0xc0, 0xc1, 0xc1, 0xc0, 0xc1, 0xc1, 0xc1, 0xc0, 0xc1, 0xc0, 0x85, 0x03, 0x02, 0x02, 0x02, 0xc0, 0xc1, 0xc0, 0xc1, 0xc1, 0xc1, 0xc0, 0xc1, 0xc1, 0xc0, 0xc1, 0xc1, 0xc1, 0xc0, 0xc1, 0xc0, 0x85, 0x02, 0x03, 0x03, 0x03, 0xc0, 0xc1, 0xc0, 0xc1, 0xc1, 0xc1, 0xc0, 0xc1, 0xc1, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc1, 0xc0, 0x85, 0x02, 0x02, 0x02, 0x03, 0xc0, 0xc1, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0xc0, 0x91, 0x90, 0x91, 0x90, 0x91, 0xc0, 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x85, 0x02, 0x02, 0x03, 0x03, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x85, 0x84, 0x85, 0x85, 0x85, 0x85, 0x91, 0x84, 0x84, 0x03, 0x02, 0x02, 0x03, 0x84, 0x85, 0x85, 0x85, 0x85, 0x85, 0x84, 0x84, 0x02, 0x02, 0x02, 0x03, 0x02, 0x03, 0x90, 0x03, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02, 0x02, 0x03, 0x02, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x03, 0x02, 0x02, 0x02, 0x91, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x03, 0x02, 0x90, 0x02, 0x02, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x91, 0x03, 0x03, 0x02, 0x02, 0x03, 0x02, 0x03, 0x02, 0x02, 0x03, 0x02, 0x02, 0x02, 0x02, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x81, 0x02, 0x03, 0x03, 0x03, 0x03, 0x03, 0x02, 0x02, 0x03, 0x03, 0x02, 0x02, 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0xc0, 0x84, 0x03, 0x03, 0x02, 0x03, 0x02, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0xc1, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc1, 0xc0, 0x85, 0x02, 0x03, 0x03, 0x03, 0x03, 0x03, 0x02, 0x02, 0x02, 0x03, 0x02, 0x03, 0xc1, 0xc0, 0xc1, 0xc1, 0xc1, 0xc0, 0xc1, 0xc0, 0x85, 0x02, 0x02, 0x02, 0x03, 0x02, 0x02, 0x03, 0x02, 0x03, 0x03, 0x02, 0x02, 0xc1, 0xc0, 0xc1, 0xc1, 0xc1, 0xc0, 0xc1, 0xc0, 0x85, 0x03, 0x02, 0x02, 0x03, 0x02, 0x02, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0xc1, 0xc0, 0xc1, 0xc1, 0xc1, 0xc0, 0xc1, 0xc0, 0x85, 0x02, 0x03, 0x03, 0x02, 0x03, 0x02, 0x02, 0x03, 0x02, 0x03, 0x02, 0x02, 0xc1, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc1, 0xc0, 0x84, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x02, 0x03, 0x03, 0x02, 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0xc0, 0x85, 0x03, 0x03, 0x03, 0x02, 0x03, 0x02, 0x02, 0x03, 0x02, 0x03, 0x02, 0x02}; testStart("Encode 01234567 in 1-M"); stream = QRinput_new2(1, QR_ECLEVEL_M); QRinput_append(stream, QR_MODE_NUM, 8, (unsigned char *)num); qrcode = QRcode_encodeInput(stream); for(i=0; i<qrcode->width * qrcode->width; i++) { if(qrcode->data[i] != correct[i]) { err++; } } testEnd(err); QRinput_free(stream); QRcode_free(qrcode); }
QRcode *QRcode_encodeString8bit(const char *string, int version, QRecLevel level) { QRinput *input; QRcode *code; int ret; if(string == NULL) { errno = EINVAL; return NULL; } input = QRinput_new2(version, level); if(input == NULL) return NULL; ret = QRinput_append(input, QR_MODE_8, strlen(string), (unsigned char *)string); if(ret < 0) { QRinput_free(input); return NULL; } code = QRcode_encodeInput(input); QRinput_free(input); return code; }