directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fel...@apache.org
Subject svn commit: r1036636 - in /directory/apacheds/trunk/kerberos-shared/src: main/java/org/apache/directory/server/kerberos/shared/messages/value/flags/ test/java/org/apache/directory/server/kerberos/shared/messages/value/flags/
Date Thu, 18 Nov 2010 21:17:10 GMT
Author: felixk
Date: Thu Nov 18 21:17:09 2010
New Revision: 1036636

URL: http://svn.apache.org/viewvc?rev=1036636&view=rev
Log:
Fix variable switch, add test case

Added:
    directory/apacheds/trunk/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/flags/
    directory/apacheds/trunk/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/flags/AbstractKerberosFlagsTest.java
  (with props)
Modified:
    directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/flags/AbstractKerberosFlags.java

Modified: directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/flags/AbstractKerberosFlags.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/flags/AbstractKerberosFlags.java?rev=1036636&r1=1036635&r2=1036636&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/flags/AbstractKerberosFlags.java
(original)
+++ directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/messages/value/flags/AbstractKerberosFlags.java
Thu Nov 18 21:17:09 2010
@@ -61,17 +61,17 @@ public abstract class AbstractKerberosFl
     
     
     /**
-     * A static method to get the bayte array representation of an int
+     * A static method to get the byte array representation of an int
      * @return The byte array for a list of flags.
      */
     public static byte[] getBytes( int flags )
     {
         return new byte[]{
-                (byte)( flags >>> 24), 
-                (byte)( ( flags >> 16 ) & 0x00ff ), 
-                (byte)( ( flags >> 8 ) & 0x00ff ), 
-                (byte)( flags & 0x00ff ) };
-    }
+            (byte)( flags >>> 24), 
+            (byte)( ( flags >> 16 ) & 0x00ff ), 
+            (byte)( ( flags >> 8 ) & 0x00ff ), 
+            (byte)( flags & 0x00ff ) };
+}
     
     
     /**
@@ -123,7 +123,7 @@ public abstract class AbstractKerberosFl
      */
     public boolean isFlagSet( int flag )
     {
-        return ( flag & ( 1 << value ) ) != 0;
+        return ( value & ( 1 << flag ) ) != 0;
     }
     
     

Added: directory/apacheds/trunk/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/flags/AbstractKerberosFlagsTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/flags/AbstractKerberosFlagsTest.java?rev=1036636&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/flags/AbstractKerberosFlagsTest.java
(added)
+++ directory/apacheds/trunk/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/flags/AbstractKerberosFlagsTest.java
Thu Nov 18 21:17:09 2010
@@ -0,0 +1,93 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.server.kerberos.shared.messages.value.flags;
+
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Before;
+import org.junit.Test;
+
+
+/**
+ * Test for AbstractKerberosFlags
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AbstractKerberosFlagsTest
+{
+
+    AbstractKerberosFlags akf;
+
+
+    @Before
+    public void setUp() throws Exception
+    {
+        akf = new AbstractKerberosFlags()
+        {
+            private static final long serialVersionUID = 1L;
+        };
+    }
+
+
+    @Test
+    public void testFlags()
+    {
+        // MAX_VALUE is not a real ticket flag and will cause an Out Of Bounds Exception,
+        // so skip this
+        TicketFlag[] ticketFlags = new TicketFlag[TicketFlag.values().length - 1];
+        int i = 0;
+        for ( TicketFlag tf : TicketFlag.values() )
+        {
+            if ( !tf.equals( TicketFlag.MAX_VALUE ) )
+            {
+                ticketFlags[i] = tf;
+            }
+            i++;
+        }
+
+        boolean setFlag = true;
+        for ( TicketFlag ticketFlag : ticketFlags )
+        {
+            // Only set every 2nd ticket flag
+            if ( setFlag )
+            {
+                akf.setFlag( ticketFlag.getOrdinal() );
+            }
+            setFlag = !setFlag;
+        }
+
+        setFlag = true;
+        for ( TicketFlag ticketFlag : ticketFlags )
+        {
+            // Only every 2nd ticket flag is set
+            if ( setFlag )
+            {
+                assertTrue( "TicketFlag: " + ticketFlag.toString(), akf.isFlagSet( ticketFlag
) );
+            }
+            else
+            {
+                assertFalse( "TicketFlag: " + ticketFlag.toString(), akf.isFlagSet( ticketFlag
) );
+            }
+            setFlag = !setFlag;
+        }
+    }
+}

Propchange: directory/apacheds/trunk/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/flags/AbstractKerberosFlagsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message