Commits

Tobias Westerblom  committed e3c6ab6

fixed missing int64 (long) support for java library

  • Participants
  • Parent commits 9f529c9

Comments (0)

Files changed (7)

File core/dependency-reduced-pom.xml

     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
-      <version>3.8.1</version>
+      <version>4.11</version>
       <scope>test</scope>
+      <exclusions>
+        <exclusion>
+          <artifactId>hamcrest-core</artifactId>
+          <groupId>org.hamcrest</groupId>
+        </exclusion>
+      </exclusions>
     </dependency>
   </dependencies>
 </project>

File core/pom.xml

 		<dependency>
 			<groupId>junit</groupId>
 			<artifactId>junit</artifactId>
-			<version>3.8.1</version>
+			<version>4.11</version>
 			<scope>test</scope>
 		</dependency>
 		<dependency>

File core/src/main/java/com/cubeia/firebase/io/PacketInputStream.java

 			data[i] = inBuffer.getInt();
 		}
 	}
+	
+    public void loadLongArray(long[] data) throws IOException {
+        for (int i = 0; i < data.length; i++) {
+            data[i] = inBuffer.getLong();
+        }
+    }
 
 	public void loadStringArray(String[] removedParams) throws IOException {
 		for (int i = 0; i < removedParams.length; i++) {

File core/src/main/java/com/cubeia/firebase/io/PacketOutputStream.java

 			os.writeInt(val);
 		}
 	}
-
+	
+    public void saveArray(long[] data) throws IOException {
+        for (long val : data) {
+            os.writeLong(val);
+        }
+    }
+	
 	public void saveArray(String[] removedParams) throws IOException {
 		for (String name : removedParams) {
 			saveString(name);

File core/src/test/java/com/cubeia/firebase/protocol/StyxTest.java

 package com.cubeia.firebase.protocol;
 
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
 import com.cubeia.firebase.io.PacketInputStream;
 import com.cubeia.firebase.io.PacketOutputStream;
 import com.cubeia.firebase.io.StyxSerializer;
 
-
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-import java.io.*;
-import java.nio.ByteBuffer;
-
 public class StyxTest extends TestCase {
 
     public void testBasicSerialization() throws Exception {
         assertEquals(in.loadBoolean(), in_bool);
         assertEquals(in.loadBoolean(), in_bool2);
     }
+    
+    public void testBasicArraysSerialization() throws Exception {
+        byte[] in_int8_array = new byte[] {1, 2, -100};
+        int[] in_int32_array = new int[] {1000, 2000000, -10000000};
+        long[] in_int64_array = new long[] {100000L, 200000000000L, -1000000000000L};
+        String[] in_string_array = new String[] {"one", "two", "three"};
+        
+        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+        PacketOutputStream out = new PacketOutputStream(new DataOutputStream(bytes));
+        out.saveArray(in_int8_array);
+        out.saveArray(in_int32_array);
+        out.saveArray(in_int64_array);
+        out.saveArray(in_string_array);
+        
+        ByteBuffer buffer = ByteBuffer.wrap(bytes.toByteArray());
+        PacketInputStream in = new PacketInputStream(buffer);
+
+        byte[] out_int8_array = new byte[3];
+        in.loadByteArray(out_int8_array);
+        assertThat(out_int8_array, is(in_int8_array));
+        
+        int[] out_int32_array = new int[3];
+        in.loadIntArray(out_int32_array);
+        assertThat(out_int32_array, is(in_int32_array));
+        
+        long[] out_int64_array = new long[3];
+        in.loadLongArray(out_int64_array);
+        assertThat(out_int64_array, is(in_int64_array));
+        
+        String[] out_string_array = new String[3];
+        in.loadStringArray(out_string_array);
+        assertThat(out_string_array, is(in_string_array));
+    }
+    
 
     public void testSaveStringSizeOverflow() throws IOException {
         ByteArrayOutputStream byteOut = new ByteArrayOutputStream();

File maven/pom.xml

 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 	<modelVersion>4.0.0</modelVersion>
 	<artifactId>styx-maven</artifactId>
-	<name>Sttyx Maven Tools</name>
+	<name>Styx Maven Tools</name>
 	<packaging>pom</packaging>
 
 	<parent>

File maven/protocol-tests/java-test/src/test/resources/protocol.xml

     </struct>
     
     <struct id="2" name="type_test_packet">
+        <var name="ui8" type="uint8"/>
+        <var name="ui64" type="uint64"/>
+        
         <var name="i8" type="int8"/>
-        <var name="ui8" type="uint8"/>
         <var name="i16" type="int16"/>
         <var name="i32" type="int32"/>
+        <var name="i64" type="int64"/>
+        
         <var name="b" type="bool"/>
         <var name="s" type="string"/>
     </struct>
     <struct id="6" name="list_of_ints">
     	<list name="l" type="int32" />
     </struct>
+    
+    <struct id="7" name="list_of_ints_64">
+    	<list name="l" type="int64" />
+    </struct>
+    
+    <struct id="8" name="list_of_uints_64">
+    	<list name="l" type="uint64" />
+    </struct>
   
 </protocol>