Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/LibreOffice/sc/qa/unit/   (LibreOffice Version 25.8.3.2©)  Datei vom 5.10.2025 mit Größe 3 kB image not shown  

Quelle  datacache.cxx

  Sprache: C
 

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */


#include <sal/config.h>
#include <comphelper/configuration.hxx>
#include "helper/qahelper.hxx"

#include <global.hxx>
#include <document.hxx>
#include <scdll.hxx>

#include <tools/stream.hxx>

class ScCacheTest : public CppUnit::TestFixture
{
public:
    void testCacheSimple();
    void testCacheString();
    void testCacheFormula();

    CPPUNIT_TEST_SUITE(ScCacheTest);
    CPPUNIT_TEST(testCacheSimple);
    CPPUNIT_TEST(testCacheString);
    CPPUNIT_TEST(testCacheFormula);
    CPPUNIT_TEST_SUITE_END();

public:
    ScCacheTest()
    {
        comphelper::EnableFuzzing();
        ScDLL::Init();
        ScGlobal::Init();
    }
    ~ScCacheTest() { ScGlobal::Clear(); }
};

void ScCacheTest::testCacheSimple()
{
    ScDocument aDoc;
    aDoc.InsertTab(0, u"test"_ustr);
    for (SCROW nRow = 0; nRow < 10; ++nRow)
        aDoc.SetValue(0, nRow, 0, nRow);

    aDoc.SetValue(01000000, -10);

    SvMemoryStream aStrm;
    aDoc.StoreTabToCache(0, aStrm);

    aStrm.Seek(0);

    ScDocument aNewDoc;
    aNewDoc.InsertTab(0, u"test"_ustr);
    aNewDoc.RestoreTabFromCache(0, aStrm);

    for (SCROW nRow = 0; nRow < 10; ++nRow)
        ASSERT_DOUBLES_EQUAL(nRow, aNewDoc.GetValue(0, nRow, 0));
}

void ScCacheTest::testCacheString()
{
    ScDocument aDoc;
    aDoc.InsertTab(0, u"test"_ustr);

    aDoc.SetString(000, u"TestString"_ustr);
    aDoc.SetString(010, u"asjdaonfdssda"_ustr);
    aDoc.SetString(020, u"da"_ustr);

    SvMemoryStream aStrm;
    aDoc.StoreTabToCache(0, aStrm);

    aStrm.Seek(0);

    ScDocument aNewDoc;
    aNewDoc.InsertTab(0, u"test"_ustr);
    aNewDoc.RestoreTabFromCache(0, aStrm);

    CPPUNIT_ASSERT_EQUAL(u"TestString"_ustr, aNewDoc.GetString(000));
    CPPUNIT_ASSERT_EQUAL(u"asjdaonfdssda"_ustr, aNewDoc.GetString(010));
    CPPUNIT_ASSERT_EQUAL(u"da"_ustr, aNewDoc.GetString(020));
}

void ScCacheTest::testCacheFormula()
{
    ScDocument aDoc;
    aDoc.InsertTab(0, u"test"_ustr);

    aDoc.SetString(000, u"=B1"_ustr);
    aDoc.SetString(010, u"=B2"_ustr);
    aDoc.SetString(020, u"=B3"_ustr);
    aDoc.SetString(030, u"=B4"_ustr);
    aDoc.SetString(040, u"=B5"_ustr);
    aDoc.SetString(050, u"=B1"_ustr);

    SvMemoryStream aStrm;
    aDoc.StoreTabToCache(0, aStrm);

    aStrm.Seek(0);

    ScDocument aNewDoc;
    aNewDoc.InsertTab(0, u"test"_ustr);
    aNewDoc.RestoreTabFromCache(0, aStrm);

    std::vector<OUString> aFormulas
        = { u"=B1"_ustr, u"=B2"_ustr, u"=B3"_ustr, u"=B4"_ustr, u"=B5"_ustr, u"=B1"_ustr };
    for (SCROW nRow = 0; nRow <= 5; ++nRow)
    {
        OUString aFormula = aNewDoc.GetFormula(0, nRow, 0);
        CPPUNIT_ASSERT_EQUAL(aFormulas[nRow], aFormula);
    }
}

CPPUNIT_TEST_SUITE_REGISTRATION(ScCacheTest);

CPPUNIT_PLUGIN_IMPLEMENT();

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Messung V0.5 in Prozent
C=97 H=54 G=78

¤ Dauer der Verarbeitung: 0.11 Sekunden  (vorverarbeitet am  2026-06-10) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.