tests/libjava-mauve/src/gnu/testlet/javax/imageio/plugins/jpeg/TestJPEGHuffmanTable.java
branchjk_new_structure
changeset 1541 75c2e24dea9a
parent 1540 92ac284961c1
child 1542 be11db817bcf
equal deleted inserted replaced
1540:92ac284961c1 1541:75c2e24dea9a
     1 // Tags: JDK1.4
       
     2 
       
     3 // Copyright (C) 2006  Red Hat
       
     4 
       
     5 // This file is part of Mauve.
       
     6 
       
     7 // Mauve is free software; you can redistribute it and/or modify
       
     8 // it under the terms of the GNU General Public License as published by
       
     9 // the Free Software Foundation; either version 2, or (at your option)
       
    10 // any later version.
       
    11 
       
    12 // Mauve is distributed in the hope that it will be useful,
       
    13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    15 // GNU General Public License for more details.
       
    16 
       
    17 // You should have received a copy of the GNU General Public License
       
    18 // along with Mauve; see the file COPYING.  If not, write to
       
    19 // the Free Software Foundation, 59 Temple Place - Suite 330,
       
    20 // Boston, MA 02111-1307, USA.
       
    21 
       
    22 package gnu.testlet.javax.imageio.plugins.jpeg;
       
    23 
       
    24 import gnu.testlet.Testlet;
       
    25 import gnu.testlet.TestHarness;
       
    26 
       
    27 import java.util.Arrays;
       
    28 import javax.imageio.plugins.jpeg.JPEGHuffmanTable;
       
    29 
       
    30 /**
       
    31  * Test JPEGHuffmanTable construction and static fields.
       
    32  */
       
    33 public class TestJPEGHuffmanTable implements Testlet
       
    34 {
       
    35   public void test(TestHarness h)
       
    36   {
       
    37     JPEGHuffmanTable t = null;
       
    38     boolean constructionFailed = false;
       
    39 
       
    40     // Some valid data for construction testing.
       
    41     short[] ACChrominanceLengths =
       
    42       {
       
    43         0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77
       
    44       };
       
    45 
       
    46     short[] ACChrominanceValues =
       
    47       {
       
    48         0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, 0x31, 0x06,
       
    49         0x12, 0x41, 0x51, 0x07, 0x61, 0x71, 0x13, 0x22, 0x32, 0x81,
       
    50         0x08, 0x14, 0x42, 0x91, 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33,
       
    51         0x52, 0xf0, 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
       
    52         0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26, 0x27, 0x28,
       
    53         0x29, 0x2a, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x43, 0x44,
       
    54         0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56,
       
    55         0x57, 0x58, 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
       
    56         0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a,
       
    57         0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x92,
       
    58         0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3,
       
    59         0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
       
    60         0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
       
    61         0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6,
       
    62         0xd7, 0xd8, 0xd9, 0xda, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
       
    63         0xe8, 0xe9, 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
       
    64         0xf9, 0xfa
       
    65       };
       
    66 
       
    67     short[] ACLuminanceLengths =
       
    68       {
       
    69         0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d
       
    70       };
       
    71 
       
    72     short[] ACLuminanceValues =
       
    73       {
       
    74         0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, 0x21, 0x31,
       
    75         0x41, 0x06, 0x13, 0x51, 0x61, 0x07, 0x22, 0x71, 0x14, 0x32,
       
    76         0x81, 0x91, 0xa1, 0x08, 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52,
       
    77         0xd1, 0xf0, 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
       
    78         0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a,
       
    79         0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x43, 0x44, 0x45,
       
    80         0x46, 0x47, 0x48, 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57,
       
    81         0x58, 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
       
    82         0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x83,
       
    83         0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94,
       
    84         0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
       
    85         0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
       
    86         0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
       
    87         0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8,
       
    88         0xd9, 0xda, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8,
       
    89         0xe9, 0xea, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
       
    90         0xf9, 0xfa
       
    91       };
       
    92 
       
    93     short[] DCChrominanceLengths =
       
    94       {
       
    95         0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0
       
    96       };
       
    97 
       
    98     short[] DCChrominanceValues =
       
    99       {
       
   100         0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
       
   101       };
       
   102 
       
   103     short[] DCLuminanceLengths =
       
   104       {
       
   105         0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0
       
   106       };
       
   107 
       
   108     short[] DCLuminanceValues =
       
   109       {
       
   110         0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
       
   111       };
       
   112 
       
   113     // Test that it is impossible to construct an invalid Huffman table.
       
   114     // Both arguments are null.
       
   115     try
       
   116       {
       
   117         t = new JPEGHuffmanTable(null, null);
       
   118       }
       
   119     catch (IllegalArgumentException e)
       
   120       {
       
   121         constructionFailed = true;
       
   122       }
       
   123     h.check(constructionFailed);
       
   124 
       
   125     // values argument is null.
       
   126     constructionFailed = false;
       
   127     try
       
   128       {
       
   129         t = new JPEGHuffmanTable(ACLuminanceLengths, null);
       
   130       }
       
   131     catch (IllegalArgumentException e)
       
   132       {
       
   133         constructionFailed = true;
       
   134       }
       
   135     h.check(constructionFailed);
       
   136 
       
   137     // lengths argument is null.
       
   138     constructionFailed = false;
       
   139     try
       
   140       {
       
   141         t = new JPEGHuffmanTable(null, ACLuminanceValues);
       
   142       }
       
   143     catch (IllegalArgumentException e)
       
   144       {
       
   145         constructionFailed = true;
       
   146       }
       
   147     h.check(constructionFailed);
       
   148 
       
   149     // lengths argument has length > 16.
       
   150     short[] boguslengths = { 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1,
       
   151                              0x7d, 5 };
       
   152 
       
   153     constructionFailed = false;
       
   154     try
       
   155       {
       
   156         t = new JPEGHuffmanTable(boguslengths, ACLuminanceValues);
       
   157       }
       
   158     catch (IllegalArgumentException e)
       
   159       {
       
   160         constructionFailed = true;
       
   161       }
       
   162     h.check(constructionFailed);
       
   163 
       
   164     // values argument has length > 256.
       
   165     short[] bogusvalues = new short[257];
       
   166     System.arraycopy(ACLuminanceValues, 0, bogusvalues, 0, 128);
       
   167     System.arraycopy(ACLuminanceValues, 0, bogusvalues, 128, 128);
       
   168     bogusvalues[256] = 0x4a;
       
   169 
       
   170     constructionFailed = false;
       
   171     try
       
   172       {
       
   173         t = new JPEGHuffmanTable(ACLuminanceLengths, bogusvalues);
       
   174       }
       
   175     catch (IllegalArgumentException e)
       
   176       {
       
   177         constructionFailed = true;
       
   178       }
       
   179     h.check(constructionFailed);
       
   180 
       
   181     // check bogus length value
       
   182     ACLuminanceLengths[3] = 16;
       
   183     constructionFailed = false;
       
   184     try
       
   185       {
       
   186         t = new JPEGHuffmanTable(ACLuminanceLengths, ACLuminanceValues);
       
   187       }
       
   188     catch (IllegalArgumentException e)
       
   189       {
       
   190         constructionFailed = true;
       
   191       }
       
   192     h.check(constructionFailed);
       
   193     // restore original value
       
   194     ACLuminanceLengths[3] = 3;
       
   195 
       
   196     // check bogus length total
       
   197     ACLuminanceLengths[9] = 6;
       
   198     constructionFailed = false;
       
   199     try
       
   200       {
       
   201         t = new JPEGHuffmanTable(ACLuminanceLengths, ACLuminanceValues);
       
   202       }
       
   203     catch (IllegalArgumentException e)
       
   204       {
       
   205         constructionFailed = true;
       
   206       }
       
   207     h.check(constructionFailed);
       
   208     // restore original value
       
   209     ACLuminanceLengths[9] = 5;
       
   210 
       
   211     // check bogus number of values
       
   212     short[] valueslessone = new short[ACLuminanceValues.length - 1];
       
   213     System.arraycopy(ACLuminanceValues, 0, valueslessone, 0,
       
   214                      ACLuminanceValues.length - 1);
       
   215     constructionFailed = false;
       
   216     try
       
   217       {
       
   218         t = new JPEGHuffmanTable(ACLuminanceLengths, valueslessone);
       
   219       }
       
   220     catch (IllegalArgumentException e)
       
   221       {
       
   222         constructionFailed = true;
       
   223       }
       
   224     h.check(constructionFailed);
       
   225 
       
   226     // check StdACChrominance
       
   227     short[] lengths = JPEGHuffmanTable.StdACChrominance.getLengths();
       
   228     h.check (Arrays.equals(lengths, ACChrominanceLengths));
       
   229 
       
   230     short[] values = JPEGHuffmanTable.StdACChrominance.getValues();
       
   231     h.check (Arrays.equals(values, ACChrominanceValues));
       
   232 
       
   233     // check StdACLuminance
       
   234     lengths = JPEGHuffmanTable.StdACLuminance.getLengths();
       
   235     h.check(Arrays.equals(lengths, ACLuminanceLengths));
       
   236 
       
   237     values = JPEGHuffmanTable.StdACLuminance.getValues();
       
   238     h.check(Arrays.equals(values, ACLuminanceValues));
       
   239 
       
   240     // check StdDCChrominance
       
   241     lengths = JPEGHuffmanTable.StdDCChrominance.getLengths();
       
   242     h.check (Arrays.equals(lengths, DCChrominanceLengths));
       
   243 
       
   244     values = JPEGHuffmanTable.StdDCChrominance.getValues();
       
   245     h.check (Arrays.equals(values, DCChrominanceValues));
       
   246 
       
   247     // check StdDCLuminance
       
   248     lengths = JPEGHuffmanTable.StdDCLuminance.getLengths();
       
   249     h.check(Arrays.equals(lengths, DCLuminanceLengths));
       
   250 
       
   251     values = JPEGHuffmanTable.StdDCLuminance.getValues();
       
   252     h.check(Arrays.equals(values, DCLuminanceValues));
       
   253   }
       
   254 }