1 #include "tpl.h"
2 #include <stdio.h>
3 #include <string.h>
4 #include <inttypes.h>
5 
6 typedef struct {
7   int64_t j;
8   int l1;
9   unsigned l2;
10   int i;
11   int16_t h;
12   char c[4];
13 } test_t;
14 
15 const char *filename = "/tmp/test108.tpl";
16 
main()17 int main() {
18   test_t s[5], t[5];
19   tpl_node *tn;
20   int w=10,x=20,y=30,z=40,W,X,Y,Z;
21   uint64_t b=10,B;
22 
23   memset(s, 0, sizeof(s));
24   memset(t, 0, sizeof(t));
25 
26   s[0].j=0;   s[0].i=0; s[0].l1= 0; s[0].l2=0;  s[0].h=   0; strcpy(s[0].c, "cat");
27   s[1].j=100; s[1].i=1; s[1].l1=-1; s[1].l2=10; s[1].h=1000; strcpy(s[1].c, "dog");
28   s[2].j=200; s[2].i=2; s[2].l1=-2; s[2].l2=20; s[2].h=2000; strcpy(s[2].c, "eel");
29   s[3].j=300; s[3].i=3; s[3].l1=-3; s[3].l2=30; s[3].h=3000; strcpy(s[3].c, "emu");
30   s[4].j=400; s[4].i=4; s[4].l1=-4; s[4].l2=40; s[4].h=4000; strcpy(s[4].c, "ant");
31 
32   tn = tpl_map("IS(Iiuijc#)#iiii", &b, s, 4, 5, &w, &x, &y, &z);
33   tpl_pack(tn,0);
34   tpl_dump(tn,TPL_FILE,filename);
35   tpl_free(tn);
36 
37   tn = tpl_map("IS(Iiuijc#)#iiii", &B, t, 4, 5, &W, &X, &Y, &Z);
38   tpl_load(tn,TPL_FILE,filename);
39   tpl_unpack(tn,0);
40   tpl_free(tn);
41 
42   if (memcmp(t,s,sizeof(t)) == 0) printf("structure matches original\n");
43   else printf("structure mismatches original\n");
44 
45   if (b==B && w==W && x==X && y==Y && z==Z) printf("other fields match original\n");
46   else printf("other fields mismatch originals\n");
47 
48   return 0;
49 }
50