[9b2e20c] | 1 | /*
|
---|
| 2 | * Copyright (c) 2021 Jiri Svoboda
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | #include <codepage/cp437.h>
|
---|
| 30 | #include <pcut/pcut.h>
|
---|
| 31 |
|
---|
| 32 | PCUT_INIT;
|
---|
| 33 |
|
---|
| 34 | PCUT_TEST_SUITE(cp437);
|
---|
| 35 |
|
---|
| 36 | /** Encode(decode) == identity */
|
---|
| 37 | PCUT_TEST(decode_encode)
|
---|
| 38 | {
|
---|
| 39 | unsigned code;
|
---|
| 40 | char32_t c;
|
---|
| 41 | uint8_t cdec;
|
---|
| 42 | errno_t rc;
|
---|
| 43 |
|
---|
| 44 | for (code = 0; code < 256; code++) {
|
---|
| 45 | c = cp437_decode(code);
|
---|
| 46 | rc = cp437_encode(c, &cdec);
|
---|
| 47 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 48 | PCUT_ASSERT_EQUALS(code, cdec);
|
---|
| 49 | }
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | /** Test limit encoding cases */
|
---|
| 53 | PCUT_TEST(encode_cases)
|
---|
| 54 | {
|
---|
| 55 | uint8_t code;
|
---|
| 56 | errno_t rc;
|
---|
| 57 |
|
---|
| 58 | /* Zero maps to zero */
|
---|
| 59 | rc = cp437_encode(0, &code);
|
---|
| 60 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 61 | PCUT_ASSERT_EQUALS(0x00, code);
|
---|
| 62 |
|
---|
| 63 | /* Last entry in the 0x0000-0x03ff table is unmapped */
|
---|
| 64 | rc = cp437_encode(0x3ff, &code);
|
---|
| 65 | PCUT_ASSERT_ERRNO_VAL(EDOM, rc);
|
---|
| 66 |
|
---|
| 67 | /* 0x0400 is out of range of first table */
|
---|
| 68 | rc = cp437_encode(0x400, &code);
|
---|
| 69 | PCUT_ASSERT_ERRNO_VAL(EDOM, rc);
|
---|
| 70 |
|
---|
| 71 | /* 0x1fff is before start of 0x2000-0x26ff table */
|
---|
| 72 | rc = cp437_encode(0x1fff, &code);
|
---|
| 73 | PCUT_ASSERT_ERRNO_VAL(EDOM, rc);
|
---|
| 74 |
|
---|
| 75 | /* First entry in 0x2000-0x26ff table is unmapped */
|
---|
| 76 | rc = cp437_encode(0x2000, &code);
|
---|
| 77 | PCUT_ASSERT_ERRNO_VAL(EDOM, rc);
|
---|
| 78 |
|
---|
| 79 | /* Last entry in 0x2000-0x26ff table is unmapped */
|
---|
| 80 | rc = cp437_encode(0x26ff, &code);
|
---|
| 81 | PCUT_ASSERT_ERRNO_VAL(EDOM, rc);
|
---|
| 82 |
|
---|
| 83 | /* 0x2700 is beyond the end of 0x2000-0x26ff table */
|
---|
| 84 | rc = cp437_encode(0x2700, &code);
|
---|
| 85 | PCUT_ASSERT_ERRNO_VAL(EDOM, rc);
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | PCUT_EXPORT(cp437);
|
---|