/* $Id: cpl_parameter-test.c,v 1.6 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.6 $ * $Name: $ */ #undef CX_DISABLE_ASSERT #undef CX_LOG_DOMAIN #include #include #include #include #include "cpl_init.h" #include "cpl_parameter.h" int main(void) { const cxchar *sval1 = "abcdefghijklmnopqrstuvwxyz"; const cxchar *sval2 = "zyxwvutsrqponmlkjihgfedcba"; cpl_parameter *p; cpl_init(CPL_INIT_DEFAULT); /* * Test 1: Create a string parameter and check its validity */ p = cpl_parameter_new_value("a", CPL_TYPE_STRING, "Test parameter", "None", sval1); cx_assert(p != NULL); cx_assert(strcmp(cpl_parameter_get_name(p), "a") == 0); cx_assert(strcmp(cpl_parameter_get_help(p), "Test parameter") == 0); cx_assert(strcmp(cpl_parameter_get_context(p), "None") == 0); cx_assert(cpl_parameter_get_tag(p) == NULL); cx_assert(cpl_parameter_get_type(p) == CPL_TYPE_STRING); cx_assert(cpl_parameter_get_class(p) == CPL_PARAMETER_CLASS_VALUE); cx_assert(strcmp(cpl_parameter_get_string(p), sval1) == 0); cx_assert(cpl_parameter_get_string(p) != sval1); /* * Test 2: Assign a new string value to the parameter and check * its validity */ cpl_parameter_set_string(p, sval2); cx_assert(strcmp(cpl_parameter_get_string(p), sval2) == 0); cx_assert(cpl_parameter_get_string(p) != sval2); cpl_parameter_delete(p); /* * Test 3: Change the parameter's default value. */ p = cpl_parameter_new_value("b", CPL_TYPE_BOOL, "A boolean value.", "None", 0); cx_assert(cpl_parameter_get_default_bool(p) == 0); cx_assert(cpl_parameter_get_default_bool(p) == cpl_parameter_get_bool(p)); cpl_parameter_set_default_bool(p, 1); cx_assert(cpl_parameter_get_default_bool(p) == 1); cx_assert(cpl_parameter_get_default_bool(p) != cpl_parameter_get_bool(p)); cpl_parameter_delete(p); p = cpl_parameter_new_value("c", CPL_TYPE_STRING, "A string value.", "None", sval1); cx_assert(strcmp(cpl_parameter_get_default_string(p), sval1) == 0); cx_assert(strcmp(cpl_parameter_get_default_string(p), cpl_parameter_get_string(p)) == 0); cpl_parameter_set_default_string(p, sval2); cx_assert(strcmp(cpl_parameter_get_default_string(p), sval2) == 0); cx_assert(strcmp(cpl_parameter_get_default_string(p), cpl_parameter_get_string(p)) != 0); cpl_parameter_delete(p); /* * All tests succeeded */ cpl_end(); return 0; }