From 2a429ca76b97cca197f105b665271360b74f6917 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 14 Aug 2012 04:22:07 +0000 Subject: Remove glib dependency. Make Symbol, URI, and Path simpler derivatives of std::string. 100% test coverage by line for Symbol, URI, Path, AtomicInt, and AtomicPtr. Add Raul::Exception. git-svn-id: http://svn.drobilla.net/lad/trunk/raul@4686 a436a847-0d15-0410-975c-d299462d15a1 --- test/path_test.cpp | 64 ++++++++++++++++++++++++++----------------- test/symbol_test.cpp | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++ test/table_test.cpp | 5 ++-- test/uri_test.cpp | 61 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 180 insertions(+), 27 deletions(-) create mode 100644 test/symbol_test.cpp create mode 100644 test/uri_test.cpp (limited to 'test') diff --git a/test/path_test.cpp b/test/path_test.cpp index f267595..1bdd99e 100644 --- a/test/path_test.cpp +++ b/test/path_test.cpp @@ -14,8 +14,9 @@ along with Raul. If not, see . */ +#include #include -#include + #include "raul/log.hpp" #include "raul/Path.hpp" @@ -31,23 +32,6 @@ main() return 1; \ } } while (0) - list names; - names.push_back("Dry/Wet Balance"); - names.push_back("foo+1bar(baz)"); - names.push_back("ThisCRAR"); - names.push_back("NAME"); - names.push_back("thing with a bunch of spaces"); - names.push_back("thing-with-a-bunch-of-dashes"); - names.push_back("CamelCaseABC"); - names.push_back("Signal Level [dB]"); - names.push_back("Gain dB"); - names.push_back("Dry/Wet Balance"); - names.push_back("Phaser1 - Similar to CSound's phaser1 by Sean Costello"); - - for (list::iterator i = names.begin(); i != names.end(); ++i) { - CHECK(strcmp(Symbol::symbolify(*i).c_str(), "")); - } - CHECK(Path("/foo/bar").parent() == Path("/foo")); CHECK(Path("/foo").parent() == Path("/")); CHECK(Path("/").parent() == Path("/")); @@ -68,13 +52,13 @@ main() CHECK(Path::is_valid("/")); CHECK(!Path::is_valid("/foo/3foo/bar")); - CHECK(Path::descendant_comparator("/", "/foo")); - CHECK(Path::descendant_comparator("/foo", "/foo/bar")); - CHECK(Path::descendant_comparator("/foo", "/foo")); - CHECK(Path::descendant_comparator("/", "/")); - CHECK(!Path::descendant_comparator("/baz", "/")); - CHECK(!Path::descendant_comparator("/foo", "/bar")); - CHECK(!Path::descendant_comparator("/foo/bar", "/foo")); + CHECK(Path::descendant_comparator(Path("/"), Path("/foo"))); + CHECK(Path::descendant_comparator(Path("/foo"), Path("/foo/bar"))); + CHECK(Path::descendant_comparator(Path("/foo"), Path("/foo"))); + CHECK(Path::descendant_comparator(Path("/"), Path("/"))); + CHECK(!Path::descendant_comparator(Path("/baz"), Path("/"))); + CHECK(!Path::descendant_comparator(Path("/foo"), Path("/bar"))); + CHECK(!Path::descendant_comparator(Path("/foo/bar"), Path("/foo"))); CHECK(!Symbol::is_valid("")); CHECK(!Symbol::is_valid("/I/have/slashes")); @@ -82,5 +66,35 @@ main() CHECK(!Symbol::is_valid("0illegalleadingdigit")); CHECK(strcmp(Symbol::symbolify("").c_str(), "")); + CHECK(Path("/foo").child(Symbol("bar")) == "/foo/bar"); + CHECK(Path("/foo").child(Path("/bar/baz")) == "/foo/bar/baz"); + CHECK(Path("/foo").child(Path("/")) == "/foo"); + + CHECK(!strcmp(Path("/foo").symbol(), "foo")); + CHECK(!strcmp(Path("/foo/bar").symbol(), "bar")); + CHECK(!strcmp(Path("/").symbol(), "")); + + Path original(std::string("/foo/bar")); + Path copy(original); + CHECK(original == copy); + + bool valid = true; + try { + Path path("/ends/in/slash/"); + } catch (const Path::BadPath& e) { + std::cerr << "Caught exception: " << e.what() << std::endl; + valid = false; + } + CHECK(!valid); + + valid = true; + try { + Path path(std::string("/has//double/slash")); + } catch (const Path::BadPath& e) { + std::cerr << "Caught exception: " << e.what() << std::endl; + valid = false; + } + CHECK(!valid); + return 0; } diff --git a/test/symbol_test.cpp b/test/symbol_test.cpp new file mode 100644 index 0000000..9726001 --- /dev/null +++ b/test/symbol_test.cpp @@ -0,0 +1,77 @@ +/* + This file is part of Raul. + Copyright 2007-2012 David Robillard + + Raul 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 any later version. + + Raul 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 Raul. If not, see . +*/ + +#include +#include +#include + +#include "raul/log.hpp" +#include "raul/Path.hpp" + +using namespace std; +using namespace Raul; + +int +main() +{ +#define CHECK(cond) \ + do { if (!(cond)) { \ + error << "Test failed: " << (cond) << endl; \ + return 1; \ + } } while (0) + + list names; + names.push_back("Dry/Wet Balance"); + names.push_back("foo+1bar(baz)"); + names.push_back("ThisCRAR"); + names.push_back("NAME"); + names.push_back("thing with a bunch of spaces"); + names.push_back("thing-with-a-bunch-of-dashes"); + names.push_back("CamelCaseABC"); + names.push_back("Signal Level [dB]"); + names.push_back("Gain dB"); + names.push_back("Dry/Wet Balance"); + names.push_back("Phaser1 - Similar to CSound's phaser1 by Sean Costello"); + names.push_back(""); + + for (list::iterator i = names.begin(); i != names.end(); ++i) { + CHECK(!Symbol::symbolify(*i).empty()); + } + + Symbol original("sym"); + Symbol copy(original); + CHECK(original == copy); + + bool valid = true; + try { + Symbol symbol("0startswithdigit"); + } catch (const Symbol::BadSymbol& e) { + std::cerr << "Caught exception: " << e.what() << std::endl; + valid = false; + } + CHECK(!valid); + + valid = true; + try { + Symbol symbol(std::string("invalid/symbol")); + } catch (const Symbol::BadSymbol& e) { + std::cerr << "Caught exception: " << e.what() << std::endl; + valid = false; + } + CHECK(!valid); + + return 0; +} diff --git a/test/table_test.cpp b/test/table_test.cpp index 70ab5b1..f372d7c 100644 --- a/test/table_test.cpp +++ b/test/table_test.cpp @@ -14,12 +14,13 @@ along with Raul. If not, see . */ -#include +#include #include -#include #include #include +#include #include +#include #include "raul/log.hpp" #include "raul/PathTable.hpp" diff --git a/test/uri_test.cpp b/test/uri_test.cpp new file mode 100644 index 0000000..d3b9a99 --- /dev/null +++ b/test/uri_test.cpp @@ -0,0 +1,61 @@ +/* + This file is part of Raul. + Copyright 2007-2012 David Robillard + + Raul 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 any later version. + + Raul 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 Raul. If not, see . +*/ + +#include + +#include "raul/log.hpp" +#include "raul/URI.hpp" + +using namespace std; +using namespace Raul; + +int +main() +{ +#define CHECK(cond) \ + do { if (!(cond)) { \ + error << "Test failed: " << (cond) << endl; \ + assert(0); \ + return 1; \ + } } while (0) + + CHECK(URI("http://example.org").scheme() == "http"); + CHECK(URI("svn+ssh://example.org/").scheme() == "svn+ssh"); + CHECK(URI("osc.udp://example.org/").scheme() == "osc.udp"); + CHECK(URI("weird-scheme://example.org/").scheme() == "weird-scheme"); + + URI original(std::string("http://example.org")); + URI copy(original); + CHECK(original == copy); + + bool valid = true; + try { + URI uri("not/a/uri"); + } catch (const URI::BadURI& e) { + valid = false; + } + CHECK(!valid); + + valid = true; + try { + URI uri(std::string("/this/is/a/path")); + } catch (const URI::BadURI& e) { + valid = false; + } + CHECK(!valid); + + return 0; +} -- cgit v1.2.1