1
/*
2
 * Copyright © 2004 Red Hat, Inc.
3
 *
4
 * Permission to use, copy, modify, distribute, and sell this software
5
 * and its documentation for any purpose is hereby granted without
6
 * fee, provided that the above copyright notice appear in all copies
7
 * and that both that copyright notice and this permission notice
8
 * appear in supporting documentation, and that the name of
9
 * Red Hat, Inc. not be used in advertising or publicity pertaining to
10
 * distribution of the software without specific, written prior
11
 * permission. Red Hat, Inc. makes no representations about the
12
 * suitability of this software for any purpose.  It is provided "as
13
 * is" without express or implied warranty.
14
 *
15
 * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
16
 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17
 * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
18
 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19
 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20
 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
21
 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
 *
23
 * Author: Carl D. Worth <cworth@cworth.org>
24
 */
25

            
26
/* Bug history
27
 *
28
 * 2004-11-04 Ned Konz <ned@squeakland.org>
29
 *
30
 *   Reported bug on mailing list:
31
 *
32
 *	From: Ned Konz <ned@squeakland.org>
33
 *	To: cairo@cairographics.org
34
 *	Date: Thu, 4 Nov 2004 09:49:38 -0800
35
 *	Subject: [cairo] getting assertions [cairo_cache.c:143: _entry_destroy:
36
 *	        Assertion `cache->used_memory > entry->memory' failed]
37
 *
38
 *	The attached program dies on me with the assert
39
 *
40
 *	$ ./testCairo
41
 *	testCairo: cairo_cache.c:143: _entry_destroy: Assertion `cache->used_memory > entry->memory' failed.
42
 *
43
 * 2004-11-04 Carl Worth <cworth@cworth.org>
44
 *
45
 *   I trimmed down Ned's example to the following test while still
46
 *   maintaining the assertion.
47
 *
48
 *   Oh, actually, it looks like I may have triggered something
49
 *   slightly different:
50
 *
51
 *	text_cache_crash: cairo_cache.c:422: _cairo_cache_lookup: Assertion `cache->max_memory >= (cache->used_memory + new_entry->memory)' failed.
52
 *
53
 *   I'll have to go back and try the original test after I fix this.
54
 *
55
 * 2004-11-13 Carl Worth <cworth@cworth.org>
56
 *
57
 *   Found the bug. cairo_gstate_select_font was noticing when the
58
 *   same font was selected twice in a row and was erroneously failing
59
 *   to free the old reference. Committed a fix and verified it also
60
 *   fixed the original test case.
61
 */
62

            
63
#include "cairo-test.h"
64

            
65
static cairo_test_status_t
66
3
draw (cairo_t *cr, int width, int height)
67
{
68
    /* Once there was a bug that choked when selecting the same font twice. */
69
3
    cairo_select_font_face (cr, CAIRO_TEST_FONT_FAMILY " Sans",
70
			    CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
71
3
    cairo_set_font_size (cr, 40.0);
72

            
73
3
    cairo_select_font_face (cr, CAIRO_TEST_FONT_FAMILY " Sans",
74
			    CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
75
3
    cairo_set_font_size (cr, 40.0);
76
3
    cairo_move_to (cr, 10, 50);
77
3
    cairo_show_text (cr, "hello");
78

            
79
    /* Then there was a bug that choked when selecting a font too big
80
     * for the cache. */
81

            
82
3
    cairo_set_font_size (cr, 500);
83
3
    cairo_show_text (cr, "hello");
84

            
85
3
    return CAIRO_TEST_SUCCESS;
86
}
87

            
88
1
CAIRO_TEST (text_cache_crash,
89
	    "Test case for bug causing an assertion failure in _cairo_cache_lookup",
90
	    "text, stress", /* keywords */
91
	    NULL, /* requirements */
92
	    0, 0,
93
	    NULL, draw)