You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.2 KiB

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "UDPTCPNetwork.h"
int main(int argc, char **argv) {
std::string encoded = "TnVyIGVpbiBUZXN0Pw==";
std::string text = "Nur ein Test?";
std::string temp;
int result, i;
char *buffer = (char*) malloc(256);
int bufferlen = 256;
//
// test decoding
if (base64decode(encoded, &buffer, &bufferlen) == 0)
debug ("************* error on base64decode");
else {
if (bufferlen+1 < 256) {
buffer[bufferlen] = 0;
debug (" decode: %s (%d bytes)", buffer, bufferlen);
}
for (i=0, result = 1; result && i < bufferlen && i < text.length(); i++)
if (buffer[i] != text[i]) result = 0;
debug ("base64decode ----------------------------> %s", (result == 1 ? "OK" : "FAILED"));
}
//
// test encode
if (base64encode((char *)text.c_str(), strlen(text.c_str()), &temp, 0) == 0)
debug ("************* error on base64decode");
else {
debug (" encode: %s", temp.c_str());
debug (" : %s", encoded.c_str());
debug ("base64encode ----------------------------> %s", (encoded.compare(temp) == 0) ? "OK" : "FAILED");
}
return 0;
};