btool
A parser/converter/transpiler for .bib files
GeneratorFixtureTest.cpp
Go to the documentation of this file.
1 #include <gtest/gtest.h>
2 #include <BibElement.hpp>
3 #include <HtmlGenerator.hpp>
4 #include <XmlGenerator.hpp>
5 #include <PlainTextGenerator.hpp>
6 
7 using namespace std::literals::string_literals;
8 
14 struct GeneratorFixtureTest : public ::testing::Test {
15  std::vector<BibElement> element{
16  {
17  {
18  "FeigenspanSiFr11",
19  "article",
20  {
21  {"author", "{Janet Feigenspan and Norbert Siegmund and Jana Fruth}"},
22  {"title", "{{On the Role of Program Comprehension in Embedded Systems}}"},
23  {"journal", "{Softwaretechnik-Trends}"},
24  {"year", "{2011}"},
25  {"volume", "{31}"},
26  {"number", "{2}"},
27  {"month", "May"},
28  {"url",
29  "{http://www.uni-koblenz-landau.de/koblenz/fb4/institute/uebergreifend/sre/conferences/wsr/wsr2011/wsr2011_proceedings.pdf}"
30  }
31  }
32  }
33  }
34  };
35 };
36 
37 TEST_F(GeneratorFixtureTest, uniqueFields) {
38  std::unordered_set<std::string> expected{
39  "author",
40  "title",
41  "journal",
42  "year",
43  "volume",
44  "number",
45  "month",
46  "url"
47  };
48 
49  ASSERT_EQ(AbstractGenerator::uniqueFieldsOf(element), expected);
50 }
51 
52 TEST_F(GeneratorFixtureTest, htmlGeneratorTest) {
53  ASSERT_NO_THROW(([&](){
54  const auto html = HtmlGenerator{element}.write();
55  ASSERT_NE(html, "");
56  }()));
57 }
58 
59 TEST_F(GeneratorFixtureTest, xmlGeneratorTest) {
60  ASSERT_NO_THROW(([&](){
61  const auto xml = XmlGenerator{element}.write();
62  ASSERT_NE(xml, "");
63  }()));
64 }
65 
66 TEST_F(GeneratorFixtureTest, plainTextGeneratorTest) {
67  ASSERT_NO_THROW(([&](){
68  const auto plain = PlainTextGenerator{element}.write();
69  ASSERT_NE(plain, "");
70  }()));
71 }
72 
73 TEST_F(GeneratorFixtureTest, htmlGeneratorThrowsOnEmptyInput) {
74  ASSERT_ANY_THROW([]() {
75  HtmlGenerator({}).write();
76  }());
77 }
PlainTextGenerator.hpp
XmlGenerator.hpp
HtmlGenerator::write
auto write() -> std::string override
Definition: HtmlGenerator.cpp:17
HtmlGenerator
Definition: HtmlGenerator.hpp:11
HtmlGenerator.hpp
PlainTextGenerator
Definition: PlainTextGenerator.hpp:6
PlainTextGenerator::write
auto write() -> std::string override
Definition: PlainTextGenerator.cpp:9
AbstractGenerator::uniqueFieldsOf
static auto uniqueFieldsOf(const std::vector< BibElement > &values) noexcept -> std::unordered_set< std::string >
Definition: AbstractGenerator.cpp:33
XmlGenerator
Definition: XmlGenerator.hpp:9
TEST_F
TEST_F(GeneratorFixtureTest, uniqueFields)
Definition: GeneratorFixtureTest.cpp:37
XmlGenerator::write
auto write() -> std::string override
Definition: XmlGenerator.cpp:15
BibElement.hpp
GeneratorFixtureTest
Definition: GeneratorFixtureTest.cpp:14