Flutter Engine
The Flutter Engine
base64_test.cc
Go to the documentation of this file.
1// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5#include "vm/base64.h"
6
7#include "platform/assert.h"
8#include "vm/unit_test.h"
9
10namespace dart {
11
12TEST_CASE(Base64Decode) {
13 intptr_t decoded_len;
14 uint8_t* decoded_bytes = DecodeBase64("SGVsbG8sIHdvcmxkIQo=", &decoded_len);
15 const char expected_bytes[] = "Hello, world!\n";
16 intptr_t expected_len = strlen(expected_bytes);
17 EXPECT(!memcmp(expected_bytes, decoded_bytes, expected_len));
18 EXPECT_EQ(expected_len, decoded_len);
19 free(decoded_bytes);
20}
21
22TEST_CASE(Base64DecodeMalformed) {
23 intptr_t decoded_len;
24 EXPECT(DecodeBase64("SomethingMalformed", &decoded_len) == nullptr);
25}
26
27TEST_CASE(Base64DecodeEmpty) {
28 intptr_t decoded_len;
29 EXPECT(DecodeBase64("", &decoded_len) == nullptr);
30}
31} // namespace dart
#define EXPECT(type, expectedAlignment, expectedSize)
Definition: dart_vm.cc:33
TEST_CASE(DirectoryCurrent)
uint8_t * DecodeBase64(const char *str, intptr_t *out_decoded_len)
Definition: base64.cc:39