[rkward-cvs] SF.net SVN: rkward:[2546] trunk/rkward

tfry at users.sourceforge.net tfry at users.sourceforge.net
Wed Jun 24 16:29:10 UTC 2009


Revision: 2546
          http://rkward.svn.sourceforge.net/rkward/?rev=2546&view=rev
Author:   tfry
Date:     2009-06-24 16:29:09 +0000 (Wed, 24 Jun 2009)

Log Message:
-----------
Fix some more buglets in the testing framework

Modified Paths:
--------------
    trunk/rkward/rkward/plugin/rkabstractoptionselector.cpp
    trunk/rkward/rkward/plugin/rkcomponent.cpp
    trunk/rkward/rkward/plugin/rkcomponent.h
    trunk/rkward/rkward/plugin/rkcomponentproperties.cpp
    trunk/rkward/rkward/plugin/rkcomponentproperties.h
    trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R
    trunk/rkward/tests/import_export_plugins.R
    trunk/rkward/tests/test.R

Modified: trunk/rkward/rkward/plugin/rkabstractoptionselector.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkabstractoptionselector.cpp	2009-06-24 12:27:55 UTC (rev 2545)
+++ trunk/rkward/rkward/plugin/rkabstractoptionselector.cpp	2009-06-24 16:29:09 UTC (rev 2546)
@@ -118,7 +118,12 @@
 		RK_ASSERT (false);
 	}
 	if (new_id < 0) {
-		RK_DO (qDebug ("no such option"), PLUGIN, DL_ERROR);
+		RK_DO (qDebug ("option selector '%s' has no such option:", qPrintable (getIdInParent ())), PLUGIN, DL_ERROR);
+		if (property == string) {
+			RK_DO (qDebug ("'%s'", qPrintable (string->value ())), PLUGIN, DL_ERROR);
+		} else {
+			RK_DO (qDebug ("index %d", number->intValue ()), PLUGIN, DL_ERROR);
+		}
 		return;
 	}
 
@@ -164,7 +169,7 @@
 				}
 			}
 			if (settable_opt >= 0) itemSelected (settable_opt);
-			else RK_DO (qDebug ("No option left enabled. Disable the entire component, instead!"), PLUGIN, DL_ERROR);
+			else RK_DO (qDebug ("No option left enabled. Disable the entire component '%s', instead!", qPrintable (getIdInParent ())), PLUGIN, DL_ERROR);
 		}
 	}
 

Modified: trunk/rkward/rkward/plugin/rkcomponent.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponent.cpp	2009-06-24 12:27:55 UTC (rev 2545)
+++ trunk/rkward/rkward/plugin/rkcomponent.cpp	2009-06-24 16:29:09 UTC (rev 2546)
@@ -49,19 +49,17 @@
 	RK_TRACE (PLUGIN);
 
 	for (QHash<QString, RKComponentBase*>::const_iterator it = child_map.constBegin (); it != child_map.constEnd (); ++it) {
-		if (it.key () != "#noid#") {
-			if (it.value ()->isProperty ()) {
-				if (include_top_level) {
-					RKComponentPropertyBase *p = static_cast<RKComponentPropertyBase*> (it.value ());
-					if (!p->isInternal ()) {
-						list->insert (prefix + it.key (), it.value ()->value ());
-					}
-				}
-			} else {
-				RK_ASSERT (it.value ()->isComponent ());
-				if (!static_cast<RKComponent *> (it.value ())->isEnabled ()) continue;
-				it.value ()->fetchPropertyValuesRecursive (list, true, prefix + it.key () + '.');
+		if (it.key () == "#noid#") continue;
+		if (it.value ()->isInternal ()) continue;
+
+		if (it.value ()->isProperty ()) {
+			if (include_top_level) {
+				list->insert (prefix + it.key (), static_cast<RKComponentPropertyBase*> (it.value ())->value ());
 			}
+		} else {
+			RK_ASSERT (it.value ()->isComponent ());
+			if (!static_cast<RKComponent *> (it.value ())->isEnabled ()) continue;
+			it.value ()->fetchPropertyValuesRecursive (list, true, prefix + it.key () + '.');
 		}
 	}
 }
@@ -276,18 +274,18 @@
 
 	if (!parentComponent ()) return;
 
-	for (QHash<QString, RKComponentBase*>::const_iterator it = parentComponent ()->child_map.constBegin (); it != parentComponent ()->child_map.constEnd (); ++it) {
-		if (it.value () == this) {
-			QString key = it.key ();
 	// unfortunately, several items might hvae the same key, and there seems to be no way to selectively remove the current item only.
 	// however, this function should only ever be called in cases of emergency and to prevent crashes. So we make extra sure to remove the child,
 	// even if we remove a little more than necessary along the way.
-			while (parentComponent ()->child_map.remove (key)) {;}
-			return;
-		}
-	}
+	QString key = getIdInParent ();
+	while (parentComponent ()->child_map.remove (key)) {;}
+}
 
-	RK_ASSERT (false);
+QString RKComponent::getIdInParent () const {
+	RK_TRACE (PLUGIN);
+
+	if (!parentComponent ()) return QString ();
+	return (parentComponent ()->child_map.key (const_cast<RKComponent*> (this)));
 }
 
 #include "rkcomponent.moc"

Modified: trunk/rkward/rkward/plugin/rkcomponent.h
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponent.h	2009-06-24 12:27:55 UTC (rev 2545)
+++ trunk/rkward/rkward/plugin/rkcomponent.h	2009-06-24 16:29:09 UTC (rev 2546)
@@ -28,7 +28,7 @@
 class RKComponentBase {
 public:
 /** constructor */
-	RKComponentBase () { required=true; };
+	RKComponentBase () { required=true; is_internal=false; };
 /** destructor */
 	virtual ~RKComponentBase () {};
 /** enum of types of properties. Used from RTTI. Don't change the values, as there are some range checks in the code (see isProperty ()) */
@@ -95,6 +95,10 @@
 /** set values from a string created with serializeState() (split by "\n"). @see serializeState (), @see setPropertyValues ().
 @returns status code */
 	UnserializeError unserializeState (const QStringList &state);
+
+/** Some properties/components will be marked as internal, such as visibility properties, which are not meant to be set directly by the user. These will be ignored in RKComponent::fetchPropertyValuesRecursive() */
+	void setInternal (bool internal) { is_internal = internal; };
+	bool isInternal () const { return is_internal; };
 protected:
 	QHash<QString, RKComponentBase*> child_map;
 	bool required;
@@ -106,6 +110,8 @@
 /** counterpart to fetchPropertyValuesRecursive (). Tries to apply all values from the list to properties of the given names. If some keys can not be found, or do not resolve to properties, the are ignored.
 @param list a list of id->value such as generated by fetchPropertyValuesRecursive () */
 	void setPropertyValues (QMap<QString, QString> *list, bool warn_internal=false);
+private:
+	bool is_internal;
 };
 
 #include "rkcomponentproperties.h"
@@ -157,10 +163,13 @@
 	void setRequired (bool required);
 
 /** The parent of this component. Should be notified, whenever isSatisfied () or isReady ()-state changed. */
-	RKComponent *parentComponent () { return _parent; };
+	RKComponent *parentComponent () const { return _parent; };
 
 /** Is the component "ready"? I.e. it is up to date according to current settings. Does not imply it is also satisfied. Default implementation always returns true. */
 	virtual bool isReady () { return true; };
+
+/** Find the id of this component. NOTE: this is slow. Better to store the id in the first place, if needed */
+	QString getIdInParent () const;
 protected slots:
 /** if a child component self-destructs, it should remove itself from its parent *before* destructing. Don't use in a regular destructor. Call only if the child dies unexpectedly */
 	void removeFromParent ();

Modified: trunk/rkward/rkward/plugin/rkcomponentproperties.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponentproperties.cpp	2009-06-24 12:27:55 UTC (rev 2545)
+++ trunk/rkward/rkward/plugin/rkcomponentproperties.cpp	2009-06-24 16:29:09 UTC (rev 2546)
@@ -101,7 +101,6 @@
 	RK_TRACE (PLUGIN);
 	RKComponentPropertyBase::required = required;
 	is_valid = true;
-	is_internal = false;
 }
 
 RKComponentPropertyBase::~RKComponentPropertyBase () {

Modified: trunk/rkward/rkward/plugin/rkcomponentproperties.h
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponentproperties.h	2009-06-24 12:27:55 UTC (rev 2545)
+++ trunk/rkward/rkward/plugin/rkcomponentproperties.h	2009-06-24 16:29:09 UTC (rev 2546)
@@ -53,10 +53,6 @@
 Generally with few exceptions, you can only connect to properties that are either of the same class as this property, or of an extended class. Maybe in the future we will add some sophisticated converters allowing to connect vastly different types of properties in a meaningful way.
 If you specify a modifier, only the sub-value indicated by the modifier will be retrieved from the governing property on governorValueChanged. In this case reconcile_requirements is ignored. */
 	virtual void connectToGovernor (RKComponentPropertyBase *governor, const QString &modifier=QString::null, bool reconcile_requirements=true);
-
-/** Some properties will be marked as internal, such as visibility properties, which are not meant to be set directly by the user. These will be ignored in RKComponent::fetchPropertyValuesRecursive() */
-	void setInternal (bool internal) { is_internal = internal; };
-	bool isInternal () const { return is_internal; };
 signals:
 /** property has changed its value. Any connected RKComponentPropertys/RKComponents should update their state
 @param property A pointer to the changed property for easy reference */
@@ -70,8 +66,6 @@
 	QString _value;
 /** if we're only interested in a specific sub-information of the governor-property, we need to remember the corresponding modifier */
 	QString governor_modifier;
-private:
-	bool is_internal;
 };
 
 

Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R	2009-06-24 12:27:55 UTC (rev 2545)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R	2009-06-24 16:29:09 UTC (rev 2546)
@@ -337,7 +337,11 @@
 	callstrings[2] <- match.arg (submit.mode)
 	if (length (settings) > 0) {
 		for (i in 1:length(settings)) {
-			callstrings[i+2] = paste (names(settings)[i], settings[i], sep="=")
+			# properly passing on escaped characters is a pain. This seems to work.
+			deparsed <- deparse (settings[[i]])
+			deparsed_unquoted <- substr (deparsed, 2, nchar (deparsed) - 1)
+			callstrings[i + 2] <- paste(names(settings)[i], deparsed_unquoted, 
+			sep = "=")
 		}
 	}
 

Modified: trunk/rkward/tests/import_export_plugins.R
===================================================================
--- trunk/rkward/tests/import_export_plugins.R	2009-06-24 12:27:55 UTC (rev 2545)
+++ trunk/rkward/tests/import_export_plugins.R	2009-06-24 16:29:09 UTC (rev 2546)
@@ -2,27 +2,36 @@
 # test framework, multiple inclusion should do no harm
 source ("test.R")
 
-x <- new ("RKTest", id="firsttest", call=function () rk.print (1))
-
 suite <- new ("RKTestSuite", id="import_export_plugins",
 	initCalls = list (
 		function () {
 			library ("R2HTML")
 		},
 		function () {
+			# prepare some different files for loading
 			women <- datasets::women
+
 			save (women, file="women.RData")
+			write.csv (women, file="women.csv")
+
+			suppressWarnings (rm ("women"))
 		}
 	), tests = list (
 		new ("RKTest", id="load_r_object", call=function () {
-			suppressWarnings (rm ("women"))
-
 			rk.call.plugin ("rkward::load_r_object", file.selection="women.RData", other_env.state="0", submit.mode="submit")
 
 			stopifnot (all.equal (women, datasets::women))
+
+			# always clean up after the test!
+			suppressWarnings (rm ("women"))
 		}),
-		new ("RKTest", id="secondtest", call=function () rk.print (2)),
-		x
+		new ("RKTest", id="import_csv", call=function () {
+			rk.call.plugin ("rkward::import_csv", allow_escapes.state="", blanklinesskip.state="TRUE", checkname.state="TRUE", colclass.string="", colname.string="", dec.string="'.'", doedit.state="0", file.selection="women.csv", flush.state="", isrow.state="false", na.text="NA", name.selection="women", nrows.text="-1", quick.string="csv", quote.string="'\\\"'", sep.string="','", skip.text="0", strings_as_factors.string="", stripwhite.state="FALSE", submit.mode="auto")
+
+			stopifnot (all.equal (women, datasets::women))
+
+			suppressWarnings (rm ("women"))
+		})
 	), postCalls = list ()
 )
 

Modified: trunk/rkward/tests/test.R
===================================================================
--- trunk/rkward/tests/test.R	2009-06-24 12:27:55 UTC (rev 2545)
+++ trunk/rkward/tests/test.R	2009-06-24 16:29:09 UTC (rev 2546)
@@ -209,7 +209,7 @@
 	.rk.cat.output ("rk.call.plugin (\"")
 	.rk.cat.output (plugin)
 	.rk.cat.output ("\", ")
-	.rk.cat.output (gsub ("=", "=\"", gsub ("\n", "\", ", gsub ("\"", "\\\"", settings))))
+	.rk.cat.output (gsub ("^\"", "", gsub ("=", "=\"", gsub ("\n", "\", ", settings))))
 	.rk.cat.output ("\", submit.mode=\"submit\")</pre>")
 }
 


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




More information about the rkward-tracker mailing list