diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2011-11-16 16:06:07 -0600 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2011-11-16 16:06:07 -0600 |
commit | be0ca741fd12897337408d1d7a7d8f5f18e1fac9 (patch) | |
tree | b9fa3458193a17180d8773a0204ee05ae206cd99 /libtdenetwork/qgpgme/tests | |
parent | bbb7afdb6da2969535e7f05715e2cb95cfdc917c (diff) | |
download | tdepim-be0ca741fd12897337408d1d7a7d8f5f18e1fac9.tar.gz tdepim-be0ca741fd12897337408d1d7a7d8f5f18e1fac9.zip |
Finish rename from prior commit
Diffstat (limited to 'libtdenetwork/qgpgme/tests')
-rw-r--r-- | libtdenetwork/qgpgme/tests/Makefile.am | 9 | ||||
-rw-r--r-- | libtdenetwork/qgpgme/tests/dataprovidertest.cpp | 125 |
2 files changed, 134 insertions, 0 deletions
diff --git a/libtdenetwork/qgpgme/tests/Makefile.am b/libtdenetwork/qgpgme/tests/Makefile.am new file mode 100644 index 000000000..5c2436d04 --- /dev/null +++ b/libtdenetwork/qgpgme/tests/Makefile.am @@ -0,0 +1,9 @@ +INCLUDES = -I$(top_srcdir)/libtdenetwork $(GPGME_CFLAGS) $(all_includes) + +check_PROGRAMS = dataprovidertest + +TESTS = $(check_PROGRAMS) + +dataprovidertest_SOURCES = dataprovidertest.cpp + +LDADD = ../libqgpgme.la #?$(LIB_QT) diff --git a/libtdenetwork/qgpgme/tests/dataprovidertest.cpp b/libtdenetwork/qgpgme/tests/dataprovidertest.cpp new file mode 100644 index 000000000..675c85ea8 --- /dev/null +++ b/libtdenetwork/qgpgme/tests/dataprovidertest.cpp @@ -0,0 +1,125 @@ +/* tests/dataprovidertest.cpp + Copyright (C) 2004 Klarälvdalens Datakonsult AB + + This file is part of TQGPGME's regression test suite. + + TQGPGME is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + TQGPGME is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with TQGPGME; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ + +// -*- c++ -*- + +#ifdef NDEBUG +#undef NDEBUG +#endif + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <qgpgme/dataprovider.h> +#include <gpgmepp/data.h> +#include <gpgmepp/data_p.h> +#include <gpgme.h> + +#include <iostream> + +#include <string.h> +#include <unistd.h> +#include <assert.h> +#include <errno.h> +#include <stdlib.h> + +using namespace GpgME; + +static const char input[] = "foo bar baz\0foo bar baz"; +static const size_t inputSize = sizeof (input) / sizeof (*input) - 1; +static const char nulls[256] = { '\0' }; + +#define assertEqual( expr, expected ) \ +do { \ + long long foo = (expr); \ + if ( foo != (long long)expected ) { \ + std::cerr << #expr << ": expected " << expected << "; got " << foo \ + << ";errno: " << errno << "(" << strerror( errno ) << ")" << std::endl; \ + exit( 1 ); \ + } \ +} while( 0 ) + +int main( int, char** ) { + + { + // + // TQByteArrayDataProvider + // + + // writing: + QGpgME::TQByteArrayDataProvider qba_dp; + Data data( &qba_dp ); + + assertEqual( data.write( input, inputSize ), inputSize ); + + const TQByteArray ba1 = qba_dp.data(); + assertEqual( ba1.size(), inputSize ); + assertEqual( memcmp( ba1.data(), input, inputSize ), 0 ); + + // seeking and reading: + assertEqual( data.seek( 0, SEEK_CUR ), inputSize ); + assertEqual( data.seek( 4, SEEK_SET ), 4 ); + char ch = '\0'; + assertEqual( data.read( &ch, 1 ), 1 ); + assertEqual( ch, input[4] ); + assertEqual( data.read( &ch, 1 ), 1 ); + assertEqual( ch, input[5] ); + + char buf[ inputSize + 10 ] = { '\0' }; + assertEqual( data.seek( 0, SEEK_SET ), 0 ); + assertEqual( data.read( buf, sizeof buf ), inputSize ); + assertEqual( memcmp( buf, input, inputSize ), 0 ); + + // writing single char at end: + assertEqual( data.seek( 0, SEEK_END ), inputSize ); + assertEqual( data.write( &ch, 1 ) , 1 ); + const TQByteArray ba2 = qba_dp.data(); + assertEqual( ba2.size(), inputSize + 1 ); + assertEqual( memcmp( ba2.data(), input, inputSize ), 0 ); + assertEqual( ba2[inputSize], ch ); + + // writing past end of buffer: + assertEqual( data.seek( 10, SEEK_END ), inputSize + 11 ); + assertEqual( data.write( &ch, 1 ), 1 ); + const TQByteArray ba3 = qba_dp.data(); + assertEqual( ba3.size(), inputSize + 12 ); + assertEqual( memcmp( ba3.data(), input, inputSize ), 0 ); + assertEqual( ba3[inputSize], ch ); + assertEqual( ba3[inputSize+11], ch ); + assertEqual( memcmp( ba3.data() + inputSize + 1, nulls, 10 ), 0 ); + } + + { + // + // TQByteArrayDataProvider with initial data: + // + TQByteArray ba; + ba.duplicate( input, inputSize ); + QGpgME::TQByteArrayDataProvider qba_dp( ba ); + Data data( &qba_dp ); + + assertEqual( data.seek( 0, SEEK_END ), inputSize ); + assertEqual( data.seek( 0, SEEK_SET ), 0 ); + const TQByteArray ba1 = qba_dp.data(); + assertEqual( ba1.size(), inputSize ); + assertEqual( memcmp( ba1.data(), input, inputSize ), 0 ); + } + return 0; +} |