From: <ro...@us...> - 2011-01-09 00:26:36
|
Revision: 1777 http://nsclspectcl.svn.sourceforge.net/nsclspectcl/?rev=1777&view=rev Author: ron-fox Date: 2011-01-09 00:26:30 +0000 (Sun, 09 Jan 2011) Log Message: ----------- Get evtclose command working. Added Paths: ----------- trunk/nextgen/bindings/tcl/TclEvtClose.cpp trunk/nextgen/bindings/tcl/evtclose.test Added: trunk/nextgen/bindings/tcl/TclEvtClose.cpp =================================================================== --- trunk/nextgen/bindings/tcl/TclEvtClose.cpp (rev 0) +++ trunk/nextgen/bindings/tcl/TclEvtClose.cpp 2011-01-09 00:26:30 UTC (rev 1777) @@ -0,0 +1,66 @@ +/* + This software is Copyright by the Board of Trustees of Michigan + State University (c) Copyright 2008 + + You may use this software under the terms of the GNU public license + (GPL). The terms of this license are described at: + + http://www.gnu.org/licenses/gpl.txt + + Author: + Ron Fox + NSCL + Michigan State University + East Lansing, MI 48824-1321 +*/ + +#include <config.h> +#include "TclEvtClose.h" +#include "handleManager.h" +#include <TCLInterpreter.h> +#include <TCLObject.h> +#include <spectcl_experiment.h> + +/** + ** Constructor uses the base class to get the real work done. + ** @param interp - referencde to the TCL Intpereter on which the command is registered. + */ +CTclEvtClose::CTclEvtClose(CTCLInterpreter& interp) : + CTclDBCommand(interp, "evtclose", true) +{ +} +/** + ** The destructor is also handled by the base class. + */ +CTclEvtClose::~CTclEvtClose() +{} + +/** + ** The command is dispatched here. + ** See the class level comments for information about command syntax. + ** @param interp - interpreter running the command. + ** @param objv - encapsluated Tcl_Obj*s that represent this command. + ** @return int + ** @retval TCL_OK - command worked. Result is a handle to the database. + ** @retval TCL_ERROR - command failed; result is an error message. + */ +int +CTclEvtClose::operator()(CTCLInterpreter& interp, + std::vector<CTCLObject>& objv) +{ + try { + spectcl_events pHandle = getDatabaseHandle(interp, objv, 1, + "spectcl::evtclose"); + int status = spectcl_events_close(pHandle); + if (status != SPEXP_OK) { + std::string msg = spectcl_experiment_error_msg(status); + throw msg; + } + } + catch (std::string msg) { + interp.setResult(msg); + return TCL_ERROR; + } + + return TCL_OK; +} Added: trunk/nextgen/bindings/tcl/evtclose.test =================================================================== --- trunk/nextgen/bindings/tcl/evtclose.test (rev 0) +++ trunk/nextgen/bindings/tcl/evtclose.test 2011-01-09 00:26:30 UTC (rev 1777) @@ -0,0 +1,73 @@ +# +# Tests for the spectcl::evtclose command. +# +package require tcltest +load .libs/libSpecTclExperiment.so + +namespace import ::tcltest::* + +# +# much of the setup/cleanup is standard... +# Create an experiment database, and put run 1 in it. +# +proc setup {} { + set tmpdir [makeDirectory databases] + set expfile [file join $tmpdir exp.db] + set evtfile [file join $tmpdir evt.db] + + set exphandle [::spectcl::expcreate $expfile] + ::spectcl::run create $exphandle 1 {This is a test title} + set evhandle [::spectcl::evtcreate $exphandle 1 $evtfile] + + return [list $exphandle $expfile $evtfile $evhandle] + +} + +proc cleanup {exphandle expfile evtfile} { + ::spectcl::expclose $exphandle + + catch {file delete $expfile} + catch {file delete $evtfile} + +} + +#----------------------- tests begin here ------------------- + +test fail_1 {Close without handle can't work} \ + -body { + catch {::spectcl::evtclose} + } -result 1 + +test fail_2 {Close of something that is not a database handle should also fail} \ + -body { + catch {::spectcl::evtclose junk} + } -result 1 +test fail_3 {Close of something that is not an event handle should also fail} \ + -setup { + set setupdata [setup] + set exphandle [lindex $setupdata 0] + set expfile [lindex $setupdata 1] + set evtfile [lindex $setupdata 2] + set evhandle [lindex $setupdata 3] + } \ + -cleanup { + cleanup $exphandle $expfile $evtfile + } \ + -body { + catch {::spectcl::evtclose $exphandle} + } -result 1 + +test evtcloseOk {Close of an event file should work} \ + -setup { + set setupdata [setup] + set exphandle [lindex $setupdata 0] + set expfile [lindex $setupdata 1] + set evtfile [lindex $setupdata 2] + set evhandle [lindex $setupdata 3] + } \ + -cleanup { + cleanup $exphandle $expfile $evtfile + } \ + -body { + catch {::spectcl::evtclose $evhandle} + } -result 0 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |