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 #include <algorithm>
16 
17 class TestVbaEncryption : public CppUnit::TestFixture
18 {
19 public:
20 
21 #if 0
22     // an initial test for the encryption taken from the spec
23     void testSimple1();
24 
25     void testSimple2();
26 #endif
27 
28     void testProjKey1();
29 
30     CPPUNIT_TEST_SUITE(TestVbaEncryption);
31     // CPPUNIT_TEST(testSimple1);
32     // CPPUNIT_TEST(testSimple2);
33     CPPUNIT_TEST(testProjKey1);
34     CPPUNIT_TEST_SUITE_END();
35 };
36 
37 #if 0
38 void TestVbaEncryption::testSimple1()
39 {
40     sal_uInt8 nSeed = 0x07;
41     sal_uInt8 nProjKey = 0xDF;
42     sal_uInt16 nLength = 0x04;
43     sal_uInt8 pData[] = { 0x00, 0x00, 0x00, 0x00 };
44 
45     SvMemoryStream aEncryptedStream(4096, 4096);
46     VBAEncryption aEncryption(pData, nLength, aEncryptedStream,
47             &nSeed, nProjKey);
48     aEncryption.write();
49 }
50 
51 void TestVbaEncryption::testSimple2()
52 {
53     sal_uInt8 nSeed = 0x15;
54     sal_uInt8 nProjKey = 0xDF;
55     sal_uInt16 nLength = 0x01;
56     sal_uInt8 pData[] = { 0xFF };
57 
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)
66     {
67         unsigned char val = 0;
68         aEncryptedStream.ReadUChar(val);
69         CPPUNIT_ASSERT_EQUAL((int)pExpectedData[i], (int)sal_uInt8(val));
70     }
71 }
72 #endif
73 
testProjKey1()74 void TestVbaEncryption::testProjKey1()
75 {
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));
79 }
80 
81 CPPUNIT_TEST_SUITE_REGISTRATION(TestVbaEncryption);
82 
83 CPPUNIT_PLUGIN_IMPLEMENT();
84 
85 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
86