/* $Id: cpl_parameterlist-test.c,v 1.2 2007/07/16 09:09:04 llundin Exp $ * * This file is part of the ESO Common Pipeline Library * Copyright (C) 2001-2005 European Southern Observatory * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* * $Author: llundin $ * $Date: 2007/07/16 09:09:04 $ * $Revision: 1.2 $ * $Name: $ */ #undef CX_DISABLE_ASSERT #undef CX_LOG_DOMAIN #include #include #include #include #include "cpl_init.h" #include "cpl_parameterlist.h" int main(void) { cpl_parameter *p[4]; cpl_parameter *q = NULL; cpl_parameterlist *list = NULL; cpl_init(CPL_INIT_DEFAULT); /* * Test 1: Create a parameter list */ list = cpl_parameterlist_new(); cx_assert(list != NULL); cx_assert(cpl_parameterlist_get_size(list) == 0); /* * Test 2: Append parameters to the list */ p[0] = cpl_parameter_new_value("a", CPL_TYPE_STRING, "parameter1", "None", "value1"); cpl_parameterlist_append(list, p[0]); p[1] = cpl_parameter_new_value("b", CPL_TYPE_STRING, "parameter2", "None", "value2"); cpl_parameterlist_append(list, p[1]); p[2] = cpl_parameter_new_value("c", CPL_TYPE_STRING, "parameter3", "None", "value3"); cpl_parameterlist_append(list, p[2]); p[3] = cpl_parameter_new_value("d", CPL_TYPE_STRING, "parameter4", "None", "value4"); cpl_parameterlist_append(list, p[3]); cx_assert(cpl_parameterlist_get_size(list) == 4); /* * Test 3: Verify the sequential access to the list elements. */ cx_assert(p[0] == cpl_parameterlist_get_first(list)); cx_assert(p[1] == cpl_parameterlist_get_next(list)); cx_assert(p[2] == cpl_parameterlist_get_next(list)); cx_assert(p[3] == cpl_parameterlist_get_next(list)); cx_assert(p[3] == cpl_parameterlist_get_last(list)); cx_assert(cpl_parameterlist_get_next(list) == NULL); /* * Test4: Add a user tag to one of the parameters an check whether it * can be found by looking for the tag. */ cpl_parameter_set_tag(p[2], "mytag"); q = cpl_parameterlist_find_tag(list, "mytag"); cx_assert(q == p[2]); cpl_parameterlist_delete(list); list = NULL; /* * All tests succeeded */ cpl_end(); return 0; }