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 <sal/config.h>
11 #include <unotools/configmgr.hxx>
12 #include "helper/qahelper.hxx"
13
14 #include <global.hxx>
15 #include <document.hxx>
16 #include <scdll.hxx>
17
18 #include <tools/stream.hxx>
19
20 class ScCacheTest : public CppUnit::TestFixture
21 {
22 public:
23 void testCacheSimple();
24 void testCacheString();
25 void testCacheFormula();
26
27 CPPUNIT_TEST_SUITE(ScCacheTest);
28 CPPUNIT_TEST(testCacheSimple);
29 CPPUNIT_TEST(testCacheString);
30 CPPUNIT_TEST(testCacheFormula);
31 CPPUNIT_TEST_SUITE_END();
32
33 public:
ScCacheTest()34 ScCacheTest()
35 {
36 utl::ConfigManager::EnableFuzzing();
37 ScDLL::Init();
38 ScGlobal::Init();
39 }
~ScCacheTest()40 ~ScCacheTest() { ScGlobal::Clear(); }
41 };
42
testCacheSimple()43 void ScCacheTest::testCacheSimple()
44 {
45 ScDocument aDoc;
46 aDoc.InsertTab(0, "test");
47 for (SCROW nRow = 0; nRow < 10; ++nRow)
48 aDoc.SetValue(0, nRow, 0, nRow);
49
50 aDoc.SetValue(0, 100000, 0, -10);
51
52 SvMemoryStream aStrm;
53 aDoc.StoreTabToCache(0, aStrm);
54
55 aStrm.Seek(0);
56
57 ScDocument aNewDoc;
58 aNewDoc.InsertTab(0, "test");
59 aNewDoc.RestoreTabFromCache(0, aStrm);
60
61 for (SCROW nRow = 0; nRow < 10; ++nRow)
62 ASSERT_DOUBLES_EQUAL(nRow, aNewDoc.GetValue(0, nRow, 0));
63 }
64
testCacheString()65 void ScCacheTest::testCacheString()
66 {
67 ScDocument aDoc;
68 aDoc.InsertTab(0, "test");
69
70 aDoc.SetString(0, 0, 0, "TestString");
71 aDoc.SetString(0, 1, 0, "asjdaonfdssda");
72 aDoc.SetString(0, 2, 0, "da");
73
74 SvMemoryStream aStrm;
75 aDoc.StoreTabToCache(0, aStrm);
76
77 aStrm.Seek(0);
78
79 ScDocument aNewDoc;
80 aNewDoc.InsertTab(0, "test");
81 aNewDoc.RestoreTabFromCache(0, aStrm);
82
83 CPPUNIT_ASSERT_EQUAL(OUString("TestString"), aNewDoc.GetString(0, 0, 0));
84 CPPUNIT_ASSERT_EQUAL(OUString("asjdaonfdssda"), aNewDoc.GetString(0, 1, 0));
85 CPPUNIT_ASSERT_EQUAL(OUString("da"), aNewDoc.GetString(0, 2, 0));
86 }
87
testCacheFormula()88 void ScCacheTest::testCacheFormula()
89 {
90 ScDocument aDoc;
91 aDoc.InsertTab(0, "test");
92
93 aDoc.SetString(0, 0, 0, "=B1");
94 aDoc.SetString(0, 1, 0, "=B2");
95 aDoc.SetString(0, 2, 0, "=B3");
96 aDoc.SetString(0, 3, 0, "=B4");
97 aDoc.SetString(0, 4, 0, "=B5");
98 aDoc.SetString(0, 5, 0, "=B1");
99
100 SvMemoryStream aStrm;
101 aDoc.StoreTabToCache(0, aStrm);
102
103 aStrm.Seek(0);
104
105 ScDocument aNewDoc;
106 aNewDoc.InsertTab(0, "test");
107 aNewDoc.RestoreTabFromCache(0, aStrm);
108
109 std::vector<OUString> aFormulas = { "=B1", "=B2", "=B3", "=B4", "=B5", "=B1" };
110 for (SCROW nRow = 0; nRow <= 5; ++nRow)
111 {
112 OUString aFormula;
113 aNewDoc.GetFormula(0, nRow, 0, aFormula);
114 CPPUNIT_ASSERT_EQUAL(aFormulas[nRow], aFormula);
115 }
116 }
117
118 CPPUNIT_TEST_SUITE_REGISTRATION(ScCacheTest);
119
120 CPPUNIT_PLUGIN_IMPLEMENT();
121
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
123