microsoft/onnxruntime-extensions

Public

mirrored fromhttps://github.com/microsoft/onnxruntime-extensionsAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
352b2003bc6c4604f4285d64133d8bdf11549253

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

test/static_test/test_base64.cc

53lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT License.
3
4#include "gtest/gtest.h"
5#include "base64.h"
6
7TEST(base64, encode_decode) {
8 std::vector<uint8_t> raw{0, 1, 2, 0, 45, 7, 255, 4};
9 std::string encoded;
10 base64_encode(raw, encoded);
11 std::vector<uint8_t> decoded;
12 base64_decode(encoded, decoded);
13 EXPECT_EQ(raw, decoded);
14}
15
16TEST(base64, encode_decode_single) {
17 std::vector<std::string> expected = {"AA==", "AQ==", "Ag=="};
18 for (int i = 1; i <= 256; ++i) {
19 uint8_t b = (uint8_t)(i % 256);
20 std::vector<uint8_t> raw{b};
21 std::string encoded;
22 base64_encode(raw, encoded);
23 if (b < expected.size()) {
24 EXPECT_EQ(expected[b], encoded);
25 }
26 std::vector<uint8_t> decoded;
27 base64_decode(encoded, decoded);
28 EXPECT_EQ(raw, decoded);
29 }
30}
31
32TEST(base64, decode_encode) {
33 std::vector<uint8_t> raw;
34 std::string encoded("AAECAC0HAAQ=");
35 base64_decode(encoded, raw);
36 std::string encode2;
37 base64_encode(raw, encode2);
38 EXPECT_EQ(encoded, encode2);
39}
40
41TEST(base64, decode_false_length) {
42 std::vector<uint8_t> raw;
43 std::string encoded("AAAC0HAAQ=");
44 bool r = base64_decode(encoded, raw);
45 EXPECT_EQ(r, false);
46}
47
48TEST(base64, decode_false_wrong) {
49 std::vector<uint8_t> raw;
50 std::string encoded("AAECAC0HAA'=");
51 bool r = base64_decode(encoded, raw);
52 EXPECT_EQ(r, false);
53}
54