Date: Monday, January 2, 2006 @ 12:14:28
Author: csaba
Path: /cvsroot/carob/libmysequoia
Added: test/TestIniParser.cpp (1.1) test/TestIniParser.hpp (1.1)
test/data/my.cnf (1.1)
Modified: include/IniParser.hpp (1.1 -> 1.2) src/IniParser.cpp (1.1 ->
1.2) test/Makefile.am (1.2 -> 1.3)
Added unit tests for the IniParser class.
------------------------+
include/IniParser.hpp | 15 ++---
src/IniParser.cpp | 5 +
test/Makefile.am | 5 +
test/TestIniParser.cpp | 86 ++++++++++++++++++++++++++++++
test/TestIniParser.hpp | 42 +++++++++++++++
test/data/my.cnf | 131 +++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 275 insertions(+), 9 deletions(-)
Index: libmysequoia/include/IniParser.hpp
diff -u libmysequoia/include/IniParser.hpp:1.1
libmysequoia/include/IniParser.hpp:1.2
--- libmysequoia/include/IniParser.hpp:1.1 Mon Dec 19 18:10:21 2005
+++ libmysequoia/include/IniParser.hpp Mon Jan 2 12:14:27 2006
@@ -32,7 +32,7 @@
* Open the file and parse it.
* @param name the name of the file
*/
- void parseFile(const char *name);
+ bool parseFile(const char *name);
/**
* Get the value of the option name in the group
@@ -42,12 +42,7 @@
*/
std::string get(std::string group, std::string name) const;
-private:
- /**
- * holds the name=value pairs in each group
- */
- std::map<std::string, std::map<std::string, std::string> > keys;
-
+protected:
void removeLeadingSpaces(std::string& s);
void removeTrailingSpaces(std::string& s);
void removeComments(std::string& s);
@@ -56,6 +51,12 @@
bool parseGroup(std::string line, std::string& group);
void parseName(std::string line, std::string group);
std::string parseValue(std::string value);
+
+private:
+ /**
+ * holds the name=value pairs in each group
+ */
+ std::map<std::string, std::map<std::string, std::string> > keys;
};
#endif /* _INIPARSER_HPP */
Index: libmysequoia/src/IniParser.cpp
diff -u libmysequoia/src/IniParser.cpp:1.1 libmysequoia/src/IniParser.cpp:1.2
--- libmysequoia/src/IniParser.cpp:1.1 Mon Dec 19 18:10:21 2005
+++ libmysequoia/src/IniParser.cpp Mon Jan 2 12:14:27 2006
@@ -26,7 +26,7 @@
using namespace std;
-void IniParser::parseFile(const char *name)
+bool IniParser::parseFile(const char *name)
{
string group, line;
bool in_group = false;
@@ -50,7 +50,10 @@
parseName(line, group);
}
}
+ return true;
}
+
+ return false;
}
string IniParser::get(std::string group, std::string name) const
Index: libmysequoia/test/Makefile.am
diff -u libmysequoia/test/Makefile.am:1.2 libmysequoia/test/Makefile.am:1.3
--- libmysequoia/test/Makefile.am:1.2 Mon Dec 19 09:06:58 2005
+++ libmysequoia/test/Makefile.am Mon Jan 2 12:14:27 2006
@@ -24,7 +24,9 @@
runTests_SOURCES = runTests.cpp \
TestCarobMySQL.cpp \
- TestMySQLAPI.cpp
+ TestMySQLAPI.cpp \
+ TestIniParser.cpp
+
# FIXME the relative PATH
runTests_CXXFLAGS = -I$(top_builddir)/../carob/include @CPPUNIT_CFLAGS@
@MYSQL_CFLAGS@ @GCOV_CFLAGS@
runTests_LDADD = $(top_builddir)/src/libmysequoia.la @CPPUNIT_LDADD@
@GCOV_LDADD@ -lpthread
@@ -34,6 +36,7 @@
EXTRA_DIST = Globals.hpp \
TestCarobMySQL.hpp \
TestMySQLAPI.hpp \
+ TestIniParser.hpp \
logger.cfg
clean-local:
Index: libmysequoia/test/TestIniParser.cpp
diff -u /dev/null libmysequoia/test/TestIniParser.cpp:1.1
--- /dev/null Mon Jan 2 12:14:28 2006
+++ libmysequoia/test/TestIniParser.cpp Mon Jan 2 12:14:27 2006
@@ -0,0 +1,86 @@
+/*
+ * Sequoia: Database clustering technology.
+ * Copyright (C) 2005 Continuent, Inc.
+ * Contact: [EMAIL PROTECTED]
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License")
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Initial developer(s): Zsolt Simon, Csaba Simon
+ * Contributor(s):
+ */
+
+#include "TestIniParser.hpp"
+
+#include "IniParser.hpp"
+
+#include <string>
+
+CPPUNIT_TEST_SUITE_REGISTRATION (TestIniParser);
+
+void TestIniParser::setUp(void)
+{
+}
+
+void TestIniParser::tearDown(void)
+{
+}
+
+void TestIniParser::ini_parser_test(void)
+{
+ IniParser iniparser;
+
+ CPPUNIT_ASSERT(iniparser.parseFile("data/my.cnf") == true);
+ CPPUNIT_ASSERT(iniparser.get("client", "port") == "3306");
+ CPPUNIT_ASSERT(iniparser.get("mysqld", "user") == "mysql");
+ CPPUNIT_ASSERT(iniparser.get("mysqld", "old_passwords") == "");
+
+/*
+ * Commented out because this methods are protected.
+ *
+ std::string s = " apple";
+ iniparser.removeLeadingSpaces(s);
+ CPPUNIT_ASSERT(s == "apple");
+
+ s = "\t apple";
+ iniparser.removeLeadingSpaces(s);
+ CPPUNIT_ASSERT(s == "apple");
+
+ s = " apple ";
+ iniparser.removeLeadingSpaces(s);
+ CPPUNIT_ASSERT(s == "apple ");
+
+ s = "apple ";
+ iniparser.removeTrailingSpaces(s);
+ CPPUNIT_ASSERT(s == "apple");
+
+ s = "apple \t ";
+ iniparser.removeTrailingSpaces(s);
+ CPPUNIT_ASSERT(s == "apple");
+
+ s = ";comment";
+ iniparser.removeComments(s);
+ CPPUNIT_ASSERT(s == "");
+
+ s = "#comment";
+ iniparser.removeComments(s);
+ CPPUNIT_ASSERT(s == "");
+
+ s = "apple\t #comment";
+ iniparser.removeComments(s);
+ CPPUNIT_ASSERT(s == "apple\t ");
+
+ s = "apple\t #comment";
+ iniparser.removeSpacesAndComments(s);
+ CPPUNIT_ASSERT(s == "apple");
+*/
+}
Index: libmysequoia/test/TestIniParser.hpp
diff -u /dev/null libmysequoia/test/TestIniParser.hpp:1.1
--- /dev/null Mon Jan 2 12:14:28 2006
+++ libmysequoia/test/TestIniParser.hpp Mon Jan 2 12:14:27 2006
@@ -0,0 +1,42 @@
+/*
+ * Sequoia: Database clustering technology.
+ * Copyright (C) 2005 Continuent, Inc.
+ * Contact: [EMAIL PROTECTED]
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License")
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Initial developer(s): Zsolt Simon, Csaba Simon
+ * Contributor(s):
+ */
+
+#ifndef _TESTINIPARSER_HPP
+#define _TESTINIPARSER_HPP
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+class TestIniParser : public CPPUNIT_NS::TestFixture
+{
+ CPPUNIT_TEST_SUITE (TestIniParser);
+ CPPUNIT_TEST (ini_parser_test);
+ CPPUNIT_TEST_SUITE_END ();
+
+ public:
+ void setUp (void);
+ void tearDown (void);
+
+ protected:
+ void ini_parser_test(void);
+};
+
+#endif /*_TESTINIPARSER_HPP*/
Index: libmysequoia/test/data/my.cnf
diff -u /dev/null libmysequoia/test/data/my.cnf:1.1
--- /dev/null Mon Jan 2 12:14:28 2006
+++ libmysequoia/test/data/my.cnf Mon Jan 2 12:14:27 2006
@@ -0,0 +1,131 @@
+#
+# The MySQL database server configuration file.
+#
+# You can copy this to one of:
+# - "/etc/mysql/my.cnf" to set global options,
+# - "/var/lib/mysql/my.cnf" to set server-specific options or
+# - "~/.my.cnf" to set user-specific options.
+#
+# One can use all long options that the program supports.
+# Run program with --help to get a list of available options and with
+# --print-defaults to see which it would actually understand and use.
+#
+# For explanations see
+# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
+
+# This will be passed to all mysql clients
+# It has been reported that passwords should be enclosed with ticks/quotes
+# escpecially if they contain "#" chars...
+# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
+[client]
+port = 3306
+socket = /var/run/mysqld/mysqld.sock
+
+# Here is entries for some specific programs
+# The following values assume you have at least 32M ram
+
+# This was formally known as [safe_mysqld]. Both versions are currently parsed.
+[mysqld_safe]
+socket = /var/run/mysqld/mysqld.sock
+nice = 0
+
+[mysqld]
+#
+# * Basic Settings
+#
+user = mysql
+pid-file = /var/run/mysqld/mysqld.pid
+socket = /var/run/mysqld/mysqld.sock
+port = 3306
+basedir = /usr
+datadir = /var/lib/mysql
+tmpdir = /tmp
+language = /usr/share/mysql/english
+skip-external-locking
+#
+# For compatibility to other Debian packages that still use
+# libmysqlclient10 and libmysqlclient12.
+###old_passwords = 1
+#
+# Instead of skip-networking you can listen only on
+# localhost which is more compatible and is not less secure.
+# bind-address = 127.0.0.1
+###skip-networking
+#
+# * Fine Tuning
+#
+key_buffer = 16M
+max_allowed_packet = 16M
+thread_stack = 128K
+#
+# * Query Cache Configuration
+#
+query_cache_limit = 1048576
+query_cache_size = 16777216
+query_cache_type = 1
+#
+# * Logging and Replication
+#
+# Both location gets rotated by the cronjob.
+# Be aware that this log type is a performance killer.
+#log = /var/log/mysql.log
+#log = /var/log/mysql/mysql.log
+#
+# Error logging goes to syslog. This is a Debian improvement :)
+#
+# Here you can see queries with especially long duration
+#log-slow-queries = /var/log/mysql/mysql-slow.log
+#
+# The following can be used as easy to replay backup logs or for replication.
+#server-id = 1
+log-bin = /var/log/mysql/mysql-bin.log
+# See /etc/mysql/debian-log-rotate.conf for the number of files kept.
+max_binlog_size = 104857600
+#binlog-do-db = include_database_name
+#binlog-ignore-db = include_database_name
+#
+# * BerkeleyDB
+#
+# According to an MySQL employee the use of BerkeleyDB is now discouraged
+# and support for it will probably cease in the next versions.
+skip-bdb
+#
+# * InnoDB
+#
+# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
+# Read the manual for more InnoDB related options. There are many!
+#
+# * Security Features
+#
+# Read the manual, too, if you want chroot!
+# chroot = /var/lib/mysql/
+#
+# If you want to enable SSL support (recommended) read the manual or my
+# HOWTO in /usr/share/doc/mysql-server/SSL-MINI-HOWTO.txt.gz
+# ssl-ca=/etc/mysql/cacert.pem
+# ssl-cert=/etc/mysql/server-cert.pem
+# ssl-key=/etc/mysql/server-key.pem
+
+
+
+[mysqldump]
+quick
+quote-names
+max_allowed_packet = 16M
+
+[mysql]
+#no-auto-rehash # faster start of mysql but no tab completition
+
+[isamchk]
+key_buffer = 16M
+
+#
+# * NDB Cluster
+#
+# See /usr/share/doc/mysql-server-*/README.Debian for more information.
+#
+# The following configuration is read by the ndbd storage daemons,
+# not from the ndb_mgmd management daemon.
+#
+# [MYSQL_CLUSTER]
+# ndb-connectstring=127.0.0.1
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits