Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ccfd05b

Browse files
committed
Improve DesktopFile's comparison operators
1 parent 6cf9bc5 commit ccfd05b

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

src/core/desktopfile/desktopfile.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,10 @@ namespace linuxdeploy {
194194
}
195195

196196
bool operator==(const DesktopFile& first, const DesktopFile& second) {
197-
return first.d->data == second.d->data;
197+
return first.d->path == second.d->path && first.d->data == second.d->data;
198198
}
199199

200-
bool operator!=(const DesktopFile& first, const DesktopFile& second) {
200+
bool operator !=(const DesktopFile& first, const DesktopFile& second) {
201201
return !operator==(first, second);
202202
}
203203
}

tests/core/desktopfile/test_desktopfilereader.cpp

+25-3
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,31 @@ TEST_F(DesktopFileReaderTest, testPathConstructorWithNonExistingPath) {
4444
}
4545

4646
TEST_F(DesktopFileReaderTest, testEqualityAndInequalityOperators) {
47-
DesktopFileReader emptyReader;
48-
EXPECT_TRUE(emptyReader == emptyReader);
49-
EXPECT_FALSE(emptyReader != emptyReader);
47+
{
48+
DesktopFileReader emptyReader;
49+
EXPECT_TRUE(emptyReader == emptyReader);
50+
EXPECT_FALSE(emptyReader != emptyReader);
51+
}
52+
53+
{
54+
// make sure that files with different paths are recognized as different
55+
DesktopFile nullFile("/dev/null");
56+
DesktopFile fileWithoutPath;
57+
58+
EXPECT_TRUE(nullFile != fileWithoutPath);
59+
EXPECT_FALSE(nullFile == fileWithoutPath);
60+
}
61+
62+
{
63+
// make sure that files with different contents are recognized as different
64+
DesktopFile fileWithContents;
65+
fileWithContents.setEntry("Desktop Entry", DesktopFileEntry("test", "test"));
66+
67+
DesktopFile emptyFile;
68+
69+
EXPECT_TRUE(emptyFile != fileWithContents);
70+
EXPECT_FALSE(emptyFile == fileWithContents);
71+
}
5072
}
5173

5274
TEST_F(DesktopFileReaderTest, testCopyConstructor) {

0 commit comments

Comments
 (0)