LCOV - code coverage report
Current view: top level - t - c-parse2.c (source / functions) Hit Total Coverage
Test: PB-C-TEXT Code Coverage Lines: 19 27 70.4 %
Date: 2014-09-08 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #include <sys/types.h>
       2             : #include <sys/stat.h>
       3             : #include <unistd.h>
       4             : #include <stdio.h>
       5             : #include <string.h>
       6             : #include <stdlib.h>
       7             : #include <protobuf-c/protobuf-c.h>
       8             : #include "protobuf-c-text/protobuf-c-text.h"
       9             : #include "addressbook.pb-c.h"
      10             : #include "broken-alloc.h"
      11             : 
      12             : #define CHUNK 1024
      13             : 
      14             : int
      15         148 : main(int argc, char *argv[])
      16             : {
      17             :   ProtobufCTextError tf_res;
      18             :   Tutorial__Test *testmsg;
      19             :   size_t len;
      20             :   uint8_t *buf;
      21             :   FILE *out;
      22             : 
      23         148 :   testmsg = (Tutorial__Test *)protobuf_c_text_from_file(
      24             :             &tutorial__test__descriptor,
      25             :             stdin, &tf_res, &broken_allocator);
      26         148 :   if (tf_res.error_txt) {
      27         142 :     printf("ERROR on import:\n%s", tf_res.error_txt);
      28         142 :     free(tf_res.error_txt);
      29         142 :     exit(1);
      30             :   }
      31           6 :   if (!tf_res.complete) {
      32           0 :     printf("ERROR on import: message not complete.an");
      33           0 :     if (testmsg) {
      34           0 :       tutorial__test__free_unpacked(testmsg, &broken_allocator);
      35             :     }
      36           0 :     exit(1);
      37             :   }
      38           6 :   if (!testmsg) {
      39           4 :     printf("ERROR malloc failures.\n");
      40           4 :     exit(1);
      41             :   }
      42             : 
      43           2 :   len = tutorial__test__get_packed_size(testmsg);
      44           2 :   buf = malloc(len);
      45           2 :   tutorial__test__pack(testmsg, buf);
      46           2 :   if (argv[1]) {
      47           2 :     out = fopen(argv[1], "w");
      48           2 :     if (len != fwrite(buf, 1, len, out)) {
      49           0 :       printf("ERROR: Protobuf output file truncated.");
      50           0 :       exit(1);
      51             :     }
      52           2 :     fclose(out);
      53             :   } else {
      54           0 :     printf("ERROR: Name for protobuf output file not provided.");
      55           0 :     exit(1);
      56             :   }
      57             : 
      58           2 :   tutorial__test__free_unpacked(testmsg, &broken_allocator);
      59             : 
      60           2 :   exit(0);
      61             : }

Generated by: LCOV version 1.10