-
Notifications
You must be signed in to change notification settings - Fork 286
Prevent Pencil2D projects from referencing external files #1843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
scribblemaniac
merged 8 commits into
pencil2d:master
from
scribblemaniac:external-ref-block
Jun 6, 2024
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
51244f8
Check to make sure assets are only loaded from the data dir
scribblemaniac 37cadbd
Add tests for loading xml in various src conditions
scribblemaniac f255b62
Fix Qt 6 build error
scribblemaniac dd4f4e7
Refactor data dir checks into utility function and handle new edge cases
scribblemaniac a99aedf
Add check for palette reading
scribblemaniac 0c5bb63
Fix memory leaks in layer xml loading tests
scribblemaniac fb2f6fb
Refactor a couple minor parts of validDataPath for clarity
scribblemaniac a82bd7b
Refactor validateDataPath loops to improve readability
scribblemaniac File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
|
||
Pencil2D - Traditional Animation Software | ||
Copyright (C) 2012-2020 Matthew Chiawen Chang | ||
|
||
This program is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU General Public License | ||
as published by the Free Software Foundation; version 2 of the License. | ||
|
||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
|
||
*/ | ||
#include "catch.hpp" | ||
|
||
#include "layerbitmap.h" | ||
#include "bitmapimage.h" | ||
|
||
#include <memory> | ||
#include <QDir> | ||
#include <QDomElement> | ||
#include <QTemporaryDir> | ||
|
||
TEST_CASE("Load bitmap layer from XML") | ||
{ | ||
std::unique_ptr<Layer> bitmapLayer(new LayerBitmap(1)); | ||
QTemporaryDir dataDir; | ||
REQUIRE(dataDir.isValid()); | ||
QDomDocument doc; | ||
doc.setContent(QString("<layer id='1' name='Bitmap Layer' visibility='1'></layer>")); | ||
QDomElement layerElem = doc.documentElement(); | ||
ProgressCallback nullCallback = []() {}; | ||
|
||
auto createFrame = [&layerElem, &doc](QString src = "001.001.png", int frame = 1, int topLeftX = 0, int topLeftY = 0) | ||
{ | ||
QDomElement frameElem = doc.createElement("image"); | ||
frameElem.setAttribute("src", src); | ||
frameElem.setAttribute("frame", frame); | ||
frameElem.setAttribute("topLeftX", topLeftX); | ||
frameElem.setAttribute("topLeftY", topLeftY); | ||
layerElem.appendChild(frameElem); | ||
}; | ||
|
||
SECTION("No frames") | ||
{ | ||
bitmapLayer->loadDomElement(layerElem, dataDir.path(), []() {}); | ||
|
||
REQUIRE(bitmapLayer->keyFrameCount() == 0); | ||
} | ||
|
||
SECTION("Single frame") | ||
{ | ||
createFrame("001.001.png", 1, 0, 0); | ||
|
||
bitmapLayer->loadDomElement(layerElem, dataDir.path(), nullCallback); | ||
|
||
REQUIRE(bitmapLayer->keyFrameCount() == 1); | ||
BitmapImage* frame = static_cast<BitmapImage*>(bitmapLayer->getKeyFrameAt(1)); | ||
REQUIRE(frame != nullptr); | ||
REQUIRE(frame->top() == 0); | ||
REQUIRE(frame->left() == 0); | ||
REQUIRE(QDir(frame->fileName()) == QDir(dataDir.filePath("001.001.png"))); | ||
} | ||
|
||
SECTION("Multiple frames") | ||
{ | ||
createFrame("001.001.png", 1); | ||
createFrame("001.002.png", 2); | ||
|
||
bitmapLayer->loadDomElement(layerElem, dataDir.path(), nullCallback); | ||
|
||
REQUIRE(bitmapLayer->keyFrameCount() == 2); | ||
for (int i = 1; i <= 2; i++) | ||
{ | ||
BitmapImage* frame = static_cast<BitmapImage*>(bitmapLayer->getKeyFrameAt(i)); | ||
REQUIRE(frame != nullptr); | ||
REQUIRE(frame->top() == 0); | ||
REQUIRE(frame->left() == 0); | ||
REQUIRE(QDir(frame->fileName()) == QDir(dataDir.filePath(QString("001.%1.png").arg(QString::number(i), 3, QChar('0'))))); | ||
} | ||
} | ||
|
||
SECTION("Frame with absolute src") | ||
{ | ||
createFrame(QDir(dataDir.filePath("001.001.png")).absolutePath()); | ||
|
||
bitmapLayer->loadDomElement(layerElem, dataDir.path(), nullCallback); | ||
|
||
REQUIRE(bitmapLayer->keyFrameCount() == 0); | ||
} | ||
|
||
SECTION("Frame src outside of data dir") | ||
{ | ||
QTemporaryDir otherDir; | ||
createFrame(QDir(dataDir.path()).relativeFilePath(QDir(otherDir.filePath("001.001.png")).absolutePath())); | ||
|
||
bitmapLayer->loadDomElement(layerElem, dataDir.path(), nullCallback); | ||
|
||
REQUIRE(bitmapLayer->keyFrameCount() == 0); | ||
} | ||
|
||
SECTION("Frame src nested in data dir") | ||
{ | ||
createFrame("subdir/001.001.png"); | ||
|
||
bitmapLayer->loadDomElement(layerElem, dataDir.path(), nullCallback); | ||
|
||
REQUIRE(bitmapLayer->keyFrameCount() == 1); | ||
BitmapImage* frame = static_cast<BitmapImage*>(bitmapLayer->getKeyFrameAt(1)); | ||
REQUIRE(frame != nullptr); | ||
REQUIRE(frame->top() == 0); | ||
REQUIRE(frame->left() == 0); | ||
REQUIRE(QDir(frame->fileName()) == QDir(dataDir.filePath("subdir/001.001.png"))); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.