991638906c6a88dab6ba2060b11926e578a7433e
[zxing.git] / cpp / core / tests / src / qrcode / decoder / DataMaskTest.h
1 #ifndef __DATA_MASK_TEST_H__
2 #define __DATA_MASK_TEST_H__
3
4 /*
5  *  DataMaskTest.h
6  *  zxing
7  *
8  *  Created by Christian Brunschen on 19/05/2008.
9  *  Copyright 2008 ZXing authors All rights reserved.
10  *
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  *
15  *      http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  */
23
24 #include <cppunit/TestFixture.h>
25 #include <cppunit/extensions/HelperMacros.h>
26 #include <zxing/qrcode/decoder/DataMask.h>
27 #include <zxing/common/BitMatrix.h>
28
29 namespace zxing {
30 namespace qrcode {
31
32 class MaskCondition {
33 public:
34   MaskCondition() { }
35   virtual bool isMasked(int i, int j) = 0;
36   virtual ~MaskCondition() { }
37 };
38
39
40 class DataMaskTest : public CPPUNIT_NS::TestFixture {
41   CPPUNIT_TEST_SUITE(DataMaskTest);
42   CPPUNIT_TEST(testMask0);
43   CPPUNIT_TEST(testMask1);
44   CPPUNIT_TEST(testMask2);
45   CPPUNIT_TEST(testMask3);
46   CPPUNIT_TEST(testMask4);
47   CPPUNIT_TEST(testMask5);
48   CPPUNIT_TEST(testMask6);
49   CPPUNIT_TEST(testMask7);
50   CPPUNIT_TEST_SUITE_END();
51
52 public:
53
54 protected:
55   void testMask0();
56   void testMask1();
57   void testMask2();
58   void testMask3();
59   void testMask4();
60   void testMask5();
61   void testMask6();
62   void testMask7();
63
64 private:
65   void testMaskAcrossDimensions(int reference,
66                                 MaskCondition &condition) {
67     DataMask& mask = DataMask::forReference(reference);
68     for (int version = 1; version <= 40; version++) {
69       int dimension = 17 + 4 * version;
70       testMask(mask, dimension, condition);
71     }
72   }
73
74   void testMask(DataMask& mask, int dimension, MaskCondition &condition) {
75     BitMatrix bits(dimension);
76     mask.unmaskBitMatrix(bits, dimension);
77     for (int i = 0; i < dimension; i++) {
78       for (int j = 0; j < dimension; j++) {
79         //TODO: check why the coordinates are swapped
80         CPPUNIT_ASSERT_EQUAL(
81           //"(" + i + ',' + j + ')',
82           condition.isMasked(i, j),
83           bits.get(j, i));
84       }
85     }
86   }
87 };
88
89 }
90 }
91
92 #endif // __DATA_MASK_TEST_H__