|
@@ -26,82 +26,85 @@ using namespace isc;
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
+// Tests basic construction of ClientClassDef
|
|
|
TEST(ClientClassDef, construction) {
|
|
|
boost::scoped_ptr<ClientClassDef> cclass;
|
|
|
|
|
|
std::string name = "class1";
|
|
|
ExpressionPtr expr;
|
|
|
- OptionCollectionPtr options;
|
|
|
+ CfgOptionPtr cfg_option;
|
|
|
|
|
|
// Classes cannot have blank names
|
|
|
- ASSERT_THROW(cclass.reset(new ClientClassDef("", expr, options)), BadValue);
|
|
|
+ ASSERT_THROW(cclass.reset(new ClientClassDef("", expr, cfg_option)), BadValue);
|
|
|
|
|
|
- // Verify we can create a class with a name, expression, and no options
|
|
|
+ // Verify we can create a class with a name, expression, and no cfg_option
|
|
|
ASSERT_NO_THROW(cclass.reset(new ClientClassDef(name, expr)));
|
|
|
EXPECT_EQ(name, cclass->getName());
|
|
|
ASSERT_FALSE(cclass->getMatchExpr());
|
|
|
|
|
|
- // Verify we get an empty collection of options
|
|
|
- options = cclass->getOptions();
|
|
|
- ASSERT_TRUE(options);
|
|
|
- EXPECT_EQ(0, options->size());
|
|
|
+ // Verify we get an empty collection of cfg_option
|
|
|
+ cfg_option = cclass->getCfgOption();
|
|
|
+ ASSERT_TRUE(cfg_option);
|
|
|
+ //EXPECT_EQ(0, cfg_option->size());
|
|
|
}
|
|
|
|
|
|
-TEST(ClientClassDef, optionsBasics) {
|
|
|
+// Tests options operations. Note we just do the basics
|
|
|
+// as CfgOption is heavily tested elsewhere.
|
|
|
+TEST(ClientClassDef, cfgOptionBasics) {
|
|
|
boost::scoped_ptr<ClientClassDef> cclass;
|
|
|
|
|
|
std::string name = "class1";
|
|
|
ExpressionPtr expr;
|
|
|
- OptionCollectionPtr options;
|
|
|
+ CfgOptionPtr test_options;
|
|
|
+ CfgOptionPtr class_options;
|
|
|
OptionPtr opt;
|
|
|
|
|
|
// First construct the class with empty option pointer
|
|
|
- ASSERT_NO_THROW(cclass.reset(new ClientClassDef(name, expr, options)));
|
|
|
+ ASSERT_NO_THROW(cclass.reset(new ClientClassDef(name, expr, test_options)));
|
|
|
|
|
|
// We should get back a collection with no entries,
|
|
|
// not an empty collection pointer
|
|
|
- options = cclass->getOptions();
|
|
|
- ASSERT_TRUE(options);
|
|
|
- EXPECT_EQ(0, options->size());
|
|
|
-
|
|
|
- // We should not be able find an option
|
|
|
- opt = cclass->findOption(17);
|
|
|
- ASSERT_FALSE(opt);
|
|
|
-
|
|
|
- // Create an option container with two options
|
|
|
- options.reset(new OptionCollection());
|
|
|
- EXPECT_NO_THROW(opt.reset(new Option(Option::V4, 17)));
|
|
|
- options->insert(make_pair(17, opt));
|
|
|
- EXPECT_NO_THROW(opt.reset(new Option(Option::V4, 18)));
|
|
|
- options->insert(make_pair(18, opt));
|
|
|
-
|
|
|
- // Now remake the client class with options
|
|
|
- ASSERT_NO_THROW(cclass.reset(new ClientClassDef(name, expr, options)));
|
|
|
-
|
|
|
- options = cclass->getOptions();
|
|
|
- ASSERT_TRUE(options);
|
|
|
- EXPECT_EQ(2, options->size());
|
|
|
-
|
|
|
- // We should be able to find option 17
|
|
|
- opt = cclass->findOption(17);
|
|
|
- ASSERT_TRUE(opt);
|
|
|
- EXPECT_EQ(17, opt->getType());
|
|
|
-
|
|
|
- // We should be able to find option 18
|
|
|
- opt = cclass->findOption(18);
|
|
|
- ASSERT_TRUE(opt);
|
|
|
- EXPECT_EQ(18, opt->getType());
|
|
|
-
|
|
|
- // We should not be able to find option 90
|
|
|
- opt = cclass->findOption(90);
|
|
|
- ASSERT_FALSE(opt);
|
|
|
+ class_options = cclass->getCfgOption();
|
|
|
+ ASSERT_TRUE(class_options);
|
|
|
+
|
|
|
+ // Create an option container and add some options
|
|
|
+ OptionPtr option;
|
|
|
+ test_options.reset(new CfgOption());
|
|
|
+ option.reset(new Option(Option::V4, 17, OptionBuffer(10, 0xFF)));
|
|
|
+ ASSERT_NO_THROW(test_options->add(option, false, "dhcp4"));
|
|
|
+
|
|
|
+ option.reset(new Option(Option::V6, 101, OptionBuffer(10, 0xFF)));
|
|
|
+ ASSERT_NO_THROW(test_options->add(option, false, "isc"));
|
|
|
+
|
|
|
+ option.reset(new Option(Option::V6, 100, OptionBuffer(10, 0xFF)));
|
|
|
+ ASSERT_NO_THROW(test_options->add(option, false, "dhcp6"));
|
|
|
+
|
|
|
+ // Now remake the client class with cfg_option
|
|
|
+ ASSERT_NO_THROW(cclass.reset(new ClientClassDef(name, expr, test_options)));
|
|
|
+ class_options = cclass->getCfgOption();
|
|
|
+ ASSERT_TRUE(class_options);
|
|
|
+
|
|
|
+ // Now make sure we can find all the options
|
|
|
+ OptionDescriptor opt_desc = class_options->get("dhcp4",17);
|
|
|
+ ASSERT_TRUE(opt_desc.option_);
|
|
|
+ EXPECT_EQ(100, opt_desc.option_->getType());
|
|
|
+
|
|
|
+ opt_desc = class_options->get("isc",101);
|
|
|
+ ASSERT_TRUE(opt_desc.option_);
|
|
|
+ EXPECT_EQ(101, opt_desc.option_->getType());
|
|
|
+
|
|
|
+ opt_desc = class_options->get("dhcp6",100);
|
|
|
+ ASSERT_TRUE(opt_desc.option_);
|
|
|
+ EXPECT_EQ(100, opt_desc.option_->getType());
|
|
|
}
|
|
|
|
|
|
+// Tests the basic operation of ClientClassDictionary
|
|
|
+// This includes adding, finding, and removing classes
|
|
|
TEST(ClientClassDictionary, basics) {
|
|
|
ClientClassDictionaryPtr dictionary;
|
|
|
ClientClassDefPtr cclass;
|
|
|
ExpressionPtr expr;
|
|
|
- OptionCollectionPtr options;
|
|
|
+ CfgOptionPtr cfg_option;
|
|
|
|
|
|
// Verify constructor doesn't throw
|
|
|
ASSERT_NO_THROW(dictionary.reset(new ClientClassDictionary()));
|
|
@@ -113,19 +116,19 @@ TEST(ClientClassDictionary, basics) {
|
|
|
EXPECT_EQ(0, classes->size());
|
|
|
|
|
|
// Verify that we can add classes with both addClass variants
|
|
|
- // First addClass(name, expression, options)
|
|
|
- ASSERT_NO_THROW(dictionary->addClass("cc1", expr, options));
|
|
|
- ASSERT_NO_THROW(dictionary->addClass("cc2", expr, options));
|
|
|
+ // First addClass(name, expression, cfg_option)
|
|
|
+ ASSERT_NO_THROW(dictionary->addClass("cc1", expr, cfg_option));
|
|
|
+ ASSERT_NO_THROW(dictionary->addClass("cc2", expr, cfg_option));
|
|
|
|
|
|
// Verify duplicate add attempt throws
|
|
|
- ASSERT_THROW(dictionary->addClass("cc2", expr, options),
|
|
|
+ ASSERT_THROW(dictionary->addClass("cc2", expr, cfg_option),
|
|
|
DuplicateClientClassDef);
|
|
|
|
|
|
// Verify that you cannot add a class with no name.
|
|
|
- ASSERT_THROW(dictionary->addClass("", expr, options), BadValue);
|
|
|
+ ASSERT_THROW(dictionary->addClass("", expr, cfg_option), BadValue);
|
|
|
|
|
|
// Now with addClass(class pointer)
|
|
|
- ASSERT_NO_THROW(cclass.reset(new ClientClassDef("cc3", expr, options)));
|
|
|
+ ASSERT_NO_THROW(cclass.reset(new ClientClassDef("cc3", expr, cfg_option)));
|
|
|
ASSERT_NO_THROW(dictionary->addClass(cclass));
|
|
|
|
|
|
// Verify duplicate add attempt throws
|