[gnote] Make file_read_all_* function throw when failed to open file
- From: Aurimas ÄŒernius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Make file_read_all_* function throw when failed to open file
- Date: Thu, 16 Feb 2017 11:11:39 +0000 (UTC)
commit cf40062002ffc155c66edf426b9b8ab1befbf34f
Author: Aurimas ÄŒernius <aurisc4 gmail com>
Date: Thu Feb 16 12:26:49 2017 +0200
Make file_read_all_* function throw when failed to open file
src/sharp/files.cpp | 4 ++++
src/test/unit/filesutests.cpp | 7 +++----
2 files changed, 7 insertions(+), 4 deletions(-)
---
diff --git a/src/sharp/files.cpp b/src/sharp/files.cpp
index f15ab01..d2fae2a 100644
--- a/src/sharp/files.cpp
+++ b/src/sharp/files.cpp
@@ -29,6 +29,7 @@
#include <glibmm.h>
#include <giomm/file.h>
+#include "exception.hpp"
#include "files.hpp"
@@ -90,6 +91,9 @@ namespace sharp {
}
fin.close();
}
+ else {
+ throw sharp::Exception("Failed to open file: " + path);
+ }
return lines;
}
diff --git a/src/test/unit/filesutests.cpp b/src/test/unit/filesutests.cpp
index 0403e6a..8ec25eb 100644
--- a/src/test/unit/filesutests.cpp
+++ b/src/test/unit/filesutests.cpp
@@ -24,6 +24,7 @@
#include <glibmm/miscutils.h>
#include <UnitTest++/UnitTest++.h>
+#include "sharp/exception.hpp"
#include "sharp/files.hpp"
@@ -67,8 +68,7 @@ SUITE(files)
{
std::vector<Glib::ustring> lines;
// very unlikely to exist
- lines = sharp::file_read_all_lines(__FILE__ __FILE__);
- CHECK_EQUAL(0, lines.size());
+ CHECK_THROW(sharp::file_read_all_lines(__FILE__ __FILE__), sharp::Exception);
char temp_file_name[] = "/tmp/gnotetestXXXXXX";
int fd = mkstemp(temp_file_name);
@@ -92,8 +92,7 @@ SUITE(files)
{
Glib::ustring file_content;
// very unlikely to exist
- file_content = sharp::file_read_all_text(__FILE__ __FILE__);
- CHECK_EQUAL("", file_content);
+ CHECK_THROW(sharp::file_read_all_text(__FILE__ __FILE__), sharp::Exception);
char temp_file_name[] = "/tmp/gnotetestXXXXXX";
int fd = mkstemp(temp_file_name);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]