1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include <cppunit/plugin/TestPlugIn.h>
11 #include <cppunit/extensions/HelperMacros.h>
12 #include <cppunit/TestFixture.h>
14 #include <oox/ole/vbaexport.hxx>
17 class TestVbaEncryption
: public CppUnit::TestFixture
22 // an initial test for the encryption taken from the spec
30 CPPUNIT_TEST_SUITE(TestVbaEncryption
);
31 // CPPUNIT_TEST(testSimple1);
32 // CPPUNIT_TEST(testSimple2);
33 CPPUNIT_TEST(testProjKey1
);
34 CPPUNIT_TEST_SUITE_END();
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
,
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
,
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
));
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: */