Turn OSL_DEBUG_LEVEL >= 2 SelfTest into CppunitTest

...and move "10.0", "10.10", and "1.5.0_010" from badVersions[] to good
versions[] to make the test succeed (assuming these shall indeed be classified
as good by now, presumably due to changes to the SunVersion implementation in
the meantime)

Change-Id: Ia7cf9b0e607743a5e0534078c0221c1423f6cfb3
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118570
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
This commit is contained in:
Stephan Bergmann 2021-07-07 16:00:12 +02:00
parent 822f128e73
commit 395ecf1ed3
6 changed files with 173 additions and 112 deletions

View file

@ -0,0 +1,40 @@
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t; fill-column: 100 -*-
#
# 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/.
#
$(eval $(call gb_CppunitTest_CppunitTest,jvmfwk_sunversion))
$(eval $(call gb_CppunitTest_add_exception_objects,jvmfwk_sunversion, \
jvmfwk/qa/unit/sunversion \
))
$(eval $(call gb_CppunitTest_set_include,jvmfwk_sunversion, \
$$(INCLUDE) \
-I$(SRCDIR) \
))
$(eval $(call gb_CppunitTest_use_externals,jvmfwk_sunversion, \
libxml2 \
))
$(eval $(call gb_CppunitTest_use_libraries,jvmfwk_sunversion, \
sal \
salhelper \
))
$(eval $(call gb_CppunitTest_use_library_objects,jvmfwk_sunversion, \
jvmfwk \
))
ifeq ($(OS),MACOSX)
$(eval $(call gb_CppunitTest_use_system_darwin_frameworks,jvmfwk_sunversion, \
Foundation \
))
endif
# vim: set noet sw=4 ts=4:

View file

@ -28,6 +28,10 @@ $(eval $(call gb_Module_add_targets,jvmfwk,\
endif
endif
$(eval $(call gb_Module_add_check_targets,jvmfwk, \
CppunitTest_jvmfwk_sunversion \
))
endif
# vim:set noet sw=4 ts=4:

View file

@ -22,21 +22,9 @@
#include <osl/thread.h>
#include <rtl/character.hxx>
#include <string.h>
#if OSL_DEBUG_LEVEL >= 2
#include <osl/diagnose.h>
#include "diagnostics.h"
#endif
namespace jfw_plugin { //stoc_javadetect
#if OSL_DEBUG_LEVEL >= 2
class SelfTest
{
public:
SelfTest();
} test;
#endif
SunVersion::SunVersion(std::u16string_view usVer):
m_nUpdateSpecial(0), m_preRelease(Rel_NONE)
{
@ -314,104 +302,6 @@ bool SunVersion::operator == (const SunVersion& ver) const
return bRet;
}
#if OSL_DEBUG_LEVEL >= 2
SelfTest::SelfTest()
{
bool bRet = true;
static char const * versions[] = {"1.4.0", "1.4.1", "1.0.0", "10.0.0", "10.10.0",
"10.2.2", "10.10.0", "10.10.10", "111.0.999",
"1.4.1_01", "9.90.99_09", "1.4.1_99",
"1.4.1_00a",
"1.4.1-ea", "1.4.1-beta", "1.4.1-rc1",
"1.5.0_01-ea", "1.5.0_01-rc2"};
static char const * badVersions[] = {".4.0", "..1", "", "10.0", "10.10.0.", "10.10.0-", "10.10.0.",
"10.2-2", "10_10.0", "10..10","10.10", "a.0.999",
"1.4b.1_01", "9.90.-99_09", "1.4.1_99-",
"1.4.1_00a2", "1.4.0_z01z", "1.4.1__99A",
"1.4.1-1ea", "1.5.0_010", "1.5.0._01-", "1.5.0_01-eac"};
static char const * orderedVer[] = { "1.3.1-ea", "1.3.1-beta", "1.3.1-rc1",
"1.3.1", "1.3.1_00a", "1.3.1_01", "1.3.1_01a",
"1.3.2", "1.4.0", "1.5.0_01-ea", "2.0.0"};
int num = SAL_N_ELEMENTS (versions);
int numBad = SAL_N_ELEMENTS (badVersions);
int numOrdered = SAL_N_ELEMENTS (orderedVer);
//parsing test (positive)
for (int i = 0; i < num; i++)
{
SunVersion ver(versions[i]);
if ( ! ver)
{
bRet = false;
break;
}
}
OSL_ENSURE(bRet, "SunVersion selftest failed");
//Parsing test (negative)
for ( int i = 0; i < numBad; i++)
{
SunVersion ver(badVersions[i]);
if (ver)
{
bRet = false;
break;
}
}
OSL_ENSURE(bRet, "SunVersion selftest failed");
// Ordering test
bRet = true;
int j = 0;
for (int i = 0; i < numOrdered; i ++)
{
SunVersion curVer(orderedVer[i]);
if ( ! curVer)
{
bRet = false;
break;
}
for (j = 0; j < numOrdered; j++)
{
SunVersion compVer(orderedVer[j]);
if (i < j)
{
if ( !(curVer < compVer))
{
bRet = false;
break;
}
}
else if ( i == j)
{
if (! (curVer == compVer
&& ! (curVer > compVer)
&& ! (curVer < compVer)))
{
bRet = false;
break;
}
}
else if (i > j)
{
if ( !(curVer > compVer))
{
bRet = false;
break;
}
}
}
if ( ! bRet)
break;
}
if (bRet)
JFW_TRACE2("Testing class SunVersion succeeded.");
else
OSL_ENSURE(bRet, "[Java framework] sunjavaplugin: SunVersion self test failed.");
}
#endif
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View file

@ -28,8 +28,6 @@
namespace jfw_plugin
{
// Define OSL_DEBUG_LEVEL >= 2 to run a test when this lib is loaded
/* SunVersion is used to compare java versions based on a string, as taken
from the registry. The strings look like "1.3", "1.3.1", "1.3.1_02" etc.
Versions such as "1.4.1_01a" are allowed although this is not specified.

View file

@ -0,0 +1,128 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* 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 <sal/config.h>
#include <cppunit/TestAssert.h>
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/plugin/TestPlugIn.h>
#include <rtl/string.hxx>
#include <sal/types.h>
#include <jvmfwk/plugins/sunmajor/pluginlib/sunversion.hxx>
namespace
{
class TestSunVersion : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(TestSunVersion);
CPPUNIT_TEST(testSunVersion);
CPPUNIT_TEST_SUITE_END();
void testSunVersion();
};
void TestSunVersion::testSunVersion()
{
static char const * versions[] = {"1.4.0", "1.4.1", "1.0.0", "10.0.0", "10.10.0",
"10.2.2", "10.10.0", "10.10.10", "111.0.999",
"1.4.1_01", "9.90.99_09", "1.4.1_99",
"1.4.1_00a",
"1.4.1-ea", "1.4.1-beta", "1.4.1-rc1",
"1.5.0_01-ea", "1.5.0_01-rc2",
"10.0", "10.10", "1.5.0_010"};
static char const * badVersions[] = {".4.0", "..1", "", "10.10.0.", "10.10.0-", "10.10.0.",
"10.2-2", "10_10.0", "10..10", "a.0.999",
"1.4b.1_01", "9.90.-99_09", "1.4.1_99-",
"1.4.1_00a2", "1.4.0_z01z", "1.4.1__99A",
"1.4.1-1ea", "1.5.0._01-", "1.5.0_01-eac"};
static char const * orderedVer[] = { "1.3.1-ea", "1.3.1-beta", "1.3.1-rc1",
"1.3.1", "1.3.1_00a", "1.3.1_01", "1.3.1_01a",
"1.3.2", "1.4.0", "1.5.0_01-ea", "2.0.0"};
int num = SAL_N_ELEMENTS (versions);
int numBad = SAL_N_ELEMENTS (badVersions);
int numOrdered = SAL_N_ELEMENTS (orderedVer);
//parsing test (positive)
for (int i = 0; i < num; i++)
{
jfw_plugin::SunVersion ver(versions[i]);
CPPUNIT_ASSERT_MESSAGE(
OString(OString::Concat("SunVersion(\"") + versions[i] + "\") good").getStr(), ver);
}
//Parsing test (negative)
for ( int i = 0; i < numBad; i++)
{
jfw_plugin::SunVersion ver(badVersions[i]);
CPPUNIT_ASSERT_MESSAGE(
OString(OString::Concat("SunVersion(\"") + badVersions[i] + "\") bad").getStr(), !ver);
}
// Ordering test
int j = 0;
for (int i = 0; i < numOrdered; i ++)
{
jfw_plugin::SunVersion curVer(orderedVer[i]);
CPPUNIT_ASSERT_MESSAGE(
OString(OString::Concat("SunVersion(\"") + orderedVer[i] + "\") good").getStr(),
curVer);
for (j = 0; j < numOrdered; j++)
{
jfw_plugin::SunVersion compVer(orderedVer[j]);
if (i < j)
{
CPPUNIT_ASSERT_MESSAGE(
OString(OString::Concat("\"") + orderedVer[i] + "\" < \"" + orderedVer[j])
.getStr(),
curVer < compVer);
}
else if ( i == j)
{
CPPUNIT_ASSERT_MESSAGE(
OString(OString::Concat("\"") + orderedVer[i] + "\" == \"" + orderedVer[j])
.getStr(),
curVer.operator ==(compVer));
CPPUNIT_ASSERT_MESSAGE(
OString(OString::Concat("not \"") + orderedVer[i] + "\" > \"" + orderedVer[j])
.getStr(),
! (curVer > compVer));
CPPUNIT_ASSERT_MESSAGE(
OString(OString::Concat("not \"") + orderedVer[i] + "\" < \"" + orderedVer[j])
.getStr(),
! (curVer < compVer));
}
else if (i > j)
{
CPPUNIT_ASSERT_MESSAGE(
OString(OString::Concat("\"") + orderedVer[i] + "\" > \"" + orderedVer[j])
.getStr(),
curVer > compVer);
}
}
}
}
CPPUNIT_TEST_SUITE_REGISTRATION(TestSunVersion);
}
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */

View file

@ -6654,6 +6654,7 @@ jvmfwk/plugins/sunmajor/pluginlib/util.hxx
jvmfwk/plugins/sunmajor/pluginlib/vendorbase.cxx
jvmfwk/plugins/sunmajor/pluginlib/vendorlist.cxx
jvmfwk/plugins/sunmajor/pluginlib/vendorlist.hxx
jvmfwk/qa/unit/sunversion.cxx
jvmfwk/source/elements.cxx
jvmfwk/source/framework.cxx
jvmfwk/source/framework.hxx