unit: Add test/base64.cc

Signed-off-by: Colin McCabe <colinm@hq.newdream.net>
This commit is contained in:
Colin Patrick McCabe 2011-01-13 10:23:49 -08:00
parent 983e62c81d
commit e7153f383f
2 changed files with 51 additions and 5 deletions

View File

@ -315,15 +315,26 @@ endif
# target to build but not run the unit tests
unittests:: $(check_PROGRAMS)
unittest_encoding_SOURCES = test/encoding.cc
unittest_encoding_LDADD = libceph.la libcrush.la -lpthread -lm -lcrypto \
$(top_builddir)/src/gtest/lib/libgtest.la \
$(top_builddir)/src/gtest/lib/libgtest_main.la
unittest_encoding_CPPFLAGS = \
UNITTEST_CFLAGS = \
-I$(top_srcdir)/src/gtest/include \
-I$(top_builddir)/src/gtest/include
UNITTEST_LDADD = \
$(top_builddir)/src/gtest/lib/libgtest.la \
$(top_builddir)/src/gtest/lib/libgtest_main.la
unittest_encoding_SOURCES = test/encoding.cc
unittest_encoding_LDADD = libceph.la libcrush.la -lpthread -lm -lcrypto \
${UNITTEST_LDADD}
unittest_encoding_CPPFLAGS = ${AM_CFLAGS} ${UNITTEST_CFLAGS}
check_PROGRAMS += unittest_encoding
unittest_base64_SOURCES = test/base64.cc
unittest_base64_LDFLAGS = -pthread
unittest_base64_LDADD = libceph.la libcrush.la -lpthread -lm -lcrypto \
${UNITTEST_LDADD}
unittest_base64_CPPFLAGS = ${AM_CFLAGS} ${UNITTEST_CFLAGS}
check_PROGRAMS += unittest_base64
# shell scripts
editpaths = sed \
-e 's|@bindir[@]|$(bindir)|g' \

35
src/test/base64.cc Normal file
View File

@ -0,0 +1,35 @@
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
/*
* Ceph - scalable distributed file system
*
* Copyright (C) 2011 Dreamhost
*
* This is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software
* Foundation. See file COPYING.
*
*/
#include "common/armor.h"
#include "config.h"
#include "include/buffer.h"
#include "include/encoding.h"
#include "gtest/gtest.h"
TEST(CorrectBase64Encoding, StringSimple) {
static const int OUT_LEN = 4096;
const char * const original = "abracadabra";
const char * const correctly_encoded = "YWJyYWNhZGFicmE=";
char out[OUT_LEN];
memset(out, 0, sizeof(out));
int alen = ceph_armor(out, out + OUT_LEN, original, original + strlen(original));
ASSERT_STREQ(correctly_encoded, out);
char out2[OUT_LEN];
memset(out2, 0, sizeof(out2));
ceph_unarmor(out2, out2 + OUT_LEN, out, out + alen);
ASSERT_STREQ(original, out2);
}