forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocument_api_tests.cpp
More file actions
65 lines (52 loc) · 1.76 KB
/
document_api_tests.cpp
File metadata and controls
65 lines (52 loc) · 1.76 KB
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
// Aseprite
// Copyright (C) 2001-2015 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
#include "tests/test.h"
#include "app/context.h"
#include "app/document.h"
#include "app/document_api.h"
#include "app/transaction.h"
#include "base/unique_ptr.h"
#include "doc/cel.h"
#include "doc/image.h"
#include "doc/primitives.h"
#include "doc/test_context.h"
using namespace app;
using namespace doc;
typedef base::UniquePtr<app::Document> DocumentPtr;
TEST(DocumentApi, MoveCel) {
TestContextT<app::Context> ctx;
DocumentPtr doc(static_cast<app::Document*>(ctx.documents().add(32, 16)));
Sprite* sprite = doc->sprite();
LayerImage* layer1 = dynamic_cast<LayerImage*>(sprite->folder()->getFirstLayer());
LayerImage* layer2 = new LayerImage(sprite);
Cel* cel1 = layer1->cel(frame_t(0));
cel1->setPosition(2, -2);
cel1->setOpacity(128);
Image* image1 = cel1->image();
EXPECT_EQ(32, image1->width());
EXPECT_EQ(16, image1->height());
for (int v=0; v<image1->height(); ++v)
for (int u=0; u<image1->width(); ++u)
image1->putPixel(u, v, u+v*image1->width());
// Create a copy for later comparison.
base::UniquePtr<Image> expectedImage(Image::createCopy(image1));
Transaction transaction(&ctx, "");
doc->getApi(transaction).moveCel(
layer1, frame_t(0),
layer2, frame_t(1));
transaction.commit();
EXPECT_EQ(NULL, layer1->cel(frame_t(0)));
Cel* cel2 = layer2->cel(frame_t(1));
ASSERT_TRUE(cel2 != NULL);
Image* image2 = cel2->image();
EXPECT_EQ(32, image2->width());
EXPECT_EQ(16, image2->height());
EXPECT_EQ(0, count_diff_between_images(expectedImage, image2));
EXPECT_EQ(2, cel2->x());
EXPECT_EQ(-2, cel2->y());
EXPECT_EQ(128, cel2->opacity());
doc->close();
}