Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / oox / qa / unit / vba_encryption.cxx
blob023cc197bafb12c4d11294a106b1951e13751477
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/.
8 */
10 #include <cppunit/plugin/TestPlugIn.h>
11 #include <cppunit/extensions/HelperMacros.h>
12 #include <cppunit/TestFixture.h>
14 #include <oox/ole/vbaexport.hxx>
16 class TestVbaEncryption : public CppUnit::TestFixture
18 public:
19 #if 0
20 // an initial test for the encryption taken from the spec
21 void testSimple1();
23 void testSimple2();
24 #endif
26 void testProjKey1();
28 CPPUNIT_TEST_SUITE(TestVbaEncryption);
29 // CPPUNIT_TEST(testSimple1);
30 // CPPUNIT_TEST(testSimple2);
31 CPPUNIT_TEST(testProjKey1);
32 CPPUNIT_TEST_SUITE_END();
35 #if 0
36 void TestVbaEncryption::testSimple1()
38 sal_uInt8 nSeed = 0x07;
39 sal_uInt8 nProjKey = 0xDF;
40 sal_uInt16 nLength = 0x04;
41 sal_uInt8 pData[] = { 0x00, 0x00, 0x00, 0x00 };
43 SvMemoryStream aEncryptedStream(4096, 4096);
44 VBAEncryption aEncryption(pData, nLength, aEncryptedStream,
45 &nSeed, nProjKey);
46 aEncryption.write();
49 void TestVbaEncryption::testSimple2()
51 sal_uInt8 nSeed = 0x15;
52 sal_uInt8 nProjKey = 0xDF;
53 sal_uInt16 nLength = 0x01;
54 sal_uInt8 pData[] = { 0xFF };
56 SvMemoryStream aEncryptedStream(4096, 4096);
57 VBAEncryption aEncryption(pData, nLength, aEncryptedStream,
58 &nSeed, nProjKey);
59 aEncryption.write();
60 sal_uInt8 pExpectedData[] = "1517CAF1D6F9D7F9D706";
61 size_t length = sizeof(pExpectedData);
62 aEncryptedStream.Seek(0);
63 for (size_t i = 0; i < length; ++i)
65 unsigned char val = 0;
66 aEncryptedStream.ReadUChar(val);
67 CPPUNIT_ASSERT_EQUAL((int)pExpectedData[i], (int)sal_uInt8(val));
70 #endif
72 void TestVbaEncryption::testProjKey1()
74 sal_uInt8 nProjKey = VBAEncryption::calculateProjKey("{917DED54-440B-4FD1-A5C1-74ACF261E600}");
75 CPPUNIT_ASSERT_EQUAL(int(0xdf), static_cast<int>(nProjKey));
78 CPPUNIT_TEST_SUITE_REGISTRATION(TestVbaEncryption);
80 CPPUNIT_PLUGIN_IMPLEMENT();
82 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */