[Rcpp-commits] r4379 - in pkg/Rcpp/inst/unitTests: . cpp
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Jul 2 11:11:36 CEST 2013
Author: romain
Date: 2013-07-02 11:11:35 +0200 (Tue, 02 Jul 2013)
New Revision: 4379
Removed:
pkg/Rcpp/inst/unitTests/runit.rcout.R
Modified:
pkg/Rcpp/inst/unitTests/cpp/misc.cpp
pkg/Rcpp/inst/unitTests/runit.misc.R
Log:
move runit.rcout to runit.misc
Modified: pkg/Rcpp/inst/unitTests/cpp/misc.cpp
===================================================================
--- pkg/Rcpp/inst/unitTests/cpp/misc.cpp 2013-07-02 09:00:31 UTC (rev 4378)
+++ pkg/Rcpp/inst/unitTests/cpp/misc.cpp 2013-07-02 09:11:35 UTC (rev 4379)
@@ -22,6 +22,8 @@
#include <Rcpp.h>
using namespace Rcpp ;
using namespace std;
+#include <iostream>
+#include <fstream>
class simple {
Rcpp::Dimension dd;
@@ -84,3 +86,24 @@
);
}
+// [[Rcpp::export]]
+void test_rcout(std::string tfile, std::string teststring){
+ // define and open testfile
+ std::ofstream testfile(tfile.c_str());
+
+ // save output buffer of the Rcout stream
+ std::streambuf* Rcout_buffer = Rcout.rdbuf();
+
+ // redirect ouput into testfile
+ Rcout.rdbuf( testfile.rdbuf() );
+
+ // write a test string to the file
+ Rcout << teststring << std::endl;
+
+ // restore old output buffer
+ Rcout.rdbuf(Rcout_buffer);
+
+ // close testfile
+ testfile.close();
+}
+
Modified: pkg/Rcpp/inst/unitTests/runit.misc.R
===================================================================
--- pkg/Rcpp/inst/unitTests/runit.misc.R 2013-07-02 09:00:31 UTC (rev 4378)
+++ pkg/Rcpp/inst/unitTests/runit.misc.R 2013-07-02 09:11:35 UTC (rev 4379)
@@ -100,5 +100,22 @@
test.AreMacrosDefined <- function(){
checkTrue( Rcpp:::areMacrosDefined( "__cplusplus" ) )
}
+
+test.rcout <- function(){
+ ## define test string that is written to two files
+ teststr <- "First line.\nSecond line."
+ rcppfile <- tempfile()
+ rfile <- tempfile()
+
+ ## write to test_rcpp.txt from Rcpp
+ test_rcout(rcppfile, teststr )
+
+ ## write to test_r.txt from R
+ cat( teststr, file=rfile, sep='\n' )
+
+ ## compare whether the two files have the same data
+ checkEquals( readLines(rcppfile), readLines(rfile), msg="Rcout output")
}
+
+}
Deleted: pkg/Rcpp/inst/unitTests/runit.rcout.R
===================================================================
--- pkg/Rcpp/inst/unitTests/runit.rcout.R 2013-07-02 09:00:31 UTC (rev 4378)
+++ pkg/Rcpp/inst/unitTests/runit.rcout.R 2013-07-02 09:11:35 UTC (rev 4379)
@@ -1,71 +0,0 @@
-#!/usr/bin/r -t
-#
-# Copyright (C) 2011 - 2012 Dirk Eddelbuettel, Romain Francois and Jelmer Ypma
-#
-# This file is part of Rcpp.
-#
-# Rcpp is free software: you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 2 of the License, or
-# (at your option) any later version.
-#
-# Rcpp 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 Rcpp. If not, see <http://www.gnu.org/licenses/>.
-
-.runThisTest <- Sys.getenv("RunAllRcppTests") == "yes"
-
-if (.runThisTest) {
-
- test.rcout <- function() {
-
- src <- '
- std::string tfile = as<std::string>(tmpfile);
-
- // define and open testfile
- std::ofstream testfile(tfile.c_str());
-
- // save output buffer of the Rcout stream
- std::streambuf* Rcout_buffer = Rcout.rdbuf();
-
- // redirect ouput into testfile
- Rcout.rdbuf( testfile.rdbuf() );
-
- // write a test string to the file
- Rcout << as<std::string>( teststring ) << std::endl;
-
- // restore old output buffer
- Rcout.rdbuf(Rcout_buffer);
-
- // close testfile
- testfile.close();
-
- return Rcpp::wrap<int>( 0 );
-'
-
- fun <- cxxfunction(signature(tmpfile="character",
- teststring = "character" ),
- includes = "#include <iostream>\n#include <fstream>",
- body = src, plugin="Rcpp")
-
- ## define test string that is written to two files
- teststr <- "First line.\nSecond line."
-
- rcppfile <- tempfile()
- rfile <- tempfile()
-
- ## write to test_rcpp.txt from Rcpp
- fun(rcppfile, teststr )
-
- ## write to test_r.txt from R
- cat( teststr, file=rfile, sep='\n' )
-
- ## compare whether the two files have the same data
- checkEquals( readLines(rcppfile), readLines(rfile), msg="Rcout output")
-
- }
-}
More information about the Rcpp-commits
mailing list