|
| 1 | +/* |
| 2 | + * Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"). |
| 5 | + * You may not use this file except in compliance with the License. |
| 6 | + * A copy of the License is located at |
| 7 | + * |
| 8 | + * http://aws.amazon.com/apache2.0 |
| 9 | + * |
| 10 | + * or in the "license" file accompanying this file. This file is distributed |
| 11 | + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 12 | + * express or implied. See the License for the specific language governing |
| 13 | + * permissions and limitations under the License. |
| 14 | + */ |
| 15 | +#include <aws/crt/Api.h> |
| 16 | +#include <aws/crt/Types.h> |
| 17 | +#include <aws/testing/aws_test_harness.h> |
| 18 | + |
| 19 | +static int s_base64_round_trip(struct aws_allocator *allocator, void *ctx) |
| 20 | +{ |
| 21 | + (void)ctx; |
| 22 | + Aws::Crt::ApiHandle apiHandle(allocator); |
| 23 | + |
| 24 | + { |
| 25 | + Aws::Crt::String test_data = "foobar"; |
| 26 | + Aws::Crt::String expected = "Zm9vYmFy"; |
| 27 | + |
| 28 | + const Aws::Crt::Vector<uint8_t> test_vector(test_data.begin(), test_data.end()); |
| 29 | + const Aws::Crt::Vector<uint8_t> expected_vector(expected.begin(), expected.end()); |
| 30 | + |
| 31 | + Aws::Crt::String encoded = Aws::Crt::Base64Encode(test_vector); |
| 32 | + ASSERT_BIN_ARRAYS_EQUALS(expected.data(), expected.size(), encoded.data(), encoded.size()); |
| 33 | + |
| 34 | + Aws::Crt::Vector<uint8_t> decoded = Aws::Crt::Base64Decode(encoded); |
| 35 | + ASSERT_BIN_ARRAYS_EQUALS(test_vector.data(), test_vector.size(), decoded.data(), decoded.size()); |
| 36 | + } |
| 37 | + |
| 38 | + return 0; |
| 39 | +} |
| 40 | + |
| 41 | +AWS_TEST_CASE(Base64RoundTrip, s_base64_round_trip) |
0 commit comments