File: Torture1.java

package info (click to toggle)
jcifs 1.3.16-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 2,856 kB
  • sloc: java: 23,124; xml: 3,663; ansic: 386; sh: 170; makefile: 26
file content (102 lines) | stat: -rw-r--r-- 2,974 bytes parent folder | download | duplicates (8)
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
99
100
101
102
import java.io.*;
import jcifs.smb.*;
import java.util.*;

class Worker extends Thread {

    Torture1 t;
    Exception e;

    Worker( Torture1 t ) {
        this.t = t;
        e = null;
    }
    public void run() {
        try {
            t.torture();
        } catch( Exception e ) {
            this.e = e;
        }
    }
}

public class Torture1 {

    Properties prp;

    Torture1( Properties prp ) {
        this.prp = prp;
    }

    void compare( SmbFile f1, SmbFile f2 ) throws Exception {
        if( f1.isDirectory() && f2.isDirectory() ) {
            SmbFile[] dirents = f1.listFiles();
            SmbFile f;
            for( int i = 0; i < dirents.length; i++ ) {
                f = new SmbFile( f2, dirents[i].getName() );
                compare( dirents[i], f );
            }
        }
        if( f1.isDirectory() != f2.isDirectory() ) {
            System.err.println( "directory comparison failed" );
        }
        if( f1.isFile() != f2.isFile() ) {
            System.err.println( "file comparison failed" );
        }
        if( f1.getType() != f2.getType() ) {
            System.err.println( "type comparison failed" );
        }
        if( f1.getName().equals( f2.getName() ) == false ) {
            System.err.println( "name comparison failed: " + f1.getName() + " " + f2.getName() );
        }
        if( f1.length() != f2.length() ) {
            System.err.println( "length comparison failed: " + f1.length() + " " + f2.length() );
        }
    }

    void torture() throws Exception {
        String domain, username, password, server, share, directory;
        NtlmPasswordAuthentication ntlm;

        domain = prp.getProperty( "torture.dst.domain" );
        username = prp.getProperty( "torture.dst.username" );
        password = prp.getProperty( "torture.dst.password" );

        ntlm = new NtlmPasswordAuthentication( domain, username, password );

        server = prp.getProperty( "torture.dst.server" );
        share = prp.getProperty( "torture.dst.share" );
        directory = prp.getProperty( "torture.dst.directory" );

        SmbFile dst = new SmbFile( "smb://", ntlm );
        dst = new SmbFile( dst, server );
        dst = new SmbFile( dst, share );
        dst = new SmbFile( dst, directory );

        SmbFile src = new SmbFile( prp.getProperty( "torture.src.url" ));

System.err.println( src + " --> " + dst );
System.in.read();

        if( dst.exists() ) {
            dst.delete();
        }
        src.copyTo( dst );
System.err.println( "CopyTo done" );
System.in.read();
        compare( src, dst );
System.err.println( "Test Complete" );
    }

    public static void main( String[] argv ) throws Exception {
        Properties prp = new Properties();
        prp.load( new FileInputStream( "torture.prp" ));
        Torture1 t = new Torture1( prp );
        Worker w = new Worker( t );
        w.start();
        w.join();
        if( w.e != null ) {
            throw w.e;
        }
    }
}