summaryrefslogtreecommitdiffhomepage
path: root/tests/test-base64.cpp
blob: 5b7644e551c91433f055309e9ced2cd281667c9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <gtest/gtest.h>

#include "base64.h"

class Base64Test: public ::testing::Test
{
protected:
 Base64Test(){
 }

 ~Base64Test() override{
 }

 void SetUp() override
 {
 }

 void TearDown() override
 {
 }

};

TEST_F(Base64Test, encode)
{
 EXPECT_EQ(Reichwein::Base64::encode64(""), "");
 EXPECT_EQ(Reichwein::Base64::encode64("a"), "YQ==");
 EXPECT_EQ(Reichwein::Base64::encode64("ab"), "YWI=");
 EXPECT_EQ(Reichwein::Base64::encode64("abc"), "YWJj");
 EXPECT_EQ(Reichwein::Base64::encode64("abcd"), "YWJjZA==");
}

TEST_F(Base64Test, decode)
{
 EXPECT_EQ(Reichwein::Base64::decode64(""), "");
 EXPECT_EQ(Reichwein::Base64::decode64("YQ=="), "a");
 EXPECT_EQ(Reichwein::Base64::decode64("YQ"), "a"); // unpadded is accepted here
 EXPECT_EQ(Reichwein::Base64::decode64("YWI="), "ab");
 EXPECT_EQ(Reichwein::Base64::decode64("YWI"), "ab");
 EXPECT_EQ(Reichwein::Base64::decode64("YWJj"), "abc");
 EXPECT_EQ(Reichwein::Base64::decode64("YWJjZA=="), "abcd");
 EXPECT_EQ(Reichwein::Base64::decode64("YWJjZA="), "abcd");
 EXPECT_EQ(Reichwein::Base64::decode64("YWJjZA"), "abcd");
 EXPECT_ANY_THROW({Reichwein::Base64::decode64("_");});
 EXPECT_ANY_THROW({Reichwein::Base64::decode64("abc_");});
}