Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Test that wbxml_conv_wbxml2xml_run vaguely works

  • Loading branch information...
commit 6ed266d71a41c032d4bef51a3172231e6d35aa59 1 parent ca74c53
@samstokes samstokes authored
Showing with 52 additions and 2 deletions.
  1. +1 −0  pom.xml
  2. +51 −2 src/test/java/com/rapportive/jawbone/JawboneTest.java
View
1  pom.xml
@@ -36,6 +36,7 @@
<configuration>
<argLine>
-Djna.library.path=${basedir}/lib
+ -Dtest.resources=${basedir}/src/test/resources
</argLine>
</configuration>
</plugin>
View
53 src/test/java/com/rapportive/jawbone/JawboneTest.java
@@ -3,7 +3,8 @@
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
-import java.io.OutputStream;
+import java.io.InputStream;
+import java.io.IOException;
import static org.junit.Assert.*;
@@ -22,8 +23,12 @@
private PointerByReference jawbonePtr = new PointerByReference();
private Pointer jawbone;
+ private static byte[] wbxml;
+
@BeforeClass
public static void setUpBeforeClass() throws Exception {
+ wbxml = readFile(testResource("activesync-001-settings_device_information.wbxml"));
+
binding = JawboneBinding.INSTANCE;
}
@@ -37,6 +42,50 @@ public void setUp() throws Exception {
@Test
public void test() throws Exception {
- assertNotNull(jawbone);
+ binding.wbxml_conv_wbxml2xml_set_gen_type(jawbone, 2); /* WBXML_GEN_XML_CANONICAL */
+ binding.wbxml_conv_wbxml2xml_set_language(jawbone, 2402); /* WBXML_LANG_ACTIVESYNC */
+ binding.wbxml_conv_wbxml2xml_set_charset(jawbone, 0); /* WBXML_CHARSET_UNKNOWN */
+ binding.wbxml_conv_wbxml2xml_set_indent(jawbone, 4); /* 4-space indent */
+ binding.wbxml_conv_wbxml2xml_enable_preserve_whitespaces(jawbone);
+
+ PointerByReference xmlPtr = new PointerByReference();
+ // TODO worry about cleanup
+ LongByReference xmlLength = new LongByReference();
+ int ret = binding.wbxml_conv_wbxml2xml_run(jawbone, wbxml, wbxml.length, xmlPtr, xmlLength);
+
+ assertEquals("wbxml_conv_wbxml2xml_run failed", 0, ret);
+ assertTrue("returned no XML", xmlLength.getValue() > 0);
+
+ byte[] xmlBytes = xmlPtr.getValue().getByteArray(0L, (int) xmlLength.getValue());
+ assertEquals("returned b0rked bytes", xmlLength.getValue(), xmlBytes.length);
+ }
+
+
+ private static String testResource(String path) {
+ String testResourcesDir = System.getProperty("test.resources");
+ if (testResourcesDir == null) {
+ throw new IllegalStateException("Must define property test.resources");
+ }
+ return testResourcesDir + "/" + path;
+ }
+
+ private static byte[] readFile(String path) throws IOException {
+ InputStream fileIn = null;
+ try {
+ fileIn = new BufferedInputStream(new FileInputStream(path));
+ ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
+
+ byte[] buf = new byte[4096];
+ int read;
+ while ((read = fileIn.read(buf)) >= 0) {
+ bytesOut.write(buf, 0, read);
+ }
+
+ return bytesOut.toByteArray();
+ } finally {
+ if (fileIn != null) {
+ fileIn.close();
+ }
+ }
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.