Package org.waveprotocol.wave.model.document.bootstrap

Examples of org.waveprotocol.wave.model.document.bootstrap.BootstrapDocument$Item


  void doTest(TestData t) throws OperationException {
    DocOpBuffer d = new DocOpBuffer();
    DocOpBuffer m = new DocOpBuffer();
    boolean expected = t.build(d, m);

    BootstrapDocument doc = new BootstrapDocument();

    // initialize document
    doc.consume(d.finishUnchecked());

    // check whether m would apply
    ViolationCollector v = new ViolationCollector();
    ValidationResult result =
        DocOpValidator.validate(v, t.getSchemaConstraints(), doc, m.finishUnchecked());
View Full Code Here


    AutomatonDocument checkAuto;

    // Set to false for faster test runs
    boolean checkAgainstBootstrapDocument = true;
    if (checkAgainstBootstrapDocument) {
      BootstrapDocument bootstrapDoc = new BootstrapDocument();
      checkDocOpProvider = bootstrapDoc;
      checkDoc = bootstrapDoc;
      checkAuto = bootstrapDoc;
    } else {
      IndexedDocument<Node, Element, Text> indexedDoc = DocProviders.POJO.parse("");
      checkDocOpProvider = indexedDoc;
      checkDoc = indexedDoc;
      checkAuto = Automatons.fromReadable(indexedDoc);
    }

    for (int i = 0; i < NUM_INITIAL_MUTATIONS; i++) {
      DocOp op = RandomDocOpGenerator.generate(random, params,
          // FIXME(ohler): Add back schema constraints
          // DocumentOperationValidator.DEFAULT_BLIP_SCHEMA_CONSTRAINTS,
          autoDoc);
      doc.consume(op);
      checkDoc.consume(op);
    }

    String originalXml = DocOpUtil.toXmlString(doc.asOperation());

    for (int i = 0; i < NUM_REVERSED_MUTATIONS_PER_RUN; i++) {

      // Apply random mutation and revert it.
      DocOp op = RandomDocOpGenerator.generate(random, params,
          // FIXME(ohler): Add back schema constraints
          // DocumentOperationValidator.DEFAULT_BLIP_SCHEMA_CONSTRAINTS,
          autoDoc);

      Nindo nindo = null;
      String finalXml = null;
      DocOp docOpCopy = null;
      DocInitialization docAsOp = null;

      try {

        //System.out.println("  " + i);
        //System.out.println("\n===" + iteration + "." + i + "===============================");

        docAsOp = doc.asOperation();
        validate(DocOpAutomaton.EMPTY_DOCUMENT, docAsOp);
        IndexedDocument<Node, Element, Text> copy = DocProviders.POJO.build(docAsOp,
            DocumentSchema.NO_SCHEMA_CONSTRAINTS);
        BootstrapDocument copy2 = new BootstrapDocument();
        copy2.consume(docAsOp);

        // CONSUME
        doc.consume(op);
        checkDoc.consume(op);

        finalXml = DocOpUtil.toXmlString(checkDocOpProvider.asOperation());

        assertEquals(finalXml, DocOpUtil.toXmlString(doc.asOperation()));

        // UNDO
        DocOp inverted1 = DocOpInverter.invert(op);
        validate(autoDoc, inverted1);
        doc.consume(inverted1);
        assertEquals(originalXml, DocOpUtil.toXmlString(doc.asOperation()));

        // CONSUME NINDO
        // TODO(danilatos): Both remove and don't remove the trailing skip, randomly
        nindo = Nindo.fromDocOp(op, true);
        docOpCopy = doc.consumeAndReturnInvertible(nindo);
        assertEquals(finalXml, DocOpUtil.toXmlString(doc.asOperation()));

        validate(Automatons.fromReadable(copy), docOpCopy);
        validate(copy2, docOpCopy);
        copy2.consume(docOpCopy);
        assertEquals(finalXml, DocOpUtil.toXmlString(copy2.asOperation()));

        // UNDO NINDO
        DocOp inverted2 = DocOpInverter.invert(docOpCopy);
        validate(checkAuto, inverted2);
        validate(autoDoc, inverted2);
View Full Code Here

  /**
   * Stand-alone main() for quick experimentation.
   */
  public static void main(String[] args) throws OperationException {
    BootstrapDocument initialDoc = new BootstrapDocument();
    initialDoc.consume(new DocInitializationBuilder()
        .elementStart("blip", Attributes.EMPTY_MAP)
        .elementStart("p", Attributes.EMPTY_MAP)
        .characters("abc")
        .elementEnd()
        .elementEnd().build());

    Parameters p = new Parameters();

    p.setMaxOpeningComponents(10);

    RandomProvider r = RandomProviderImpl.ofSeed(2538);
    for (int i = 0; i < 200; i++) {
      BootstrapDocument doc = new BootstrapDocument();
      doc.consume(initialDoc.asOperation());
      for (int j = 0; j < 20; j++) {
        System.err.println("i=" + i + ", j=" + j);
        System.err.println("old: " + DocOpUtil.toXmlString(doc.asOperation()));
        System.err.println("old: " + DocOpUtil.toConciseString(doc.asOperation()));
        DocOp op = generate(r, p, doc);
        System.err.println("op:  " + DocOpUtil.toConciseString(op));
        doc.consume(op);
        System.err.println("new: " + DocOpUtil.toConciseString(doc.asOperation()));
        System.err.println("new: " + DocOpUtil.toXmlString(doc.asOperation()));
        if (!DocOpValidator.validate(null, DocumentSchema.NO_SCHEMA_CONSTRAINTS,
            doc.asOperation()).isValid()) {
          throw new RuntimeException("doc not valid");
        }
      }
    }
  }
View Full Code Here

  /**
   * Stand-alone main() for quick experimentation.
   */
  public static void main(String[] args) throws OperationException {
    BootstrapDocument initialDoc = new BootstrapDocument();
    initialDoc.consume(new DocInitializationBuilder()
        .elementStart("blip", Attributes.EMPTY_MAP)
        .elementStart("p", Attributes.EMPTY_MAP)
        .characters("abc")
        .elementEnd()
        .elementEnd().build());

    Parameters p = new Parameters();

    p.setMaxOpeningComponents(10);

    RandomProvider r = RandomProviderImpl.ofSeed(2538);
    for (int i = 0; i < 200; i++) {
      BootstrapDocument doc = new BootstrapDocument();
      doc.consume(initialDoc.asOperation());
      for (int j = 0; j < 20; j++) {
        System.err.println("i=" + i + ", j=" + j);
        System.err.println("old: " + DocOpUtil.toXmlString(doc.asOperation()));
        System.err.println("old: " + DocOpUtil.toConciseString(doc.asOperation()));
        DocOp op = generate(r, p, doc);
        System.err.println("op:  " + DocOpUtil.toConciseString(op));
        doc.consume(op);
        System.err.println("new: " + DocOpUtil.toConciseString(doc.asOperation()));
        System.err.println("new: " + DocOpUtil.toXmlString(doc.asOperation()));
        if (!DocOpValidator.validate(null, DocumentSchema.NO_SCHEMA_CONSTRAINTS,
            doc.asOperation()).isValid()) {
          throw new RuntimeException("doc not valid");
        }
      }
    }
  }
View Full Code Here

TOP

Related Classes of org.waveprotocol.wave.model.document.bootstrap.BootstrapDocument$Item

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.