aboutsummaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorUlas Kirazci <ulas@google.com>2013-07-23 12:04:39 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2013-07-23 12:04:39 -0700
commit09400156818ec809cfc37a950d8b599b52cef88f (patch)
tree3b74a598085c68dec90b1b54610df86db0cba023 /java
parent521d472b7f3efc75118b301131495248d56e3196 (diff)
parent49e4bdc1eb0a66ea2c5cf370564d746bb9b8053e (diff)
downloadprotobuf-09400156818ec809cfc37a950d8b599b52cef88f.tar.gz
protobuf-09400156818ec809cfc37a950d8b599b52cef88f.tar.bz2
protobuf-09400156818ec809cfc37a950d8b599b52cef88f.zip
am 19c4090e: Merge "Allow NaN/+inf/-inf defaults in micro/nano."
* commit '19c4090eddf0eb4d65d1b41f283368c5e0f615a1': Allow NaN/+inf/-inf defaults in micro/nano.
Diffstat (limited to 'java')
-rw-r--r--java/src/test/java/com/google/protobuf/NanoTest.java26
1 files changed, 26 insertions, 0 deletions
diff --git a/java/src/test/java/com/google/protobuf/NanoTest.java b/java/src/test/java/com/google/protobuf/NanoTest.java
index 5a04b6f1..92ddda62 100644
--- a/java/src/test/java/com/google/protobuf/NanoTest.java
+++ b/java/src/test/java/com/google/protobuf/NanoTest.java
@@ -2062,6 +2062,12 @@ public class NanoTest extends TestCase {
assertEquals(TestAllTypesNano.BAR, msg.defaultNestedEnum);
assertEquals(NanoOuterClass.FOREIGN_NANO_BAR, msg.defaultForeignEnum);
assertEquals(UnittestImportNano.IMPORT_NANO_BAR, msg.defaultImportEnum);
+ assertEquals(Float.POSITIVE_INFINITY, msg.defaultFloatInf);
+ assertEquals(Float.NEGATIVE_INFINITY, msg.defaultFloatNegInf);
+ assertEquals(Float.NaN, msg.defaultFloatNan);
+ assertEquals(Double.POSITIVE_INFINITY, msg.defaultDoubleInf);
+ assertEquals(Double.NEGATIVE_INFINITY, msg.defaultDoubleNegInf);
+ assertEquals(Double.NaN, msg.defaultDoubleNan);
// Default values are not output, except for required fields.
byte [] result = MessageNano.toByteArray(msg);
@@ -2074,6 +2080,26 @@ public class NanoTest extends TestCase {
}
/**
+ * Tests that fields with a default value of NaN are not serialized when
+ * set to NaN. This is a special case as NaN != NaN, so normal equality
+ * checks don't work.
+ */
+ public void testNanoNotANumberDefaults() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ msg.defaultDoubleNan = 0;
+ msg.defaultFloatNan = 0;
+ byte[] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ assertTrue(msgSerializedSize > 3);
+
+ msg.defaultDoubleNan = Double.NaN;
+ msg.defaultFloatNan = Float.NaN;
+ result = MessageNano.toByteArray(msg);
+ msgSerializedSize = msg.getSerializedSize();
+ assertEquals(3, msgSerializedSize);
+ }
+
+ /**
* Test that a bug in skipRawBytes() has been fixed: if the skip skips
* exactly up to a limit, this should not break things.
*/