Skip to content

Commit

Permalink
Add a few more tests. Debugging l problem.:
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkx committed Apr 2, 2021
1 parent 14cb92c commit 9476dd5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ INC_FLAGS :=

CPPFLAGS ?= $(INC_FLAGS) -MMD -MP

tests: all
for i in 1 7 13 10 103 1002 10009 100007 1000001 0; do \
tests: all $(TARGET_TEST)
./test
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 17 19 41 42 43 103 1002 10009 100007 1000001 0; do \
openssl rand $$i > $$TMPDIR/x; \
cat $$TMPDIR/x | ./base45 | ./base45 -d > $$TMPDIR/y; \
diff $$TMPDIR/x $$TMPDIR/y || exit 1; \
done; \
rm $$TMPDIR/x $$TMPDIR/y

all: $(TARGET_EXEC) $(TARGET_LIB)
all: $(TARGET_EXEC) $(TARGET_LIB)

$(TARGET_EXEC): $(SRCS)
$(CC) $(SRCS) -DBASE45_UTIL -o $@ $(LDFLAGS)
Expand Down
10 changes: 8 additions & 2 deletions test.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@
#include "base45.h"

void check(char * in, char * out) {
char enc[0124];
char enc[1024];
unsigned char dec[1024];
size_t elen = sizeof(enc), dlen = sizeof(dec);
bzero(enc,1024);
bzero(dec,1024);

assert(0 == base45_encode(enc, &elen, (const unsigned char*) in, strlen(in)));
assert(elen == strlen(out));
assert(0 == strcmp(enc,out));

assert(0 == base45_decode(dec, &dlen, out, strlen(out)));
assert(0 == base45_decode(dec, &dlen, out, strlen(out)));
assert(dlen == strlen(in));
for(int i = 0; i < dlen; i++) printf("%d %d %c %c %d\n", i, dec[i],dec[i],in[i],in[i]);
assert(0 == bcmp(dec,in,dlen));

printf("base64(\"%s\") -> \"%s\"\n", (char*)dec, enc);
Expand All @@ -25,4 +28,7 @@ int main(int argc, char **argv) {
check("Hello!!","%69 VD92EX0");
check("base-45","UJCLQE7W581");
check("ietf!","QED8WEX0");
check("COVID-19","-M8*+A%R81A6");
check("2021 Digital Green Certificates for travel",
"NF6OF6P34SED-EDAECS34ZKE1$CO345$CBWER.CGPC7WE.OEX.CBJEKWEKEC: C");
};

0 comments on commit 9476dd5

Please sign in to comment.