guacamole-spice-protocol/tests/protocol/base64_decode.c

60 lines
1.9 KiB
C
Raw Normal View History

/*
2016-03-25 19:59:40 +00:00
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
2013-09-27 22:51:45 +00:00
*
2016-03-25 19:59:40 +00:00
* http://www.apache.org/licenses/LICENSE-2.0
2013-09-27 22:51:45 +00:00
*
2016-03-25 19:59:40 +00:00
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
2014-01-01 22:44:28 +00:00
#include "config.h"
#include "suite.h"
2013-09-27 22:51:45 +00:00
#include <stdio.h>
#include <stdlib.h>
2014-01-01 22:44:28 +00:00
#include <unistd.h>
2013-09-27 22:51:45 +00:00
2014-01-01 22:44:28 +00:00
#include <CUnit/Basic.h>
2013-09-27 22:51:45 +00:00
#include <guacamole/protocol.h>
void test_base64_decode() {
/* Test strings */
char test_HELLO[] = "SEVMTE8=";
char test_AVOCADO[] = "QVZPQ0FETw==";
char test_GUACAMOLE[] = "R1VBQ0FNT0xF";
/* Invalid strings */
char invalid1[] = "====";
char invalid2[] = "";
/* Test one character of padding */
CU_ASSERT_EQUAL(guac_protocol_decode_base64(test_HELLO), 5);
2013-09-27 22:53:27 +00:00
CU_ASSERT_NSTRING_EQUAL(test_HELLO, "HELLO", 5);
2013-09-27 22:51:45 +00:00
/* Test two characters of padding */
CU_ASSERT_EQUAL(guac_protocol_decode_base64(test_AVOCADO), 7);
2013-09-27 22:53:27 +00:00
CU_ASSERT_NSTRING_EQUAL(test_AVOCADO, "AVOCADO", 7);
2013-09-27 22:51:45 +00:00
/* Test three characters of padding */
CU_ASSERT_EQUAL(guac_protocol_decode_base64(test_GUACAMOLE), 9);
2013-09-27 22:53:27 +00:00
CU_ASSERT_NSTRING_EQUAL(test_GUACAMOLE, "GUACAMOLE", 9);
2013-09-27 22:51:45 +00:00
/* Verify invalid strings stop early as expected */
CU_ASSERT_EQUAL(guac_protocol_decode_base64(invalid1), 0);
CU_ASSERT_EQUAL(guac_protocol_decode_base64(invalid2), 0);
}