summaryrefslogtreecommitdiff
path: root/lib/compression
diff options
context:
space:
mode:
authorbubulle <bubulle@alioth.debian.org>2012-01-26 19:58:37 +0000
committerbubulle <bubulle@alioth.debian.org>2012-01-26 19:58:37 +0000
commitcb25bc5ca98dff7a896f596f9f1586a4739ad8ec (patch)
tree31bd310956a0c533e3e46cb88aec6e00b5eedf53 /lib/compression
parent5f021ee1efe415ba8fe4281d0622204a68074ea8 (diff)
downloadsamba-cb25bc5ca98dff7a896f596f9f1586a4739ad8ec.tar.gz
Load samba-3.6.2 into branches/samba/upstream.upstream/3.6.2
git-svn-id: svn://svn.debian.org/svn/pkg-samba/branches/samba/upstream@3992 fc4039ab-9d04-0410-8cac-899223bdd6b0
Diffstat (limited to 'lib/compression')
-rw-r--r--lib/compression/lzxpress.c17
-rw-r--r--lib/compression/testsuite.c51
-rw-r--r--lib/compression/wscript_build6
3 files changed, 65 insertions, 9 deletions
diff --git a/lib/compression/lzxpress.c b/lib/compression/lzxpress.c
index 0abbfc4d3d..a4ded7e455 100644
--- a/lib/compression/lzxpress.c
+++ b/lib/compression/lzxpress.c
@@ -34,6 +34,7 @@
#include "replace.h"
#include "lzxpress.h"
+#include "../lib/util/byteorder.h"
#define __BUF_POS_CONST(buf,ofs)(((const uint8_t *)buf)+(ofs))
@@ -80,6 +81,7 @@ ssize_t lzxpress_compress(const uint8_t *uncompressed,
uncompressed_pos = 0;
indic = 0;
+ *(uint32_t *)compressed = 0;
compressed_pos = sizeof(uint32_t);
indic_pos = &compressed[0];
@@ -129,11 +131,11 @@ ssize_t lzxpress_compress(const uint8_t *uncompressed,
if (best_len < 10) {
/* Classical meta-data */
metadata = (uint16_t)(((best_offset - 1) << 3) | (best_len - 3));
- dest[metadata_size / sizeof(uint16_t)] = metadata;
+ SSVAL(dest, metadata_size / sizeof(uint16_t), metadata);
metadata_size += sizeof(uint16_t);
} else {
metadata = (uint16_t)(((best_offset - 1) << 3) | 7);
- dest[metadata_size / sizeof(uint16_t)] = metadata;
+ SSVAL(dest, metadata_size / sizeof(uint16_t), metadata);
metadata_size = sizeof(uint16_t);
if (best_len < (15 + 7 + 3)) {
@@ -155,7 +157,7 @@ ssize_t lzxpress_compress(const uint8_t *uncompressed,
compressed[nibble_index] |= (15 * 16);
}
- /* Additionnal best_len */
+ /* Additional best_len */
compressed[compressed_pos + metadata_size] = (best_len - (3 + 7 + 15)) & 0xFF;
metadata_size += sizeof(uint8_t);
} else {
@@ -167,7 +169,7 @@ ssize_t lzxpress_compress(const uint8_t *uncompressed,
compressed[nibble_index] |= 15 << 4;
}
- /* Additionnal best_len */
+ /* Additional best_len */
compressed[compressed_pos + metadata_size] = 255;
metadata_size += sizeof(uint8_t);
@@ -198,7 +200,7 @@ ssize_t lzxpress_compress(const uint8_t *uncompressed,
indic_bit++;
if ((indic_bit - 1) % 32 > (indic_bit % 32)) {
- *(uint32_t *)indic_pos = indic;
+ SIVAL(indic_pos, 0, indic);
indic = 0;
indic_pos = &compressed[compressed_pos];
compressed_pos += sizeof(uint32_t);
@@ -212,7 +214,7 @@ ssize_t lzxpress_compress(const uint8_t *uncompressed,
uncompressed_pos++;
compressed_pos++;
if (((indic_bit - 1) % 32) > (indic_bit % 32)){
- *(uint32_t *)indic_pos = indic;
+ SIVAL(indic_pos, 0, indic);
indic = 0;
indic_pos = &compressed[compressed_pos];
compressed_pos += sizeof(uint32_t);
@@ -223,7 +225,8 @@ ssize_t lzxpress_compress(const uint8_t *uncompressed,
for (; (indic_bit % 32) != 0; indic_bit++)
indic |= 0 << (32 - ((indic_bit % 32) + 1));
- *(uint32_t *)indic_pos = indic;
+ *(uint32_t *)&compressed[compressed_pos] = 0;
+ SIVAL(indic_pos, 0, indic);
compressed_pos += sizeof(uint32_t);
}
diff --git a/lib/compression/testsuite.c b/lib/compression/testsuite.c
index b9cebb2e8d..ff7d892e64 100644
--- a/lib/compression/testsuite.c
+++ b/lib/compression/testsuite.c
@@ -20,11 +20,58 @@
#include "includes.h"
#include "torture/torture.h"
-#include "../compression/mszip.h"
+#include "talloc.h"
+#include "mszip.h"
+#include "lzxpress.h"
+
+/*
+ test lzxpress
+ */
+static bool test_lzxpress(struct torture_context *test)
+{
+ TALLOC_CTX *tmp_ctx = talloc_new(test);
+ uint8_t *data;
+ const char *fixed_data = "this is a test. and this is a test too";
+ const uint8_t fixed_out[] = { 0x00, 0x20, 0x00, 0x04, 0x74, 0x68, 0x69, 0x73,
+ 0x20, 0x10, 0x00, 0x61, 0x20, 0x74, 0x65, 0x73,
+ 0x74, 0x2E, 0x20, 0x61, 0x6E, 0x64, 0x20, 0x9F,
+ 0x00, 0x04, 0x20, 0x74, 0x6F, 0x6F, 0x00, 0x00,
+ 0x00, 0x00 };
+ ssize_t c_size;
+ uint8_t *out, *out2;
+
+ data = talloc_size(tmp_ctx, 1023);
+ out = talloc_size(tmp_ctx, 2048);
+ memset(out, 0x42, talloc_get_size(out));
+
+ torture_comment(test, "lzxpress fixed compression\n");
+ c_size = lzxpress_compress((const uint8_t *)fixed_data,
+ strlen(fixed_data),
+ out,
+ talloc_get_size(out));
+
+ torture_assert_int_equal(test, c_size, sizeof(fixed_out), "fixed lzxpress_compress size");
+ torture_assert_mem_equal(test, out, fixed_out, c_size, "fixed lzxpress_compress data");
+
+ torture_comment(test, "lzxpress fixed decompression\n");
+ out2 = talloc_size(tmp_ctx, strlen(fixed_data));
+ c_size = lzxpress_decompress(out,
+ sizeof(fixed_out),
+ out2,
+ talloc_get_size(out2));
+
+ torture_assert_int_equal(test, c_size, strlen(fixed_data), "fixed lzxpress_decompress size");
+ torture_assert_mem_equal(test, out2, fixed_data, c_size, "fixed lzxpress_decompress data");
+
+ return true;
+}
+
struct torture_suite *torture_local_compression(TALLOC_CTX *mem_ctx)
{
- struct torture_suite *suite = torture_suite_create(mem_ctx, "COMPRESSION");
+ struct torture_suite *suite = torture_suite_create(mem_ctx, "compression");
+
+ torture_suite_add_simple_test(suite, "lzxpress", test_lzxpress);
return suite;
}
diff --git a/lib/compression/wscript_build b/lib/compression/wscript_build
new file mode 100644
index 0000000000..7ad533340d
--- /dev/null
+++ b/lib/compression/wscript_build
@@ -0,0 +1,6 @@
+#!/usr/bin/env python
+
+bld.SAMBA_SUBSYSTEM('LZXPRESS',
+ deps='replace',
+ source='lzxpress.c'
+ )