From e7153f383f8a6e4b32f8a38809b2023799bab3b7 Mon Sep 17 00:00:00 2001 From: Colin Patrick McCabe Date: Thu, 13 Jan 2011 10:23:49 -0800 Subject: [PATCH] unit: Add test/base64.cc Signed-off-by: Colin McCabe --- src/Makefile.am | 21 ++++++++++++++++----- src/test/base64.cc | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 src/test/base64.cc diff --git a/src/Makefile.am b/src/Makefile.am index 133afd3923ea9..06dfca39dba8c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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' \ diff --git a/src/test/base64.cc b/src/test/base64.cc new file mode 100644 index 0000000000000..0612bfa207f1d --- /dev/null +++ b/src/test/base64.cc @@ -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); +} -- 2.39.5