|
| 1 | +//system |
| 2 | +#include <sstream> |
| 3 | + |
| 4 | +// library |
| 5 | +#include <gtest/gtest.h> |
| 6 | +#include <XdgUtils/DesktopEntry/DesktopEntry.h> |
| 7 | +#include <boost/property_tree/xml_parser.hpp> |
| 8 | +#include <boost/property_tree/ptree.hpp> |
| 9 | + |
| 10 | +// local |
| 11 | +#include <appimage/core/exceptions.h> |
| 12 | +#include "utils/hashlib.h" |
| 13 | +#include "integrator/MimeInfoEditor.h" |
| 14 | + |
| 15 | +using namespace appimage::desktop_integration::integrator; |
| 16 | +using namespace appimage::utils; |
| 17 | + |
| 18 | +class MimeInfoEditorTests : public ::testing::Test { |
| 19 | +protected: |
| 20 | + std::stringstream mimeInfo; |
| 21 | + std::stringstream mimeInfoWithIconEntry; |
| 22 | + std::stringstream expectedMimeInfo; |
| 23 | +protected: |
| 24 | + |
| 25 | + void SetUp() override { |
| 26 | + mimeInfo << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
| 27 | + "<mime-info xmlns=\"http://www.freedesktop.org/standards/shared-mime-info\">\n" |
| 28 | + " <mime-type type=\"application/x-starbright-file\">\n" |
| 29 | + " <sub-class-of type=\"application/xml\"/>\n" |
| 30 | + " <comment>Starbright File</comment>\n" |
| 31 | + " <glob pattern=\"*.starb\"/>\n" |
| 32 | + " </mime-type>\n" |
| 33 | + "</mime-info>"; |
| 34 | + |
| 35 | + mimeInfoWithIconEntry |
| 36 | + << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
| 37 | + "<mime-info xmlns=\"http://www.freedesktop.org/standards/shared-mime-info\">\n" |
| 38 | + " <mime-type type=\"application/x-starbright-file\">\n" |
| 39 | + " <sub-class-of type=\"application/xml\"/>\n" |
| 40 | + " <comment>Starbright File</comment>\n" |
| 41 | + " <glob pattern=\"*.starb\"/>\n" |
| 42 | + " <icon name=\"application-x-starbright-file\"/>\n" |
| 43 | + " </mime-type>\n" |
| 44 | + "</mime-info>"; |
| 45 | + |
| 46 | + expectedMimeInfo |
| 47 | + << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
| 48 | + "<mime-info xmlns=\"http://www.freedesktop.org/standards/shared-mime-info\">\n" |
| 49 | + " <mime-type type=\"application/x-starbright-file\">\n" |
| 50 | + " <sub-class-of type=\"application/xml\"/>\n" |
| 51 | + " <comment>Starbright File</comment>\n" |
| 52 | + " <glob pattern=\"*.starb\"/>\n" |
| 53 | + " <icon name=\"application-x-starbright-file-appimaged-d41d8cd98f00b204e9800998ecf8427e\"/>\n" |
| 54 | + " </mime-type>\n" |
| 55 | + "</mime-info>"; |
| 56 | + } |
| 57 | +}; |
| 58 | + |
| 59 | +TEST_F(MimeInfoEditorTests, setIcon) { |
| 60 | + MimeInfoEditor editor(mimeInfo.str(), "appimaged-d41d8cd98f00b204e9800998ecf8427e"); |
| 61 | + std::string result = editor.edit(); |
| 62 | + |
| 63 | + |
| 64 | + using boost::property_tree::ptree; |
| 65 | + |
| 66 | + std::stringstream resultStream(result); |
| 67 | + |
| 68 | + // populate tree structure pt |
| 69 | + ptree resultPt, expectedPt; |
| 70 | + read_xml(resultStream, resultPt, boost::property_tree::xml_parser::trim_whitespace); |
| 71 | + read_xml(expectedMimeInfo, expectedPt, boost::property_tree::xml_parser::trim_whitespace); |
| 72 | + |
| 73 | + |
| 74 | + ASSERT_EQ(resultPt, expectedPt); |
| 75 | +} |
| 76 | + |
| 77 | +TEST_F(MimeInfoEditorTests, updateIcon) { |
| 78 | + MimeInfoEditor editor(mimeInfoWithIconEntry.str(), "appimaged-d41d8cd98f00b204e9800998ecf8427e"); |
| 79 | + std::string result = editor.edit(); |
| 80 | + |
| 81 | + |
| 82 | + using boost::property_tree::ptree; |
| 83 | + |
| 84 | + std::stringstream resultStream(result); |
| 85 | + |
| 86 | + // populate tree structure pt |
| 87 | + ptree resultPt, expectedPt; |
| 88 | + read_xml(resultStream, resultPt, boost::property_tree::xml_parser::trim_whitespace); |
| 89 | + read_xml(expectedMimeInfo, expectedPt, boost::property_tree::xml_parser::trim_whitespace); |
| 90 | + |
| 91 | + |
| 92 | + ASSERT_EQ(resultPt, expectedPt); |
| 93 | +} |
0 commit comments