BIND 10 master, updated. 8ad1accced4284ff727b03c43cab755566e486ab [master] Use CommandOptionsHelper for CommandOptions unit tests.
BIND 10 source code commits
bind10-changes at lists.isc.org
Fri Sep 14 08:11:08 UTC 2012
The branch, master has been updated
via 8ad1accced4284ff727b03c43cab755566e486ab (commit)
from f77fcfce01df67ba90dd9a2708d6926e3065bfd4 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 8ad1accced4284ff727b03c43cab755566e486ab
Author: Marcin Siodelski <marcin at isc.org>
Date: Fri Sep 14 10:10:15 2012 +0200
[master] Use CommandOptionsHelper for CommandOptions unit tests.
This fixes memory leak reported by Valgrind. Dicussed with Jelte on jabber.
-----------------------------------------------------------------------
Summary of changes:
.../perfdhcp/tests/command_options_unittest.cc | 49 +-------------------
1 file changed, 2 insertions(+), 47 deletions(-)
-----------------------------------------------------------------------
diff --git a/tests/tools/perfdhcp/tests/command_options_unittest.cc b/tests/tools/perfdhcp/tests/command_options_unittest.cc
index 0481d28..801b02d 100644
--- a/tests/tools/perfdhcp/tests/command_options_unittest.cc
+++ b/tests/tools/perfdhcp/tests/command_options_unittest.cc
@@ -21,7 +21,7 @@
#include <dhcp/iface_mgr.h>
#include <exceptions/exceptions.h>
-#include "../command_options.h"
+#include "command_options_helper.h"
using namespace std;
using namespace isc;
@@ -48,16 +48,7 @@ protected:
/// \param cmdline Command line to parse
/// \throws std::bad allocation if tokenization failed
void process(const std::string& cmdline) {
- CommandOptions& opt = CommandOptions::instance();
- int argc = 0;
- char** argv = tokenizeString(cmdline, &argc);
- opt.reset();
- opt.parse(argc, argv);
- for(int i = 0; i < argc; ++i) {
- free(argv[i]);
- argv[i] = NULL;
- }
- free(argv);
+ CommandOptionsHelper::process(cmdline);
}
/// \brief Check default initialized values
@@ -143,42 +134,6 @@ protected:
EXPECT_EQ("", opt.getWrapped());
EXPECT_EQ("192.168.0.1", opt.getServerName());
}
-
- /// \brief Split string to array of C-strings
- ///
- /// \param s String to split (tokenize)
- /// \param num Number of tokens returned
- /// \return array of C-strings (tokens)
- char** tokenizeString(const std::string& text_to_split, int* num) const {
- char** results = NULL;
- // Tokenization with std streams
- std::stringstream text_stream(text_to_split);
- // Iterators to be used for tokenization
- std::istream_iterator<std::string> text_iterator(text_stream);
- std::istream_iterator<std::string> text_end;
- // Tokenize string (space is a separator) using begin and end iteratos
- std::vector<std::string> tokens(text_iterator, text_end);
-
- if (tokens.size() > 0) {
- // Allocate array of C-strings where we will store tokens
- results = static_cast<char**>(malloc(tokens.size() * sizeof(char*)));
- if (results == NULL) {
- throw std::bad_alloc();
- }
- // Store tokens in C-strings array
- for (int i = 0; i < tokens.size(); ++i) {
- char* cs = static_cast<char*>(malloc(tokens[i].length() + 1));
- strcpy(cs, tokens[i].c_str());
- results[i] = cs;
- }
- // Return number of tokens to calling function
- if (num != NULL) {
- *num = tokens.size();
- }
- }
- return results;
- }
-
};
TEST_F(CommandOptionsTest, Defaults) {
More information about the bind10-changes
mailing list