Linux multi-monitor fullscreen support
[ryzomcore.git] / nel / tools / nel_unit_test / ut_misc_base64.h
blobff5d24c4c6501b572dac45ad9f051844ba34c2ee
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010-2020 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef UT_MISC_BASE64
18 #define UT_MISC_BASE64
20 #include <nel/misc/base64.h>
22 struct CUTMiscBase64 : public Test::Suite
24 CUTMiscBase64()
26 TEST_ADD(CUTMiscBase64::testEncode);
27 TEST_ADD(CUTMiscBase64::testDecode);
28 TEST_ADD(CUTMiscBase64::testDecodeNoPadding);
29 TEST_ADD(CUTMiscBase64::testDecodeInvalid);
32 void testEncode()
34 TEST_ASSERT("" == NLMISC::base64::encode(""));
36 TEST_ASSERT("AA==" == NLMISC::base64::encode(std::string(1, '\0')));
37 TEST_ASSERT("YQ==" == NLMISC::base64::encode("a"));
38 TEST_ASSERT("YWI=" == NLMISC::base64::encode("ab"));
39 TEST_ASSERT("YWJj" == NLMISC::base64::encode("abc"));
41 std::string expect = "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NTY3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==";
42 std::string encoded = NLMISC::base64::encode("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#0^&*();:<>,. []{}");
43 TEST_ASSERT(expect == encoded);
46 void testDecode()
48 TEST_ASSERT("" == NLMISC::base64::decode(""));
49 TEST_ASSERT("" == NLMISC::base64::decode("="));
50 TEST_ASSERT("" == NLMISC::base64::decode("=="));
51 TEST_ASSERT("" == NLMISC::base64::decode("==="));
52 TEST_ASSERT("" == NLMISC::base64::decode("===="));
54 TEST_ASSERT(std::string(1, '\0') == NLMISC::base64::decode("AA=="));
55 TEST_ASSERT("a" == NLMISC::base64::decode("YQ=="));
56 TEST_ASSERT("ab" == NLMISC::base64::decode("YWI="));
57 TEST_ASSERT("abc" == NLMISC::base64::decode("YWJj"));
59 std::string expect = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#0^&*();:<>,. []{}";
60 std::string decoded = NLMISC::base64::decode("YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NTY3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==");
61 TEST_ASSERT(expect == decoded);
64 void testDecodeNoPadding()
66 TEST_ASSERT(std::string(1, '\0') == NLMISC::base64::decode("AA"));
67 TEST_ASSERT("a" == NLMISC::base64::decode("YQ"));
68 TEST_ASSERT("ab" == NLMISC::base64::decode("YWI"));
70 std::string expect = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#0^&*();:<>,. []{}";
71 std::string decoded = NLMISC::base64::decode("YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NTY3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ");
72 TEST_ASSERT(expect == decoded);
75 void testDecodeInvalid()
77 TEST_ASSERT("" == NLMISC::base64::decode("A"));
78 TEST_ASSERT("" == NLMISC::base64::decode("A==="));
82 #endif