writerfilter/qa/cppunittests/odiapi/ExternalViewLogger.cxx | 194 --- writerfilter/qa/cppunittests/odiapi/ExternalViewLogger.hxx | 82 - writerfilter/qa/cppunittests/odiapi/FileLoggerImpl.cxx | 73 - writerfilter/qa/cppunittests/odiapi/FileLoggerImpl.hxx | 51 writerfilter/qa/cppunittests/odiapi/export.exp | 1 writerfilter/qa/cppunittests/odiapi/export.map | 25 writerfilter/qa/cppunittests/odiapi/testCore.cxx | 166 --- writerfilter/qa/cppunittests/odiapi/testProperty.cxx | 675 ------------- 8 files changed, 1267 deletions(-)
New commits: commit 529f9cf52fd01f140892852584f77572b0e43a29 Author: Jelle van der Waa <je...@vdwaa.nl> Date: Tue Sep 10 17:58:02 2013 +0200 writerfilter: remove old unit tests Change-Id: Icaa0560b812b96e41c52d7a43267873fe364ceb7 Reviewed-on: https://gerrit.libreoffice.org/5904 Reviewed-by: Andrzej J.R. Hunt <andr...@ahunt.org> Tested-by: Andrzej J.R. Hunt <andr...@ahunt.org> diff --git a/writerfilter/qa/cppunittests/odiapi/ExternalViewLogger.cxx b/writerfilter/qa/cppunittests/odiapi/ExternalViewLogger.cxx deleted file mode 100644 index a894030..0000000 --- a/writerfilter/qa/cppunittests/odiapi/ExternalViewLogger.cxx +++ /dev/null @@ -1,194 +0,0 @@ -/* -*- 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/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include "ExternalViewLogger.hxx" -#include <iostream> -#include <boost/assert.hpp> -#include <stdio.h> - -#ifdef WNT - #define SNPRINTF(buffer, size, format, args) _snprintf(buffer, size, format, args) -#else - #define SNPRINTF(buffer, size, format, args) snprintf(buffer, size, format, args) -#endif - -using namespace std; - -namespace util -{ - - NodeDescription::NodeDescription(const string& parent, const string& refersTo, const string& value, bool inUse) : - mParentNodeId(parent), - mRefersToNodeId(refersTo), - mNodeValue(value), - mInUse(inUse) - {} - - ExternalViewLoggerImpl::ExternalViewLoggerImpl(const string& fileName) : - mFileName(fileName), - mFile(fileName.c_str()) - { - if (!mFile) - throw "Cannot open file"; - } - - string ExternalViewLoggerImpl::getNewStyleName() - { - static int i = 0; - char buff[20]; - SNPRINTF(buff, sizeof(buff), "Style_%d", i++); - return string(buff); - } - - void ExternalViewLoggerImpl::beginTree() - { - mParentNodeStack.push(""); - } - - void ExternalViewLoggerImpl::dumpNodeContainer(const std::string& fileName) - { - std::ofstream file(fileName.c_str()); - NodeContainer_t::iterator iter = mNodeContainer.begin(); - NodeContainer_t::iterator iter_end = mNodeContainer.end(); - for (; iter != iter_end; ++iter) - { - file << iter->first << string(" ") << iter->second->mParentNodeId << string(" ") << iter->second->mRefersToNodeId << string(" ") << iter->second->mNodeValue << endl; - } - } - - void ExternalViewLoggerImpl::endTree() - { - mFile << "digraph {" << endl; - mFile << "Root [shape=box, color=grey];" << endl; - - while (!mParentNodeStack.empty()) - mParentNodeStack.pop(); - - mParentNodeStack.push("Root"); - - NodeContainer_t::iterator iter = mNodeContainer.begin(); - NodeContainer_t::iterator iter_end = mNodeContainer.end(); - for (; iter != iter_end; ++iter) - { - if (isUnreferencedLeaf(iter->first)) - { - string newStyleName = getNewStyleName(); - mFile << newStyleName << " [shape=box];" << endl; - mFile << mParentNodeStack.top() << " -> " << newStyleName << endl; - mParentNodeStack.push(newStyleName); - dumpTree(iter->first); - mParentNodeStack.pop(); - } - } - - mFile << "}" << endl; - } - - void ExternalViewLoggerImpl::beginNode(const std::string& nodeId, const std::string& value, const std::string& refersToNodeId, bool inUse) - { - mNodeContainer.insert( - NodeContainer_t::value_type(nodeId, - NodeDescription::Pointer_t(new NodeDescription(mParentNodeStack.top(), refersToNodeId, value, inUse)))); - mParentNodeStack.push(nodeId); - } - - void ExternalViewLoggerImpl::endNode(const std::string& nodeId) - { - mParentNodeStack.pop(); - } - - bool ExternalViewLoggerImpl::isLeaf(const std::string& nodeId) - { - bool isLeaf = true; - - NodeContainer_t::const_iterator iter = mNodeContainer.begin(); - NodeContainer_t::const_iterator iter_end = mNodeContainer.end(); - for (; iter != iter_end; ++iter) - { - if (iter->second->mParentNodeId == nodeId) - { - isLeaf = false; - break; - } - } - return isLeaf; - } - - bool ExternalViewLoggerImpl::isUnreferencedLeaf(const string& nodeId) - { - return isLeaf(nodeId) && !isReferenced(nodeId); - } - - bool ExternalViewLoggerImpl::isReferenced(const string& nodeId) - { - bool isReferenced = false; - - NodeContainer_t::const_iterator iter = mNodeContainer.begin(); - NodeContainer_t::const_iterator iter_end = mNodeContainer.end(); - for (; iter != iter_end; ++iter) - { - if (iter->second->mRefersToNodeId == nodeId) - { - isReferenced = true; - break; - } - } - return isReferenced; - } - - bool ExternalViewLoggerImpl::isReferingToOtherNode(const string& nodeId) - { - NodeContainer_t::const_iterator iter = mNodeContainer.find(nodeId); - BOOST_ASSERT(iter != mNodeContainer.end()); - return !iter->second->mRefersToNodeId.empty(); - } - - bool ExternalViewLoggerImpl::hasParent(const string& nodeId) - { - NodeContainer_t::const_iterator iter = mNodeContainer.find(nodeId); - BOOST_ASSERT(iter != mNodeContainer.end()); - return iter->second->mParentNodeId != "Root" && iter->second->mParentNodeId != ""; - } - - string ExternalViewLoggerImpl::getValue(const string& nodeId) - { - return mNodeContainer.find(nodeId)->second->mNodeValue; - } - - void ExternalViewLoggerImpl::dumpTree(const string& nodeId) - { - if (nodeId != "Root") - { - mFile << nodeId << " [label=\"(" << getValue(nodeId) << ")\",shape=box];" << endl; - mFile << mParentNodeStack.top() << " -> " << nodeId << ";" << endl; - if (isReferingToOtherNode(nodeId)) - { - mParentNodeStack.push(nodeId); - dumpTree(mNodeContainer.find(nodeId)->second->mRefersToNodeId); - mParentNodeStack.pop(); - } - } - - if (hasParent(nodeId)) - dumpTree(mNodeContainer.find(nodeId)->second->mParentNodeId); - } - -} // namespace util - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/qa/cppunittests/odiapi/ExternalViewLogger.hxx b/writerfilter/qa/cppunittests/odiapi/ExternalViewLogger.hxx deleted file mode 100644 index 50a393b..0000000 --- a/writerfilter/qa/cppunittests/odiapi/ExternalViewLogger.hxx +++ /dev/null @@ -1,82 +0,0 @@ -/* -*- 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/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_EXTERNALVIEWLOGGER_HXX -#define INCLUDED_EXTERNALVIEWLOGGER_HXX - -#include <odiapi/props/Logger.hxx> - -#include <fstream> -#include <stack> -#include <map> -#include <utility> -#include <boost/shared_ptr.hpp> - -namespace util { - - struct NodeDescription - { - typedef boost::shared_ptr<NodeDescription> Pointer_t; - - NodeDescription(const std::string& parent, const std::string& refersTo, const std::string& value, bool inUse); - - std::string mParentNodeId; - std::string mRefersToNodeId; - std::string mNodeValue; - bool mInUse; - }; - - /** A file logger - */ - class ExternalViewLoggerImpl : public Logger - { - public: - ExternalViewLoggerImpl(const std::string& fileName); - - virtual void beginTree(); - virtual void endTree(); - - virtual void beginNode(const std::string& nodeId, const std::string& value, const std::string& refersToNodeId, bool inUse); - virtual void endNode(const std::string& nodeId); - - private: - bool isLeaf(const std::string& nodeId); - bool isUnreferencedLeaf(const std::string& nodeId); - bool isReferenced(const std::string& nodeId); - bool isReferingToOtherNode(const std::string& nodeId); - bool hasParent(const std::string& nodeId); - void dumpTree(const std::string& nodeId); - std::string getValue(const std::string& nodeId); - std::string getNewStyleName(); - void dumpNodeContainer(const std::string& fileName); - - private: - typedef std::map<std::string, NodeDescription::Pointer_t> NodeContainer_t; - - std::string mFileName; - NodeContainer_t mNodeContainer; - std::ofstream mFile; - std::stack<std::string> mParentNodeStack; - }; - -} // namespace util - -#endif // INCLUDED_LOGGER_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/qa/cppunittests/odiapi/FileLoggerImpl.cxx b/writerfilter/qa/cppunittests/odiapi/FileLoggerImpl.cxx deleted file mode 100644 index 9d8afe6..0000000 --- a/writerfilter/qa/cppunittests/odiapi/FileLoggerImpl.cxx +++ /dev/null @@ -1,73 +0,0 @@ -/* -*- 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/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include "FileLoggerImpl.hxx" -#include <iostream> - -using namespace std; - -namespace util -{ - - FileLoggerImpl::FileLoggerImpl(const string& fileName) : - file_(fileName.c_str()) - { - if (!file_) - throw "Cannot open file"; - } - - void FileLoggerImpl::beginTree() - { - file_ << "digraph {" << endl; - } - - void FileLoggerImpl::endTree() - { - file_ << "}" << endl; - } - - void FileLoggerImpl::beginNode(const std::string& nodeId, const std::string& value, const std::string& refersToNodeId, bool inUse) - { - if (!nodeStack_.empty()) - { - if (inUse) - file_ << nodeId << " [ label=\"(" << value << ")\", shape=box, color=grey, style=filled ];"<< endl; - else - file_ << nodeId << " [ label=\"(" << value << ")\" ];"<< endl; - - file_ << nodeStack_.top() << " -> " << nodeId << ";" << endl; - - if (!refersToNodeId.empty()) - file_ << nodeId << " -> " << refersToNodeId << " [ color=grey, weight=0 ];" << endl; - } - else - { - file_ << nodeId << " [ label=\"(" << value << ")\", shape=diamond ];"<< endl; - } - nodeStack_.push(nodeId); - } - - void FileLoggerImpl::endNode(const std::string& nodeId) - { - nodeStack_.pop(); - } - -} // namespace util - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/qa/cppunittests/odiapi/FileLoggerImpl.hxx b/writerfilter/qa/cppunittests/odiapi/FileLoggerImpl.hxx deleted file mode 100644 index a32e367..0000000 --- a/writerfilter/qa/cppunittests/odiapi/FileLoggerImpl.hxx +++ /dev/null @@ -1,51 +0,0 @@ -/* -*- 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/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_FILELOGGERIMPL_HXX -#define INCLUDED_FILELOGGERIMPL_HXX - -#include <odiapi/props/Logger.hxx> -#include <fstream> -#include <stack> - -namespace util { - -/** A file logger - */ -class FileLoggerImpl : public util::Logger -{ -public: - FileLoggerImpl(const std::string& fileName); - - virtual void beginTree(); - virtual void endTree(); - - virtual void beginNode(const std::string& nodeId, const std::string& value, const std::string& refersToNodeId, bool inUse); - virtual void endNode(const std::string& nodeId); - -private: - std::ofstream file_; - std::stack<std::string> nodeStack_; -}; - -} // namespace util - -#endif // INCLUDED_LOGGER_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/qa/cppunittests/odiapi/export.exp b/writerfilter/qa/cppunittests/odiapi/export.exp deleted file mode 100644 index a13529d..0000000 --- a/writerfilter/qa/cppunittests/odiapi/export.exp +++ /dev/null @@ -1 +0,0 @@ -registerAllTestFunction diff --git a/writerfilter/qa/cppunittests/odiapi/export.map b/writerfilter/qa/cppunittests/odiapi/export.map deleted file mode 100644 index 06b6a4a..0000000 --- a/writerfilter/qa/cppunittests/odiapi/export.map +++ /dev/null @@ -1,25 +0,0 @@ -# -# 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/. -# -# This file incorporates work covered by the following license notice: -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed -# with this work for additional information regarding copyright -# ownership. The ASF licenses this file to you under the Apache -# License, Version 2.0 (the "License"); you may not use this file -# except in compliance with the License. You may obtain a copy of -# the License at http://www.apache.org/licenses/LICENSE-2.0 . -# - -UDK_3_0_0 { - global: - registerAllTestFunction; - - local: - *; -}; diff --git a/writerfilter/qa/cppunittests/odiapi/testCore.cxx b/writerfilter/qa/cppunittests/odiapi/testCore.cxx deleted file mode 100644 index a80de90..0000000 --- a/writerfilter/qa/cppunittests/odiapi/testCore.cxx +++ /dev/null @@ -1,166 +0,0 @@ -/* -*- 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/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - - -#include <testshl/simpleheader.hxx> -#include <odiapi/core/Node.hxx> -#include <odiapi/props/Properties.hxx> - -using namespace odiapi::core; -using namespace odiapi::props; -using namespace writerfilter; -using namespace std; - -class TestCore : public CppUnit::TestFixture -{ -public: - void testCreateCore() - { - PropertyPool::Pointer_t pool = createPropertyPool(); - PropertyBag_Pointer_t pb = createPropertyBag(); - - pb->insert(createIntegerProperty(NS_fo::LN_font_weight, 12)); - PropertyPoolHandle_Pointer_t ph = pool->insert(pb); - - Node::Pointer_t node = createNode(NS_style::LN_char, ph, "NS_style::LN_char"); - - CPPUNIT_ASSERT_MESSAGE("Create node failed wrong node id", node->getId() == NS_style::LN_char); - CPPUNIT_ASSERT_MESSAGE("Create node failed wrong text", node->getText() == "NS_style::LN_char"); - CPPUNIT_ASSERT_MESSAGE("Create node failed wrong pool handle", node->getProperties() == ph); - } - - void testInsertSibling() - { - PropertyPool::Pointer_t pool = createPropertyPool(); - PropertyBag_Pointer_t pb = createPropertyBag(); - - pb->insert(createIntegerProperty(NS_fo::LN_font_weight, 12)); - PropertyPoolHandle_Pointer_t ph = pool->insert(pb); - - Node::Pointer_t node1 = createNode(NS_style::LN_char, ph, "Text"); - Node::Pointer_t node2 = createNode(NS_style::LN_char, ph, "\\par"); - - node1->insertSibling(node2); - - string postfixSeq = node1->getText(); - const Node* n = node1.get(); - while (n->hasNext()) - { - n = &n->getNext(); - postfixSeq = postfixSeq + n->getText(); - } - - CPPUNIT_ASSERT_MESSAGE("Insert sibling failed", postfixSeq == "Text\\par"); - - Node::Pointer_t node3 = createNode(NS_style::LN_char, ph, "\\span"); - - node1->insertSibling(node3); - - postfixSeq = node1->getText(); - n = node1.get(); - while (n->hasNext()) - { - n = &n->getNext(); - postfixSeq = postfixSeq + n->getText(); - } - - CPPUNIT_ASSERT_MESSAGE("Insert sibling failed", postfixSeq == "Text\\span\\par"); - } - - void testAppendChildren() - { - PropertyPool::Pointer_t pool = createPropertyPool(); - PropertyBag_Pointer_t pb = createPropertyBag(); - - pb->insert(createIntegerProperty(NS_fo::LN_font_weight, 12)); - PropertyPoolHandle_Pointer_t ph = pool->insert(pb); - - Node::Pointer_t node1 = createNode(NS_style::LN_char, ph, "Text"); - const Node* pn1 = node1.get(); - - Node::Pointer_t node2 = createNode(NS_style::LN_char, ph, "\\par"); - - node2->appendChildren(node1); - - CPPUNIT_ASSERT_MESSAGE("Append children failed", &node2->getFirstChild() == pn1); - - const Node* n = &node2->getFirstChild(); - string postfixSeq = n->getText() + n->getNext().getText(); - - CPPUNIT_ASSERT_MESSAGE("Append children failed", postfixSeq == "Text\\par"); - } - - void testCore() - { - PropertyPool::Pointer_t pool = createPropertyPool(); - PropertyBag_Pointer_t pb = createPropertyBag(); - - pb->insert(createIntegerProperty(NS_fo::LN_font_weight, 12)); - PropertyPoolHandle_Pointer_t ph = pool->insert(pb); - - Node::Pointer_t node1 = createNode(NS_style::LN_char, ph, "A"); - Node::Pointer_t node2 = createNode(NS_style::LN_char, ph, "\\span"); - - node2->appendChildren(node1); - - Node::Pointer_t node3 = createNode(NS_style::LN_char, ph, "B"); - Node::Pointer_t node4 = createNode(NS_style::LN_char, ph, "\\span"); - - node4->appendChildren(node3); - - node2->insertSibling(node4); - - Node::Pointer_t node5 = createNode(NS_style::LN_char, ph, "\\par"); - - node5->appendChildren(node2); - - Node::Pointer_t node6 = createNode(NS_style::LN_char, ph, "C"); - Node::Pointer_t node7 = createNode(NS_style::LN_char, ph, "\\span"); - - node7->appendChildren(node6); - - node5->appendChildren(node7); - - - string postfixSeq = node5->getText(); - const Node* n = node5.get(); - while (n->hasPrevious()) - { - n = &n->getPrevious(); - postfixSeq = postfixSeq + n->getText(); - } - - CPPUNIT_ASSERT_MESSAGE("Insert sibling failed", postfixSeq == "\\par\\spanC\\spanB\\spanA"); - } - - CPPUNIT_TEST_SUITE(TestCore); - CPPUNIT_TEST(testCreateCore); - CPPUNIT_TEST(testInsertSibling); - CPPUNIT_TEST(testAppendChildren); - CPPUNIT_TEST(testCore); - CPPUNIT_TEST_SUITE_END(); -}; - -//##################################### -// register test suites -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(TestCore, "TestCore"); - -//NOADDITIONAL; - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/qa/cppunittests/odiapi/testProperty.cxx b/writerfilter/qa/cppunittests/odiapi/testProperty.cxx deleted file mode 100644 index 091853f..0000000 --- a/writerfilter/qa/cppunittests/odiapi/testProperty.cxx +++ /dev/null @@ -1,675 +0,0 @@ -/* -*- 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/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include <testshl/simpleheader.hxx> -#include <odiapi/props/Properties.hxx> -#include "FileLoggerImpl.hxx" -#include "ExternalViewLogger.hxx" -#include <osl/file.hxx> -#include <osl/thread.hxx> -#include <exception> -#include <stdio.h> - -using namespace odiapi::props; -using namespace writerfilter; -using namespace std; -using namespace util; -using namespace osl; - -/** Helper function, get a temporary file name - */ -OString getTempFileName(const OUString& fileName) -{ - OUString ousTmpUrl; - FileBase::getTempDirURL(ousTmpUrl); - if (!ousTmpUrl.endsWithIgnoreAsciiCaseAsciiL("/", 1)) - ousTmpUrl += "/"; - ousTmpUrl += fileName; - - OUString sysTmpPath; - FileBase::getSystemPathFromFileURL(ousTmpUrl, sysTmpPath); - - return OUStringToOString(sysTmpPath, osl_getThreadTextEncoding()); -} - -class TestProperty : public CppUnit::TestFixture -{ -public: - void testCreateIntProperty() - { - Property::Pointer_t intProp = createIntegerProperty(NS_fo::LN_font_weight, 35); - CPPUNIT_ASSERT_MESSAGE("Wrong property id", intProp->getId() == NS_fo::LN_font_weight); - CPPUNIT_ASSERT_MESSAGE("Wrong int value", intProp->getIntValue() == 35); - CPPUNIT_ASSERT_MESSAGE("Wrong string value", intProp->getStringValue() == "35"); - } - - void testCreateStringProperty() - { - Property::Pointer_t strProp = createStringProperty(NS_style::LN_font_face, "Times New Roman"); - CPPUNIT_ASSERT_MESSAGE("Wrong property id", strProp->getId() == NS_style::LN_font_face); - CPPUNIT_ASSERT_MESSAGE("Wrong string value", strProp->getStringValue() == "Times New Roman"); - try - { - strProp->getIntValue(); - } - catch(const logic_error& ex) - { - return; - } - CPPUNIT_ASSERT_MESSAGE("Operation getIntValue should not be supported by StringProperty", false); - } - - void testCreateCompositeProperty() - { - PropertyPool::Pointer_t pool = createPropertyPool(); - - PropertyBag_Pointer_t pb = createPropertyBag(); - pb->insert(createStringProperty(NS_style::LN_font_face, "Times")); - pb->insert(createIntegerProperty(NS_fo::LN_font_weight, 12)); - Property::Pointer_t cp1 = createCompositeProperty(NS_style::LN_paragraph_properties, pool->insert(pb)); - - CPPUNIT_ASSERT_MESSAGE("Failed to get NS_style::LN_font_face", cp1->findChild(NS_style::LN_font_face)->getStringValue() == "Times"); - CPPUNIT_ASSERT_MESSAGE("Failed to get NS_fo::LN_font_weight", cp1->findChild(NS_fo::LN_font_weight)->getIntValue() == 12); - } - - void testCompareSimpleProperties() - { - Property::Pointer_t pb1 = createStringProperty(NS_style::LN_font_face, "Times New Roman"); - Property::Pointer_t pb2 = createStringProperty(NS_style::LN_font_face, "Times New Roman"); - CPPUNIT_ASSERT_MESSAGE("pb1 == pb2", pb1 == pb2); - - Property::Pointer_t fw = createIntegerProperty(NS_fo::LN_font_weight, 12); - Property::Pointer_t ff = createStringProperty(NS_style::LN_font_face, "Times"); - - CPPUNIT_ASSERT_MESSAGE("fw == fw failed", fw == fw); - CPPUNIT_ASSERT_MESSAGE("fw > ff failed", ff < fw); - CPPUNIT_ASSERT_MESSAGE("ff == ff failed", ff == ff); - CPPUNIT_ASSERT_MESSAGE("!(ff < fw) failed", !(fw < ff)); - } - - void testCompareCompositeProperties() - { - PropertyPool::Pointer_t pool = createPropertyPool(); - - PropertyBag_Pointer_t pb1 = createPropertyBag(); - pb1->insert(createStringProperty(NS_style::LN_font_face, "Times")); - pb1->insert(createIntegerProperty(NS_fo::LN_font_weight, 12)); - Property::Pointer_t cp1 = createCompositeProperty(NS_style::LN_paragraph_properties, pool->insert(pb1)); - - PropertyBag_Pointer_t ps2 = createPropertyBag(); - ps2->insert(createStringProperty(NS_style::LN_font_face, "Times")); - ps2->insert(createIntegerProperty(NS_fo::LN_font_weight, 12)); - Property::Pointer_t cp2 = createCompositeProperty(NS_style::LN_paragraph_properties, pool->insert(ps2)); - - CPPUNIT_ASSERT_MESSAGE("cp1 == cp2 failed", cp1 == cp2); - } - - void testPropertyBagAsStructure() - { - PropertyBag_Pointer_t propSeq = createPropertyBag(); - Property::Pointer_t fontWeight12 = createIntegerProperty(NS_fo::LN_font_weight, 12); - - propSeq->insert(fontWeight12); - CPPUNIT_ASSERT_MESSAGE("Inserting property into property sequence failed", propSeq->size() == 1); - CPPUNIT_ASSERT_MESSAGE("Property not in property sequence", propSeq->find(NS_fo::LN_font_weight)->getIntValue() == 12); - } - - void testNoDuplicatesInPropertyBagStructures() - { - PropertyBag_Pointer_t propSeq = createPropertyBag(); - Property::Pointer_t fontWeight12 = createIntegerProperty(NS_fo::LN_font_weight, 12); - propSeq->insert(fontWeight12); - - CPPUNIT_ASSERT_MESSAGE("Expect property sequence with 1 element", propSeq->size() == 1); - CPPUNIT_ASSERT_MESSAGE("Expect property sequence with one int value 12", propSeq->find(NS_fo::LN_font_weight)->getIntValue() == 12); - - Property::Pointer_t fontWeight14 = createIntegerProperty(NS_fo::LN_font_weight, 14); - propSeq->insert(fontWeight14); - - CPPUNIT_ASSERT_MESSAGE("Expect property sequence with 1 element", propSeq->size() == 1); - CPPUNIT_ASSERT_MESSAGE("Expect property sequence with one int value 14", propSeq->find(NS_fo::LN_font_weight)->getIntValue() == 14); - } - - void testPropertyBagAsArray() - { - PropertyBag_Pointer_t pb = createPropertyBag(); - Property::Pointer_t fontWeight12 = createIntegerProperty(NS_fo::LN_font_weight, 12); - - pb->insert(0, fontWeight12); - - CPPUNIT_ASSERT_MESSAGE("Inserting property into property sequence failed", pb->size() == 1); - CPPUNIT_ASSERT_MESSAGE("Property not in property sequence", pb->get(0)->getIntValue() == 12); - CPPUNIT_ASSERT_MESSAGE("Wrong property id", pb->get(0)->getId() == NS_fo::LN_font_weight); - - Iterator<Property::Pointer_t>::Pointer_t iter = pb->createIterator(); - for (iter->first(); !iter->isDone(); iter->next()) - { - CPPUNIT_ASSERT_MESSAGE("Test property bag as array failed", iter->getCurrent()->getId() == NS_fo::LN_font_weight); - } - } - - void testCopyPropertyBag() - { - PropertyBag_Pointer_t propBag = createPropertyBag(); - Property::Pointer_t fontWeight12 = createIntegerProperty(NS_fo::LN_font_weight, 12); - - propBag->insert(0, fontWeight12); - - CPPUNIT_ASSERT_MESSAGE("Inserting property into property sequence failed", propBag->size() == 1); - CPPUNIT_ASSERT_MESSAGE("Property not in property sequence", propBag->get(0)->getIntValue() == 12); - CPPUNIT_ASSERT_MESSAGE("Wrong property id", propBag->get(0)->getId() == NS_fo::LN_font_weight); - - PropertyBag_Pointer_t propBagCopy = propBag->copy(); - - CPPUNIT_ASSERT_MESSAGE("Copy property bag failed, distinct instances expected", propBag.get() != propBagCopy.get()); - - CPPUNIT_ASSERT_MESSAGE("Copy property bag failed", propBagCopy->size() == 1); - CPPUNIT_ASSERT_MESSAGE("Copy property bag failed", propBagCopy->get(0)->getIntValue() == 12); - CPPUNIT_ASSERT_MESSAGE("Copy property bag failed", propBagCopy->get(0)->getId() == NS_fo::LN_font_weight); - } - - void testClearPropertyBag() - { - PropertyBag_Pointer_t pb = createPropertyBag(); - pb->insert(createStringProperty(NS_style::LN_font_face, "Times")); - pb->insert(createIntegerProperty(NS_fo::LN_font_weight, 12)); - - CPPUNIT_ASSERT_MESSAGE("Insert into property bag failed", pb->size() == 2); - - pb->clear(); - - CPPUNIT_ASSERT_MESSAGE("Clearing property bag failed", pb->empty()); - } - - void testSortPropertyBag() - { - QName_t sortedOrder [] = { NS_style::LN_font_face, NS_fo::LN_font_weight }; - - PropertyBag_Pointer_t pb = createPropertyBag(); - pb->insert(createIntegerProperty(NS_fo::LN_font_weight, 12)); - pb->insert(createStringProperty(NS_style::LN_font_face, "Times")); - - pb->sort(); - - Iterator<Property::Pointer_t>::Pointer_t iter = pb->createIterator(); - int i = 0; - for (iter->first(); !iter->isDone(); iter->next(), i++) - { - CPPUNIT_ASSERT_MESSAGE("Sorting property bag failed", sortedOrder[i] == iter->getCurrent()->getId()); - } - } - - void testDuplicateValuesInArray() - { - PropertyBag_Pointer_t propSeq = createPropertyBag(); - - Property::Pointer_t fontWeight1 = createIntegerProperty(NS_fo::LN_font_weight, 12); - propSeq->insert(0, fontWeight1); - - Property::Pointer_t fontWeight2 = createIntegerProperty(NS_fo::LN_font_weight, 12); - propSeq->insert(1, fontWeight2); - - CPPUNIT_ASSERT_MESSAGE("Inserting property into property sequence failed", propSeq->size() == 2); - CPPUNIT_ASSERT_MESSAGE("Property not in property sequence", - propSeq->get(0)->getId() == propSeq->get(1)->getId() && - propSeq->get(0)->getIntValue() == propSeq->get(1)->getIntValue()); - } - - void testPropertyPool() - { - PropertyPool::Pointer_t pool = createPropertyPool(); - - PropertyBag_Pointer_t pb1 = createPropertyBag(); - pb1->insert(createStringProperty(NS_style::LN_font_face, "Times")); - pb1->insert(createIntegerProperty(NS_fo::LN_font_weight, 12)); - PropertyPoolHandle_Pointer_t ph1 = pool->insert(pb1); - - PropertyBag_Pointer_t ps2 = createPropertyBag(); - ps2->insert(createIntegerProperty(NS_fo::LN_font_weight, 12)); - ps2->insert(createStringProperty(NS_style::LN_font_face, "Times")); - PropertyPoolHandle_Pointer_t ph2 = pool->insert(ps2); - - CPPUNIT_ASSERT_MESSAGE("ph1 == ph2 failed", ph1 == ph2); - - PropertyBag_Pointer_t ps3 = createPropertyBag(); - ps3->insert(createIntegerProperty(NS_fo::LN_font_weight, 14)); - ps3->insert(createStringProperty(NS_style::LN_font_face, "Times")); - - PropertyPoolHandle_Pointer_t ph3 = pool->insert(ps3); - - CPPUNIT_ASSERT_MESSAGE("ph2 != ph3 failed", ph2 != ph3); - - PropertyBag_Pointer_t ps4 = createPropertyBag(); - ps4->insert(0, createIntegerProperty(NS_fo::LN_font_weight, 12)); - ps4->insert(1, createIntegerProperty(NS_fo::LN_font_weight, 12)); - ps4->insert(2, createIntegerProperty(NS_fo::LN_font_weight, 12)); - ps4->insert(3, createIntegerProperty(NS_fo::LN_font_weight, 12)); - - pool->insert(ps4); - - OString tmpFileName = getTempFileName(OUString("testPropertyPool_int.dot")); - printf("Pool dump: %s\n", tmpFileName.getStr()); - FileLoggerImpl fl(tmpFileName.getStr()); - pool->dump(&fl); - - OString tmpFileName2 = getTempFileName(OUString("testPropertyPool_ext.dot")); - printf("Pool dump: %s\n", tmpFileName2.getStr()); - ExternalViewLoggerImpl evl(tmpFileName2.getStr()); - pool->dump(&evl); - } - - void testCompareEqualPropertyTypesWithDifferentIdsDoesNotFail() - { - PropertyPool::Pointer_t pool = createPropertyPool(); - - PropertyBag_Pointer_t pb1 = createPropertyBag(); - pb1->insert(createIntegerProperty(NS_style::LN_tab_stop, 100)); - pb1->insert(createStringProperty(NS_style::LN_type, "left")); - Property::Pointer_t tab100 = createCompositeProperty(NS_style::LN_tab_stop, pool->insert(pb1)); - - pb1->clear(); - pb1->insert(createIntegerProperty(NS_fo::LN_font_weight, 12)); - pb1->insert(createStringProperty(NS_style::LN_font_face, "Times New Roman")); - Property::Pointer_t charProps1 = createCompositeProperty(NS_style::LN_char, pool->insert(pb1)); - - pb1->clear(); - pb1->insert(createIntegerProperty(NS_fo::LN_font_weight, 12)); - pb1->insert(createStringProperty(NS_style::LN_font_face, "Times New Roman")); - Property::Pointer_t charProps2 = createCompositeProperty(NS_style::LN_char, pool->insert(pb1)); - - CPPUNIT_ASSERT_MESSAGE("CharProps1 == CharProps2 failed", charProps1 == charProps2); - } - - void testComplexParagraphProperty() - { - PropertyPool::Pointer_t pool = createPropertyPool(); - PropertyBag_Pointer_t pb1 = createPropertyBag(); - - pb1->insert(createIntegerProperty(NS_style::LN_position, 100)); - pb1->insert(createStringProperty(NS_style::LN_type, "left")); - Property::Pointer_t tab100 = createCompositeProperty(NS_style::LN_tab_stop, pool->insert(pb1)); - - pb1->clear(); - - pb1->insert(createIntegerProperty(NS_style::LN_position, 200)); - pb1->insert(createStringProperty(NS_style::LN_type, "center")); - Property::Pointer_t tab200 = createCompositeProperty(NS_style::LN_tab_stop, pool->insert(pb1)); - - CPPUNIT_ASSERT_MESSAGE("tab100 != tab200 failed", tab100 != tab200); - - pb1->clear(); - pb1->insert(100, tab100); - pb1->insert(200, tab200); - Property::Pointer_t tabs = createCompositeProperty(NS_style::LN_tab_stops, pool->insert(pb1)); - - pb1->clear(); - pb1->insert(createIntegerProperty(NS_fo::LN_font_weight, 12)); - pb1->insert(createStringProperty(NS_style::LN_font_face, "Times New Roman")); - Property::Pointer_t charProps = createCompositeProperty(NS_style::LN_char, pool->insert(pb1)); - - pb1->clear(); - pb1->insert(createIntegerProperty(NS_fo::LN_line_height, 20)); - pb1->insert(tabs); - pb1->insert(charProps); - Property::Pointer_t paraProps = createCompositeProperty(NS_style::LN_paragraph_properties, pool->insert(pb1)); - - pb1->clear(); - pb1->insert(createIntegerProperty(NS_style::LN_position, 100)); - pb1->insert(createStringProperty(NS_style::LN_type, "left")); - Property::Pointer_t tab300 = createCompositeProperty(NS_style::LN_tab_stop, pool->insert(pb1)); - - pb1->clear(); - pb1->insert(createIntegerProperty(NS_style::LN_position, 200)); - pb1->insert(createStringProperty(NS_style::LN_type, "center")); - Property::Pointer_t tab400 = createCompositeProperty(NS_style::LN_tab_stop, pool->insert(pb1)); - - CPPUNIT_ASSERT_MESSAGE("tab300 != tab400 failed", tab300 != tab400); - - pb1->clear(); - pb1->insert(100, tab300); - pb1->insert(200, tab400); - Property::Pointer_t tabulators = createCompositeProperty(NS_style::LN_tab_stops, pool->insert(pb1)); - - CPPUNIT_ASSERT_MESSAGE("tabs == tabulators failed", tabs == tabulators); - - pb1->clear(); - pb1->insert(createIntegerProperty(NS_fo::LN_font_weight, 12)); - pb1->insert(createStringProperty(NS_style::LN_font_face, "Times New Roman")); - Property::Pointer_t characterProps = createCompositeProperty(NS_style::LN_char, pool->insert(pb1)); - - CPPUNIT_ASSERT_MESSAGE("Comparison of character properties failed", charProps == characterProps); - - pb1->clear(); - pb1->insert(createIntegerProperty(NS_fo::LN_line_height, 20)); - pb1->insert(tabulators); - pb1->insert(characterProps); - Property::Pointer_t paragraphProps = createCompositeProperty(NS_style::LN_paragraph_properties, pool->insert(pb1)); - - CPPUNIT_ASSERT_MESSAGE("paraProps == failed failed", paraProps == paragraphProps); - - OString tmpFileName = getTempFileName(OUString("testComplexParaProps_int.dot")); - printf("Pool dump: %s\n", tmpFileName.getStr()); - FileLoggerImpl fl(tmpFileName.getStr()); - pool->dump(&fl); - - OString tmpFileName2 = getTempFileName(OUString("testComplexParaProps_ext.dot")); - printf("Pool dump: %s\n", tmpFileName2.getStr()); - ExternalViewLoggerImpl evl(tmpFileName2.getStr()); - pool->dump(&evl); - } - - void testInsertEmptyPropertyBag() - { - PropertyPool::Pointer_t pool = createPropertyPool(); - PropertyBag_Pointer_t pb = createPropertyBag(); - PropertyPoolHandle_Pointer_t ph = pool->insert(pb); - - CPPUNIT_ASSERT_MESSAGE("Inserting empty property bag failed", ph->getPropertyBag()->empty()); - } - - void testDumpPropertyPool() - { - PropertyPool::Pointer_t pool = createPropertyPool(); - PropertyBag_Pointer_t pb1 = createPropertyBag(); - pb1->insert(createIntegerProperty(NS_fo::LN_font_weight, 12)); - pb1->insert(createStringProperty(NS_style::LN_font_face, "Times")); - PropertyPoolHandle_Pointer_t ph1 = pool->insert(pb1); - - Iterator<PropertyBag_Pointer_t>::Pointer_t iter = pool->createIterator(); - - int i = 0; - for (iter->first(); !iter->isDone(); iter->next(), i++) /* nothing to do */; - - CPPUNIT_ASSERT_MESSAGE("Dump PropertyBags failed", i == 1); - - /* Insert an equal PropertyBag again, as PropertyBags in the - pool are unique there must be still just one PropertyBag in the pool - */ - PropertyBag_Pointer_t pb2 = createPropertyBag(); - pb2->insert(createIntegerProperty(NS_fo::LN_font_weight, 12)); - pb2->insert(createStringProperty(NS_style::LN_font_face, "Times")); - PropertyPoolHandle_Pointer_t ph2 = pool->insert(pb2); - - iter = pool->createIterator(); - - i = 0; - for (iter->first(); !iter->isDone(); iter->next(), i++) /* nothing to do */; - - CPPUNIT_ASSERT_MESSAGE("Dump PropertyBags failed", i == 1); - - { // scope - - /* Insert a different PropertyBag into the pool now there must be - two PropertyBags in the pool */ - PropertyBag_Pointer_t pb3 = createPropertyBag(); - pb3->insert(createIntegerProperty(NS_style::LN_position, 12)); - pb3->insert(createStringProperty(NS_style::LN_type, "left")); - PropertyPoolHandle_Pointer_t ph3 = pool->insert(pb3); - - iter = pool->createIterator(); - - i = 0; - for (iter->first(); !iter->isDone(); iter->next(), i++) /* nothing to do */; - - CPPUNIT_ASSERT_MESSAGE("Dump PropertyBags failed", i == 2); - - } // end scope - - /* as pb3 is only valid in the above scope the property pool must - now contain just one property bag - */ - iter = pool->createIterator(); - - i = 0; - for (iter->first(); !iter->isDone(); iter->next(), i++) /*nothing to do*/; - - CPPUNIT_ASSERT_MESSAGE("Dump PropertyBags failed", i == 1); - } - - void testInsertPropertySubsets() - { - PropertyPool::Pointer_t pool = createPropertyPool(); - - PropertyBag_Pointer_t pb1 = createPropertyBag(); - pb1->insert(createIntegerProperty(NS_fo::LN_font_weight, 12)); - pb1->insert(createStringProperty(NS_style::LN_font_face, "Times")); - PropertyPoolHandle_Pointer_t ph1 = pool->insert(pb1); - - /* Insert an equal PropertyBag again, as PropertyBags in the - pool are unique there must be still just one PropertyBag in the pool - */ - pb1->clear(); - pb1->insert(createIntegerProperty(NS_fo::LN_font_weight, 12)); - PropertyPoolHandle_Pointer_t ph2 = pool->insert(pb1); - - CPPUNIT_ASSERT_MESSAGE("ph1 != ph2 failed", ph1 != ph2); - - Iterator<PropertyBag_Pointer_t>::Pointer_t iter = pool->createIterator(); - - int i = 0; - for (iter->first(); !iter->isDone(); iter->next(), i++) /* nothing to do */; - - CPPUNIT_ASSERT_MESSAGE("Dump PropertyBags failed", i == 2); - } - - void testDumpEmptyPropertyPool() - { - PropertyPool::Pointer_t pool = createPropertyPool(); - Iterator<PropertyBag_Pointer_t>::Pointer_t iter = pool->createIterator(); - - int i = 0; - for (iter->first(); !iter->isDone(); iter->next(), i++) /*nothing to do*/; - - CPPUNIT_ASSERT_MESSAGE("Dump PropertyBags failed", i == 0); - } - - void testPropertyPoolGarbageCollection() - { - PropertyPool::Pointer_t pool = createPropertyPool(); - - PropertyBag_Pointer_t pb1 = createPropertyBag(); - pb1->insert(createIntegerProperty(NS_fo::LN_font_weight, 12)); - pb1->insert(createStringProperty(NS_style::LN_font_face, "Times")); - pb1->insert(createIntegerProperty(NS_fo::LN_line_height, 20)); - PropertyPoolHandle_Pointer_t ph1 = pool->insert(pb1); - - { - PropertyBag_Pointer_t pb2 = createPropertyBag(); - pb2->insert(createIntegerProperty(NS_fo::LN_font_weight, 12)); - pb2->insert(createStringProperty(NS_style::LN_font_face, "Roman")); - PropertyPoolHandle_Pointer_t ph2 = pool->insert(pb2); - - OString tmpFileName = getTempFileName(OUString("testPropPoolGarbageColl_1.dot")); - printf("Pool dump: %s\n", tmpFileName.getStr()); - FileLoggerImpl fl(tmpFileName.getStr()); - pool->dump(&fl); - - } - - OString tmpFileName = getTempFileName(OUString("testPropPoolGarbageColl_2.dot")); - printf("Pool dump: %s\n", tmpFileName.getStr()); - FileLoggerImpl fl(tmpFileName.getStr()); - pool->dump(&fl); - - pool->garbageCollection(); - - OString tmpFileName2 = getTempFileName(OUString("testPropPoolGarbageColl_after.dot")); - printf("Pool dump: %s\n", tmpFileName2.getStr()); - FileLoggerImpl fl2(tmpFileName2.getStr()); - pool->dump(&fl2); - - } - - void testDumpPropertyPoolAfterGarbageCollection() - { - PropertyPool::Pointer_t pool = createPropertyPool(); - - PropertyBag_Pointer_t pb1 = createPropertyBag(); - pb1->insert(createIntegerProperty(NS_fo::LN_font_weight, 12)); - pb1->insert(createStringProperty(NS_style::LN_font_face, "Times")); - pb1->insert(createIntegerProperty(NS_fo::LN_line_height, 20)); - PropertyPoolHandle_Pointer_t ph1 = pool->insert(pb1); - - { - PropertyBag_Pointer_t pb2 = createPropertyBag(); - pb2->insert(createIntegerProperty(NS_fo::LN_font_weight, 12)); - pb2->insert(createStringProperty(NS_style::LN_font_face, "Roman")); - PropertyPoolHandle_Pointer_t ph2 = pool->insert(pb2); - - Iterator<PropertyBag_Pointer_t>::Pointer_t iter = pool->createIterator(); - - int i = 0; - for (iter->first(); !iter->isDone(); iter->next(), i++) /*nothing to do*/; - - CPPUNIT_ASSERT_MESSAGE("Expectation '2 PropertyBags in PropertyPool' failed", i == 2); - } - - pool->garbageCollection(); - - Iterator<PropertyBag_Pointer_t>::Pointer_t iter = pool->createIterator(); - - int i = 0; - for (iter->first(); !iter->isDone(); iter->next(), i++) /*nothing to do*/; - - CPPUNIT_ASSERT_MESSAGE("Expectation '1 PropertyBag in PropertyPool' failed", i == 1); - } - - // 'cm', 'mm', 'inch', 'pt', 'px', 'pc' - void testCreateTwipsProperty() - { - Property::Pointer_t tp1 = createTwipsProperty(NS_style::LN_position, "1cm"); - CPPUNIT_ASSERT_MESSAGE("getIntValue: wrong twips value returned", tp1->getIntValue() == 567); - CPPUNIT_ASSERT_MESSAGE("getStringValue: wrong twips value returned", tp1->getStringValue() == "1.000 cm"); - - Property::Pointer_t tp2 = createTwipsProperty(NS_style::LN_position, "1 cm"); - CPPUNIT_ASSERT_MESSAGE("getIntValue: wrong twips value returned", tp2->getIntValue() == 567); - CPPUNIT_ASSERT_MESSAGE("getStringValue: wrong twips value returned", tp2->getStringValue() == "1.000 cm"); - - Property::Pointer_t tp3 = createTwipsProperty(NS_style::LN_position, "1 cm "); - CPPUNIT_ASSERT_MESSAGE("getIntValue: wrong twips value returned", tp3->getIntValue() == 567); - CPPUNIT_ASSERT_MESSAGE("getStringValue: wrong twips value returned", tp3->getStringValue() == "1.000 cm"); - - Property::Pointer_t tp4 = createTwipsProperty(NS_style::LN_position, "0 cm"); - CPPUNIT_ASSERT_MESSAGE("getIntValue: wrong twips value returned", tp4->getIntValue() == 0); - CPPUNIT_ASSERT_MESSAGE("getStringValue: wrong twips value returned", tp4->getStringValue() == "0.000 cm"); - - Property::Pointer_t tp5 = createTwipsProperty(NS_style::LN_position, "10mm"); - CPPUNIT_ASSERT_MESSAGE("getIntValue: wrong twips value returned", tp5->getIntValue() == 567); - CPPUNIT_ASSERT_MESSAGE("getStringValue: wrong twips value returned", tp5->getStringValue() == "1.000 cm"); - - Property::Pointer_t tp6 = createTwipsProperty(NS_style::LN_position, 567); - CPPUNIT_ASSERT_MESSAGE("getIntValue: wrong twips value returned", tp6->getIntValue() == 567); - CPPUNIT_ASSERT_MESSAGE("getStringValue: wrong twips value returned", tp6->getStringValue() == "1.000 cm"); - - Property::Pointer_t tp7 = createTwipsProperty(NS_style::LN_position, "100pt"); - CPPUNIT_ASSERT_MESSAGE("getIntValue: wrong twips value returned", tp7->getIntValue() == 2000); - CPPUNIT_ASSERT_MESSAGE("getStringValue: wrong twips value returned", tp7->getStringValue() == "3.527 cm"); - - Property::Pointer_t tp8 = createTwipsProperty(NS_style::LN_position, "1 in"); - CPPUNIT_ASSERT_MESSAGE("getIntValue: wrong twips value returned", tp8->getIntValue() == 1440); - CPPUNIT_ASSERT_MESSAGE("getStringValue: wrong twips value returned", tp8->getStringValue() == "2.540 cm"); - - Property::Pointer_t tp9 = createTwipsProperty(NS_style::LN_position, "-1 cm"); - CPPUNIT_ASSERT_MESSAGE("getIntValue: wrong twips value returned", tp9->getIntValue() == -567); - CPPUNIT_ASSERT_MESSAGE("getStringValue: wrong twips value returned", tp9->getStringValue() == "-1.000 cm"); - - Property::Pointer_t tp10 = createTwipsProperty(NS_style::LN_position, "+1 cm"); - CPPUNIT_ASSERT_MESSAGE("getIntValue: wrong twips value returned", tp10->getIntValue() == 567); - CPPUNIT_ASSERT_MESSAGE("getStringValue: wrong twips value returned", tp10->getStringValue() == "1.000 cm"); - - Property::Pointer_t tp11 = createTwipsProperty(NS_style::LN_position, "1 pt "); - Property::Pointer_t tp12 = createTwipsProperty(NS_style::LN_position, "2pt"); - CPPUNIT_ASSERT_MESSAGE("Comparing twips properties failed", tp11 < tp12); - } - - void testCreateInvalidTwipsProperty() - { - try - { - Property::Pointer_t tp = createTwipsProperty(NS_style::LN_position, "0,1 cm"); - } - catch(std::invalid_argument& ) - { - return; // OK - } - CPPUNIT_ASSERT_MESSAGE("Creating an twips property with invalid number must fail", false); - } - - void testCreateInvalidTwipsProperty2() - { - try - { - Property::Pointer_t tp = createTwipsProperty(NS_style::LN_position, ""); - } - catch(std::invalid_argument& ) - { - return; // OK - } - CPPUNIT_ASSERT_MESSAGE("Creating an twips property with invalid number must fail", false); - } - - void testCreateInvalidTwipsProperty3() - { - try - { - Property::Pointer_t tp = createTwipsProperty(NS_style::LN_position, " cm"); - } - catch(std::invalid_argument& ) - { - return; // OK - } - CPPUNIT_ASSERT_MESSAGE("Creating an twips property with invalid number must fail", false); - } - - CPPUNIT_TEST_SUITE(TestProperty); - CPPUNIT_TEST(testCreateIntProperty); - CPPUNIT_TEST(testCreateStringProperty); - CPPUNIT_TEST(testCreateCompositeProperty); - CPPUNIT_TEST(testPropertyBagAsStructure); - CPPUNIT_TEST(testNoDuplicatesInPropertyBagStructures); - CPPUNIT_TEST(testPropertyBagAsArray); - CPPUNIT_TEST(testDuplicateValuesInArray); - CPPUNIT_TEST(testCopyPropertyBag); - CPPUNIT_TEST(testClearPropertyBag); - CPPUNIT_TEST(testSortPropertyBag); - CPPUNIT_TEST(testCompareSimpleProperties); - CPPUNIT_TEST(testCompareCompositeProperties); - CPPUNIT_TEST(testPropertyPool); - CPPUNIT_TEST(testComplexParagraphProperty); - CPPUNIT_TEST(testInsertEmptyPropertyBag); - CPPUNIT_TEST(testCompareEqualPropertyTypesWithDifferentIdsDoesNotFail); - CPPUNIT_TEST(testDumpPropertyPool); - CPPUNIT_TEST(testDumpEmptyPropertyPool); - CPPUNIT_TEST(testInsertPropertySubsets); - CPPUNIT_TEST(testPropertyPoolGarbageCollection); - CPPUNIT_TEST(testDumpPropertyPoolAfterGarbageCollection); - CPPUNIT_TEST(testCreateTwipsProperty); - CPPUNIT_TEST(testCreateInvalidTwipsProperty); - CPPUNIT_TEST(testCreateInvalidTwipsProperty2); - CPPUNIT_TEST(testCreateInvalidTwipsProperty3); - CPPUNIT_TEST_SUITE_END(); -}; - -//##################################### -// register test suites -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(TestProperty, "TestProperty"); - -NOADDITIONAL; - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits