1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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  */
9 
10 #include <cppunit/plugin/TestPlugIn.h>
11 #include <cppunit/extensions/HelperMacros.h>
12 #include <cppunit/TestFixture.h>
13 
14 #include <oox/ole/vbaexport.hxx>
15 
16 class TestVbaEncryption : public CppUnit::TestFixture
17 {
18 public:
19 #if 0
20     // an initial test for the encryption taken from the spec
21     void testSimple1();
22 
23     void testSimple2();
24 #endif
25 
26     void testProjKey1();
27 
28     CPPUNIT_TEST_SUITE(TestVbaEncryption);
29     // CPPUNIT_TEST(testSimple1);
30     // CPPUNIT_TEST(testSimple2);
31     CPPUNIT_TEST(testProjKey1);
32     CPPUNIT_TEST_SUITE_END();
33 };
34 
35 #if 0
36 void TestVbaEncryption::testSimple1()
37 {
38     sal_uInt8 nSeed = 0x07;
39     sal_uInt8 nProjKey = 0xDF;
40     sal_uInt16 nLength = 0x04;
41     sal_uInt8 pData[] = { 0x00, 0x00, 0x00, 0x00 };
42 
43     SvMemoryStream aEncryptedStream(4096, 4096);
44     VBAEncryption aEncryption(pData, nLength, aEncryptedStream,
45             &nSeed, nProjKey);
46     aEncryption.write();
47 }
48 
49 void TestVbaEncryption::testSimple2()
50 {
51     sal_uInt8 nSeed = 0x15;
52     sal_uInt8 nProjKey = 0xDF;
53     sal_uInt16 nLength = 0x01;
54     sal_uInt8 pData[] = { 0xFF };
55 
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)
64     {
65         unsigned char val = 0;
66         aEncryptedStream.ReadUChar(val);
67         CPPUNIT_ASSERT_EQUAL((int)pExpectedData[i], (int)sal_uInt8(val));
68     }
69 }
70 #endif
71 
testProjKey1()72 void TestVbaEncryption::testProjKey1()
73 {
74     sal_uInt8 nProjKey = VBAEncryption::calculateProjKey("{917DED54-440B-4FD1-A5C1-74ACF261E600}");
75     CPPUNIT_ASSERT_EQUAL(int(0xdf), static_cast<int>(nProjKey));
76 }
77 
78 CPPUNIT_TEST_SUITE_REGISTRATION(TestVbaEncryption);
79 
80 CPPUNIT_PLUGIN_IMPLEMENT();
81 
82 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
83