/[ascend]/trunk/ascend/general/test/test_pairlist.c
ViewVC logotype

Contents of /trunk/ascend/general/test/test_pairlist.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3410 - (show annotations) (download) (as text)
Thu Jul 12 03:39:49 2018 UTC (4 years, 4 months ago) by jpye
File MIME type: text/x-csrc
File size: 3223 byte(s)
completing testing of pairlist

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 Test functions for general/pairlist.c
19 by John Pye.
20 */
21
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <stdarg.h>
25 #include <ascend/general/pairlist.h>
26 #include <ascend/general/list.h>
27
28 #include "test/common.h"
29 #include "test/assertimpl.h"
30
31 #ifndef MEMUSED
32 # define MEMUSED(N) CU_TEST(ascmeminuse()==(N))
33 #endif
34
35 static void setup(void){
36 gl_init_pool();
37 gl_init();
38 }
39
40 static void teardown(void){
41 gl_destroy_pool();
42 }
43
44 static void test_createdestroy(void){
45 setup();
46 struct pairlist_t *pl1 = pairlist_create(10);
47 pairlist_destroy(pl1);
48 teardown();
49 MEMUSED(0);
50 }
51 //------------------------
52
53 static void test_setappend(void){
54 setup();
55 struct pairlist_t *pl1 = pairlist_create(10);
56 pairlist_append(pl1,"A","value1");
57 pairlist_append(pl1,"B","value2");
58 pairlist_append(pl1,"C","value3");
59 int l = pairlist_length(pl1);
60 CU_TEST(l==3);
61 CU_TEST(3==pairlist_append_unique(pl1,"C","value4"));
62 CU_TEST(4==pairlist_append_unique(pl1,"F","value7"));
63 void *old;
64 old = pairlist_set(pl1,"C","value5");
65 CU_TEST(strcmp(old,"value3")==0);
66 old = pairlist_set(pl1,"D","value6");
67 CU_TEST(old==NULL);
68 unsigned long i;
69 i = pairlist_contains(pl1,"B");
70 CU_TEST(i==2);
71 CU_TEST(strcmp(pairlist_keyAt(pl1,i),"B")==0);
72 CU_TEST(strcmp(pairlist_valueAt(pl1,i),"value2")==0);
73 CU_TEST(strcmp(pairlist_valueAt(pl1,pairlist_contains(pl1,"C")),"value5")==0);
74 pairlist_destroy(pl1);
75 teardown();
76 MEMUSED(0);
77 }
78
79 //------------------------
80
81 static void test_clear(void){
82 setup();
83 struct pairlist_t *pl1 = pairlist_create(10);
84 pairlist_append(pl1,"A","value1");
85 pairlist_append(pl1,"B","value2");
86 pairlist_append(pl1,"C","value3");
87 CU_TEST(3==pairlist_length(pl1));
88 pairlist_clear(pl1);
89 CU_TEST(0==pairlist_length(pl1));
90 pairlist_destroy(pl1);
91 teardown();
92 }
93
94 //------------------------
95
96 static void test_vad(void){
97 setup();
98 struct pairlist_t *pl1 = pairlist_create(10);
99 pairlist_append(pl1,"A","value1");
100 pairlist_append(pl1,"B","value2");
101 pairlist_append(pl1,"C","value3");
102 CU_TEST(3==pairlist_length(pl1));
103
104 struct gl_list_t *vl = pairlist_values_and_destroy(pl1);
105
106 CU_TEST(3==gl_length(vl));
107 CU_TEST(0==strcmp((char *)gl_fetch(vl,1),"value1"));
108 CU_TEST(0==strcmp((char *)gl_fetch(vl,2),"value2"));
109 CU_TEST(0==strcmp((char *)gl_fetch(vl,3),"value3"));
110 gl_destroy(vl);
111
112 teardown();
113 }
114
115
116 /*===========================================================================*/
117 /* Registration information */
118
119
120 #define TESTS(T) \
121 T(createdestroy) \
122 T(setappend) \
123 T(clear) \
124 T(vad)
125
126 REGISTER_TESTS_SIMPLE(general_pairlist, TESTS);
127

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