1 /*
2 ** Copyright (C) 2010-2013 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	CART_MAX	512
30 
31 typedef SF_CART_INFO_VAR (CART_MAX) SF_CART_INFO_512 ;
32 
33 static void
fill_tag_text(SF_CART_INFO_512 * ci)34 fill_tag_text (SF_CART_INFO_512 * ci)
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 	ci->tag_text [0] = 0 ;
53 
54 	for (k = 0 ; strlen (ci->tag_text) < ci->tag_text_size - 1 ; k ++)
55 		append_snprintf (ci->tag_text, ci->tag_text_size, "%s\n", lines [k % ARRAY_LEN (lines)]) ;
56 
57 	return ;
58 } /* fill_tag_text */
59 
60 void
test_cart_var(void)61 test_cart_var (void)
62 {	SF_PRIVATE	sf_private, *psf ;
63 	SF_CART_TIMER timer ;
64 	int k ;
65 
66 	psf = &sf_private ;
67 	memset (psf, 0, sizeof (sf_private)) ;
68 
69 	print_test_name ("Testing cart_var_set ") ;
70 
71 	for (k = 64 ; k < CART_MAX ; k++)
72 	{
73 		SF_CART_INFO_512 ci ;
74 
75 		memset (&ci, 0, sizeof (ci)) ;
76 
77 		memset (&timer, 0, sizeof (timer)) ;
78 		memcpy (ci.post_timers, &timer, sizeof (timer)) ;
79 
80 		ci.tag_text_size = k ;
81 		fill_tag_text (&ci) ;
82 		ci.tag_text_size -- ;
83 
84 		cart_var_set (psf, (SF_CART_INFO*) &ci, sizeof (ci)) ;
85 		} ;
86 
87 	if (psf->cart_16k != NULL)
88 		free (psf->cart_16k) ;
89 
90 	puts ("ok") ;
91 } /* test_cart_var */
92