Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4185460

Container list the indentation is 2x the indent param value

XMLWordPrintable

    • hopper
    • sparc
    • solaris_2.5, solaris_2.6
    • Verified

      In Container list method the first line of output is indented 2 times the
      value of the indent parameter. This is an unexpected result. The 1st line
      of output should be printed with indent number of spaces.

      Sample output:
      Indent set at: 10
      Indent return: 20
                          java.awt.Frame[frame3,0,0,0x0,invalid,hidden,layout=java.awt.BorderLayout,resizable,title=]
                            java.awt.Button[button15,0,0,0x0,invalid,label=North]
                            java.awt.Button[button16,0,0,0x0,invalid,label=South]
                            java.awt.Button[button17,0,0,0x0,invalid,label=East]
                            java.awt.Button[button18,0,0,0x0,invalid,label=West]
                            java.awt.Button[button19,0,0,0x0,invalid,label=Center]


      /*
       * @(#)listTest.java
       * @author Mike Colburn
       * @version 1.0
       *
       * java.awt Container list method tests
       */

      import java.awt.*;
      import java.io.*;
      import java.util.Vector;

      /**
       * Method: awt.Container.list
       * <p>Syntax: public void list(PrintStream out, int indent)
       * public void list(PrintWriter outwriter, int indent)
       * <p>Param: out a print stream
       * <p>Param: outwriter a print writer
       * <p>Param: indent the number of spaces to indent
       * <p>Pupose: Prints a listing of this container, starting at the specified
       * indention, to the specified output {stream, writer}.
       * <p>Test: These tests check if the list method works correctly.
       */
       
      public class listTest {
        
        public static void main(String[] args) {
          
          boolean bReturn = false;
          int iCompCount = 0;
          int iNotEqual = 0;
          int iIndentWrong = 0;
          System.out.println("Test: Check indentation");
          Vector v = new Vector();
          String sLine;
          String sReturn;
          String sExpTrim;
          Button b1, b2, b3, b4, b5;
          
          try {
            Frame f = new Frame();
                   
            f.add(b1 = new Button("North"), BorderLayout.NORTH, 0);
            f.add(b2 = new Button("South"), BorderLayout.SOUTH, 1);
            f.add(b3 = new Button("East"), BorderLayout.EAST, 2);
            f.add(b4 = new Button("West"), BorderLayout.WEST, 3);
            f.add(b5 = new Button("Center"), BorderLayout.CENTER, -1);
          
            String[] sExpected = {f.toString(), b1.toString(), b2.toString(),
           b3.toString(), b4.toString(), b5.toString()};
          
            iCompCount = f.getComponentCount();
            System.out.println("Component count: " + iCompCount);
          
            for (int j = 0; j <= 10; j++) {
            
             PipedInputStream pin = new PipedInputStream();
             PrintStream output = new PrintStream(new PipedOutputStream(pin), true);
             BufferedReader input = new BufferedReader(new InputStreamReader(pin));
                      
             f.list(output, j);
          
             output.flush();
             output.close();
         
             while ((sLine = input.readLine()) != null) {
           v.addElement(sLine);
             }
            
             for (int i = 0; i < v.size(); i++) {
             sReturn = (String)v.elementAt(i);
             sExpTrim = sExpected[i].trim();
           
            if ( !(sExpTrim.equals(sReturn.trim())) ) {
           ++iNotEqual;
           }
          
           int iSpace = sReturn.lastIndexOf(' ') + 1;
          
           if ( i == 0 ) {
           System.out.println("Indent set at: " + j);
           System.out.println("Indent return: " + iSpace);
           if (iSpace != j) {
           ++iIndentWrong;
           }
           } else {
           if ( iSpace != (j+2) ) {
           ++iIndentWrong;
           }
           }
           System.out.println(sReturn);
             }
             v.removeAllElements();
             v.trimToSize();
            
            } // end for
            
            if ( iNotEqual == 0 && iIndentWrong == 0 ) {
           bReturn = true;
            } else {
             bReturn = false;
            }
          
          } catch(IOException e) {
           bReturn = false;
          System.out.println ("Unexpected Exception thrown");
             e.printStackTrace();
          }
       
          // check if test passed
          if ( bReturn ) {
            System.out.println("Test for Container.list Passed");
          } else {
            System.out.println("Test for Container.list Failed");
          }
        
        }
        
      } // end listTest

            son Oleg Sukhodolsky (Inactive)
            mcolburnsunw Michael Colburn (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: