LCOV - code coverage report
Current view: top level - t - c-dump2.c (source / functions) Hit Total Coverage
Test: PB-C-TEXT Code Coverage Lines: 21 26 80.8 %
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             : 
      10             : #define CHUNK 1024
      11             : 
      12             : Tutorial__Test *testmsg;
      13             : 
      14             : Tutorial__Test *
      15           1 : read_tutorial_test(char *filename)
      16             : {
      17             :   FILE *f;
      18           1 :   int bufsize = 0, bytes, bytes_total = 0;
      19           1 :   char *buf = NULL;
      20             :   Tutorial__Test *testmsg;
      21             : 
      22           1 :   f = fopen(filename, "r");
      23           1 :   if (!f) {
      24           0 :     printf("Can't open tutorial test message data file '%s'.\n", filename);
      25           0 :     exit(1);
      26             :   }
      27             :   do {
      28           1 :     bufsize += CHUNK;
      29           1 :     buf = realloc(buf, bufsize);
      30           1 :     bytes = fread(buf + bytes_total, 1, CHUNK, f);
      31           1 :     bytes_total += bytes;
      32           1 :   } while (bytes == CHUNK);
      33           1 :   testmsg = tutorial__test__unpack(NULL, bytes_total, buf);
      34           1 :   free(buf);
      35           1 :   return testmsg;
      36             : }
      37             : 
      38             : int
      39           1 : main(int argc, char *argv[])
      40             : {
      41             :   char *s;
      42             : 
      43           1 :   if (argc != 2) {
      44           0 :     printf("Must supply tutorial test message data file.\n");
      45           0 :     exit(1);
      46             :   }
      47             : 
      48           1 :   testmsg = read_tutorial_test(argv[1]);
      49             : 
      50           1 :   s = protobuf_c_text_to_string((ProtobufCMessage *)testmsg, NULL);
      51           1 :   if (s) {
      52           1 :     printf("%s", s);
      53           1 :     free(s);
      54             :   } else {
      55           0 :     printf("ERROR: Failed to generate text format.\n");
      56             :   }
      57             : 
      58           1 :   return 0;
      59             : }

Generated by: LCOV version 1.10