Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

hey_good.cc

Go to the documentation of this file.
00001 /*
00002  * hey_good.cc
00003  *
00004  * Copyright (c) 2003 The University of Utah and the Flux Group.
00005  * All rights reserved.
00006  *
00007  * This file is licensed under the terms of the GNU Public License.  
00008  * See the file "license.terms" for restrictions on redistribution 
00009  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
00010  */
00011 
00012 /**
00013  * @file hey_good.cc
00014  *
00015  * Test valid inputs to a HeyParser instance.
00016  *
00017  * @sa hey_bad.cc
00018  */
00019 
00020 #include "config.h"
00021 
00022 #include <iostream>
00023 
00024 #include <assert_pp.h>
00025 
00026 #include "HeyParser.hh"
00027 
00028 int main(int argc, const char *argv[])
00029 {
00030     int retval = EXIT_SUCCESS;
00031 
00032     /* Check the verb mappings for list, */
00033     {
00034         const char *hp_argv[] = {
00035             "hey", "ior", "list",
00036         };
00037 
00038         HeyParser hp(3, hp_argv);
00039 
00040         require(strcmp(hp.who(), hp_argv[1]) == 0);
00041         require(hp.what() == HeyParser::LIST_PROPERTIES);
00042     }
00043 
00044     /* ... get, and */
00045     {
00046         const char *hp_argv[] = {
00047             "hey", "ior", "get", "prop",
00048         };
00049 
00050         HeyParser hp(4, hp_argv);
00051         const char *name, *value = "not-null";
00052 
00053         require(hp.what() == HeyParser::GET_PROPERTY);
00054 
00055         hp.popProperty(name, value);
00056 
00057         require(strcmp(name, hp_argv[3]) == 0);
00058         require(value == NULL);
00059     }
00060 
00061     /* ... set. */
00062     {
00063         const char *hp_argv[] = {
00064             "hey", "ior", "set", "prop", "foo", "to", "bar",
00065         };
00066 
00067         HeyParser hp(7, hp_argv);
00068         const char *name, *value;
00069 
00070         require(hp.what() == HeyParser::SET_PROPERTY);
00071 
00072         hp.popProperty(name, value);
00073 
00074         require(strcmp(name, hp_argv[3]) == 0);
00075         require(strcmp(value, hp_argv[4]) == 0);
00076     }
00077 
00078     /*
00079      * Make sure 'to' is detected properly for a 'set' with a name/value
00080      * property and
00081      */
00082     {
00083         const char *hp_argv[] = {
00084             "hey", "ior", "set", "prop", "foo", "to", "5",
00085         };
00086 
00087         HeyParser hp(7, hp_argv);
00088         const char *name, *value;
00089 
00090         require(hp.what() == HeyParser::SET_PROPERTY);
00091 
00092         hp.popProperty(name, value);
00093 
00094         require(strcmp(name, hp_argv[3]) == 0);
00095         require(strcmp(value, hp_argv[4]) == 0);
00096         require(strcmp(hp.to(), hp_argv[6]) == 0);
00097     }
00098 
00099     /* ... just a name property. */
00100     {
00101         const char *hp_argv[] = {
00102             "hey", "ior", "set", "prop", "to", "5",
00103         };
00104 
00105         HeyParser hp(6, hp_argv);
00106         const char *name, *value;
00107 
00108         require(hp.what() == HeyParser::SET_PROPERTY);
00109 
00110         hp.popProperty(name, value);
00111 
00112         require(strcmp(name, hp_argv[3]) == 0);
00113         require(strcmp(hp.to(), hp_argv[5]) == 0);
00114     }
00115 
00116     /* Make sure multiple properties are stacked properly. */
00117     {
00118         const char *hp_argv[] = {
00119             "hey", "ior", "get", "prop", "foo", "of", "prop", "bar",
00120         };
00121 
00122         HeyParser hp(8, hp_argv);
00123         const char *name, *value;
00124 
00125         require(hp.what() == HeyParser::GET_PROPERTY);
00126 
00127         hp.popProperty(name, value);
00128         
00129         require(strcmp(name, hp_argv[6]) == 0);
00130         require(strcmp(value, hp_argv[7]) == 0);
00131 
00132         hp.popProperty(name, value);
00133 
00134         require(strcmp(name, hp_argv[3]) == 0);
00135         require(strcmp(value, hp_argv[4]) == 0);
00136     }
00137 
00138     /* Make sure 'getsuites of prop' works. */
00139     {
00140         const char *hp_argv[] = {
00141             "hey", "ior", "getsuites", "of", "foo",
00142         };
00143         
00144         HeyParser hp(5, hp_argv);
00145         const char *name, *value;
00146 
00147         require(hp.what() == HeyParser::GET_SUITES);
00148 
00149         hp.popProperty(name, value);
00150         
00151         require(strcmp(name, hp_argv[4]) == 0);
00152     }
00153 
00154     /* Make sure 'with' and 'withValue' works. */
00155     {
00156         const char *hp_argv[] = {
00157             "hey", "ior", "create", "foo", "with", "bar", "baz", "num", "2",
00158         };
00159         
00160         HeyParser hp(9, hp_argv);
00161         const char *name, *value;
00162         const char **with_values;
00163         size_t with_count;
00164 
00165         require(hp.what() == HeyParser::CREATE_PROPERTY);
00166 
00167         hp.popProperty(name, value);
00168         
00169         require(strcmp(name, hp_argv[3]) == 0);
00170         require(hp.withValue("bar") == hp_argv[6]);
00171         require(hp.withValue("num") == hp_argv[8]);
00172         require(hp.withValue("non-existent", 0, "") == "");
00173         hp.with(with_values, with_count);
00174         require(with_values == &hp_argv[5]);
00175         require(with_count == 4);
00176     }
00177     
00178     /* Make sure 'withValue' works with equal signs. */
00179     try
00180     {
00181         const char *hp_argv[] = {
00182             "hey", "ior", "create", "foo", "with", "bar=baz"
00183         };
00184         
00185         HeyParser hp(6, hp_argv);
00186         const char *name, *value;
00187 
00188         require(hp.what() == HeyParser::CREATE_PROPERTY);
00189 
00190         hp.popProperty(name, value);
00191         
00192         require(strcmp(name, hp_argv[3]) == 0);
00193         require(strcmp(hp.withValue("bar"), "baz") == 0);
00194     }
00195     catch(const HeyParserException &e)
00196     {
00197         cerr << e << endl;
00198         retval = EXIT_FAILURE;
00199     }
00200 
00201     /* Make sure 'getsuites' works. */
00202     {
00203         HeyPropertyInfo hpi("foo",
00204                             (1L << HeyParser::GET_PROPERTY),
00205                             "",
00206                             "Bar baz...\n");
00207         
00208         HeyPropertyInfo string_suites[] = {
00209             HeyPropertyInfo("string",
00210                             (1L << HeyParser::CREATE_PROPERTY),
00211                             "",
00212                             "id:int - The string's identifer.\n"
00213                             "value:string - The string's value.\n"
00214                             "\n"
00215                             "Create a string with the given id and value.\n"),
00216             HeyPropertyInfo("string",
00217                             (1L << HeyParser::GET_PROPERTY) |
00218                             (1L << HeyParser::SET_PROPERTY),
00219                             "id:int",
00220                             "Get or set the value of string 'id'.\n"),
00221             HeyPropertyInfo("string",
00222                             (1L << HeyParser::DELETE_PROPERTY),
00223                             "id:int",
00224                             "Delete a string 'id'.\n"),
00225             HeyPropertyInfo::HPI_NULL,
00226         };
00227         
00228         cout << hpi;
00229 
00230         cout << string_suites;
00231     }
00232     
00233     return( retval );
00234 }

Generated on Fri Oct 22 07:50:24 2004 for CPU Broker by  doxygen 1.3.9.1