Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
8d47ec4f
Commit
8d47ec4f
authored
Jul 04, 2015
by
Jon Skeet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes to ByteString's equality handling.
parent
b2ac8684
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
20 deletions
+41
-20
ByteStringTest.cs
csharp/src/ProtocolBuffers.Test/ByteStringTest.cs
+26
-0
ByteString.cs
csharp/src/ProtocolBuffers/ByteString.cs
+15
-20
No files found.
csharp/src/ProtocolBuffers.Test/ByteStringTest.cs
View file @
8d47ec4f
...
@@ -38,6 +38,32 @@ namespace Google.Protobuf
...
@@ -38,6 +38,32 @@ namespace Google.Protobuf
{
{
public
class
ByteStringTest
public
class
ByteStringTest
{
{
[
Test
]
public
void
Equality
()
{
ByteString
b1
=
ByteString
.
CopyFrom
(
1
,
2
,
3
);
ByteString
b2
=
ByteString
.
CopyFrom
(
1
,
2
,
3
);
ByteString
b3
=
ByteString
.
CopyFrom
(
1
,
2
,
4
);
ByteString
b4
=
ByteString
.
CopyFrom
(
1
,
2
,
3
,
4
);
EqualityTester
.
AssertEquality
(
b1
,
b1
);
EqualityTester
.
AssertEquality
(
b1
,
b2
);
EqualityTester
.
AssertInequality
(
b1
,
b3
);
EqualityTester
.
AssertInequality
(
b1
,
b4
);
EqualityTester
.
AssertInequality
(
b1
,
null
);
Assert
.
IsTrue
(
b1
==
b1
);
Assert
.
IsTrue
(
b1
==
b2
);
Assert
.
IsFalse
(
b1
==
b3
);
Assert
.
IsFalse
(
b1
==
b4
);
Assert
.
IsFalse
(
b1
==
null
);
Assert
.
IsTrue
((
ByteString
)
null
==
null
);
Assert
.
IsFalse
(
b1
!=
b1
);
Assert
.
IsFalse
(
b1
!=
b2
);
Assert
.
IsTrue
(
b1
!=
b3
);
Assert
.
IsTrue
(
b1
!=
b4
);
Assert
.
IsTrue
(
b1
!=
null
);
Assert
.
IsFalse
((
ByteString
)
null
!=
null
);
}
[
Test
]
[
Test
]
public
void
EmptyByteStringHasZeroSize
()
public
void
EmptyByteStringHasZeroSize
()
{
{
...
...
csharp/src/ProtocolBuffers/ByteString.cs
View file @
8d47ec4f
...
@@ -212,11 +212,22 @@ namespace Google.Protobuf
...
@@ -212,11 +212,22 @@ namespace Google.Protobuf
{
{
return
true
;
return
true
;
}
}
if
(
ReferenceEquals
(
lhs
,
null
))
if
(
ReferenceEquals
(
lhs
,
null
)
||
ReferenceEquals
(
rhs
,
null
)
)
{
{
return
false
;
return
false
;
}
}
return
lhs
.
Equals
(
rhs
);
if
(
lhs
.
bytes
.
Length
!=
rhs
.
bytes
.
Length
)
{
return
false
;
}
for
(
int
i
=
0
;
i
<
lhs
.
Length
;
i
++)
{
if
(
rhs
.
bytes
[
i
]
!=
lhs
.
bytes
[
i
])
{
return
false
;
}
}
return
true
;
}
}
public
static
bool
operator
!=(
ByteString
lhs
,
ByteString
rhs
)
public
static
bool
operator
!=(
ByteString
lhs
,
ByteString
rhs
)
...
@@ -228,12 +239,7 @@ namespace Google.Protobuf
...
@@ -228,12 +239,7 @@ namespace Google.Protobuf
public
override
bool
Equals
(
object
obj
)
public
override
bool
Equals
(
object
obj
)
{
{
ByteString
other
=
obj
as
ByteString
;
return
this
==
(
obj
as
ByteString
);
if
(
obj
==
null
)
{
return
false
;
}
return
Equals
(
other
);
}
}
public
override
int
GetHashCode
()
public
override
int
GetHashCode
()
...
@@ -248,18 +254,7 @@ namespace Google.Protobuf
...
@@ -248,18 +254,7 @@ namespace Google.Protobuf
public
bool
Equals
(
ByteString
other
)
public
bool
Equals
(
ByteString
other
)
{
{
if
(
other
.
bytes
.
Length
!=
bytes
.
Length
)
return
this
==
other
;
{
return
false
;
}
for
(
int
i
=
0
;
i
<
bytes
.
Length
;
i
++)
{
if
(
other
.
bytes
[
i
]
!=
bytes
[
i
])
{
return
false
;
}
}
return
true
;
}
}
/// <summary>
/// <summary>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment