2005-01-02 14:10:16 +00:00
|
|
|
//
|
2005-03-18 21:33:11 +00:00
|
|
|
// VMime library (http://www.vmime.org)
|
2018-09-05 21:54:48 +00:00
|
|
|
// Copyright (C) 2002 Vincent Richard <vincent@vmime.org>
|
2005-01-02 14:10:16 +00:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
2009-09-06 12:02:10 +00:00
|
|
|
// published by the Free Software Foundation; either version 3 of
|
2005-01-02 14:10:16 +00:00
|
|
|
// 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.
|
|
|
|
//
|
2005-09-17 10:10:29 +00:00
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// Linking this library statically or dynamically with other modules is making
|
|
|
|
// a combined work based on this library. Thus, the terms and conditions of
|
|
|
|
// the GNU General Public License cover the whole combination.
|
2005-01-02 14:10:16 +00:00
|
|
|
//
|
|
|
|
|
2005-08-25 21:25:45 +00:00
|
|
|
#include "tests/testUtils.hpp"
|
2005-01-02 14:10:16 +00:00
|
|
|
|
|
|
|
#include "vmime/utility/path.hpp"
|
|
|
|
|
|
|
|
|
2014-01-15 23:15:21 +00:00
|
|
|
VMIME_TEST_SUITE_BEGIN(utilityPathTest)
|
2005-08-25 21:25:45 +00:00
|
|
|
|
|
|
|
VMIME_TEST_LIST_BEGIN
|
|
|
|
VMIME_TEST(testConstruct1)
|
|
|
|
VMIME_TEST(testConstruct2)
|
|
|
|
VMIME_TEST(testConstruct3)
|
|
|
|
VMIME_TEST(testConstruct4)
|
|
|
|
|
|
|
|
VMIME_TEST(testAppendComponent)
|
|
|
|
|
|
|
|
VMIME_TEST(testOperatorDiv1)
|
|
|
|
VMIME_TEST(testOperatorDiv2)
|
|
|
|
|
|
|
|
VMIME_TEST(testOperatorDivEqual1)
|
|
|
|
VMIME_TEST(testOperatorDivEqual2)
|
|
|
|
|
|
|
|
VMIME_TEST(testGetParent)
|
|
|
|
|
|
|
|
VMIME_TEST(testComparison)
|
|
|
|
|
|
|
|
VMIME_TEST(testGetLastComponent)
|
|
|
|
|
|
|
|
VMIME_TEST(testIsDirectParentOf)
|
|
|
|
VMIME_TEST(testIsParentOf)
|
2014-01-15 23:15:21 +00:00
|
|
|
VMIME_TEST(testIsParentOf_EquivalentCharset)
|
2005-08-25 21:25:45 +00:00
|
|
|
|
|
|
|
VMIME_TEST(testRenameParent)
|
2014-01-19 16:25:25 +00:00
|
|
|
|
|
|
|
VMIME_TEST(testFromString)
|
|
|
|
VMIME_TEST(testFromString_IgnoreLeadingOrTrailingSep)
|
|
|
|
VMIME_TEST(testToString)
|
2005-08-25 21:25:45 +00:00
|
|
|
VMIME_TEST_LIST_END
|
|
|
|
|
|
|
|
|
|
|
|
typedef vmime::utility::path path;
|
|
|
|
typedef vmime::utility::path::component comp;
|
|
|
|
|
|
|
|
|
2018-09-05 21:54:48 +00:00
|
|
|
void testConstruct1() {
|
|
|
|
|
2005-08-25 21:25:45 +00:00
|
|
|
VASSERT_EQ("1", true, path().isEmpty());
|
|
|
|
VASSERT_EQ("2", 0, path().getSize());
|
|
|
|
}
|
|
|
|
|
2018-09-05 21:54:48 +00:00
|
|
|
void testConstruct2() {
|
|
|
|
|
2005-08-25 21:25:45 +00:00
|
|
|
path p(comp("foo"));
|
|
|
|
|
|
|
|
VASSERT_EQ("1", false, p.isEmpty());
|
|
|
|
VASSERT_EQ("2", 1, p.getSize());
|
|
|
|
VASSERT_EQ("3", "foo", p.getComponentAt(0).getBuffer());
|
|
|
|
}
|
|
|
|
|
2018-09-05 21:54:48 +00:00
|
|
|
void testAppendComponent() {
|
|
|
|
|
2005-08-25 21:25:45 +00:00
|
|
|
path p;
|
|
|
|
|
|
|
|
VASSERT_EQ("1", 0, p.getSize());
|
|
|
|
|
|
|
|
comp c("foo");
|
|
|
|
p.appendComponent(c);
|
2005-01-02 14:10:16 +00:00
|
|
|
|
2005-08-25 21:25:45 +00:00
|
|
|
VASSERT_EQ("2", 1, p.getSize());
|
|
|
|
VASSERT_EQ("3", c.getBuffer(), p.getComponentAt(0).getBuffer());
|
|
|
|
}
|
|
|
|
|
2018-09-05 21:54:48 +00:00
|
|
|
void testConstruct3() {
|
|
|
|
|
2005-08-25 21:25:45 +00:00
|
|
|
path p1;
|
|
|
|
p1.appendComponent(comp("foo"));
|
|
|
|
p1.appendComponent(comp("bar"));
|
|
|
|
|
|
|
|
path p2(p1);
|
|
|
|
|
|
|
|
VASSERT_EQ("1", 2, p2.getSize());
|
|
|
|
VASSERT_EQ("2", "foo", p2.getComponentAt(0).getBuffer());
|
|
|
|
VASSERT_EQ("3", "bar", p2.getComponentAt(1).getBuffer());
|
|
|
|
}
|
|
|
|
|
2018-09-05 21:54:48 +00:00
|
|
|
void testConstruct4() {
|
|
|
|
|
2005-08-25 21:25:45 +00:00
|
|
|
// Same as path::path(const component&)
|
|
|
|
path p("foo");
|
|
|
|
|
|
|
|
VASSERT_EQ("1", false, p.isEmpty());
|
|
|
|
VASSERT_EQ("2", 1, p.getSize());
|
|
|
|
VASSERT_EQ("3", "foo", p.getComponentAt(0).getBuffer());
|
|
|
|
}
|
|
|
|
|
2018-09-05 21:54:48 +00:00
|
|
|
void testOperatorDiv1() {
|
|
|
|
|
2005-08-25 21:25:45 +00:00
|
|
|
path p1;
|
|
|
|
p1.appendComponent(comp("foo"));
|
|
|
|
p1.appendComponent(comp("bar"));
|
|
|
|
|
|
|
|
path p2;
|
|
|
|
p2.appendComponent(comp("baz"));
|
|
|
|
|
|
|
|
path p3 = p1 / p2;
|
|
|
|
|
|
|
|
VASSERT_EQ("1", 3, p3.getSize());
|
|
|
|
VASSERT_EQ("2", p1.getComponentAt(0).getBuffer(), p3.getComponentAt(0).getBuffer());
|
|
|
|
VASSERT_EQ("3", p1.getComponentAt(1).getBuffer(), p3.getComponentAt(1).getBuffer());
|
|
|
|
VASSERT_EQ("4", p2.getComponentAt(0).getBuffer(), p3.getComponentAt(2).getBuffer());
|
|
|
|
}
|
|
|
|
|
2018-09-05 21:54:48 +00:00
|
|
|
void testOperatorDiv2() {
|
|
|
|
|
2005-08-25 21:25:45 +00:00
|
|
|
path p1;
|
|
|
|
p1.appendComponent(comp("foo"));
|
|
|
|
p1.appendComponent(comp("bar"));
|
|
|
|
|
|
|
|
comp c("baz");
|
|
|
|
|
|
|
|
path p2 = p1 / c;
|
2005-01-02 14:10:16 +00:00
|
|
|
|
2005-08-25 21:25:45 +00:00
|
|
|
VASSERT_EQ("1", 3, p2.getSize());
|
|
|
|
VASSERT_EQ("2", p1.getComponentAt(0).getBuffer(), p2.getComponentAt(0).getBuffer());
|
|
|
|
VASSERT_EQ("3", p1.getComponentAt(1).getBuffer(), p2.getComponentAt(1).getBuffer());
|
|
|
|
VASSERT_EQ("4", c.getBuffer(), p2.getComponentAt(2).getBuffer());
|
|
|
|
}
|
2005-01-02 14:10:16 +00:00
|
|
|
|
2018-09-05 21:54:48 +00:00
|
|
|
void testOperatorDivEqual1() {
|
|
|
|
|
2005-08-25 21:25:45 +00:00
|
|
|
path p1;
|
|
|
|
p1.appendComponent(comp("foo"));
|
|
|
|
p1.appendComponent(comp("bar"));
|
|
|
|
|
|
|
|
path p2;
|
|
|
|
p2.appendComponent(comp("baz"));
|
2005-01-02 14:10:16 +00:00
|
|
|
|
2005-08-25 21:25:45 +00:00
|
|
|
path p3(p1);
|
|
|
|
p3 /= p2;
|
2005-01-02 14:10:16 +00:00
|
|
|
|
2005-08-25 21:25:45 +00:00
|
|
|
VASSERT_EQ("1", 3, p3.getSize());
|
|
|
|
VASSERT_EQ("2", p1.getComponentAt(0).getBuffer(), p3.getComponentAt(0).getBuffer());
|
|
|
|
VASSERT_EQ("3", p1.getComponentAt(1).getBuffer(), p3.getComponentAt(1).getBuffer());
|
|
|
|
VASSERT_EQ("4", p2.getComponentAt(0).getBuffer(), p3.getComponentAt(2).getBuffer());
|
|
|
|
}
|
2005-01-02 14:10:16 +00:00
|
|
|
|
2018-09-05 21:54:48 +00:00
|
|
|
void testOperatorDivEqual2() {
|
|
|
|
|
2005-08-25 21:25:45 +00:00
|
|
|
path p1;
|
|
|
|
p1.appendComponent(comp("foo"));
|
|
|
|
p1.appendComponent(comp("bar"));
|
2005-01-02 14:10:16 +00:00
|
|
|
|
2005-08-25 21:25:45 +00:00
|
|
|
comp c("baz");
|
2005-01-02 14:10:16 +00:00
|
|
|
|
2005-08-25 21:25:45 +00:00
|
|
|
path p2(p1);
|
|
|
|
p2 /= c;
|
2005-01-02 14:10:16 +00:00
|
|
|
|
2005-08-25 21:25:45 +00:00
|
|
|
VASSERT_EQ("1", 3, p2.getSize());
|
|
|
|
VASSERT_EQ("2", p1.getComponentAt(0).getBuffer(), p2.getComponentAt(0).getBuffer());
|
|
|
|
VASSERT_EQ("3", p1.getComponentAt(1).getBuffer(), p2.getComponentAt(1).getBuffer());
|
|
|
|
VASSERT_EQ("4", c.getBuffer(), p2.getComponentAt(2).getBuffer());
|
|
|
|
}
|
2005-01-02 14:10:16 +00:00
|
|
|
|
2018-09-05 21:54:48 +00:00
|
|
|
void testGetParent() {
|
|
|
|
|
2005-08-25 21:25:45 +00:00
|
|
|
path p1;
|
|
|
|
path p1p = p1.getParent();
|
2005-01-02 14:10:16 +00:00
|
|
|
|
2005-08-25 21:25:45 +00:00
|
|
|
VASSERT_EQ("1", true, p1p.isEmpty());
|
2005-01-02 14:10:16 +00:00
|
|
|
|
2005-08-25 21:25:45 +00:00
|
|
|
path p2;
|
|
|
|
p2.appendComponent(comp("foo"));
|
|
|
|
p2.appendComponent(comp("bar"));
|
2005-01-02 14:10:16 +00:00
|
|
|
|
2005-08-25 21:25:45 +00:00
|
|
|
path p2p = p2.getParent();
|
2005-01-02 14:10:16 +00:00
|
|
|
|
2005-08-25 21:25:45 +00:00
|
|
|
VASSERT_EQ("2", 1, p2p.getSize());
|
|
|
|
VASSERT_EQ("3", p2.getComponentAt(0).getBuffer(), p2p.getComponentAt(0).getBuffer());
|
|
|
|
}
|
2005-01-02 14:10:16 +00:00
|
|
|
|
2018-09-05 21:54:48 +00:00
|
|
|
void testComparison() {
|
|
|
|
|
2005-08-25 21:25:45 +00:00
|
|
|
path p1;
|
|
|
|
p1.appendComponent(comp("foo"));
|
|
|
|
p1.appendComponent(comp("bar"));
|
2005-01-02 14:10:16 +00:00
|
|
|
|
2005-08-25 21:25:45 +00:00
|
|
|
path p2;
|
|
|
|
p2.appendComponent(comp("foo"));
|
|
|
|
p2.appendComponent(comp("bar"));
|
2005-01-02 14:10:16 +00:00
|
|
|
|
2005-08-25 21:25:45 +00:00
|
|
|
path p3;
|
|
|
|
p3.appendComponent(comp("foo"));
|
|
|
|
p3.appendComponent(comp("bar"));
|
|
|
|
p3.appendComponent(comp("baz"));
|
2005-01-02 14:10:16 +00:00
|
|
|
|
2005-08-25 21:25:45 +00:00
|
|
|
VASSERT_EQ("1", true, p1 == p2);
|
|
|
|
VASSERT_EQ("2", false, p1 == p3);
|
2005-01-02 14:10:16 +00:00
|
|
|
|
2005-08-25 21:25:45 +00:00
|
|
|
VASSERT_EQ("3", false, p1 != p2);
|
|
|
|
VASSERT_EQ("4", true, p1 != p3);
|
2005-01-02 14:10:16 +00:00
|
|
|
|
2005-08-25 21:25:45 +00:00
|
|
|
VASSERT_EQ("5", true, p3.getParent() == p1);
|
|
|
|
}
|
2005-01-02 14:10:16 +00:00
|
|
|
|
2018-09-05 21:54:48 +00:00
|
|
|
void testGetLastComponent() {
|
|
|
|
|
2005-08-25 21:25:45 +00:00
|
|
|
path p1;
|
|
|
|
p1.appendComponent(comp("foo"));
|
|
|
|
p1.appendComponent(comp("bar"));
|
|
|
|
p1.appendComponent(comp("baz"));
|
2005-01-02 14:10:16 +00:00
|
|
|
|
2005-08-25 21:25:45 +00:00
|
|
|
VASSERT_EQ("1", "baz", p1.getLastComponent().getBuffer());
|
|
|
|
VASSERT_EQ("2", "bar", p1.getParent().getLastComponent().getBuffer());
|
|
|
|
VASSERT_EQ("3", "foo", p1.getParent().getParent().getLastComponent().getBuffer());
|
|
|
|
}
|
2005-01-02 14:10:16 +00:00
|
|
|
|
2018-09-05 21:54:48 +00:00
|
|
|
void testIsDirectParentOf() {
|
|
|
|
|
2005-08-25 21:25:45 +00:00
|
|
|
path p1;
|
|
|
|
p1.appendComponent(comp("foo"));
|
2005-01-02 14:10:16 +00:00
|
|
|
|
2005-08-25 21:25:45 +00:00
|
|
|
path p2;
|
|
|
|
p2.appendComponent(comp("foo"));
|
|
|
|
p2.appendComponent(comp("bar"));
|
2005-01-02 14:10:16 +00:00
|
|
|
|
2005-08-25 21:25:45 +00:00
|
|
|
path p3;
|
|
|
|
p3.appendComponent(comp("foo"));
|
|
|
|
p3.appendComponent(comp("bar"));
|
|
|
|
p3.appendComponent(comp("baz"));
|
2005-01-02 14:10:16 +00:00
|
|
|
|
2005-08-25 21:25:45 +00:00
|
|
|
VASSERT_EQ("1", true, p1.isDirectParentOf(p2));
|
|
|
|
VASSERT_EQ("2", true, p2.isDirectParentOf(p3));
|
|
|
|
VASSERT_EQ("3", false, p1.isDirectParentOf(p3));
|
|
|
|
VASSERT_EQ("4", false, p2.isDirectParentOf(p1));
|
|
|
|
}
|
2005-01-02 14:10:16 +00:00
|
|
|
|
2018-09-05 21:54:48 +00:00
|
|
|
void testIsParentOf() {
|
|
|
|
|
2005-08-25 21:25:45 +00:00
|
|
|
path p1;
|
|
|
|
p1.appendComponent(comp("foo"));
|
2005-01-02 14:10:16 +00:00
|
|
|
|
2005-08-25 21:25:45 +00:00
|
|
|
path p2;
|
|
|
|
p2.appendComponent(comp("foo"));
|
|
|
|
p2.appendComponent(comp("bar"));
|
2005-01-02 14:10:16 +00:00
|
|
|
|
2005-08-25 21:25:45 +00:00
|
|
|
path p3;
|
|
|
|
p3.appendComponent(comp("foo"));
|
|
|
|
p3.appendComponent(comp("bar"));
|
|
|
|
p3.appendComponent(comp("baz"));
|
2005-01-02 14:10:16 +00:00
|
|
|
|
2005-08-25 21:25:45 +00:00
|
|
|
VASSERT_EQ("1", true, p1.isParentOf(p2));
|
|
|
|
VASSERT_EQ("2", true, p2.isParentOf(p3));
|
|
|
|
VASSERT_EQ("3", true, p1.isParentOf(p3));
|
|
|
|
VASSERT_EQ("4", false, p2.isParentOf(p1));
|
|
|
|
}
|
2005-01-02 14:10:16 +00:00
|
|
|
|
2018-09-05 21:54:48 +00:00
|
|
|
void testIsParentOf_EquivalentCharset() {
|
|
|
|
|
2014-01-15 23:15:21 +00:00
|
|
|
path p1;
|
|
|
|
p1.appendComponent(comp("foo", "us-ascii"));
|
|
|
|
|
|
|
|
path p2;
|
|
|
|
p2.appendComponent(comp("foo", "utf-8"));
|
|
|
|
p2.appendComponent(comp("bar"));
|
|
|
|
p2.appendComponent(comp("baz"));
|
|
|
|
|
|
|
|
VASSERT_EQ("1", true, p1.isParentOf(p2));
|
|
|
|
}
|
|
|
|
|
2018-09-05 21:54:48 +00:00
|
|
|
void testRenameParent() {
|
|
|
|
|
2005-08-25 21:25:45 +00:00
|
|
|
path p1;
|
|
|
|
p1.appendComponent(comp("a"));
|
|
|
|
p1.appendComponent(comp("b"));
|
|
|
|
p1.appendComponent(comp("c"));
|
|
|
|
p1.appendComponent(comp("d"));
|
|
|
|
|
|
|
|
path p2;
|
|
|
|
p2.appendComponent(comp("a"));
|
|
|
|
p2.appendComponent(comp("b"));
|
|
|
|
|
|
|
|
path p3;
|
|
|
|
p3.appendComponent(comp("x"));
|
|
|
|
p3.appendComponent(comp("y"));
|
|
|
|
p3.appendComponent(comp("z"));
|
|
|
|
|
|
|
|
path p(p1);
|
|
|
|
p.renameParent(p2, p3);
|
|
|
|
|
|
|
|
VASSERT_EQ("1", 5, p.getSize());
|
|
|
|
VASSERT_EQ("2", "x", p.getComponentAt(0).getBuffer());
|
|
|
|
VASSERT_EQ("3", "y", p.getComponentAt(1).getBuffer());
|
|
|
|
VASSERT_EQ("4", "z", p.getComponentAt(2).getBuffer());
|
|
|
|
VASSERT_EQ("5", "c", p.getComponentAt(3).getBuffer());
|
|
|
|
VASSERT_EQ("6", "d", p.getComponentAt(4).getBuffer());
|
|
|
|
}
|
|
|
|
|
2018-09-05 21:54:48 +00:00
|
|
|
void testFromString() {
|
|
|
|
|
2014-01-19 16:25:25 +00:00
|
|
|
path p = path::fromString("ab/cde/f", "/", vmime::charset("my-charset"));
|
|
|
|
|
|
|
|
VASSERT_EQ("count", 3, p.getSize());
|
|
|
|
VASSERT_EQ("buffer1", "ab", p.getComponentAt(0).getBuffer());
|
|
|
|
VASSERT_EQ("charset1", "my-charset", p.getComponentAt(0).getCharset().getName());
|
|
|
|
VASSERT_EQ("buffer2", "cde", p.getComponentAt(1).getBuffer());
|
|
|
|
VASSERT_EQ("charset2", "my-charset", p.getComponentAt(1).getCharset().getName());
|
|
|
|
VASSERT_EQ("buffer3", "f", p.getComponentAt(2).getBuffer());
|
|
|
|
VASSERT_EQ("charset3", "my-charset", p.getComponentAt(2).getCharset().getName());
|
|
|
|
}
|
|
|
|
|
2018-09-05 21:54:48 +00:00
|
|
|
void testFromString_IgnoreLeadingOrTrailingSep() {
|
|
|
|
|
2014-01-19 16:25:25 +00:00
|
|
|
path p = path::fromString("//ab/cde/f////", "/", vmime::charset("my-charset"));
|
|
|
|
|
|
|
|
VASSERT_EQ("count", 3, p.getSize());
|
|
|
|
VASSERT_EQ("buffer1", "ab", p.getComponentAt(0).getBuffer());
|
|
|
|
VASSERT_EQ("charset1", "my-charset", p.getComponentAt(0).getCharset().getName());
|
|
|
|
VASSERT_EQ("buffer2", "cde", p.getComponentAt(1).getBuffer());
|
|
|
|
VASSERT_EQ("charset2", "my-charset", p.getComponentAt(1).getCharset().getName());
|
|
|
|
VASSERT_EQ("buffer3", "f", p.getComponentAt(2).getBuffer());
|
|
|
|
VASSERT_EQ("charset3", "my-charset", p.getComponentAt(2).getCharset().getName());
|
|
|
|
}
|
|
|
|
|
2018-09-05 21:54:48 +00:00
|
|
|
void testToString() {
|
|
|
|
|
2014-01-19 16:25:25 +00:00
|
|
|
path p;
|
|
|
|
p.appendComponent(comp("ab"));
|
|
|
|
p.appendComponent(comp("cde"));
|
|
|
|
p.appendComponent(comp("f"));
|
|
|
|
|
|
|
|
VASSERT_EQ("string", "ab/cde/f", p.toString("/", vmime::charset("us-ascii")));
|
|
|
|
}
|
|
|
|
|
2005-08-25 21:25:45 +00:00
|
|
|
VMIME_TEST_SUITE_END
|