parent
1a0e166f55
commit
0c958326c6
@ -0,0 +1,43 @@
|
|||||||
|
#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;
|
||||||
|
};
|
||||||
|
|
||||||
Loading…
Reference in new issue