C++ port: Make sure #indef/#define/#endif's and copyright information on all header...
[zxing.git] / cpp / core / tests / src / qrcode / decoder / DataMaskTest.cpp
1 /*
2  *  DataMaskTest.cpp
3  *  zxing
4  *
5  *  Created by Christian Brunschen on 19/05/2008.
6  *  Copyright 2008 ZXing authors All rights reserved.
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20
21 #include "DataMaskTest.h"
22
23 namespace zxing {
24 namespace qrcode {
25
26 CPPUNIT_TEST_SUITE_REGISTRATION(DataMaskTest);
27
28 class Mask0Condition : public MaskCondition {
29 public:
30   Mask0Condition() { }
31   bool isMasked(int i, int j) {
32     return (i + j) % 2 == 0;
33   }
34 };
35
36 class Mask1Condition : public MaskCondition {
37 public:
38   Mask1Condition() { }
39   bool isMasked(int i, int j) {
40     return i % 2 == 0;
41   }
42 };
43
44 class Mask2Condition : public MaskCondition {
45 public:
46   Mask2Condition() { }
47   bool isMasked(int i, int j) {
48     return j % 3 == 0;
49   }
50 };
51
52 class Mask3Condition : public MaskCondition {
53 public:
54   Mask3Condition() { }
55   bool isMasked(int i, int j) {
56     return (i + j) % 3 == 0;
57   }
58 };
59
60 class Mask4Condition : public MaskCondition {
61 public:
62   Mask4Condition() { }
63   bool isMasked(int i, int j) {
64     return (i / 2 + j / 3) % 2 == 0;
65   }
66 };
67
68 class Mask5Condition : public MaskCondition {
69 public:
70   Mask5Condition() { }
71   bool isMasked(int i, int j) {
72     return (i * j) % 2 + (i * j) % 3 == 0;
73   }
74 };
75
76 class Mask6Condition : public MaskCondition {
77 public:
78   Mask6Condition() { }
79   bool isMasked(int i, int j) {
80     return ((i * j) % 2 + (i * j) % 3) % 2 == 0;
81   }
82 };
83
84 class Mask7Condition : public MaskCondition {
85 public:
86   Mask7Condition() { }
87   bool isMasked(int i, int j) {
88     return ((i + j) % 2 + (i * j) % 3) % 2 == 0;
89   }
90 };
91
92
93 void DataMaskTest::testMask0() {
94   Mask0Condition condition;
95   testMaskAcrossDimensions(0, condition);
96 }
97
98 void DataMaskTest::testMask1() {
99   Mask1Condition condition;
100   testMaskAcrossDimensions(1, condition);
101 }
102
103 void DataMaskTest::testMask2() {
104   Mask2Condition condition;
105   testMaskAcrossDimensions(2, condition);
106 }
107
108 void DataMaskTest::testMask3() {
109   Mask3Condition condition;
110   testMaskAcrossDimensions(3, condition);
111 }
112
113 void DataMaskTest::testMask4() {
114   Mask4Condition condition;
115   testMaskAcrossDimensions(4, condition);
116 }
117
118 void DataMaskTest::testMask5() {
119   Mask5Condition condition;
120   testMaskAcrossDimensions(5, condition);
121 }
122
123 void DataMaskTest::testMask6() {
124   Mask6Condition condition;
125   testMaskAcrossDimensions(6, condition);
126 }
127
128 void DataMaskTest::testMask7() {
129   Mask7Condition condition;
130   testMaskAcrossDimensions(7, condition);
131 }
132
133 }
134 }