Lasse Collin | bcc4b36 | 2009-03-22 13:12:47 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Test application for xz_boot.c |
| 3 | * |
| 4 | * Author: Lasse Collin <lasse.collin@tukaani.org> |
| 5 | * |
| 6 | * This file has been put into the public domain. |
| 7 | * You can do whatever you want with this file. |
| 8 | */ |
| 9 | |
Lasse Collin | 2889235 | 2009-05-26 11:07:45 +0300 | [diff] [blame] | 10 | #include <stdlib.h> |
| 11 | #include <string.h> |
Lasse Collin | bcc4b36 | 2009-03-22 13:12:47 +0200 | [diff] [blame] | 12 | #include <stdio.h> |
| 13 | |
Lasse Collin | 4d5e69a | 2010-11-20 10:14:29 +0200 | [diff] [blame] | 14 | #define STATIC static |
| 15 | #define INIT |
Lasse Collin | 2889235 | 2009-05-26 11:07:45 +0300 | [diff] [blame] | 16 | |
| 17 | static void error(/*const*/ char *msg) |
Lasse Collin | bcc4b36 | 2009-03-22 13:12:47 +0200 | [diff] [blame] | 18 | { |
| 19 | fprintf(stderr, "%s\n", msg); |
| 20 | } |
| 21 | |
Lasse Collin | 0568cfa | 2013-02-27 09:28:55 +0200 | [diff] [blame] | 22 | /* Disable the CRC64 support even if it was enabled in the Makefile. */ |
| 23 | #undef XZ_USE_CRC64 |
| 24 | |
Lasse Collin | 2889235 | 2009-05-26 11:07:45 +0300 | [diff] [blame] | 25 | #include "../linux/lib/decompress_unxz.c" |
Lasse Collin | bcc4b36 | 2009-03-22 13:12:47 +0200 | [diff] [blame] | 26 | |
| 27 | static uint8_t in[1024 * 1024]; |
| 28 | static uint8_t out[1024 * 1024]; |
Lasse Collin | bcc4b36 | 2009-03-22 13:12:47 +0200 | [diff] [blame] | 29 | |
Lasse Collin | 2889235 | 2009-05-26 11:07:45 +0300 | [diff] [blame] | 30 | static int fill(void *buf, unsigned int size) |
| 31 | { |
| 32 | return fread(buf, 1, size, stdin); |
| 33 | } |
| 34 | |
| 35 | static int flush(/*const*/ void *buf, unsigned int size) |
| 36 | { |
| 37 | return fwrite(buf, 1, size, stdout); |
| 38 | } |
| 39 | |
| 40 | static void test_buf_to_buf(void) |
| 41 | { |
| 42 | size_t in_size; |
| 43 | int ret; |
| 44 | in_size = fread(in, 1, sizeof(in), stdin); |
| 45 | ret = decompress(in, in_size, NULL, NULL, out, NULL, &error); |
| 46 | /* fwrite(out, 1, FIXME, stdout); */ |
| 47 | fprintf(stderr, "ret = %d\n", ret); |
| 48 | } |
| 49 | |
| 50 | static void test_buf_to_cb(void) |
| 51 | { |
| 52 | size_t in_size; |
| 53 | int in_used; |
| 54 | int ret; |
| 55 | in_size = fread(in, 1, sizeof(in), stdin); |
| 56 | ret = decompress(in, in_size, NULL, &flush, NULL, &in_used, &error); |
| 57 | fprintf(stderr, "ret = %d; in_used = %d\n", ret, in_used); |
| 58 | } |
| 59 | |
Lasse Collin | 2889235 | 2009-05-26 11:07:45 +0300 | [diff] [blame] | 60 | static void test_cb_to_cb(void) |
Lasse Collin | bcc4b36 | 2009-03-22 13:12:47 +0200 | [diff] [blame] | 61 | { |
| 62 | int ret; |
Lasse Collin | 2889235 | 2009-05-26 11:07:45 +0300 | [diff] [blame] | 63 | ret = decompress(NULL, 0, &fill, &flush, NULL, NULL, &error); |
| 64 | fprintf(stderr, "ret = %d\n", ret); |
| 65 | } |
Lasse Collin | bcc4b36 | 2009-03-22 13:12:47 +0200 | [diff] [blame] | 66 | |
Lasse Collin | 64a7180 | 2010-12-02 12:38:21 +0200 | [diff] [blame] | 67 | /* |
| 68 | * Not used by Linux <= 2.6.37-rc4 and newer probably won't use it either, |
| 69 | * but this kind of use case is still required to be supported by the API. |
| 70 | */ |
| 71 | static void test_cb_to_buf(void) |
| 72 | { |
| 73 | int in_used; |
| 74 | int ret; |
| 75 | ret = decompress(in, 0, &fill, NULL, out, &in_used, &error); |
| 76 | /* fwrite(out, 1, FIXME, stdout); */ |
| 77 | fprintf(stderr, "ret = %d; in_used = %d\n", ret, in_used); |
| 78 | } |
| 79 | |
Lasse Collin | 2889235 | 2009-05-26 11:07:45 +0300 | [diff] [blame] | 80 | int main(int argc, char **argv) |
| 81 | { |
| 82 | if (argc != 2) |
Lasse Collin | 64a7180 | 2010-12-02 12:38:21 +0200 | [diff] [blame] | 83 | fprintf(stderr, "Usage: %s [bb|bc|cc|cb]\n", argv[0]); |
Lasse Collin | 2889235 | 2009-05-26 11:07:45 +0300 | [diff] [blame] | 84 | else if (strcmp(argv[1], "bb") == 0) |
| 85 | test_buf_to_buf(); |
| 86 | else if (strcmp(argv[1], "bc") == 0) |
| 87 | test_buf_to_cb(); |
Lasse Collin | 2889235 | 2009-05-26 11:07:45 +0300 | [diff] [blame] | 88 | else if (strcmp(argv[1], "cc") == 0) |
| 89 | test_cb_to_cb(); |
Lasse Collin | 64a7180 | 2010-12-02 12:38:21 +0200 | [diff] [blame] | 90 | else if (strcmp(argv[1], "cb") == 0) |
| 91 | test_cb_to_buf(); |
Lasse Collin | 2889235 | 2009-05-26 11:07:45 +0300 | [diff] [blame] | 92 | else |
Lasse Collin | 64a7180 | 2010-12-02 12:38:21 +0200 | [diff] [blame] | 93 | fprintf(stderr, "Usage: %s [bb|bc|cc|cb]\n", argv[0]); |
Lasse Collin | bcc4b36 | 2009-03-22 13:12:47 +0200 | [diff] [blame] | 94 | |
Lasse Collin | bcc4b36 | 2009-03-22 13:12:47 +0200 | [diff] [blame] | 95 | return 0; |
| 96 | } |