[gnote] Add tests for directory_get_directories
- From: Aurimas Černius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Add tests for directory_get_directories
- Date: Sat, 6 Apr 2019 16:58:07 +0000 (UTC)
commit 2139715a51e166d0ad3aa4f609051adcb9be8cde
Author: Aurimas Černius <aurisc4 gmail com>
Date: Mon Jul 30 17:38:00 2018 +0300
Add tests for directory_get_directories
src/Makefile.am | 1 +
src/test/runner.cpp | 5 +-
src/test/unit/directorytests.cpp | 128 +++++++++++++++++++++++++++++++++++++++
3 files changed, 133 insertions(+), 1 deletion(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index e4907b56..630743b3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -40,6 +40,7 @@ gnoteunittests_SOURCES = \
test/testsyncmanager.cpp test/testsyncmanager.hpp \
test/testtagmanager.cpp test/testtagmanager.hpp \
test/unit/datetimeutests.cpp \
+ test/unit/directorytests.cpp \
test/unit/filesutests.cpp \
test/unit/fileinfoutests.cpp \
test/unit/gnotesyncclientutests.cpp \
diff --git a/src/test/runner.cpp b/src/test/runner.cpp
index df79c3c7..a47355f9 100644
--- a/src/test/runner.cpp
+++ b/src/test/runner.cpp
@@ -1,7 +1,7 @@
/*
* gnote
*
- * Copyright (C) 2017-2018 Aurimas Cernius
+ * Copyright (C) 2017-2019 Aurimas Cernius
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,6 +19,8 @@
#include <glibmm/init.h>
+#include <giomm/init.h>
+
#include <UnitTest++/UnitTest++.h>
int main(int /*argc*/, char ** /*argv*/)
@@ -26,6 +28,7 @@ int main(int /*argc*/, char ** /*argv*/)
// force certain timezone so that time tests work
setenv("TZ", "Europe/London", 1);
Glib::init();
+ Gio::init();
return UnitTest::RunAllTests();
}
diff --git a/src/test/unit/directorytests.cpp b/src/test/unit/directorytests.cpp
new file mode 100644
index 00000000..b3e55100
--- /dev/null
+++ b/src/test/unit/directorytests.cpp
@@ -0,0 +1,128 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2018 Aurimas Cernius
+ *
+ * This program 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include <glibmm/miscutils.h>
+#include <UnitTest++/UnitTest++.h>
+
+#include "sharp/directory.hpp"
+
+#include <glibmm/fileutils.h>
+
+SUITE(directory)
+{
+ TEST(get_directories__ustr__non_existent_directory)
+ {
+ Glib::ustring dir = Glib::build_filename(Glib::path_get_dirname(__FILE__), "nonexistent");
+
+ std::list<Glib::ustring> directories;
+ sharp::directory_get_directories(dir, directories);
+ CHECK_EQUAL(0, directories.size());
+ }
+
+ TEST(get_directories__File__non_existent_directory)
+ {
+ auto dir = Gio::File::create_for_path(Glib::build_filename(Glib::path_get_dirname(__FILE__),
"nonexistent"));
+
+ std::vector<Glib::RefPtr<Gio::File>> directories;
+ sharp::directory_get_directories(dir, directories);
+ CHECK_EQUAL(0, directories.size());
+ }
+
+ TEST(get_directories__ustr__regular_file)
+ {
+ Glib::ustring dir(__FILE__);
+
+ std::list<Glib::ustring> directories;
+ sharp::directory_get_directories(dir, directories);
+ CHECK_EQUAL(0, directories.size());
+ }
+
+ TEST(get_directories__File__regular_file)
+ {
+ auto dir = Gio::File::create_for_path(__FILE__);
+
+ std::vector<Glib::RefPtr<Gio::File>> directories;
+ sharp::directory_get_directories(dir, directories);
+ CHECK_EQUAL(0, directories.size());
+ }
+
+ TEST(get_directories__ustr__no_subdirs)
+ {
+ Glib::ustring dir = Glib::build_filename(Glib::path_get_dirname(__FILE__), ".deps");
+
+ std::list<Glib::ustring> directories;
+ sharp::directory_get_directories(dir, directories);
+ CHECK_EQUAL(0, directories.size());
+ }
+
+ TEST(get_directories__File__no_subdirs)
+ {
+ auto dir = Gio::File::create_for_path(Glib::build_filename(Glib::path_get_dirname(__FILE__), ".deps"));
+
+ std::vector<Glib::RefPtr<Gio::File>> directories;
+ sharp::directory_get_directories(dir, directories);
+ CHECK_EQUAL(0, directories.size());
+ }
+
+ TEST(get_directories__ustr__one_subdir)
+ {
+ Glib::ustring dir = Glib::path_get_dirname(__FILE__);
+
+ std::list<Glib::ustring> directories;
+ sharp::directory_get_directories(dir, directories);
+ CHECK_EQUAL(1, directories.size());
+ }
+
+ TEST(get_directories__File__one_subdir)
+ {
+ auto dir = Gio::File::create_for_path(Glib::path_get_dirname(__FILE__));
+
+ std::vector<Glib::RefPtr<Gio::File>> directories;
+ sharp::directory_get_directories(dir, directories);
+ CHECK_EQUAL(1, directories.size());
+ }
+
+ TEST(get_directories__same_return)
+ {
+ auto dir = Glib::path_get_dirname(Glib::path_get_dirname(__FILE__));
+
+ std::list<Glib::ustring> dirss;
+ sharp::directory_get_directories(dir, dirss);
+
+ auto file = Gio::File::create_for_path(dir);
+
+ std::vector<Glib::RefPtr<Gio::File>> dirsf;
+ sharp::directory_get_directories(file, dirsf);
+
+ CHECK(0 < dirss.size());
+ CHECK_EQUAL(dirss.size(), dirsf.size());
+ for(auto f : dirsf) {
+ auto name = Glib::path_get_basename(f->get_path());
+ for(auto iter = dirss.begin(); iter != dirss.end(); ++iter) {
+ if(name == Glib::path_get_basename(*iter)) {
+ dirss.erase(iter);
+ break;
+ }
+ }
+ }
+ CHECK_EQUAL(0, dirss.size());
+ }
+}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]