2 This file is part of systemd
4 Copyright 2014 Ronny Chevalier
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
24 static void test_compress_uncompress(void) {
25 char text[] = "foofoofoofoo AAAA aaaaaaaaa ghost busters barbarbar FFF"
26 "foofoofoofoo AAAA aaaaaaaaa ghost busters barbarbar FFF";
30 _cleanup_free_ char *uncompressed = NULL;
32 assert_se(compress_blob(text, sizeof(text), compressed, &csize));
33 assert_se(uncompress_blob(compressed,
35 (void **) &uncompressed,
37 assert_se(uncompressed);
38 assert_se(streq(uncompressed, text));
39 assert_se(!uncompress_blob("garbage",
41 (void **) &uncompressed,
45 static void test_uncompress_startswith(void) {
46 char text[] = "foofoofoofoo AAAA aaaaaaaaa ghost busters barbarbar FFF"
47 "foofoofoofoo AAAA aaaaaaaaa ghost busters barbarbar FFF";
51 _cleanup_free_ char *uncompressed = NULL;
53 assert_se(compress_blob(text, sizeof(text), compressed, &csize));
54 assert_se(uncompress_startswith(compressed,
56 (void **) &uncompressed,
58 "foofoofoofoo", 12, ' '));
59 assert_se(!uncompress_startswith(compressed,
61 (void **) &uncompressed,
63 "foofoofoofoo", 12, 'w'));
64 assert_se(!uncompress_startswith(compressed,
66 (void **) &uncompressed,
68 "barbarbar", 9, ' '));
71 int main(int argc, char *argv[]) {
72 test_compress_uncompress();
73 test_uncompress_startswith();