dexample Picture: improve the test coverage.

In this patch, it replaced the test images with Lenna.
and fix the wrong jpeg file size figuring.
This commit is contained in:
Hermet Park 2021-07-30 11:01:08 +09:00 committed by Hermet Park
parent e59ba67b7c
commit 5e52134e2a
12 changed files with 54 additions and 23 deletions

View file

@ -20,8 +20,8 @@
* SOFTWARE. * SOFTWARE.
*/ */
#include "Common.h"
#include <fstream> #include <fstream>
#include "Common.h"
/************************************************************************/ /************************************************************************/
/* Drawing Commands */ /* Drawing Commands */
@ -34,7 +34,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
//Load jpg file from path //Load jpg file from path
for (int i = 0; i < 5; ++i) { for (int i = 0; i < 5; ++i) {
auto picture = tvg::Picture::gen(); auto picture = tvg::Picture::gen();
if (picture->load(EXAMPLE_DIR"/logo.jpg") != tvg::Result::Success) { if (picture->load(EXAMPLE_DIR"/test.jpg") != tvg::Result::Success) {
cout << "JPG is not supported. Did you enable JPG Loader?" << endl; cout << "JPG is not supported. Did you enable JPG Loader?" << endl;
return; return;
} }
@ -45,11 +45,14 @@ void tvgDrawCmds(tvg::Canvas* canvas)
} }
//Open file manually //Open file manually
ifstream file(EXAMPLE_DIR"/logo.jpg"); ifstream file(EXAMPLE_DIR"/test.jpg");
if (!file.is_open()) return; if (!file.is_open()) return;
auto size = sizeof(uint32_t) * (1000*1000); auto begin = file.tellg();
file.seekg(0, std::ios::end);
auto size = file.tellg() - begin;
auto data = (char*)malloc(size); auto data = (char*)malloc(size);
if (!data) return; if (!data) return;
file.seekg(0, std::ios::beg);
file.read(data, size); file.read(data, size);
file.close(); file.close();
@ -61,7 +64,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
free(data); free(data);
picture->translate(400, 0); picture->translate(400, 0);
picture->scale(0.4); picture->scale(0.8);
canvas->push(move(picture)); canvas->push(move(picture));
} }

View file

@ -20,6 +20,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
#include <fstream>
#include "Common.h" #include "Common.h"
/************************************************************************/ /************************************************************************/
@ -30,10 +31,11 @@ void tvgDrawCmds(tvg::Canvas* canvas)
{ {
if (!canvas) return; if (!canvas) return;
//Load png file from path
for (int i = 0; i < 5; ++i) { for (int i = 0; i < 5; ++i) {
auto picture = tvg::Picture::gen(); auto picture = tvg::Picture::gen();
if (picture->load(EXAMPLE_DIR"/logo.png") != tvg::Result::Success) { if (picture->load(EXAMPLE_DIR"/test.png") != tvg::Result::Success) {
cout << "PNG is not supported, Did you enable PNG Loader??" << endl; cout << "PNG is not supported. Did you enable PNG Loader?" << endl;
return; return;
} }
picture->translate(i* 150, i * 150); picture->translate(i* 150, i * 150);
@ -41,6 +43,29 @@ void tvgDrawCmds(tvg::Canvas* canvas)
picture->size(200, 200); picture->size(200, 200);
if (canvas->push(move(picture)) != tvg::Result::Success) return; if (canvas->push(move(picture)) != tvg::Result::Success) return;
} }
//Open file manually
ifstream file(EXAMPLE_DIR"/test.png");
if (!file.is_open()) return;
auto begin = file.tellg();
file.seekg(0, std::ios::end);
auto size = file.tellg() - begin;
auto data = (char*)malloc(size);
if (!data) return;
file.seekg(0, std::ios::beg);
file.read(data, size);
file.close();
auto picture = tvg::Picture::gen();
if (picture->load(data, size, true) != tvg::Result::Success) {
cout << "Couldnt load PNG file from data." << endl;
return;
}
free(data);
picture->translate(400, 0);
picture->scale(0.8);
canvas->push(move(picture));
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 399 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 463 KiB

View file

@ -112,7 +112,7 @@ TEST_CASE("Load Png file in Picture", "[capiPicture]")
REQUIRE(tvg_picture_load(picture, "invalid.png") == TVG_RESULT_INVALID_ARGUMENT); REQUIRE(tvg_picture_load(picture, "invalid.png") == TVG_RESULT_INVALID_ARGUMENT);
//Load Png file //Load Png file
REQUIRE(tvg_picture_load(picture, TEST_DIR"/logo.png") == TVG_RESULT_SUCCESS); REQUIRE(tvg_picture_load(picture, TEST_DIR"/test.png") == TVG_RESULT_SUCCESS);
//Verify Size //Verify Size
float w, h; float w, h;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

BIN
test/images/test.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 399 KiB

BIN
test/images/test.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 463 KiB

View file

@ -103,13 +103,13 @@ TEST_CASE("Load PNG file from path", "[tvgPicture]")
//Invalid file //Invalid file
REQUIRE(picture->load("invalid.png") == Result::InvalidArguments); REQUIRE(picture->load("invalid.png") == Result::InvalidArguments);
REQUIRE(picture->load(TEST_DIR"/logo.png") == Result::Success); REQUIRE(picture->load(TEST_DIR"/test.png") == Result::Success);
float w, h; float w, h;
REQUIRE(picture->size(&w, &h) == Result::Success); REQUIRE(picture->size(&w, &h) == Result::Success);
REQUIRE(w == 1000); REQUIRE(w == 512);
REQUIRE(h == 1000); REQUIRE(h == 512);
} }
TEST_CASE("Load PNG file from data", "[tvgPicture]") TEST_CASE("Load PNG file from data", "[tvgPicture]")
@ -118,7 +118,7 @@ TEST_CASE("Load PNG file from data", "[tvgPicture]")
REQUIRE(picture); REQUIRE(picture);
//Open file //Open file
ifstream file(TEST_DIR"/logo.png"); ifstream file(TEST_DIR"/test.png");
REQUIRE(file.is_open()); REQUIRE(file.is_open());
auto size = sizeof(uint32_t) * (1000*1000); auto size = sizeof(uint32_t) * (1000*1000);
auto data = (char*)malloc(size); auto data = (char*)malloc(size);
@ -130,8 +130,8 @@ TEST_CASE("Load PNG file from data", "[tvgPicture]")
float w, h; float w, h;
REQUIRE(picture->size(&w, &h) == Result::Success); REQUIRE(picture->size(&w, &h) == Result::Success);
REQUIRE(w == 1000); REQUIRE(w == 512);
REQUIRE(h == 1000); REQUIRE(h == 512);
free(data); free(data);
} }
@ -144,13 +144,13 @@ TEST_CASE("Load JPG file from path", "[tvgPicture]")
//Invalid file //Invalid file
REQUIRE(picture->load("invalid.jpg") == Result::InvalidArguments); REQUIRE(picture->load("invalid.jpg") == Result::InvalidArguments);
REQUIRE(picture->load(TEST_DIR"/logo.jpg") == Result::Success); REQUIRE(picture->load(TEST_DIR"/test.jpg") == Result::Success);
float w, h; float w, h;
REQUIRE(picture->size(&w, &h) == Result::Success); REQUIRE(picture->size(&w, &h) == Result::Success);
REQUIRE(w == 1000); REQUIRE(w == 512);
REQUIRE(h == 1000); REQUIRE(h == 512);
} }
TEST_CASE("Load JPG file from data", "[tvgPicture]") TEST_CASE("Load JPG file from data", "[tvgPicture]")
@ -159,10 +159,13 @@ TEST_CASE("Load JPG file from data", "[tvgPicture]")
REQUIRE(picture); REQUIRE(picture);
//Open file //Open file
ifstream file(TEST_DIR"/logo.jpg"); ifstream file(TEST_DIR"/test.jpg");
REQUIRE(file.is_open()); REQUIRE(file.is_open());
auto size = sizeof(uint32_t) * (1000*1000); auto begin = file.tellg();
file.seekg(0, std::ios::end);
auto size = file.tellg() - begin;
auto data = (char*)malloc(size); auto data = (char*)malloc(size);
file.seekg(0, std::ios::beg);
file.read(data, size); file.read(data, size);
file.close(); file.close();
@ -171,8 +174,8 @@ TEST_CASE("Load JPG file from data", "[tvgPicture]")
float w, h; float w, h;
REQUIRE(picture->size(&w, &h) == Result::Success); REQUIRE(picture->size(&w, &h) == Result::Success);
REQUIRE(w == 1000); REQUIRE(w == 512);
REQUIRE(h == 1000); REQUIRE(h == 512);
free(data); free(data);
} }
@ -231,7 +234,7 @@ TEST_CASE("Load PNG file and render", "[tvgPicture]")
auto picture = Picture::gen(); auto picture = Picture::gen();
REQUIRE(picture); REQUIRE(picture);
REQUIRE(picture->load(TEST_DIR"/logo.png") == Result::Success); REQUIRE(picture->load(TEST_DIR"/test.png") == Result::Success);
REQUIRE(canvas->push(move(picture)) == Result::Success); REQUIRE(canvas->push(move(picture)) == Result::Success);
@ -251,7 +254,7 @@ TEST_CASE("Load JPG file and render", "[tvgPicture]")
auto picture = Picture::gen(); auto picture = Picture::gen();
REQUIRE(picture); REQUIRE(picture);
REQUIRE(picture->load(TEST_DIR"/logo.jpg") == Result::Success); REQUIRE(picture->load(TEST_DIR"/test.jpg") == Result::Success);
REQUIRE(canvas->push(move(picture)) == Result::Success); REQUIRE(canvas->push(move(picture)) == Result::Success);