You are viewing a plain text version of this content. The canonical link for it is here.
Posted to yoko-commits@incubator.apache.org by dm...@apache.org on 2006/09/15 17:29:40 UTC
svn commit: r446663 - in /incubator/yoko/trunk/bindings/src:
main/java/org/apache/yoko/bindings/corba/types/CorbaAnyHandler.java
test/java/org/apache/yoko/bindings/corba/types/CorbaAnyHandlerTest.java
Author: dmiddlem
Date: Fri Sep 15 10:29:39 2006
New Revision: 446663
URL: http://svn.apache.org/viewvc?view=rev&rev=446663
Log:
Tests for recently added Any support. Also a bug fix to the Any
handler (YOKO-156)
Added:
incubator/yoko/trunk/bindings/src/test/java/org/apache/yoko/bindings/corba/types/CorbaAnyHandlerTest.java (with props)
Modified:
incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/types/CorbaAnyHandler.java
Modified: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/types/CorbaAnyHandler.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/types/CorbaAnyHandler.java?view=diff&rev=446663&r1=446662&r2=446663
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/types/CorbaAnyHandler.java (original)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/types/CorbaAnyHandler.java Fri Sep 15 10:29:39 2006
@@ -113,7 +113,7 @@
result = Boolean.toString(value.extract_boolean());
break;
case TCKind._tk_char:
- result = Character.toString(value.extract_char());
+ result = Byte.toString((byte)value.extract_char());
break;
case TCKind._tk_wchar:
result = Character.toString(value.extract_wchar());
Added: incubator/yoko/trunk/bindings/src/test/java/org/apache/yoko/bindings/corba/types/CorbaAnyHandlerTest.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/test/java/org/apache/yoko/bindings/corba/types/CorbaAnyHandlerTest.java?view=auto&rev=446663
==============================================================================
--- incubator/yoko/trunk/bindings/src/test/java/org/apache/yoko/bindings/corba/types/CorbaAnyHandlerTest.java (added)
+++ incubator/yoko/trunk/bindings/src/test/java/org/apache/yoko/bindings/corba/types/CorbaAnyHandlerTest.java Fri Sep 15 10:29:39 2006
@@ -0,0 +1,354 @@
+package org.apache.yoko.bindings.corba.types;
+
+import javax.xml.namespace.QName;
+
+import org.apache.yoko.bindings.corba.CorbaConstants;
+
+import org.omg.CORBA.Any;
+import org.omg.CORBA.ORB;
+import org.omg.CORBA.TCKind;
+import org.omg.CORBA.TypeCode;
+
+import junit.framework.TestCase;
+
+public class CorbaAnyHandlerTest extends TestCase {
+
+ private ORB orb;
+
+ public CorbaAnyHandlerTest(String arg0) {
+ super(arg0);
+ }
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(CorbaAnyHandlerTest.class);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ java.util.Properties props = System.getProperties();
+ props.put("org.omg.CORBA.ORBClass", "org.apache.yoko.orb.CORBA.ORB");
+ props.put("org.omg.CORBA.ORBSingletonClass", "org.apache.yoko.orb.CORBA.ORBSingleton");
+ props.put("yoko.orb.id", "Yoko-Server-Binding");
+ orb = ORB.init(new String[0], props);
+ }
+
+ protected void tearDown() throws Exception {
+ if (orb != null) {
+ try {
+ orb.destroy();
+ } catch (Exception ex) {
+ // Do nothing. Throw an Exception?
+ }
+ }
+ }
+
+ public void testGetSetSchemaType() {
+ String testSchemaType = "xs:string";
+ QName anyName = new QName("TestAny");
+ QName anyIdlType = CorbaConstants.NT_CORBA_ANY;
+ TypeCode anyTC = orb.get_primitive_tc(TCKind.tk_any);
+
+ CorbaAnyHandler anyHandler = new CorbaAnyHandler(anyName, anyIdlType, anyTC, null);
+ anyHandler.setSchemaType(testSchemaType);
+ String result = anyHandler.getSchemaType();
+ assert(result.equals(testSchemaType));
+ }
+
+ public void testGetSetValue() {
+ QName anyName = new QName("TestAny");
+ QName anyIdlType = CorbaConstants.NT_CORBA_ANY;
+ TypeCode anyTC = orb.get_primitive_tc(TCKind.tk_any);
+
+ CorbaAnyHandler anyHandler = new CorbaAnyHandler(anyName, anyIdlType, anyTC, null);
+ Any any = orb.create_any();
+ String expectedSchemaType = null;
+ Any result = null;
+ String resultSchemaType = null;
+
+ boolean boolValue = false;
+ any.insert_boolean(boolValue);
+ anyHandler.setValue(any);
+ expectedSchemaType = "xs:boolean";
+ result = anyHandler.getValue();
+ assertTrue(result.type().kind().value() == TCKind._tk_boolean);
+ boolean boolResult = result.extract_boolean();
+ assertTrue(boolResult == boolValue);
+ resultSchemaType = anyHandler.getSchemaType();
+ assertTrue(resultSchemaType.equals(expectedSchemaType));
+
+ char charValue = 'c';
+ any.insert_char(charValue);
+ anyHandler.setValue(any);
+ expectedSchemaType = "xs:byte";
+ result = anyHandler.getValue();
+ assertTrue(result.type().kind().value() == TCKind._tk_char);
+ char charResult = result.extract_char();
+ assertTrue(charResult == charValue);
+ resultSchemaType = anyHandler.getSchemaType();
+ assertTrue(resultSchemaType.equals(expectedSchemaType));
+
+ char wcharValue = 'w';
+ any.insert_wchar(wcharValue);
+ anyHandler.setValue(any);
+ expectedSchemaType = "xs:string";
+ result = anyHandler.getValue();
+ assertTrue(result.type().kind().value() == TCKind._tk_wchar);
+ char wcharResult = result.extract_wchar();
+ assertTrue(wcharResult == wcharValue);
+ resultSchemaType = anyHandler.getSchemaType();
+ assertTrue(resultSchemaType.equals(expectedSchemaType));
+
+ byte octetValue = (byte)8;
+ any.insert_octet(octetValue);
+ anyHandler.setValue(any);
+ expectedSchemaType = "xs:unsignedByte";
+ result = anyHandler.getValue();
+ assertTrue(result.type().kind().value() == TCKind._tk_octet);
+ byte octetResult = result.extract_octet();
+ assertTrue(octetResult == octetValue);
+ resultSchemaType = anyHandler.getSchemaType();
+ assertTrue(resultSchemaType.equals(expectedSchemaType));
+
+ short shortValue = (short)-123;
+ any.insert_short(shortValue);
+ anyHandler.setValue(any);
+ expectedSchemaType = "xs:short";
+ result = anyHandler.getValue();
+ assertTrue(result.type().kind().value() == TCKind._tk_short);
+ short shortResult = result.extract_short();
+ assertTrue(shortResult == shortValue);
+ resultSchemaType = anyHandler.getSchemaType();
+ assertTrue(resultSchemaType.equals(expectedSchemaType));
+
+ short ushortValue = (short)123;
+ any.insert_ushort(ushortValue);
+ anyHandler.setValue(any);
+ expectedSchemaType = "xs:unsignedShort";
+ result = anyHandler.getValue();
+ assertTrue(result.type().kind().value() == TCKind._tk_ushort);
+ short ushortResult = result.extract_ushort();
+ assertTrue(ushortResult == ushortValue);
+ resultSchemaType = anyHandler.getSchemaType();
+ assertTrue(resultSchemaType.equals(expectedSchemaType));
+
+ int longValue = -12345;
+ any.insert_long(longValue);
+ anyHandler.setValue(any);
+ expectedSchemaType = "xs:int";
+ result = anyHandler.getValue();
+ assertTrue(result.type().kind().value() == TCKind._tk_long);
+ int longResult = result.extract_long();
+ assertTrue(longResult == longValue);
+ resultSchemaType = anyHandler.getSchemaType();
+ assertTrue(resultSchemaType.equals(expectedSchemaType));
+
+ int ulongValue = 12345;
+ any.insert_ulong(ulongValue);
+ anyHandler.setValue(any);
+ expectedSchemaType = "xs:unsignedInt";
+ result = anyHandler.getValue();
+ assertTrue(result.type().kind().value() == TCKind._tk_ulong);
+ int ulongResult = result.extract_ulong();
+ assertTrue(ulongResult == ulongValue);
+ resultSchemaType = anyHandler.getSchemaType();
+ assertTrue(resultSchemaType.equals(expectedSchemaType));
+
+ long longlongValue = -123456789;
+ any.insert_longlong(longlongValue);
+ anyHandler.setValue(any);
+ expectedSchemaType = "xs:long";
+ result = anyHandler.getValue();
+ assertTrue(result.type().kind().value() == TCKind._tk_longlong);
+ long longlongResult = result.extract_longlong();
+ assertTrue(longlongResult == longlongValue);
+ resultSchemaType = anyHandler.getSchemaType();
+ assertTrue(resultSchemaType.equals(expectedSchemaType));
+
+ long ulonglongValue = 123456789;
+ any.insert_ulonglong(ulonglongValue);
+ anyHandler.setValue(any);
+ expectedSchemaType = "xs:unsignedLong";
+ result = anyHandler.getValue();
+ assertTrue(result.type().kind().value() == TCKind._tk_ulonglong);
+ long ulonglongResult = result.extract_ulonglong();
+ assertTrue(ulonglongResult == ulonglongValue);
+ resultSchemaType = anyHandler.getSchemaType();
+ assertTrue(resultSchemaType.equals(expectedSchemaType));
+
+ double doubleValue = 1234.56;
+ any.insert_double(doubleValue);
+ anyHandler.setValue(any);
+ expectedSchemaType = "xs:double";
+ result = anyHandler.getValue();
+ assertTrue(result.type().kind().value() == TCKind._tk_double);
+ double doubleResult = result.extract_double();
+ assertTrue(doubleResult == doubleValue);
+ resultSchemaType = anyHandler.getSchemaType();
+ assertTrue(resultSchemaType.equals(expectedSchemaType));
+
+ float floatValue = 123456.78f;
+ any.insert_float(floatValue);
+ anyHandler.setValue(any);
+ expectedSchemaType = "xs:float";
+ result = anyHandler.getValue();
+ assertTrue(result.type().kind().value() == TCKind._tk_float);
+ float floatResult = result.extract_float();
+ assertTrue(floatResult == floatValue);
+ resultSchemaType = anyHandler.getSchemaType();
+ assertTrue(resultSchemaType.equals(expectedSchemaType));
+
+ String stringValue = "test string";
+ any.insert_string(stringValue);
+ anyHandler.setValue(any);
+ expectedSchemaType = "xs:string";
+ result = anyHandler.getValue();
+ assertTrue(result.type().kind().value() == TCKind._tk_string);
+ String stringResult = result.extract_string();
+ assertTrue(stringResult == stringValue);
+ resultSchemaType = anyHandler.getSchemaType();
+ assertTrue(resultSchemaType.equals(expectedSchemaType));
+
+ String wstringValue = "test wstring";
+ any.insert_wstring(wstringValue);
+ anyHandler.setValue(any);
+ expectedSchemaType = "xs:string";
+ result = anyHandler.getValue();
+ assertTrue(result.type().kind().value() == TCKind._tk_wstring);
+ String wstringResult = result.extract_wstring();
+ assertTrue(wstringResult == wstringValue);
+ resultSchemaType = anyHandler.getSchemaType();
+ assertTrue(resultSchemaType.equals(expectedSchemaType));
+ }
+
+ public void testGetSetValueData() {
+ QName anyName = new QName("TestAny");
+ QName anyIdlType = CorbaConstants.NT_CORBA_ANY;
+ TypeCode anyTC = orb.get_primitive_tc(TCKind.tk_any);
+ CorbaAnyHandler anyHandler = new CorbaAnyHandler(anyName, anyIdlType, anyTC, null);
+
+ String value = null;
+ String resultValue = null;
+ String schemaType = null;
+ String resultSchemaType = null;
+ Any resultAny = null;
+
+ value = "false";
+ schemaType = "xs:boolean";
+ anyHandler.setValueFromData(orb, value, schemaType);
+ resultValue = anyHandler.getValueData();
+ resultSchemaType = anyHandler.getSchemaType();
+ assertTrue(resultValue.equals(value));
+ assertTrue(resultSchemaType.equals(schemaType));
+ resultAny = anyHandler.getValue();
+ assertTrue(resultAny.type().kind().value() == TCKind._tk_boolean);
+
+ value = "7";
+ schemaType = "xs:byte";
+ anyHandler.setValueFromData(orb, value, schemaType);
+ resultValue = anyHandler.getValueData();
+ resultSchemaType = anyHandler.getSchemaType();
+ assertTrue(resultValue.equals(value));
+ assertTrue(resultSchemaType.equals(schemaType));
+ resultAny = anyHandler.getValue();
+ assertTrue(resultAny.type().kind().value() == TCKind._tk_char);
+
+ value = "1234.56";
+ schemaType = "xs:double";
+ anyHandler.setValueFromData(orb, value, schemaType);
+ resultValue = anyHandler.getValueData();
+ resultSchemaType = anyHandler.getSchemaType();
+ assertTrue(resultValue.equals(value));
+ assertTrue(resultSchemaType.equals(schemaType));
+ resultAny = anyHandler.getValue();
+ assertTrue(resultAny.type().kind().value() == TCKind._tk_double);
+
+ value = "987654.321";
+ schemaType = "xs:float";
+ anyHandler.setValueFromData(orb, value, schemaType);
+ resultSchemaType = anyHandler.getSchemaType();
+ assertTrue(resultSchemaType.equals(schemaType));
+ resultAny = anyHandler.getValue();
+ assertTrue(resultAny.type().kind().value() == TCKind._tk_float);
+
+ value = "12345";
+ schemaType = "xs:int";
+ anyHandler.setValueFromData(orb, value, schemaType);
+ resultValue = anyHandler.getValueData();
+ resultSchemaType = anyHandler.getSchemaType();
+ assertTrue(resultValue.equals(value));
+ assertTrue(resultSchemaType.equals(schemaType));
+ resultAny = anyHandler.getValue();
+ assertTrue(resultAny.type().kind().value() == TCKind._tk_long);
+
+ value = "123456789";
+ schemaType = "xs:long";
+ anyHandler.setValueFromData(orb, value, schemaType);
+ resultValue = anyHandler.getValueData();
+ resultSchemaType = anyHandler.getSchemaType();
+ assertTrue(resultValue.equals(value));
+ assertTrue(resultSchemaType.equals(schemaType));
+ resultAny = anyHandler.getValue();
+ assertTrue(resultAny.type().kind().value() == TCKind._tk_longlong);
+
+ value = "123";
+ schemaType = "xs:short";
+ anyHandler.setValueFromData(orb, value, schemaType);
+ resultValue = anyHandler.getValueData();
+ resultSchemaType = anyHandler.getSchemaType();
+ assertTrue(resultValue.equals(value));
+ assertTrue(resultSchemaType.equals(schemaType));
+ resultAny = anyHandler.getValue();
+ assertTrue(resultAny.type().kind().value() == TCKind._tk_short);
+
+ value = "test string";
+ schemaType = "xs:string";
+ anyHandler.setValueFromData(orb, value, schemaType);
+ resultValue = anyHandler.getValueData();
+ resultSchemaType = anyHandler.getSchemaType();
+ assertTrue(resultValue.equals(value));
+ assertTrue(resultSchemaType.equals(schemaType));
+ resultAny = anyHandler.getValue();
+ assertTrue(resultAny.type().kind().value() == TCKind._tk_string);
+
+ value = "9";
+ schemaType = "xs:unsignedByte";
+ anyHandler.setValueFromData(orb, value, schemaType);
+ resultValue = anyHandler.getValueData();
+ resultSchemaType = anyHandler.getSchemaType();
+ assertTrue(resultValue.equals(value));
+ assertTrue(resultSchemaType.equals(schemaType));
+ resultAny = anyHandler.getValue();
+ assertTrue(resultAny.type().kind().value() == TCKind._tk_octet);
+
+ value = "654321";
+ schemaType = "xs:unsignedInt";
+ anyHandler.setValueFromData(orb, value, schemaType);
+ resultValue = anyHandler.getValueData();
+ resultSchemaType = anyHandler.getSchemaType();
+ assertTrue(resultValue.equals(value));
+ assertTrue(resultSchemaType.equals(schemaType));
+ resultAny = anyHandler.getValue();
+ assertTrue(resultAny.type().kind().value() == TCKind._tk_ulong);
+
+ value = "987654321";
+ schemaType = "xs:unsignedLong";
+ anyHandler.setValueFromData(orb, value, schemaType);
+ resultValue = anyHandler.getValueData();
+ resultSchemaType = anyHandler.getSchemaType();
+ assertTrue(resultValue.equals(value));
+ assertTrue(resultSchemaType.equals(schemaType));
+ resultAny = anyHandler.getValue();
+ assertTrue(resultAny.type().kind().value() == TCKind._tk_ulonglong);
+
+ value = "321";
+ schemaType = "xs:unsignedShort";
+ anyHandler.setValueFromData(orb, value, schemaType);
+ resultValue = anyHandler.getValueData();
+ resultSchemaType = anyHandler.getSchemaType();
+ assertTrue(resultValue.equals(value));
+ assertTrue(resultSchemaType.equals(schemaType));
+ resultAny = anyHandler.getValue();
+ assertTrue(resultAny.type().kind().value() == TCKind._tk_ushort);
+ }
+}
Propchange: incubator/yoko/trunk/bindings/src/test/java/org/apache/yoko/bindings/corba/types/CorbaAnyHandlerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/yoko/trunk/bindings/src/test/java/org/apache/yoko/bindings/corba/types/CorbaAnyHandlerTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date