home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 February / CHIP_2_98.iso / misc / src / rpm / lib / test.c < prev    next >
C/C++ Source or Header  |  1997-09-17  |  2KB  |  60 lines

  1. #include <sys/types.h>
  2. #include <sys/stat.h>
  3. #include <fcntl.h>
  4. #include <string.h>
  5.  
  6. #include "header.h"
  7. #include "rpmlib.h"
  8.  
  9. void main(int argc, char **argv)
  10. {
  11.     Header h, h2, h3, h4;
  12.     int fd;
  13.     char *sa[] = {"one", "two", "three"};
  14.     int_32 i32 = 400;
  15.     int_32 i32a[] = {100, 200, 300};
  16.     int_16 i16 = 1;
  17.     int_16 i16a[] = {100, 200, 300};
  18.     char ca[] = "char array";
  19.  
  20.     h = headerNew();
  21.  
  22.     headerAddEntry(h, RPMTAG_NAME, RPM_STRING_TYPE, "MarcEwing", 1);
  23.     headerAddEntry(h, RPMTAG_VERSION, RPM_STRING_TYPE, "1.1", 1);
  24.     headerAddEntry(h, RPMTAG_VERSION, RPM_STRING_ARRAY_TYPE, sa, 3);
  25.     headerAddEntry(h, RPMTAG_SIZE, RPM_INT32_TYPE, &i32, 1);
  26.     headerAddEntry(h, RPMTAG_SIZE, RPM_INT16_TYPE, &i16, 1);
  27.     headerAddEntry(h, RPMTAG_SIZE, RPM_INT16_TYPE, i16a, 3);
  28.     headerAddEntry(h, RPMTAG_VENDOR, RPM_CHAR_TYPE, ca, strlen(ca));
  29.     headerAddEntry(h, RPMTAG_SIZE, RPM_INT32_TYPE, i32a, 3);
  30.  
  31.     printf("Original = %d\n", headerSizeof(h));
  32.     fd = open("test.out", O_WRONLY|O_CREAT);
  33.     headerWrite(fd, h);
  34.     close(fd);
  35.     h2 = headerCopy(h);
  36.     printf("Copy     = %d\n", headerSizeof(h2));
  37.  
  38.     fd = open("test.out", O_RDONLY);
  39.     h3 = headerRead(fd);
  40.     close(fd);
  41.    
  42.     printf("From disk    = %d\n", headerSizeof(h3));
  43.     h4 = headerCopy(h3);
  44.     printf("Copy of disk = %d\n", headerSizeof(h4));
  45.    
  46.     printf("=====================\n");
  47.     printf("Original\n");
  48.     headerDump(h, stdout, 1);
  49.     printf("=====================\n");
  50.     printf("From disk\n");
  51.     headerDump(h3, stdout, 1);
  52.     printf("=====================\n");
  53.     printf("Copy of disk\n");
  54.     headerDump(h4, stdout, 1);
  55.  
  56. #if 0
  57.     convertDB("");
  58. #endif
  59. }
  60.