]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.fastlz/testcases/org/simantics/fastlz/FastLZTest1.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.fastlz / testcases / org / simantics / fastlz / FastLZTest1.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.fastlz;
13
14 import static org.junit.Assert.assertTrue;
15 import static org.junit.Assert.fail;
16
17 import java.io.File;
18 import java.io.FileInputStream;
19 import java.io.FileOutputStream;
20 import java.io.IOException;
21 import java.io.InputStream;
22 import java.io.OutputStream;
23 import java.util.zip.GZIPInputStream;
24 import java.util.zip.GZIPOutputStream;
25
26 import org.junit.Test;
27 import org.simantics.fastlz.impl.OS;
28
29 public class FastLZTest1 {
30
31     @Test
32     public void testCalculateOS() {
33         OSType os = OSType.calculate();
34         assertTrue("unknown OS type", os != OSType.UNKNOWN);
35     }
36
37     @Test
38     public void testCalculateArch() {
39         ARCHType arch = ARCHType.calculate();
40         assertTrue("unknown architecture type", arch != ARCHType.UNKNOWN);
41     }
42
43     @Test
44     public void testFormOsArchSuffix() {
45         OS.formOsArchSuffix();
46     }
47
48     @Test
49     public void testInitialize() {
50         fail("Not yet implemented");
51     }
52
53     @Test
54     public void testCompress() {
55         fail("Not yet implemented");
56     }
57
58     @Test
59     public void testDecompressCluster() {
60         fail("Not yet implemented");
61     }
62
63     @Test
64     public void testDecompress() {
65         fail("Not yet implemented");
66     }
67
68     @Test
69     public void testRead() {
70         fail("Not yet implemented");
71     }
72
73     @Test
74     public void testWrite() {
75         fail("Not yet implemented");
76     }
77
78     public static void test() {
79         byte[] data = new byte[537520000];
80         
81         while(true) {
82             try {
83                 long beginTime = System.nanoTime();
84                 File snapfile = new File("d:/Loviisa080129/Loviisa080129.dir/loviisa080129.snp.gz");
85                 GZIPInputStream stream = new GZIPInputStream(new FileInputStream(snapfile), 128*1024);          
86                 int pos = 0;
87                 while(true) {               
88                     int length = stream.read(data, pos, data.length-pos);               
89                     if(length <= 0)
90                         break;              
91                     pos += length;
92                 }               
93                 stream.close();
94                 long endTime = System.nanoTime();
95                 
96                 System.out.println("Uncompressed size: " + pos);
97                 System.out.println("GZip read: " + (endTime-beginTime)*1e-9 + "s");             
98             } catch (Throwable e) {
99                 e.printStackTrace();
100             }
101             
102             /*{
103                 Checksum cs = new CRC32();              
104                 cs.update(data, 0, data.length);
105                 System.out.println("Checksum: " + cs.getValue());
106             }*/         
107             
108             try {           
109                 File file = new File("d:/testlz.dat");
110                 {
111                     long beginTime = System.nanoTime();
112                     OutputStream output = FastLZ.write(file);
113                     output.write(data); 
114                     output.close();
115                     long endTime = System.nanoTime();
116                     
117                     System.out.println("FastLZ write: " + (endTime-beginTime)*1e-9 + "s");
118                 }
119                 
120                 System.out.println("FastLZ compressed size: " + file.length());
121                 
122                 {
123                     long beginTime = System.nanoTime();
124                     InputStream input = FastLZ.read(file);
125                     input.read(data);               
126                     input.close();
127                     long endTime = System.nanoTime();
128                     
129                     System.out.println("FastLZ read: " + (endTime-beginTime)*1e-9 + "s");
130                 }
131                 
132                 /*{
133                     Checksum cs = new CRC32();              
134                     cs.update(data, 0, data.length);
135                     System.out.println("Checksum: " + cs.getValue());
136                 }*/
137             } catch(Throwable e) {
138                 e.printStackTrace();
139             }
140             
141             try {           
142                 File snapfile = new File("d:/testgz.dat");
143                 
144                 long beginTime = System.nanoTime();             
145                 OutputStream stream = new GZIPOutputStream(new FileOutputStream(snapfile)); 
146                 stream.write(data);                         
147                 stream.close();
148                 long endTime = System.nanoTime();
149                 
150                 System.out.println("GZip write: " + (endTime-beginTime)*1e-9 + "s");
151                 System.out.println("GZip compressed size: " + snapfile.length());
152             } catch (Throwable e) {
153                 e.printStackTrace();
154             }
155         }
156     }
157     
158     public static void test2() {
159         File file = new File("d:/testi.flz");
160         try {
161             /*OutputStream stream = write(file);
162             for(int i=0;i<100000;++i)
163                 stream.write((Integer.toString(i) + "\n").getBytes());
164                 */                          
165             InputStream stream = FastLZ.read(file);
166             byte[] b = new byte[100000];
167             stream.read(b);
168             for(int i=0;i<100000;++i) {
169                 System.out.print((char)b[i]);
170             }
171             stream.close();
172         } catch(IOException e) {
173             e.printStackTrace();
174         }
175     }
176
177 }