At last update to JUnit 4.x
[zxing.git] / core / test / src / com / google / zxing / AllPositiveBlackBoxTester.java
1 /*
2  * Copyright 2008 ZXing authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package com.google.zxing;
18
19 import com.google.zxing.common.AbstractBlackBoxTestCase;
20 import com.google.zxing.datamatrix.DataMatrixBlackBox1TestCase;
21 import com.google.zxing.datamatrix.DataMatrixBlackBox2TestCase;
22 import com.google.zxing.oned.Code128BlackBox1TestCase;
23 import com.google.zxing.oned.Code128BlackBox2TestCase;
24 import com.google.zxing.oned.Code128BlackBox3TestCase;
25 import com.google.zxing.oned.Code39BlackBox1TestCase;
26 import com.google.zxing.oned.Code39BlackBox3TestCase;
27 import com.google.zxing.oned.Code39ExtendedBlackBox2TestCase;
28 import com.google.zxing.oned.EAN13BlackBox1TestCase;
29 import com.google.zxing.oned.EAN13BlackBox2TestCase;
30 import com.google.zxing.oned.EAN13BlackBox3TestCase;
31 import com.google.zxing.oned.EAN13BlackBox4TestCase;
32 import com.google.zxing.oned.EAN8BlackBox1TestCase;
33 import com.google.zxing.oned.ITFBlackBox1TestCase;
34 import com.google.zxing.oned.ITFBlackBox2TestCase;
35 import com.google.zxing.oned.UPCABlackBox1TestCase;
36 import com.google.zxing.oned.UPCABlackBox2TestCase;
37 import com.google.zxing.oned.UPCABlackBox3ReflectiveTestCase;
38 import com.google.zxing.oned.UPCABlackBox4TestCase;
39 import com.google.zxing.oned.UPCABlackBox5TestCase;
40 import com.google.zxing.oned.UPCEBlackBox1TestCase;
41 import com.google.zxing.oned.UPCEBlackBox2TestCase;
42 import com.google.zxing.oned.UPCEBlackBox3ReflectiveTestCase;
43 import com.google.zxing.pdf417.PDF417BlackBox1TestCase;
44 import com.google.zxing.pdf417.PDF417BlackBox2TestCase;
45 import com.google.zxing.qrcode.QRCodeBlackBox1TestCase;
46 import com.google.zxing.qrcode.QRCodeBlackBox2TestCase;
47 import com.google.zxing.qrcode.QRCodeBlackBox3TestCase;
48 import com.google.zxing.qrcode.QRCodeBlackBox4TestCase;
49 import com.google.zxing.qrcode.QRCodeBlackBox5TestCase;
50
51 /**
52  * This is a quick and dirty way to get totals across all the positive black box tests. It is
53  * necessary because we spawn multiple processes when using the standard test-blackbox Ant target.
54  * It would be a shame to change that because it does help with performance. Perhaps we can find a
55  * way to unify these in the future.
56  *
57  * @author dswitkin@google.com (Daniel Switkin)
58  */
59 public final class AllPositiveBlackBoxTester {
60
61   // This list has to be manually kept up to date. I don't know any automatic way to include every
62   // subclass of AbstractBlackBoxTestCase, and furthermore to exclude subclasses of
63   // AbstractNegativeBlackBoxTestCase which derives from it.
64   private static final AbstractBlackBoxTestCase[] TESTS = {
65     new DataMatrixBlackBox1TestCase(),
66     new DataMatrixBlackBox2TestCase(),
67     new Code128BlackBox1TestCase(),
68     new Code128BlackBox2TestCase(),
69     new Code128BlackBox3TestCase(),
70     new Code39BlackBox1TestCase(),
71     new Code39ExtendedBlackBox2TestCase(),
72     new Code39BlackBox3TestCase(),
73     new EAN13BlackBox1TestCase(),
74     new EAN13BlackBox2TestCase(),
75     new EAN13BlackBox3TestCase(),
76     new EAN13BlackBox4TestCase(),
77     new EAN8BlackBox1TestCase(),
78     new ITFBlackBox1TestCase(),
79     new ITFBlackBox2TestCase(),
80     new UPCABlackBox1TestCase(),
81     new UPCABlackBox2TestCase(),
82     new UPCABlackBox3ReflectiveTestCase(),
83     new UPCABlackBox4TestCase(),
84     new UPCABlackBox5TestCase(),
85     new UPCEBlackBox1TestCase(),
86     new UPCEBlackBox2TestCase(),
87     new UPCEBlackBox3ReflectiveTestCase(),
88     new PDF417BlackBox1TestCase(),
89     new PDF417BlackBox2TestCase(),
90     new QRCodeBlackBox1TestCase(),
91     new QRCodeBlackBox2TestCase(),
92     new QRCodeBlackBox3TestCase(),
93     new QRCodeBlackBox4TestCase(),
94     new QRCodeBlackBox5TestCase()
95   };
96
97 //  private static final AbstractBlackBoxTestCase[] TESTS1 = {
98 //    new DataMatrixBlackBox1TestCase(),
99 //    new DataMatrixBlackBox2TestCase(),
100 //    new Code128BlackBox1TestCase(),
101 //    new Code128BlackBox2TestCase(),
102 //    new Code128BlackBox3TestCase(),
103 //    new Code39BlackBox1TestCase(),
104 //    new Code39ExtendedBlackBox2TestCase(),
105 //    new Code39BlackBox3TestCase(),
106 //    new EAN13BlackBox1TestCase(),
107 //    new EAN13BlackBox2TestCase(),
108 //    new EAN13BlackBox3TestCase(),
109 //    new EAN13BlackBox4TestCase(),
110 //    new EAN8BlackBox1TestCase(),
111 //    new ITFBlackBox1TestCase(),
112 //    new ITFBlackBox2TestCase(),
113 //  };
114 //
115 //  private static final AbstractBlackBoxTestCase[] TESTS2 = {
116 //    new UPCABlackBox1TestCase(),
117 //    new UPCABlackBox2TestCase(),
118 //    new UPCABlackBox3ReflectiveTestCase(),
119 //    new UPCABlackBox4TestCase(),
120 //    new UPCABlackBox5TestCase(),
121 //    new UPCEBlackBox1TestCase(),
122 //    new UPCEBlackBox2TestCase(),
123 //    new UPCEBlackBox3ReflectiveTestCase(),
124 //    new QRCodeBlackBox1TestCase(),
125 //    new QRCodeBlackBox2TestCase(),
126 //    new QRCodeBlackBox3TestCase(),
127 //    new QRCodeBlackBox4TestCase(),
128 //    new QRCodeBlackBox5TestCase()
129 //  };
130 //
131 //  private static class WorkerThread extends Thread {
132 //
133 //    private AbstractBlackBoxTestCase[] testCases;
134 //    private AbstractBlackBoxTestCase.SummaryResults results;
135 //
136 //    public WorkerThread(AbstractBlackBoxTestCase[] tests) {
137 //      testCases = tests;
138 //    }
139 //
140 //    @Override
141 //    public void run() {
142 //      try {
143 //        results = new AbstractBlackBoxTestCase.SummaryResults();
144 //        for (int x = 0; x < testCases.length; x++) {
145 //          results.add(testCases[x].testBlackBoxCountingResults());
146 //        }
147 //      } catch (IOException e) {
148 //
149 //      }
150 //    }
151 //
152 //    public AbstractBlackBoxTestCase.SummaryResults getResults() {
153 //      return results;
154 //    }
155 //  }
156
157   private AllPositiveBlackBoxTester() {
158
159   }
160
161   public static void main(String[] args) throws Exception {
162     long now = System.currentTimeMillis();
163     AbstractBlackBoxTestCase.SummaryResults results = new AbstractBlackBoxTestCase.SummaryResults();
164
165     for (AbstractBlackBoxTestCase test : TESTS) {
166       results.add(test.testBlackBoxCountingResults(false));
167     }
168
169     // This threaded version can't be used yet because BlackPointEstimator (and possibly other code)
170     // is not thread-safe. It's also pretty lame. It would be much better to spawn a group of
171     // threads which pull tests from a shared, locked list as needed.
172 //    WorkerThread thread1 = new WorkerThread(TESTS1);
173 //    WorkerThread thread2 = new WorkerThread(TESTS2);
174 //    thread1.start();
175 //    thread2.start();
176 //    thread1.join();
177 //    thread2.join();
178 //    results.add(thread1.getResults());
179 //    results.add(thread2.getResults());
180
181     now = System.currentTimeMillis() - now;
182     System.out.println(results.toString() + "\n  Total time: " + now + " ms");
183   }
184 }