View Javadoc
1   package org.codehaus.plexus.components.io.attributes;
2   
3   /*
4    * Copyright 2007 The Codehaus Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import junit.framework.TestCase;
20  
21  public abstract class AbstractResourceAttributesTCK
22      extends TestCase
23  {
24      
25      protected AbstractResourceAttributesTCK()
26      {
27      }
28      
29      protected abstract PlexusIoResourceAttributes newAttributes( int mode );
30  
31      protected abstract PlexusIoResourceAttributes newAttributes( String mode );
32  
33  
34      public final void testSetOctalModeString_OwnerModes()
35      {
36          verifyStringOctalModeSet( "700", new boolean[] { true, true, true, false, false, false, false, false, false } );
37          verifyStringOctalModeSet( "600", new boolean[] { true, true, false, false, false, false, false, false, false } );
38          verifyStringOctalModeSet( "400", new boolean[] { true, false, false, false, false, false, false, false, false } );
39          verifyStringOctalModeSet( "200", new boolean[] { false, true, false, false, false, false, false, false, false } );
40      }
41  
42      public final void testSetOctalModeString_GroupModes()
43      {
44          verifyStringOctalModeSet( "070", new boolean[] { false, false, false, true, true, true, false, false, false } );
45          verifyStringOctalModeSet( "060", new boolean[] { false, false, false, true, true, false, false, false, false } );
46          verifyStringOctalModeSet( "040", new boolean[] { false, false, false, true, false, false, false, false, false } );
47          verifyStringOctalModeSet( "020", new boolean[] { false, false, false, false, true, false, false, false, false } );
48      }
49  
50      public final void testSetOctalModeString_WorldModes()
51      {
52          verifyStringOctalModeSet( "007", new boolean[] { false, false, false, false, false, false, true, true, true } );
53          verifyStringOctalModeSet( "006", new boolean[] { false, false, false, false, false, false, true, true, false } );
54          verifyStringOctalModeSet( "004", new boolean[] { false, false, false, false, false, false, true, false, false } );
55          verifyStringOctalModeSet( "002", new boolean[] { false, false, false, false, false, false, false, true, false } );
56      }
57  
58      public final void testSetOctalMode_OwnerModes()
59      {
60          verifyOctalModeSet( "700", new boolean[] { true, true, true, false, false, false, false, false, false } );
61          verifyOctalModeSet( "600", new boolean[] { true, true, false, false, false, false, false, false, false } );
62          verifyOctalModeSet( "400", new boolean[] { true, false, false, false, false, false, false, false, false } );
63          verifyOctalModeSet( "200", new boolean[] { false, true, false, false, false, false, false, false, false } );
64      }
65  
66      public final void testSetOctalMode_GroupModes()
67      {
68          verifyOctalModeSet( "070", new boolean[] { false, false, false, true, true, true, false, false, false } );
69          verifyOctalModeSet( "060", new boolean[] { false, false, false, true, true, false, false, false, false } );
70          verifyOctalModeSet( "040", new boolean[] { false, false, false, true, false, false, false, false, false } );
71          verifyOctalModeSet( "020", new boolean[] { false, false, false, false, true, false, false, false, false } );
72      }
73  
74      public final void testSetOctalMode_WorldModes()
75      {
76          verifyOctalModeSet( "007", new boolean[] { false, false, false, false, false, false, true, true, true } );
77          verifyOctalModeSet( "006", new boolean[] { false, false, false, false, false, false, true, true, false } );
78          verifyOctalModeSet( "004", new boolean[] { false, false, false, false, false, false, true, false, false } );
79          verifyOctalModeSet( "002", new boolean[] { false, false, false, false, false, false, false, true, false } );
80      }
81  
82      private void verifyStringOctalModeSet( String mode, boolean[] checkValues )
83      {
84          PlexusIoResourceAttributes attrs = newAttributes( Integer.parseInt( mode, 8 ) );
85  
86          assertEquals( checkValues[0], attrs.isOwnerReadable() );
87          assertEquals( checkValues[1], attrs.isOwnerWritable() );
88          assertEquals( checkValues[2], attrs.isOwnerExecutable() );
89  
90          assertEquals( checkValues[3], attrs.isGroupReadable() );
91          assertEquals( checkValues[4], attrs.isGroupWritable() );
92          assertEquals( checkValues[5], attrs.isGroupExecutable() );
93  
94          assertEquals( checkValues[6], attrs.isWorldReadable() );
95          assertEquals( checkValues[7], attrs.isWorldWritable() );
96          assertEquals( checkValues[8], attrs.isWorldExecutable() );
97      }
98  
99      private void verifyOctalModeSet( String mode, boolean[] checkValues )
100     {
101         PlexusIoResourceAttributes attrs = newAttributes( Integer.parseInt( mode, 8 ) );
102 
103         assertEquals( checkValues[0], attrs.isOwnerReadable() );
104         assertEquals( checkValues[1], attrs.isOwnerWritable() );
105         assertEquals( checkValues[2], attrs.isOwnerExecutable() );
106 
107         assertEquals( checkValues[3], attrs.isGroupReadable() );
108         assertEquals( checkValues[4], attrs.isGroupWritable() );
109         assertEquals( checkValues[5], attrs.isGroupExecutable() );
110 
111         assertEquals( checkValues[6], attrs.isWorldReadable() );
112         assertEquals( checkValues[7], attrs.isWorldWritable() );
113         assertEquals( checkValues[8], attrs.isWorldExecutable() );
114     }
115 
116 }