summaryrefslogtreecommitdiff
path: root/dviware/dvisvgm/tests/BitmapTest.cpp
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /dviware/dvisvgm/tests/BitmapTest.cpp
Initial commit
Diffstat (limited to 'dviware/dvisvgm/tests/BitmapTest.cpp')
-rw-r--r--dviware/dvisvgm/tests/BitmapTest.cpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/dviware/dvisvgm/tests/BitmapTest.cpp b/dviware/dvisvgm/tests/BitmapTest.cpp
new file mode 100644
index 0000000000..8a93519186
--- /dev/null
+++ b/dviware/dvisvgm/tests/BitmapTest.cpp
@@ -0,0 +1,78 @@
+/*************************************************************************
+** BitmapTest.cpp **
+** **
+** This file is part of dvisvgm -- a fast DVI to SVG converter **
+** Copyright (C) 2005-2019 Martin Gieseking <martin.gieseking@uos.de> **
+** **
+** 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; either version 3 of **
+** the License, or (at your option) any later version. **
+** **
+** 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. **
+** **
+** You should have received a copy of the GNU General Public License **
+** along with this program; if not, see <http://www.gnu.org/licenses/>. **
+*************************************************************************/
+
+#include <gtest/gtest.h>
+#include "Bitmap.hpp"
+
+using namespace std;
+
+
+TEST(BitmapTest, bbox) {
+ Bitmap bitmap(-4, 10, 3, 10);
+ EXPECT_EQ(bitmap.width(), 15);
+ EXPECT_EQ(bitmap.height(), 8);
+ EXPECT_EQ(bitmap.xshift(), -4);
+ EXPECT_EQ(bitmap.yshift(), 3);
+ EXPECT_EQ(bitmap.bytesPerRow(), 2);
+ EXPECT_EQ(bitmap.empty(), false);
+}
+
+
+TEST(BitmapTest, setBits) {
+ int w, h;
+ Bitmap bitmap(-4, 10, 3, 10);
+ bitmap.getExtent(w, h);
+ EXPECT_EQ(w, 0);
+ EXPECT_EQ(h, 0);
+ bitmap.setBits(3, 5, 5);
+ bitmap.getExtent(w, h);
+ EXPECT_EQ(w, 5);
+ EXPECT_EQ(h, 1);
+
+ EXPECT_EQ(bitmap.rowPtr(3-3)[0], 0);
+ EXPECT_EQ(bitmap.rowPtr(3-3)[1], 0x7c);
+
+ EXPECT_EQ(bitmap.rowPtr(10-3)[0], 0);
+ EXPECT_EQ(bitmap.rowPtr(10-3)[1], 0);
+ bitmap.setBits(10, -3, 10);
+ bitmap.getExtent(w, h);
+ EXPECT_EQ(w, 13);
+ EXPECT_EQ(h, 8);
+
+ EXPECT_EQ(bitmap.rowPtr(10-3)[0], 0x7f);
+ EXPECT_EQ(bitmap.rowPtr(10-3)[1], 0xe0);
+}
+
+
+TEST(BitmapTest, copy) {
+ Bitmap bitmap(-4, 10, 3, 10);
+ vector<uint16_t> target;
+ bitmap.setBits(4, 5, 5);
+ bitmap.copy(target, false);
+ EXPECT_EQ(target.size(), 8u);
+ EXPECT_EQ(target[0], 0);
+ EXPECT_EQ(target[1], 124);
+ EXPECT_EQ(target[2], 0);
+ bitmap.copy(target, true);
+ EXPECT_EQ(target.size(), 8u);
+ EXPECT_EQ(target[5], 0);
+ EXPECT_EQ(target[6], 124);
+ EXPECT_EQ(target[7], 0);
+}