1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
#include <gtest/gtest.h>
#include <AST.h>
#include <Comment.h>
#include <Entry.h>
#include <Group.h>
using namespace XdgUtils::DesktopEntry::AST;
TEST(TestAST, create) {
AST ast1;
auto g1 = new Group("[Desktop Entry]", "Desktop Entry");;
std::vector<std::shared_ptr<Node>> g1Entries = {
std::shared_ptr<Node>(new Entry(" Name", "Name", "", "", "=My App", "My App")),
std::shared_ptr<Node>(new Comment("# Test", " Test"))
};
g1->setEntries(g1Entries);
std::vector<std::shared_ptr<Node>> ast1Entries = {
std::shared_ptr<Node>(new Comment("# Test", " Test")),
std::shared_ptr<Node>(g1)
};
ast1.setEntries(ast1Entries);;
}
TEST(TestAST, compare) {
AST ast1;
auto g1 = new Group("[Desktop Entry]", "Desktop Entry");;
std::vector<std::shared_ptr<Node>> g1Entries = {
std::shared_ptr<Node>(new Entry(" Name", "Name", "", "", "=My App", "My App")),
std::shared_ptr<Node>(new Comment("# Test", " Test"))
};
g1->setEntries(g1Entries);
std::vector<std::shared_ptr<Node>> ast1Entries = {
std::shared_ptr<Node>(new Comment("# Test", " Test")),
std::shared_ptr<Node>(g1)
};
ast1.setEntries(ast1Entries);;
AST ast2;
auto g2 = new Group("[Desktop Entry]", "Desktop Entry");;
std::vector<std::shared_ptr<Node>> g2Entries = {
std::shared_ptr<Node>(new Entry(" Name", "Name", "", "", "=My App", "My App")),
std::shared_ptr<Node>(new Comment("# Test", " Test"))
};
g2->setEntries(g2Entries);
std::vector<std::shared_ptr<Node>> ast2Entries = {
std::shared_ptr<Node>(new Comment("# Test", " Test")),
std::shared_ptr<Node>(g2)
};
ast2.setEntries(ast2Entries);;
ASSERT_EQ(ast1, ast2);
AST ast3;
auto g3 = new Group("[Desktop Entry]", "Desktop Entry");;
std::vector<std::shared_ptr<Node>> g3Entries = {
std::shared_ptr<Node>(new Entry(" Name", "Name", "", "", "=My App", "My App")),
std::shared_ptr<Node>(new Comment("# Test", " Test"))
};
g3->setEntries(g3Entries);
std::vector<std::shared_ptr<Node>> ast3Entries = {std::shared_ptr<Node>(g3)};
ast3.setEntries(ast3Entries);;
ASSERT_NE(ast1, ast3);
}
TEST(TestAST, write) {
AST ast1;
auto g1 = new Group("[Desktop Entry]", "Desktop Entry");;
std::vector<std::shared_ptr<Node>> g1Entries = {
std::shared_ptr<Node>(new Entry(" Name", "Name", "", "", "=My App", "My App")),
std::shared_ptr<Node>(new Comment("# Test", " Test"))
};
g1->setEntries(g1Entries);
std::vector<std::shared_ptr<Node>> ast1Entries = {
std::shared_ptr<Node>(new Comment("# Test", " Test")),
std::shared_ptr<Node>(g1)
};
ast1.setEntries(ast1Entries);;
std::stringstream res;
ast1.write(res);
ASSERT_EQ(res.str(),
"# Test\n"
"[Desktop Entry]\n"
" Name=My App\n"
"# Test");
}
TEST(TestAST, copy) {
AST ast1;
auto g1 = new Group("[Desktop Entry]", "Desktop Entry");;
std::vector<std::shared_ptr<Node>> g1Entries = {
std::shared_ptr<Node>(new Entry(" Name", "Name", "", "", "=My App", "My App")),
std::shared_ptr<Node>(new Comment("# Test", " Test"))
};
g1->setEntries(g1Entries);
std::vector<std::shared_ptr<Node>> ast1Entries = {
std::shared_ptr<Node>(new Comment("# Test", " Test")),
std::shared_ptr<Node>(g1)
};
ast1.setEntries(ast1Entries);;
AST ast2 = ast1;
ASSERT_EQ(ast1, ast2);
ast1.getEntries().front()->setValue("Desktop Action One");
ASSERT_NE(ast1, ast2);
}
TEST(TestAST, move) {
AST ast1;
auto g1 = new Group("[Desktop Entry]", "Desktop Entry");;
std::vector<std::shared_ptr<Node>> g1Entries = {
std::shared_ptr<Node>(new Entry(" Name", "Name", "", "", "=My App", "My App")),
std::shared_ptr<Node>(new Comment("# Test", " Test"))
};
g1->setEntries(g1Entries);
std::vector<std::shared_ptr<Node>> ast1Entries = {
std::shared_ptr<Node>(new Comment("# Test", " Test")),
std::shared_ptr<Node>(g1)
};
ast1.setEntries(ast1Entries);;
std::stringstream stream1;
stream1 << ast1;
AST ast2 = std::move(ast1);
std::stringstream stream2;
stream2 << ast2;
ASSERT_EQ(stream1.str(), stream2.str());
}
|