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 | |
10 | namespace dart { |
11 | |
12 | TEST_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 | |
22 | TEST_CASE(Base64DecodeMalformed) { |
23 | intptr_t decoded_len; |
24 | EXPECT(DecodeBase64("SomethingMalformed", &decoded_len) == nullptr); |
25 | } |
26 | |
27 | TEST_CASE(Base64DecodeEmpty) { |
28 | intptr_t decoded_len; |
29 | EXPECT(DecodeBase64("", &decoded_len) == nullptr); |
30 | } |
31 | } // namespace dart |
32 |