SWE-350 TOTP Generator Milestone 5
The DE-10 board has six 7-segment displays, this can be used to display and generate a time based one-time pin (TOTP).
Loading...
Searching...
No Matches
run-tests.cpp
Go to the documentation of this file.
1#include <iostream>
2#include <string>
3
4#include "../src/qrcode.h"
5#include "QrCode.hpp"
6
7static uint32_t check(const qrcodegen::QrCode &nayuki, QRCode *ricmoo) {
8 uint32_t wrong = 0;
9
10 if (nayuki.size != ricmoo->size) { wrong += (1 << 20); }
11
12 int border = 4;
13 for (int y = -border; y < nayuki.size + border; y++) {
14 for (int x = -border; x < nayuki.size + border; x++) {
15 if (!!nayuki.getModule(x, y) != qrcode_getModule(ricmoo, x, y)) {
16 wrong++;
17 }
18 }
19 }
20
21 return wrong;
22}
23
24int main() {
25 std::clock_t t0, totalNayuki, totalRicMoo;
26
27 int total = 0, passed = 0;
28 for (char version = 1; version <= 40; version++) {
29 if (LOCK_VERSION != 0 && LOCK_VERSION != version) { continue; }
30
31 for (char ecc = 0; ecc < 4; ecc++) {
32 const qrcodegen::QrCode::Ecc *errCorLvl;
33 switch (ecc) {
34 case 0:
35 errCorLvl = &qrcodegen::QrCode::Ecc::LOW;
36 break;
37 case 1:
39 break;
40 case 2:
42 break;
43 case 3:
45 break;
46 }
47
48 for (char tc = 0; tc < 3; tc++) {
49 char *data;
50 switch(tc) {
51 case 0:
52 data = (char*)"HELLO";
53 break;
54 case 1:
55 data = (char*)"Hello";
56 break;
57 case 2:
58 data = (char*)"1234";
59 break;
60 }
61 t0 = std::clock();
62 const qrcodegen::QrCode nayuki = qrcodegen::QrCode::encodeText(data, version, *errCorLvl);
63 totalNayuki += std::clock() - t0;
64
65 t0 = std::clock();
66 QRCode ricmoo;
67 uint8_t ricmooBytes[qrcode_getBufferSize(version)];
68 qrcode_initText(&ricmoo, ricmooBytes, version, ecc, data);
69 totalRicMoo += std::clock() - t0;
70
71 uint32_t badModules = check(nayuki, &ricmoo);
72 if (badModules) {
73 printf("Failed test case: version=%d, ecc=%d, data=\"%s\", faliured=%d\n", version, ecc, data, badModules);
74 } else {
75 passed++;
76 }
77
78 total++;
79 }
80 }
81 }
82
83 printf("Tests complete: %d passed (out of %d)\n", passed, total);
84 printf("Timing: Nayuki=%lu, RicMoo=%lu\n", totalNayuki, totalRicMoo);
85}
static const Ecc LOW
Definition QrCode.hpp:52
static const Ecc QUARTILE
Definition QrCode.hpp:52
static const Ecc HIGH
Definition QrCode.hpp:52
static const Ecc MEDIUM
Definition QrCode.hpp:52
static QrCode encodeText(const char *text, int version, const Ecc &ecl)
Definition QrCode.cpp:45
const int size
Definition QrCode.hpp:109
int getModule(int x, int y) const
Definition QrCode.cpp:158
bool qrcode_getModule(QRCode *qrcode, uint8_t x, uint8_t y)
Definition qrcode.c:860
uint16_t qrcode_getBufferSize(uint8_t version)
Definition qrcode.c:775
int8_t qrcode_initText(QRCode *qrcode, uint8_t *modules, uint8_t version, uint8_t ecc, const char *data)
Definition qrcode.c:856
#define LOCK_VERSION
Definition qrcode.h:64
int main()
Definition run-tests.cpp:24
uint8_t size
Definition qrcode.h:70