blob: 1aef5ed69d1142e13633e735aa9799741dd4cfd8 [file] [log] [blame]
Lasse Collinbcc4b362009-03-22 13:12:47 +02001/*
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 Collin28892352009-05-26 11:07:45 +030010#include <stdlib.h>
11#include <string.h>
Lasse Collinbcc4b362009-03-22 13:12:47 +020012#include <stdio.h>
13
Lasse Collin4d5e69a2010-11-20 10:14:29 +020014#define STATIC static
15#define INIT
Lasse Collin28892352009-05-26 11:07:45 +030016
17static void error(/*const*/ char *msg)
Lasse Collinbcc4b362009-03-22 13:12:47 +020018{
19 fprintf(stderr, "%s\n", msg);
20}
21
Lasse Collin0568cfa2013-02-27 09:28:55 +020022/* Disable the CRC64 support even if it was enabled in the Makefile. */
23#undef XZ_USE_CRC64
24
Lasse Collin28892352009-05-26 11:07:45 +030025#include "../linux/lib/decompress_unxz.c"
Lasse Collinbcc4b362009-03-22 13:12:47 +020026
27static uint8_t in[1024 * 1024];
28static uint8_t out[1024 * 1024];
Lasse Collinbcc4b362009-03-22 13:12:47 +020029
Lasse Collin28892352009-05-26 11:07:45 +030030static int fill(void *buf, unsigned int size)
31{
32 return fread(buf, 1, size, stdin);
33}
34
35static int flush(/*const*/ void *buf, unsigned int size)
36{
37 return fwrite(buf, 1, size, stdout);
38}
39
40static 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
50static 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 Collin28892352009-05-26 11:07:45 +030060static void test_cb_to_cb(void)
Lasse Collinbcc4b362009-03-22 13:12:47 +020061{
62 int ret;
Lasse Collin28892352009-05-26 11:07:45 +030063 ret = decompress(NULL, 0, &fill, &flush, NULL, NULL, &error);
64 fprintf(stderr, "ret = %d\n", ret);
65}
Lasse Collinbcc4b362009-03-22 13:12:47 +020066
Lasse Collin64a71802010-12-02 12:38:21 +020067/*
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 */
71static 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 Collin28892352009-05-26 11:07:45 +030080int main(int argc, char **argv)
81{
82 if (argc != 2)
Lasse Collin64a71802010-12-02 12:38:21 +020083 fprintf(stderr, "Usage: %s [bb|bc|cc|cb]\n", argv[0]);
Lasse Collin28892352009-05-26 11:07:45 +030084 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 Collin28892352009-05-26 11:07:45 +030088 else if (strcmp(argv[1], "cc") == 0)
89 test_cb_to_cb();
Lasse Collin64a71802010-12-02 12:38:21 +020090 else if (strcmp(argv[1], "cb") == 0)
91 test_cb_to_buf();
Lasse Collin28892352009-05-26 11:07:45 +030092 else
Lasse Collin64a71802010-12-02 12:38:21 +020093 fprintf(stderr, "Usage: %s [bb|bc|cc|cb]\n", argv[0]);
Lasse Collinbcc4b362009-03-22 13:12:47 +020094
Lasse Collinbcc4b362009-03-22 13:12:47 +020095 return 0;
96}