1 | /*
|
---|
2 | Unix SMB/CIFS implementation.
|
---|
3 | test suite for the compression functions
|
---|
4 |
|
---|
5 | Copyright (C) Jelmer Vernooij 2007
|
---|
6 |
|
---|
7 | This program is free software; you can redistribute it and/or modify
|
---|
8 | it 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 | This program is distributed in the hope that it will be useful,
|
---|
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | GNU General Public 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 |
|
---|
21 | #include "includes.h"
|
---|
22 | #include "torture/torture.h"
|
---|
23 | #include "torture/local/proto.h"
|
---|
24 | #include "talloc.h"
|
---|
25 | #include "lzxpress.h"
|
---|
26 |
|
---|
27 | /*
|
---|
28 | test lzxpress
|
---|
29 | */
|
---|
30 | static bool test_lzxpress(struct torture_context *test)
|
---|
31 | {
|
---|
32 | TALLOC_CTX *tmp_ctx = talloc_new(test);
|
---|
33 | const char *fixed_data = "this is a test. and this is a test too";
|
---|
34 | const uint8_t fixed_out[] = { 0x00, 0x20, 0x00, 0x04, 0x74, 0x68, 0x69, 0x73,
|
---|
35 | 0x20, 0x10, 0x00, 0x61, 0x20, 0x74, 0x65, 0x73,
|
---|
36 | 0x74, 0x2E, 0x20, 0x61, 0x6E, 0x64, 0x20, 0x9F,
|
---|
37 | 0x00, 0x04, 0x20, 0x74, 0x6F, 0x6F, 0x00, 0x00,
|
---|
38 | 0x00, 0x00 };
|
---|
39 | ssize_t c_size;
|
---|
40 | uint8_t *out, *out2;
|
---|
41 |
|
---|
42 | out = talloc_size(tmp_ctx, 2048);
|
---|
43 | memset(out, 0x42, talloc_get_size(out));
|
---|
44 |
|
---|
45 | torture_comment(test, "lzxpress fixed compression\n");
|
---|
46 | c_size = lzxpress_compress((const uint8_t *)fixed_data,
|
---|
47 | strlen(fixed_data),
|
---|
48 | out,
|
---|
49 | talloc_get_size(out));
|
---|
50 |
|
---|
51 | torture_assert_int_equal(test, c_size, sizeof(fixed_out), "fixed lzxpress_compress size");
|
---|
52 | torture_assert_mem_equal(test, out, fixed_out, c_size, "fixed lzxpress_compress data");
|
---|
53 |
|
---|
54 | torture_comment(test, "lzxpress fixed decompression\n");
|
---|
55 | out2 = talloc_size(tmp_ctx, strlen(fixed_data));
|
---|
56 | c_size = lzxpress_decompress(out,
|
---|
57 | sizeof(fixed_out),
|
---|
58 | out2,
|
---|
59 | talloc_get_size(out2));
|
---|
60 |
|
---|
61 | torture_assert_int_equal(test, c_size, strlen(fixed_data), "fixed lzxpress_decompress size");
|
---|
62 | torture_assert_mem_equal(test, out2, fixed_data, c_size, "fixed lzxpress_decompress data");
|
---|
63 |
|
---|
64 | return true;
|
---|
65 | }
|
---|
66 |
|
---|
67 |
|
---|
68 | struct torture_suite *torture_local_compression(TALLOC_CTX *mem_ctx)
|
---|
69 | {
|
---|
70 | struct torture_suite *suite = torture_suite_create(mem_ctx, "compression");
|
---|
71 |
|
---|
72 | torture_suite_add_simple_test(suite, "lzxpress", test_lzxpress);
|
---|
73 |
|
---|
74 | return suite;
|
---|
75 | }
|
---|