Permalink
Browse files

Test that wbxml_conv_xml2wbxml_run vaguely works

  • Loading branch information...
1 parent d18d437 commit 46ebee55a72df8d564985601aa2820d833868988 @samstokes samstokes committed May 24, 2012
@@ -24,5 +24,17 @@
void wbxml_conv_wbxml2xml_destroy(Pointer conv);
+ int wbxml_conv_xml2wbxml_create(PointerByReference convPtr);
+
+ void wbxml_conv_xml2wbxml_set_version(Pointer conv, int version);
+ void wbxml_conv_xml2wbxml_enable_preserve_whitespaces(Pointer conv);
+ void wbxml_conv_xml2wbxml_disable_string_table(Pointer conv);
+ void wbxml_conv_xml2wbxml_disable_public_id(Pointer conv);
+
+ int wbxml_conv_xml2wbxml_run(Pointer conv, byte[] xml, long xmlLength, PointerByReference wbxmlPtr, LongByReference wbxmlLength);
+
+ void wbxml_conv_xml2wbxml_destroy(Pointer conv);
+
+
String wbxml_errors_string(int ret);
}
@@ -22,10 +22,12 @@
private static JawboneBinding binding;
private static byte[] wbxml;
+ private static byte[] xml;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
wbxml = readFile(testResource("activesync-001-settings_device_information.wbxml"));
+ xml = readFile(testResource("activesync-001-settings_device_information.xml"));
binding = JawboneBinding.INSTANCE;
}
@@ -64,6 +66,38 @@ public void testWbxmlToXml() throws Exception {
}
}
+ @Test
+ public void testXmlToWbxml() throws Exception {
+ PointerByReference convPtr = new PointerByReference();
+ Pointer conv = null;
+
+ int ret = binding.wbxml_conv_xml2wbxml_create(convPtr);
+ assertEquals("wbxml_conv_xml2wbxml_create failed", 0, ret);
+ conv = convPtr.getValue();
+
+ try {
+ binding.wbxml_conv_xml2wbxml_enable_preserve_whitespaces(conv);
+ binding.wbxml_conv_xml2wbxml_disable_string_table(conv);
+ binding.wbxml_conv_xml2wbxml_disable_public_id(conv);
+
+ PointerByReference wbxmlPtr = new PointerByReference();
+ LongByReference wbxmlLength = new LongByReference();
+ ret = binding.wbxml_conv_xml2wbxml_run(conv, xml, xml.length, wbxmlPtr, wbxmlLength);
+
+ assertSuccess("wbxml_conv_xml2wbxml_run", ret);
+ assertTrue("returned no WBXML", wbxmlLength.getValue() > 0);
+
+ byte[] wbxmlBytes = wbxmlPtr.getValue().getByteArray(0L, (int) wbxmlLength.getValue());
+ Native.free(Pointer.nativeValue(wbxmlPtr.getValue()));
+
+ assertEquals("returned b0rked bytes", wbxmlLength.getValue(), wbxmlBytes.length);
+ } finally {
+ if (conv != null) {
+ binding.wbxml_conv_xml2wbxml_destroy(conv);
+ }
+ }
+ }
+
private void assertSuccess(String function, int ret) {
if (ret != 0) {

0 comments on commit 46ebee5

Please sign in to comment.