summaryrefslogtreecommitdiff
path: root/Build/source/texk/dvisvgm/dvisvgm-src/tests/CMapManagerTest.cpp
blob: e36ed3af0a7080f060c62b3988b6032ddeb77c80 (plain)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*************************************************************************
** CMapReaderTest.cpp                                                   **
**                                                                      **
** This file is part of dvisvgm -- a fast DVI to SVG converter          **
** Copyright (C) 2005-2017 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 <fstream>
#include "CMap.hpp"
#include "CMapManager.hpp"
#include "FileFinder.hpp"
#include "Message.hpp"

#ifndef SRCDIR
#define SRCDIR "."
#endif


class CMapManagerTest : public ::testing::Test
{
	protected:
		void SetUp () override {
			FileFinder::init("CMapManagerTest", "CMapManagerTest", false);
			FileFinder::instance().addLookupDir(SRCDIR"/data");
		}
};


TEST_F(CMapManagerTest, lookup_buildin) {
	CMapManager &manager = CMapManager::instance();
	CMap *cmap=0;
	EXPECT_TRUE((cmap = manager.lookup("Identity-H")) != 0);
	EXPECT_STREQ(cmap->name(), "Identity-H");
	EXPECT_EQ(cmap->getROString(), "Adobe-Identity");
	EXPECT_TRUE(cmap->mapsToCID());

	EXPECT_TRUE((cmap = manager.lookup("Identity-V")) != 0);
	EXPECT_STREQ(cmap->name(), "Identity-V");
	EXPECT_EQ(cmap->getROString(), "Adobe-Identity");
	EXPECT_TRUE(cmap->mapsToCID());

	EXPECT_TRUE((cmap = manager.lookup("unicode")) != 0);
	EXPECT_STREQ(cmap->name(), "unicode");
	EXPECT_EQ(cmap->getROString(), "");
	EXPECT_FALSE(cmap->mapsToCID());
	EXPECT_TRUE(cmap->path() == 0);
}


TEST_F(CMapManagerTest, lookup_file) {
	CMapManager &manager = CMapManager::instance();
	CMap *cmap = manager.lookup("ot1.cmap");
	EXPECT_TRUE(cmap != 0);
	EXPECT_STREQ(cmap->name(), "ot1.cmap");
	EXPECT_EQ(cmap->getROString(), "");
	EXPECT_FALSE(cmap->mapsToCID());
	EXPECT_EQ(cmap->bfcode(0x00), 0x0393);
	EXPECT_EQ(cmap->bfcode(0x01), 0x0394);
	EXPECT_EQ(cmap->bfcode(0x02), 0x0398);
	EXPECT_EQ(cmap->bfcode(0x7c), 0x2014);
	EXPECT_EQ(cmap->bfcode(0x7d), 0x02dd);
	EXPECT_EQ(cmap->bfcode(0x7f), 0x00a8);
	EXPECT_EQ(cmap->bfcode(0x80), 0);
}


TEST_F(CMapManagerTest, lookup_fail) {
	Message::LEVEL = 0;  // avoid warning messages
	CMapManager &manager = CMapManager::instance();
	EXPECT_TRUE(manager.lookup("does-not-exists") == 0);
}