Subversion Repository Public Repository

litesoft

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
package com.esotericsoftware.utils;

import java.io.*;

import org.junit.*;

import static org.junit.Assert.*;

public class FileTest
{
    @Test
    public void test_FileStuff()
            throws IOException
    {
        if ( Util.isWindows )
        {
            assertAbsolute( "\\\\TheServer\\Fred" );
            assertAbsolute( "\\\\TheServer/Fred" );

            assertRelative( "./Fred" );
            assertRelative( "../Fred" );
            assertRelative( ".\\Fred" );
            assertRelative( "..\\Fred" );

            String zPath = FileUtil.CANONICAL_USER_DIR.getPath();
            System.out.println( "Current User Dir Path: " + zPath );

            assertEquals( zPath, new File( zPath + '\\' ).getCanonicalPath() );

            assertTrue( zPath, (zPath.length() > 1) && (zPath.charAt( 1 ) == ':') );

            char zDriveLetter = zPath.charAt( 0 );

            assertTrue( zPath, ('A' <= zDriveLetter) && (zDriveLetter <= 'Z') );

            String zDrivePath = zPath.substring( 0, 2 );

            assertEquals( zPath, new File( zDrivePath ).getCanonicalPath() ); // Just Our Drive Letter is equivalent to "."

            assertRelative( zDrivePath ); // Just Our Drive Letter is equivalent to "."

            assertTrue( new File( zDrivePath ).exists() );

            String zOtherDrivePath = "" + findNonExistingDriveLetter() + ':';
            System.out.println( "The Other Drive Path is " + zOtherDrivePath );

            assertAbsolute( zOtherDrivePath + "\\Fred" );
            assertAbsolute( zOtherDrivePath + "/Fred" );

            // *** All of the following are: *** What the F!!! ***

            assertRelative( zOtherDrivePath ); // Just the Other Drive Letter is equivalent to "."

            assertRelative( zOtherDrivePath + ".\\Fred" );
            assertRelative( zOtherDrivePath + "..\\Fred" );
            assertRelative( zOtherDrivePath + "./Fred" );
            assertRelative( zOtherDrivePath + "../Fred" );

            assertRelative( "\\Fred" );
            assertRelative( "/Fred" );
        }
    }

    private void assertAbsolute( String pPath )
    {
        assertTrue( "!Absolute?: " + pPath, new File( pPath ).isAbsolute() );
    }

    private void assertRelative( String pPath )
    {
        assertFalse( "!Relative?: " + pPath, new File( pPath ).isAbsolute() );
    }

    private char findNonExistingDriveLetter()
    {
        for ( int i = 'Z'; 'A' <= i; i-- )
        {
            if ( !new File( "" + ((char) i) + ':' ).exists() )
            {
                return (char) i;
            }
        }
        throw new IllegalStateException( "All Drive Letters Exist!" );
    }
}

Commits for litesoft/trunk/Java/ScarPlus/test/com/esotericsoftware/utils/FileTest.java

Diff revisions: vs.
Revision Author Commited Message
315 Diff Diff GeorgeS picture GeorgeS Sun 17 Jul, 2011 15:48:36 +0000
307 GeorgeS picture GeorgeS Sun 10 Jul, 2011 01:43:51 +0000