00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00024 #include "config.h"
00025
00026 #include <scalestack/kernel/module.h>
00027 #include <scalestack/kernel/option.h>
00028 #include <scalestack/kernel/test.h>
00029
00030 using namespace scalestack;
00031
00032 class test_suite: public scalestack::kernel::test_suite<test_suite>
00033 {
00034 public:
00035
00036 void test_constructor_true(void)
00037 {
00038 kernel::module& module = core->get_or_add_module("module");
00039 kernel::option& option = module.add_option("option", "Help", "BOOL",
00040 "true");
00041 assert(&option.get_module() == &module);
00042 assert(option.get_name() == "option");
00043 assert(option.get_help() == "Help");
00044 assert(option.get_value_name() == "BOOL");
00045 assert(option.get_default_value() == "true");
00046 assert(option.get_value() == "true");
00047 assert(option.get_bool_value() == true);
00048 assert(option.is_valid() == true);
00049 }
00050
00051 void test_constructor_false(void)
00052 {
00053 kernel::module& module = core->get_or_add_module("module");
00054 kernel::option& option = module.add_option("option", "Help", "BOOL",
00055 "false");
00056 assert(&option.get_module() == &module);
00057 assert(option.get_name() == "option");
00058 assert(option.get_help() == "Help");
00059 assert(option.get_value_name() == "BOOL");
00060 assert(option.get_default_value() == "false");
00061 assert(option.get_value() == "false");
00062 assert(option.get_bool_value() == false);
00063 assert(option.is_valid() == true);
00064 }
00065
00066 void test_constructor_value(void)
00067 {
00068 kernel::module& module = core->get_or_add_module("module");
00069 kernel::option& option = module.add_option("option", "Help", "VALUE_NAME",
00070 "default_value");
00071 assert(&option.get_module() == &module);
00072 assert(option.get_name() == "option");
00073 assert(option.get_help() == "Help");
00074 assert(option.get_value_name() == "VALUE_NAME");
00075 assert(option.get_default_value() == "default_value");
00076 assert(option.get_value() == "default_value");
00077 assert(option.is_valid() == true);
00078 }
00079
00080 void test_load_option(void)
00081 {
00082 kernel::module& module =
00083 core->get_or_add_module("kernel::test::option_basic");
00084 core->add_module_option_value("kernel::test::option_basic", "option4", "");
00085 core->add_module_option_value("kernel::test::option_basic", "option5", "");
00086 core->add_module_option_value("kernel::test::option_basic", "option6",
00087 "value6");
00088 assert(module.get_option("option4").is_valid() == false);
00089 assert(module.get_option("option5").is_valid() == false);
00090 assert(module.get_option("option6").is_valid() == false);
00091 core->run();
00092 assert(module.get_option("option1").is_valid() == true);
00093 assert(module.get_option("option2").is_valid() == true);
00094 assert(module.get_option("option3").is_valid() == true);
00095 assert(module.get_option("option4").is_valid() == true);
00096 assert(module.get_option("option5").is_valid() == true);
00097 assert(module.get_option("option6").is_valid() == true);
00098 assert(module.get_option("option7").is_valid() == true);
00099 assert(module.get_option("option8").is_valid() == true);
00100 }
00101
00102 void test_reconfigure_option(void)
00103 {
00104 core->get_or_add_module("kernel::test::option_reconfigure");
00105 core->run();
00106 }
00107
00108 void test_bad_option(void)
00109 {
00110 core->get_or_add_module("kernel::test::option_bad");
00111 assert_exception(core->run());
00112 }
00113
00114 test_suite(int argc, const char** argv):
00115 scalestack::kernel::test_suite<test_suite>(argc, argv)
00116 {
00117 test_case(test_suite::test_constructor_true);
00118 test_case(test_suite::test_constructor_false);
00119 test_case(test_suite::test_constructor_value);
00120 test_case(test_suite::test_load_option);
00121 test_case(test_suite::test_reconfigure_option);
00122 test_case(test_suite::test_bad_option);
00123 }
00124 };
00125
00126 int main(int argc, const char* argv[])
00127 {
00128 test_suite test_suite(argc - 1, argv + 1);
00129 test_suite.run();
00130 return 0;
00131 }