/[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 3258 - (show annotations) (download) (as text)
Wed Nov 15 04:57:56 2017 UTC (5 years, 2 months ago) by jpye
File MIME type: text/x-csrc
File size: 2275 byte(s)
Merged relerrorlist branch back to trunk.

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 void *old;
63 old = pairlist_set(pl1,"C","value5");
64 CU_TEST(strcmp(old,"value3")==0);
65 old = pairlist_set(pl1,"D","value6");
66 CU_TEST(old==NULL);
67 unsigned long i;
68 i = pairlist_contains(pl1,"B");
69 CU_TEST(i==2);
70 CU_TEST(strcmp(pairlist_keyAt(pl1,i),"B")==0);
71 CU_TEST(strcmp(pairlist_valueAt(pl1,i),"value2")==0);
72 CU_TEST(strcmp(pairlist_valueAt(pl1,pairlist_contains(pl1,"C")),"value5")==0);
73 pairlist_destroy(pl1);
74 teardown();
75 MEMUSED(0);
76 }
77 //------------------------
78
79 /*===========================================================================*/
80 /* Registration information */
81
82
83 #define TESTS(T) \
84 T(createdestroy) \
85 T(setappend)
86
87 REGISTER_TESTS_SIMPLE(general_pairlist, TESTS);
88

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