Test parsing of header and encoding
authorGabriel F. T. Gomes <gabriel@gftg.com.br>
Sun, 13 Mar 2016 19:34:54 +0000 (16:34 -0300)
committerThadeu Lima de Souza Cascardo <cascardo@cascardo.eti.br>
Wed, 6 Apr 2016 10:49:37 +0000 (07:49 -0300)
This test opens DEC files from the years supported by rnetclient, parse their
headers and encode the data for transmission. The DEC files contain only
fictitious information.

.gitignore
Makefile.am
configure.ac
data/12345678909-IRPF-A-2013-2012-ORIGI.DEC [new file with mode: 0644]
data/12345678909-IRPF-A-2014-2013-ORIGI.DEC [new file with mode: 0644]
data/12345678909-IRPF-A-2015-2014-ORIGI.DEC [new file with mode: 0644]
data/12345678909-IRPF-A-2016-2015-ORIGI.DEC [new file with mode: 0644]
data/Makefile.am [new file with mode: 0644]
t-parse.c [new file with mode: 0644]

index c62646f..37d408a 100644 (file)
@@ -13,3 +13,8 @@ config.h*
 # Object files
 *.o
 rnetclient
+
+# Test files
+*.log
+*.trs
+t-parse
index 2b45a72..02dc7e5 100644 (file)
@@ -1,5 +1,12 @@
-SUBDIRS = doc
+SUBDIRS = doc data
 
 bin_PROGRAMS = rnetclient
 rnetclient_SOURCES = rnetclient.c decfile.c decfile.h pmhash.c pmhash.h \
        rnet_message.c rnet_message.h rnet_encode.c rnet_encode.h
+
+check_PROGRAMS = t-parse
+t_parse_SOURCES = t-parse.c decfile.c decfile.h pmhash.c pmhash.h \
+       rnet_message.c rnet_message.h rnet_encode.c rnet_encode.h
+t_parse_CFLAGS = -DSRCDIR=\"$(abs_top_srcdir)\"
+
+TESTS = $(check_PROGRAMS)
index 03d2e92..53dc60c 100644 (file)
@@ -52,6 +52,7 @@ $CFLAGS"
 dnl Outputting the necessary files for the build.
 AC_CONFIG_HEADERS([config.h])
 AC_OUTPUT([Makefile]
+         [data/Makefile]
          [doc/Makefile]
          [doc/man/Makefile]
          [doc/man/pt_BR/Makefile])
diff --git a/data/12345678909-IRPF-A-2013-2012-ORIGI.DEC b/data/12345678909-IRPF-A-2013-2012-ORIGI.DEC
new file mode 100644 (file)
index 0000000..c2e6b9e
--- /dev/null
@@ -0,0 +1,8 @@
+IRPF    201320122300012345678909   1150JOAQUIM MARIA MACHADO DE ASSIS                              RJ1321200096101012000S0S          2LINUX         4.2.6-31.8.0_72           6001           000000000000001234567890200002100000000000000 000000000000000000000                                    0000000000000                                                                                                                                                                                                                            RIO DE JANEIRO                          JOAQUIM MARIA MACHADO DE ASSIS                                         94DE807B0F8D00000000           0000000000000000                            000000000000000000000000000000000000000   0888818345\r
+1612345678909JOAQUIM MARIA MACHADO DE ASSIS                              RUA            COSME VELHO                             1                                             21000000 6001RIO DE JANEIRO                          RJ   105                                                                                                                             01012000123456780396 266110SNSN            0000000N                N0              1234567890A0268768295\r
+1912345678909              00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000193070458\r
+2012345678909000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004291363080\r
+T912345678909000004000010000000000000010000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000    000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002116812726\r
+HR12345678909   1670646968\r
+DR12345678909   SJOAQUIM MARIA MACHADO DE ASSIS                              RUA            COSME VELHO                             1                                             21000000 6001RIO DE JANEIRO                          RJ                                                                                                                             N0000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000               00000000000002583852340\r
+R912345678909   39582221450644435249\r
diff --git a/data/12345678909-IRPF-A-2014-2013-ORIGI.DEC b/data/12345678909-IRPF-A-2014-2013-ORIGI.DEC
new file mode 100644 (file)
index 0000000..6180a83
--- /dev/null
@@ -0,0 +1,8 @@
+IRPF    201420132400012345678909   1160JOAQUIM MARIA MACHADO DE ASSIS                              RJ4007331496101012000S0S          2LINUX         4.2.6-31.8.0_72           6001           000000000000001234567890200002100000000000000 000000000000000000000                                                0000000000000                                                                                                                                                                                                                            RIO DE JANEIRO                          JOAQUIM MARIA MACHADO DE ASSIS                                         94DE807B0F8D00000000           0000000000000000                            000000000000000000000000000000000000000               0   2867674185\r
+1612345678909JOAQUIM MARIA MACHADO DE ASSIS                              RUA            COSME VELHO                             1                                             21000000 6001RIO DE JANEIRO                          RJ   105                                                                                                                             01012000123456780396 266110SNSN            0000000N0               N0              1234567890A           1259370438\r
+1912345678909              00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000193070458\r
+2012345678909000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004291363080\r
+T912345678909000004000010000000000000010000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000    000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003464148678\r
+HR12345678909   1670646968\r
+DR12345678909   SJOAQUIM MARIA MACHADO DE ASSIS                              RUA            COSME VELHO                             1                                             21000000 6001RIO DE JANEIRO                          RJ                                                                                                                             N0000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000               00000000000002583852340\r
+R912345678909   28634939210340387355\r
diff --git a/data/12345678909-IRPF-A-2015-2014-ORIGI.DEC b/data/12345678909-IRPF-A-2015-2014-ORIGI.DEC
new file mode 100644 (file)
index 0000000..779c7d8
--- /dev/null
@@ -0,0 +1,8 @@
+IRPF    201520142500012345678909   1130JOAQUIM MARIA MACHADO DE ASSIS                              RJ1115462690101012000S0S          2LINUX         4.2.6-31.8.0_72           6001           000000000000001234567890200002100000000000000 000000000000000000000                                                0000000000000                                                                                                                                                                                                                            RIO DE JANEIRO                          JOAQUIM MARIA MACHADO DE ASSIS                                         94DE807B0F8D00000000           0000000000000000                            000000000000000000000000000000000000000               011                                                                  1100000001   0468715280\r
+1612345678909JOAQUIM MARIA MACHADO DE ASSIS                              RUA            COSME VELHO                             1                                             21000000 6001RIO DE JANEIRO                          RJ   105                                                                                                                             01012000123456780396 266110SNSN            0000000N0               N0              1234567890A           1259370438\r
+1912345678909              00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000193070458\r
+2012345678909000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004291363080\r
+T912345678909000004000010000000000000010000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000    0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004010792585\r
+HR12345678909   1670646968\r
+DR12345678909   SJOAQUIM MARIA MACHADO DE ASSIS                              RUA            COSME VELHO                             1                                             21000000 6001RIO DE JANEIRO                          RJ                                                                                                                             N0000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000               00000000000002583852340\r
+R912345678909   17860739000115671359\r
diff --git a/data/12345678909-IRPF-A-2016-2015-ORIGI.DEC b/data/12345678909-IRPF-A-2016-2015-ORIGI.DEC
new file mode 100644 (file)
index 0000000..ff35d52
--- /dev/null
@@ -0,0 +1,8 @@
+IRPF    201620152600012345678909   1110JOAQUIM MARIA MACHADO DE ASSIS                              RJ2119917808101012000S0S          2LINUX         4.2.6-31.8.0_72           6001           000000000000001234567890200002100000000000000 000000000000000000000                                                0000000000000                                                                                                                                                                                                                            RIO DE JANEIRO                          JOAQUIM MARIA MACHADO DE ASSIS                                         94DE807B0F8D00000000           0000000000000000                            000000000000000000000000000000000000000               011                                                                  1100000001                                                                                                     1034069486\r
+1612345678909JOAQUIM MARIA MACHADO DE ASSIS                              RUA            COSME VELHO                             1                                             21000000 6001RIO DE JANEIRO                          RJ   105                                                                                                                             01012000123456780396 266110SNSN            0000000N0               N0              1234567890A                               0439317218\r
+1912345678909              0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003417993840\r
+2012345678909000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004291363080\r
+T912345678909000004000010000000000000010000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000    000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000665831501\r
+HR12345678909   1670646968\r
+DR12345678909   SJOAQUIM MARIA MACHADO DE ASSIS                              RUA            COSME VELHO                             1                                             21000000 6001RIO DE JANEIRO                          RJ                                                                                                                             N0000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000               00000000000002583852340\r
+R912345678909   42895113931825258592\r
diff --git a/data/Makefile.am b/data/Makefile.am
new file mode 100644 (file)
index 0000000..1288709
--- /dev/null
@@ -0,0 +1 @@
+EXTRA_DIST = .
diff --git a/t-parse.c b/t-parse.c
new file mode 100644 (file)
index 0000000..827dcec
--- /dev/null
+++ b/t-parse.c
@@ -0,0 +1,54 @@
+/*
+ *  Copyright (C) 2016  Gabriel F. T. Gomes <gabriel@gftg.com.br>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+
+#include "decfile.h"
+#include "rnet_encode.h"
+
+int main(void)
+{
+       int i, r;
+       struct rnet_decfile *decfile;
+       struct rnet_message *message = NULL;
+       char *filename[4] = {
+               SRCDIR"/data/12345678909-IRPF-A-2013-2012-ORIGI.DEC",
+               SRCDIR"/data/12345678909-IRPF-A-2014-2013-ORIGI.DEC",
+               SRCDIR"/data/12345678909-IRPF-A-2015-2014-ORIGI.DEC",
+               SRCDIR"/data/12345678909-IRPF-A-2016-2015-ORIGI.DEC"
+       };
+
+       for (i = 0; i < 4; i++) {
+
+               decfile = rnet_decfile_open(filename[i]);
+               if (decfile == NULL) {
+                       fprintf(stderr, "Error opening DEC file.\n");
+                       return -1;
+               }
+
+               r = rnet_encode(decfile, &message);
+               if (r < 0) {
+                       fprintf(stderr, "Error encoding message\n");
+                       return -1;
+               }
+
+               rnet_message_del(message);
+       }
+
+       return 0;
+}