2 * FormatInformationTest.cpp
5 * Created by Christian Brunschen on 19/05/2008.
6 * Copyright 2008 ZXing authors All rights reserved.
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include "FormatInformationTest.h"
23 #include "ErrorCorrectionLevelTest.h"
24 #include <zxing/ReaderException.h>
25 #include <zxing/qrcode/FormatInformation.h>
26 #include <zxing/qrcode/ErrorCorrectionLevel.h>
31 CPPUNIT_TEST_SUITE_REGISTRATION(FormatInformationTest);
33 static void assertEquals(Ref<FormatInformation> a,
34 Ref<FormatInformation> b) {
35 FormatInformation &aa = *a;
36 FormatInformation &bb = *b;
37 CPPUNIT_ASSERT_EQUAL(aa, bb);
40 void FormatInformationTest::testBitsDiffering() {
41 CPPUNIT_ASSERT_EQUAL(0, FormatInformation::numBitsDiffering(1, 1));
42 CPPUNIT_ASSERT_EQUAL(1, FormatInformation::numBitsDiffering(0, 2));
43 CPPUNIT_ASSERT_EQUAL(2, FormatInformation::numBitsDiffering(1, 2));
44 CPPUNIT_ASSERT_EQUAL(32, FormatInformation::numBitsDiffering(0xffffffff,
48 void FormatInformationTest::testDecode() {
50 Ref<FormatInformation> expected =
51 FormatInformation::decodeFormatInformation(0x2BED ^ 0x5412);
52 CPPUNIT_ASSERT_EQUAL((unsigned char) 0x07, expected->getDataMask());
53 CPPUNIT_ASSERT_EQUAL(&ErrorCorrectionLevel::Q,
54 &expected->getErrorCorrectionLevel());
55 // where the code forgot the mask!
56 assertEquals(expected,
57 FormatInformation::decodeFormatInformation(0x2BED));
59 // 1,2,3,4 bits difference
60 assertEquals(expected,
61 FormatInformation::decodeFormatInformation(0x2BEF ^ 0x5412));
62 assertEquals(expected,
63 FormatInformation::decodeFormatInformation(0x2BEE ^ 0x5412));
64 assertEquals(expected,
65 FormatInformation::decodeFormatInformation(0x2BEA ^ 0x5412));
66 CPPUNIT_ASSERT_EQUAL(true, FormatInformation::
67 decodeFormatInformation(0x2BE2 ^ 0x5412) == 0);