02c91f82c2
In the tools module it can be used in more other modules. Changed the instantiation to increase the counter already in the constructor, so no need to check if the ID is 0. Also test for UniqueID Change-Id: I77c80461875c69496a7e218534d16d6550c168c2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170061 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
79 lines
2.1 KiB
C++
79 lines
2.1 KiB
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 <tools/UniqueID.hxx>
|
|
|
|
#include <cppunit/TestAssert.h>
|
|
#include <cppunit/TestFixture.h>
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
#include <cppunit/plugin/TestPlugIn.h>
|
|
|
|
namespace
|
|
{
|
|
class UniqueIdTest : public CppUnit::TestFixture
|
|
{
|
|
};
|
|
|
|
struct ObjectExample1
|
|
{
|
|
UniqueID maID;
|
|
};
|
|
|
|
struct ObjectExample2
|
|
{
|
|
UniqueID maID;
|
|
};
|
|
|
|
CPPUNIT_TEST_FIXTURE(UniqueIdTest, testUniqueness)
|
|
{
|
|
UniqueID aID;
|
|
// Check ID
|
|
CPPUNIT_ASSERT_EQUAL(sal_uInt64(1), aID.getID());
|
|
// Call again - same result
|
|
CPPUNIT_ASSERT_EQUAL(sal_uInt64(1), aID.getID());
|
|
|
|
// Check creating another instance
|
|
{
|
|
UniqueID aID2;
|
|
CPPUNIT_ASSERT_EQUAL(sal_uInt64(1), aID.getID());
|
|
CPPUNIT_ASSERT_EQUAL(sal_uInt64(2), aID2.getID());
|
|
}
|
|
|
|
// Check creating third instance
|
|
{
|
|
UniqueID aID3;
|
|
CPPUNIT_ASSERT_EQUAL(sal_uInt64(1), aID.getID());
|
|
CPPUNIT_ASSERT_EQUAL(sal_uInt64(3), aID3.getID());
|
|
}
|
|
|
|
// Check object copying - preserve the id
|
|
ObjectExample1 objectA;
|
|
CPPUNIT_ASSERT_EQUAL(sal_uInt64(4), objectA.maID.getID());
|
|
|
|
ObjectExample1 objectB = objectA;
|
|
CPPUNIT_ASSERT_EQUAL(sal_uInt64(4), objectA.maID.getID());
|
|
CPPUNIT_ASSERT_EQUAL(sal_uInt64(4), objectB.maID.getID());
|
|
|
|
// Multiple objects
|
|
ObjectExample2 objectC;
|
|
ObjectExample1 objectD;
|
|
ObjectExample2 objectE;
|
|
ObjectExample1 objectF;
|
|
|
|
CPPUNIT_ASSERT_EQUAL(sal_uInt64(5), objectC.maID.getID());
|
|
CPPUNIT_ASSERT_EQUAL(sal_uInt64(6), objectD.maID.getID());
|
|
CPPUNIT_ASSERT_EQUAL(sal_uInt64(7), objectE.maID.getID());
|
|
CPPUNIT_ASSERT_EQUAL(sal_uInt64(8), objectF.maID.getID());
|
|
}
|
|
|
|
} // end anonymous namespace
|
|
|
|
CPPUNIT_PLUGIN_IMPLEMENT();
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|