1 // -*- coding: utf-8 -*-
2 // Copyright (C) 2011, 2014, 2015, 2018 Laboratoire de Recherche et
3 // Developpement de l'Epita (LRDE).
4 //
5 // This file is part of Spot, a model checking library.
6 //
7 // Spot is free software; you can redistribute it and/or modify it
8 // under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // Spot is distributed in the hope that it will be useful, but WITHOUT
13 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 // or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
15 // License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 
20 #include "config.h"
21 #include <iostream>
22 #include <spot/misc/intvcmp2.hh>
23 #include <cstring>
24 
25 
26 static int
check_aa(int * data,int size,unsigned expected=0)27 check_aa(int* data, int size, unsigned expected = 0)
28 {
29   int* comp = new int[size * 2];
30   size_t csize = size * 2;
31   spot::int_array_array_compress2(data, size, comp, csize);
32 
33   std::cout << "AC[" << csize << "] ";
34   for (size_t i = 0; i < csize; ++i)
35     std::cout << comp[i] << ' ';
36   std::cout << std::endl;
37 
38   int* decomp = new int[size + 30];
39   spot::int_array_array_decompress2(comp, csize, decomp, size);
40 
41   std::cout << "AD[" << size << "] ";
42   for (int i = 0; i < size; ++i)
43     std::cout << decomp[i] << ' ';
44   std::cout << std::endl;
45 
46   int res = memcmp(data, decomp, size * sizeof(int));
47 
48   if (res)
49     {
50       std::cout << "*** cmp error *** " << res << std::endl;
51       std::cout << "AE[" << size << "] ";
52       for (int i = 0; i < size; ++i)
53         std::cout << data[i] << ' ';
54       std::cout << std::endl;
55     }
56 
57   if (expected && (csize * sizeof(int) != expected))
58     {
59       std::cout << "*** size error *** (expected "
60                 << expected << " bytes, got " << csize * sizeof(int)
61                 << " bytes)" << std::endl;
62       res = 1;
63     }
64 
65   std::cout << std::endl;
66 
67   delete[] comp;
68   delete[] decomp;
69   return !!res;
70 }
71 
72 static int
check(int * comp,int size,unsigned expected=0)73 check(int* comp, int size, unsigned expected = 0)
74 {
75   return
76     //check_vv(comp, size, expected) +
77     //check_av(comp, size, expected) +
78     check_aa(comp, size, expected);
79 }
80 
main()81 int main()
82 {
83   int errors = 0;
84 
85   int comp1[] = { 1, 0, 0, 0, 0, 0, 3, 3, 4, 0, 0, 0 };
86   errors += check(comp1, sizeof(comp1) / sizeof(*comp1));
87 
88   int comp2[] = { 3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 1 };
89   errors += check(comp2, sizeof(comp2) / sizeof(*comp2));
90 
91   int comp3[] = { 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1,
92                   0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0,
93                   0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1,
94                   0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
95                   0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1,
96                   0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0 };
97   errors += check(comp3, sizeof(comp3) / sizeof(*comp3));
98 
99   int comp4[] = { 1, 2, 1, 2, 1, 2, 2, 0 }; // 32 bits
100   errors += check(comp4, sizeof(comp4) / sizeof(*comp4), 4);
101 
102   int comp5[] = { 1, 2, 1, 2, 1, 2, 2, 0, 1, 2, 1, 2, 1, 2, 2, 0 }; // 64 bits
103   errors += check(comp5, sizeof(comp5) / sizeof(*comp5), 8);
104 
105   int comp6[] = { 1, 2, 1, 2, 1, 2, 2, 0, 1, 2, 1, 2, 1, 2, 2, 0,
106                   1, 2, 1, 2, 1, 2, 2, 0, 1, 2, 1, 2, 1, 2, 2, 0 }; // 128 bits
107   errors += check(comp6, sizeof(comp6) / sizeof(*comp6), 16);
108 
109   int comp7[] = { 4, 8, 10, 3, 49, 50, 0, 20, 13 };
110   errors += check(comp7, sizeof(comp7) / sizeof(*comp7));
111 
112   int comp8[] = { 4959, 6754, 8133, 10985, 11121, 14413, 17335, 20754,
113                   21317, 30008, 30381, 33494, 34935, 41210, 41417 };
114   errors += check(comp8, sizeof(comp8) / sizeof(*comp8));
115 
116   int comp9[] = { 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
117   errors += check(comp9, sizeof(comp9) / sizeof(*comp9));
118 
119   int comp10[] = { 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0,
120                    0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
121                    0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
122                    0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
123                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
124                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
125                    1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0,
126                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0,
127                    9, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
128                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 10,
129                    0, 0, 0, 0, 0, 0, 0, 0, 9 };
130   errors += check(comp10, sizeof(comp10) / sizeof(*comp10));
131 
132   int comp11[] = { 2, 254, 254, 0, 1, 4, 0, 0, 0, 1, 0, 1, 253, 0 };
133   errors += check(comp11, sizeof(comp11) / sizeof(*comp11));
134 
135   return errors;
136 }
137