@Test()
  public void testURLInvocation_doctype_FEATURE_PROCESS_DOCDECL() throws Exception {

    SimpleClient http = new SimpleClient();

    // reset the counter
    http.sendGet(_URL_ + "/reset");
    String response = http.sendGet(_URL_ + "/getCounter");
    assertEquals("0", response);

    String xmlFile = "data/data/de.rub.nds.parsers/url_invocation_doctype.xml";

    String name;
    String value;
    int event;

    factory = XmlPullParserFactory.newInstance();
    factory.setFeature(XmlPullParser.FEATURE_PROCESS_DOCDECL, true);
    parser = factory.newPullParser();
    InputStream xmlInput = new FileInputStream(xmlFile);
    parser.setInput(xmlInput, "UTF-8");

    int token = parser.nextToken();
    int i = 0;

    //          parse the entire Document
    while (token != XmlPullParser.END_DOCUMENT) {
      token = parser.nextToken();
      i++;
    }

    response = http.sendGet(_URL_ + "/getCounter");
    assertEquals("0", response);
  }
  /**
   * @throws FileNotFoundException
   * @throws XmlPullParserException
   * @throws XmlPullParserException: This parser doesn't support parameter entities
   *     (position:DOCDECL @4:15 in java.io.InputStreamReader@ec20ff4)
   */
  @Test(expected = XmlPullParserException.class)
  public void testDOS_indirections_parameterEntity_FEATURE_PROCESS_DOCDECL()
      throws FileNotFoundException, XmlPullParserException, IOException {

    String xmlFile = "data/data/de.rub.nds.parsers/dos_indirections_parameterEntity.xml";

    String name;
    String value;
    int event;

    factory = XmlPullParserFactory.newInstance();
    factory.setFeature(XmlPullParser.FEATURE_PROCESS_DOCDECL, true);
    parser = factory.newPullParser();

    InputStream xmlInput = new FileInputStream(xmlFile);
    parser.setInput(xmlInput, "UTF-8");

    int token = parser.nextToken();
    name = parser.getName();
    value = parser.getText();
    event = parser.getEventType();
    assertEquals(10, event);

    parser.nextToken(); // IGNORABLE_WHITESPACE - this call is necessary in order to trigger the
    // exception.
    name = parser.getName();
    value = parser.getText();
    event = parser.getEventType();
    assertEquals(7, event);
  }
  @Test
  public void testParameterEntity_doctype_FEATURE_PROCESS_DOCDECL()
      throws FileNotFoundException, XmlPullParserException, IOException {

    String xmlFile = "data/data/de.rub.nds.parsers/parameterEntity_doctype.xml";

    String name;
    String value;
    int event;

    factory = XmlPullParserFactory.newInstance();
    factory.setFeature(XmlPullParser.FEATURE_PROCESS_DOCDECL, true);
    parser = factory.newPullParser();
    InputStream xmlInput = new FileInputStream(xmlFile);
    parser.setInput(xmlInput, "UTF-8");

    parser.nextToken();
    name = parser.getName();
    value = parser.getText();
    event = parser.getEventType();
    assertEquals(10, event);

    parser.nextToken();
    name = parser.getName();
    value = parser.getText();
    event = parser.getEventType();
    assertEquals(7, event);

    parser.nextToken();
    name = parser.getName();
    value = parser.getText();
    event = parser.getEventType();
    assertEquals(2, event);
    assertEquals("data", name);

    parser.nextToken();
    name = parser.getName();
    value = parser.getText();
    event = parser.getEventType();
    assertEquals(6, event);
    assertEquals("all", name);

    // make sure that the external subset has not been fetched and the entity not been resolved due
    // to the feature
    parser.nextToken();
    name = parser.getName();
    value = parser.getText();
    event = parser.getEventType();
    assertEquals(3, event); // End Tag
  }
Exemple #4
0
 protected void setUp() throws XmlPullParserException {
   factory = factoryNewInstance();
   factory.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
   assertEquals(true, factory.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
 }
  @Test
  public void testDOS_recursion_FEATURE_PROCESS_DOCDECL()
      throws FileNotFoundException, XmlPullParserException, IOException {

    String xmlFile = "data/data/de.rub.nds.parsers/dos_recursion.xml";

    String name;
    String value;
    int event;

    factory = XmlPullParserFactory.newInstance();
    factory.setFeature(XmlPullParser.FEATURE_PROCESS_DOCDECL, true);
    parser = factory.newPullParser();
    InputStream xmlInput = new FileInputStream(xmlFile);
    parser.setInput(xmlInput, "UTF-8");

    parser.nextToken(); // Document Type Declaration
    name = parser.getName();
    value = parser.getText();
    event = parser.getEventType();
    assertEquals(10, event);

    parser.nextToken(); // IGNORABLE_WHITESPACE
    name = parser.getName();
    value = parser.getText();
    event = parser.getEventType();
    assertEquals(7, event);

    parser.nextToken(); // element
    name = parser.getName();
    value = parser.getText(); // not used here
    event = parser.getEventType();
    assertEquals("data", name);
    assertEquals(2, event);

    // the parser resolves the first entity reference
    parser.nextToken(); // the content of the element
    name = parser.getName();
    value = parser.getText();
    event = parser.getEventType();
    assertEquals(6, event);
    assertEquals("", value);
    assertEquals("a", name);

    // the first part of the reference is the replacement text "a"
    parser.nextToken();
    name = parser.getName();
    value = parser.getText();
    event = parser.getEventType();
    assertEquals(4, event);
    assertEquals("a", value);
    assertEquals(null, name);

    // the second part is a reference to the entity "b"
    parser.nextToken();
    name = parser.getName();
    value = parser.getText();
    event = parser.getEventType();
    assertEquals(6, event);
    assertEquals("", value);
    assertEquals("b", name);

    // resolve entity b: it's a reference to the entity "a"
    parser.nextToken();
    name = parser.getName();
    value = parser.getText();
    event = parser.getEventType();
    assertEquals(6, event);
    assertEquals("", value);
    assertEquals("a", name);

    // the first part of the reference is the replacement text "a"
    parser.nextToken();
    name = parser.getName();
    value = parser.getText();
    event = parser.getEventType();
    assertEquals(4, event);
    assertEquals("a", value);
    assertEquals(null, name);

    // and so on...

    // use this code to verify
    //        int token = parser.nextToken();
    //        int i = 0;
    //
    //        Log.d("recursion", "Name " + parser.getName());
    //        Log.d("recursion", "Text " + parser.getText());
    //        Log.d("recursion", "Event " + parser.getEventType());
    //        Log.d("recursion", "----------------------");
    //
    //            while (token != XmlPullParser.END_DOCUMENT) {
    //                Log.d("recursion", Integer.toString(i));
    //                Log.d("recursion", "Name " + parser.getName());
    //                Log.d("recursion", "Text " + parser.getText());
    //                Log.d("recursion", "Event " + parser.getEventType());
    //                Log.d("recursion", "----------------------");
    //                token =             parser.nextToken();
    //                i++;
    //            }
  }
  @Test
  public void testDOS_indirections_FEATURE_PROCESS_DOCDECL()
      throws FileNotFoundException, XmlPullParserException, IOException {

    String xmlFile = "data/data/de.rub.nds.parsers/dos_indirections.xml";

    String name;
    String value;
    int event;

    factory = XmlPullParserFactory.newInstance();
    factory.setFeature(XmlPullParser.FEATURE_PROCESS_DOCDECL, true);
    parser = factory.newPullParser();

    InputStream xmlInput = new FileInputStream(xmlFile);
    parser.setInput(xmlInput, "UTF-8");

    int token = parser.nextToken();
    name = parser.getName();
    value = parser.getText();
    event = parser.getEventType();
    assertEquals(10, event);

    parser.nextToken();
    name = parser.getName();
    value = parser.getText();
    event = parser.getEventType();
    assertEquals(7, event);

    parser.nextToken();
    name = parser.getName();
    value = parser.getText();
    event = parser.getEventType();

    assertEquals(2, event);
    assertEquals("data", name);

    parser.nextToken();
    name = parser.getName();
    value = parser.getText();
    event = parser.getEventType();

    assertEquals("a4", name);
    assertEquals("", value);
    assertEquals(6, event);

    String content = "";
    int i = 0;

    // construct the entity replacement text
    while (token != XmlPullParser.END_TAG) {

      if (parser.getEventType() == 4) {
        content += parser.getText();
      }
      token = parser.nextToken();
      i++;
    }

    int expectedCount = 10000;
    // we know that each word is 3 chars long
    int dosCount = content.length() / 3;
    assertEquals(expectedCount, dosCount);
  }
  @Test(expected = OutOfMemoryError.class)
  /**
   * java.lang.OutOfMemoryError: Failed to allocate a 10200016 byte allocation with 4194304 free
   * bytes and 8MB until OOM
   */
  public void testDOS_entitySize_FEATURE_PROCESS_DOCDECL()
      throws FileNotFoundException, XmlPullParserException, IOException {

    String xmlFile = "data/data/de.rub.nds.parsers/dos_entitySize.xml";

    String name;
    String value;
    int event;

    factory = XmlPullParserFactory.newInstance();
    factory.setFeature(XmlPullParser.FEATURE_PROCESS_DOCDECL, true);
    parser = factory.newPullParser();

    InputStream xmlInput = new FileInputStream(xmlFile);
    parser.setInput(xmlInput, "UTF-8");

    int token = parser.nextToken();
    name = parser.getName();
    value = parser.getText();
    event = parser.getEventType();
    assertEquals(10, event);

    parser.nextToken();
    name = parser.getName();
    value = parser.getText();
    event = parser.getEventType();
    assertEquals(7, event);

    parser.nextToken();
    name = parser.getName();
    value = parser.getText();
    event = parser.getEventType();

    assertEquals(2, event);
    assertEquals("data", name);

    parser.nextToken();
    name = parser.getName();
    value = parser.getText();
    event = parser.getEventType();

    assertEquals("a0", name);
    assertEquals("", value);
    assertEquals(6, event);

    String content = "";
    int i = 0;

    // construct the entity replacement text
    while (token != XmlPullParser.END_TAG) {

      if (parser.getEventType() == 4) {
        content += parser.getText();
      }
      token = parser.nextToken();
      i++;
    }
    //
    //        int expectedCount = 25;
    //        // we know that each word is 3 chars long
    //        int dosCount = content.length() / 3;
    //        assertEquals(expectedCount, dosCount);

  }