• Views
  • Iteration Report
  • My Iteration Report
  •  
OMERO.server
  • Login
  • Help/Guide
  • About Trac
  • Preferences
  • Wiki
  • Timeline
  • Roadmap
  • Browse Source
  • View Tickets
  • Search

Context Navigation

  • ← Previous Change
  • Next Change →

Changeset 1654 for branches/3.0-Beta2/components/romio/test/ome/io/nio/utests/DeltaVisionTest.java

Show
Ignore:
Timestamp:
06/20/07 00:46:03 (18 months ago)
Author:
david
Message:

added serial plane MD5 checks

Files:
1 modified

  • branches/3.0-Beta2/components/romio/test/ome/io/nio/utests/DeltaVisionTest.java (modified) (3 diffs)

Legend:

Unmodified
Added
Removed
  • branches/3.0-Beta2/components/romio/test/ome/io/nio/utests/DeltaVisionTest.java

    r1608 r1654  
    11package ome.io.nio.utests; 
    22 
     3import java.io.DataOutputStream; 
    34import java.io.File; 
     5import java.io.FileOutputStream; 
    46import java.net.URL; 
     7import java.nio.ByteBuffer; 
     8import java.nio.MappedByteBuffer; 
     9import java.security.MessageDigest; 
     10import java.security.NoSuchAlgorithmException; 
    511 
    612import junit.framework.TestCase; 
    713import ome.io.nio.DeltaVision; 
    814import ome.io.nio.DeltaVisionHeader; 
     15import ome.io.nio.DimensionsOutOfBoundsException; 
    916import ome.model.core.OriginalFile; 
    1017import ome.conditions.ResourceError; 
    … …  
    1522import org.testng.annotations.Configuration; 
    1623import org.testng.annotations.Test; 
    17  
    1824 
    1925/** 
    … …  
    3137public class DeltaVisionTest extends TestCase { 
    3238 
    33         private OriginalFile originalFile; 
    34  
    35         private DeltaVision deltaVision; 
    36  
    37         private static int setupCount = 0; 
    38          
    39         private static Log log = LogFactory.getLog(DeltaVisionTest.class); 
    40  
    41         public final static String FILENAME = "tinyTest.d3d.dv"; 
    42          
    43         @Configuration(beforeTestMethod = true) 
    44         protected void setUp() { 
    45  
    46                 setupCount++; 
    47  
    48                 // run this once only 
    49                 if (setupCount == 1) { 
    50  
    51                         // create an OriginalFile object and DeltaVision for testing 
    52                         originalFile = new OriginalFile(); 
    53                         //URL url = getClass().getResource("tinyTest.d3d.dv"); 
    54                         try { 
    55                                 File file = ResourceUtils.getFile("classpath:"+FILENAME); 
    56  
    57                                 //File file = new File(url.toURI()); 
    58                                 originalFile.setPath(file.getCanonicalPath()); 
    59                                 //originalFile.setPath("OMERO/tinyTest.d3d.dv"); 
    60                                 deltaVision = new DeltaVision(originalFile, true); 
    61                                  
    62                         } catch (Exception ex) { 
    63                 log.error("Exception caught, throwing ResourceError", ex.getCause()); 
    64                 throw new ResourceError( 
    65                         ex.getMessage() + " Please check server log."); 
    66                         } 
    67                          
    68                         log.info("Size X = " + deltaVision.getHeader().getSizeX()); 
    69                         log.info("Size Y = " + deltaVision.getHeader().getSizeY()); 
    70                         log.info("Size Z = " + deltaVision.getHeader().getSizeZ()); 
    71                         log.info("Size C = " + deltaVision.getHeader().getSizeC()); 
    72                         log.info("Size T = " + deltaVision.getHeader().getSizeT()); 
    73  
    74                          
    75                          
    76                         log.info(deltaVision.getPath()); 
    77                         log.info("Row size = " + new Integer(deltaVision.getRowSize()).intValue()); 
    78                         log.info("Stack size = " + new Integer(deltaVision.getStackSize()).intValue()); 
    79                         log.info("Plane size = " + new Integer(deltaVision.getPlaneSize()).intValue()); 
    80                          
    81                         log.info("Timepoint size = " + deltaVision.getTimepointSize()); 
    82                         log.info("Total size = " + deltaVision.getTotalSize().toString()); 
    83                          
    84                         log.info("ImageSequence = (should be 0=ZTC) " + deltaVision.getHeader().getSequence()); 
    85  
    86                 } 
    87         } 
    88  
    89         @Configuration(afterTestMethod = true) 
    90         protected void tearDown() { 
    91                 if (setupCount == 12) { 
    92                         originalFile = null; 
    93                         deltaVision = null; 
    94                 } 
    95         } 
    96          
    97         @Test 
    98         public void testGetSizeX() throws Exception { 
    99                 int result = deltaVision.getSizeX(); 
    100                 assertTrue(result == 20); 
    101         } 
    102          
    103         @Test 
    104         public void testGetSizeY() throws Exception { 
    105                 int result = deltaVision.getSizeY(); 
    106                 assertTrue(result == 20); 
    107         } 
    108          
    109         @Test 
    110         public void testGetSizeZ() throws Exception { 
    111                 int result = deltaVision.getSizeZ(); 
    112                 assertTrue(result == 5); 
    113         } 
    114          
    115         @Test 
    116         public void testGetSizeC() throws Exception { 
    117                 int result = deltaVision.getSizeC(); 
    118                 assertTrue(result == 1); 
    119         } 
    120          
    121         @Test 
    122         public void testGetSizeT() throws Exception { 
    123                 int result = deltaVision.getSizeT(); 
    124                 assertTrue(result == 6); 
    125         } 
    126          
    127         @Test 
    128         public void testTotalSize() throws Exception { 
    129                 String result = deltaVision.getTotalSize().toString(); 
    130                 assertTrue(result.equals("24000")); 
    131         } 
    132          
    133         @Test 
    134         public void testTimepointSize() throws Exception { 
    135                 Integer result = deltaVision.getTimepointSize(); 
    136                 assertTrue(result.equals(new Integer(4000))); 
    137         } 
    138  
    139         @Test 
    140         public void testRowSize() throws Exception { 
    141                 Integer result = deltaVision.getRowSize(); 
    142                 assertTrue(result.equals(new Integer(40))); 
    143                  
    144         } 
    145          
    146         @Test 
    147         public void testStackSize() throws Exception { 
    148                 Integer result = deltaVision.getStackSize(); 
    149                 assertTrue(result.equals(new Integer(4000))); 
    150         } 
    151          
    152         @Test 
    153         public void testPlaneSize() throws Exception { 
    154                 Integer result = deltaVision.getPlaneSize(); 
    155                 assertTrue(result.equals(new Integer(800))); 
    156                  
    157         } 
    158          
    159         @Test 
    160         public void testGetPlaneIndex() throws Exception { 
    161                 Long result = deltaVision.getPlaneOffset(2, 0, 3); // (2,0,3) plane 17 ? 
    162                 //log.info("Plane offset = " + result.intValue()); 
    163                 // should be 17 * planeSize=800 = 13600 
    164                 assertTrue(result.equals(new Long(13600))); 
    165         } 
    166          
    167         @Test 
    168         public void testGetStackIndex() throws Exception { 
    169                 Long result = deltaVision.getStackOffset(0, 2); 
    170                 //log.info("Stack offset = " + result.intValue()); 
    171                 // should be 2 * stackSize=4000 = 8000 
    172                 assertTrue(result.equals(new Long(8000))); 
    173         } 
    174          
    175          
    176 //      public void testGetRowIndex() throws Exception { 
    177 //              Long result = deltaVision.getRowOffset(10, 2, 0, 3); // row 170 * rowsize 
    178 //              log.info("Row offset = " + result.intValue()); 
    179 //              assertTrue(result.equals(new Long(6800))); 
    180 //               
    181 //      } 
     39    private OriginalFile originalFile; 
     40 
     41    private DeltaVision deltaVision; 
     42 
     43    private static int setupCount = 0; 
     44 
     45    private static Log log = LogFactory.getLog(DeltaVisionTest.class); 
     46 
     47    public final static String FILENAME = "tinyTest.d3d.dv"; 
     48 
     49    @Configuration(beforeTestMethod = true) 
     50    protected void setUp() { 
     51 
     52        setupCount++; 
     53 
     54        // run this once only 
     55        if (setupCount == 1) { 
     56 
     57            // create an OriginalFile object and DeltaVision for testing 
     58            originalFile = new OriginalFile(); 
     59            // URL url = getClass().getResource("tinyTest.d3d.dv"); 
     60            try { 
     61                File file = ResourceUtils.getFile("classpath:" + FILENAME); 
     62 
     63                // File file = new File(url.toURI()); 
     64                originalFile.setPath(file.getCanonicalPath()); 
     65                // originalFile.setPath("OMERO/tinyTest.d3d.dv"); 
     66                deltaVision = new DeltaVision(originalFile, true); 
     67 
     68            } catch (Exception ex) { 
     69                log.error("Exception caught, throwing ResourceError", ex 
     70                        .getCause()); 
     71                throw new ResourceError(ex.getMessage() 
     72                        + " Please check server log."); 
     73            } 
     74 
     75            log.info("Size X = " + deltaVision.getHeader().getSizeX()); 
     76            log.info("Size Y = " + deltaVision.getHeader().getSizeY()); 
     77            log.info("Size Z = " + deltaVision.getHeader().getSizeZ()); 
     78            log.info("Size C = " + deltaVision.getHeader().getSizeC()); 
     79            log.info("Size T = " + deltaVision.getHeader().getSizeT()); 
     80 
     81            log.info(deltaVision.getPath()); 
     82            log.info("Row size = " 
     83                    + new Integer(deltaVision.getRowSize()).intValue()); 
     84            log.info("Stack size = " 
     85                    + new Integer(deltaVision.getStackSize()).intValue()); 
     86            log.info("Plane size = " 
     87                    + new Integer(deltaVision.getPlaneSize()).intValue()); 
     88 
     89            log.info("Timepoint size = " + deltaVision.getTimepointSize()); 
     90            log.info("Total size = " + deltaVision.getTotalSize().toString()); 
     91 
     92            log.info("ImageSequence = (should be 0=ZTC) " 
     93                    + deltaVision.getHeader().getSequence()); 
     94 
     95        } 
     96    } 
     97 
     98    @Configuration(afterTestMethod = true) 
     99    protected void tearDown() { 
     100        if (setupCount == 13) { 
     101            originalFile = null; 
     102            deltaVision = null; 
     103        } 
     104    } 
     105 
     106    @Test 
     107    public void testGetSizeX() throws Exception { 
     108        int result = deltaVision.getSizeX(); 
     109        assertTrue(result == 20); 
     110    } 
     111 
     112    @Test 
     113    public void testGetSizeY() throws Exception { 
     114        int result = deltaVision.getSizeY(); 
     115        assertTrue(result == 20); 
     116    } 
     117 
     118    @Test 
     119    public void testGetSizeZ() throws Exception { 
     120        int result = deltaVision.getSizeZ(); 
     121        assertTrue(result == 5); 
     122    } 
     123 
     124    @Test 
     125    public void testGetSizeC() throws Exception { 
     126        int result = deltaVision.getSizeC(); 
     127        assertTrue(result == 1); 
     128    } 
     129 
     130    @Test 
     131    public void testGetSizeT() throws Exception { 
     132        int result = deltaVision.getSizeT(); 
     133        assertTrue(result == 6); 
     134    } 
     135 
     136    @Test 
     137    public void testTotalSize() throws Exception { 
     138        String result = deltaVision.getTotalSize().toString(); 
     139        assertTrue(result.equals("24000")); 
     140    } 
     141 
     142    @Test 
     143    public void testTimepointSize() throws Exception { 
     144        Integer result = deltaVision.getTimepointSize(); 
     145        assertTrue(result.equals(new Integer(4000))); 
     146    } 
     147 
     148    @Test 
     149    public void testRowSize() throws Exception { 
     150        Integer result = deltaVision.getRowSize(); 
     151        assertTrue(result.equals(new Integer(40))); 
     152 
     153    } 
     154 
     155    @Test 
     156    public void testStackSize() throws Exception { 
     157        Integer result = deltaVision.getStackSize(); 
     158        assertTrue(result.equals(new Integer(4000))); 
     159    } 
     160 
     161    @Test 
     162    public void testPlaneSize() throws Exception { 
     163        Integer result = deltaVision.getPlaneSize(); 
     164        assertTrue(result.equals(new Integer(800))); 
     165 
     166    } 
     167 
     168    @Test 
     169    public void testGetPlaneIndex() throws Exception { 
     170        Long result = deltaVision.getPlaneOffset(2, 0, 3); // (2,0,3) plane 17 
     171        // ? 
     172        // log.info("Plane offset = " + result.intValue()); 
     173        // should be 17 * planeSize=800 = 13600 
     174        assertTrue(result.equals(new Long(13600))); 
     175    } 
     176 
     177    @Test 
     178    public void testGetStackIndex() throws Exception { 
     179        Long result = deltaVision.getStackOffset(0, 2); 
     180        // log.info("Stack offset = " + result.intValue()); 
     181        // should be 2 * stackSize=4000 = 8000 
     182        assertTrue(result.equals(new Long(8000))); 
     183    } 
     184 
     185    @Test 
     186    public void testGetDigest() throws Exception { 
     187        MessageDigest md; 
     188        String[] controls = { 
     189                "472b52ffbeb0f6397571c8a8482e2e37", // 0 
     190                "36afde357e0e89905403cf1563182798", // 1 
     191                "87b7f3e5653550d550d54377e8aa32c3", // 2 
     192                "1fd67721b392c746a8c82d63352b3930", // 3 
     193                "4245d518c4c3ab9cf22211df8b59b9dc", // 4 
     194                "d71ee5397381961763729e7806ba70e6", // 5 
     195                "2d8819f668b9bcb3e77297c110fdc2b8", // 6 
     196                "354f6a7a057bf6e229dce28483b6b666", // 7 
     197                "44a9db6eb3e665897715561e881947e7", // 8 
     198                "3e62132a4145f545034313dc3ccb8406", // 9 
     199                "e67de55f57dcd328e082b1925d828286", // 10 
     200                "ceaaea38d478de45d32f8c7488f9c003", // 11 
     201                "d1992745966a8f6eb4e56fc458ad3ea1", // 12 
     202                "588678a268c0875efd1570d34e39c6ab", // 13 
     203                "a60f2e0b40a5bf0f41a6a68f8f79bbd4", // 14 
     204                "8fb13befd7b046766e000daf61cb3029", // 15 
     205                "1acadc8c7bedc55388fad61bc2a5d81d", // 16 
     206                "b5ca57b86d799876ada84cf2c36dd726", // 17 
     207                "0dd76877705ac7e27011c7d9314981c0", // 18 
     208                "4ff64f897a512516b643870fb416e771", // 19 
     209                "91b9dace231080254403fdcef181ff8a", // 20 
     210                "d7683987d3a68d6d1ddbd2a5d9aacad7", // 21 
     211                "1ff104dba9ac95275be383f6a6c4c04e", // 22 
     212                "ae7623339f2486efef9178b19bc97ea1", // 23 
     213                "c162e80f350dc2dbb20fbf8f479ae1e8", // 24 
     214                "1f4278861506438b5a9e623b0db7b61c", // 25 
     215                "2071ba00d672e3e73b5cdb771d7234d2", // 26 
     216                "606ec319d5126ba99636f4b573947315", // 27 
     217                "47662680c45544f9ba080072eddb7832", // 28 
     218                "5ba8cc329b663dfdb59d3432b799e1e6"};  // 29            
     219 
     220         
     221        try { 
     222            md = MessageDigest.getInstance("MD5"); 
     223        } catch (NoSuchAlgorithmException e) { 
     224            throw new RuntimeException( 
     225                    "Required MD5 message digest algorithm unavailable."); 
     226        } 
     227 
     228        int begin = deltaVision.header.getPixelBeginOffset(); 
     229        int i = 0; 
     230        int offset = 0; 
     231 
     232        while (i < 30) { 
     233             
     234            offset = begin + (800 * i); 
     235 
     236            MappedByteBuffer buffer = deltaVision.getRegion(new Integer(800), 
     237                    new Long(offset)); // plane 0 
     238 
     239//            File file = new File("myplane" + i + ".dat"); 
     240//            FileOutputStream out = new FileOutputStream (file); 
     241//            byte[] planebytes = ByteBuffer.allocate(800).array(); 
     242//             
     243//            for (int j=0; j<planebytes.length; j++) { 
     244//                planebytes[j] = buffer.get(j); 
     245//            } 
     246//    
     247//            out.write(planebytes); 
     248 
     249            md.update(buffer); 
     250            byte[] bytes = md.digest(); 
     251 
     252 
     253            System.out.println("md5 version is " + byteArrayToHexString(bytes)); 
     254            assertTrue(byteArrayToHexString(bytes).equals(controls[i])); 
     255             
     256            i++; 
     257//            out.close(); 
     258             
     259        } 
     260    } 
     261 
     262 
     263    static String byteArrayToHexString(byte in[]) { 
     264 
     265        byte ch = 0x00; 
     266        int i = 0; 
     267 
     268        if (in == null || in.length <= 0) 
     269            return null; 
     270 
     271        String pseudo[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", 
     272                "a", "b", "c", "d", "e", "f" }; 
     273 
     274        StringBuffer out = new StringBuffer(in.length * 2); 
     275 
     276        while (i < in.length) { 
     277 
     278            ch = (byte) (in[i] & 0xF0); 
     279            ch = (byte) (ch >>> 4); 
     280            ch = (byte) (ch & 0x0F); 
     281            out.append(pseudo[(int) ch]); 
     282            ch = (byte) (in[i] & 0x0F); 
     283            out.append(pseudo[(int) ch]); 
     284            i++; 
     285 
     286        } 
     287 
     288        String rslt = new String(out); 
     289        return rslt; 
     290    } 
    182291} 

Download in other formats:

  • Unified Diff
  • Zip Archive

Trac Powered

Powered by Trac 0.11
By Edgewall Software.

Visit the Trac open source project at
http://trac.edgewall.org/