Exemplo n.º 1
0
 public static void simulate(String fname) throws FileNotFoundException, IOException {
   AdaptedSplitPaneDividerDemo.main();
   AdaptedSplitPaneDividerDemo current = AdaptedSplitPaneDividerDemo.getSplitPaneDividerDemo();
   SwingEventHandler handler = SanityChecker.getEventHandler(current);
   InputStream is = new FileInputStream(fname);
   BufferedReader br = new BufferedReader(new InputStreamReader(is));
   String line = br.readLine();
   while (line != null) {
     handler.handleEvent(line);
     line = br.readLine();
   }
 }
  public void testCheckRecordOrder() {
    final SanityChecker c = new SanityChecker();
    List<Record> records = new ArrayList<Record>();
    records.add(new BOFRecord());
    records.add(INTERFACEHDR);
    records.add(createBoundSheetRec());
    records.add(EOFRecord.instance);
    CheckRecord[] check = {
      new CheckRecord(BOFRecord.class, '1'),
      new CheckRecord(InterfaceHdrRecord.class, '0'),
      new CheckRecord(BoundSheetRecord.class, 'M'),
      new CheckRecord(NameRecord.class, '*'),
      new CheckRecord(EOFRecord.class, '1'),
    };
    // check pass
    c.checkRecordOrder(records, check);
    records.add(2, createBoundSheetRec());
    c.checkRecordOrder(records, check);
    records.remove(1); // optional record missing
    c.checkRecordOrder(records, check);
    records.add(3, new NameRecord());
    records.add(3, new NameRecord()); // optional multiple record occurs more than one time
    c.checkRecordOrder(records, check);

    // check fail
    confirmBadRecordOrder(
        check,
        new Record[] {
          new BOFRecord(), createBoundSheetRec(), INTERFACEHDR, EOFRecord.instance,
        });

    confirmBadRecordOrder(
        check,
        new Record[] {
          new BOFRecord(), INTERFACEHDR, createBoundSheetRec(), INTERFACEHDR, EOFRecord.instance,
        });

    confirmBadRecordOrder(
        check,
        new Record[] {
          new BOFRecord(),
          createBoundSheetRec(),
          new NameRecord(),
          EOFRecord.instance,
          new NameRecord(),
        });

    confirmBadRecordOrder(
        check,
        new Record[] {
          INTERFACEHDR, createBoundSheetRec(), EOFRecord.instance,
        });

    confirmBadRecordOrder(
        check,
        new Record[] {
          new BOFRecord(), INTERFACEHDR, EOFRecord.instance,
        });

    confirmBadRecordOrder(
        check,
        new Record[] {
          INTERFACEHDR, createBoundSheetRec(), new BOFRecord(), EOFRecord.instance,
        });

    confirmBadRecordOrder(
        check,
        new Record[] {
          new BOFRecord(), createBoundSheetRec(), INTERFACEHDR, EOFRecord.instance,
        });
  }