LCOV - code coverage report
Current view: top level - t - c-dump.c (source / functions) Hit Total Coverage
Test: PB-C-TEXT Code Coverage Lines: 22 26 84.6 %
Date: 2014-09-08 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #include <sys/types.h>
       2             : #include <unistd.h>
       3             : #include <stdio.h>
       4             : #include <string.h>
       5             : #include <stdlib.h>
       6             : #include <protobuf-c/protobuf-c.h>
       7             : #include "protobuf-c-text/protobuf-c-text.h"
       8             : #include "addressbook.pb-c.h"
       9             : #include "broken-alloc.h"
      10             : 
      11             : #define CHUNK 1024
      12             : 
      13             : Tutorial__AddressBook *ab;
      14             : 
      15             : Tutorial__AddressBook *
      16          33 : read_addressbook(char *filename)
      17             : {
      18             :   FILE *f;
      19          33 :   int bufsize = 0, bytes, bytes_total = 0;
      20          33 :   char *buf = NULL;
      21             :   Tutorial__AddressBook *ab;
      22             : 
      23          33 :   f = fopen(filename, "r");
      24          33 :   if (!f) {
      25           0 :     printf("Can't open addressbook file '%s'.\n", filename);
      26           0 :     exit(1);
      27             :   }
      28             :   do {
      29          33 :     bufsize += CHUNK;
      30          33 :     buf = realloc(buf, bufsize);
      31          33 :     bytes = fread(buf + bytes_total, 1, CHUNK, f);
      32          33 :     bytes_total += bytes;
      33          33 :   } while (bytes == CHUNK);
      34          33 :   ab = tutorial__address_book__unpack(NULL, bytes_total, buf);
      35          33 :   free(buf);
      36          33 :   return ab;
      37             : }
      38             : 
      39             : int
      40          33 : main(int argc, char *argv[])
      41             : {
      42             :   char *s;
      43             : 
      44          33 :   if (argc != 2) {
      45           0 :     printf("Must supply address book file.\n");
      46           0 :     exit(1);
      47             :   }
      48             : 
      49          33 :   ab = read_addressbook(argv[1]);
      50             : 
      51          33 :   s = protobuf_c_text_to_string((ProtobufCMessage *)ab, &broken_allocator);
      52          33 :   if (s) {
      53           2 :     printf("%s", s);
      54           2 :     free(s);
      55             :   } else {
      56          31 :     printf("ERROR: Failed to generate text format.\n");
      57             :   }
      58             : 
      59          33 :   return 0;
      60             : }

Generated by: LCOV version 1.10