Blame test/test_Unzip.ml

rpm-build 0f2925
(*
rpm-build 0f2925
 * ExtLib Testing Suite
rpm-build 0f2925
 * Copyright (C) 2004, 2007 Janne Hellsten
rpm-build 0f2925
 *
rpm-build 0f2925
 * This library is free software; you can redistribute it and/or
rpm-build 0f2925
 * modify it under the terms of the GNU Lesser General Public
rpm-build 0f2925
 * License as published by the Free Software Foundation; either
rpm-build 0f2925
 * version 2.1 of the License, or (at your option) any later version,
rpm-build 0f2925
 * with the special exception on linking described in file LICENSE.
rpm-build 0f2925
 *
rpm-build 0f2925
 * This library is distributed in the hope that it will be useful,
rpm-build 0f2925
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
rpm-build 0f2925
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
rpm-build 0f2925
 * Lesser General Public License for more details.
rpm-build 0f2925
 *
rpm-build 0f2925
 * You should have received a copy of the GNU Lesser General Public
rpm-build 0f2925
 * License along with this library; if not, write to the Free Software
rpm-build 0f2925
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
rpm-build 0f2925
 *)
rpm-build 0f2925
rpm-build 0f2925
(* test_unzip_bug1 test case was contributed by Robert Atkey on
rpm-build 0f2925
   ocaml-lib-devel@lists.sourceforge.net on Nov 26, 2007.  
rpm-build 0f2925
   Thanks Rob! *)
rpm-build 0f2925
rpm-build 0f2925
let test_unzip_bug1 () =
rpm-build 0f2925
  let test data =
rpm-build 0f2925
    let input    = IO.input_string data in
rpm-build 0f2925
    let unzipped = Unzip.inflate input in
rpm-build 0f2925
    try
rpm-build 0f2925
      let str      = IO.read_all unzipped in
rpm-build 0f2925
      assert (str = "XY")
rpm-build 0f2925
    with Unzip.Error Unzip.Invalid_data -> assert false
rpm-build 0f2925
  in
rpm-build 0f2925
  (* this is "XY" compressed by zlib at level 9 *)
rpm-build 0f2925
  test "\x78\xda\x8b\x88\x04\x00\x01\x0b\x00\xb2";
rpm-build 0f2925
  (* this is "XY" compressed by zlib at level 0 *)
rpm-build 0f2925
  test "\x78\x01\x01\x02\x00\xfd\xff\x58\x59\x01\x0b\x00\xb2"
rpm-build 0f2925
rpm-build 0f2925
(* Some zlib compressed strings with various compression levels.  See
rpm-build 0f2925
   extlib-test/util/zlib-test/gen_ml.sh for more info.  This is not
rpm-build 0f2925
   very exhaustive but is still better than nothing.  The generation
rpm-build 0f2925
   script should be pretty easy to extend to cover longer strings. *)
rpm-build 0f2925
let inputs = 
rpm-build 0f2925
  [("a", "\x78\x01\x4b\x04\x00\x00\x62\x00\x62");
rpm-build 0f2925
   ("a", "\x78\x5e\x4b\x04\x00\x00\x62\x00\x62");
rpm-build 0f2925
   ("a", "\x78\x9c\x4b\x04\x00\x00\x62\x00\x62");
rpm-build 0f2925
   ("a", "\x78\xda\x4b\x04\x00\x00\x62\x00\x62");
rpm-build 0f2925
   ("b", "\x78\x01\x4b\x02\x00\x00\x63\x00\x63");
rpm-build 0f2925
   ("b", "\x78\x5e\x4b\x02\x00\x00\x63\x00\x63");
rpm-build 0f2925
   ("b", "\x78\x9c\x4b\x02\x00\x00\x63\x00\x63");
rpm-build 0f2925
   ("b", "\x78\xda\x4b\x02\x00\x00\x63\x00\x63");
rpm-build 0f2925
   ("c", "\x78\x01\x4b\x06\x00\x00\x64\x00\x64");
rpm-build 0f2925
   ("c", "\x78\x5e\x4b\x06\x00\x00\x64\x00\x64");
rpm-build 0f2925
   ("c", "\x78\x9c\x4b\x06\x00\x00\x64\x00\x64");
rpm-build 0f2925
   ("c", "\x78\xda\x4b\x06\x00\x00\x64\x00\x64");
rpm-build 0f2925
   ("aa", "\x78\x01\x4b\x4c\x04\x00\x01\x25\x00\xc3");
rpm-build 0f2925
   ("aa", "\x78\x5e\x4b\x4c\x04\x00\x01\x25\x00\xc3");
rpm-build 0f2925
   ("aa", "\x78\x9c\x4b\x4c\x04\x00\x01\x25\x00\xc3");
rpm-build 0f2925
   ("aa", "\x78\xda\x4b\x4c\x04\x00\x01\x25\x00\xc3");
rpm-build 0f2925
   ("aaa", "\x78\x01\x4b\x4c\x4c\x04\x00\x02\x49\x01\x24");
rpm-build 0f2925
   ("aaa", "\x78\x5e\x4b\x4c\x4c\x04\x00\x02\x49\x01\x24");
rpm-build 0f2925
   ("aaa", "\x78\x9c\x4b\x4c\x4c\x04\x00\x02\x49\x01\x24");
rpm-build 0f2925
   ("aaa", "\x78\xda\x4b\x4c\x4c\x04\x00\x02\x49\x01\x24");
rpm-build 0f2925
   ("aaaa", "\x78\x01\x4b\x4c\x4c\x4c\x04\x00\x03\xce\x01\x85");
rpm-build 0f2925
   ("aaaa", "\x78\x5e\x4b\x4c\x4c\x4c\x04\x00\x03\xce\x01\x85");
rpm-build 0f2925
   ("aaaa", "\x78\x9c\x4b\x4c\x4c\x4c\x04\x00\x03\xce\x01\x85");
rpm-build 0f2925
   ("aaaa", "\x78\xda\x4b\x4c\x4c\x4c\x04\x00\x03\xce\x01\x85");
rpm-build 0f2925
   ("foobar", "\x78\x01\x4b\xcb\xcf\x4f\x4a\x2c\x02\x00\x08\xab\x02\x7a");
rpm-build 0f2925
   ("foobar", "\x78\x5e\x4b\xcb\xcf\x4f\x4a\x2c\x02\x00\x08\xab\x02\x7a");
rpm-build 0f2925
   ("foobar", "\x78\x9c\x4b\xcb\xcf\x4f\x4a\x2c\x02\x00\x08\xab\x02\x7a");
rpm-build 0f2925
   ("foobar", "\x78\xda\x4b\xcb\xcf\x4f\x4a\x2c\x02\x00\x08\xab\x02\x7a");
rpm-build 0f2925
   ("012345678", "\x78\x01\x33\x30\x34\x32\x36\x31\x35\x33\xb7\x00\x00\x08\xf1\x01\xd5");
rpm-build 0f2925
   ("012345678", "\x78\x5e\x33\x30\x34\x32\x36\x31\x35\x33\xb7\x00\x00\x08\xf1\x01\xd5");
rpm-build 0f2925
   ("012345678", "\x78\x9c\x33\x30\x34\x32\x36\x31\x35\x33\xb7\x00\x00\x08\xf1\x01\xd5");
rpm-build 0f2925
   ("012345678", "\x78\xda\x33\x30\x34\x32\x36\x31\x35\x33\xb7\x00\x00\x08\xf1\x01\xd5");
rpm-build 0f2925
   ("00000000", "\x78\x01\x33\x30\x80\x00\x00\x06\xc8\x01\x81");
rpm-build 0f2925
   ("00000000", "\x78\x5e\x33\x30\x80\x00\x00\x06\xc8\x01\x81");
rpm-build 0f2925
   ("00000000", "\x78\x9c\x33\x30\x80\x00\x00\x06\xc8\x01\x81");
rpm-build 0f2925
   ("00000000", "\x78\xda\x33\x30\x80\x00\x00\x06\xc8\x01\x81");
rpm-build 0f2925
   ("aaaaaaaaaa", "\x78\x01\x4b\x4c\x84\x01\x00\x14\xe1\x03\xcb");
rpm-build 0f2925
   ("aaaaaaaaaa", "\x78\x5e\x4b\x4c\x84\x01\x00\x14\xe1\x03\xcb");
rpm-build 0f2925
   ("aaaaaaaaaa", "\x78\x9c\x4b\x4c\x84\x01\x00\x14\xe1\x03\xcb");
rpm-build 0f2925
   ("aaaaaaaaaa", "\x78\xda\x4b\x4c\x84\x01\x00\x14\xe1\x03\xcb");
rpm-build 0f2925
   ("-------------------------aaaaaaaaa------------------", "\x78\x01\xd3\xd5\xc5\x01\x12\x61\x00\x53\x1e\x00\x1c\x89\x0a\xf9");
rpm-build 0f2925
   ("-------------------------aaaaaaaaa------------------", "\x78\x5e\xd3\xd5\xc5\x01\x12\x61\x00\x53\x1e\x00\x1c\x89\x0a\xf9");
rpm-build 0f2925
   ("-------------------------aaaaaaaaa------------------", "\x78\x5e\xd3\xd5\xc5\x01\x12\x61\x00\x5d\x42\x57\x17\x00\x1c\x89\x0a\xf9");
rpm-build 0f2925
   ("-------------------------aaaaaaaaa------------------", "\x78\x5e\xd3\xd5\xc5\x01\x12\x61\x00\x53\x0a\x00\x1c\x89\x0a\xf9");
rpm-build 0f2925
   ("-------------------------aaaaaaaaa------------------", "\x78\x9c\xd3\xd5\xc5\x01\x12\x61\x00\x53\x0a\x00\x1c\x89\x0a\xf9");
rpm-build 0f2925
   ("-------------------------aaaaaaaaa------------------", "\x78\xda\xd3\xd5\xc5\x01\x12\x61\x00\x53\x0a\x00\x1c\x89\x0a\xf9")]
rpm-build 0f2925
rpm-build 0f2925
let test_unzip_gen_inputs () =
rpm-build 0f2925
  let test orig data =
rpm-build 0f2925
    let input    = IO.input_string data in
rpm-build 0f2925
    let unzipped = Unzip.inflate input in
rpm-build 0f2925
    try
rpm-build 0f2925
      let str      = IO.read_all unzipped in
rpm-build 0f2925
      assert (str = orig)
rpm-build 0f2925
    with Unzip.Error Unzip.Invalid_data -> assert false
rpm-build 0f2925
  in
rpm-build 0f2925
  List.iter
rpm-build 0f2925
    (fun (orig,compressed) ->
rpm-build 0f2925
       test orig compressed)
rpm-build 0f2925
    inputs
rpm-build 0f2925
rpm-build 0f2925
let () = 
rpm-build 0f2925
  Util.register "Unzip" [
rpm-build 0f2925
    "bug1", test_unzip_bug1;
rpm-build 0f2925
    "gen_inputs", test_unzip_gen_inputs;
rpm-build 0f2925
  ]