NeoMutt  2019-12-07-168-gc45f47
Teaching an old dog new tricks
DOXYGEN
mutt_b64_decode.c File Reference

Test code for mutt_b64_decode() More...

#include "acutest.h"
#include "config.h"
#include <string.h>
#include "mutt/lib.h"
+ Include dependency graph for mutt_b64_decode.c:

Go to the source code of this file.

Macros

#define TEST_NO_MAIN
 

Functions

void test_mutt_b64_decode (void)
 

Variables

static const char clear [] = "Hello"
 
static const char encoded [] = "SGVsbG8="
 

Detailed Description

Test code for mutt_b64_decode()

Authors
  • Richard Russon

This program 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 this program. If not, see http://www.gnu.org/licenses/.

Definition in file mutt_b64_decode.c.

Macro Definition Documentation

◆ TEST_NO_MAIN

#define TEST_NO_MAIN

Definition at line 23 of file mutt_b64_decode.c.

Function Documentation

◆ test_mutt_b64_decode()

void test_mutt_b64_decode ( void  )

Definition at line 32 of file mutt_b64_decode.c.

33 {
34  // int mutt_b64_decode(const char *in, char *out, size_t olen);
35 
36  {
37  TEST_CHECK(mutt_b64_decode(NULL, "banana", 10) != 0);
38  }
39 
40  {
41  TEST_CHECK(mutt_b64_decode("apple", NULL, 10) != 0);
42  }
43 
44  {
45  char buffer[16] = { 0 };
46  int len = mutt_b64_decode(encoded, buffer, sizeof(buffer));
47  if (!TEST_CHECK(len == sizeof(clear) - 1))
48  {
49  TEST_MSG("Expected: %zu", sizeof(clear) - 1);
50  TEST_MSG("Actual : %zu", len);
51  }
52  buffer[len] = '\0';
53  if (!TEST_CHECK(strcmp(buffer, clear) == 0))
54  {
55  TEST_MSG("Expected: %s", clear);
56  TEST_MSG("Actual : %s", buffer);
57  }
58  }
59 
60  {
61  char out1[32] = { 0 };
62  char out2[32] = { 0 };
63 
64  /* Decoding a zero-length string should fail, too */
65  int declen = mutt_b64_decode(out1, out2, sizeof(out2));
66  if (!TEST_CHECK(declen == -1))
67  {
68  TEST_MSG("Expected: %zu", -1);
69  TEST_MSG("Actual : %zu", declen);
70  }
71  }
72 }
#define TEST_MSG(...)
Definition: acutest.h:206
#define TEST_CHECK(cond)
Definition: acutest.h:83
static const char encoded[]
int mutt_b64_decode(const char *in, char *out, size_t olen)
Convert null-terminated base64 string to raw bytes.
Definition: base64.c:136
static const char clear[]
+ Here is the call graph for this function:

Variable Documentation

◆ clear

const char clear[] = "Hello"
static

Definition at line 29 of file mutt_b64_decode.c.

◆ encoded

const char encoded[] = "SGVsbG8="
static

Definition at line 30 of file mutt_b64_decode.c.