Files
clang-p2996/compiler-rt/test/sanitizer_common/TestCases/Linux/b64.cpp
Kevin Athey 6dce56b2a3 [Driver] add -lresolv for all but Android.
As there 3 intercepts that depend on libresolv, link tests in ./configure scripts may be confuse by the presence of resolv symbols (i.e. dn_expand) even with -lresolv and get a runtime error.

Android provides the functionality in libc.

https://reviews.llvm.org/D122849
https://reviews.llvm.org/D126851

Reviewed By: eugenis, MaskRay

Differential Revision: https://reviews.llvm.org/D127145
2022-06-06 15:49:42 -07:00

43 lines
1.2 KiB
C++

// RUN: %clangxx %s -o %t && %run %t %p
#include <assert.h>
#include <resolv.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
int main(int iArgc, char *szArgv[]) {
// Check NTOP writing
const char *src = "base64 test data";
size_t src_len = strlen(src);
size_t dst_len = ((src_len + 2) / 3) * 4 + 1;
char dst[dst_len];
int res = b64_ntop(reinterpret_cast<const unsigned char *>(src), src_len, dst,
dst_len);
assert(res >= 0);
assert(strcmp(dst, "YmFzZTY0IHRlc3QgZGF0YQ==") == 0);
// Check PTON writing
unsigned char target[dst_len];
res = b64_pton(dst, target, dst_len);
assert(res >= 0);
assert(strncmp(reinterpret_cast<const char *>(target), src, res) == 0);
// Check NTOP writing for zero length src
src = "";
src_len = strlen(src);
assert(((src_len + 2) / 3) * 4 + 1 < dst_len);
res = b64_ntop(reinterpret_cast<const unsigned char *>(src), src_len, dst,
dst_len);
assert(res >= 0);
assert(strcmp(dst, "") == 0);
// Check PTON writing for zero length src
dst[0] = '\0';
res = b64_pton(dst, target, dst_len);
assert(res >= 0);
assert(strncmp(reinterpret_cast<const char *>(target), src, res) == 0);
return 0;
}