ESAPI-C 1.0
The OWASP Enterprise Security API for C

test/src/base64_test.c

Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <string.h>
00004 #include "minunit.h"
00005 #include "base64.h"
00006 
00007 int tests_run = 0;
00008 
00009 void test_esapi_isbase64(void) 
00010 {
00011    (void)fprintf(stdout,"Testing %s\n", __func__);
00012 
00013    TEST(isbase64('G') == true);
00014    TEST(isbase64('*') == false);
00015 }
00016 
00017 void test_esapi_base64_encode(void) 
00018 {
00019    (void)fprintf(stdout,"Testing %s\n", __func__);
00020 
00021    char *input = "Hello";
00022    char encoded[32];
00023    char *expected = "SGVsbG8=";
00024 
00025    base64_encode(input, strlen(input), encoded, sizeof(encoded));
00026 
00027    TEST(strcmp(encoded, expected) == 0);
00028 }
00029 
00030 void test_esapi_base64_decode(void) 
00031 {
00032    (void)fprintf(stdout,"Testing %s\n", __func__);
00033 
00034    char *input = "SGVsbG8=";
00035    size_t decoded_len = 32;
00036    char decoded[decoded_len];
00037    char *expected = "Hello";
00038    bool result;
00039    
00040    if(memset(decoded, '\0', decoded_len) != decoded) {
00041       (void)fprintf(stderr, "memset error in %s\n", __func__);
00042    } else {
00043       TEST(base64_decode(input, strlen(input), decoded, &decoded_len) == 1);
00044       TEST(strcmp(decoded, expected) == 0);
00045    }
00046 }
00047 
00048 int main(void) 
00049 {
00050   test_esapi_isbase64();
00051   test_esapi_base64_encode();
00052   test_esapi_base64_decode();
00053 
00054   (void)fprintf(stdout, "%s: Pass <%i>, Fail<%i>\n", __FILE__, passed, failed);   
00055   return(EXIT_SUCCESS);
00056 }
 All Data Structures Files Functions Variables Typedefs Defines