tstBase64.cpp revision 909b49e9391c03444e8aadbc0d9b5ff78669cfb2
/* $Id$ */
/** @file
* IPRT Testcase - Base64.
*/
/*
* Copyright (C) 2009 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <iprt/initterm.h>
struct TstI64
{
const char *psz;
unsigned uBase;
int rc;
};
struct TstU64
{
const char *psz;
unsigned uBase;
int rc;
};
struct TstI32
{
const char *psz;
unsigned uBase;
int rc;
};
struct TstU32
{
const char *psz;
unsigned uBase;
int rc;
};
do \
{ \
{ \
RTPrintf("failure: '%s' -> " Fmt " expected " Fmt ". (%s/%u)\n", Test.psz, Result, Test.Result, #Fun, iTest); \
cErrors++; \
} \
{ \
RTPrintf("failure: '%s' -> rc=%Rrc expected %Rrc. (%s/%u)\n", Test.psz, rc, Test.rc, #Fun, iTest); \
cErrors++; \
} \
} while (0)
int main()
{
int cErrors =0;
RTR3Init();
/*
* Test 0.
*/
static const char s_szText0[] = "Hey";
static const char s_szEnc0[] = "SGV5";
if (RT_FAILURE(rc))
{
cErrors++;
}
{
RTPrintf("tstBase64: FAILURE - RTBase64Decode returned %zu bytes, expected %zu.\n",
cErrors++;
}
{
RTPrintf("tstBase64: FAILURE - RTBase64Decode returned:\n%.*s\nexpected:\n%s\n",
cErrors++;
}
/*
* Test 1.
*/
static const char s_szText1[] = "Call me Ishmael.";
static const char s_szEnc1[] = "Q2FsbCBtZSBJc2htYWVsLg==";
if (RT_FAILURE(rc))
{
cErrors++;
}
{
RTPrintf("tstBase64: FAILURE - RTBase64Decode returned %zu bytes, expected %zu.\n",
cErrors++;
}
{
RTPrintf("tstBase64: FAILURE - RTBase64Decode returned:\n%.*s\nexpected:\n%s\n",
cErrors++;
}
/*
* Test 2.
*/
static const char s_szText2[] =
"Man is distinguished, not only by his reason, but by this singular passion "
"from other animals, which is a lust of the mind, that by a perseverance of "
"delight in the continued and indefatigable generation of knowledge, exceeds "
"the short vehemence of any carnal pleasure."; /* Thomas Hobbes's Leviathan */
static const char s_szEnc2[] =
" TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz\n"
" IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg\n\r"
" dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu\n"
" dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo\n\r"
" ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=\n \n";
if (RT_FAILURE(rc))
{
cErrors++;
}
{
RTPrintf("tstBase64: FAILURE - RTBase64Decode returned %zu bytes, expected %zu.\n",
cErrors++;
}
{
RTPrintf("tstBase64: FAILURE - RTBase64Decode returned:\n%.*s\nexpected:\n%s\n",
cErrors++;
}
/*
* Summary.
*/
if (!cErrors)
RTPrintf("tstBase64: SUCCESS\n");
else
return !!cErrors;
}