2015-02-12 23:16:25 +08:00
|
|
|
// Aseprite
|
2016-06-07 00:57:35 +08:00
|
|
|
// Copyright (C) 2001-2016 David Capello
|
2015-02-12 23:16:25 +08:00
|
|
|
//
|
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License version 2 as
|
|
|
|
|
// published by the Free Software Foundation.
|
2012-05-20 03:22:55 +08:00
|
|
|
|
2012-08-24 11:24:51 +08:00
|
|
|
#include "tests/test.h"
|
2012-05-20 03:22:55 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/app.h"
|
2014-07-20 09:01:39 +08:00
|
|
|
#include "app/context.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/document.h"
|
|
|
|
|
#include "app/file/file.h"
|
|
|
|
|
#include "app/file/file_formats_manager.h"
|
2016-06-07 00:57:35 +08:00
|
|
|
#include "base/unique_ptr.h"
|
2014-10-21 09:21:31 +08:00
|
|
|
#include "doc/doc.h"
|
2012-05-20 03:22:55 +08:00
|
|
|
|
|
|
|
|
#include <cstdio>
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2014-07-07 09:10:48 +08:00
|
|
|
using namespace app;
|
2013-08-06 08:20:19 +08:00
|
|
|
|
2012-05-20 03:22:55 +08:00
|
|
|
TEST(File, SeveralSizes)
|
|
|
|
|
{
|
|
|
|
|
// Register all possible image formats.
|
|
|
|
|
std::vector<char> fn(256);
|
2014-07-29 11:53:24 +08:00
|
|
|
app::Context ctx;
|
2012-05-20 03:22:55 +08:00
|
|
|
|
|
|
|
|
for (int w=10; w<=10+503*2; w+=503) {
|
|
|
|
|
for (int h=10; h<=10+503*2; h+=503) {
|
|
|
|
|
//std::sprintf(&fn[0], "test_%dx%d.ase", w, h);
|
|
|
|
|
std::sprintf(&fn[0], "test.ase");
|
|
|
|
|
|
|
|
|
|
{
|
2016-06-07 00:57:35 +08:00
|
|
|
base::UniquePtr<doc::Document> doc(ctx.documents().add(w, h, doc::ColorMode::INDEXED, 256));
|
2012-05-20 03:22:55 +08:00
|
|
|
doc->setFilename(&fn[0]);
|
|
|
|
|
|
|
|
|
|
// Random pixels
|
2014-12-29 08:04:08 +08:00
|
|
|
Layer* layer = doc->sprite()->folder()->getFirstLayer();
|
2013-03-29 22:01:11 +08:00
|
|
|
ASSERT_TRUE(layer != NULL);
|
2014-12-29 08:04:08 +08:00
|
|
|
Image* image = layer->cel(frame_t(0))->image();
|
2012-05-20 03:22:55 +08:00
|
|
|
std::srand(w*h);
|
|
|
|
|
int c = std::rand()%256;
|
|
|
|
|
for (int y=0; y<h; y++) {
|
|
|
|
|
for (int x=0; x<w; x++) {
|
2013-11-10 06:59:05 +08:00
|
|
|
put_pixel_fast<IndexedTraits>(image, x, y, c);
|
2012-05-20 03:22:55 +08:00
|
|
|
if ((std::rand()&4) == 0)
|
|
|
|
|
c = std::rand()%256;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-07 00:57:35 +08:00
|
|
|
save_document(&ctx, doc.get());
|
2014-07-30 12:45:59 +08:00
|
|
|
doc->close();
|
2012-05-20 03:22:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2016-06-07 00:57:35 +08:00
|
|
|
base::UniquePtr<app::Document> doc(load_document(&ctx, &fn[0]));
|
2014-07-30 12:28:15 +08:00
|
|
|
ASSERT_EQ(w, doc->sprite()->width());
|
|
|
|
|
ASSERT_EQ(h, doc->sprite()->height());
|
2012-05-20 03:22:55 +08:00
|
|
|
|
|
|
|
|
// Same random pixels (see the seed)
|
2014-12-29 08:04:08 +08:00
|
|
|
Layer* layer = doc->sprite()->folder()->getFirstLayer();
|
2016-06-07 00:57:35 +08:00
|
|
|
ASSERT_TRUE(layer != nullptr);
|
2014-12-29 08:04:08 +08:00
|
|
|
Image* image = layer->cel(frame_t(0))->image();
|
2012-05-20 03:22:55 +08:00
|
|
|
std::srand(w*h);
|
|
|
|
|
int c = std::rand()%256;
|
|
|
|
|
for (int y=0; y<h; y++) {
|
|
|
|
|
for (int x=0; x<w; x++) {
|
2013-11-10 06:59:05 +08:00
|
|
|
ASSERT_EQ(c, get_pixel_fast<IndexedTraits>(image, x, y));
|
2012-05-20 03:22:55 +08:00
|
|
|
if ((std::rand()&4) == 0)
|
|
|
|
|
c = std::rand()%256;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-07-30 12:45:59 +08:00
|
|
|
|
|
|
|
|
doc->close();
|
2012-05-20 03:22:55 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|