~ubuntu-branches/ubuntu/saucy/freecell-solver/saucy

« back to all changes in this revision

Viewing changes to t/bit-reader-and-writer-test.c

  • Committer: Package Import Robot
  • Author(s): Gergely Risko
  • Date: 2012-06-22 10:08:05 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20120622100805-evoda1ccdr8vt5xr
Tags: 3.12.0-1
New upstream version. (closes: #675262)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2011 Shlomi Fish
 
2
 *
 
3
 * Permission is hereby granted, free of charge, to any person
 
4
 * obtaining a copy of this software and associated documentation
 
5
 * files (the "Software"), to deal in the Software without
 
6
 * restriction, including without limitation the rights to use,
 
7
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 
8
 * copies of the Software, and to permit persons to whom the
 
9
 * Software is furnished to do so, subject to the following
 
10
 * conditions:
 
11
 *
 
12
 * The above copyright notice and this permission notice shall be
 
13
 * included in all copies or substantial portions of the Software.
 
14
 *
 
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
16
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 
17
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
18
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 
19
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 
20
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 
21
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 
22
 * OTHER DEALINGS IN THE SOFTWARE.
 
23
 */
 
24
/*
 
25
 * A test for the bit reader and writer.
 
26
 */
 
27
 
 
28
#include <string.h>
 
29
#include <stdio.h>
 
30
 
 
31
#include <tap.h>
 
32
#include "../bit_rw.h"
 
33
 
 
34
int main_tests()
 
35
{
 
36
    {
 
37
        unsigned char buffer[10];
 
38
        fc_solve_bit_writer_t writer;
 
39
 
 
40
        fc_solve_bit_writer_init(&writer, buffer);
 
41
 
 
42
        fc_solve_bit_writer_write(&writer, 4, 5);
 
43
        fc_solve_bit_writer_write(&writer, 2, 1);
 
44
 
 
45
        /* TEST
 
46
         * */
 
47
        ok (buffer[0] == (5 | (1 << 4)), "Write works.");
 
48
 
 
49
        fc_solve_bit_writer_write(&writer, 4, (2 | (3 << 2)));
 
50
 
 
51
        /* TEST
 
52
         * */
 
53
        ok (buffer[0] == (5 | (1 << 4) | (2 << 6)), "Extra write works.");
 
54
 
 
55
        /* TEST
 
56
         * */
 
57
        ok (buffer[1] == 3, "Extra byte write works.");
 
58
 
 
59
        {
 
60
            fc_solve_bit_reader_t reader;
 
61
 
 
62
            fc_solve_bit_reader_init(&reader, buffer);
 
63
 
 
64
            /* TEST
 
65
             * */
 
66
            ok (fc_solve_bit_reader_read(&reader, 4) == 5,
 
67
                    "reader 1");
 
68
 
 
69
            /* TEST
 
70
             * */
 
71
            ok (fc_solve_bit_reader_read(&reader, 2) == 1,
 
72
                    "reader 2");
 
73
 
 
74
            /* TEST
 
75
             * */
 
76
            ok (fc_solve_bit_reader_read(&reader, 4) == (2 | (3 << 2)),
 
77
                    "reader 3");
 
78
        }
 
79
    }
 
80
 
 
81
    return 0;
 
82
}
 
83
 
 
84
int main(int argc, char * argv[])
 
85
{
 
86
    plan_tests(6);
 
87
    main_tests();
 
88
    return exit_status();
 
89
}