}
}
+ out << indent() << "// check for sub-struct validity" << endl;
+ for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
+ t_type* type = (*f_iter)->get_type();
+ if (type->is_struct() && ! ((t_struct*)type)->is_union()) {
+ out << indent() << "if (" << (*f_iter)->get_name() << " != null) {" << endl;
+ out << indent() << " " << (*f_iter)->get_name() << ".validate();" << endl;
+ out << indent() << "}" << endl;
+ }
+ }
+
indent_down();
indent(out) << "}" << endl << endl;
}
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
-
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;
import thrift.test.Nesting;
import thrift.test.Numberz;
import thrift.test.OneOfEach;
+import thrift.test.StructA;
+import thrift.test.StructB;
import thrift.test.Xtruct;
public class TestStruct extends TestCase {
assertEquals(ooe, ooe2);
}
+
+ public void testSubStructValidation() throws Exception {
+ StructA valid = new StructA("valid");
+ StructA invalid = new StructA();
+
+ StructB b = new StructB();
+ try {
+ b.validate();
+ fail();
+ } catch (TException e) {
+ // expected
+ }
+
+ b = new StructB().setAb(valid);
+ b.validate();
+
+ b = new StructB().setAb(invalid);
+ try {
+ b.validate();
+ fail();
+ } catch (TException e) {
+ // expected
+ }
+
+ b = new StructB().setAb(valid).setAa(invalid);
+ try {
+ b.validate();
+ fail();
+ } catch (TException e) {
+ // expected
+ }
+ }
}
1: optional bool b = true;
2: optional string s = "true";
}
+
+struct StructA {
+ 1: required string s;
+}
+
+struct StructB {
+ 1: optional StructA aa;
+ 2: required StructA ab;
+}
\ No newline at end of file