Support conversion of linkshere
[dueringa_WikiWalker.git] / test / ToGraphvizWriterTests.cpp
blob1040e10119bfcdf54191bd074df3dc7df2afa1da
1 #include <fstream>
2 #include <memory>
4 #include <UnitTest++/UnitTest++.h>
6 #include "Article.h"
7 #include "ToGraphvizWriter.h"
9 // these test always pass, unless exceptions occur
10 //! TODO: try to initialize some variables only in one place
12 SUITE(ArticleToGraphvizWriterTests)
14 using namespace WikiWalker;
15 using namespace WikiWalker::CollectionUtils;
17 TEST(WriteArticleWithMultipleLinks)
19 std::ofstream outfile("_artlinks.dot",
20 std::ofstream::out | std::ofstream::trunc);
21 ToGraphvizWriter atj;
22 Article a("Farm");
24 auto al1 = std::make_shared<Article>("Animal"),
25 al2 = std::make_shared<Article>("Pig"),
26 al3 = std::make_shared<Article>("Equality");
28 a.addLink(al1);
29 a.addLink(al2);
30 a.addLink(al3);
31 atj.output(&a, outfile);
32 outfile.flush();
33 outfile.close();
36 TEST(WriteArticleCollectionDepthOne)
38 std::ofstream outfile("_artctree.dot",
39 std::ofstream::out | std::ofstream::trunc);
40 ToGraphvizWriter atj;
41 ArticleCollection ac;
43 auto farm = std::make_shared<Article>("Farm");
44 CollectionUtils::add(ac, farm);
46 auto animal = std::make_shared<Article>("Animal");
47 farm->addLink(animal);
48 CollectionUtils::add(ac, animal);
50 auto pig = std::make_shared<Article>("Pig");
51 farm->addLink(pig);
52 CollectionUtils::add(ac, pig);
54 auto equa = std::make_shared<Article>("Equality");
55 farm->addLink(equa);
56 CollectionUtils::add(ac, equa);
58 atj.output(ac, outfile);
59 outfile.flush();
60 outfile.close();
63 TEST(WriteArticleCollectionDepthOne_WithInterlinks)
65 std::ofstream outfile("_artctree_interlink.dot",
66 std::ofstream::out | std::ofstream::trunc);
67 ToGraphvizWriter atj;
68 ArticleCollection ac;
70 auto farm = std::make_shared<Article>("Farm");
71 CollectionUtils::add(ac, farm);
73 auto animal = std::make_shared<Article>("Animal");
74 farm->addLink(animal);
75 CollectionUtils::add(ac, animal);
77 auto pig = std::make_shared<Article>("Pig");
78 pig->marked(true);
79 farm->addLink(pig);
80 CollectionUtils::add(ac, pig);
82 pig->addLink(animal);
83 animal->addLink(pig);
85 auto equa = std::make_shared<Article>("Equality");
86 farm->addLink(equa);
87 CollectionUtils::add(ac, equa);
89 atj.output(ac, outfile);
90 outfile.flush();
91 outfile.close();
94 TEST(WriteArticleCollectionDepthTwo)
96 std::ofstream outfile("_artc_deeptree.dot",
97 std::ofstream::out | std::ofstream::trunc);
98 ToGraphvizWriter atj;
99 ArticleCollection ac;
101 auto farm = std::make_shared<Article>("Farm");
102 CollectionUtils::add(ac, farm);
104 auto animal = std::make_shared<Article>("Animal");
105 farm->addLink(animal);
106 CollectionUtils::add(ac, animal);
108 auto pig = std::make_shared<Article>("Pig");
109 farm->addLink(pig);
110 CollectionUtils::add(ac, pig);
112 auto equa = std::make_shared<Article>("Equality");
113 farm->addLink(equa);
114 CollectionUtils::add(ac, equa);
116 auto rights = std::make_shared<Article>("Rights");
117 equa->addLink(rights);
118 CollectionUtils::add(ac, rights);
120 auto cat = std::make_shared<Article>("Cat");
121 CollectionUtils::add(ac, cat);
122 animal->addLink(cat);
123 auto dog = std::make_shared<Article>("Dog");
124 CollectionUtils::add(ac, dog);
125 animal->addLink(dog);
127 atj.output(ac, outfile);
128 outfile.flush();
129 outfile.close();