Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract utility functions for QUuid #4308

Merged
merged 4 commits into from
Sep 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1560,7 +1560,6 @@ add_executable(mixxx-test
src/test/colorconfig_test.cpp
src/test/colormapperjsproxy_test.cpp
src/test/colorpalette_test.cpp
src/test/compatibility_test.cpp
src/test/configobject_test.cpp
src/test/controller_mapping_validation_test.cpp
src/test/controllerscriptenginelegacy_test.cpp
Expand Down Expand Up @@ -1639,6 +1638,7 @@ add_executable(mixxx-test
src/test/tracknumberstest.cpp
src/test/trackreftest.cpp
src/test/trackupdate_test.cpp
src/test/uuid_test.cpp
src/test/wbatterytest.cpp
src/test/wpushbutton_test.cpp
src/test/wwidgetstack_test.cpp
Expand Down
2 changes: 1 addition & 1 deletion src/library/basetracktablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const QStringList kDefaultTableColumns = {
inline QSqlDatabase cloneDatabase(
const QSqlDatabase& prototype) {
const auto connectionName =
uuidToStringWithoutBraces(QUuid::createUuid());
QUuid::createUuid().toString(QUuid::WithoutBraces);
auto cloned = QSqlDatabase::cloneDatabase(
prototype,
connectionName);
Expand Down
3 changes: 1 addition & 2 deletions src/musicbrainz/web/musicbrainzrecordingstask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "musicbrainz/musicbrainzxml.h"
#include "network/httpstatuscode.h"
#include "util/assert.h"
#include "util/compatibility.h"
#include "util/logger.h"
#include "util/thread_affinity.h"
#include "util/versionstore.h"
Expand Down Expand Up @@ -50,7 +49,7 @@ QNetworkRequest createNetworkRequest(
DEBUG_ASSERT(kBaseUrl.isValid());
DEBUG_ASSERT(!recordingId.isNull());
QUrl url = kBaseUrl;
url.setPath(kRequestPath + uuidToStringWithoutBraces(recordingId));
url.setPath(kRequestPath + recordingId.toString(QUuid::WithoutBraces));
url.setQuery(createUrlQuery());
DEBUG_ASSERT(url.isValid());
QNetworkRequest networkRequest(url);
Expand Down
26 changes: 0 additions & 26 deletions src/test/compatibility_test.cpp

This file was deleted.

20 changes: 20 additions & 0 deletions src/test/uuid_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <gtest/gtest.h>

#include "util/quuid.h"

class UuidTest : public testing::Test {
};

TEST_F(UuidTest, uuidToNullableStringWithoutBracesNullTest) {
EXPECT_STREQ(
qPrintable(QString{}),
qPrintable(uuidToNullableStringWithoutBraces(QUuid{})));
}

TEST_F(UuidTest, uuidToNullableStringWithoutBracesValidTest) {
const auto validUuid = QUuid::createUuid();
ASSERT_FALSE(validUuid.isNull());
EXPECT_STREQ(
qPrintable(validUuid.toString(QUuid::WithoutBraces)),
qPrintable(uuidToNullableStringWithoutBraces(validUuid)));
}
3 changes: 1 addition & 2 deletions src/track/taglib/trackmetadata_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
#include <QString>

#if defined(__EXTRA_METADATA__)
// UUID -> QString
#include "util/compatibility.h"
#include "util/quuid.h"
#endif // __EXTRA_METADATA__

#include "track/trackmetadata.h"
Expand Down
15 changes: 0 additions & 15 deletions src/util/compatibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <QCoreApplication>
#include <QGuiApplication>
#include <QScreen>
#include <QUuid>
#include <QWidget>
#include <QtDebug>

Expand All @@ -24,17 +23,3 @@ inline QScreen* getPrimaryScreen() {
}
return app->primaryScreen();
}

inline
QString uuidToStringWithoutBraces(const QUuid& uuid) {
return uuid.toString(QUuid::WithoutBraces);
}

inline
QString uuidToNullableStringWithoutBraces(const QUuid& uuid) {
if (uuid.isNull()) {
return QString();
} else {
return uuidToStringWithoutBraces(uuid);
}
}
18 changes: 18 additions & 0 deletions src/util/quuid.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include <QString>
#include <QUuid>

///
/// Utility functions for QUuid
///

/// Format a UUID without enclosing curly braces, representing a null UUID
/// by an empty string instead of 00000000-0000-0000-0000-000000000000.
inline QString uuidToNullableStringWithoutBraces(const QUuid& uuid) {
if (uuid.isNull()) {
return QString{};
} else {
return uuid.toString(QUuid::WithoutBraces);
}
}
1 change: 1 addition & 0 deletions src/widget/wtrackmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "preferences/colorpalettesettings.h"
#include "sources/soundsourceproxy.h"
#include "track/track.h"
#include "util/compatibility.h"
#include "util/desktophelper.h"
#include "util/parented_ptr.h"
#include "util/qt.h"
Expand Down