File: basic.java

package info (click to toggle)
mauve 20080616-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 26,856 kB
  • ctags: 21,952
  • sloc: java: 234,107; sh: 2,834; xml: 208; makefile: 59
file content (98 lines) | stat: -rw-r--r-- 3,250 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Tags: JDK1.1

// Copyright (C) 2003 John Leuner

// This file is part of Mauve.

// Mauve is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or (at your option)
// any later version.

// Mauve is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Mauve; see the file COPYING.  If not, write to
// the Free Software Foundation, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.  */

package gnu.testlet.java.util.jar.JarFile;

import gnu.testlet.Testlet;
import gnu.testlet.TestHarness;
import java.util.Enumeration;
import java.util.jar.*;
import java.io.*;

public class basic implements Testlet
{
    public void test_jar(TestHarness harness, JarFile jarfile)
    {
	try {
	harness.checkPoint("manifest tests");
	Manifest m = jarfile.getManifest();

	harness.checkPoint("entries");

	/* I'm not sure if the order of these entries has to be in this order or not. 
	   But it would seem likely that someone will write a program expecting the files to be enumerated the same way every time
	*/

	int item = 0;
	Enumeration e = jarfile.entries();
	while(e.hasMoreElements())
	    {
		JarEntry je = (JarEntry) e.nextElement();
		String n = je.getName();
		String s = new BufferedReader(new InputStreamReader(jarfile.getInputStream(je))).readLine();

		if ("META-INF/".equals(n))
		  harness.check(s == null);
		else if ("META-INF/MANIFEST.MF".equals(n))
		  harness.check(s.equals("Manifest-Version: 1.0"));
		else if ("file1".equals(n))
		  harness.check(s.equals("this jar file was created with the jar tool for IBM JDK 1.3"));
		else if ("file2".equals(n))
		  harness.check(s.equals("We seek peace. We strive for peace. And sometimes peace must be defended. A future lived at the mercy of terrible threats is no peace at all. If war is forced upon us, we will fight in a just cause and by just means -- sparing, in every way we can, the innocent. And if war is forced upon us, we will fight with the full force and might of the United States military -- and we will prevail."));
		else if ("file3".equals(n))
		  harness.check(s.equals("I am he as you are he as you are me and we are all together."));
		else
		  harness.check(false, "Unexpected entry: " + n);

		item++;
	    }

	harness.check(item, 5);

	jarfile.close();

	} catch(IOException e)
	    {
		harness.debug(e);
		harness.check(false, "all jarfile tests failed");
	    }
    }

  public void test (TestHarness harness)
  {
      try
	  {
	      test_jar(harness,
			     new JarFile (harness.getResourceFile("gnu#testlet#java#util#jar#JarFile#jartest.jar")));
	  }
      catch (gnu.testlet.ResourceNotFoundException _)
	  {
	      // FIXME: all tests should fail.
	      harness.check(false, "all basic tests failed");
	  }
      catch (IOException _)
	  {
	      // FIXME: all tests should fail.
	      harness.check(false, "all basic tests failed (ioexception)");
	  }
      
  }
}