// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include <config.h>
+
+#include <cc/data.h>
#include <dhcp/classify.h>
#include <util/strutil.h>
+
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/constants.hpp>
#include <boost/algorithm/string/split.hpp>
+
#include <sstream>
#include <vector>
namespace isc {
namespace dhcp {
+using namespace isc::data;
+
ClientClasses::ClientClasses(const std::string& class_names)
: container_() {
std::vector<std::string> split_text;
return (s.str());
}
+ElementPtr
+ClientClasses::toElement() const {
+ ElementPtr result(Element::createList());
+ for (ClientClass c : container_) {
+ result->add(Element::create(c));
+ }
+ return (result);
+}
+
} // end of namespace isc::dhcp
} // end of namespace isc
#ifndef CLASSIFY_H
#define CLASSIFY_H
+#include <cc/data.h>
+
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/identity.hpp>
/// @param separator Separator to be used between class names. The
/// default separator comprises comma sign followed by space
/// character.
+ ///
+ /// @return the string representation of all classes
std::string toText(const std::string& separator = ", ") const;
+ /// @brief Returns all class names as an ElementPtr of type ListElement
+ ///
+ /// @return the list
+ isc::data::ElementPtr toElement() const;
+
private:
/// @brief container part
ClientClassContainer container_;
EXPECT_EQ("alpha.gamma.beta", classes.toText("."));
}
+// Check that the ClientClasses::toElement function returns
+// correct values.
+TEST(ClassifyTest, ClientClassesToElement) {
+ // No classes.
+ ClientClasses classes;
+ EXPECT_TRUE(classes.toElement()->empty());
+
+ // Insert single class name and see that it's there.
+ classes.insert("alpha");
+ EXPECT_EQ("[ \"alpha\" ]", classes.toElement()->str());
+
+ // Insert next class name and see that both classes are present.
+ classes.insert("gamma");
+ EXPECT_EQ("[ \"alpha\", \"gamma\" ]", classes.toElement()->str());
+
+ // Insert third class and make sure they get ordered in insert order.
+ classes.insert("beta");
+ EXPECT_EQ("[ \"alpha\", \"gamma\", \"beta\" ]", classes.toElement()->str());
+}
+
// Check that selected class can be erased.
TEST(ClassifyTest, Erase) {
ClientClasses classes;