C++ port: Make sure #indef/#define/#endif's and copyright information on all header...
[zxing.git] / cpp / core / tests / src / qrcode / decoder / ModeTest.cpp
1 /*
2  *  ModeTest.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 "ModeTest.h"
22 #include <zxing/qrcode/Version.h>
23
24 namespace zxing {
25 namespace qrcode {
26
27 CPPUNIT_TEST_SUITE_REGISTRATION(ModeTest);
28
29 void ModeTest::testForBits() {
30   CPPUNIT_ASSERT_EQUAL(&Mode::TERMINATOR, &(Mode::forBits(0x00)));
31   CPPUNIT_ASSERT_EQUAL(&Mode::NUMERIC, &(Mode::forBits(0x01)));
32   CPPUNIT_ASSERT_EQUAL(&Mode::ALPHANUMERIC, &(Mode::forBits(0x02)));
33   CPPUNIT_ASSERT_EQUAL(&Mode::BYTE, &(Mode::forBits(0x04)));
34   CPPUNIT_ASSERT_EQUAL(&Mode::KANJI, &(Mode::forBits(0x08)));
35   try {
36     Mode::forBits(0x10);
37     CPPUNIT_FAIL("should have thrown an exception");
38   } catch (zxing::ReaderException ex) {
39     // expected
40   }
41 }
42
43 void ModeTest::testCharacterCount() {
44   CPPUNIT_ASSERT_EQUAL(10, Mode::NUMERIC.getCharacterCountBits(Version::getVersionForNumber(5)));
45   CPPUNIT_ASSERT_EQUAL(12, Mode::NUMERIC.getCharacterCountBits(Version::getVersionForNumber(26)));
46   CPPUNIT_ASSERT_EQUAL(14, Mode::NUMERIC.getCharacterCountBits(Version::getVersionForNumber(40)));
47   CPPUNIT_ASSERT_EQUAL(9, Mode::ALPHANUMERIC.getCharacterCountBits(Version::getVersionForNumber(6)));
48   CPPUNIT_ASSERT_EQUAL(8, Mode::BYTE.getCharacterCountBits(Version::getVersionForNumber(7)));
49   CPPUNIT_ASSERT_EQUAL(8, Mode::KANJI.getCharacterCountBits(Version::getVersionForNumber(8)));
50 }
51 }
52 }