2 Copyright (C) 2015 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "lib/uploader.h"
21 #include <boost/bind.hpp>
22 #include <boost/test/unit_test.hpp>
30 using boost::shared_ptr;
45 class TestUploader : public Uploader
49 : Uploader (bind (&set_status, _1), bind (&set_progress, _1))
51 _directories.push_back ("uploader");
52 _directories.push_back ("uploader/c");
53 _directories.push_back ("uploader/b");
54 _directories.push_back ("uploader/b/e");
55 _directories.push_back ("uploader/a");
56 _next_directory = _directories.begin ();
58 _files.push_back (make_pair ("test/data/uploader/b/e/f", "uploader/b/e/f"));
59 _files.push_back (make_pair ("test/data/uploader/a/d", "uploader/a/d"));
60 _next_file = _files.begin ();
64 void create_directory (boost::filesystem::path directory) {
65 std::cout << directory << "\n";
66 BOOST_CHECK (directory == *_next_directory);
70 void upload_file (boost::filesystem::path from, boost::filesystem::path to, boost::uintmax_t &, boost::uintmax_t) {
71 BOOST_CHECK (make_pair (from, to) == *_next_file);
76 vector<boost::filesystem::path> _directories;
77 vector<boost::filesystem::path>::iterator _next_directory;
78 vector<std::pair<boost::filesystem::path, boost::filesystem::path> > _files;
79 vector<std::pair<boost::filesystem::path, boost::filesystem::path> >::iterator _next_file;
82 BOOST_AUTO_TEST_CASE (uploader_test)
84 boost::filesystem::remove_all ("test/data/uploader");
85 boost::filesystem::create_directories ("test/data/uploader/a");
86 boost::filesystem::create_directories ("test/data/uploader/b");
87 boost::filesystem::create_directories ("test/data/uploader/c");
88 boost::filesystem::create_directories ("test/data/uploader/b/e");
90 ofstream f ("test/data/uploader/a/d");
93 ofstream g ("test/data/uploader/b/e/f");
96 TestUploader uploader;
97 uploader.upload ("test/data/uploader");