Kaydet (Commit) b612cf0e authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Introduce o3tl::underlyingEnumValue

Change-Id: I6554eb86326159b0da707539f45c411f61c0f3de
Reviewed-on: https://gerrit.libreoffice.org/68761
Tested-by: Jenkins
Reviewed-by: 's avatarStephan Bergmann <sbergman@redhat.com>
üst efbd217a
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <cassert> #include <cassert>
#include <type_traits> #include <type_traits>
#include <o3tl/underlyingenumvalue.hxx>
#include <sal/types.h> #include <sal/types.h>
namespace o3tl { namespace o3tl {
...@@ -104,10 +105,10 @@ template<typename E> ...@@ -104,10 +105,10 @@ template<typename E>
constexpr typename o3tl::typed_flags<E>::Wrap operator ~(E rhs) { constexpr typename o3tl::typed_flags<E>::Wrap operator ~(E rhs) {
assert( assert(
o3tl::detail::isNonNegative( o3tl::detail::isNonNegative(
static_cast<typename std::underlying_type<E>::type>(rhs))); o3tl::underlyingEnumValue(rhs)));
return static_cast<typename o3tl::typed_flags<E>::Wrap>( return static_cast<typename o3tl::typed_flags<E>::Wrap>(
o3tl::typed_flags<E>::mask o3tl::typed_flags<E>::mask
& ~static_cast<typename std::underlying_type<E>::type>(rhs)); & ~o3tl::underlyingEnumValue(rhs));
} }
template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator ~( template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator ~(
...@@ -115,7 +116,7 @@ template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator ~( ...@@ -115,7 +116,7 @@ template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator ~(
{ {
return static_cast<typename o3tl::typed_flags<E>::Wrap>( return static_cast<typename o3tl::typed_flags<E>::Wrap>(
o3tl::typed_flags<E>::mask o3tl::typed_flags<E>::mask
& ~static_cast<typename std::underlying_type<E>::type>(rhs)); & ~o3tl::underlyingEnumValue<E>(rhs));
} }
template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator ^( template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator ^(
...@@ -123,13 +124,13 @@ template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator ^( ...@@ -123,13 +124,13 @@ template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator ^(
{ {
assert( assert(
o3tl::detail::isNonNegative( o3tl::detail::isNonNegative(
static_cast<typename std::underlying_type<E>::type>(lhs))); o3tl::underlyingEnumValue(lhs)));
assert( assert(
o3tl::detail::isNonNegative( o3tl::detail::isNonNegative(
static_cast<typename std::underlying_type<E>::type>(rhs))); o3tl::underlyingEnumValue(rhs)));
return static_cast<typename o3tl::typed_flags<E>::Wrap>( return static_cast<typename o3tl::typed_flags<E>::Wrap>(
static_cast<typename std::underlying_type<E>::type>(lhs) o3tl::underlyingEnumValue(lhs)
^ static_cast<typename std::underlying_type<E>::type>(rhs)); ^ o3tl::underlyingEnumValue(rhs));
} }
template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator ^( template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator ^(
...@@ -137,10 +138,10 @@ template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator ^( ...@@ -137,10 +138,10 @@ template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator ^(
{ {
assert( assert(
o3tl::detail::isNonNegative( o3tl::detail::isNonNegative(
static_cast<typename std::underlying_type<E>::type>(lhs))); o3tl::underlyingEnumValue(lhs)));
return static_cast<typename o3tl::typed_flags<E>::Wrap>( return static_cast<typename o3tl::typed_flags<E>::Wrap>(
static_cast<typename std::underlying_type<E>::type>(lhs) o3tl::underlyingEnumValue(lhs)
^ static_cast<typename std::underlying_type<E>::type>(rhs)); ^ o3tl::underlyingEnumValue<E>(rhs));
} }
template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator ^( template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator ^(
...@@ -148,10 +149,10 @@ template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator ^( ...@@ -148,10 +149,10 @@ template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator ^(
{ {
assert( assert(
o3tl::detail::isNonNegative( o3tl::detail::isNonNegative(
static_cast<typename std::underlying_type<E>::type>(rhs))); o3tl::underlyingEnumValue(rhs)));
return static_cast<typename o3tl::typed_flags<E>::Wrap>( return static_cast<typename o3tl::typed_flags<E>::Wrap>(
static_cast<typename std::underlying_type<E>::type>(lhs) o3tl::underlyingEnumValue<E>(lhs)
^ static_cast<typename std::underlying_type<E>::type>(rhs)); ^ o3tl::underlyingEnumValue(rhs));
} }
template<typename W> constexpr template<typename W> constexpr
...@@ -159,25 +160,21 @@ typename o3tl::typed_flags<typename W::Unwrapped::Self>::Wrap operator ^( ...@@ -159,25 +160,21 @@ typename o3tl::typed_flags<typename W::Unwrapped::Self>::Wrap operator ^(
W lhs, W rhs) W lhs, W rhs)
{ {
return static_cast<W>( return static_cast<W>(
static_cast< o3tl::underlyingEnumValue<typename W::Unwrapped::Self>(lhs)
typename std::underlying_type<typename W::Unwrapped::Self>::type>( ^ o3tl::underlyingEnumValue<typename W::Unwrapped::Self>(rhs));
lhs)
^ static_cast<
typename std::underlying_type<typename W::Unwrapped::Self>::type>(
rhs));
} }
template<typename E> template<typename E>
constexpr typename o3tl::typed_flags<E>::Wrap operator &(E lhs, E rhs) { constexpr typename o3tl::typed_flags<E>::Wrap operator &(E lhs, E rhs) {
assert( assert(
o3tl::detail::isNonNegative( o3tl::detail::isNonNegative(
static_cast<typename std::underlying_type<E>::type>(lhs))); o3tl::underlyingEnumValue(lhs)));
assert( assert(
o3tl::detail::isNonNegative( o3tl::detail::isNonNegative(
static_cast<typename std::underlying_type<E>::type>(rhs))); o3tl::underlyingEnumValue(rhs)));
return static_cast<typename o3tl::typed_flags<E>::Wrap>( return static_cast<typename o3tl::typed_flags<E>::Wrap>(
static_cast<typename std::underlying_type<E>::type>(lhs) o3tl::underlyingEnumValue(lhs)
& static_cast<typename std::underlying_type<E>::type>(rhs)); & o3tl::underlyingEnumValue(rhs));
} }
template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator &( template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator &(
...@@ -185,10 +182,10 @@ template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator &( ...@@ -185,10 +182,10 @@ template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator &(
{ {
assert( assert(
o3tl::detail::isNonNegative( o3tl::detail::isNonNegative(
static_cast<typename std::underlying_type<E>::type>(lhs))); o3tl::underlyingEnumValue(lhs)));
return static_cast<typename o3tl::typed_flags<E>::Wrap>( return static_cast<typename o3tl::typed_flags<E>::Wrap>(
static_cast<typename std::underlying_type<E>::type>(lhs) o3tl::underlyingEnumValue(lhs)
& static_cast<typename std::underlying_type<E>::type>(rhs)); & o3tl::underlyingEnumValue<E>(rhs));
} }
template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator &( template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator &(
...@@ -196,10 +193,10 @@ template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator &( ...@@ -196,10 +193,10 @@ template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator &(
{ {
assert( assert(
o3tl::detail::isNonNegative( o3tl::detail::isNonNegative(
static_cast<typename std::underlying_type<E>::type>(rhs))); o3tl::underlyingEnumValue(rhs)));
return static_cast<typename o3tl::typed_flags<E>::Wrap>( return static_cast<typename o3tl::typed_flags<E>::Wrap>(
static_cast<typename std::underlying_type<E>::type>(lhs) o3tl::underlyingEnumValue<E>(lhs)
& static_cast<typename std::underlying_type<E>::type>(rhs)); & o3tl::underlyingEnumValue(rhs));
} }
template<typename W> constexpr template<typename W> constexpr
...@@ -207,25 +204,21 @@ typename o3tl::typed_flags<typename W::Unwrapped::Self>::Wrap operator &( ...@@ -207,25 +204,21 @@ typename o3tl::typed_flags<typename W::Unwrapped::Self>::Wrap operator &(
W lhs, W rhs) W lhs, W rhs)
{ {
return static_cast<W>( return static_cast<W>(
static_cast< o3tl::underlyingEnumValue<typename W::Unwrapped::Self>(lhs)
typename std::underlying_type<typename W::Unwrapped::Self>::type>( & o3tl::underlyingEnumValue<typename W::Unwrapped::Self>(rhs));
lhs)
& static_cast<
typename std::underlying_type<typename W::Unwrapped::Self>::type>(
rhs));
} }
template<typename E> template<typename E>
constexpr typename o3tl::typed_flags<E>::Wrap operator |(E lhs, E rhs) { constexpr typename o3tl::typed_flags<E>::Wrap operator |(E lhs, E rhs) {
assert( assert(
o3tl::detail::isNonNegative( o3tl::detail::isNonNegative(
static_cast<typename std::underlying_type<E>::type>(lhs))); o3tl::underlyingEnumValue(lhs)));
assert( assert(
o3tl::detail::isNonNegative( o3tl::detail::isNonNegative(
static_cast<typename std::underlying_type<E>::type>(rhs))); o3tl::underlyingEnumValue(rhs)));
return static_cast<typename o3tl::typed_flags<E>::Wrap>( return static_cast<typename o3tl::typed_flags<E>::Wrap>(
static_cast<typename std::underlying_type<E>::type>(lhs) o3tl::underlyingEnumValue(lhs)
| static_cast<typename std::underlying_type<E>::type>(rhs)); | o3tl::underlyingEnumValue(rhs));
} }
template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator |( template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator |(
...@@ -233,10 +226,10 @@ template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator |( ...@@ -233,10 +226,10 @@ template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator |(
{ {
assert( assert(
o3tl::detail::isNonNegative( o3tl::detail::isNonNegative(
static_cast<typename std::underlying_type<E>::type>(lhs))); o3tl::underlyingEnumValue(lhs)));
return static_cast<typename o3tl::typed_flags<E>::Wrap>( return static_cast<typename o3tl::typed_flags<E>::Wrap>(
static_cast<typename std::underlying_type<E>::type>(lhs) o3tl::underlyingEnumValue(lhs)
| static_cast<typename std::underlying_type<E>::type>(rhs)); | o3tl::underlyingEnumValue<E>(rhs));
} }
template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator |( template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator |(
...@@ -244,10 +237,10 @@ template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator |( ...@@ -244,10 +237,10 @@ template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator |(
{ {
assert( assert(
o3tl::detail::isNonNegative( o3tl::detail::isNonNegative(
static_cast<typename std::underlying_type<E>::type>(rhs))); o3tl::underlyingEnumValue(rhs)));
return static_cast<typename o3tl::typed_flags<E>::Wrap>( return static_cast<typename o3tl::typed_flags<E>::Wrap>(
static_cast<typename std::underlying_type<E>::type>(lhs) o3tl::underlyingEnumValue<E>(lhs)
| static_cast<typename std::underlying_type<E>::type>(rhs)); | o3tl::underlyingEnumValue(rhs));
} }
template<typename W> constexpr template<typename W> constexpr
...@@ -255,22 +248,18 @@ typename o3tl::typed_flags<typename W::Unwrapped::Self>::Wrap operator |( ...@@ -255,22 +248,18 @@ typename o3tl::typed_flags<typename W::Unwrapped::Self>::Wrap operator |(
W lhs, W rhs) W lhs, W rhs)
{ {
return static_cast<W>( return static_cast<W>(
static_cast< o3tl::underlyingEnumValue<typename W::Unwrapped::Self>(lhs)
typename std::underlying_type<typename W::Unwrapped::Self>::type>( | o3tl::underlyingEnumValue<typename W::Unwrapped::Self>(rhs));
lhs)
| static_cast<
typename std::underlying_type<typename W::Unwrapped::Self>::type>(
rhs));
} }
template<typename E> template<typename E>
inline typename o3tl::typed_flags<E>::Self operator &=(E & lhs, E rhs) { inline typename o3tl::typed_flags<E>::Self operator &=(E & lhs, E rhs) {
assert( assert(
o3tl::detail::isNonNegative( o3tl::detail::isNonNegative(
static_cast<typename std::underlying_type<E>::type>(lhs))); o3tl::underlyingEnumValue(lhs)));
assert( assert(
o3tl::detail::isNonNegative( o3tl::detail::isNonNegative(
static_cast<typename std::underlying_type<E>::type>(rhs))); o3tl::underlyingEnumValue(rhs)));
lhs = lhs & rhs; lhs = lhs & rhs;
return lhs; return lhs;
} }
...@@ -281,7 +270,7 @@ inline typename o3tl::typed_flags<E>::Self operator &=( ...@@ -281,7 +270,7 @@ inline typename o3tl::typed_flags<E>::Self operator &=(
{ {
assert( assert(
o3tl::detail::isNonNegative( o3tl::detail::isNonNegative(
static_cast<typename std::underlying_type<E>::type>(lhs))); o3tl::underlyingEnumValue(lhs)));
lhs = lhs & rhs; lhs = lhs & rhs;
return lhs; return lhs;
} }
...@@ -290,10 +279,10 @@ template<typename E> ...@@ -290,10 +279,10 @@ template<typename E>
inline typename o3tl::typed_flags<E>::Self operator |=(E & lhs, E rhs) { inline typename o3tl::typed_flags<E>::Self operator |=(E & lhs, E rhs) {
assert( assert(
o3tl::detail::isNonNegative( o3tl::detail::isNonNegative(
static_cast<typename std::underlying_type<E>::type>(lhs))); o3tl::underlyingEnumValue(lhs)));
assert( assert(
o3tl::detail::isNonNegative( o3tl::detail::isNonNegative(
static_cast<typename std::underlying_type<E>::type>(rhs))); o3tl::underlyingEnumValue(rhs)));
lhs = lhs | rhs; lhs = lhs | rhs;
return lhs; return lhs;
} }
...@@ -304,7 +293,7 @@ inline typename o3tl::typed_flags<E>::Self operator |=( ...@@ -304,7 +293,7 @@ inline typename o3tl::typed_flags<E>::Self operator |=(
{ {
assert( assert(
o3tl::detail::isNonNegative( o3tl::detail::isNonNegative(
static_cast<typename std::underlying_type<E>::type>(lhs))); o3tl::underlyingEnumValue(lhs)));
lhs = lhs | rhs; lhs = lhs | rhs;
return lhs; return lhs;
} }
...@@ -313,10 +302,10 @@ template<typename E> ...@@ -313,10 +302,10 @@ template<typename E>
inline typename o3tl::typed_flags<E>::Self operator ^=(E & lhs, E rhs) { inline typename o3tl::typed_flags<E>::Self operator ^=(E & lhs, E rhs) {
assert( assert(
o3tl::detail::isNonNegative( o3tl::detail::isNonNegative(
static_cast<typename std::underlying_type<E>::type>(lhs))); o3tl::underlyingEnumValue(lhs)));
assert( assert(
o3tl::detail::isNonNegative( o3tl::detail::isNonNegative(
static_cast<typename std::underlying_type<E>::type>(rhs))); o3tl::underlyingEnumValue(rhs)));
lhs = lhs ^ rhs; lhs = lhs ^ rhs;
return lhs; return lhs;
} }
...@@ -327,7 +316,7 @@ inline typename o3tl::typed_flags<E>::Self operator ^=( ...@@ -327,7 +316,7 @@ inline typename o3tl::typed_flags<E>::Self operator ^=(
{ {
assert( assert(
o3tl::detail::isNonNegative( o3tl::detail::isNonNegative(
static_cast<typename std::underlying_type<E>::type>(lhs))); o3tl::underlyingEnumValue(lhs)));
lhs = lhs ^ rhs; lhs = lhs ^ rhs;
return lhs; return lhs;
} }
......
/* -*- 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/.
*/
#ifndef INCLUDED_O3TL_UNDERLYINGENUMVALUE_HXX
#define INCLUDED_O3TL_UNDERLYINGENUMVALUE_HXX
#include <sal/config.h>
#include <type_traits>
namespace o3tl
{
// For a value e of an enumeration type T, return the corresponding value of T's underlying type:
template <typename T> constexpr std::underlying_type_t<T> underlyingEnumValue(T e)
{
return static_cast<std::underlying_type_t<T>>(e);
}
}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <formula/grammar.hxx> #include <formula/grammar.hxx>
#include <o3tl/typed_flags_set.hxx> #include <o3tl/typed_flags_set.hxx>
#include <o3tl/underlyingenumvalue.hxx>
namespace com { namespace sun { namespace star { namespace com { namespace sun { namespace star {
namespace sheet { namespace sheet {
...@@ -178,11 +179,11 @@ namespace o3tl ...@@ -178,11 +179,11 @@ namespace o3tl
} }
inline void applyStartToEndFlags(ScRefFlags &target,const ScRefFlags source) inline void applyStartToEndFlags(ScRefFlags &target,const ScRefFlags source)
{ {
target |= ScRefFlags(static_cast<std::underlying_type<ScRefFlags>::type>(source) << 4); target |= ScRefFlags(o3tl::underlyingEnumValue(source) << 4);
} }
inline void applyStartToEndFlags(ScRefFlags &target) inline void applyStartToEndFlags(ScRefFlags &target)
{ {
target |= ScRefFlags(static_cast<std::underlying_type<ScRefFlags>::type>(target) << 4); target |= ScRefFlags(o3tl::underlyingEnumValue(target) << 4);
} }
// ScAddress // ScAddress
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#include <externalrefmgr.hxx> #include <externalrefmgr.hxx>
#include <osl/diagnose.h> #include <osl/diagnose.h>
#include <o3tl/underlyingenumvalue.hxx>
#include <com/sun/star/frame/XModel.hpp> #include <com/sun/star/frame/XModel.hpp>
#include <com/sun/star/sheet/ExternalLinkInfo.hpp> #include <com/sun/star/sheet/ExternalLinkInfo.hpp>
#include <com/sun/star/sheet/ExternalLinkType.hpp> #include <com/sun/star/sheet/ExternalLinkType.hpp>
...@@ -2219,7 +2219,7 @@ OUString ScRange::Format( ScRefFlags nFlags, const ScDocument* pDoc, ...@@ -2219,7 +2219,7 @@ OUString ScRange::Format( ScRefFlags nFlags, const ScDocument* pDoc,
lcl_RowAbsFlagDiffer( nFlags )) lcl_RowAbsFlagDiffer( nFlags ))
{ {
// move flags of end reference to start reference, mask with BITS to exclude FORCE_DOC flag // move flags of end reference to start reference, mask with BITS to exclude FORCE_DOC flag
nFlags = ScRefFlags::VALID | (ScRefFlags(static_cast<std::underlying_type<ScRefFlags>::type>(nFlags) >> 4) & ScRefFlags::BITS); nFlags = ScRefFlags::VALID | (ScRefFlags(o3tl::underlyingEnumValue(nFlags) >> 4) & ScRefFlags::BITS);
if ( bOneTab ) if ( bOneTab )
pDoc = nullptr; pDoc = nullptr;
else else
......
...@@ -17,6 +17,10 @@ ...@@ -17,6 +17,10 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ */
#include <sal/config.h>
#include <o3tl/underlyingenumvalue.hxx>
#include <reffind.hxx> #include <reffind.hxx>
#include <global.hxx> #include <global.hxx>
#include <compiler.hxx> #include <compiler.hxx>
...@@ -219,7 +223,7 @@ static ScRefFlags lcl_NextFlags( ScRefFlags nOld ) ...@@ -219,7 +223,7 @@ static ScRefFlags lcl_NextFlags( ScRefFlags nOld )
{ {
const ScRefFlags Mask_ABS = ScRefFlags::COL_ABS | ScRefFlags::ROW_ABS | ScRefFlags::TAB_ABS; const ScRefFlags Mask_ABS = ScRefFlags::COL_ABS | ScRefFlags::ROW_ABS | ScRefFlags::TAB_ABS;
ScRefFlags nNew = nOld & Mask_ABS; ScRefFlags nNew = nOld & Mask_ABS;
nNew = ScRefFlags( static_cast<std::underlying_type<ScRefFlags>::type>(nNew) - 1 ) & Mask_ABS; // weiterzaehlen nNew = ScRefFlags( o3tl::underlyingEnumValue(nNew) - 1 ) & Mask_ABS; // weiterzaehlen
if (!(nOld & ScRefFlags::TAB_3D)) if (!(nOld & ScRefFlags::TAB_3D))
nNew &= ~ScRefFlags::TAB_ABS; // not 3D -> never absolute! nNew &= ~ScRefFlags::TAB_ABS; // not 3D -> never absolute!
......
...@@ -520,8 +520,7 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testODFGood) ...@@ -520,8 +520,7 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testODFGood)
// We expect NOTVALIDATED in case the root CA is not imported on the system, and OK otherwise, so accept both. // We expect NOTVALIDATED in case the root CA is not imported on the system, and OK otherwise, so accept both.
SignatureState nActual = pObjectShell->GetDocumentSignatureState(); SignatureState nActual = pObjectShell->GetDocumentSignatureState();
CPPUNIT_ASSERT_MESSAGE( CPPUNIT_ASSERT_MESSAGE(
(OString::number(static_cast<std::underlying_type<SignatureState>::type>(nActual)) (OString::number(o3tl::underlyingEnumValue(nActual)).getStr()),
.getStr()),
(nActual == SignatureState::NOTVALIDATED || nActual == SignatureState::OK)); (nActual == SignatureState::NOTVALIDATED || nActual == SignatureState::OK));
} }
...@@ -561,11 +560,9 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testOOXMLPartial) ...@@ -561,11 +560,9 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testOOXMLPartial)
// We expect NOTVALIDATED_PARTIAL_OK in case the root CA is not imported on the system, and PARTIAL_OK otherwise, so accept both. // We expect NOTVALIDATED_PARTIAL_OK in case the root CA is not imported on the system, and PARTIAL_OK otherwise, so accept both.
// But reject NOTVALIDATED, hiding incompleteness is not OK. // But reject NOTVALIDATED, hiding incompleteness is not OK.
SignatureState nActual = pObjectShell->GetDocumentSignatureState(); SignatureState nActual = pObjectShell->GetDocumentSignatureState();
CPPUNIT_ASSERT_MESSAGE( CPPUNIT_ASSERT_MESSAGE((OString::number(o3tl::underlyingEnumValue(nActual)).getStr()),
(OString::number(static_cast<std::underlying_type<SignatureState>::type>(nActual)) (nActual == SignatureState::NOTVALIDATED_PARTIAL_OK
.getStr()), || nActual == SignatureState::PARTIAL_OK));
(nActual == SignatureState::NOTVALIDATED_PARTIAL_OK
|| nActual == SignatureState::PARTIAL_OK));
} }
/// Test a typical broken OOXML signature where one stream is corrupted. /// Test a typical broken OOXML signature where one stream is corrupted.
...@@ -594,8 +591,7 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testPDFGood) ...@@ -594,8 +591,7 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testPDFGood)
// We expect NOTVALIDATED in case the root CA is not imported on the system, and OK otherwise, so accept both. // We expect NOTVALIDATED in case the root CA is not imported on the system, and OK otherwise, so accept both.
SignatureState nActual = pObjectShell->GetDocumentSignatureState(); SignatureState nActual = pObjectShell->GetDocumentSignatureState();
CPPUNIT_ASSERT_MESSAGE( CPPUNIT_ASSERT_MESSAGE(
(OString::number(static_cast<std::underlying_type<SignatureState>::type>(nActual)) (OString::number(o3tl::underlyingEnumValue(nActual)).getStr()),
.getStr()),
(nActual == SignatureState::NOTVALIDATED || nActual == SignatureState::OK)); (nActual == SignatureState::NOTVALIDATED || nActual == SignatureState::OK));
} }
...@@ -635,11 +631,9 @@ CPPUNIT_TEST_FIXTURE(SigningTest, test96097Calc) ...@@ -635,11 +631,9 @@ CPPUNIT_TEST_FIXTURE(SigningTest, test96097Calc)
CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pObjectShell); CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pObjectShell);
SignatureState nActual = pObjectShell->GetScriptingSignatureState(); SignatureState nActual = pObjectShell->GetScriptingSignatureState();
CPPUNIT_ASSERT_MESSAGE( CPPUNIT_ASSERT_MESSAGE((OString::number(o3tl::underlyingEnumValue(nActual)).getStr()),
(OString::number(static_cast<std::underlying_type<SignatureState>::type>(nActual)) (nActual == SignatureState::OK || nActual == SignatureState::NOTVALIDATED
.getStr()), || nActual == SignatureState::INVALID));
(nActual == SignatureState::OK || nActual == SignatureState::NOTVALIDATED
|| nActual == SignatureState::INVALID));
uno::Reference<frame::XStorable> xDocStorable(mxComponent, uno::UNO_QUERY_THROW); uno::Reference<frame::XStorable> xDocStorable(mxComponent, uno::UNO_QUERY_THROW);
...@@ -674,11 +668,9 @@ CPPUNIT_TEST_FIXTURE(SigningTest, test96097Doc) ...@@ -674,11 +668,9 @@ CPPUNIT_TEST_FIXTURE(SigningTest, test96097Doc)
CPPUNIT_ASSERT(pObjectShell); CPPUNIT_ASSERT(pObjectShell);
SignatureState nActual = pObjectShell->GetScriptingSignatureState(); SignatureState nActual = pObjectShell->GetScriptingSignatureState();
CPPUNIT_ASSERT_MESSAGE( CPPUNIT_ASSERT_MESSAGE((OString::number(o3tl::underlyingEnumValue(nActual)).getStr()),
(OString::number(static_cast<std::underlying_type<SignatureState>::type>(nActual)) (nActual == SignatureState::OK || nActual == SignatureState::NOTVALIDATED
.getStr()), || nActual == SignatureState::INVALID));
(nActual == SignatureState::OK || nActual == SignatureState::NOTVALIDATED
|| nActual == SignatureState::INVALID));
uno::Reference<frame::XStorable> xDocStorable(mxComponent, uno::UNO_QUERY_THROW); uno::Reference<frame::XStorable> xDocStorable(mxComponent, uno::UNO_QUERY_THROW);
...@@ -778,8 +770,7 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testXAdESGood) ...@@ -778,8 +770,7 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testXAdESGood)
// We expect NOTVALIDATED in case the root CA is not imported on the system, and OK otherwise, so accept both. // We expect NOTVALIDATED in case the root CA is not imported on the system, and OK otherwise, so accept both.
SignatureState nActual = pObjectShell->GetDocumentSignatureState(); SignatureState nActual = pObjectShell->GetDocumentSignatureState();
CPPUNIT_ASSERT_MESSAGE( CPPUNIT_ASSERT_MESSAGE(
(OString::number(static_cast<std::underlying_type<SignatureState>::type>(nActual)) (OString::number(o3tl::underlyingEnumValue(nActual)).getStr()),
.getStr()),
(nActual == SignatureState::NOTVALIDATED || nActual == SignatureState::OK)); (nActual == SignatureState::NOTVALIDATED || nActual == SignatureState::OK));
} }
...@@ -840,10 +831,8 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testODFGoodGPG) ...@@ -840,10 +831,8 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testODFGoodGPG)
// Our local gpg config fully trusts the signing cert, so in // Our local gpg config fully trusts the signing cert, so in
// contrast to the X509 test we can fail on NOTVALIDATED here // contrast to the X509 test we can fail on NOTVALIDATED here
SignatureState nActual = pObjectShell->GetDocumentSignatureState(); SignatureState nActual = pObjectShell->GetDocumentSignatureState();
CPPUNIT_ASSERT_EQUAL_MESSAGE( CPPUNIT_ASSERT_EQUAL_MESSAGE((OString::number(o3tl::underlyingEnumValue(nActual)).getStr()),
(OString::number(static_cast<std::underlying_type<SignatureState>::type>(nActual)) SignatureState::OK, nActual);
.getStr()),
SignatureState::OK, nActual);
} }
/// Test a typical ODF where all streams are GPG-signed, but we don't trust the signature. /// Test a typical ODF where all streams are GPG-signed, but we don't trust the signature.
...@@ -858,10 +847,8 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testODFUntrustedGoodGPG) ...@@ -858,10 +847,8 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testODFUntrustedGoodGPG)
// contrast to the X509 test we can fail everything but // contrast to the X509 test we can fail everything but
// NOTVALIDATED here // NOTVALIDATED here
SignatureState nActual = pObjectShell->GetDocumentSignatureState(); SignatureState nActual = pObjectShell->GetDocumentSignatureState();
CPPUNIT_ASSERT_EQUAL_MESSAGE( CPPUNIT_ASSERT_EQUAL_MESSAGE((OString::number(o3tl::underlyingEnumValue(nActual)).getStr()),
(OString::number(static_cast<std::underlying_type<SignatureState>::type>(nActual)) SignatureState::NOTVALIDATED, nActual);
.getStr()),
SignatureState::NOTVALIDATED, nActual);
} }
/// Test a typical broken ODF signature where one stream is corrupted. /// Test a typical broken ODF signature where one stream is corrupted.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment