summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2021-10-27 19:32:41 -0400
committerKohei Yoshida <kohei.yoshida@gmail.com>2021-10-27 19:32:41 -0400
commitd28f63b2cd5b99f1677fc7040fa27a8ba2c736cd (patch)
treeb41767762f7c77ab07d42a116d1f6afa32f707a7
parent7f66db7253e4042a1f106050ec22f7f0fafc2084 (diff)
downloadorcus-d28f63b2cd5b99f1677fc7040fa27a8ba2c736cd.tar.gz
Use std::unique_ptr for css_document_tree's pimpl, and simplify ...
... test document loading.
-rw-r--r--include/orcus/css_document_tree.hpp6
-rw-r--r--src/liborcus/css_document_tree.cpp9
-rw-r--r--src/liborcus/css_document_tree_test.cpp75
3 files changed, 37 insertions, 53 deletions
diff --git a/include/orcus/css_document_tree.hpp b/include/orcus/css_document_tree.hpp
index 13c92839..76d924aa 100644
--- a/include/orcus/css_document_tree.hpp
+++ b/include/orcus/css_document_tree.hpp
@@ -12,6 +12,7 @@
#include "orcus/exception.hpp"
#include <string>
+#include <memory>
namespace orcus {
@@ -21,7 +22,7 @@ namespace orcus {
class ORCUS_DLLPUBLIC css_document_tree
{
struct impl;
- impl* mp_impl;
+ std::unique_ptr<impl> mp_impl;
public:
@@ -31,7 +32,10 @@ public:
insertion_error(const std::string& msg);
};
+ css_document_tree(const css_document_tree&) = delete;
+
css_document_tree();
+ css_document_tree(css_document_tree&& other);
~css_document_tree();
/**
diff --git a/src/liborcus/css_document_tree.cpp b/src/liborcus/css_document_tree.cpp
index 01286266..0cb0688e 100644
--- a/src/liborcus/css_document_tree.cpp
+++ b/src/liborcus/css_document_tree.cpp
@@ -527,13 +527,18 @@ struct css_document_tree::impl
simple_selectors_type m_root;
};
-css_document_tree::css_document_tree() : mp_impl(new impl)
+css_document_tree::css_document_tree() : mp_impl(std::make_unique<impl>())
{
}
+css_document_tree::css_document_tree(css_document_tree&& other) :
+ mp_impl(std::move(other.mp_impl))
+{
+ other.mp_impl = std::make_unique<impl>();
+}
+
css_document_tree::~css_document_tree()
{
- delete mp_impl;
}
void css_document_tree::load(std::string_view stream)
diff --git a/src/liborcus/css_document_tree_test.cpp b/src/liborcus/css_document_tree_test.cpp
index 8063b9f0..b3826f52 100644
--- a/src/liborcus/css_document_tree_test.cpp
+++ b/src/liborcus/css_document_tree_test.cpp
@@ -54,6 +54,16 @@ bool check_prop(const css_properties_t& props, std::string_view key, std::string
return true;
}
+css_document_tree load_document(const fs::path& path)
+{
+ std::cout << path << std::endl;
+ file_content content(path.string());
+ css_document_tree doc;
+ doc.load(content.str());
+
+ return doc;
+}
+
void test_css_invalids()
{
// Get all yaml files in this directory.
@@ -126,11 +136,7 @@ void test_css_empty()
void test_css_parse_basic1()
{
- fs::path path = SRCDIR"/test/css/basic1.css";
- std::cout << path << std::endl;
- file_content content(path.string());
- css_document_tree doc;
- doc.load(content.str());
+ css_document_tree doc = load_document(SRCDIR"/test/css/basic1.css");
css_selector_t selector;
selector.first.name = "table";
@@ -156,11 +162,7 @@ void test_css_parse_basic1()
void test_css_parse_basic2()
{
- fs::path path = SRCDIR"/test/css/basic2.css";
- std::cout << path << std::endl;
- file_content content(path.string());
- css_document_tree doc;
- doc.load(content.str());
+ css_document_tree doc = load_document(SRCDIR"/test/css/basic2.css");
css_selector_t selector;
selector.first.name = "div";
@@ -183,11 +185,7 @@ void test_css_parse_basic2()
void test_css_parse_basic3()
{
- fs::path path = SRCDIR"/test/css/basic3.css";
- std::cout << path << std::endl;
- file_content content(path.string());
- css_document_tree doc;
- doc.load(content.str());
+ css_document_tree doc = load_document(SRCDIR"/test/css/basic3.css");
css_selector_t selector;
selector.first.name = "html";
@@ -222,11 +220,7 @@ void test_css_parse_basic3()
void test_css_parse_basic4()
{
- fs::path path = SRCDIR"/test/css/basic4.css";
- std::cout << path << std::endl;
- file_content content(path.string());
- css_document_tree doc;
- doc.load(content.str());
+ css_document_tree doc = load_document(SRCDIR"/test/css/basic4.css");
css_selector_t selector;
selector.first.name = "h1";
@@ -263,11 +257,7 @@ void test_css_parse_basic4()
void test_css_parse_basic5()
{
- fs::path path = SRCDIR"/test/css/basic5.css";
- std::cout << path << std::endl;
- file_content content(path.string());
- css_document_tree doc;
- doc.load(content.str());
+ css_document_tree doc = load_document(SRCDIR"/test/css/basic5.css");
css_selector_t selector;
selector.first.classes.insert("info");
@@ -280,11 +270,7 @@ void test_css_parse_basic5()
void test_css_parse_basic6()
{
- fs::path path = SRCDIR"/test/css/basic6.css";
- std::cout << path << std::endl;
- file_content content(path.string());
- css_document_tree doc;
- doc.load(content.str());
+ css_document_tree doc = load_document(SRCDIR"/test/css/basic6.css");
css_selector_t selector;
selector.first.name = "h1";
@@ -311,11 +297,7 @@ void test_css_parse_basic6()
void test_css_parse_basic7()
{
- fs::path path = SRCDIR"/test/css/basic7.css";
- std::cout << path << std::endl;
- file_content content(path.string());
- css_document_tree doc;
- doc.load(content.str());
+ css_document_tree doc = load_document(SRCDIR"/test/css/basic7.css");
css_selector_t selector;
selector.first.classes.insert("one");
@@ -364,11 +346,7 @@ void test_css_parse_basic7()
void test_css_parse_basic8()
{
- fs::path path = SRCDIR"/test/css/basic8.css";
- std::cout << path << std::endl;
- file_content content(path.string());
- css_document_tree doc;
- doc.load(content.str());
+ css_document_tree doc = load_document(SRCDIR"/test/css/basic8.css");
css_selector_t selector;
selector.first.classes.insert("ribbon");
@@ -426,11 +404,7 @@ void test_css_parse_basic8()
void test_css_parse_basic9()
{
- fs::path path = SRCDIR"/test/css/basic9.css";
- std::cout << path << std::endl;
- file_content content(path.string());
- css_document_tree doc;
- doc.load(content.str());
+ css_document_tree doc = load_document(SRCDIR"/test/css/basic9.css");
css_selector_t selector;
selector.first.name = "a";
@@ -462,11 +436,7 @@ void test_css_parse_basic9()
void test_css_parse_basic10()
{
- fs::path path = SRCDIR"/test/css/basic10.css";
- std::cout << path << std::endl;
- file_content content(path.string());
- css_document_tree doc;
- doc.load(content.str());
+ css_document_tree doc = load_document(SRCDIR"/test/css/basic10.css");
css_selector_t selector;
selector.first.classes.insert("foo");
@@ -671,6 +641,11 @@ void test_css_parse_chained2()
assert(check_prop(*props, "border", "solid 2px"));
}
+void test_css_parse_utf8_1()
+{
+
+}
+
int main()
{
test_css_invalids();