CR2RE Pipeline Reference Manual 1.6.7
hdrl_buffer-test.c
1/* $Id: hdrl_buffer-test.c,v 1.1 2013-10-23 09:13:56 jtaylor Exp $
2 *
3 * This file is part of the HDRL
4 * Copyright (C) 2013 European Southern Observatory
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21/*
22 * $Author: jtaylor $
23 * $Date: 2013-10-23 09:13:56 $
24 * $Revision: 1.1 $
25 * $Name: not supported by cvs2svn $
26 */
27
28#ifdef HAVE_CONFIG_H
29#include <config.h>
30#endif
31
32/*-----------------------------------------------------------------------------
33 Includes
34 -----------------------------------------------------------------------------*/
35
36#ifndef _POSIX_C_SOURCE
37#define _POSIX_C_SOURCE 200112L
38#endif
39#include "hdrl_buffer.h"
40
41#include <cpl.h>
42
43#include <stdlib.h>
44#include <string.h>
45
46
47/*----------------------------------------------------------------------------*/
52/*----------------------------------------------------------------------------*/
53
54cpl_error_code test_basic(void)
55{
56 hdrl_buffer *buf = hdrl_buffer_new();
57
58 hdrl_buffer_readonly(buf, CPL_TRUE);
59 hdrl_buffer_readonly(buf, CPL_FALSE);
60
61 char * p2 = hdrl_buffer_allocate(buf, 10023);
62 memset(p2, 1, 10023);
63
64 size_t size = hdrl_buffer_set_malloc_threshold(buf, sizeof(int));
65 cpl_test_error(CPL_ERROR_NONE);
66 cpl_test(size == 0.);
67
68 hdrl_buffer_readonly(buf, CPL_TRUE);
69 cpl_test_error(CPL_ERROR_NONE);
70
71 hdrl_buffer_readonly(buf, CPL_FALSE);
72 cpl_test_error(CPL_ERROR_NONE);
73
74 hdrl_buffer_free(buf, p2);
75 hdrl_buffer_delete(buf);
76
77 cpl_msg_info(cpl_func, "test pool <= object");
78 buf = hdrl_buffer_new();
79 for (size_t i = 0; i < 100; i++) {
80 char * p = hdrl_buffer_allocate(buf, 1<<20);
81 memset(p, 1, 1<<20);
82 hdrl_buffer_free(buf, p);
83 }
84 hdrl_buffer_delete(buf);
85
86 cpl_msg_info(cpl_func, "test pool > object");
87 buf = hdrl_buffer_new();
88 for (size_t i = 0; i < 1000; i++) {
89 char * p = hdrl_buffer_allocate(buf, 1<<18);
90 p[(1<<18) - 1] = 1;
91 hdrl_buffer_free(buf, p);
92 }
93
94 hdrl_buffer_delete(NULL);
95
96 hdrl_buffer_delete(buf);
97
98 return cpl_error_get_code();
99}
100
101
102/*----------------------------------------------------------------------------*/
106/*----------------------------------------------------------------------------*/
107int main(void)
108{
109 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
110
111 test_basic();
112
113 setenv("HDRL_BUFFER_MALLOC", "1", 1);
114 test_basic();
115
116 return cpl_test_end(0);
117}