SF.net SVN: nagiosplug: [1951] nagiosplug/trunk/lib/tests

[email protected]
Newsgroups gmane.network.nagios.plugins.cvs
Message-ID <[email protected]>
Revision: 1951
          http://nagiosplug.svn.sourceforge.net/nagiosplug/?rev=1951&view=rev
Author:   dermoth
Date:     2008-03-16 11:10:47 -0700 (Sun, 16 Mar 2008)

Log Message:
-----------
Add tests:
- DOS-newline ini file
- section defined twice

Modified Paths:
--------------
    nagiosplug/trunk/lib/tests/plugin.ini
    nagiosplug/trunk/lib/tests/test_ini.c

Added Paths:
-----------
    nagiosplug/trunk/lib/tests/config-dos.ini

Added: nagiosplug/trunk/lib/tests/config-dos.ini
===================================================================
--- nagiosplug/trunk/lib/tests/config-dos.ini	                        (rev 0)
+++ nagiosplug/trunk/lib/tests/config-dos.ini	2008-03-16 18:10:47 UTC (rev 1951)
@@ -0,0 +1,24 @@
+# This config file is amended from perl's Config::Tiny's testcases
+
+# Line below is allowed in perl's Config::Tiny, but not in our parse_ini.c
+#root=something
+
+[section]
+one=two
+Foo=Bar
+this=Your Mother!
+blank=
+
+[Section Two]
+something else=blah
+ remove = whitespace   	
+
+[ /path/to/file.txt ]
+this=that
+
+[ section2]
+this=that
+
+[section3 ]
+this=that
+

Modified: nagiosplug/trunk/lib/tests/plugin.ini
===================================================================
--- nagiosplug/trunk/lib/tests/plugin.ini	2008-03-15 22:42:01 UTC (rev 1950)
+++ nagiosplug/trunk/lib/tests/plugin.ini	2008-03-16 18:10:47 UTC (rev 1951)
@@ -3,10 +3,16 @@
 username=operator
 password=secret		# Remember to change later
 
+[section_twice]
+foo=bar
+
 [check_mysql2]
 u=admin
 p=secret
 
+[section_twice]
+bar=foo
+
 [check space_and_flags]
 foo=bar
 a=

Modified: nagiosplug/trunk/lib/tests/test_ini.c
===================================================================
--- nagiosplug/trunk/lib/tests/test_ini.c	2008-03-15 22:42:01 UTC (rev 1950)
+++ nagiosplug/trunk/lib/tests/test_ini.c	2008-03-16 18:10:47 UTC (rev 1951)
@@ -34,12 +34,15 @@
 list2str(np_arg_list *optlst)
 {
 	char *optstr=NULL;
+	np_arg_list *optltmp;
 
 	/* Put everything as a space-separated string */
 	asprintf(&optstr, "");
 	while (optlst) {
 		asprintf(&optstr, "%s%s ", optstr, optlst->arg);
+		optltmp=optlst;
 		optlst=optlst->next;
+		free(optltmp);
 	}
 	/* Strip last whitespace */
 	if (strlen(optstr)>1) optstr[strlen(optstr)-1]='\0';
@@ -52,7 +55,7 @@
 {
 	char *optstr=NULL;
 
-	plan_tests(10);
+	plan_tests(12);
 
 	optstr=list2str(np_get_defaults("section@./config-tiny.ini", "check_disk"));
 	ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank"), "config-tiny.ini's section as expected");
@@ -94,6 +97,14 @@
 	ok( !strcmp(optstr, "--foo=bar -a -b --bar"), "plugin.ini space in stanza and flag arguments");
 	my_free(optstr);
 
+	optstr=list2str(np_get_defaults("Section Two@./config-dos.ini", "check_disk"));
+	ok( !strcmp(optstr, "--something else=blah --remove=whitespace"), "config-dos.ini's Section Two as expected");
+	my_free(optstr);
+
+	optstr=list2str(np_get_defaults("section_twice@./plugin.ini", "check_disk"));
+	ok( !strcmp(optstr, "--foo=bar --bar=foo"), "plugin.ini's section_twice defined twice in the file");
+	my_free(optstr);
+
 	return exit_status();
 }
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.