Feature #462: url support

- added uri class for proper uri and path handling
This commit is contained in:
Johannes Schlatow
2010-10-06 16:11:32 +02:00
parent b041e54be6
commit 042d7b40de
17 changed files with 505 additions and 343 deletions

View File

@@ -1,7 +1,7 @@
PROJECT = t.t tdb.t date.t duration.t t.benchmark.t text.t autocomplete.t \
config.t seq.t att.t stringtable.t record.t nibbler.t subst.t filt.t \
cmd.t util.t color.t list.t path.t file.t directory.t grid.t rx.t \
taskmod.t sensor.t rectangle.t tree.t tree2.t lisp.t transport.t
taskmod.t sensor.t rectangle.t tree.t tree2.t lisp.t uri.t
CFLAGS = -I. -I.. -I../.. -Wall -pedantic -ggdb3 -fno-rtti
LFLAGS = -L/usr/local/lib -lpthread -lncurses -llua
OBJECTS = ../t-TDB.o ../t-Task.o ../t-text.o ../t-Date.o ../t-Table.o \
@@ -15,7 +15,7 @@ OBJECTS = ../t-TDB.o ../t-Task.o ../t-text.o ../t-Date.o ../t-Table.o \
../t-Hooks.o ../t-API.o ../t-rx.o ../t-Taskmod.o ../t-dependency.o \
../t-Transport.o ../t-TransportSSH.o ../t-Sensor.o ../t-Thread.o \
../t-Lisp.o ../t-Rectangle.o ../t-Tree.o ../t-TransportRSYNC.o \
../t-TransportCurl.o
../t-TransportCurl.o ../t-Uri.o
all: $(PROJECT)
@@ -106,9 +106,6 @@ rx.t: rx.t.o $(OBJECTS) test.o
taskmod.t: taskmod.t.o $(OBJECTS) test.o
g++ taskmod.t.o $(OBJECTS) test.o $(LFLAGS) -o taskmod.t
transport.t: transport.t.o $(OBJECTS) test.o
g++ transport.t.o $(OBJECTS) test.o $(LFLAGS) -o transport.t
lisp.t: lisp.t.o $(OBJECTS) test.o
g++ lisp.t.o $(OBJECTS) test.o $(LFLAGS) -o lisp.t
@@ -124,3 +121,6 @@ tree.t: tree.t.o $(OBJECTS) test.o
tree2.t: tree2.t.o $(OBJECTS) test.o
g++ tree2.t.o $(OBJECTS) test.o $(LFLAGS) -o tree2.t
uri.t: uri.t.o $(OBJECTS) test.o
g++ uri.t.o $(OBJECTS) test.o $(LFLAGS) -o uri.t

View File

@@ -28,7 +28,7 @@
use strict;
use warnings;
use Test::More tests => 42;
use Test::More tests => 43;
use File::Copy;
use constant false => 0;
@@ -137,8 +137,7 @@ qx{../task rc:remote.rc 4 +gym}; # right_newer
# merge remote into local
copy("local/undo.data", "local/undo.save") or fail("copy local/undo.data to local/undo.save");
my $output_l = qx{../task rc:local.rc merge remote/undo.data};
rename("local/undo.save", "local/undo.data") or fail("rename local/undo.save in local/undo.data");
my $output_l = qx{../task rc:local.rc merge remote/};
#check output
like ($output_l, qr/Running redo/, "local-merge finished");
@@ -146,7 +145,7 @@ unlike ($output_l, qr/Missing/, "local-merge: no missing entry");
unlike ($output_l, qr/Not adding duplicate/, "local-merge: no duplicates");
# merge local into remote
my $output_r = qx{../task rc:remote.rc merge local/undo.data};
my $output_r = qx{../task rc:remote.rc merge local/undo.save};
# check output
like ($output_r, qr/Running redo/, "remote-merge finished");
@@ -240,6 +239,9 @@ ok (!-r 'local/completed.data', 'Removed local/completed.data');
unlink 'local/undo.data';
ok (!-r 'local/undo.data', 'Removed local/undo.data');
unlink 'local/undo.save';
ok (!-r 'local/undo.save', 'Removed local/undo.save');
unlink 'local.rc';
ok (!-r 'local.rc', 'Removed local.rc');

View File

@@ -1,87 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
// taskwarrior - a command line task list manager.
//
// Copyright 2006 - 2010, Paul Beckingham.
// All rights reserved.
//
// 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 2 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, write to the
//
// Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor,
// Boston, MA
// 02110-1301
// USA
//
////////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <sstream>
#include <Context.h>
//#include <Att.h>
#include <Transport.h>
#include <test.h>
Context context;
class TransportTest : public Transport
{
public:
TransportTest (const std::string& uri) : Transport (uri) {};
std::string getHost() { return host; };
std::string getPath() { return path; };
std::string getUser() { return user; };
std::string getPort() { return port; };
std::string getProt() { return protocol; };
virtual void recv(std::string) {};
virtual void send(const std::string&) {};
};
////////////////////////////////////////////////////////////////////////////////
int main (int argc, char** argv)
{
UnitTest t (20);
TransportTest tport1 ("asfd://user@host/folder/");
t.is (tport1.getUser (), "user", "Transport::parseUri() : asfd://user@host/folder/");
t.is (tport1.getHost (), "host", "Transport::parseUri() : asfd://user@host/folder/");
t.is (tport1.getPort (), "", "Transport::parseUri() : asfd://user@host/folder/");
t.is (tport1.getPath (), "folder/", "Transport::parseUri() : asfd://user@host/folder/");
t.is (tport1.getProt (), "asfd", "Transport::parseUri() : asfd://user@host/folder/");
TransportTest tport2 ("user@host:folder/file.test");
t.is (tport2.getUser (), "user", "Transport::parseUri() : user@host:22/folder/file.test");
t.is (tport2.getHost (), "host", "Transport::parseUri() : user@host:22/folder/file.test");
t.is (tport2.getPort (), "", "Transport::parseUri() : user@host:22/folder/file.test");
t.is (tport2.getPath (), "folder/file.test", "Transport::parseUri() : user@host:22/folder/file.test");
t.is (tport2.getProt (), "ssh", "Transport::parseUri() : user@host:22/folder/file.test");
TransportTest tport3 ("rsync://hostname.abc.de:1234/file.test");
t.is (tport3.getUser (), "", "Transport::parseUri() : hostname.abc.de/file.test");
t.is (tport3.getHost (), "hostname.abc.de", "Transport::parseUri() : hostname.abc.de/file.test");
t.is (tport3.getPort (), "1234", "Transport::parseUri() : hostname.abc.de/file.test");
t.is (tport3.getPath (), "file.test", "Transport::parseUri() : hostname.abc.de/file.test");
t.is (tport3.getProt (), "rsync", "Transport::parseUri() : hostname.abc.de/file.test");
TransportTest tport4 ("hostname:");
t.is (tport4.getUser (), "", "Transport::parseUri() : hostname/");
t.is (tport4.getHost (), "hostname", "Transport::parseUri() : hostname/");
t.is (tport4.getPort (), "", "Transport::parseUri() : hostname/");
t.is (tport4.getPath (), "", "Transport::parseUri() : hostname/");
t.is (tport4.getProt (), "ssh", "Transport::parseUri() : hostname/");
return 0;
}
////////////////////////////////////////////////////////////////////////////////

94
src/tests/uri.t.cpp Normal file
View File

@@ -0,0 +1,94 @@
////////////////////////////////////////////////////////////////////////////////
// taskwarrior - a command line task list manager.
//
// Copyright 2010, Johannes Schlatow.
// All rights reserved.
//
// 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 2 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, write to the
//
// Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor,
// Boston, MA
// 02110-1301
// USA
//
////////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <sstream>
#include <Context.h>
#include <Uri.h>
#include <test.h>
Context context;
////////////////////////////////////////////////////////////////////////////////
int main (int argc, char** argv)
{
UnitTest t (30);
Uri uri1 ("asfd://user@host/folder/");
uri1.parse ();
t.is (uri1.user, "user", "Uri::parse() : asdf://user@host/folder/");
t.is (uri1.host, "host", "Uri::parse() : asdf://user@host/folder/");
t.is (uri1.port, "", "Uri::parse() : asdf://user@host/folder/");
t.is (uri1.path, "folder/", "Uri::parse() : asdf://user@host/folder/");
t.is (uri1.protocol, "asfd", "Uri::parse() : asdf://user@host/folder/");
t.ok (uri1.append ("file.test"), "Uri::append() to path");
t.is (uri1.path, "folder/file.test", "Uri::append() ok");
Uri uri2 ("user@host:folder/file.test");
uri2.parse ();
t.is (uri2.user, "user", "Uri::parse() : user@host:folder/file.test");
t.is (uri2.host, "host", "Uri::parse() : user@host:folder/file.test");
t.is (uri2.port, "", "Uri::parse() : user@host/folder/file.test");
t.is (uri2.path, "folder/file.test", "Uri::parse() : user@host/folder/file.test");
t.is (uri2.protocol, "ssh", "Uri::parse() : user@host/folder/file.test");
t.notok (uri2.append ("test.dat"), "Uri::append() to file");
Uri uri3 ("rsync://hostname.abc.de:1234//abs/path");
uri3.parse ();
t.is (uri3.user, "", "Uri::parse() : rsync://hostname.abc.de:1234//abs/path");
t.is (uri3.host, "hostname.abc.de", "Uri::parse() : rsync://hostname.abc.de:1234//abs/path");
t.is (uri3.port, "1234", "Uri::parse() : rsync://hostname.abc.de:1234//abs/path");
t.is (uri3.path, "/abs/path", "Uri::parse() : rsync://hostname.abc.de:1234//abs/path");
t.is (uri3.protocol, "rsync", "Uri::parse() : rsync://hostname.abc.de:1234//abs/path");
Uri uri4 ("hostname:");
uri4.parse ();
t.is (uri4.user, "", "Uri::parse() : hostname:");
t.is (uri4.host, "hostname", "Uri::parse() : hostname:");
t.is (uri4.port, "", "Uri::parse() : hostname:");
t.is (uri4.path, "", "Uri::parse() : hostname:");
t.is (uri4.protocol, "ssh", "Uri::parse() : hostname:");
t.notok (uri4.is_local (), "Uri::is_local() : hostname:");
t.ok (uri4.append ("file.test"), "Uri::append() : hostname:");
t.is (uri4.path, "file.test","Uri::append() : ok");
context.config.set ("merge.default.uri", "../folder/");
context.config.set ("push.test.uri", "/home/user/.task/");
Uri uri5 ("", "merge");
t.ok (uri5.is_local (), "Uri::is_local() : ../server/");
uri5.parse ();
t.is (uri5.path, "../folder/", "Uri::expand() default");
Uri uri6 ("test", "push");
t.ok (uri6.is_local(), "Uri::is_local() : /home/user/.task/");
uri6.parse ();
t.is (uri6.path, "/home/user/.task/", "Uri::expand() test");
return 0;
}
////////////////////////////////////////////////////////////////////////////////