You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ro...@apache.org on 2014/02/08 23:14:50 UTC
svn commit: r1566143 - in /qpid/proton/trunk/proton-j/src:
main/java/org/apache/qpid/proton/codec/UnsignedIntegerType.java
test/java/org/apache/qpid/proton/codec/UnsignedIntegerTypeTest.java
Author: robbie
Date: Sat Feb 8 22:14:49 2014
New Revision: 1566143
URL: http://svn.apache.org/r1566143
Log:
PROTON-514: use the correct encoding for uint values over 2^31-1
Added:
qpid/proton/trunk/proton-j/src/test/java/org/apache/qpid/proton/codec/UnsignedIntegerTypeTest.java
Modified:
qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/codec/UnsignedIntegerType.java
Modified: qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/codec/UnsignedIntegerType.java
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/codec/UnsignedIntegerType.java?rev=1566143&r1=1566142&r2=1566143&view=diff
==============================================================================
--- qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/codec/UnsignedIntegerType.java (original)
+++ qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/codec/UnsignedIntegerType.java Sat Feb 8 22:14:49 2014
@@ -56,7 +56,7 @@ public class UnsignedIntegerType extends
int i = val.intValue();
return i == 0
? _zeroUnsignedIntegerEncoding
- : (i <= 255) ? _smallUnsignedIntegerEncoding : _unsignedIntegerEncoding;
+ : (i >= 0 && i <= 255) ? _smallUnsignedIntegerEncoding : _unsignedIntegerEncoding;
}
Added: qpid/proton/trunk/proton-j/src/test/java/org/apache/qpid/proton/codec/UnsignedIntegerTypeTest.java
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-j/src/test/java/org/apache/qpid/proton/codec/UnsignedIntegerTypeTest.java?rev=1566143&view=auto
==============================================================================
--- qpid/proton/trunk/proton-j/src/test/java/org/apache/qpid/proton/codec/UnsignedIntegerTypeTest.java (added)
+++ qpid/proton/trunk/proton-j/src/test/java/org/apache/qpid/proton/codec/UnsignedIntegerTypeTest.java Sat Feb 8 22:14:49 2014
@@ -0,0 +1,66 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.proton.codec;
+
+import static org.junit.Assert.*;
+
+import org.apache.qpid.proton.amqp.UnsignedInteger;
+import org.apache.qpid.proton.codec.UnsignedIntegerType.UnsignedIntegerEncoding;
+import org.junit.Test;
+
+public class UnsignedIntegerTypeTest
+{
+ @Test
+ public void testGetEncodingWithZero()
+ {
+ DecoderImpl decoder = new DecoderImpl();
+ EncoderImpl encoder = new EncoderImpl(decoder);
+ UnsignedIntegerType ult = new UnsignedIntegerType(encoder, decoder);
+
+ //values of 0 are encoded as a specific type
+ UnsignedIntegerEncoding encoding = ult.getEncoding(UnsignedInteger.valueOf(0L));
+ assertEquals("incorrect encoding returned", EncodingCodes.UINT0, encoding.getEncodingCode());
+ }
+
+ @Test
+ public void testGetEncodingWithSmallPositiveValue()
+ {
+ DecoderImpl decoder = new DecoderImpl();
+ EncoderImpl encoder = new EncoderImpl(decoder);
+ UnsignedIntegerType ult = new UnsignedIntegerType(encoder, decoder);
+
+ //values between 0 and 255 are encoded as a specific 'small' type using a single byte
+ UnsignedIntegerEncoding encoding = ult.getEncoding(UnsignedInteger.valueOf(1L));
+ assertEquals("incorrect encoding returned", EncodingCodes.SMALLUINT, encoding.getEncodingCode());
+ }
+
+ @Test
+ public void testGetEncodingWithTwoToThirtyOne()
+ {
+ DecoderImpl decoder = new DecoderImpl();
+ EncoderImpl encoder = new EncoderImpl(decoder);
+ UnsignedIntegerType ult = new UnsignedIntegerType(encoder, decoder);
+
+ long val = Integer.MAX_VALUE + 1L;
+ UnsignedIntegerEncoding encoding = ult.getEncoding(UnsignedInteger.valueOf(val));
+ assertEquals("incorrect encoding returned", EncodingCodes.UINT, encoding.getEncodingCode());
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org