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 <sal/config.h>
11 #include <unotools/configmgr.hxx>
12 #include "helper/qahelper.hxx"
15 #include <document.hxx>
18 #include <tools/stream.hxx>
20 class ScCacheTest
: public CppUnit::TestFixture
23 void testCacheSimple();
24 void testCacheString();
25 void testCacheFormula();
27 CPPUNIT_TEST_SUITE(ScCacheTest
);
28 CPPUNIT_TEST(testCacheSimple
);
29 CPPUNIT_TEST(testCacheString
);
30 CPPUNIT_TEST(testCacheFormula
);
31 CPPUNIT_TEST_SUITE_END();
36 utl::ConfigManager::EnableFuzzing();
40 ~ScCacheTest() { ScGlobal::Clear(); }
43 void ScCacheTest::testCacheSimple()
46 aDoc
.InsertTab(0, "test");
47 for (SCROW nRow
= 0; nRow
< 10; ++nRow
)
48 aDoc
.SetValue(0, nRow
, 0, nRow
);
50 aDoc
.SetValue(0, 100000, 0, -10);
53 aDoc
.StoreTabToCache(0, aStrm
);
58 aNewDoc
.InsertTab(0, "test");
59 aNewDoc
.RestoreTabFromCache(0, aStrm
);
61 for (SCROW nRow
= 0; nRow
< 10; ++nRow
)
62 ASSERT_DOUBLES_EQUAL(nRow
, aNewDoc
.GetValue(0, nRow
, 0));
65 void ScCacheTest::testCacheString()
68 aDoc
.InsertTab(0, "test");
70 aDoc
.SetString(0, 0, 0, "TestString");
71 aDoc
.SetString(0, 1, 0, "asjdaonfdssda");
72 aDoc
.SetString(0, 2, 0, "da");
75 aDoc
.StoreTabToCache(0, aStrm
);
80 aNewDoc
.InsertTab(0, "test");
81 aNewDoc
.RestoreTabFromCache(0, aStrm
);
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));
88 void ScCacheTest::testCacheFormula()
91 aDoc
.InsertTab(0, "test");
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");
100 SvMemoryStream aStrm
;
101 aDoc
.StoreTabToCache(0, aStrm
);
106 aNewDoc
.InsertTab(0, "test");
107 aNewDoc
.RestoreTabFromCache(0, aStrm
);
109 std::vector
<OUString
> aFormulas
= { "=B1", "=B2", "=B3", "=B4", "=B5", "=B1" };
110 for (SCROW nRow
= 0; nRow
<= 5; ++nRow
)
112 OUString aFormula
= aNewDoc
.GetFormula(0, nRow
, 0);
113 CPPUNIT_ASSERT_EQUAL(aFormulas
[nRow
], aFormula
);
117 CPPUNIT_TEST_SUITE_REGISTRATION(ScCacheTest
);
119 CPPUNIT_PLUGIN_IMPLEMENT();
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */