/[ascend]/branches/relerrorlist/ascend/compiler/test/test_freestore.c
ViewVC logotype

Contents of /branches/relerrorlist/ascend/compiler/test/test_freestore.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3234 - (show annotations) (download) (as text)
Thu Nov 2 11:26:15 2017 UTC (4 years, 8 months ago) by jpye
File MIME type: text/x-csrc
File size: 2032 byte(s)
added very simple test for the module 'freestore'.

1 /* ASCEND modelling environment
2 Copyright (C) 2017 John Pye
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 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 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *//**
17 @file
18 Unit test functions for freestore.
19 */
20 #include <ascend/compiler/freestore.h>
21 #include <test/common.h>
22
23 static void test_simple(void){
24
25 union RelationTermUnion *term = NULL;
26 union RelationTermUnion **list = NULL;
27 int n_buffers = 1;
28 int buffer_length = 5;
29 int len = 10;
30 int i;
31
32 CU_ASSERT(NULL == FreeStore_GetFreeStore());
33 FreeStore_SetFreeStore(FreeStore_Create(n_buffers,buffer_length));
34 CU_ASSERT(NULL != FreeStore_GetFreeStore());
35
36 list = ASC_NEW_ARRAY(union RelationTermUnion *,len);
37 CU_ASSERT(NULL != list);
38 for (i=0;i<len;i++) {
39 term = FreeStore_GetMem();
40 if(term){
41 V_TERM(term)->varnum = i;
42 V_TERM(term)->t = e_var;
43 list[i] = term;
44 }
45 }
46 CU_ASSERT(0 == FreeStore_FreeMem(list[4]));
47 CU_ASSERT(0 == FreeStore_FreeMem(list[5]));
48 CU_ASSERT(0 == FreeStore_FreeMem(list[6]));
49
50 term = (union RelationTermUnion *)malloc(sizeof(union RelationTermUnion));
51 V_TERM(term)->varnum = 6;
52 CU_ASSERT(1 == FreeStore_FreeMem(term));
53 FreeStore__Statistics(stdout,FreeStore_GetFreeStore());
54 FreeStore__BlastMem(FreeStore_GetFreeStore());
55 ASC_FREE(term);
56 ASC_FREE(list);
57 }
58
59 /*===========================================================================*/
60 /* Registration information */
61
62 /* the list of tests */
63
64 #define TESTS(T) \
65 T(simple)
66
67 REGISTER_TESTS_SIMPLE(compiler_freestore, TESTS)
68

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22