From d350c77c0721647624d790124785695d71b3e0f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wierci=C5=84ski?= Date: Mon, 14 Aug 2023 12:23:26 +0200 Subject: [PATCH] Use internal linkage for data.cpp files The Qt uses test batching and potentially encoder/data.cpp and parser/data.cpp can end up in the same translation unit. This can be problematic as they declare symbols with the same names. Change both files to use internal linkage in order to avoid symbols clashing. --- tests/encoder/data.cpp | 55 ++++++++++++++++++++++-------------------- tests/parser/data.cpp | 3 +++ 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/tests/encoder/data.cpp b/tests/encoder/data.cpp index 6dca49d4..e12932d3 100644 --- a/tests/encoder/data.cpp +++ b/tests/encoder/data.cpp @@ -24,7 +24,29 @@ #include -static float myNaNf() +struct NegativeInteger { quint64 abs; }; +Q_DECLARE_METATYPE(NegativeInteger) + +struct SimpleType { uint8_t type; }; +Q_DECLARE_METATYPE(SimpleType) + +struct Float16Standin { uint16_t val; }; +Q_DECLARE_METATYPE(Float16Standin) + +struct Tag { CborTag tag; QVariant tagged; }; +Q_DECLARE_METATYPE(Tag) + +typedef QVector> Map; +Q_DECLARE_METATYPE(Map) + +struct IndeterminateLengthArray : QVariantList { using QVariantList::QVariantList; }; +struct IndeterminateLengthMap : Map { using Map::Map; }; +Q_DECLARE_METATYPE(IndeterminateLengthArray) +Q_DECLARE_METATYPE(IndeterminateLengthMap) + +namespace { + +float myNaNf() { uint32_t v = 0x7fc00000; float f; @@ -33,7 +55,7 @@ static float myNaNf() return f; } -static float myInff() +float myInff() { uint32_t v = 0x7f800000; float f; @@ -42,7 +64,7 @@ static float myInff() return f; } -static float myNInff() +float myNInff() { uint32_t v = 0xff800000; float f; @@ -51,7 +73,7 @@ static float myNInff() return f; } -static double myNaN() +double myNaN() { uint64_t v = UINT64_C(0x7ff8000000000000); double f; @@ -60,7 +82,7 @@ static double myNaN() return f; } -static double myInf() +double myInf() { uint64_t v = UINT64_C(0x7ff0000000000000); double f; @@ -69,7 +91,7 @@ static double myInf() return f; } -static double myNInf() +double myNInf() { uint64_t v = UINT64_C(0xfff0000000000000); double f; @@ -83,36 +105,17 @@ template QByteArray raw(const char (&data)[N]) return QByteArray::fromRawData(data, N - 1); } -struct NegativeInteger { quint64 abs; }; -Q_DECLARE_METATYPE(NegativeInteger) - -struct SimpleType { uint8_t type; }; -Q_DECLARE_METATYPE(SimpleType) - -struct Float16Standin { uint16_t val; }; -Q_DECLARE_METATYPE(Float16Standin) - -struct Tag { CborTag tag; QVariant tagged; }; -Q_DECLARE_METATYPE(Tag) - template QVariant make_list(const Args &... args) { return QVariantList{args...}; } -typedef QVector> Map; -Q_DECLARE_METATYPE(Map) QVariant make_map(const std::initializer_list> &list) { return QVariant::fromValue(Map(list)); } -struct IndeterminateLengthArray : QVariantList { using QVariantList::QVariantList; }; -struct IndeterminateLengthMap : Map { using Map::Map; }; -Q_DECLARE_METATYPE(IndeterminateLengthArray) -Q_DECLARE_METATYPE(IndeterminateLengthMap) - QVariant make_ilarray(const std::initializer_list &list) { return QVariant::fromValue(IndeterminateLengthArray(list)); @@ -343,4 +346,4 @@ void addArraysAndMaps() QTest::newRow("array-1(map)") << raw("\x81\xc1\xa0") << make_list(QVariant::fromValue(Tag{1, make_map({})})); QTest::newRow("map-1(2):3(4)") << raw("\xa1\xc1\2\xc3\4") << make_map({{QVariant::fromValue(Tag{1, 2}), QVariant::fromValue(Tag{3, 4})}}); } - +} // namespace diff --git a/tests/parser/data.cpp b/tests/parser/data.cpp index f701a5a5..c99160ad 100644 --- a/tests/parser/data.cpp +++ b/tests/parser/data.cpp @@ -28,6 +28,8 @@ Q_DECLARE_METATYPE(CborError) +namespace { + template QByteArray raw(const char (&data)[N]) { return QByteArray::fromRawData(data, N - 1); @@ -605,3 +607,4 @@ void addValidationData(size_t minInvalid = ~size_t(0)) // This test technically tests the dumper, not the parser. QTest::newRow("string-utf8-chunk-split") << raw("\x81\x7f\x61\xc2\x61\xa0\xff") << 0 << CborErrorInvalidUtf8TextString; } +} // namespace