53c9c49acd3e34c27c63e14ca534e54ec5a289ae
[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.UPCEBlackBox1TestCase;
40 import com.google.zxing.oned.UPCEBlackBox2TestCase;
41 import com.google.zxing.oned.UPCEBlackBox3ReflectiveTestCase;
42 import com.google.zxing.qrcode.QRCodeBlackBox1TestCase;
43 import com.google.zxing.qrcode.QRCodeBlackBox2TestCase;
44 import com.google.zxing.qrcode.QRCodeBlackBox3TestCase;
45 import com.google.zxing.qrcode.QRCodeBlackBox4TestCase;
46 import com.google.zxing.qrcode.QRCodeBlackBox5TestCase;
47
48 /**
49  * This is a quick and dirty way to get totals across all the positive black box tests. It is
50  * necessary because we spawn multiple processes when using the standard test-blackbox Ant target.
51  * It would be a shame to change that because it does help with performance. Perhaps we can find a
52  * way to unify these in the future.
53  *
54  * @author dswitkin@google.com (Daniel Switkin)
55  */
56 public final class AllPositiveBlackBoxTester {
57
58   // This list has to be manually kept up to date. I don't know any automatic way to include every
59   // subclass of AbstractBlackBoxTestCase, and furthermore to exclude subclasses of
60   // AbstractNegativeBlackBoxTestCase which derives from it.
61   private static final AbstractBlackBoxTestCase[] TESTS = {
62     new DataMatrixBlackBox1TestCase(),
63     new DataMatrixBlackBox2TestCase(),
64     new Code128BlackBox1TestCase(),
65     new Code128BlackBox2TestCase(),
66     new Code128BlackBox3TestCase(),
67     new Code39BlackBox1TestCase(),
68     new Code39ExtendedBlackBox2TestCase(),
69     new Code39BlackBox3TestCase(),
70     new EAN13BlackBox1TestCase(),
71     new EAN13BlackBox2TestCase(),
72     new EAN13BlackBox3TestCase(),
73     new EAN13BlackBox4TestCase(),
74     new EAN8BlackBox1TestCase(),
75     new ITFBlackBox1TestCase(),
76     new ITFBlackBox2TestCase(),
77     new UPCABlackBox1TestCase(),
78     new UPCABlackBox2TestCase(),
79     new UPCABlackBox3ReflectiveTestCase(),
80     new UPCABlackBox4TestCase(),
81     new UPCEBlackBox1TestCase(),
82     new UPCEBlackBox2TestCase(),
83     new UPCEBlackBox3ReflectiveTestCase(),
84     new QRCodeBlackBox1TestCase(),
85     new QRCodeBlackBox2TestCase(),
86     new QRCodeBlackBox3TestCase(),
87     new QRCodeBlackBox4TestCase(),
88     new QRCodeBlackBox5TestCase()
89   };
90
91 //  private static final AbstractBlackBoxTestCase[] TESTS1 = {
92 //    new DataMatrixBlackBox1TestCase(),
93 //    new DataMatrixBlackBox2TestCase(),
94 //    new Code128BlackBox1TestCase(),
95 //    new Code128BlackBox2TestCase(),
96 //    new Code128BlackBox3TestCase(),
97 //    new Code39BlackBox1TestCase(),
98 //    new Code39ExtendedBlackBox2TestCase(),
99 //    new Code39BlackBox3TestCase(),
100 //    new EAN13BlackBox1TestCase(),
101 //    new EAN13BlackBox2TestCase(),
102 //    new EAN13BlackBox3TestCase(),
103 //    new EAN13BlackBox4TestCase(),
104 //    new EAN8BlackBox1TestCase(),
105 //    new ITFBlackBox1TestCase(),
106 //    new ITFBlackBox2TestCase(),
107 //  };
108 //
109 //  private static final AbstractBlackBoxTestCase[] TESTS2 = {
110 //    new UPCABlackBox1TestCase(),
111 //    new UPCABlackBox2TestCase(),
112 //    new UPCABlackBox3ReflectiveTestCase(),
113 //    new UPCABlackBox4TestCase(),
114 //    new UPCEBlackBox1TestCase(),
115 //    new UPCEBlackBox2TestCase(),
116 //    new UPCEBlackBox3ReflectiveTestCase(),
117 //    new QRCodeBlackBox1TestCase(),
118 //    new QRCodeBlackBox2TestCase(),
119 //    new QRCodeBlackBox3TestCase(),
120 //    new QRCodeBlackBox4TestCase(),
121 //    new QRCodeBlackBox5TestCase()
122 //  };
123 //
124 //  private static class WorkerThread extends Thread {
125 //
126 //    private AbstractBlackBoxTestCase[] testCases;
127 //    private AbstractBlackBoxTestCase.SummaryResults results;
128 //
129 //    public WorkerThread(AbstractBlackBoxTestCase[] tests) {
130 //      testCases = tests;
131 //    }
132 //
133 //    @Override
134 //    public void run() {
135 //      try {
136 //        results = new AbstractBlackBoxTestCase.SummaryResults();
137 //        for (int x = 0; x < testCases.length; x++) {
138 //          results.add(testCases[x].testBlackBoxCountingResults());
139 //        }
140 //      } catch (IOException e) {
141 //
142 //      }
143 //    }
144 //
145 //    public AbstractBlackBoxTestCase.SummaryResults getResults() {
146 //      return results;
147 //    }
148 //  }
149
150   private AllPositiveBlackBoxTester() {
151
152   }
153
154   public static void main(String[] args) throws Exception {
155     long now = System.currentTimeMillis();
156     AbstractBlackBoxTestCase.SummaryResults results = new AbstractBlackBoxTestCase.SummaryResults();
157
158     for (int x = 0; x < TESTS.length; x++) {
159       results.add(TESTS[x].testBlackBoxCountingResults());
160     }
161
162     // This threaded version can't be used yet because BlackPointEstimator (and possibly other code)
163     // is not thread-safe. It's also pretty lame. It would be much better to spawn a group of
164     // threads which pull tests from a shared, locked list as needed.
165 //    WorkerThread thread1 = new WorkerThread(TESTS1);
166 //    WorkerThread thread2 = new WorkerThread(TESTS2);
167 //    thread1.start();
168 //    thread2.start();
169 //    thread1.join();
170 //    thread2.join();
171 //    results.add(thread1.getResults());
172 //    results.add(thread2.getResults());
173
174     now = System.currentTimeMillis() - now;
175     System.out.println(results.toString() + "\n  Total time: " + now + " ms");
176   }
177 }