1 /*
2 ** Copyright (C) 2010-2012 Erik de Castro Lopo <erikd@mega-nerd.com>
3 **
4 ** This program is free software; you can redistribute it and/or modify
5 ** it under the terms of the GNU Lesser General Public License as published by
6 ** the Free Software Foundation; either version 2.1 of the License, or
7 ** (at your option) any later version.
8 **
9 ** This program is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ** GNU Lesser General Public License for more details.
13 **
14 ** You should have received a copy of the GNU Lesser General Public License
15 ** along with this program; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19 #include "sfconfig.h"
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24
25 #include "common.h"
26
27 #include "test_main.h"
28
29 #define BCAST_MAX 512
30
31 typedef SF_BROADCAST_INFO_VAR (BCAST_MAX) SF_BROADCAST_INFO_512 ;
32
33 static void
fill_coding_history(SF_BROADCAST_INFO_512 * bi)34 fill_coding_history (SF_BROADCAST_INFO_512 * bi)
35 { static const char *lines [] =
36 { "Lorem ipsum dolor sit amet,\nconsectetur adipiscing elit.",
37 "Donec dignissim erat\nvehicula libero condimentum\ndictum porta augue faucibus.",
38 "Maecenas nec turpis\nsit amet quam\nfaucibus adipiscing.",
39 "Mauris aliquam,\nlectus interdum\ntincidunt luctus.",
40 "\n\n\n\n\n\n\n\n\n\n\n\n",
41 "In auctor lorem\nvel est euismod\ncondimentum.",
42 "\n\n\n\n\n\n\n\n\n\n\n\n",
43 "Ut vitae magna\nid dui placerat vehicula\nin id lectus.",
44 "\n\n\n\n\n\n\n\n\n\n\n\n",
45 "Sed lacus leo,\nmolestie et luctus ac,\ntincidunt sit amet nisi.",
46 "\n\n\n\n\n\n\n\n\n\n\n\n",
47 "Sed ligula neque,\ngravida semper vulputate laoreet,\ngravida eu tellus.",
48 "Donec dolor dolor,\nscelerisque in consequat ornare,\ntempor nec nisl."
49 } ;
50 int k ;
51
52 bi->coding_history [0] = 0 ;
53
54 for (k = 0 ; strlen (bi->coding_history) < bi->coding_history_size - 1 ; k ++)
55 append_snprintf (bi->coding_history, bi->coding_history_size, "%s\n", lines [k % ARRAY_LEN (lines)]) ;
56
57 return ;
58 } /* fill_coding_listory */
59
60 static void
test_broadcast_var_set(void)61 test_broadcast_var_set (void)
62 { SF_PRIVATE sf_private, *psf ;
63 int k ;
64
65 psf = &sf_private ;
66 memset (psf, 0, sizeof (sf_private)) ;
67
68 print_test_name ("Testing broadcast_var_set ") ;
69
70 for (k = 64 ; k < BCAST_MAX ; k++)
71 {
72 SF_BROADCAST_INFO_512 bi ;
73
74 memset (&bi, 0, sizeof (bi)) ;
75
76 bi.coding_history_size = k ;
77 fill_coding_history (&bi) ;
78 bi.coding_history_size -- ;
79
80 broadcast_var_set (psf, (SF_BROADCAST_INFO*) &bi, sizeof (bi)) ;
81 } ;
82
83 if (psf->broadcast_16k != NULL)
84 free (psf->broadcast_16k) ;
85
86 puts ("ok") ;
87 } /* test_broadcast_var_set */
88
89 static void
test_broadcast_var_zero(void)90 test_broadcast_var_zero (void)
91 { SF_PRIVATE sf_private, *psf ;
92 #ifdef _MSC_VER
93 SF_BROADCAST_INFO_VAR (0) bi ;
94 #else
95 SF_BROADCAST_INFO_VAR () bi ;
96 #endif
97
98 psf = &sf_private ;
99 memset (psf, 0, sizeof (sf_private)) ;
100 psf->file.mode = SFM_RDWR ;
101
102 print_test_name ("Testing broadcast_var_zero ") ;
103
104 memset (&bi, 0, sizeof (bi)) ;
105
106 broadcast_var_set (psf, (SF_BROADCAST_INFO*) &bi, sizeof (bi)) ;
107
108 if (psf->broadcast_16k->coding_history_size != 0)
109 { printf ("\n\nLine %d: coding_history_size %d should be zero.\n\n", __LINE__, psf->broadcast_16k->coding_history_size) ;
110 exit (1) ;
111 } ;
112
113 if (psf->broadcast_16k != NULL)
114 free (psf->broadcast_16k) ;
115
116 puts ("ok") ;
117 } /* test_broadcast_var_zero */
118
119 void
test_broadcast_var(void)120 test_broadcast_var (void)
121 { test_broadcast_var_set () ;
122 test_broadcast_var_zero () ;
123 } /* test_broadcast_var */
124