Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / oox / qa / unit / vba_encryption.cxx
blob7e8a44cd9c205f58844a51bcb95fd072d1655823
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>
15 #include <algorithm>
17 class TestVbaEncryption : public CppUnit::TestFixture
19 public:
21 #if 0
22 // an initial test for the encryption taken from the spec
23 void testSimple1();
25 void testSimple2();
26 #endif
28 void testProjKey1();
30 CPPUNIT_TEST_SUITE(TestVbaEncryption);
31 // CPPUNIT_TEST(testSimple1);
32 // CPPUNIT_TEST(testSimple2);
33 CPPUNIT_TEST(testProjKey1);
34 CPPUNIT_TEST_SUITE_END();
37 #if 0
38 void TestVbaEncryption::testSimple1()
40 sal_uInt8 nSeed = 0x07;
41 sal_uInt8 nProjKey = 0xDF;
42 sal_uInt16 nLength = 0x04;
43 sal_uInt8 pData[] = { 0x00, 0x00, 0x00, 0x00 };
45 SvMemoryStream aEncryptedStream(4096, 4096);
46 VBAEncryption aEncryption(pData, nLength, aEncryptedStream,
47 &nSeed, nProjKey);
48 aEncryption.write();
51 void TestVbaEncryption::testSimple2()
53 sal_uInt8 nSeed = 0x15;
54 sal_uInt8 nProjKey = 0xDF;
55 sal_uInt16 nLength = 0x01;
56 sal_uInt8 pData[] = { 0xFF };
58 SvMemoryStream aEncryptedStream(4096, 4096);
59 VBAEncryption aEncryption(pData, nLength, aEncryptedStream,
60 &nSeed, nProjKey);
61 aEncryption.write();
62 sal_uInt8 pExpectedData[] = "1517CAF1D6F9D7F9D706";
63 size_t length = sizeof(pExpectedData);
64 aEncryptedStream.Seek(0);
65 for (size_t i = 0; i < length; ++i)
67 unsigned char val = 0;
68 aEncryptedStream.ReadUChar(val);
69 CPPUNIT_ASSERT_EQUAL((int)pExpectedData[i], (int)sal_uInt8(val));
72 #endif
74 void TestVbaEncryption::testProjKey1()
76 OUString const aProjectID("{917DED54-440B-4FD1-A5C1-74ACF261E600}");
77 sal_uInt8 nProjKey = VBAEncryption::calculateProjKey(aProjectID);
78 CPPUNIT_ASSERT_EQUAL(int(0xdf), static_cast<int>(nProjKey));
81 CPPUNIT_TEST_SUITE_REGISTRATION(TestVbaEncryption);
83 CPPUNIT_PLUGIN_IMPLEMENT();
85 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */