summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kyoshida@novell.com>2009-12-29 14:28:51 -0500
committerKohei Yoshida <kyoshida@novell.com>2009-12-29 14:28:51 -0500
commit447e2d88b800a5877594e4acfe44f9554412efd5 (patch)
treef9324e2aa29456d7baa59fae38acef6423f08d41
parent20049d18a5997b0c02283af9c7697bea3560c1a9 (diff)
Use a generic exception instead of C-lick error handling.
-rw-r--r--inc/global.hxx15
-rwxr-xr-xrun-test.sh.in1
-rw-r--r--setenv.sh.in2
-rw-r--r--source/global.cxx18
-rw-r--r--source/main.cxx24
5 files changed, 45 insertions, 15 deletions
diff --git a/inc/global.hxx b/inc/global.hxx
index db9cf96..09212ef 100644
--- a/inc/global.hxx
+++ b/inc/global.hxx
@@ -5,6 +5,7 @@
#include "cppuhelper/implementationentry.hxx"
#include <string>
+#include <exception>
namespace com { namespace sun { namespace star {
namespace frame {
@@ -18,6 +19,18 @@ namespace com { namespace sun { namespace star {
namespace test {
+class GeneralException : public ::std::exception
+{
+public:
+ explicit GeneralException(const ::std::string& msg);
+ virtual ~GeneralException() throw();
+ virtual const char* what() const throw();
+private:
+ ::std::string maMsg;
+};
+
+::rtl::OUString ascii(const sal_Char* str);
+
::com::sun::star::uno::Reference< ::com::sun::star::frame::XDesktop >
bootstrap();
@@ -28,6 +41,8 @@ namespace test {
void info(const ::std::string& msg);
void error(const ::std::string& msg);
+::std::string getEnvVar(const char* name);
+
}
#endif
diff --git a/run-test.sh.in b/run-test.sh.in
index 35cdbf2..51c13b0 100755
--- a/run-test.sh.in
+++ b/run-test.sh.in
@@ -2,6 +2,7 @@
export LD_LIBRARY_PATH=@OOO_INSTALL_PATH@/program:@OOO_INSTALL_PATH@/ure/lib
source @ROOTDIR@/setenv.sh
+mkdir "$CTRL_XLS_OUT_DIR" || /usr/true
cd @OOO_INSTALL_PATH@/ure/lib
@ROOTDIR@/test
diff --git a/setenv.sh.in b/setenv.sh.in
index 4943192..671ae97 100644
--- a/setenv.sh.in
+++ b/setenv.sh.in
@@ -1,4 +1,4 @@
CTRL_XLS_IN_DIR=@ROOTDIR@/control-import
CTRL_XLS_OUT_DIR=@ROOTDIR@/control-export
-export CTRL_XLS_IN_DIR CTRL_XSL_OUT_DIR
+export CTRL_XLS_IN_DIR CTRL_XLS_OUT_DIR
diff --git a/source/global.cxx b/source/global.cxx
index 39e63a0..47fa340 100644
--- a/source/global.cxx
+++ b/source/global.cxx
@@ -11,6 +11,7 @@
#include <com/sun/star/beans/PropertyValue.hpp>
#include <cstring>
+#include <cstdlib>
#include <iostream>
using ::com::sun::star::beans::PropertyValue;
@@ -29,6 +30,14 @@ using namespace ::std;
namespace test {
+GeneralException::GeneralException(const string& msg) : maMsg(msg) {}
+GeneralException::~GeneralException() throw() {}
+
+const char* GeneralException::what() const throw()
+{
+ return maMsg.c_str();
+}
+
OUString ascii(const sal_Char* str)
{
return ::rtl::OUString::intern(str, ::std::strlen(str), RTL_TEXTENCODING_ASCII_US);
@@ -74,4 +83,13 @@ void error(const string& msg)
cerr << "error: " << msg << endl;
}
+string getEnvVar(const char* name)
+{
+ char* var = getenv(name);
+ if (!var)
+ throw GeneralException(string("failed to get environment variable ") + name);
+
+ return string(var);
+}
+
}
diff --git a/source/main.cxx b/source/main.cxx
index 5006947..2357d7e 100644
--- a/source/main.cxx
+++ b/source/main.cxx
@@ -86,7 +86,7 @@ public:
{
cout << "loading " << rtl::OUStringToOString(r, RTL_TEXTENCODING_UTF8).getStr() << endl;
Reference<XSpreadsheetDocument> xDoc = loadComponent(mxDesktop, r);
- sleep(2);
+ sleep(1);
Reference<util::XCloseable> xCloseable(xDoc, UNO_QUERY_THROW);
xCloseable->close(true);
}
@@ -99,21 +99,17 @@ private:
int main()
{
- cout << "test program begins" << endl;
- char* pXlsInDir = getenv("CTRL_XLS_IN_DIR");
- if (!pXlsInDir)
- return EXIT_FAILURE;
-
- string aXclImportPath(pXlsInDir);
- vector<OUString> aFilePaths;
- if (!getImportDocuments(aXclImportPath, aFilePaths))
- return EXIT_FAILURE;
-
- cout << "control xls inport directory: " << aXclImportPath << endl;
- for_each(aFilePaths.begin(), aFilePaths.end(), PrintFilePath());
-
try
{
+ string aXclImportPath = getEnvVar("CTRL_XLS_IN_DIR");
+ string aXclExportPath = getEnvVar("CTRL_XLS_OUT_DIR");
+ vector<OUString> aFilePaths;
+ if (!getImportDocuments(aXclImportPath, aFilePaths))
+ return EXIT_FAILURE;
+
+ cout << "control xls inport directory: " << aXclImportPath << endl;
+ for_each(aFilePaths.begin(), aFilePaths.end(), PrintFilePath());
+
Reference<XDesktop> xDesktop = bootstrap();
for_each(aFilePaths.begin(), aFilePaths.end(), ProcessFile(xDesktop));
xDesktop->terminate();