|
| 1 | +///////////////////////////////////////////////////////////////////////////////////////////////// |
| 2 | +// |
| 3 | +// Tencent is pleased to support the open source community by making libpag available. |
| 4 | +// |
| 5 | +// Copyright (C) 2026 Tencent. All rights reserved. |
| 6 | +// |
| 7 | +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file |
| 8 | +// except in compliance with the License. You may obtain a copy of the License at |
| 9 | +// |
| 10 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +// |
| 12 | +// unless required by applicable law or agreed to in writing, software distributed under the |
| 13 | +// license is distributed on an "as is" basis, without warranties or conditions of any kind, |
| 14 | +// either express or implied. see the license for the specific language governing permissions |
| 15 | +// and limitations under the license. |
| 16 | +// |
| 17 | +///////////////////////////////////////////////////////////////////////////////////////////////// |
| 18 | + |
| 19 | +#ifdef PAG_BUILD_PPT |
| 20 | + |
| 21 | +#include <algorithm> |
| 22 | +#include <filesystem> |
| 23 | +#include <fstream> |
| 24 | +#include "pagx/PAGXExporter.h" |
| 25 | +#include "pagx/PAGXImporter.h" |
| 26 | +#include "pagx/PPTExporter.h" |
| 27 | +#include "pagx/SVGImporter.h" |
| 28 | +#include "utils/ProjectPath.h" |
| 29 | +#include "utils/TestUtils.h" |
| 30 | + |
| 31 | +namespace pag { |
| 32 | + |
| 33 | +/** |
| 34 | + * Read all SVG files from resources/svg, convert each to PAGX, then export to PPTX. |
| 35 | + */ |
| 36 | +PAGX_TEST(PAGXPPTTest, PPTExport_FromSVG) { |
| 37 | + std::string svgDir = ProjectPath::Absolute("resources/svg"); |
| 38 | + std::vector<std::string> svgFiles; |
| 39 | + |
| 40 | + for (const auto& entry : std::filesystem::directory_iterator(svgDir)) { |
| 41 | + if (entry.path().extension() == ".svg") { |
| 42 | + svgFiles.push_back(entry.path().string()); |
| 43 | + } |
| 44 | + } |
| 45 | + std::sort(svgFiles.begin(), svgFiles.end()); |
| 46 | + ASSERT_FALSE(svgFiles.empty()) << "No SVG files found in resources/svg"; |
| 47 | + |
| 48 | + auto outDir = ProjectPath::Absolute("test/out/PAGXPPTTest"); |
| 49 | + if (!std::filesystem::exists(outDir)) { |
| 50 | + std::filesystem::create_directories(outDir); |
| 51 | + } |
| 52 | + |
| 53 | + for (const auto& svgPath : svgFiles) { |
| 54 | + std::string baseName = std::filesystem::path(svgPath).stem().string(); |
| 55 | + |
| 56 | + auto doc = pagx::SVGImporter::Parse(svgPath); |
| 57 | + if (!doc) { |
| 58 | + continue; |
| 59 | + } |
| 60 | + if (doc->width <= 0 || doc->height <= 0) { |
| 61 | + continue; |
| 62 | + } |
| 63 | + |
| 64 | + auto pagxXml = pagx::PAGXExporter::ToXML(*doc); |
| 65 | + ASSERT_FALSE(pagxXml.empty()) << baseName << " PAGX export failed"; |
| 66 | + |
| 67 | + auto pagxPath = outDir + "/" + baseName + ".pagx"; |
| 68 | + { |
| 69 | + std::ofstream file(pagxPath, std::ios::binary); |
| 70 | + ASSERT_TRUE(file.good()) << "Failed to write " << pagxPath; |
| 71 | + file.write(pagxXml.data(), static_cast<std::streamsize>(pagxXml.size())); |
| 72 | + } |
| 73 | + |
| 74 | + auto reimported = pagx::PAGXImporter::FromFile(pagxPath); |
| 75 | + ASSERT_NE(reimported, nullptr) << baseName << " PAGX re-import failed"; |
| 76 | + |
| 77 | + auto pptxPath = outDir + "/" + baseName + ".pptx"; |
| 78 | + ASSERT_TRUE(pagx::PPTExporter::ToFile(*reimported, pptxPath)) |
| 79 | + << baseName << " PPT export failed"; |
| 80 | + EXPECT_TRUE(std::filesystem::exists(pptxPath)); |
| 81 | + EXPECT_GT(std::filesystem::file_size(pptxPath), 0u) << baseName << " PPTX file is empty"; |
| 82 | + } |
| 83 | +} |
| 84 | + |
| 85 | +} // namespace pag |
| 86 | + |
| 87 | +#endif |
0 commit comments