Skip to content

Commit 094a67f

Browse files
committed
Implemented Icon::GetDefaultUnknownFileTypeIcon() and Icon::operator ==() with tests.
1 parent 56b0a7c commit 094a67f

3 files changed

Lines changed: 91 additions & 7 deletions

File tree

src/core/Icon.cpp

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,28 @@ namespace shellanything
5050
{
5151
}
5252

53-
const Icon& Icon::operator =(const Icon& icon)
53+
const Icon& Icon::operator =(const Icon& other)
5454
{
55-
if (this != &icon)
55+
if (this != &other)
5656
{
57-
mFileExtension = icon.mFileExtension;
58-
mPath = icon.mPath;
59-
mIndex = icon.mIndex;
57+
mFileExtension = other.mFileExtension;
58+
mPath = other.mPath;
59+
mIndex = other.mIndex;
6060
}
6161
return (*this);
6262
}
6363

64+
bool Icon::operator ==(const Icon& other) const
65+
{
66+
if (this == &other)
67+
return true;
68+
if ((mFileExtension == other.mFileExtension) &&
69+
(mPath == other.mPath) &&
70+
(mIndex == other.mIndex))
71+
return true;
72+
return false;
73+
}
74+
6475
bool Icon::IsValid() const
6576
{
6677
if (!mFileExtension.empty())
@@ -150,6 +161,14 @@ namespace shellanything
150161
mIndex = index;
151162
}
152163

164+
Icon Icon::GetDefaultUnknownFileTypeIcon()
165+
{
166+
Icon tmp;
167+
tmp.SetFileExtension("this_file_extension_is_not_registered_on_system");
168+
tmp.ResolveFileExtensionIcon();
169+
return tmp;
170+
}
171+
153172
std::string Icon::ToShortString() const
154173
{
155174
std::string str;

src/core/Icon.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,20 @@ namespace shellanything
5353
/// <summary>
5454
/// Copy operator
5555
/// </summary>
56-
const Icon& operator =(const Icon& icon);
56+
const Icon& operator =(const Icon& other);
57+
58+
/// <summary>
59+
/// Equal operator
60+
/// </summary>
61+
bool operator ==(const Icon& other) const;
62+
63+
/// <summary>
64+
/// Not Equal operator
65+
/// </summary>
66+
inline bool operator !=(const Icon& other) const
67+
{
68+
return !((*this) == other);
69+
}
5770

5871
/// <summary>
5972
/// Returns true if the icon have a valid path and index.
@@ -96,6 +109,11 @@ namespace shellanything
96109
/// </summary>
97110
void SetIndex(const int& index);
98111

112+
/// <summary>
113+
/// Get the system's default visual icon for unknown file type.
114+
/// </summary>
115+
static Icon GetDefaultUnknownFileTypeIcon();
116+
99117
// IObject methods
100118
virtual std::string ToShortString() const;
101119
virtual void ToLongString(std::string& str, int indent) const;

src/tests/TestIcon.cpp

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,39 @@ namespace shellanything
6565
{
6666
}
6767
//--------------------------------------------------------------------------------------------------
68+
TEST_F(TestIcon, testOperatorEquals)
69+
{
70+
Icon iconA;
71+
Icon iconB;
72+
73+
#define ASSERT_ICON_EQUALS(iconA, iconB) ASSERT_TRUE(iconA == iconB); ASSERT_FALSE(iconA != iconB);
74+
#define ASSERT_ICON_NOT_EQUALS(iconA, iconB) ASSERT_TRUE(iconA != iconB); ASSERT_FALSE(iconA == iconB);
75+
76+
// assert equals
77+
ASSERT_ICON_EQUALS(iconA, iconB);
78+
79+
iconA.SetFileExtension("txt");
80+
ASSERT_ICON_NOT_EQUALS(iconA, iconB);
81+
82+
iconA.SetFileExtension("exe");
83+
iconB.SetFileExtension("exe");
84+
ASSERT_ICON_EQUALS(iconA, iconB);
85+
86+
iconA.SetPath("foo.dll");
87+
ASSERT_ICON_NOT_EQUALS(iconA, iconB);
88+
89+
iconA.SetPath("bar.dll");
90+
iconB.SetPath("bar.dll");
91+
ASSERT_ICON_EQUALS(iconA, iconB);
92+
93+
iconA.SetIndex(11);
94+
ASSERT_ICON_NOT_EQUALS(iconA, iconB);
95+
96+
iconA.SetIndex(99);
97+
iconB.SetIndex(99);
98+
ASSERT_ICON_EQUALS(iconA, iconB);
99+
}
100+
//--------------------------------------------------------------------------------------------------
68101
TEST_F(TestIcon, testValidIcon)
69102
{
70103
// default ctor
@@ -104,7 +137,7 @@ namespace shellanything
104137
}
105138
}
106139
//--------------------------------------------------------------------------------------------------
107-
TEST_F(TestIcon, testResolveFileExtensionIcon)
140+
TEST_F(TestIcon, testResolveFileExtensionIconTxt)
108141
{
109142
Icon icon;
110143
icon.SetFileExtension("txt");
@@ -115,6 +148,20 @@ namespace shellanything
115148
ASSERT_TRUE(icon.GetFileExtension().empty());
116149
ASSERT_FALSE(icon.GetPath().empty());
117150
ASSERT_NE(Icon::INVALID_ICON_INDEX, icon.GetIndex());
151+
152+
// assert we did not resolve to default unknown icon
153+
ASSERT_TRUE(icon != Icon::GetDefaultUnknownFileTypeIcon());
154+
}
155+
//--------------------------------------------------------------------------------------------------
156+
TEST_F(TestIcon, testGetDefaultUnknownFileTypeIcon)
157+
{
158+
Icon icon = Icon::GetDefaultUnknownFileTypeIcon();
159+
160+
ASSERT_TRUE(icon.IsValid());
161+
ASSERT_TRUE(icon.GetFileExtension().empty());
162+
163+
ASSERT_FALSE(icon.GetPath().empty());
164+
ASSERT_NE(Icon::INVALID_ICON_INDEX, icon.GetIndex());
118165
}
119166
//--------------------------------------------------------------------------------------------------
120167
TEST_F(TestIcon, testResolveMultipleFileExtensionIcon) // issue #98

0 commit comments

Comments
 (0)