tdf#162786, tdf#161947: Add support for setuptools and pip
[LibreOffice.git] / comphelper / qa / unit / base64_test.cxx
blobf589e1809dd02385efd852176ba264d81c2f7da6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/types.h>
21 #include <cppunit/TestAssert.h>
22 #include <cppunit/TestFixture.h>
23 #include <cppunit/extensions/HelperMacros.h>
25 #include <rtl/ustrbuf.hxx>
27 #include <com/sun/star/uno/Sequence.hxx>
29 #include <comphelper/base64.hxx>
31 using namespace css;
33 namespace
35 class Base64Test : public CppUnit::TestFixture
37 public:
38 void testBase64Encode();
39 void testBase64Decode();
40 void testBase64EncodeForOStringBuffer();
42 CPPUNIT_TEST_SUITE(Base64Test);
43 CPPUNIT_TEST(testBase64Encode);
44 CPPUNIT_TEST(testBase64Decode);
45 CPPUNIT_TEST(testBase64EncodeForOStringBuffer);
46 CPPUNIT_TEST_SUITE_END();
49 void Base64Test::testBase64Encode()
51 OUStringBuffer aBuffer(32);
52 uno::Sequence<sal_Int8> inputSequence;
54 inputSequence = { 0, 0, 0, 0, 0, 1, 2, 3 };
55 comphelper::Base64::encode(aBuffer, inputSequence);
56 CPPUNIT_ASSERT_EQUAL(u"AAAAAAABAgM="_ustr, aBuffer.toString());
57 aBuffer.setLength(0);
59 inputSequence = { 5, 2, 3, 0, 0, 1, 2, 3 };
60 comphelper::Base64::encode(aBuffer, inputSequence);
61 CPPUNIT_ASSERT_EQUAL(u"BQIDAAABAgM="_ustr, aBuffer.toString());
62 aBuffer.setLength(0);
64 inputSequence = { sal_Int8(sal_uInt8(200)), 31, 77, 111, 0, 1, 2, 3 };
65 comphelper::Base64::encode(aBuffer, inputSequence);
66 CPPUNIT_ASSERT_EQUAL(u"yB9NbwABAgM="_ustr, aBuffer.makeStringAndClear());
69 void Base64Test::testBase64Decode()
71 uno::Sequence<sal_Int8> decodedSequence;
73 uno::Sequence<sal_Int8> expectedSequence = { 0, 0, 0, 0, 0, 1, 2, 3 };
74 comphelper::Base64::decode(decodedSequence, u"AAAAAAABAgM=");
75 CPPUNIT_ASSERT(std::equal(std::cbegin(expectedSequence), std::cend(expectedSequence),
76 std::cbegin(decodedSequence)));
78 expectedSequence = { 5, 2, 3, 0, 0, 1, 2, 3 };
79 comphelper::Base64::decode(decodedSequence, u"BQIDAAABAgM=");
80 CPPUNIT_ASSERT(std::equal(std::cbegin(expectedSequence), std::cend(expectedSequence),
81 std::cbegin(decodedSequence)));
83 expectedSequence = { sal_Int8(sal_uInt8(200)), 31, 77, 111, 0, 1, 2, 3 };
84 comphelper::Base64::decode(decodedSequence, u"yB9NbwABAgM=");
85 CPPUNIT_ASSERT(std::equal(std::cbegin(expectedSequence), std::cend(expectedSequence),
86 std::cbegin(decodedSequence)));
89 void Base64Test::testBase64EncodeForOStringBuffer()
91 OStringBuffer aBuffer(32);
92 uno::Sequence<sal_Int8> inputSequence;
94 inputSequence = { 0, 0, 0, 0, 0, 1, 2, 3 };
95 comphelper::Base64::encode(aBuffer, inputSequence);
96 CPPUNIT_ASSERT_EQUAL("AAAAAAABAgM="_ostr, aBuffer.toString());
97 aBuffer.setLength(0);
99 inputSequence = { 5, 2, 3, 0, 0, 1, 2, 3 };
100 comphelper::Base64::encode(aBuffer, inputSequence);
101 CPPUNIT_ASSERT_EQUAL("BQIDAAABAgM="_ostr, aBuffer.toString());
102 aBuffer.setLength(0);
104 inputSequence = { sal_Int8(sal_uInt8(200)), 31, 77, 111, 0, 1, 2, 3 };
105 comphelper::Base64::encode(aBuffer, inputSequence);
106 CPPUNIT_ASSERT_EQUAL("yB9NbwABAgM="_ostr, aBuffer.makeStringAndClear());
109 CPPUNIT_TEST_SUITE_REGISTRATION(Base64Test);
112 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */