mirror of
				https://github.com/ElvishArtisan/rivendell.git
				synced 2025-10-30 17:23:53 +01:00 
			
		
		
		
	2020-05-23 Fred Gleason <fredg@paravelsystems.com>
* Added a 'cmdline_parser_test' test harness. * Fixed a bug in 'RDCmdSwitch' that caused value-only arguments containing '=' characters to be incorrectly parsed. Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -105,6 +105,7 @@ tests/audio_export_test | ||||
| tests/audio_import_test | ||||
| tests/audio_metadata_test | ||||
| tests/audio_peaks_test | ||||
| tests/cmdline_parser_test | ||||
| tests/datedecode_test | ||||
| tests/dateparse_test | ||||
| tests/db_charset_test | ||||
|   | ||||
| @@ -19843,3 +19843,7 @@ | ||||
| 	enumeration. | ||||
| 	* Fixed a bug in rdlibrary(1) that caused cuts to be incorrectly | ||||
| 	sorted when scheduled 'By Specified Order'. | ||||
| 2020-05-23 Fred Gleason <fredg@paravelsystems.com> | ||||
| 	* Added a 'cmdline_parser_test' test harness. | ||||
| 	* Fixed a bug in 'RDCmdSwitch' that caused value-only arguments | ||||
| 	containing '=' characters to be incorrectly parsed. | ||||
|   | ||||
| @@ -44,17 +44,23 @@ RDCmdSwitch::RDCmdSwitch(int argc,char *argv[],const char *modname, | ||||
|     if(value=="-d") { | ||||
|       switch_debug=true; | ||||
|     } | ||||
|     QStringList f0=value.split("="); | ||||
|     QStringList f0=value.split("=",QString::KeepEmptyParts); | ||||
|     if(f0.size()>=2) { | ||||
|       switch_keys.push_back(f0[0]); | ||||
|       for(int i=2;i<f0.size();i++) { | ||||
| 	f0[1]+="="+f0[i]; | ||||
|       } | ||||
|       if(f0[1].isEmpty()) { | ||||
| 	switch_values.push_back(""); | ||||
|       if(f0.at(0).left(1)=="-") { | ||||
| 	switch_keys.push_back(f0.at(0)); | ||||
| 	for(int i=2;i<f0.size();i++) { | ||||
| 	  f0[1]+="="+f0.at(i); | ||||
| 	} | ||||
| 	if(f0.at(1).isEmpty()) { | ||||
| 	  switch_values.push_back(""); | ||||
| 	} | ||||
| 	else { | ||||
| 	  switch_values.push_back(f0.at(1)); | ||||
| 	} | ||||
|       } | ||||
|       else { | ||||
| 	switch_values.push_back(f0[1]); | ||||
| 	switch_keys.push_back(f0.join("=")); | ||||
| 	switch_values.push_back(""); | ||||
|       } | ||||
|       switch_processed.push_back(false); | ||||
|     } | ||||
|   | ||||
| @@ -31,6 +31,7 @@ noinst_PROGRAMS = audio_convert_test\ | ||||
|                   audio_import_test\ | ||||
|                   audio_metadata_test\ | ||||
|                   audio_peaks_test\ | ||||
|                   cmdline_parser_test\ | ||||
|                   datedecode_test\ | ||||
|                   dateparse_test\ | ||||
|                   db_charset_test\ | ||||
| @@ -65,6 +66,9 @@ audio_metadata_test_LDADD = @LIB_RDLIBS@ @LIBVORBIS@ @QT4_LIBS@ @MUSICBRAINZ_LIB | ||||
| dist_audio_peaks_test_SOURCES = audio_peaks_test.cpp audio_peaks_test.h | ||||
| audio_peaks_test_LDADD = @LIB_RDLIBS@ @LIBVORBIS@ @QT4_LIBS@ @MUSICBRAINZ_LIBS@ -lQt3Support | ||||
|  | ||||
| dist_cmdline_parser_test_SOURCES = cmdline_parser_test.cpp cmdline_parser_test.h | ||||
| cmdline_parser_test_LDADD = @LIB_RDLIBS@ @LIBVORBIS@ @QT4_LIBS@ @MUSICBRAINZ_LIBS@ -lQt3Support | ||||
|  | ||||
| dist_datedecode_test_SOURCES = datedecode_test.cpp datedecode_test.h | ||||
| datedecode_test_LDADD = @LIB_RDLIBS@ @LIBVORBIS@ @QT4_LIBS@ @MUSICBRAINZ_LIBS@ -lQt3Support | ||||
|  | ||||
|   | ||||
							
								
								
									
										52
									
								
								tests/cmdline_parser_test.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								tests/cmdline_parser_test.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,52 @@ | ||||
| // cmdline_parser_test.cpp | ||||
| // | ||||
| // Test the Rivendell command-line parser routines. | ||||
| // | ||||
| //   (C) Copyright 2020 Fred Gleason <fredg@paravelsystems.com> | ||||
| // | ||||
| //   This program is free software; you can redistribute it and/or modify | ||||
| //   it under the terms of the GNU General Public License version 2 as | ||||
| //   published by the Free Software Foundation. | ||||
| // | ||||
| //   This program is distributed in the hope that it will be useful, | ||||
| //   but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
| //   GNU General Public License for more details. | ||||
| // | ||||
| //   You should have received a copy of the GNU General Public | ||||
| //   License along with this program; if not, write to the Free Software | ||||
| //   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||||
| // | ||||
|  | ||||
| #include <stdlib.h> | ||||
| #include <stdio.h> | ||||
|  | ||||
| #include <qapplication.h> | ||||
|  | ||||
| #include <rdcmd_switch.h> | ||||
|  | ||||
| #include "cmdline_parser_test.h" | ||||
|  | ||||
| MainObject::MainObject(QObject *parent) | ||||
|   :QObject(parent) | ||||
| { | ||||
|   // | ||||
|   // Read Command Options | ||||
|   // | ||||
|   RDCmdSwitch *cmd= | ||||
|     new RDCmdSwitch(qApp->argc(),qApp->argv(),"cmdline_parser_test", | ||||
| 		    CMDLINE_PARSER_TEST_USAGE); | ||||
|   for(unsigned i=0;i<cmd->keys();i++) { | ||||
|     printf("  key[%d]: %s\n",i,cmd->key(i).utf8().constData()); | ||||
|     printf("value[%d]: %s\n",i,cmd->value(i).toUtf8().constData()); | ||||
|   } | ||||
|   exit(0); | ||||
| } | ||||
|  | ||||
|  | ||||
| int main(int argc,char *argv[]) | ||||
| { | ||||
|   QApplication a(argc,argv,false); | ||||
|   new MainObject(); | ||||
|   return a.exec(); | ||||
| } | ||||
							
								
								
									
										35
									
								
								tests/cmdline_parser_test.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								tests/cmdline_parser_test.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,35 @@ | ||||
| // cmdline_parser_test.h | ||||
| // | ||||
| // Test the Rivendell command-line parser routines. | ||||
| // | ||||
| //   (C) Copyright 2020 Fred Gleason <fredg@paravelsystems.com> | ||||
| // | ||||
| //   This program is free software; you can redistribute it and/or modify | ||||
| //   it under the terms of the GNU General Public License version 2 as | ||||
| //   published by the Free Software Foundation. | ||||
| // | ||||
| //   This program is distributed in the hope that it will be useful, | ||||
| //   but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
| //   GNU General Public License for more details. | ||||
| // | ||||
| //   You should have received a copy of the GNU General Public | ||||
| //   License along with this program; if not, write to the Free Software | ||||
| //   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||||
| // | ||||
|  | ||||
| #ifndef CMDLINE_PARSER_TEST_H | ||||
| #define CMDLINE_PARSER_TEST_H | ||||
|  | ||||
| #include <qobject.h> | ||||
|  | ||||
| #define CMDLINE_PARSER_TEST_USAGE "<test-args> ...\n\n" | ||||
|  | ||||
| class MainObject : public QObject | ||||
| { | ||||
|  public: | ||||
|   MainObject(QObject *parent=0); | ||||
| }; | ||||
|  | ||||
|  | ||||
| #endif  // CMDLINE_PARSER_TEST_H | ||||
		Reference in New Issue
	
	Block a user