OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libjava/] [classpath/] [test/] [java.io/] [LineNumberInputStreamTest.java] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
/*************************************************************************
2
/* LineNumberInputStreamTest.java -- Tests LineNumberInputStream's
3
/*
4
/* Copyright (c) 1998 Free Software Foundation, Inc.
5
/* Written by Aaron M. Renn (arenn@urbanophile.com)
6
/*
7
/* This program is free software; you can redistribute it and/or modify
8
/* it under the terms of the GNU General Public License as published
9
/* by the Free Software Foundation, either version 2 of the License, or
10
/* (at your option) any later version.
11
/*
12
/* This program is distributed in the hope that it will be useful, but
13
/* WITHOUT ANY WARRANTY; without even the implied warranty of
14
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
/* GNU General Public License for more details.
16
/*
17
/* You should have received a copy of the GNU General Public License
18
/* along with this program; if not, write to the Free Software Foundation
19
/* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
20
/*************************************************************************/
21
 
22
import java.io.*;
23
 
24
public class LineNumberInputStreamTest
25
{
26
 
27
public static void
28
main(String[] argv)
29
{
30
  System.out.println("Started test of LineNumberInputStream");
31
 
32
  try
33
    {
34
      System.out.println("Test 1: First test series");
35
 
36
      boolean passed = true;
37
 
38
      String str = "I grew up by a small town called Laconia, Indiana\r" +
39
         "which has a population of about 64 people.  But I didn't live\r\n" +
40
         "in town.  I lived on a gravel road about 4 miles away\n" +
41
         "They paved that road\n";
42
 
43
      StringBufferInputStream sbis = new StringBufferInputStream(str);
44
      LineNumberInputStream lnis = new LineNumberInputStream(sbis);
45
 
46
      lnis.setLineNumber(2);
47
 
48
      byte[] buf = new byte[32];
49
      int bytes_read;
50
      while ((bytes_read = lnis.read(buf)) != -1)
51
        {
52
          str = new String(buf, 0, bytes_read);
53
          if (str.indexOf("\r") != -1)
54
            {
55
              passed = false;
56
              System.out.println("\nFound an unexpected \\r\n");
57
            }
58
 
59
          System.out.print(str);
60
        }
61
 
62
      if (lnis.getLineNumber() != 6)
63
        {
64
          passed = false;
65
          System.out.println("Line number was wrong.  Expected 6 but got " +
66
            lnis.getLineNumber());
67
        }
68
 
69
      if (passed)
70
        System.out.println("PASSED: First test series");
71
      else
72
        System.out.println("FAILED: First test series");
73
    }
74
  catch(IOException e)
75
    {
76
      System.out.println("FAILED: First test series: " + e);
77
    }
78
 
79
  try
80
    {
81
      System.out.println("Test 2: Second test series");
82
 
83
      boolean passed = true;
84
 
85
      String str = "One time I was playing kickball on the playground\n" +
86
         "in 4th grade and my friends kept talking about how they smelled\n" +
87
         "pot.  I kept asking them what they smelled because I couldn't\n" +
88
         "figure out how a pot could have a smell";
89
 
90
      StringBufferInputStream sbis = new StringBufferInputStream(str);
91
      LineNumberInputStream lnis = new LineNumberInputStream(sbis);
92
 
93
      byte[] buf = new byte[32];
94
      int bytes_read;
95
      while ((bytes_read = lnis.read(buf)) != -1)
96
        System.out.print(new String(buf, 0, bytes_read));
97
 
98
      if (lnis.getLineNumber() != 3)
99
        {
100
          passed = false;
101
          System.out.println("\nLine number was wrong.  Expected 3 but got " +
102
            lnis.getLineNumber());
103
        }
104
 
105
      if (passed)
106
        System.out.println("PASSED: Second test series");
107
      else
108
        System.out.println("FAILED: Second test series");
109
    }
110
  catch(IOException e)
111
    {
112
      System.out.println("FAILED: Second test series: " + e);
113
    }
114
 
115
  System.out.println("Finished test of LineNumberInputStream");
116
}
117
 
118
} // class LineNumberInputStreamTest
119
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.