summaryrefslogtreecommitdiff
path: root/lib/test.c
blob: 6ba81877ba4c6be729b1934822d41a9813b3eb60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "system.h"

#include <rpmlib.h>

void main(int argc, char **argv)
{
    Header h, h2, h3, h4;
    int fd;
    char *sa[] = {"one", "two", "three"};
    int_32 i32 = 400;
    int_32 i32a[] = {100, 200, 300};
    int_16 i16 = 1;
    int_16 i16a[] = {100, 200, 300};
    char ca[] = "char array";
    int rc;

    h = headerNew();

    headerAddEntry(h, RPMTAG_NAME, RPM_STRING_TYPE, "MarcEwing", 1);
    headerAddEntry(h, RPMTAG_VERSION, RPM_STRING_TYPE, "1.1", 1);
    headerAddEntry(h, RPMTAG_VERSION, RPM_STRING_ARRAY_TYPE, sa, 3);
    headerAddEntry(h, RPMTAG_SIZE, RPM_INT32_TYPE, &i32, 1);
    headerAddEntry(h, RPMTAG_SIZE, RPM_INT16_TYPE, &i16, 1);
    headerAddEntry(h, RPMTAG_SIZE, RPM_INT16_TYPE, i16a, 3);
    headerAddEntry(h, RPMTAG_VENDOR, RPM_CHAR_TYPE, ca, strlen(ca));
    headerAddEntry(h, RPMTAG_SIZE, RPM_INT32_TYPE, i32a, 3);

    fprintf(stdout, "Original = %d\n", headerSizeof(h));
    fd = open("test.out", O_WRONLY|O_CREAT);
    rc = headerWrite(fd, h);
    close(fd);
    h2 = headerCopy(h);
    fprintf(stdout, "Copy     = %d\n", headerSizeof(h2));

    fd = open("test.out", O_RDONLY);
    h3 = headerRead(fd);
    close(fd);
   
    fprintf(stdout, "From disk    = %d\n", headerSizeof(h3));
    h4 = headerCopy(h3);
    fprintf(stdout, "Copy of disk = %d\n", headerSizeof(h4));
   
    fprintf(stdout, "=====================\n");
    fprintf(stdout, "Original\n");
    headerDump(h, stdout, 1);
    fprintf(stdout, "=====================\n");
    fprintf(stdout, "From disk\n");
    headerDump(h3, stdout, 1);
    fprintf(stdout, "=====================\n");
    fprintf(stdout, "Copy of disk\n");
    headerDump(h4, stdout, 1);

#if 0
    convertDB("");
#endif
}